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

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