Keyboard firmwares for Atmel AVR and Cortex-M
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

suspend.c 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 matrix and keyboard state
  47. matrix_init();
  48. clear_keyboard();
  49. #ifdef BACKLIGHT_ENABLE
  50. backlight_init();
  51. #endif
  52. }
  53. #ifndef NO_SUSPEND_POWER_DOWN
  54. /* watchdog timeout */
  55. ISR(WDT_vect)
  56. {
  57. /* wakeup from MCU sleep mode */
  58. /*
  59. // blink LED
  60. static uint8_t led_state = 0;
  61. static uint8_t led_count = 0;
  62. led_count++;
  63. if ((led_count & 0x07) == 0) {
  64. led_set((led_state ^= (1<<USB_LED_CAPS_LOCK)));
  65. }
  66. */
  67. }
  68. #endif