keyboard stuff
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Bind Bluetooth driver to `host_driver_t` (#25199)

authored by

Joel Challis and committed by
GitHub
842c8401 614b631e

+174 -93
+3 -2
builddefs/common_features.mk
··· 898 898 NO_USB_STARTUP_CHECK := yes 899 899 CONNECTION_ENABLE := yes 900 900 COMMON_VPATH += $(DRIVER_PATH)/bluetooth 901 + SRC += $(DRIVER_PATH)/bluetooth/bluetooth.c 901 902 902 903 ifeq ($(strip $(BLUETOOTH_DRIVER)), bluefruit_le) 903 904 SPI_DRIVER_REQUIRED = yes 904 - SRC += $(DRIVER_PATH)/bluetooth/bluetooth.c 905 + SRC += $(DRIVER_PATH)/bluetooth/bluetooth_drivers.c 905 906 SRC += $(DRIVER_PATH)/bluetooth/bluefruit_le.cpp 906 907 endif 907 908 908 909 ifeq ($(strip $(BLUETOOTH_DRIVER)), rn42) 909 910 UART_DRIVER_REQUIRED = yes 910 - SRC += $(DRIVER_PATH)/bluetooth/bluetooth.c 911 + SRC += $(DRIVER_PATH)/bluetooth/bluetooth_drivers.c 911 912 SRC += $(DRIVER_PATH)/bluetooth/rn42.c 912 913 endif 913 914 endif
+16 -52
drivers/bluetooth/bluetooth.c
··· 1 - /* 2 - * Copyright 2022 3 - * 4 - * This program is free software: you can redistribute it and/or modify 5 - * it under the terms of the GNU General Public License as published by 6 - * the Free Software Foundation, either version 2 of the License, or 7 - * (at your option) any later version. 8 - * 9 - * This program is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 - * GNU General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU General Public License 15 - * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 - */ 1 + // Copyright 2025 QMK 2 + // SPDX-License-Identifier: GPL-2.0-or-later 17 3 18 4 #include "bluetooth.h" 19 5 20 - #if defined(BLUETOOTH_BLUEFRUIT_LE) 21 - # include "bluefruit_le.h" 22 - #elif defined(BLUETOOTH_RN42) 23 - # include "rn42.h" 24 - #endif 6 + __attribute__((weak)) void bluetooth_init(void) {} 25 7 26 - void bluetooth_init(void) { 27 - #if defined(BLUETOOTH_BLUEFRUIT_LE) 28 - bluefruit_le_init(); 29 - #elif defined(BLUETOOTH_RN42) 30 - rn42_init(); 31 - #endif 32 - } 8 + __attribute__((weak)) void bluetooth_task(void) {} 33 9 34 - void bluetooth_task(void) { 35 - #if defined(BLUETOOTH_BLUEFRUIT_LE) 36 - bluefruit_le_task(); 37 - #endif 10 + __attribute__((weak)) bool bluetooth_is_connected(void) { 11 + return true; 38 12 } 39 13 40 - void bluetooth_send_keyboard(report_keyboard_t *report) { 41 - #if defined(BLUETOOTH_BLUEFRUIT_LE) 42 - bluefruit_le_send_keyboard(report); 43 - #elif defined(BLUETOOTH_RN42) 44 - rn42_send_keyboard(report); 45 - #endif 14 + __attribute__((weak)) uint8_t bluetooth_keyboard_leds(void) { 15 + return 0; 46 16 } 47 17 48 - void bluetooth_send_mouse(report_mouse_t *report) { 49 - #if defined(BLUETOOTH_BLUEFRUIT_LE) 50 - bluefruit_le_send_mouse(report); 51 - #elif defined(BLUETOOTH_RN42) 52 - rn42_send_mouse(report); 53 - #endif 54 - } 18 + __attribute__((weak)) void bluetooth_send_keyboard(report_keyboard_t *report) {} 19 + 20 + __attribute__((weak)) void bluetooth_send_nkro(report_nkro_t *report) {} 21 + 22 + __attribute__((weak)) void bluetooth_send_mouse(report_mouse_t *report) {} 23 + 24 + __attribute__((weak)) void bluetooth_send_consumer(uint16_t usage) {} 55 25 56 - void bluetooth_send_consumer(uint16_t usage) { 57 - #if defined(BLUETOOTH_BLUEFRUIT_LE) 58 - bluefruit_le_send_consumer(usage); 59 - #elif defined(BLUETOOTH_RN42) 60 - rn42_send_consumer(usage); 61 - #endif 62 - } 26 + __attribute__((weak)) void bluetooth_send_system(uint16_t usage) {}
+26
drivers/bluetooth/bluetooth.h
··· 31 31 void bluetooth_task(void); 32 32 33 33 /** 34 + * \brief Detects if Bluetooth is connected. 35 + * 36 + * \return `true` if connected, `false` otherwise. 37 + */ 38 + bool bluetooth_is_connected(void); 39 + 40 + /** 41 + * \brief Get current LED state. 42 + */ 43 + uint8_t bluetooth_keyboard_leds(void); 44 + 45 + /** 34 46 * \brief Send a keyboard report. 35 47 * 36 48 * \param report The keyboard report to send. ··· 38 50 void bluetooth_send_keyboard(report_keyboard_t *report); 39 51 40 52 /** 53 + * \brief Send a nkro report. 54 + * 55 + * \param report The nkro report to send. 56 + */ 57 + void bluetooth_send_nkro(report_nkro_t *report); 58 + 59 + /** 41 60 * \brief Send a mouse report. 42 61 * 43 62 * \param report The mouse report to send. ··· 50 69 * \param usage The consumer usage to send. 51 70 */ 52 71 void bluetooth_send_consumer(uint16_t usage); 72 + 73 + /** 74 + * \brief Send a system usage. 75 + * 76 + * \param usage The system usage to send. 77 + */ 78 + void bluetooth_send_system(uint16_t usage);
+71
drivers/bluetooth/bluetooth_drivers.c
··· 1 + /* 2 + * Copyright 2022 3 + * 4 + * This program is free software: you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License as published by 6 + * the Free Software Foundation, either version 2 of the License, or 7 + * (at your option) any later version. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License 15 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 + */ 17 + 18 + #include "bluetooth.h" 19 + 20 + #if defined(BLUETOOTH_BLUEFRUIT_LE) 21 + # include "bluefruit_le.h" 22 + #elif defined(BLUETOOTH_RN42) 23 + # include "rn42.h" 24 + #endif 25 + 26 + void bluetooth_init(void) { 27 + #if defined(BLUETOOTH_BLUEFRUIT_LE) 28 + bluefruit_le_init(); 29 + #elif defined(BLUETOOTH_RN42) 30 + rn42_init(); 31 + #endif 32 + } 33 + 34 + void bluetooth_task(void) { 35 + #if defined(BLUETOOTH_BLUEFRUIT_LE) 36 + bluefruit_le_task(); 37 + #endif 38 + } 39 + 40 + bool bluetooth_is_connected(void) { 41 + #if defined(BLUETOOTH_BLUEFRUIT_LE) 42 + return bluefruit_le_is_connected(); 43 + #else 44 + // TODO: drivers should check if BT is connected here 45 + return true; 46 + #endif 47 + } 48 + 49 + void bluetooth_send_keyboard(report_keyboard_t *report) { 50 + #if defined(BLUETOOTH_BLUEFRUIT_LE) 51 + bluefruit_le_send_keyboard(report); 52 + #elif defined(BLUETOOTH_RN42) 53 + rn42_send_keyboard(report); 54 + #endif 55 + } 56 + 57 + void bluetooth_send_mouse(report_mouse_t *report) { 58 + #if defined(BLUETOOTH_BLUEFRUIT_LE) 59 + bluefruit_le_send_mouse(report); 60 + #elif defined(BLUETOOTH_RN42) 61 + rn42_send_mouse(report); 62 + #endif 63 + } 64 + 65 + void bluetooth_send_consumer(uint16_t usage) { 66 + #if defined(BLUETOOTH_BLUEFRUIT_LE) 67 + bluefruit_le_send_consumer(usage); 68 + #elif defined(BLUETOOTH_RN42) 69 + rn42_send_consumer(usage); 70 + #endif 71 + }
+4 -10
quantum/connection/connection.c
··· 5 5 #include "usb_util.h" 6 6 #include "util.h" 7 7 8 + #ifdef BLUETOOTH_ENABLE 9 + # include "bluetooth.h" 10 + #endif 11 + 8 12 // ======== DEPRECATED DEFINES - DO NOT USE ======== 9 13 #ifdef OUTPUT_DEFAULT 10 14 # undef CONNECTION_HOST_DEFAULT ··· 13 17 14 18 __attribute__((weak)) void set_output_user(uint8_t output) {} 15 19 // ======== 16 - 17 - #ifdef BLUETOOTH_ENABLE 18 - # ifdef BLUETOOTH_BLUEFRUIT_LE 19 - # include "bluefruit_le.h" 20 - # define bluetooth_is_connected() bluefruit_le_is_connected() 21 - # else 22 - // TODO: drivers should check if BT is connected here 23 - # define bluetooth_is_connected() true 24 - # endif 25 - #endif 26 20 27 21 #define CONNECTION_HOST_INVALID 0xFF 28 22
+54 -29
tmk_core/protocol/host.c
··· 30 30 # include "joystick.h" 31 31 #endif 32 32 33 + #ifdef CONNECTION_ENABLE 34 + # include "connection.h" 35 + #endif 36 + 33 37 #ifdef BLUETOOTH_ENABLE 34 - # ifndef CONNECTION_ENABLE 35 - # error CONNECTION_ENABLE required and not enabled 36 - # endif 37 - # include "connection.h" 38 38 # include "bluetooth.h" 39 + 40 + static void bluetooth_send_extra(report_extra_t *report) { 41 + switch (report->report_id) { 42 + case REPORT_ID_SYSTEM: 43 + bluetooth_send_system(report->usage); 44 + return; 45 + case REPORT_ID_CONSUMER: 46 + bluetooth_send_consumer(report->usage); 47 + return; 48 + } 49 + } 50 + 51 + host_driver_t bt_driver = { 52 + .keyboard_leds = bluetooth_keyboard_leds, 53 + .send_keyboard = bluetooth_send_keyboard, 54 + .send_nkro = bluetooth_send_nkro, 55 + .send_mouse = bluetooth_send_mouse, 56 + .send_extra = bluetooth_send_extra, 57 + }; 39 58 #endif 40 59 41 60 #ifdef NKRO_ENABLE ··· 55 74 return driver; 56 75 } 57 76 77 + static host_driver_t *host_get_active_driver(void) { 78 + #ifdef CONNECTION_ENABLE 79 + switch (connection_get_host()) { 80 + # ifdef BLUETOOTH_ENABLE 81 + case CONNECTION_HOST_BLUETOOTH: 82 + return &bt_driver; 83 + # endif 84 + case CONNECTION_HOST_NONE: 85 + return NULL; 86 + default: 87 + break; 88 + } 89 + #endif 90 + return driver; 91 + } 92 + 58 93 #ifdef SPLIT_KEYBOARD 59 94 uint8_t split_led_state = 0; 60 95 void set_split_host_keyboard_leds(uint8_t led_state) { ··· 66 101 #ifdef SPLIT_KEYBOARD 67 102 if (!is_keyboard_master()) return split_led_state; 68 103 #endif 69 - if (!driver) return 0; 104 + 105 + host_driver_t *driver = host_get_active_driver(); 106 + if (!driver || !driver->keyboard_leds) return 0; 107 + 70 108 return (*driver->keyboard_leds)(); 71 109 } 72 110 ··· 76 114 77 115 /* send report */ 78 116 void host_keyboard_send(report_keyboard_t *report) { 79 - #ifdef BLUETOOTH_ENABLE 80 - if (connection_get_host() == CONNECTION_HOST_BLUETOOTH) { 81 - bluetooth_send_keyboard(report); 82 - return; 83 - } 84 - #endif 117 + host_driver_t *driver = host_get_active_driver(); 118 + if (!driver || !driver->send_keyboard) return; 85 119 86 - if (!driver) return; 87 120 #ifdef KEYBOARD_SHARED_EP 88 121 report->report_id = REPORT_ID_KEYBOARD; 89 122 #endif ··· 99 132 } 100 133 101 134 void host_nkro_send(report_nkro_t *report) { 102 - if (!driver) return; 135 + host_driver_t *driver = host_get_active_driver(); 136 + if (!driver || !driver->send_nkro) return; 137 + 103 138 report->report_id = REPORT_ID_NKRO; 104 139 (*driver->send_nkro)(report); 105 140 ··· 113 148 } 114 149 115 150 void host_mouse_send(report_mouse_t *report) { 116 - #ifdef BLUETOOTH_ENABLE 117 - if (connection_get_host() == CONNECTION_HOST_BLUETOOTH) { 118 - bluetooth_send_mouse(report); 119 - return; 120 - } 121 - #endif 151 + host_driver_t *driver = host_get_active_driver(); 152 + if (!driver || !driver->send_mouse) return; 122 153 123 - if (!driver) return; 124 154 #ifdef MOUSE_SHARED_EP 125 155 report->report_id = REPORT_ID_MOUSE; 126 156 #endif ··· 136 166 if (usage == last_system_usage) return; 137 167 last_system_usage = usage; 138 168 139 - if (!driver) return; 169 + host_driver_t *driver = host_get_active_driver(); 170 + if (!driver || !driver->send_extra) return; 140 171 141 172 report_extra_t report = { 142 173 .report_id = REPORT_ID_SYSTEM, ··· 149 180 if (usage == last_consumer_usage) return; 150 181 last_consumer_usage = usage; 151 182 152 - #ifdef BLUETOOTH_ENABLE 153 - if (connection_get_host() == CONNECTION_HOST_BLUETOOTH) { 154 - bluetooth_send_consumer(usage); 155 - return; 156 - } 157 - #endif 158 - 159 - if (!driver) return; 183 + host_driver_t *driver = host_get_active_driver(); 184 + if (!driver || !driver->send_extra) return; 160 185 161 186 report_extra_t report = { 162 187 .report_id = REPORT_ID_CONSUMER,