Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

suspend.c 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* TODO */
  2. #include "ch.h"
  3. #include "hal.h"
  4. #include "matrix.h"
  5. #include "action.h"
  6. #include "action_util.h"
  7. #include "mousekey.h"
  8. #include "host.h"
  9. #include "backlight.h"
  10. #include "suspend.h"
  11. void suspend_idle(uint8_t time) {
  12. // TODO: this is not used anywhere - what units is 'time' in?
  13. chThdSleepMilliseconds(time);
  14. }
  15. void suspend_power_down(void) {
  16. // TODO: figure out what to power down and how
  17. // shouldn't power down TPM/FTM if we want a breathing LED
  18. // also shouldn't power down USB
  19. // on AVR, this enables the watchdog for 15ms (max), and goes to
  20. // SLEEP_MODE_PWR_DOWN
  21. chThdSleepMilliseconds(17);
  22. }
  23. __attribute__ ((weak)) void matrix_power_up(void) {}
  24. __attribute__ ((weak)) void matrix_power_down(void) {}
  25. bool suspend_wakeup_condition(void)
  26. {
  27. matrix_power_up();
  28. matrix_scan();
  29. matrix_power_down();
  30. for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
  31. if (matrix_get_row(r)) return true;
  32. }
  33. return false;
  34. }
  35. // run immediately after wakeup
  36. void suspend_wakeup_init(void)
  37. {
  38. // clear keyboard state
  39. // need to do it manually, because we're running from ISR
  40. // and clear_keyboard() calls print
  41. // so only clear the variables in memory
  42. // the reports will be sent from main.c afterwards
  43. // or if the PC asks for GET_REPORT
  44. clear_mods();
  45. clear_weak_mods();
  46. clear_keys();
  47. #ifdef MOUSEKEY_ENABLE
  48. mousekey_clear();
  49. #endif /* MOUSEKEY_ENABLE */
  50. #ifdef EXTRAKEY_ENABLE
  51. host_system_send(0);
  52. host_consumer_send(0);
  53. #endif /* EXTRAKEY_ENABLE */
  54. #ifdef BACKLIGHT_ENABLE
  55. backlight_init();
  56. #endif /* BACKLIGHT_ENABLE */
  57. }