summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/chibios/usb_main.c
diff options
context:
space:
mode:
authorDrashna Jael're <drashna@live.com>2021-12-07 09:27:44 -0800
committerDrashna Jael're <drashna@live.com>2021-12-07 09:27:44 -0800
commit7c18b1c9d3d968ded45e072af3483547c3ec7859 (patch)
treeed7c8a4176033046eacff21228364290b44fcfdb /tmk_core/protocol/chibios/usb_main.c
parent43002bdf77ab0f48af6b04e87edcc37f7cb7b905 (diff)
parent6d0a62920410f50d7f6707960ca1ca0c8fd1d1fa (diff)
Merge commit '6d0a62920410f50d7f6707960ca1ca0c8fd1d1fa' into firmware21
Diffstat (limited to 'tmk_core/protocol/chibios/usb_main.c')
-rw-r--r--tmk_core/protocol/chibios/usb_main.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 697566e27a..14de2fc8cc 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -39,6 +39,7 @@
# include "led.h"
#endif
#include "wait.h"
+#include "usb_device_state.h"
#include "usb_descriptor.h"
#include "usb_driver.h"
@@ -74,7 +75,12 @@ uint8_t keyboard_protocol __attribute__((aligned(2))) = 1;
uint8_t keyboard_led_state = 0;
volatile uint16_t keyboard_idle_count = 0;
static virtual_timer_t keyboard_idle_timer;
-static void keyboard_idle_timer_cb(void *arg);
+
+#if CH_KERNEL_MAJOR >= 7
+static void keyboard_idle_timer_cb(struct ch_virtual_timer *, void *arg);
+#elif CH_KERNEL_MAJOR <= 6
+static void keyboard_idle_timer_cb(void *arg);
+#endif
report_keyboard_t keyboard_report_sent = {{0}};
#ifdef MOUSE_ENABLE
@@ -443,6 +449,7 @@ static inline bool usb_event_queue_dequeue(usbevent_t *event) {
}
static inline void usb_event_suspend_handler(void) {
+ usb_device_state_set_suspend(USB_DRIVER.configuration != 0, USB_DRIVER.configuration);
#ifdef SLEEP_LED_ENABLE
sleep_led_enable();
#endif /* SLEEP_LED_ENABLE */
@@ -450,6 +457,7 @@ static inline void usb_event_suspend_handler(void) {
static inline void usb_event_wakeup_handler(void) {
suspend_wakeup_init();
+ usb_device_state_set_resume(USB_DRIVER.configuration != 0, USB_DRIVER.configuration);
#ifdef SLEEP_LED_ENABLE
sleep_led_disable();
// NOTE: converters may not accept this
@@ -471,6 +479,15 @@ void usb_event_queue_task(void) {
last_suspend_state = false;
usb_event_wakeup_handler();
break;
+ case USB_EVENT_CONFIGURED:
+ usb_device_state_set_configuration(USB_DRIVER.configuration != 0, USB_DRIVER.configuration);
+ break;
+ case USB_EVENT_UNCONFIGURED:
+ usb_device_state_set_configuration(false, 0);
+ break;
+ case USB_EVENT_RESET:
+ usb_device_state_set_reset();
+ break;
default:
// Nothing to do, we don't handle it.
break;
@@ -513,13 +530,14 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
if (last_suspend_state) {
usb_event_queue_enqueue(USB_EVENT_WAKEUP);
}
+ usb_event_queue_enqueue(USB_EVENT_CONFIGURED);
return;
case USB_EVENT_SUSPEND:
- usb_event_queue_enqueue(USB_EVENT_SUSPEND);
/* Falls into.*/
case USB_EVENT_UNCONFIGURED:
/* Falls into.*/
case USB_EVENT_RESET:
+ usb_event_queue_enqueue(event);
for (int i = 0; i < NUM_USB_DRIVERS; i++) {
chSysLockFromISR();
/* Disconnection event on suspend.*/
@@ -813,7 +831,12 @@ void kbd_sof_cb(USBDriver *usbp) { (void)usbp; }
/* Idle requests timer code
* callback (called from ISR, unlocked state) */
+#if CH_KERNEL_MAJOR >= 7
+static void keyboard_idle_timer_cb(struct ch_virtual_timer *timer, void *arg) {
+ (void)timer;
+#elif CH_KERNEL_MAJOR <= 6
static void keyboard_idle_timer_cb(void *arg) {
+#endif
USBDriver *usbp = (USBDriver *)arg;
osalSysLockFromISR();
@@ -973,6 +996,17 @@ static void send_extra(uint8_t report_id, uint16_t data) {
return;
}
+ if (usbGetTransmitStatusI(&USB_DRIVER, SHARED_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[SHARED_IN_EPNUM]->in_state->thread, TIME_MS2I(10)) == MSG_TIMEOUT) {
+ osalSysUnlock();
+ return;
+ }
+ }
+
static report_extra_t report;
report = (report_extra_t){.report_id = report_id, .usage = data};
@@ -1142,6 +1176,8 @@ void midi_ep_task(void) {
#ifdef VIRTSER_ENABLE
+void virtser_init(void) {}
+
void virtser_send(const uint8_t byte) { chnWrite(&drivers.serial_driver.driver, &byte, 1); }
__attribute__((weak)) void virtser_recv(uint8_t c) {