suspend.c 1.6 KB

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