aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis La Marr <exiva@exiva.net>2017-03-24 12:53:55 -0400
committerTravis La Marr <exiva@exiva.net>2017-03-24 12:53:55 -0400
commitddc036b69ea508750f5129d9a43fee484148716a (patch)
tree24cb80061dfa59b0fe81a73bd987c228571aad80
parent7a9437a2e3a2597e8eef1ea293bfb3c394f588b9 (diff)
downloadqmk_firmware-ddc036b69ea508750f5129d9a43fee484148716a.tar.gz
qmk_firmware-ddc036b69ea508750f5129d9a43fee484148716a.zip
Refactor Bluetooth Handling
Refactored Bluetooth support to make adding new Bluetooth modules easier in the future. * Remove `OUT_BLE` key from QMK's keymap. `OUT_BT` is all we need now as there's no difference anymore. * Made BLUETOOTH_ENABLE build option legacy as not to break existing keymaps (Falls back to existing EZ Key support if on) * Removed `ADAFRUIT_BLE_ENABLE` build option * Created new build option `BLUETOOTH` with module option (Currently `AdafruitEZKey` & `AdafruitBLE`) * Moved all LUFA bluetooth key/mouse events under `BLUETOOTH_ENABLE` ifdef with selected modules output.
-rw-r--r--quantum/quantum.c8
-rw-r--r--quantum/quantum_keycodes.h3
-rw-r--r--tmk_core/common.mk12
-rw-r--r--tmk_core/protocol/lufa.mk12
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.h4
-rw-r--r--tmk_core/protocol/lufa/lufa.c77
-rw-r--r--tmk_core/protocol/lufa/outputselect.c6
-rw-r--r--tmk_core/protocol/lufa/outputselect.h1
8 files changed, 57 insertions, 66 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 582f8920b..807a7084a 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -294,14 +294,6 @@ bool process_record_quantum(keyrecord_t *record) {
294 return false; 294 return false;
295 break; 295 break;
296 #endif 296 #endif
297 #ifdef ADAFRUIT_BLE_ENABLE
298 case OUT_BLE:
299 if (record->event.pressed) {
300 set_output(OUTPUT_ADAFRUIT_BLE);
301 }
302 return false;
303 break;
304 #endif
305 #endif 297 #endif
306 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO: 298 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO:
307 if (record->event.pressed) { 299 if (record->event.pressed) {
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 903d57f1e..78b02a0de 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -159,9 +159,6 @@ enum quantum_keycodes {
159#ifdef BLUETOOTH_ENABLE 159#ifdef BLUETOOTH_ENABLE
160 OUT_BT, 160 OUT_BT,
161#endif 161#endif
162#ifdef ADAFRUIT_BLE_ENABLE
163 OUT_BLE,
164#endif
165 162
166 // always leave at the end 163 // always leave at the end
167 SAFE_RANGE 164 SAFE_RANGE
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index a86dccc61..2b0fda5f2 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -93,14 +93,18 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
93 TMK_COMMON_DEFS += -DBACKLIGHT_ENABLE 93 TMK_COMMON_DEFS += -DBACKLIGHT_ENABLE
94endif 94endif
95 95
96ifeq ($(strip $(ADAFRUIT_BLE_ENABLE)), yes)
97 TMK_COMMON_DEFS += -DADAFRUIT_BLE_ENABLE
98endif
99
100ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) 96ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)
101 TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE 97 TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE
102endif 98endif
103 99
100ifeq ($(strip $(BLUETOOTH)), AdafruitBLE)
101 TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE
102endif
103
104ifeq ($(strip $(BLUETOOTH)), AdafruitEZKey)
105 TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE
106endif
107
104ifeq ($(strip $(ONEHAND_ENABLE)), yes) 108ifeq ($(strip $(ONEHAND_ENABLE)), yes)
105 TMK_COMMON_DEFS += -DONEHAND_ENABLE 109 TMK_COMMON_DEFS += -DONEHAND_ENABLE
106endif 110endif
diff --git a/tmk_core/protocol/lufa.mk b/tmk_core/protocol/lufa.mk
index de0cc795f..5b1577972 100644
--- a/tmk_core/protocol/lufa.mk
+++ b/tmk_core/protocol/lufa.mk
@@ -22,11 +22,16 @@ ifeq ($(strip $(MIDI_ENABLE)), yes)
22 include $(TMK_PATH)/protocol/midi.mk 22 include $(TMK_PATH)/protocol/midi.mk
23endif 23endif
24 24
25ifeq ($(strip $(ADAFRUIT_BLE_ENABLE)), yes) 25ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)
26 LUFA_SRC += $(LUFA_DIR)/adafruit_ble.cpp 26 LUFA_SRC += $(LUFA_DIR)/bluetooth.c \
27 $(TMK_DIR)/protocol/serial_uart.c
27endif 28endif
28 29
29ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) 30ifeq ($(strip $(BLUETOOTH)), AdafruitBLE)
31 LUFA_SRC += $(LUFA_DIR)/adafruit_ble.cpp
32endif
33
34ifeq ($(strip $(BLUETOOTH)), AdafruitEZKey)
30 LUFA_SRC += $(LUFA_DIR)/bluetooth.c \ 35 LUFA_SRC += $(LUFA_DIR)/bluetooth.c \
31 $(TMK_DIR)/protocol/serial_uart.c 36 $(TMK_DIR)/protocol/serial_uart.c
32endif 37endif
@@ -54,6 +59,7 @@ LUFA_OPTS += -DUSE_FLASH_DESCRIPTORS
54LUFA_OPTS += -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" 59LUFA_OPTS += -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
55#LUFA_OPTS += -DINTERRUPT_CONTROL_ENDPOINT 60#LUFA_OPTS += -DINTERRUPT_CONTROL_ENDPOINT
56LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8 61LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8
62LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8
57LUFA_OPTS += -DFIXED_NUM_CONFIGURATIONS=1 63LUFA_OPTS += -DFIXED_NUM_CONFIGURATIONS=1
58 64
59# Remote wakeup fix for ATmega32U2 https://github.com/tmk/tmk_keyboard/issues/361 65# Remote wakeup fix for ATmega32U2 https://github.com/tmk/tmk_keyboard/issues/361
diff --git a/tmk_core/protocol/lufa/adafruit_ble.h b/tmk_core/protocol/lufa/adafruit_ble.h
index 351fd55ae..b3bab3ca0 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.h
+++ b/tmk_core/protocol/lufa/adafruit_ble.h
@@ -3,7 +3,7 @@
3 * Supports the Adafruit BLE board built around the nRF51822 chip. 3 * Supports the Adafruit BLE board built around the nRF51822 chip.
4 */ 4 */
5#pragma once 5#pragma once
6#ifdef ADAFRUIT_BLE_ENABLE 6#ifdef MODULE_ADAFRUIT_BLE
7#include <stdbool.h> 7#include <stdbool.h>
8#include <stdint.h> 8#include <stdint.h>
9#include <string.h> 9#include <string.h>
@@ -57,4 +57,4 @@ extern bool adafruit_ble_set_power_level(int8_t level);
57} 57}
58#endif 58#endif
59 59
60#endif // ADAFRUIT_BLE_ENABLE 60#endif // MODULE_ADAFRUIT_BLE
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index ba49284c9..d71748ce3 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -67,10 +67,11 @@
67#endif 67#endif
68 68
69#ifdef BLUETOOTH_ENABLE 69#ifdef BLUETOOTH_ENABLE
70 #include "bluetooth.h" 70 #ifdef MODULE_ADAFRUIT_BLE
71#endif
72#ifdef ADAFRUIT_BLE_ENABLE
73 #include "adafruit_ble.h" 71 #include "adafruit_ble.h"
72 #else
73 #include "bluetooth.h"
74 #endif
74#endif 75#endif
75 76
76#ifdef VIRTSER_ENABLE 77#ifdef VIRTSER_ENABLE
@@ -602,18 +603,14 @@ static void send_keyboard(report_keyboard_t *report)
602 uint8_t where = where_to_send(); 603 uint8_t where = where_to_send();
603 604
604#ifdef BLUETOOTH_ENABLE 605#ifdef BLUETOOTH_ENABLE
605 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { 606 #ifdef MODULE_ADAFRUIT_BLE
606 bluefruit_serial_send(0xFD); 607 adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys));
607 for (uint8_t i = 0; i < KEYBOARD_EPSIZE; i++) { 608 #else
608 bluefruit_serial_send(report->raw[i]); 609 bluefruit_serial_send(0xFD);
609 } 610 for (uint8_t i = 0; i < KEYBOARD_EPSIZE; i++) {
610 } 611 bluefruit_serial_send(report->raw[i]);
611#endif
612
613#ifdef ADAFRUIT_BLE_ENABLE
614 if (where == OUTPUT_ADAFRUIT_BLE) {
615 adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys));
616 } 612 }
613 #endif
617#endif 614#endif
618 615
619 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { 616 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
@@ -660,24 +657,22 @@ static void send_mouse(report_mouse_t *report)
660 uint8_t where = where_to_send(); 657 uint8_t where = where_to_send();
661 658
662#ifdef BLUETOOTH_ENABLE 659#ifdef BLUETOOTH_ENABLE
663 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { 660 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
664 bluefruit_serial_send(0xFD); 661 #ifdef MODULE_ADAFRUIT_BLE
665 bluefruit_serial_send(0x00);
666 bluefruit_serial_send(0x03);
667 bluefruit_serial_send(report->buttons);
668 bluefruit_serial_send(report->x);
669 bluefruit_serial_send(report->y);
670 bluefruit_serial_send(report->v); // should try sending the wheel v here
671 bluefruit_serial_send(report->h); // should try sending the wheel h here
672 bluefruit_serial_send(0x00);
673 }
674#endif
675
676#ifdef ADAFRUIT_BLE_ENABLE
677 if (where == OUTPUT_ADAFRUIT_BLE) {
678 // FIXME: mouse buttons 662 // FIXME: mouse buttons
679 adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h); 663 adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h);
680 } 664 #else
665 bluefruit_serial_send(0xFD);
666 bluefruit_serial_send(0x00);
667 bluefruit_serial_send(0x03);
668 bluefruit_serial_send(report->buttons);
669 bluefruit_serial_send(report->x);
670 bluefruit_serial_send(report->y);
671 bluefruit_serial_send(report->v); // should try sending the wheel v here
672 bluefruit_serial_send(report->h); // should try sending the wheel h here
673 bluefruit_serial_send(0x00);
674 #endif
675 }
681#endif 676#endif
682 677
683 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { 678 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
@@ -727,6 +722,9 @@ static void send_consumer(uint16_t data)
727 722
728#ifdef BLUETOOTH_ENABLE 723#ifdef BLUETOOTH_ENABLE
729 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { 724 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
725 #ifdef MODULE_ADAFRUIT_BLE
726 adafruit_ble_send_consumer_key(data, 0);
727 #else
730 static uint16_t last_data = 0; 728 static uint16_t last_data = 0;
731 if (data == last_data) return; 729 if (data == last_data) return;
732 last_data = data; 730 last_data = data;
@@ -740,12 +738,7 @@ static void send_consumer(uint16_t data)
740 bluefruit_serial_send(0x00); 738 bluefruit_serial_send(0x00);
741 bluefruit_serial_send(0x00); 739 bluefruit_serial_send(0x00);
742 bluefruit_serial_send(0x00); 740 bluefruit_serial_send(0x00);
743 } 741 #endif
744#endif
745
746#ifdef ADAFRUIT_BLE_ENABLE
747 if (where == OUTPUT_ADAFRUIT_BLE) {
748 adafruit_ble_send_consumer_key(data, 0);
749 } 742 }
750#endif 743#endif
751 744
@@ -1130,10 +1123,6 @@ int main(void)
1130 // midi_send_noteoff(&midi_device, 0, 64, 127); 1123 // midi_send_noteoff(&midi_device, 0, 64, 127);
1131#endif 1124#endif
1132 1125
1133#ifdef BLUETOOTH_ENABLE
1134 serial_init();
1135#endif
1136
1137 /* wait for USB startup & debug output */ 1126 /* wait for USB startup & debug output */
1138 1127
1139#ifdef WAIT_FOR_USB 1128#ifdef WAIT_FOR_USB
@@ -1161,7 +1150,7 @@ int main(void)
1161 1150
1162 print("Keyboard start.\n"); 1151 print("Keyboard start.\n");
1163 while (1) { 1152 while (1) {
1164 #if !defined(BLUETOOTH_ENABLE) && !defined(ADAFRUIT_BLE_ENABLE) 1153 #if !defined(BLUETOOTH_ENABLE)
1165 while (USB_DeviceState == DEVICE_STATE_Suspended) { 1154 while (USB_DeviceState == DEVICE_STATE_Suspended) {
1166 print("[s]"); 1155 print("[s]");
1167 suspend_power_down(); 1156 suspend_power_down();
@@ -1182,7 +1171,11 @@ int main(void)
1182 rgblight_task(); 1171 rgblight_task();
1183#endif 1172#endif
1184 1173
1185#ifdef ADAFRUIT_BLE_ENABLE 1174#ifdef MODULE_ADAFRUIT_EZKEY
1175 serial_init();
1176#endif
1177
1178#ifdef MODULE_ADAFRUIT_BLE
1186 adafruit_ble_task(); 1179 adafruit_ble_task();
1187#endif 1180#endif
1188 1181
diff --git a/tmk_core/protocol/lufa/outputselect.c b/tmk_core/protocol/lufa/outputselect.c
index 5d2457bff..0df5d3b75 100644
--- a/tmk_core/protocol/lufa/outputselect.c
+++ b/tmk_core/protocol/lufa/outputselect.c
@@ -14,7 +14,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
14 14
15#include "lufa.h" 15#include "lufa.h"
16#include "outputselect.h" 16#include "outputselect.h"
17#ifdef ADAFRUIT_BLE_ENABLE 17#ifdef MODULE_ADAFRUIT_BLE
18 #include "adafruit_ble.h" 18 #include "adafruit_ble.h"
19#endif 19#endif
20 20
@@ -34,9 +34,9 @@ uint8_t auto_detect_output(void) {
34 return OUTPUT_USB; 34 return OUTPUT_USB;
35 } 35 }
36 36
37#ifdef ADAFRUIT_BLE_ENABLE 37#ifdef MODULE_ADAFRUIT_BLE
38 if (adafruit_ble_is_connected()) { 38 if (adafruit_ble_is_connected()) {
39 return OUTPUT_ADAFRUIT_BLE; 39 return OUTPUT_BLUETOOTH;
40 } 40 }
41#endif 41#endif
42 42
diff --git a/tmk_core/protocol/lufa/outputselect.h b/tmk_core/protocol/lufa/outputselect.h
index 79b4dd35d..28cc3298e 100644
--- a/tmk_core/protocol/lufa/outputselect.h
+++ b/tmk_core/protocol/lufa/outputselect.h
@@ -18,7 +18,6 @@ enum outputs {
18 OUTPUT_NONE, 18 OUTPUT_NONE,
19 OUTPUT_USB, 19 OUTPUT_USB,
20 OUTPUT_BLUETOOTH, 20 OUTPUT_BLUETOOTH,
21 OUTPUT_ADAFRUIT_BLE,
22 21
23 // backward compatibility 22 // backward compatibility
24 OUTPUT_USB_AND_BT 23 OUTPUT_USB_AND_BT