From b02a5396251c0fadb92f2632e242b555c238ad8b Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Wed, 29 Sep 2021 23:31:39 +0300 Subject: Added power tracking api (#12691) * Add power tracking API to lufa and chibios targets * power.c: Pass through power state to the notify function * power: added notify_power_state_change_user too. * making it pass the PR linter * Add a POWER_STATE_NO_INIT state, that we start in before calling power_init(); * Rename *power* to *usb_power* * removing stray newline * Rename usb_power* to usb_device_state* * Update quantum/usb_device_state.h Co-authored-by: Drashna Jaelre * Fix comment * usb_device_state.h: Don't include quantum.h, only the necessary headers. Co-authored-by: Drashna Jaelre --- tmk_core/protocol/chibios/usb_main.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'tmk_core/protocol/chibios/usb_main.c') diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index cc282e6a9b..9b139b3992 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" @@ -412,6 +413,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 */ @@ -419,6 +421,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 @@ -440,6 +443,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; @@ -482,13 +494,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.*/ -- cgit v1.2.3 From 1953a968c51630cc2badfade9ee54f59c878b422 Mon Sep 17 00:00:00 2001 From: Dasky <32983009+daskygit@users.noreply.github.com> Date: Sat, 23 Oct 2021 05:04:15 +0100 Subject: Check usb transmit status in send_extra() (#14643) --- tmk_core/protocol/chibios/usb_main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tmk_core/protocol/chibios/usb_main.c') diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index cc282e6a9b..04049c1a9a 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -921,6 +921,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}; -- cgit v1.2.3 From 5da04fb45b0d5cddc6f49f88ea9c6a4037ef82ce Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Wed, 3 Nov 2021 08:26:40 +1100 Subject: Update to ChibiOS 20.3.4, support builds against trunk (#14208) * Add support for building against ChibiOS svn/trunk. * Swap to 21.6.x * Update to latest branch revision as released version is broken. * Updated configs. * Conf updates. * Updated ChibiOS * Convert STM32L422 to actual L422 ChibiOS platform. * Downgrade to 20.3.4 as ChibiOS 21.6.x is being aborted. * Rollback L422-based boards. --- tmk_core/protocol/chibios/usb_main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tmk_core/protocol/chibios/usb_main.c') diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 3b16a0ff7b..a7db3e3ab1 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -71,7 +71,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 @@ -774,7 +779,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(); -- cgit v1.2.3 From ed49dbeac4c0deba1c6b511ac1ce8f4c542e1b3e Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 30 Nov 2021 16:54:18 +1100 Subject: Add missing virtser_init() to ChibiOS code (#15356) --- tmk_core/protocol/chibios/usb_main.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tmk_core/protocol/chibios/usb_main.c') diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index a7db3e3ab1..ac46a9312b 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -1099,6 +1099,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) { -- cgit v1.2.3