Peter's keyboard firmware (QMK) https://qmk.fm/
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 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 Run keyboard level Power down
  21. *
  22. * FIXME: needs doc
  23. */
  24. __attribute__ ((weak))
  25. void suspend_power_down_user (void) { }
  26. /** \brief Run keyboard level Power down
  27. *
  28. * FIXME: needs doc
  29. */
  30. __attribute__ ((weak))
  31. void suspend_power_down_kb(void) {
  32. suspend_power_down_user();
  33. }
  34. /** \brief suspend power down
  35. *
  36. * FIXME: needs doc
  37. */
  38. void suspend_power_down(void) {
  39. // TODO: figure out what to power down and how
  40. // shouldn't power down TPM/FTM if we want a breathing LED
  41. // also shouldn't power down USB
  42. suspend_power_down_kb();
  43. // on AVR, this enables the watchdog for 15ms (max), and goes to
  44. // SLEEP_MODE_PWR_DOWN
  45. wait_ms(17);
  46. }
  47. /** \brief suspend wakeup condition
  48. *
  49. * FIXME: needs doc
  50. */
  51. __attribute__ ((weak)) void matrix_power_up(void) {}
  52. __attribute__ ((weak)) void matrix_power_down(void) {}
  53. bool suspend_wakeup_condition(void)
  54. {
  55. matrix_power_up();
  56. matrix_scan();
  57. matrix_power_down();
  58. for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
  59. if (matrix_get_row(r)) return true;
  60. }
  61. return false;
  62. }
  63. /** \brief run user level code immediately after wakeup
  64. *
  65. * FIXME: needs doc
  66. */
  67. __attribute__ ((weak))
  68. void suspend_wakeup_init_user(void) { }
  69. /** \brief run keyboard level code immediately after wakeup
  70. *
  71. * FIXME: needs doc
  72. */
  73. __attribute__ ((weak))
  74. void suspend_wakeup_init_kb(void) {
  75. suspend_wakeup_init_user();
  76. }
  77. /** \brief suspend wakeup condition
  78. *
  79. * run immediately after wakeup
  80. * FIXME: needs doc
  81. */
  82. void suspend_wakeup_init(void)
  83. {
  84. // clear keyboard state
  85. // need to do it manually, because we're running from ISR
  86. // and clear_keyboard() calls print
  87. // so only clear the variables in memory
  88. // the reports will be sent from main.c afterwards
  89. // or if the PC asks for GET_REPORT
  90. clear_mods();
  91. clear_weak_mods();
  92. clear_keys();
  93. #ifdef MOUSEKEY_ENABLE
  94. mousekey_clear();
  95. #endif /* MOUSEKEY_ENABLE */
  96. #ifdef EXTRAKEY_ENABLE
  97. host_system_send(0);
  98. host_consumer_send(0);
  99. #endif /* EXTRAKEY_ENABLE */
  100. #ifdef BACKLIGHT_ENABLE
  101. backlight_init();
  102. #endif /* BACKLIGHT_ENABLE */
  103. suspend_wakeup_init_kb();
  104. }