summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-01-15 14:32:00 +1100
committerGitHub <noreply@github.com>2021-01-15 14:32:00 +1100
commit84e2f1ec17f12234e6c795e3855914316812cd4d (patch)
tree5ca3b77811732201add047199855f0d56025cc47 /tmk_core
parentf519a9908ee2bd1b34a92db22edd54f05c509617 (diff)
Adafruit BLE cleanups (#11556)
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.cpp45
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.h11
-rw-r--r--tmk_core/protocol/lufa/lufa.c2
3 files changed, 26 insertions, 32 deletions
diff --git a/tmk_core/protocol/lufa/adafruit_ble.cpp b/tmk_core/protocol/lufa/adafruit_ble.cpp
index 79b35fca31..3f2cc35734 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.cpp
+++ b/tmk_core/protocol/lufa/adafruit_ble.cpp
@@ -11,6 +11,7 @@
#include "spi_master.h"
#include "wait.h"
#include "analog.h"
+#include "progmem.h"
// These are the pin assignments for the 32u4 boards.
// You may define them to something else in your config.h
@@ -36,10 +37,8 @@
#define SAMPLE_BATTERY
#define ConnectionUpdateInterval 1000 /* milliseconds */
-#ifdef SAMPLE_BATTERY
-# ifndef BATTERY_LEVEL_PIN
-# define BATTERY_LEVEL_PIN B5
-# endif
+#ifndef BATTERY_LEVEL_PIN
+# define BATTERY_LEVEL_PIN B5
#endif
static struct {
@@ -118,15 +117,15 @@ enum sdep_type {
SdepResponse = 0x20,
SdepAlert = 0x40,
SdepError = 0x80,
- SdepSlaveNotReady = 0xfe, // Try again later
- SdepSlaveOverflow = 0xff, // You read more data than is available
+ SdepSlaveNotReady = 0xFE, // Try again later
+ SdepSlaveOverflow = 0xFF, // You read more data than is available
};
enum ble_cmd {
- BleInitialize = 0xbeef,
- BleAtWrapper = 0x0a00,
- BleUartTx = 0x0a01,
- BleUartRx = 0x0a02,
+ BleInitialize = 0xBEEF,
+ BleAtWrapper = 0x0A00,
+ BleUartTx = 0x0A01,
+ BleUartRx = 0x0A02,
};
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) {
msg->type = SdepCommand;
- msg->cmd_low = command & 0xff;
+ msg->cmd_low = command & 0xFF;
msg->cmd_high = command >> 8;
msg->len = len;
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) {
- auto now = timer_read();
+ uint16_t now = timer_read();
while (!resp_buf.enqueue(now)) {
resp_buf_read_one(false);
}
- auto later = timer_read();
+ uint16_t later = timer_read();
if (TIMER_DIFF_16(later, now) > 0) {
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) {
- auto cmdbuf = (char *)alloca(strlen_P(cmd) + 1);
+ char *cmdbuf = (char *)alloca(strlen_P(cmd) + 1);
strcpy_P(cmdbuf, cmd);
return at_command(cmdbuf, resp, resplen, verbose);
}
@@ -484,9 +483,9 @@ fail:
static void set_connected(bool connected) {
if (connected != state.is_connected) {
if (connected) {
- print("****** BLE CONNECT!!!!\n");
+ dprint("BLE connected\n");
} else {
- print("****** BLE DISCONNECT!!!!\n");
+ dprint("BLE disconnected\n");
}
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;
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) {
- return true;
+ return;
}
nkeys -= 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;
item.queue_type = QTConsumer;
- item.consumer = keycode;
+ item.consumer = usage;
while (!send_buf.enqueue(item)) {
send_buf_send_one();
}
- return true;
}
#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;
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)) {
send_buf_send_one();
}
- return true;
}
#endif
diff --git a/tmk_core/protocol/lufa/adafruit_ble.h b/tmk_core/protocol/lufa/adafruit_ble.h
index 9dfc9b4355..b43e0771d9 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.h
+++ b/tmk_core/protocol/lufa/adafruit_ble.h
@@ -10,7 +10,6 @@
#include <string.h>
#include "config_common.h"
-#include "progmem.h"
#ifdef __cplusplus
extern "C" {
@@ -35,17 +34,17 @@ extern void adafruit_ble_task(void);
* this set of keys.
* Also sends a key release indicator, so that the keys do not remain
* 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) */
-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
/* 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. */
-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
/* Compute battery voltage by reading an analog pin.
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 8fd4be8af5..623aa33ff5 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -809,7 +809,7 @@ static void send_consumer(uint16_t data) {
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
# ifdef MODULE_ADAFRUIT_BLE
- adafruit_ble_send_consumer_key(data, 0);
+ adafruit_ble_send_consumer_key(data);
# elif MODULE_RN42
static uint16_t last_data = 0;
if (data == last_data) return;