summaryrefslogtreecommitdiffstats
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol/arm_atsam/main_arm_atsam.c24
-rw-r--r--tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c2
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_device_conf.h14
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c29
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h1
-rw-r--r--tmk_core/protocol/chibios/chibios.c7
-rw-r--r--tmk_core/protocol/chibios/usb_main.c247
-rw-r--r--tmk_core/protocol/chibios/usb_main.h44
-rw-r--r--tmk_core/protocol/chibios/usb_util.c6
-rw-r--r--tmk_core/protocol/host.c150
-rw-r--r--tmk_core/protocol/host.h9
-rw-r--r--tmk_core/protocol/host_driver.h8
-rw-r--r--tmk_core/protocol/lufa/lufa.c289
-rw-r--r--tmk_core/protocol/report.h6
-rw-r--r--tmk_core/protocol/usb_descriptor.c12
-rw-r--r--tmk_core/protocol/usb_descriptor.h13
-rw-r--r--tmk_core/protocol/vusb/vusb.c52
-rw-r--r--tmk_core/protocol/vusb/vusb.h2
18 files changed, 316 insertions, 599 deletions
diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c
index 8ee9e042e7..1ccfbfb54a 100644
--- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c
+++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c
@@ -37,14 +37,13 @@ void main_subtasks(void);
uint8_t keyboard_leds(void);
void send_keyboard(report_keyboard_t *report);
void send_mouse(report_mouse_t *report);
-void send_system(uint16_t data);
-void send_consumer(uint16_t data);
+void send_extra(report_extra_t *report);
#ifdef DEFERRED_EXEC_ENABLE
void deferred_exec_task(void);
#endif // DEFERRED_EXEC_ENABLE
-host_driver_t arm_atsam_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
+host_driver_t arm_atsam_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra};
uint8_t led_states;
@@ -114,33 +113,20 @@ void send_mouse(report_mouse_t *report) {
#endif // MOUSEKEY_ENABLE
}
+void send_extra(report_extra_t *report) {
#ifdef EXTRAKEY_ENABLE
-void send_extra(uint8_t report_id, uint16_t data) {
uint32_t irqflags;
irqflags = __get_PRIMASK();
__disable_irq();
__DMB();
- udi_hid_exk_report.desc.report_id = report_id;
- udi_hid_exk_report.desc.report_data = data;
- udi_hid_exk_b_report_valid = 1;
+ memcpy(udi_hid_exk_report, report, UDI_HID_EXK_REPORT_SIZE);
+ udi_hid_exk_b_report_valid = 1;
udi_hid_exk_send_report();
__DMB();
__set_PRIMASK(irqflags);
-}
-#endif // EXTRAKEY_ENABLE
-
-void send_system(uint16_t data) {
-#ifdef EXTRAKEY_ENABLE
- send_extra(REPORT_ID_SYSTEM, data);
-#endif // EXTRAKEY_ENABLE
-}
-
-void send_consumer(uint16_t data) {
-#ifdef EXTRAKEY_ENABLE
- send_extra(REPORT_ID_CONSUMER, data);
#endif // EXTRAKEY_ENABLE
}
diff --git a/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c b/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c
index 69b3ad574c..58fc4efd9c 100644
--- a/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c
+++ b/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c
@@ -95,7 +95,7 @@ led_setup_t leds_rainbow_s[] = {
void *led_setups[] = {leds_rainbow_s, leds_rainbow_ns, leds_teal_salmon, leds_yellow, leds_red, leds_green, leds_blue, leds_white, leds_white_with_red_stripe, leds_black_with_red_stripe, leds_off};
-const uint8_t led_setups_count = sizeof(led_setups) / sizeof(led_setups[0]);
+const uint8_t led_setups_count = ARRAY_SIZE(led_setups);
# endif // USE_MASSDROP_CONFIGURATOR
#endif // RGB_MATRIX_ENABLE \ No newline at end of file
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h b/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h
index eeed196275..a3c6f1c397 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h
+++ b/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h
@@ -352,21 +352,9 @@ typedef struct {
// clang-format on
-// set report buffer (from host)
-extern uint8_t udi_hid_exk_report_set;
-
// report buffer
# define UDI_HID_EXK_REPORT_SIZE 3
-
-typedef union {
- struct {
- uint8_t report_id;
- uint16_t report_data;
- } desc;
- uint8_t raw[UDI_HID_EXK_REPORT_SIZE];
-} udi_hid_exk_report_t;
-
-extern udi_hid_exk_report_t udi_hid_exk_report;
+extern uint8_t udi_hid_exk_report[UDI_HID_EXK_REPORT_SIZE];
COMPILER_PACK_RESET()
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
index be4f2bb0c9..5d681a8b71 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
+++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
@@ -371,13 +371,13 @@ static uint8_t udi_hid_exk_rate;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_exk_protocol;
-COMPILER_WORD_ALIGNED
-uint8_t udi_hid_exk_report_set;
+// COMPILER_WORD_ALIGNED
+// uint8_t udi_hid_exk_report_set;
bool udi_hid_exk_b_report_valid;
COMPILER_WORD_ALIGNED
-udi_hid_exk_report_t udi_hid_exk_report;
+uint8_t udi_hid_exk_report[UDI_HID_EXK_REPORT_SIZE];
static bool udi_hid_exk_b_report_trans_ongoing;
@@ -415,39 +415,24 @@ UDC_DESC_STORAGE udi_hid_exk_report_desc_t udi_hid_exk_report_desc = {{
//clang-format on
}};
-static bool udi_hid_exk_setreport(void);
-
static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
-static void udi_hid_exk_setreport_valid(void);
-
bool udi_hid_exk_enable(void) {
// Initialize internal values
udi_hid_exk_rate = 0;
udi_hid_exk_protocol = 0;
udi_hid_exk_b_report_trans_ongoing = false;
- memset(udi_hid_exk_report.raw, 0, UDI_HID_EXK_REPORT_SIZE);
+ memset(udi_hid_exk_report, 0, UDI_HID_EXK_REPORT_SIZE);
udi_hid_exk_b_report_valid = false;
return UDI_HID_EXK_ENABLE_EXT();
}
void udi_hid_exk_disable(void) { UDI_HID_EXK_DISABLE_EXT(); }
-bool udi_hid_exk_setup(void) { return udi_hid_setup(&udi_hid_exk_rate, &udi_hid_exk_protocol, (uint8_t *)&udi_hid_exk_report_desc, udi_hid_exk_setreport); }
+bool udi_hid_exk_setup(void) { return udi_hid_setup(&udi_hid_exk_rate, &udi_hid_exk_protocol, (uint8_t *)&udi_hid_exk_report_desc, NULL); }
uint8_t udi_hid_exk_getsetting(void) { return 0; }
-static bool udi_hid_exk_setreport(void) {
- if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (1 == udd_g_ctrlreq.req.wLength)) {
- // Report OUT type on report ID 0 from USB Host
- udd_g_ctrlreq.payload = &udi_hid_exk_report_set;
- udd_g_ctrlreq.callback = udi_hid_exk_setreport_valid;
- udd_g_ctrlreq.payload_size = 1;
- return true;
- }
- return false;
-}
-
bool udi_hid_exk_send_report(void) {
if (!main_b_exk_enable) {
return false;
@@ -457,7 +442,7 @@ bool udi_hid_exk_send_report(void) {
return false;
}
- memcpy(udi_hid_exk_report_trans, udi_hid_exk_report.raw, UDI_HID_EXK_REPORT_SIZE);
+ memcpy(udi_hid_exk_report_trans, udi_hid_exk_report, UDI_HID_EXK_REPORT_SIZE);
udi_hid_exk_b_report_valid = false;
udi_hid_exk_b_report_trans_ongoing = udd_ep_run(UDI_HID_EXK_EP_IN | USB_EP_DIR_IN, false, udi_hid_exk_report_trans, UDI_HID_EXK_REPORT_SIZE, udi_hid_exk_report_sent);
@@ -474,8 +459,6 @@ static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
}
}
-static void udi_hid_exk_setreport_valid(void) {}
-
#endif // EXTRAKEY_ENABLE
//********************************************************************************************
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h
index a330014498..e17538fa70 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h
+++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h
@@ -79,7 +79,6 @@ bool udi_hid_nkro_send_report(void);
#ifdef EXTRAKEY_ENABLE
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_exk;
extern bool udi_hid_exk_b_report_valid;
-extern uint8_t udi_hid_exk_report_set;
bool udi_hid_exk_send_report(void);
#endif // EXTRAKEY_ENABLE
diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c
index c9a480c325..10a976608a 100644
--- a/tmk_core/protocol/chibios/chibios.c
+++ b/tmk_core/protocol/chibios/chibios.c
@@ -58,13 +58,10 @@
uint8_t keyboard_leds(void);
void send_keyboard(report_keyboard_t *report);
void send_mouse(report_mouse_t *report);
-void send_system(uint16_t data);
-void send_consumer(uint16_t data);
-void send_programmable_button(uint32_t data);
-void send_digitizer(report_digitizer_t *report);
+void send_extra(report_extra_t *report);
/* host struct */
-host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer, send_programmable_button};
+host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra};
#ifdef VIRTSER_ENABLE
void virtser_task(void);
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index eb9ef82554..fb3d575846 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -50,10 +50,6 @@
extern keymap_config_t keymap_config;
#endif
-#ifdef JOYSTICK_ENABLE
-# include "joystick.h"
-#endif
-
/* ---------------------------------------------------------
* Global interface variables and declarations
* ---------------------------------------------------------
@@ -124,6 +120,16 @@ static const USBDescriptor *usb_get_descriptor_cb(USBDriver *usbp, uint8_t dtype
return &desc;
}
+/*
+ * USB notification callback that does nothing. Needed to work around bugs in
+ * some USB LLDs that fail to resume the waiting thread when the notification
+ * callback pointer is NULL.
+ */
+static void dummy_usb_cb(USBDriver *usbp, usbep_t ep) {
+ (void)usbp;
+ (void)ep;
+}
+
#ifndef KEYBOARD_SHARED_EP
/* keyboard endpoint state structure */
static USBInEndpointState kbd_ep_state;
@@ -131,7 +137,7 @@ static USBInEndpointState kbd_ep_state;
static const USBEndpointConfig kbd_ep_config = {
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
NULL, /* SETUP packet notification callback */
- kbd_in_cb, /* IN notification callback */
+ dummy_usb_cb, /* IN notification callback */
NULL, /* OUT notification callback */
KEYBOARD_EPSIZE, /* IN maximum packet size */
0, /* OUT maximum packet size */
@@ -149,7 +155,7 @@ static USBInEndpointState mouse_ep_state;
static const USBEndpointConfig mouse_ep_config = {
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
NULL, /* SETUP packet notification callback */
- mouse_in_cb, /* IN notification callback */
+ dummy_usb_cb, /* IN notification callback */
NULL, /* OUT notification callback */
MOUSE_EPSIZE, /* IN maximum packet size */
0, /* OUT maximum packet size */
@@ -167,7 +173,7 @@ static USBInEndpointState shared_ep_state;
static const USBEndpointConfig shared_ep_config = {
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
NULL, /* SETUP packet notification callback */
- shared_in_cb, /* IN notification callback */
+ dummy_usb_cb, /* IN notification callback */
NULL, /* OUT notification callback */
SHARED_EPSIZE, /* IN maximum packet size */
0, /* OUT maximum packet size */
@@ -177,6 +183,42 @@ static const USBEndpointConfig shared_ep_config = {
};
#endif
+#ifdef JOYSTICK_ENABLE
+/* joystick endpoint state structure */
+static USBInEndpointState joystick_ep_state;
+
+/* joystick endpoint initialization structure (IN) - see USBEndpointConfig comment at top of file */
+static const USBEndpointConfig joystick_ep_config = {
+ USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
+ NULL, /* SETUP packet notification callback */
+ dummy_usb_cb, /* IN notification callback */
+ NULL, /* OUT notification callback */
+ JOYSTICK_EPSIZE, /* IN maximum packet size */
+ 0, /* OUT maximum packet size */
+ &joystick_ep_state, /* IN Endpoint state */
+ NULL, /* OUT endpoint state */
+ usb_lld_endpoint_fields /* USB driver specific endpoint fields */
+};
+#endif
+
+#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
+/* digitizer endpoint state structure */
+static USBInEndpointState digitizer_ep_state;
+
+/* digitizer endpoint initialization structure (IN) - see USBEndpointConfig comment at top of file */
+static const USBEndpointConfig digitizer_ep_config = {
+ USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
+ NULL, /* SETUP packet notification callback */
+ dummy_usb_cb, /* IN notification callback */
+ NULL, /* OUT notification callback */
+ DIGITIZER_EPSIZE, /* IN maximum packet size */
+ 0, /* OUT maximum packet size */
+ &digitizer_ep_state, /* IN Endpoint state */
+ NULL, /* OUT endpoint state */
+ usb_lld_endpoint_fields /* USB driver specific endpoint fields */
+};
+#endif
+
#ifdef USB_ENDPOINTS_ARE_REORDERABLE
typedef struct {
size_t queue_capacity_in;
@@ -319,12 +361,6 @@ typedef struct {
#ifdef VIRTSER_ENABLE
usb_driver_config_t serial_driver;
#endif
-#ifdef JOYSTICK_ENABLE
- usb_driver_config_t joystick_driver;
-#endif
-#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
- usb_driver_config_t digitizer_driver;
-#endif
};
usb_driver_config_t array[0];
};
@@ -365,22 +401,6 @@ static usb_driver_configs_t drivers = {
# define CDC_OUT_MODE USB_EP_MODE_TYPE_BULK
.serial_driver = QMK_USB_DRIVER_CONFIG(CDC, CDC_NOTIFICATION_EPNUM, false),
#endif
-
-#ifdef JOYSTICK_ENABLE
-# define JOYSTICK_IN_CAPACITY 4
-# define JOYSTICK_OUT_CAPACITY 4
-# define JOYSTICK_IN_MODE USB_EP_MODE_TYPE_BULK
-# define JOYSTICK_OUT_MODE USB_EP_MODE_TYPE_BULK
- .joystick_driver = QMK_USB_DRIVER_CONFIG(JOYSTICK, 0, false),
-#endif
-
-#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
-# define DIGITIZER_IN_CAPACITY 4
-# define DIGITIZER_OUT_CAPACITY 4
-# define DIGITIZER_IN_MODE USB_EP_MODE_TYPE_BULK
-# define DIGITIZER_OUT_MODE USB_EP_MODE_TYPE_BULK
- .digitizer_driver = QMK_USB_DRIVER_CONFIG(DIGITIZER, 0, false),
-#endif
};
#define NUM_USB_DRIVERS (sizeof(drivers) / sizeof(usb_driver_config_t))
@@ -487,6 +507,12 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
#ifdef SHARED_EP_ENABLE
usbInitEndpointI(usbp, SHARED_IN_EPNUM, &shared_ep_config);
#endif
+#ifdef JOYSTICK_ENABLE
+ usbInitEndpointI(usbp, JOYSTICK_IN_EPNUM, &joystick_ep_config);
+#endif
+#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
+ usbInitEndpointI(usbp, DIGITIZER_IN_EPNUM, &digitizer_ep_config);
+#endif
for (int i = 0; i < NUM_USB_DRIVERS; i++) {
#ifdef USB_ENDPOINTS_ARE_REORDERABLE
usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].inout_ep_config);
@@ -694,7 +720,6 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
/* Start-of-frame callback */
static void usb_sof_cb(USBDriver *usbp) {
- kbd_sof_cb(usbp);
osalSysLockFromISR();
for (int i = 0; i < NUM_USB_DRIVERS; i++) {
qmkusbSOFHookI(&drivers.array[i].driver);
@@ -738,6 +763,7 @@ void init_usb_driver(USBDriver *usbp) {
* after a reset.
*/
usbDisconnectBus(usbp);
+ usbStop(usbp);
wait_ms(50);
usbStart(usbp, &usbcfg);
usbConnectBus(usbp);
@@ -746,8 +772,8 @@ void init_usb_driver(USBDriver *usbp) {
}
__attribute__((weak)) void restart_usb_driver(USBDriver *usbp) {
- usbStop(usbp);
usbDisconnectBus(usbp);
+ usbStop(usbp);
#if USB_SUSPEND_WAKEUP_DELAY > 0
// Some hubs, kvm switches, and monitors do
@@ -767,21 +793,6 @@ __attribute__((weak)) void restart_usb_driver(USBDriver *usbp) {
* Keyboard functions
* ---------------------------------------------------------
*/
-/* keyboard IN callback hander (a kbd report has made it IN) */
-#ifndef KEYBOARD_SHARED_EP
-void kbd_in_cb(USBDriver *usbp, usbep_t ep) {
- /* STUB */
- (void)usbp;
- (void)ep;
-}
-#endif
-
-/* start-of-frame handler
- * TODO: i guess it would be better to re-implement using timers,
- * so that this is not going to have to be checked every 1ms */
-void kbd_sof_cb(USBDriver *usbp) {
- (void)usbp;
-}
/* Idle requests timer code
* callback (called from ISR, unlocked state) */
@@ -892,15 +903,6 @@ unlock:
*/
#ifdef MOUSE_ENABLE
-
-# ifndef MOUSE_SHARED_EP
-/* mouse IN callback hander (a mouse report has made it IN) */
-void mouse_in_cb(USBDriver *usbp, usbep_t ep) {
- (void)usbp;
- (void)ep;
-}
-# endif
-
void send_mouse(report_mouse_t *report) {
osalSysLock();
if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
@@ -929,25 +931,12 @@ void send_mouse(report_mouse_t *report) {
#endif /* MOUSE_ENABLE */
/* ---------------------------------------------------------
- * Shared EP functions
- * ---------------------------------------------------------
- */
-#ifdef SHARED_EP_ENABLE
-/* shared IN callback hander */
-void shared_in_cb(USBDriver *usbp, usbep_t ep) {
- /* STUB */
- (void)usbp;
- (void)ep;
-}
-#endif
-
-/* ---------------------------------------------------------
* Extrakey functions
* ---------------------------------------------------------
*/
+void send_extra(report_extra_t *report) {
#ifdef EXTRAKEY_ENABLE
-static void send_extra(uint8_t report_id, uint16_t data) {
osalSysLock();
if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
osalSysUnlock();
@@ -965,27 +954,12 @@ static void send_extra(uint8_t report_id, uint16_t data) {
}
}
- static report_extra_t report;
- report = (report_extra_t){.report_id = report_id, .usage = data};
-
- usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report_extra_t));
+ usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)report, sizeof(report_extra_t));
osalSysUnlock();
-}
-#endif
-
-void send_system(uint16_t data) {
-#ifdef EXTRAKEY_ENABLE
- send_extra(REPORT_ID_SYSTEM, data);
-#endif
-}
-
-void send_consumer(uint16_t data) {
-#ifdef EXTRAKEY_ENABLE
- send_extra(REPORT_ID_CONSUMER, data);
#endif
}
-void send_programmable_button(uint32_t data) {
+void send_programmable_button(report_programmable_button_t *report) {
#ifdef PROGRAMMABLE_BUTTON_ENABLE
osalSysLock();
if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
@@ -1003,31 +977,57 @@ void send_programmable_button(uint32_t data) {
return;
}
}
- static report_programmable_button_t report = {
- .report_id = REPORT_ID_PROGRAMMABLE_BUTTON,
- };
- report.usage = data;
+ usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)report, sizeof(report_programmable_button_t));
+ osalSysUnlock();
+#endif
+}
+
+void send_joystick(report_joystick_t *report) {
+#ifdef JOYSTICK_ENABLE
+ osalSysLock();
+ if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
+ osalSysUnlock();
+ return;
+ }
- usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report));
+ if (usbGetTransmitStatusI(&USB_DRIVER, JOYSTICK_IN_EPNUM)) {
+ /* Need to either suspend, or loop and call unlock/lock during
+ * every iteration - otherwise the system will remain locked,
+ * no interrupts served, so USB not going through as well.
+ * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
+ if (osalThreadSuspendTimeoutS(&(&USB_DRIVER)->epc[JOYSTICK_IN_EPNUM]->in_state->thread, TIME_MS2I(10)) == MSG_TIMEOUT) {
+ osalSysUnlock();
+ return;
+ }
+ }
+
+ usbStartTransmitI(&USB_DRIVER, JOYSTICK_IN_EPNUM, (uint8_t *)report, sizeof(report_joystick_t));
osalSysUnlock();
#endif
}
void send_digitizer(report_digitizer_t *report) {
#ifdef DIGITIZER_ENABLE
-# ifdef DIGITIZER_SHARED_EP
osalSysLock();
if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
osalSysUnlock();
return;
}
+ if (usbGetTransmitStatusI(&USB_DRIVER, DIGITIZER_IN_EPNUM)) {
+ /* Need to either suspend, or loop and call unlock/lock during
+ * every iteration - otherwise the system will remain locked,
+ * no interrupts served, so USB not going through as well.
+ * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
+ if (osalThreadSuspendTimeoutS(&(&USB_DRIVER)->epc[DIGITIZER_IN_EPNUM]->in_state->thread, TIME_MS2I(10)) == MSG_TIMEOUT) {
+ osalSysUnlock();
+ return;
+ }
+ }
+
usbStartTransmitI(&USB_DRIVER, DIGITIZER_IN_EPNUM, (uint8_t *)report, sizeof(report_digitizer_t));
osalSysUnlock();
-# else
- chnWrite(&drivers.digitizer_driver.driver, (uint8_t *)report, sizeof(report_digitizer_t));
-# endif
#endif
}
@@ -1162,60 +1162,3 @@ void virtser_task(void) {
}
#endif
-
-#ifdef JOYSTICK_ENABLE
-
-void send_joystick_packet(joystick_t *joystick) {
- static joystick_report_t rep;
- rep = (joystick_report_t) {
-# if JOYSTICK_AXES_COUNT > 0
- .axes =
- { joystick->axes[0],
-
-# if JOYSTICK_AXES_COUNT >= 2
- joystick->axes[1],
-# endif
-# if JOYSTICK_AXES_COUNT >= 3
- joystick->axes[2],
-# endif
-# if JOYSTICK_AXES_COUNT >= 4
- joystick->axes[3],
-# endif
-# if JOYSTICK_AXES_COUNT >= 5
- joystick->axes[4],
-# endif
-# if JOYSTICK_AXES_COUNT >= 6
- joystick->axes[5],
-# endif
- },
-# endif // JOYSTICK_AXES_COUNT>0
-
-# if JOYSTICK_BUTTON_COUNT > 0
- .buttons = {
- joystick->buttons[0],
-
-# if JOYSTICK_BUTTON_COUNT > 8
- joystick->buttons[1],
-# endif
-# if JOYSTICK_BUTTON_COUNT > 16
- joystick->buttons[2],
-# endif
-# if JOYSTICK_BUTTON_COUNT > 24
- joystick->buttons[3],
-# endif
- }
-# endif // JOYSTICK_BUTTON_COUNT>0
- };
-
- // chnWrite(&drivers.joystick_driver.driver, (uint8_t *)&rep, sizeof(rep));
- osalSysLock();
- if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
- osalSysUnlock();
- return;
- }
-
- usbStartTransmitI(&USB_DRIVER, JOYSTICK_IN_EPNUM, (uint8_t *)&rep, sizeof(joystick_report_t));
- osalSysUnlock();
-}
-
-#endif
diff --git a/tmk_core/protocol/chibios/usb_main.h b/tmk_core/protocol/chibios/usb_main.h
index fb33c8cd0f..07186f76b8 100644
--- a/tmk_core/protocol/chibios/usb_main.h
+++ b/tmk_core/protocol/chibios/usb_main.h
@@ -17,9 +17,6 @@
#pragma once
-// TESTING
-// extern uint8_t blinkLed;
-
#include <ch.h>
#include <hal.h>
@@ -29,7 +26,9 @@
*/
/* The USB driver to use */
-#define USB_DRIVER USBD1
+#ifndef USB_DRIVER
+# define USB_DRIVER USBD1
+#endif // USB_DRIVER
/* Initialize the USB driver and bus */
void init_usb_driver(USBDriver *usbp);
@@ -48,43 +47,6 @@ void usb_event_queue_init(void);
/* Task to dequeue and execute any handlers for the USB events on the main thread */
void usb_event_queue_task(void);
-/* ---------------
- * Keyboard header
- * ---------------
- */
-
-/* extern report_keyboard_t keyboard_report_sent; */
-
-/* keyboard IN request callback handler */
-void kbd_in_cb(USBDriver *usbp, usbep_t ep);
-
-/* start-of-frame handler */
-void kbd_sof_cb(USBDriver *usbp);
-
-#ifdef NKRO_ENABLE
-/* nkro IN callback hander */
-void nkro_in_cb(USBDriver *usbp, usbep_t ep);
-#endif /* NKRO_ENABLE */
-
-/* ------------
- * Mouse header
- * ------------
- */
-
-#ifdef MOUSE_ENABLE
-
-/* mouse IN request callback handler */
-void mouse_in_cb(USBDriver *usbp, usbep_t ep);
-#endif /* MOUSE_ENABLE */
-
-/* ---------------
- * Shared EP header
- * ---------------
- */
-
-/* shared IN request callback handler */
-void shared_in_cb(USBDriver *usbp, usbep_t ep);
-
/* --------------
* Console header
* --------------
diff --git a/tmk_core/protocol/chibios/usb_util.c b/tmk_core/protocol/chibios/usb_util.c
index c8b435db0c..9d8b2c4007 100644
--- a/tmk_core/protocol/chibios/usb_util.c
+++ b/tmk_core/protocol/chibios/usb_util.c
@@ -14,12 +14,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <hal.h>
+#include "usb_main.h"
#include "usb_util.h"
void usb_disconnect(void) {
- usbStop(&USBD1);
+ usbDisconnectBus(&USB_DRIVER);
+ usbStop(&USB_DRIVER);
}
bool usb_connected_state(void) {
- return usbGetDriverStateI(&USBD1) == USB_ACTIVE;
+ return usbGetDriverStateI(&USB_DRIVER) == USB_ACTIVE;
}
diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c
index 3d8604d541..b441d2d5d9 100644
--- a/tmk_core/protocol/host.c
+++ b/tmk_core/protocol/host.c
@@ -16,13 +16,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
-//#include <avr/interrupt.h>
#include "keyboard.h"
#include "keycode.h"
#include "host.h"
#include "util.h"
#include "debug.h"
-#include "digitizer.h"
+
+#ifdef DIGITIZER_ENABLE
+# include "digitizer.h"
+#endif
+
+#ifdef JOYSTICK_ENABLE
+# include "joystick.h"
+#endif
+
+#ifdef BLUETOOTH_ENABLE
+# include "bluetooth.h"
+# include "outputselect.h"
+#endif
#ifdef NKRO_ENABLE
# include "keycode_config.h"
@@ -30,9 +41,8 @@ extern keymap_config_t keymap_config;
#endif
static host_driver_t *driver;
-static uint16_t last_system_report = 0;
-static uint16_t last_consumer_report = 0;
-static uint32_t last_programmable_button_report = 0;
+static uint16_t last_system_usage = 0;
+static uint16_t last_consumer_usage = 0;
void host_set_driver(host_driver_t *d) {
driver = d;
@@ -63,6 +73,13 @@ led_t host_keyboard_led_state(void) {
/* send report */
void host_keyboard_send(report_keyboard_t *report) {
+#ifdef BLUETOOTH_ENABLE
+ if (where_to_send() == OUTPUT_BLUETOOTH) {
+ bluetooth_send_keyboard(report);
+ return;
+ }
+#endif
+
if (!driver) return;
#if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP)
if (keyboard_protocol && keymap_config.nkro) {
@@ -90,6 +107,13 @@ void host_keyboard_send(report_keyboard_t *report) {
}
void host_mouse_send(report_mouse_t *report) {
+#ifdef BLUETOOTH_ENABLE
+ if (where_to_send() == OUTPUT_BLUETOOTH) {
+ bluetooth_send_mouse(report);
+ return;
+ }
+#endif
+
if (!driver) return;
#ifdef MOUSE_SHARED_EP
report->report_id = REPORT_ID_MOUSE;
@@ -102,29 +126,97 @@ void host_mouse_send(report_mouse_t *report) {
(*driver->send_mouse)(report);
}
-void host_system_send(uint16_t report) {
- if (report == last_system_report) return;
- last_system_report = report;
+void host_system_send(uint16_t usage) {
+ if (usage == last_system_usage) return;
+ last_system_usage = usage;
if (!driver) return;
- (*driver->send_system)(report);
+
+ report_extra_t report = {
+ .report_id = REPORT_ID_SYSTEM,
+ .usage = usage,
+ };
+ (*driver->send_extra)(&report);
}
-void host_consumer_send(uint16_t report) {
- if (report == last_consumer_report) return;
- last_consumer_report = report;
+void host_consumer_send(uint16_t usage) {
+ if (usage == last_consumer_usage) return;
+ last_consumer_usage = usage;
+
+#ifdef BLUETOOTH_ENABLE
+ if (where_to_send() == OUTPUT_BLUETOOTH) {
+ bluetooth_send_consumer(usage);
+ return;
+ }
+#endif
if (!driver) return;
- (*driver->send_consumer)(report);
+
+ report_extra_t report = {
+ .report_id = REPORT_ID_CONSUMER,
+ .usage = usage,
+ };
+ (*driver->send_extra)(&report);
}
-void host_digitizer_send(digitizer_t *digitizer) {
+#ifdef JOYSTICK_ENABLE
+void host_joystick_send(joystick_t *joystick) {
if (!driver) return;
+ report_joystick_t report = {
+# if JOYSTICK_AXES_COUNT > 0
+ .axes =
+ {
+ joystick->axes[0],
+
+# if JOYSTICK_AXES_COUNT >= 2
+ joystick->axes[1],
+# endif
+# if JOYSTICK_AXES_COUNT >= 3
+ joystick->axes[2],
+# endif
+# if JOYSTICK_AXES_COUNT >= 4
+ joystick->axes[3],
+# endif
+# if JOYSTICK_AXES_COUNT >= 5
+ joystick->axes[4],
+# endif
+# if JOYSTICK_AXES_COUNT >= 6
+ joystick->axes[5],
+# endif
+ },
+# endif
+
+# if JOYSTICK_BUTTON_COUNT > 0
+ .buttons =
+ {
+ joystick->buttons[0],
+
+# if JOYSTICK_BUTTON_COUNT > 8
+ joystick->buttons[1],
+# endif
+# if JOYSTICK_BUTTON_COUNT > 16
+ joystick->buttons[2],
+# endif
+# if JOYSTICK_BUTTON_COUNT > 24
+ joystick->buttons[3],
+# endif
+ },
+# endif
+ };
+
+ send_joystick(&report);
+}
+#endif
+
+__attribute__((weak)) void send_joystick(report_joystick_t *report) {}
+
+#ifdef DIGITIZER_ENABLE
+void host_digitizer_send(digitizer_t *digitizer) {
report_digitizer_t report = {
-#ifdef DIGITIZER_SHARED_EP
+# ifdef DIGITIZER_SHARED_EP
.report_id = REPORT_ID_DIGITIZER,
-#endif
+# endif
.tip = digitizer->tipswitch & 0x1,
.inrange = digitizer->inrange & 0x1,
.x = (uint16_t)(digitizer->x * 0x7FFF),
@@ -133,25 +225,27 @@ void host_digitizer_send(digitizer_t *digitizer) {
send_digitizer(&report);
}
+#endif
__attribute__((weak)) void send_digitizer(report_digitizer_t *report) {}
-void host_programmable_button_send(uint32_t report) {
- if (report == last_programmable_button_report) return;
- last_programmable_button_report = report;
+#ifdef PROGRAMMABLE_BUTTON_ENABLE
+void host_programmable_button_send(uint32_t data) {
+ report_programmable_button_t report = {
+ .report_id = REPORT_ID_PROGRAMMABLE_BUTTON,
+ .usage = data,
+ };
- if (!driver) return;
- (*driver->send_programmable_button)(report);
+ send_programmable_button(&report);
}
+#endif
-uint16_t host_last_system_report(void) {