Keyboard firmwares for Atmel AVR and Cortex-M
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 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "suspend.h"
  2. #include "matrix.h"
  3. #include "action.h"
  4. void suspend_power_down(void)
  5. {
  6. #ifndef NO_SUSPEND_POWER_DOWN
  7. // Enable watchdog to wake from MCU sleep
  8. cli();
  9. wdt_reset();
  10. // Watchdog Interrupt and System Reset Mode
  11. //wdt_enable(WDTO_1S);
  12. //WDTCSR |= _BV(WDIE);
  13. // Watchdog Interrupt Mode
  14. wdt_intr_enable(WDTO_120MS);
  15. // TODO: more power saving
  16. // See PicoPower application note
  17. // - I/O port input with pullup
  18. // - prescale clock
  19. // - BOD disable
  20. // - Power Reduction Register PRR
  21. // sleep in power down mode
  22. set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  23. sleep_enable();
  24. sei();
  25. sleep_cpu();
  26. sleep_disable();
  27. // Disable watchdog after sleep
  28. wdt_disable();
  29. #endif
  30. }
  31. bool suspend_wakeup_condition(void)
  32. {
  33. matrix_scan();
  34. for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
  35. if (matrix_get_row(r)) return true;
  36. }
  37. return false;
  38. }
  39. // run immediately after wakeup
  40. void suspend_wakeup_init(void)
  41. {
  42. // clear matrix and keyboard state
  43. matrix_init();
  44. clear_keyboard();
  45. }
  46. #ifndef NO_SUSPEND_POWER_DOWN
  47. /* watchdog timeout */
  48. ISR(WDT_vect)
  49. {
  50. /* wakeup from MCU sleep mode */
  51. /*
  52. // blink LED
  53. static uint8_t led_state = 0;
  54. static uint8_t led_count = 0;
  55. led_count++;
  56. if ((led_count & 0x07) == 0) {
  57. led_set((led_state ^= (1<<USB_LED_CAPS_LOCK)));
  58. }
  59. */
  60. }
  61. #endif