suspend.c 2.0 KB

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