suspend.c 1.8 KB

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