suspend.c 2.1 KB

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