Align VUSB suspend protocol logic (#22688)
parent
6761936fcd
commit
79020519b4
|
@ -22,7 +22,7 @@
|
|||
#include "keyboard.h"
|
||||
#include "host.h"
|
||||
#include "timer.h"
|
||||
#include "print.h"
|
||||
#include "debug.h"
|
||||
#include "suspend.h"
|
||||
#include "wait.h"
|
||||
#include "sendchar.h"
|
||||
|
@ -53,7 +53,7 @@ static void initForUsbConnectivity(void) {
|
|||
usbDeviceConnect();
|
||||
}
|
||||
|
||||
static void vusb_send_remote_wakeup(void) {
|
||||
static inline void vusb_send_remote_wakeup(void) {
|
||||
cli();
|
||||
|
||||
uint8_t ddr_orig = USBDDR;
|
||||
|
@ -72,9 +72,7 @@ static void vusb_send_remote_wakeup(void) {
|
|||
|
||||
bool vusb_suspended = false;
|
||||
|
||||
static void vusb_suspend(void) {
|
||||
vusb_suspended = true;
|
||||
|
||||
static inline void vusb_suspend(void) {
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_enable();
|
||||
#endif
|
||||
|
@ -82,16 +80,13 @@ static void vusb_suspend(void) {
|
|||
suspend_power_down();
|
||||
}
|
||||
|
||||
#if USB_COUNT_SOF
|
||||
static void vusb_wakeup(void) {
|
||||
vusb_suspended = false;
|
||||
static inline void vusb_wakeup(void) {
|
||||
suspend_wakeup_init();
|
||||
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_disable();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/** \brief Setup USB
|
||||
*
|
||||
|
@ -125,27 +120,46 @@ void protocol_post_init(void) {
|
|||
wait_ms(50);
|
||||
}
|
||||
|
||||
void protocol_task(void) {
|
||||
static inline bool should_do_suspend(void) {
|
||||
#if USB_COUNT_SOF
|
||||
if (usbSofCount != 0) {
|
||||
usbSofCount = 0;
|
||||
sof_timer = timer_read();
|
||||
if (vusb_suspended) {
|
||||
vusb_wakeup();
|
||||
}
|
||||
vusb_suspended = false;
|
||||
} else {
|
||||
// Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
|
||||
if (!vusb_suspended && timer_elapsed(sof_timer) > 5) {
|
||||
vusb_suspend();
|
||||
vusb_suspended = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (vusb_suspended) {
|
||||
return vusb_suspended;
|
||||
}
|
||||
|
||||
void protocol_task(void) {
|
||||
#if !defined(NO_USB_STARTUP_CHECK)
|
||||
if (should_do_suspend()) {
|
||||
dprintln("suspending keyboard");
|
||||
while (should_do_suspend()) {
|
||||
vusb_suspend();
|
||||
if (suspend_wakeup_condition()) {
|
||||
vusb_send_remote_wakeup();
|
||||
|
||||
# if USB_SUSPEND_WAKEUP_DELAY > 0
|
||||
// Some hubs, kvm switches, and monitors do
|
||||
// weird things, with USB device state bouncing
|
||||
// around wildly on wakeup, yielding race
|
||||
// conditions that can corrupt the keyboard state.
|
||||
//
|
||||
// Pause for a while to let things settle...
|
||||
wait_ms(USB_SUSPEND_WAKEUP_DELAY);
|
||||
# endif
|
||||
}
|
||||
} else {
|
||||
}
|
||||
vusb_wakeup();
|
||||
}
|
||||
#endif
|
||||
|
||||
usbPoll();
|
||||
|
||||
// TODO: configuration process is inconsistent. it sometime fails.
|
||||
|
@ -170,4 +184,3 @@ void protocol_task(void) {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue