diff options
| author | Purdea Andrei <andrei@purdea.ro> | 2021-09-29 23:31:39 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-30 06:31:39 +1000 |
| commit | b02a5396251c0fadb92f2632e242b555c238ad8b (patch) | |
| tree | 4f01ce4de39773b3225180af56723351862c4aa8 /tmk_core | |
| parent | 552c126bea24b4f182caa62ada8c2213dc06de23 (diff) | |
| download | qmk_firmware-b02a5396251c0fadb92f2632e242b555c238ad8b.tar.gz qmk_firmware-b02a5396251c0fadb92f2632e242b555c238ad8b.zip | |
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>
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/protocol/chibios/chibios.c | 3 | ||||
| -rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 15 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 13 |
3 files changed, 29 insertions, 2 deletions
diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c index 78a2e3fcb..e5d3a4c54 100644 --- a/tmk_core/protocol/chibios/chibios.c +++ b/tmk_core/protocol/chibios/chibios.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include "keyboard.h" | 27 | #include "keyboard.h" |
| 28 | #include "action.h" | 28 | #include "action.h" |
| 29 | #include "action_util.h" | 29 | #include "action_util.h" |
| 30 | #include "usb_device_state.h" | ||
| 30 | #include "mousekey.h" | 31 | #include "mousekey.h" |
| 31 | #include "led.h" | 32 | #include "led.h" |
| 32 | #include "sendchar.h" | 33 | #include "sendchar.h" |
| @@ -139,6 +140,8 @@ void boardInit(void) { | |||
| 139 | } | 140 | } |
| 140 | 141 | ||
| 141 | void protocol_setup(void) { | 142 | void protocol_setup(void) { |
| 143 | usb_device_state_init(); | ||
| 144 | |||
| 142 | // TESTING | 145 | // TESTING |
| 143 | // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); | 146 | // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); |
| 144 | 147 | ||
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index cc282e6a9..9b139b399 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c | |||
| @@ -39,6 +39,7 @@ | |||
| 39 | # include "led.h" | 39 | # include "led.h" |
| 40 | #endif | 40 | #endif |
| 41 | #include "wait.h" | 41 | #include "wait.h" |
| 42 | #include "usb_device_state.h" | ||
| 42 | #include "usb_descriptor.h" | 43 | #include "usb_descriptor.h" |
| 43 | #include "usb_driver.h" | 44 | #include "usb_driver.h" |
| 44 | 45 | ||
| @@ -412,6 +413,7 @@ static inline bool usb_event_queue_dequeue(usbevent_t *event) { | |||
| 412 | } | 413 | } |
| 413 | 414 | ||
| 414 | static inline void usb_event_suspend_handler(void) { | 415 | static inline void usb_event_suspend_handler(void) { |
| 416 | usb_device_state_set_suspend(USB_DRIVER.configuration != 0, USB_DRIVER.configuration); | ||
| 415 | #ifdef SLEEP_LED_ENABLE | 417 | #ifdef SLEEP_LED_ENABLE |
| 416 | sleep_led_enable(); | 418 | sleep_led_enable(); |
| 417 | #endif /* SLEEP_LED_ENABLE */ | 419 | #endif /* SLEEP_LED_ENABLE */ |
| @@ -419,6 +421,7 @@ static inline void usb_event_suspend_handler(void) { | |||
| 419 | 421 | ||
| 420 | static inline void usb_event_wakeup_handler(void) { | 422 | static inline void usb_event_wakeup_handler(void) { |
| 421 | suspend_wakeup_init(); | 423 | suspend_wakeup_init(); |
| 424 | usb_device_state_set_resume(USB_DRIVER.configuration != 0, USB_DRIVER.configuration); | ||
| 422 | #ifdef SLEEP_LED_ENABLE | 425 | #ifdef SLEEP_LED_ENABLE |
| 423 | sleep_led_disable(); | 426 | sleep_led_disable(); |
| 424 | // NOTE: converters may not accept this | 427 | // NOTE: converters may not accept this |
| @@ -440,6 +443,15 @@ void usb_event_queue_task(void) { | |||
| 440 | last_suspend_state = false; | 443 | last_suspend_state = false; |
| 441 | usb_event_wakeup_handler(); | 444 | usb_event_wakeup_handler(); |
| 442 | break; | 445 | break; |
| 446 | case USB_EVENT_CONFIGURED: | ||
| 447 | usb_device_state_set_configuration(USB_DRIVER.configuration != 0, USB_DRIVER.configuration); | ||
| 448 | break; | ||
| 449 | case USB_EVENT_UNCONFIGURED: | ||
| 450 | usb_device_state_set_configuration(false, 0); | ||
| 451 | break; | ||
| 452 | case USB_EVENT_RESET: | ||
| 453 | usb_device_state_set_reset(); | ||
| 454 | break; | ||
| 443 | default: | 455 | default: |
| 444 | // Nothing to do, we don't handle it. | 456 | // Nothing to do, we don't handle it. |
| 445 | break; | 457 | break; |
| @@ -482,13 +494,14 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) { | |||
| 482 | if (last_suspend_state) { | 494 | if (last_suspend_state) { |
| 483 | usb_event_queue_enqueue(USB_EVENT_WAKEUP); | 495 | usb_event_queue_enqueue(USB_EVENT_WAKEUP); |
| 484 | } | 496 | } |
| 497 | usb_event_queue_enqueue(USB_EVENT_CONFIGURED); | ||
| 485 | return; | 498 | return; |
| 486 | case USB_EVENT_SUSPEND: | 499 | case USB_EVENT_SUSPEND: |
| 487 | usb_event_queue_enqueue(USB_EVENT_SUSPEND); | ||
| 488 | /* Falls into.*/ | 500 | /* Falls into.*/ |
| 489 | case USB_EVENT_UNCONFIGURED: | 501 | case USB_EVENT_UNCONFIGURED: |
| 490 | /* Falls into.*/ | 502 | /* Falls into.*/ |
| 491 | case USB_EVENT_RESET: | 503 | case USB_EVENT_RESET: |
| 504 | usb_event_queue_enqueue(event); | ||
| 492 | for (int i = 0; i < NUM_USB_DRIVERS; i++) { | 505 | for (int i = 0; i < NUM_USB_DRIVERS; i++) { |
| 493 | chSysLockFromISR(); | 506 | chSysLockFromISR(); |
| 494 | /* Disconnection event on suspend.*/ | 507 | /* Disconnection event on suspend.*/ |
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 4a30d2257..753762358 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
| @@ -52,6 +52,7 @@ | |||
| 52 | #include "usb_descriptor.h" | 52 | #include "usb_descriptor.h" |
| 53 | #include "lufa.h" | 53 | #include "lufa.h" |
| 54 | #include "quantum.h" | 54 | #include "quantum.h" |
| 55 | #include "usb_device_state.h" | ||
| 55 | #include <util/atomic.h> | 56 | #include <util/atomic.h> |
| 56 | 57 | ||
| 57 | #ifdef NKRO_ENABLE | 58 | #ifdef NKRO_ENABLE |
| @@ -414,7 +415,10 @@ void EVENT_USB_Device_Disconnect(void) { | |||
| 414 | * | 415 | * |
| 415 | * FIXME: Needs doc | 416 | * FIXME: Needs doc |
| 416 | */ | 417 | */ |
| 417 | void EVENT_USB_Device_Reset(void) { print("[R]"); } | 418 | void EVENT_USB_Device_Reset(void) { |
| 419 | print("[R]"); | ||
| 420 | usb_device_state_set_reset(); | ||
| 421 | } | ||
| 418 | 422 | ||
| 419 | /** \brief Event USB Device Connect | 423 | /** \brief Event USB Device Connect |
| 420 | * | 424 | * |
| @@ -422,6 +426,8 @@ void EVENT_USB_Device_Reset(void) { print("[R]"); } | |||
| 422 | */ | 426 | */ |
| 423 | void EVENT_USB_Device_Suspend() { | 427 | void EVENT_USB_Device_Suspend() { |
| 424 | print("[S]"); | 428 | print("[S]"); |
| 429 | usb_device_state_set_suspend(USB_Device_ConfigurationNumber != 0, USB_Device_ConfigurationNumber); | ||
| 430 | |||
| 425 | #ifdef SLEEP_LED_ENABLE | 431 | #ifdef SLEEP_LED_ENABLE |
| 426 | sleep_led_enable(); | 432 | sleep_led_enable(); |
| 427 | #endif | 433 | #endif |
| @@ -437,6 +443,8 @@ void EVENT_USB_Device_WakeUp() { | |||
| 437 | suspend_wakeup_init(); | 443 | suspend_wakeup_init(); |
| 438 | #endif | 444 | #endif |
| 439 | 445 | ||
| 446 | usb_device_state_set_resume(USB_DeviceState == DEVICE_STATE_Configured, USB_Device_ConfigurationNumber); | ||
| 447 | |||
| 440 | #ifdef SLEEP_LED_ENABLE | 448 | #ifdef SLEEP_LED_ENABLE |
| 441 | sleep_led_disable(); | 449 | sleep_led_disable(); |
| 442 | // NOTE: converters may not accept this | 450 | // NOTE: converters may not accept this |
| @@ -529,6 +537,8 @@ void EVENT_USB_Device_ConfigurationChanged(void) { | |||
| 529 | /* Setup digitizer endpoint */ | 537 | /* Setup digitizer endpoint */ |
| 530 | ConfigSuccess &= Endpoint_ConfigureEndpoint((DIGITIZER_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, DIGITIZER_EPSIZE, 1); | 538 | ConfigSuccess &= Endpoint_ConfigureEndpoint((DIGITIZER_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, DIGITIZER_EPSIZE, 1); |
| 531 | #endif | 539 | #endif |
| 540 | |||
| 541 | usb_device_state_set_configuration(USB_DeviceState == DEVICE_STATE_Configured, USB_Device_ConfigurationNumber); | ||
| 532 | } | 542 | } |
| 533 | 543 | ||
| 534 | /* FIXME: Expose this table in the docs somehow | 544 | /* FIXME: Expose this table in the docs somehow |
| @@ -1059,6 +1069,7 @@ void protocol_setup(void) { | |||
| 1059 | #endif | 1069 | #endif |
| 1060 | 1070 | ||
| 1061 | setup_mcu(); | 1071 | setup_mcu(); |
| 1072 | usb_device_state_init(); | ||
| 1062 | keyboard_setup(); | 1073 | keyboard_setup(); |
| 1063 | } | 1074 | } |
| 1064 | 1075 | ||
