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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. void suspend_wakeup_init(void)
  40. {
  41. matrix_init();
  42. clear_keyboard();
  43. }