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 <drashna@live.com> * Fix comment * usb_device_state.h: Don't include quantum.h, only the necessary headers. Co-authored-by: Drashna Jaelre <drashna@live.com>
This commit is contained in:
@ -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.*/
|
||||
|
Reference in New Issue
Block a user