1
0
Fork 0
forked from forks/qmk_firmware

Adafruit BLE cleanups (#11556)

This commit is contained in:
Ryan 2021-01-15 14:32:00 +11:00 committed by GitHub
parent f519a9908e
commit 84e2f1ec17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 32 deletions

View file

@ -11,6 +11,7 @@
#include "spi_master.h" #include "spi_master.h"
#include "wait.h" #include "wait.h"
#include "analog.h" #include "analog.h"
#include "progmem.h"
// These are the pin assignments for the 32u4 boards. // These are the pin assignments for the 32u4 boards.
// You may define them to something else in your config.h // You may define them to something else in your config.h
@ -36,10 +37,8 @@
#define SAMPLE_BATTERY #define SAMPLE_BATTERY
#define ConnectionUpdateInterval 1000 /* milliseconds */ #define ConnectionUpdateInterval 1000 /* milliseconds */
#ifdef SAMPLE_BATTERY #ifndef BATTERY_LEVEL_PIN
# ifndef BATTERY_LEVEL_PIN # define BATTERY_LEVEL_PIN B5
# define BATTERY_LEVEL_PIN B5
# endif
#endif #endif
static struct { static struct {
@ -118,15 +117,15 @@ enum sdep_type {
SdepResponse = 0x20, SdepResponse = 0x20,
SdepAlert = 0x40, SdepAlert = 0x40,
SdepError = 0x80, SdepError = 0x80,
SdepSlaveNotReady = 0xfe, // Try again later SdepSlaveNotReady = 0xFE, // Try again later
SdepSlaveOverflow = 0xff, // You read more data than is available SdepSlaveOverflow = 0xFF, // You read more data than is available
}; };
enum ble_cmd { enum ble_cmd {
BleInitialize = 0xbeef, BleInitialize = 0xBEEF,
BleAtWrapper = 0x0a00, BleAtWrapper = 0x0A00,
BleUartTx = 0x0a01, BleUartTx = 0x0A01,
BleUartRx = 0x0a02, BleUartRx = 0x0A02,
}; };
enum ble_system_event_bits { enum ble_system_event_bits {
@ -176,7 +175,7 @@ static bool sdep_send_pkt(const struct sdep_msg *msg, uint16_t timeout) {
static inline void sdep_build_pkt(struct sdep_msg *msg, uint16_t command, const uint8_t *payload, uint8_t len, bool moredata) { static inline void sdep_build_pkt(struct sdep_msg *msg, uint16_t command, const uint8_t *payload, uint8_t len, bool moredata) {
msg->type = SdepCommand; msg->type = SdepCommand;
msg->cmd_low = command & 0xff; msg->cmd_low = command & 0xFF;
msg->cmd_high = command >> 8; msg->cmd_high = command >> 8;
msg->len = len; msg->len = len;
msg->more = (moredata && len == SdepMaxPayload) ? 1 : 0; msg->more = (moredata && len == SdepMaxPayload) ? 1 : 0;
@ -407,11 +406,11 @@ static bool at_command(const char *cmd, char *resp, uint16_t resplen, bool verbo
} }
if (resp == NULL) { if (resp == NULL) {
auto now = timer_read(); uint16_t now = timer_read();
while (!resp_buf.enqueue(now)) { while (!resp_buf.enqueue(now)) {
resp_buf_read_one(false); resp_buf_read_one(false);
} }
auto later = timer_read(); uint16_t later = timer_read();
if (TIMER_DIFF_16(later, now) > 0) { if (TIMER_DIFF_16(later, now) > 0) {
dprintf("waited %dms for resp_buf\n", TIMER_DIFF_16(later, now)); dprintf("waited %dms for resp_buf\n", TIMER_DIFF_16(later, now));
} }
@ -422,7 +421,7 @@ static bool at_command(const char *cmd, char *resp, uint16_t resplen, bool verbo
} }
bool at_command_P(const char *cmd, char *resp, uint16_t resplen, bool verbose) { bool at_command_P(const char *cmd, char *resp, uint16_t resplen, bool verbose) {
auto cmdbuf = (char *)alloca(strlen_P(cmd) + 1); char *cmdbuf = (char *)alloca(strlen_P(cmd) + 1);
strcpy_P(cmdbuf, cmd); strcpy_P(cmdbuf, cmd);
return at_command(cmdbuf, resp, resplen, verbose); return at_command(cmdbuf, resp, resplen, verbose);
} }
@ -484,9 +483,9 @@ fail:
static void set_connected(bool connected) { static void set_connected(bool connected) {
if (connected != state.is_connected) { if (connected != state.is_connected) {
if (connected) { if (connected) {
print("****** BLE CONNECT!!!!\n"); dprint("BLE connected\n");
} else { } else {
print("****** BLE DISCONNECT!!!!\n"); dprint("BLE disconnected\n");
} }
state.is_connected = connected; state.is_connected = connected;
@ -612,7 +611,7 @@ static bool process_queue_item(struct queue_item *item, uint16_t timeout) {
} }
} }
bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys) { void adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys) {
struct queue_item item; struct queue_item item;
bool didWait = false; bool didWait = false;
@ -638,30 +637,27 @@ bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nk
} }
if (nkeys <= 6) { if (nkeys <= 6) {
return true; return;
} }
nkeys -= 6; nkeys -= 6;
keys += 6; keys += 6;
} }
return true;
} }
bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration) { void adafruit_ble_send_consumer_key(uint16_t usage) {
struct queue_item item; struct queue_item item;
item.queue_type = QTConsumer; item.queue_type = QTConsumer;
item.consumer = keycode; item.consumer = usage;
while (!send_buf.enqueue(item)) { while (!send_buf.enqueue(item)) {
send_buf_send_one(); send_buf_send_one();
} }
return true;
} }
#ifdef MOUSE_ENABLE #ifdef MOUSE_ENABLE
bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons) { void adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons) {
struct queue_item item; struct queue_item item;
item.queue_type = QTMouseMove; item.queue_type = QTMouseMove;
@ -674,7 +670,6 @@ bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan,
while (!send_buf.enqueue(item)) { while (!send_buf.enqueue(item)) {
send_buf_send_one(); send_buf_send_one();
} }
return true;
} }
#endif #endif

View file

@ -10,7 +10,6 @@
#include <string.h> #include <string.h>
#include "config_common.h" #include "config_common.h"
#include "progmem.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -35,17 +34,17 @@ extern void adafruit_ble_task(void);
* this set of keys. * this set of keys.
* Also sends a key release indicator, so that the keys do not remain * Also sends a key release indicator, so that the keys do not remain
* held down. */ * held down. */
extern bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys); extern void adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys);
/* Send a consumer keycode, holding it down for the specified duration /* Send a consumer usage.
* (milliseconds) */ * (milliseconds) */
extern bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration); extern void adafruit_ble_send_consumer_key(uint16_t usage);
#ifdef MOUSE_ENABLE #ifdef MOUSE_ENABLE
/* Send a mouse/wheel movement report. /* Send a mouse/wheel movement report.
* The parameters are signed and indicate positive of negative direction * The parameters are signed and indicate positive or negative direction
* change. */ * change. */
extern bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons); extern void adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons);
#endif #endif
/* Compute battery voltage by reading an analog pin. /* Compute battery voltage by reading an analog pin.

View file

@ -809,7 +809,7 @@ static void send_consumer(uint16_t data) {
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
# ifdef MODULE_ADAFRUIT_BLE # ifdef MODULE_ADAFRUIT_BLE
adafruit_ble_send_consumer_key(data, 0); adafruit_ble_send_consumer_key(data);
# elif MODULE_RN42 # elif MODULE_RN42
static uint16_t last_data = 0; static uint16_t last_data = 0;
if (data == last_data) return; if (data == last_data) return;