diff options
| author | Ryan <fauxpark@gmail.com> | 2022-09-08 04:59:24 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-07 19:59:24 +0100 |
| commit | f7d2b001bc4f79164e9ea3a4ff7faa54be0b7d82 (patch) | |
| tree | 304a51de5cb8a64958645812941b0ebfe65223d9 | |
| parent | cf8cdd19920b1810f3d3ecc987943ad8d59023b4 (diff) | |
Move Bluetooth-related function calls up to host/keyboard level (#18274)
* Move Bluetooth-related function calls up to host/keyboard level
* Remove pointless set_output() call
* Move bluetooth (rn42) init to end of keyboard_init()
* Enable SPI/UART for ChibiOS targets
* Some more slight tweaks
| -rw-r--r-- | builddefs/common_features.mk | 6 | ||||
| -rw-r--r-- | drivers/bluetooth/bluefruit_le.cpp | 8 | ||||
| -rw-r--r-- | drivers/bluetooth/bluefruit_le.h | 2 | ||||
| -rw-r--r-- | quantum/keyboard.c | 15 | ||||
| -rw-r--r-- | tmk_core/protocol/host.c | 43 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 51 |
6 files changed, 61 insertions, 64 deletions
diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index 9fa9e18814..f9618709c9 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk | |||
| @@ -882,14 +882,14 @@ ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) | |||
| 882 | SRC += outputselect.c | 882 | SRC += outputselect.c |
| 883 | 883 | ||
| 884 | ifeq ($(strip $(BLUETOOTH_DRIVER)), BluefruitLE) | 884 | ifeq ($(strip $(BLUETOOTH_DRIVER)), BluefruitLE) |
| 885 | OPT_DEFS += -DBLUETOOTH_BLUEFRUIT_LE | 885 | OPT_DEFS += -DBLUETOOTH_BLUEFRUIT_LE -DHAL_USE_SPI=TRUE |
| 886 | SRC += analog.c | ||
| 887 | SRC += $(DRIVER_PATH)/bluetooth/bluefruit_le.cpp | 886 | SRC += $(DRIVER_PATH)/bluetooth/bluefruit_le.cpp |
| 887 | QUANTUM_LIB_SRC += analog.c | ||
| 888 | QUANTUM_LIB_SRC += spi_master.c | 888 | QUANTUM_LIB_SRC += spi_master.c |
| 889 | endif | 889 | endif |
| 890 | 890 | ||
| 891 | ifeq ($(strip $(BLUETOOTH_DRIVER)), RN42) | 891 | ifeq ($(strip $(BLUETOOTH_DRIVER)), RN42) |
| 892 | OPT_DEFS += -DBLUETOOTH_RN42 | 892 | OPT_DEFS += -DBLUETOOTH_RN42 -DHAL_USE_SERIAL=TRUE |
| 893 | SRC += $(DRIVER_PATH)/bluetooth/rn42.c | 893 | SRC += $(DRIVER_PATH)/bluetooth/rn42.c |
| 894 | QUANTUM_LIB_SRC += uart.c | 894 | QUANTUM_LIB_SRC += uart.c |
| 895 | endif | 895 | endif |
diff --git a/drivers/bluetooth/bluefruit_le.cpp b/drivers/bluetooth/bluefruit_le.cpp index 19310767cf..50170b83fe 100644 --- a/drivers/bluetooth/bluefruit_le.cpp +++ b/drivers/bluetooth/bluefruit_le.cpp | |||
| @@ -79,9 +79,7 @@ struct sdep_msg { | |||
| 79 | enum queue_type { | 79 | enum queue_type { |
| 80 | QTKeyReport, // 1-byte modifier + 6-byte key report | 80 | QTKeyReport, // 1-byte modifier + 6-byte key report |
| 81 | QTConsumer, // 16-bit key code | 81 | QTConsumer, // 16-bit key code |
| 82 | #ifdef MOUSE_ENABLE | ||
| 83 | QTMouseMove, // 4-byte mouse report | 82 | QTMouseMove, // 4-byte mouse report |
| 84 | #endif | ||
| 85 | }; | 83 | }; |
| 86 | 84 | ||
| 87 | struct queue_item { | 85 | struct queue_item { |
| @@ -442,7 +440,7 @@ bool bluefruit_le_enable_keyboard(void) { | |||
| 442 | // Disable command echo | 440 | // Disable command echo |
| 443 | static const char kEcho[] PROGMEM = "ATE=0"; | 441 | static const char kEcho[] PROGMEM = "ATE=0"; |
| 444 | // Make the advertised name match the keyboard | 442 | // Make the advertised name match the keyboard |
| 445 | static const char kGapDevName[] PROGMEM = "AT+GAPDEVNAME=" STR(PRODUCT); | 443 | static const char kGapDevName[] PROGMEM = "AT+GAPDEVNAME=" PRODUCT; |
| 446 | // Turn on keyboard support | 444 | // Turn on keyboard support |
| 447 | static const char kHidEnOn[] PROGMEM = "AT+BLEHIDEN=1"; | 445 | static const char kHidEnOn[] PROGMEM = "AT+BLEHIDEN=1"; |
| 448 | 446 | ||
| @@ -581,10 +579,12 @@ static bool process_queue_item(struct queue_item *item, uint16_t timeout) { | |||
| 581 | snprintf(cmdbuf, sizeof(cmdbuf), fmtbuf, item->key.modifier, item->key.keys[0], item->key.keys[1], item->key.keys[2], item->key.keys[3], item->key.keys[4], item->key.keys[5]); | 579 | snprintf(cmdbuf, sizeof(cmdbuf), fmtbuf, item->key.modifier, item->key.keys[0], item->key.keys[1], item->key.keys[2], item->key.keys[3], item->key.keys[4], item->key.keys[5]); |
| 582 | return at_command(cmdbuf, NULL, 0, true, timeout); | 580 | return at_command(cmdbuf, NULL, 0, true, timeout); |
| 583 | 581 | ||
| 582 | #ifdef EXTRAKEY_ENABLE | ||
| 584 | case QTConsumer: | 583 | case QTConsumer: |
| 585 | strcpy_P(fmtbuf, PSTR("AT+BLEHIDCONTROLKEY=0x%04x")); | 584 | strcpy_P(fmtbuf, PSTR("AT+BLEHIDCONTROLKEY=0x%04x")); |
| 586 | snprintf(cmdbuf, sizeof(cmdbuf), fmtbuf, item->consumer); | 585 | snprintf(cmdbuf, sizeof(cmdbuf), fmtbuf, item->consumer); |
| 587 | return at_command(cmdbuf, NULL, 0, true, timeout); | 586 | return at_command(cmdbuf, NULL, 0, true, timeout); |
| 587 | #endif | ||
| 588 | 588 | ||
| 589 | #ifdef MOUSE_ENABLE | 589 | #ifdef MOUSE_ENABLE |
| 590 | case QTMouseMove: | 590 | case QTMouseMove: |
| @@ -658,7 +658,6 @@ void bluefruit_le_send_consumer_key(uint16_t usage) { | |||
| 658 | } | 658 | } |
| 659 | } | 659 | } |
| 660 | 660 | ||
| 661 | #ifdef MOUSE_ENABLE | ||
| 662 | void bluefruit_le_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons) { | 661 | void bluefruit_le_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons) { |
| 663 | struct queue_item item; | 662 | struct queue_item item; |
| 664 | 663 | ||
| @@ -673,7 +672,6 @@ void bluefruit_le_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, | |||
| 673 | send_buf_send_one(); | 672 | send_buf_send_one(); |
| 674 | } | 673 | } |
| 675 | } | 674 | } |
| 676 | #endif | ||
| 677 | 675 | ||
| 678 | uint32_t bluefruit_le_read_battery_voltage(void) { | 676 | uint32_t bluefruit_le_read_battery_voltage(void) { |
| 679 | return state.vbat; | 677 | return state.vbat; |
diff --git a/drivers/bluetooth/bluefruit_le.h b/drivers/bluetooth/bluefruit_le.h index de301c6167..731ba2e370 100644 --- a/drivers/bluetooth/bluefruit_le.h +++ b/drivers/bluetooth/bluefruit_le.h | |||
| @@ -40,12 +40,10 @@ extern void bluefruit_le_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uin | |||
| 40 | * (milliseconds) */ | 40 | * (milliseconds) */ |
| 41 | extern void bluefruit_le_send_consumer_key(uint16_t usage); | 41 | extern void bluefruit_le_send_consumer_key(uint16_t usage); |
| 42 | 42 | ||
| 43 | #ifdef MOUSE_ENABLE | ||
| 44 | /* Send a mouse/wheel movement report. | 43 | /* Send a mouse/wheel movement report. |
| 45 | * The parameters are signed and indicate positive or negative direction | 44 | * The parameters are signed and indicate positive or negative direction |
| 46 | * change. */ | 45 | * change. */ |
| 47 | extern void bluefruit_le_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons); | 46 | extern void bluefruit_le_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons); |
| 48 | #endif | ||
| 49 | 47 | ||
| 50 | /* Compute battery voltage by reading an analog pin. | 48 | /* Compute battery voltage by reading an analog pin. |
| 51 | * Returns the integer number of millivolts */ | 49 | * Returns the integer number of millivolts */ |
diff --git a/quantum/keyboard.c b/quantum/keyboard.c index 1c62a43d9d..3b5e9b0200 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c | |||
| @@ -107,6 +107,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 107 | #endif | 107 | #endif |
| 108 | #ifdef BLUETOOTH_ENABLE | 108 | #ifdef BLUETOOTH_ENABLE |
| 109 | # include "outputselect.h" | 109 | # include "outputselect.h" |
| 110 | # ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 111 | # include "bluefruit_le.h" | ||
| 112 | # elif BLUETOOTH_RN42 | ||
| 113 | # include "rn42.h" | ||
| 114 | # endif | ||
| 110 | #endif | 115 | #endif |
| 111 | #ifdef CAPS_WORD_ENABLE | 116 | #ifdef CAPS_WORD_ENABLE |
| 112 | # include "caps_word.h" | 117 | # include "caps_word.h" |
| @@ -346,9 +351,6 @@ void quantum_init(void) { | |||
| 346 | #ifdef HAPTIC_ENABLE | 351 | #ifdef HAPTIC_ENABLE |
| 347 | haptic_init(); | 352 | haptic_init(); |
| 348 | #endif | 353 | #endif |
| 349 | #if defined(BLUETOOTH_ENABLE) && defined(OUTPUT_AUTO_ENABLE) | ||
| 350 | set_output(OUTPUT_AUTO); | ||
| 351 | #endif | ||
| 352 | } | 354 | } |
| 353 | 355 | ||
| 354 | /** \brief keyboard_init | 356 | /** \brief keyboard_init |
| @@ -410,6 +412,9 @@ void keyboard_init(void) { | |||
| 410 | // init after split init | 412 | // init after split init |
| 411 | pointing_device_init(); | 413 | pointing_device_init(); |
| 412 | #endif | 414 | #endif |
| 415 | #if defined(BLUETOOTH_RN42) | ||
| 416 | rn42_init(); | ||
| 417 | #endif | ||
| 413 | 418 | ||
| 414 | #if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE) | 419 | #if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE) |
| 415 | debug_enable = true; | 420 | debug_enable = true; |
| @@ -670,5 +675,9 @@ void keyboard_task(void) { | |||
| 670 | programmable_button_send(); | 675 | programmable_button_send(); |
| 671 | #endif | 676 | #endif |
| 672 | 677 | ||
| 678 | #ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 679 | bluefruit_le_task(); | ||
| 680 | #endif | ||
| 681 | |||
| 673 | led_task(); | 682 | led_task(); |
| 674 | } | 683 | } |
diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c index 2ebd176ea4..53854b94fb 100644 --- a/tmk_core/protocol/host.c +++ b/tmk_core/protocol/host.c | |||
| @@ -24,6 +24,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 24 | #include "debug.h" | 24 | #include "debug.h" |
| 25 | #include "digitizer.h" | 25 | #include "digitizer.h" |
| 26 | 26 | ||
| 27 | #ifdef BLUETOOTH_ENABLE | ||
| 28 | # include "outputselect.h" | ||
| 29 | # ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 30 | # include "bluefruit_le.h" | ||
| 31 | # elif BLUETOOTH_RN42 | ||
| 32 | # include "rn42.h" | ||
| 33 | # endif | ||
| 34 | #endif | ||
| 35 | |||
| 27 | #ifdef NKRO_ENABLE | 36 | #ifdef NKRO_ENABLE |
| 28 | # include "keycode_config.h" | 37 | # include "keycode_config.h" |
| 29 | extern keymap_config_t keymap_config; | 38 | extern keymap_config_t keymap_config; |
| @@ -63,6 +72,17 @@ led_t host_keyboard_led_state(void) { | |||
| 63 | 72 | ||
| 64 | /* send report */ | 73 | /* send report */ |
| 65 | void host_keyboard_send(report_keyboard_t *report) { | 74 | void host_keyboard_send(report_keyboard_t *report) { |
| 75 | #ifdef BLUETOOTH_ENABLE | ||
| 76 | if (where_to_send() == OUTPUT_BLUETOOTH) { | ||
| 77 | # ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 78 | bluefruit_le_send_keys(report->mods, report->keys, sizeof(report->keys)); | ||
| 79 | # elif BLUETOOTH_RN42 | ||
| 80 | rn42_send_keyboard(report); | ||
| 81 | # endif | ||
| 82 | return; | ||
| 83 | } | ||
| 84 | #endif | ||
| 85 | |||
| 66 | if (!driver) return; | 86 | if (!driver) return; |
| 67 | #if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP) | 87 | #if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP) |
| 68 | if (keyboard_protocol && keymap_config.nkro) { | 88 | if (keyboard_protocol && keymap_config.nkro) { |
| @@ -90,6 +110,18 @@ void host_keyboard_send(report_keyboard_t *report) { | |||
| 90 | } | 110 | } |
| 91 | 111 | ||
| 92 | void host_mouse_send(report_mouse_t *report) { | 112 | void host_mouse_send(report_mouse_t *report) { |
| 113 | #ifdef BLUETOOTH_ENABLE | ||
| 114 | if (where_to_send() == OUTPUT_BLUETOOTH) { | ||
| 115 | # ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 116 | // FIXME: mouse buttons | ||
| 117 | bluefruit_le_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons); | ||
| 118 | # elif BLUETOOTH_RN42 | ||
| 119 | rn42_send_mouse(report); | ||
| 120 | # endif | ||
| 121 | return; | ||
| 122 | } | ||
| 123 | #endif | ||
| 124 | |||
| 93 | if (!driver) return; | 125 | if (!driver) return; |
| 94 | #ifdef MOUSE_SHARED_EP | 126 | #ifdef MOUSE_SHARED_EP |
| 95 | report->report_id = REPORT_ID_MOUSE; | 127 | report->report_id = REPORT_ID_MOUSE; |
| @@ -114,6 +146,17 @@ void host_consumer_send(uint16_t report) { | |||
| 114 | if (report == last_consumer_report) return; | 146 | if (report == last_consumer_report) return; |
| 115 | last_consumer_report = report; | 147 | last_consumer_report = report; |
| 116 | 148 | ||
| 149 | #ifdef BLUETOOTH_ENABLE | ||
| 150 | if (where_to_send() == OUTPUT_BLUETOOTH) { | ||
| 151 | # ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 152 | bluefruit_le_send_consumer_key(report); | ||
| 153 | # elif BLUETOOTH_RN42 | ||
| 154 | rn42_send_consumer(report); | ||
| 155 | # endif | ||
| 156 | return; | ||
| 157 | } | ||
| 158 | #endif | ||
| 159 | |||
| 117 | if (!driver) return; | 160 | if (!driver) return; |
| 118 | (*driver->send_extra)(REPORT_ID_CONSUMER, report); | 161 | (*driver->send_extra)(REPORT_ID_CONSUMER, report); |
| 119 | } | 162 | } |
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 03e19745f8..2a3f5fd883 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
| @@ -65,15 +65,6 @@ extern keymap_config_t keymap_config; | |||
| 65 | # include "audio.h" | 65 | # include "audio.h" |
| 66 | #endif | 66 | #endif |
| 67 | 67 | ||
| 68 | #ifdef BLUETOOTH_ENABLE | ||
| 69 | # include "outputselect.h" | ||
| 70 | # ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 71 | # include "bluefruit_le.h" | ||
| 72 | # elif BLUETOOTH_RN42 | ||
| 73 | # include "rn42.h" | ||
| 74 | # endif | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #ifdef VIRTSER_ENABLE | 68 | #ifdef VIRTSER_ENABLE |
| 78 | # include "virtser.h" | 69 | # include "virtser.h" |
| 79 | #endif | 70 | #endif |
| @@ -648,17 +639,6 @@ static uint8_t keyboard_leds(void) { | |||
| 648 | static void send_keyboard(report_keyboard_t *report) { | 639 | static void send_keyboard(report_keyboard_t *report) { |
| 649 | uint8_t timeout = 255; | 640 | uint8_t timeout = 255; |
| 650 | 641 | ||
| 651 | #ifdef BLUETOOTH_ENABLE | ||
| 652 | if (where_to_send() == OUTPUT_BLUETOOTH) { | ||
| 653 | # ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 654 | bluefruit_le_send_keys(report->mods, report->keys, sizeof(report->keys)); | ||
| 655 | # elif BLUETOOTH_RN42 | ||
| 656 | rn42_send_keyboard(report); | ||
| 657 | # endif | ||
| 658 | return; | ||
| 659 | } | ||
| 660 | #endif | ||
| 661 | |||
| 662 | /* Select the Keyboard Report Endpoint */ | 642 | /* Select the Keyboard Report Endpoint */ |
| 663 | uint8_t ep = KEYBOARD_IN_EPNUM; | 643 | uint8_t ep = KEYBOARD_IN_EPNUM; |
| 664 | uint8_t size = KEYBOARD_REPORT_SIZE; | 644 | uint8_t size = KEYBOARD_REPORT_SIZE; |
| @@ -695,18 +675,6 @@ static void send_mouse(report_mouse_t *report) { | |||
| 695 | #ifdef MOUSE_ENABLE | 675 | #ifdef MOUSE_ENABLE |
| 696 | uint8_t timeout = 255; | 676 | uint8_t timeout = 255; |
| 697 | 677 | ||
| 698 | # ifdef BLUETOOTH_ENABLE | ||
| 699 | if (where_to_send() == OUTPUT_BLUETOOTH) { | ||
| 700 | # ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 701 | // FIXME: mouse buttons | ||
| 702 | bluefruit_le_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons); | ||
| 703 | # elif BLUETOOTH_RN42 | ||
| 704 | rn42_send_mouse(report); | ||
| 705 | # endif | ||
| 706 | return; | ||
| 707 | } | ||
| 708 | # endif | ||
| 709 | |||
| 710 | /* Select the Mouse Report Endpoint */ | 678 | /* Select the Mouse Report Endpoint */ |
| 711 | Endpoint_SelectEndpoint(MOUSE_IN_EPNUM); | 679 | Endpoint_SelectEndpoint(MOUSE_IN_EPNUM); |
| 712 | 680 | ||
| @@ -747,17 +715,6 @@ static void send_report(void *report, size_t size) { | |||
| 747 | */ | 715 | */ |
| 748 | static void send_extra(uint8_t report_id, uint16_t data) { | 716 | static void send_extra(uint8_t report_id, uint16_t data) { |
| 749 | #ifdef EXTRAKEY_ENABLE | 717 | #ifdef EXTRAKEY_ENABLE |
| 750 | # ifdef BLUETOOTH_ENABLE | ||
| 751 | if (report_id == REPORT_ID_CONSUMER && where_to_send() == OUTPUT_BLUETOOTH) { | ||
| 752 | # ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 753 | bluefruit_le_send_consumer_key(data); | ||
| 754 | # elif BLUETOOTH_RN42 | ||
| 755 | rn42_send_consumer(data); | ||
| 756 | # endif | ||
| 757 | return; | ||
| 758 | } | ||
| 759 | # endif | ||
| 760 | |||
| 761 | static report_extra_t r; | 718 | static report_extra_t r; |
| 762 | r = (report_extra_t){.report_id = report_id, .usage = data}; | 719 | r = (report_extra_t){.report_id = report_id, .usage = data}; |
| 763 | send_report(&r, sizeof(r)); | 720 | send_report(&r, sizeof(r)); |
| @@ -1007,10 +964,6 @@ void protocol_pre_init(void) { | |||
| 1007 | setup_usb(); | 964 | setup_usb(); |
| 1008 | sei(); | 965 | sei(); |
| 1009 | 966 | ||
| 1010 | #if defined(BLUETOOTH_RN42) | ||
| 1011 | rn42_init(); | ||
| 1012 | #endif | ||
| 1013 | |||
| 1014 | /* wait for USB startup & debug output */ | 967 | /* wait for USB startup & debug output */ |
| 1015 | 968 | ||
| 1016 | #ifdef WAIT_FOR_USB | 969 | #ifdef WAIT_FOR_USB |
| @@ -1062,10 +1015,6 @@ void protocol_post_task(void) { | |||
| 1062 | MIDI_Device_USBTask(&USB_MIDI_Interface); | 1015 | MIDI_Device_USBTask(&USB_MIDI_Interface); |
| 1063 | #endif | 1016 | #endif |
| 1064 | 1017 | ||
| 1065 | #ifdef BLUETOOTH_BLUEFRUIT_LE | ||
| 1066 | bluefruit_le_task(); | ||
| 1067 | #endif | ||
| 1068 | |||
| 1069 | #ifdef VIRTSER_ENABLE | 1018 | #ifdef VIRTSER_ENABLE |
| 1070 | virtser_task(); | 1019 | virtser_task(); |
| 1071 | CDC_Device_USBTask(&cdc_device); | 1020 | CDC_Device_USBTask(&cdc_device); |
