summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2023-08-26 19:52:12 -0700
committerGitHub <noreply@github.com>2023-08-27 03:52:12 +0100
commit25331be3164ca609ebecbfcc727ce904e3676594 (patch)
treecd82b1dc06085a977c1ccb9a6c6ba5752a037bc7 /tmk_core
parent736451558e3c66d10838625a30c904cfa30b170c (diff)
Revert changes to ChibiOS Suspend Code (#21830)
* Partially revert #19780 * Finish * Get teensy 3.5/3.6 board files too * fix lint issue * Revert "[Bug] Restore usb suspend wakeup delay (#21676)" This reverts commit e8e989fd7ad7c10e725e50ae8b0a4426e09f7f30. * Apply suggestions from code review Co-authored-by: Joel Challis <git@zvecr.com> --------- Co-authored-by: Joel Challis <git@zvecr.com>
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol/chibios/chibios.c51
-rw-r--r--tmk_core/protocol/chibios/usb_main.c27
2 files changed, 56 insertions, 22 deletions
diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c
index ac39606179..4d97f1cd82 100644
--- a/tmk_core/protocol/chibios/chibios.c
+++ b/tmk_core/protocol/chibios/chibios.c
@@ -80,6 +80,26 @@ void console_task(void);
80void midi_ep_task(void); 80void midi_ep_task(void);
81#endif 81#endif
82 82
83/* TESTING
84 * Amber LED blinker thread, times are in milliseconds.
85 */
86/* set this variable to non-zero anywhere to blink once */
87// static THD_WORKING_AREA(waThread1, 128);
88// static THD_FUNCTION(Thread1, arg) {
89
90// (void)arg;
91// chRegSetThreadName("blinker");
92// while (true) {
93// systime_t time;
94
95// time = USB_DRIVER.state == USB_ACTIVE ? 250 : 500;
96// palClearLine(LINE_CAPS_LOCK);
97// chSysPolledDelayX(MS2RTC(STM32_HCLK, time));
98// palSetLine(LINE_CAPS_LOCK);
99// chSysPolledDelayX(MS2RTC(STM32_HCLK, time));
100// }
101// }
102
83/* Early initialisation 103/* Early initialisation
84 */ 104 */
85__attribute__((weak)) void early_hardware_init_pre(void) { 105__attribute__((weak)) void early_hardware_init_pre(void) {
@@ -115,6 +135,9 @@ void boardInit(void) {
115 135
116void protocol_setup(void) { 136void protocol_setup(void) {
117 usb_device_state_init(); 137 usb_device_state_init();
138
139 // TESTING
140 // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
118} 141}
119 142
120static host_driver_t *driver = NULL; 143static host_driver_t *driver = NULL;
@@ -157,32 +180,28 @@ void protocol_post_init(void) {
157} 180}
158 181
159void protocol_pre_task(void) { 182void protocol_pre_task(void) {
183 usb_event_queue_task();
184
160#if !defined(NO_USB_STARTUP_CHECK) 185#if !defined(NO_USB_STARTUP_CHECK)
161 if (USB_DRIVER.state == USB_SUSPENDED) { 186 if (USB_DRIVER.state == USB_SUSPENDED) {
162 dprintln("suspending keyboard"); 187 dprintln("suspending keyboard");
163 while (USB_DRIVER.state == USB_SUSPENDED) { 188 while (USB_DRIVER.state == USB_SUSPENDED) {
164 suspend_power_down(); 189 /* Do this in the suspended state */
190 suspend_power_down(); // on AVR this deep sleeps for 15ms
191 /* Remote wakeup */
165 if ((USB_DRIVER.status & USB_GETSTATUS_REMOTE_WAKEUP_ENABLED) && suspend_wakeup_condition()) { 192 if ((USB_DRIVER.status & USB_GETSTATUS_REMOTE_WAKEUP_ENABLED) && suspend_wakeup_condition()) {
166 /* issue a remote wakeup event to the host which should resume
167 * the bus and get our keyboard out of suspension. */
168 usbWakeupHost(&USB_DRIVER); 193 usbWakeupHost(&USB_DRIVER);
169# if USB_SUSPEND_WAKEUP_DELAY > 0 194 restart_usb_driver(&USB_DRIVER);
170 /* Some hubs, kvm switches, and monitors do weird things, with
171 * USB device state bouncing around wildly on wakeup, yielding
172 * race conditions that can corrupt the keyboard state.
173 *
174 * Pause for a while to let things settle... */
175 wait_ms(USB_SUSPEND_WAKEUP_DELAY);
176# endif
177 } 195 }
178 } 196 }
179 /* after a successful wakeup a USB_EVENT_WAKEUP is signaled to QMK by 197 /* Woken up */
180 * ChibiOS, which triggers a wakeup callback that restores the state of 198 // variables has been already cleared by the wakeup hook
181 * the keyboard. Therefore we do nothing here. */ 199 send_keyboard_report();
200# ifdef MOUSEKEY_ENABLE
201 mousekey_send();
202# endif /* MOUSEKEY_ENABLE */
182 } 203 }
183#endif 204#endif
184
185 usb_event_queue_task();
186} 205}
187 206
188void protocol_post_task(void) { 207void protocol_post_task(void) {
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index e1327f065c..b14ca30c1a 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -784,19 +784,34 @@ void init_usb_driver(USBDriver *usbp) {
784#endif 784#endif
785 } 785 }
786 786
787 restart_usb_driver(usbp); 787 /*
788 * Activates the USB driver and then the USB bus pull-up on D+.
789 * Note, a delay is inserted in order to not have to disconnect the cable
790 * after a reset.
791 */
792 usbDisconnectBus(usbp);
793 usbStop(usbp);
794 wait_ms(50);
795 usbStart(usbp, &usbcfg);
796 usbConnectBus(usbp);
788 797
789 chVTObjectInit(&keyboard_idle_timer); 798 chVTObjectInit(&keyboard_idle_timer);
790} 799}
791 800
792/** @brief Restarts the USB driver and emulates a physical bus reconnection.
793 * Note that the bus reconnection is MCU and even board specific, so it might
794 * be a NOP on some hardware platforms.
795 */
796__attribute__((weak)) void restart_usb_driver(USBDriver *usbp) { 801__attribute__((weak)) void restart_usb_driver(USBDriver *usbp) {
797 usbDisconnectBus(usbp); 802 usbDisconnectBus(usbp);
798 usbStop(usbp); 803 usbStop(usbp);
799 wait_ms(50); 804
805#if USB_SUSPEND_WAKEUP_DELAY > 0
806 // Some hubs, kvm switches, and monitors do
807 // weird things, with USB device state bouncing
808 // around wildly on wakeup, yielding race
809 // conditions that can corrupt the keyboard state.
810 //
811 // Pause for a while to let things settle...
812 wait_ms(USB_SUSPEND_WAKEUP_DELAY);
813#endif
814
800 usbStart(usbp, &usbcfg); 815 usbStart(usbp, &usbcfg);
801 usbConnectBus(usbp); 816 usbConnectBus(usbp);
802} 817}