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.

152 lines
3.2 KiB

Zeal60/Zeal65/M60-A implementation (#3879) * Initial version of zeal60 * WIP * Fixes issue #900 * Adding RGB underglow functionality. Fixed a compile-time conflict caused by enabling RGB underglow functionality. * Refactor RPC protocol * Fix last merge * README for RGB underglow updated. * Additional README changes. * Adding RGBW strip software-based current-limiting functionality. * RGBW current-limiting functionality should be handled by RGBSTRIP_MAX_CURRENT_PER_LIGHT instead. * Updated README to reflect implementation of built-in current limiting. * Keymap readability improvements. * Minor keymap improvements. * Fixed LED driver init sequence, formatting * Dimming implementation tested, working. * Stab LEDs synced with spacebar hits in effects. * RGB underglow tested and functional. Simplified README for RGB underglow. * Undid accidental file deletion from previous merge conflict. Safer values for RGB underglow. * Improved arrow key positions in keymap. * Added functionality to correct uneven RGB underglow. Refactored related code. * Reverted to safer values for underglow. * Changes for v0.3 * Custom LED brightness scaling will take place after current adjustment in order to avoid being overridden. * Create keymap.c Added split backspace and split shift to ISO layout * Create config.h Turned on LEDs for new layout * Fixed bug where left spacebar stabilizer LED (LC06) would adopt color of row above. * Added hhkb_wilba keymap * Update keymap.c * Update keymap.c * Update keymap.c * Added indicators, full param setting via host * Added "mousekey" layout * Added Zeal65 support, factory test mode * Keycode safe range changed, caused bugs * Bumped EEPROM version due to change in QMK keycodes * Disable HHKB "blocked" LEDs if KC_NO in keymap * Added "disable_hhkb_blocker_leds" * Required overridden function for keymaps in EEPROM * Added polar coordinate mapping, effect speed * Force Raw HID interface number to 1 always * Fixed last merge from master * Added effect speed to default keymaps * add BACKLIGHT_ prefix to vars * add BACKLIGHT_ prefix to vars * Keymap speed effect; keymap improvements/fixes Readme updated to match changes * Refactored to use common IS31FL3731/I2C drivers * Fixed make rules, backlight disabled feature * Make split rightshift default for Zeal65 * Added M60-A as a "version" of Zeal60. * Renamed IS31FL3731 driver functions * Fix suspend_wakeup_init_kb() being defined twice * First pass refactor dynamic keymaps * Updated to changed I2C and ISSI drivers * Refactor zeal_color.* usage to quantum/color.* * Updated Zeal65, fixed dynamic_keymap * Major refactoring of Zeal60 backlight and API * Lots of little cleanups * Added readme.md * Added readme.md * Added LAYOUT_60*() macros, refactored and cleaned up default keymaps * Fix compile error in suspend.c * Added Zeal65 LAYOUT macros, info.json * Added rama/m60_a, deleted zeal60/keymaps/m60_a * Fixed rama/m60_a/keymaps/proto * Fixed compilation error for suspend.c * Requested changes for PR * Fixed readme.md images * Another readme.md fix * Added drashna's requested changes
5 years ago
Zeal60/Zeal65/M60-A implementation (#3879) * Initial version of zeal60 * WIP * Fixes issue #900 * Adding RGB underglow functionality. Fixed a compile-time conflict caused by enabling RGB underglow functionality. * Refactor RPC protocol * Fix last merge * README for RGB underglow updated. * Additional README changes. * Adding RGBW strip software-based current-limiting functionality. * RGBW current-limiting functionality should be handled by RGBSTRIP_MAX_CURRENT_PER_LIGHT instead. * Updated README to reflect implementation of built-in current limiting. * Keymap readability improvements. * Minor keymap improvements. * Fixed LED driver init sequence, formatting * Dimming implementation tested, working. * Stab LEDs synced with spacebar hits in effects. * RGB underglow tested and functional. Simplified README for RGB underglow. * Undid accidental file deletion from previous merge conflict. Safer values for RGB underglow. * Improved arrow key positions in keymap. * Added functionality to correct uneven RGB underglow. Refactored related code. * Reverted to safer values for underglow. * Changes for v0.3 * Custom LED brightness scaling will take place after current adjustment in order to avoid being overridden. * Create keymap.c Added split backspace and split shift to ISO layout * Create config.h Turned on LEDs for new layout * Fixed bug where left spacebar stabilizer LED (LC06) would adopt color of row above. * Added hhkb_wilba keymap * Update keymap.c * Update keymap.c * Update keymap.c * Added indicators, full param setting via host * Added "mousekey" layout * Added Zeal65 support, factory test mode * Keycode safe range changed, caused bugs * Bumped EEPROM version due to change in QMK keycodes * Disable HHKB "blocked" LEDs if KC_NO in keymap * Added "disable_hhkb_blocker_leds" * Required overridden function for keymaps in EEPROM * Added polar coordinate mapping, effect speed * Force Raw HID interface number to 1 always * Fixed last merge from master * Added effect speed to default keymaps * add BACKLIGHT_ prefix to vars * add BACKLIGHT_ prefix to vars * Keymap speed effect; keymap improvements/fixes Readme updated to match changes * Refactored to use common IS31FL3731/I2C drivers * Fixed make rules, backlight disabled feature * Make split rightshift default for Zeal65 * Added M60-A as a "version" of Zeal60. * Renamed IS31FL3731 driver functions * Fix suspend_wakeup_init_kb() being defined twice * First pass refactor dynamic keymaps * Updated to changed I2C and ISSI drivers * Refactor zeal_color.* usage to quantum/color.* * Updated Zeal65, fixed dynamic_keymap * Major refactoring of Zeal60 backlight and API * Lots of little cleanups * Added readme.md * Added readme.md * Added LAYOUT_60*() macros, refactored and cleaned up default keymaps * Fix compile error in suspend.c * Added Zeal65 LAYOUT macros, info.json * Added rama/m60_a, deleted zeal60/keymaps/m60_a * Fixed rama/m60_a/keymaps/proto * Fixed compilation error for suspend.c * Requested changes for PR * Fixed readme.md images * Another readme.md fix * Added drashna's requested changes
5 years ago
  1. #include <stdbool.h>
  2. #include <avr/sleep.h>
  3. #include <avr/wdt.h>
  4. #include <avr/interrupt.h>
  5. #include "matrix.h"
  6. #include "action.h"
  7. #include "suspend.h"
  8. #include "timer.h"
  9. #include "led.h"
  10. #include "host.h"
  11. #ifdef PROTOCOL_LUFA
  12. # include "lufa.h"
  13. #endif
  14. #ifdef PROTOCOL_VUSB
  15. # include "vusb.h"
  16. #endif
  17. /** \brief Suspend idle
  18. *
  19. * FIXME: needs doc
  20. */
  21. void suspend_idle(uint8_t time) {
  22. cli();
  23. set_sleep_mode(SLEEP_MODE_IDLE);
  24. sleep_enable();
  25. sei();
  26. sleep_cpu();
  27. sleep_disable();
  28. }
  29. // TODO: This needs some cleanup
  30. #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect)
  31. // clang-format off
  32. #define wdt_intr_enable(value) \
  33. __asm__ __volatile__ ( \
  34. "in __tmp_reg__,__SREG__" "\n\t" \
  35. "cli" "\n\t" \
  36. "wdr" "\n\t" \
  37. "sts %0,%1" "\n\t" \
  38. "out __SREG__,__tmp_reg__" "\n\t" \
  39. "sts %0,%2" "\n\t" \
  40. : /* no outputs */ \
  41. : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
  42. "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
  43. "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | _BV(WDIE) | (value & 0x07))) \
  44. : "r0" \
  45. )
  46. // clang-format on
  47. /** \brief Power down MCU with watchdog timer
  48. *
  49. * wdto: watchdog timer timeout defined in <avr/wdt.h>
  50. * WDTO_15MS
  51. * WDTO_30MS
  52. * WDTO_60MS
  53. * WDTO_120MS
  54. * WDTO_250MS
  55. * WDTO_500MS
  56. * WDTO_1S
  57. * WDTO_2S
  58. * WDTO_4S
  59. * WDTO_8S
  60. */
  61. static uint8_t wdt_timeout = 0;
  62. /** \brief Power down
  63. *
  64. * FIXME: needs doc
  65. */
  66. static void power_down(uint8_t wdto) {
  67. wdt_timeout = wdto;
  68. // Watchdog Interrupt Mode
  69. wdt_intr_enable(wdto);
  70. // TODO: more power saving
  71. // See PicoPower application note
  72. // - I/O port input with pullup
  73. // - prescale clock
  74. // - BOD disable
  75. // - Power Reduction Register PRR
  76. set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  77. sleep_enable();
  78. sei();
  79. sleep_cpu();
  80. sleep_disable();
  81. // Disable watchdog after sleep
  82. wdt_disable();
  83. }
  84. #endif
  85. /** \brief Suspend power down
  86. *
  87. * FIXME: needs doc
  88. */
  89. void suspend_power_down(void) {
  90. #ifdef PROTOCOL_LUFA
  91. if (USB_DeviceState == DEVICE_STATE_Configured) return;
  92. #endif
  93. #ifdef PROTOCOL_VUSB
  94. if (!vusb_suspended) return;
  95. #endif
  96. suspend_power_down_quantum();
  97. #ifndef NO_SUSPEND_POWER_DOWN
  98. // Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt)
  99. # if defined(WDT_vect)
  100. power_down(WDTO_15MS);
  101. # endif
  102. #endif
  103. }
  104. __attribute__((weak)) void matrix_power_up(void) {}
  105. __attribute__((weak)) void matrix_power_down(void) {}
  106. bool suspend_wakeup_condition(void) {
  107. matrix_power_up();
  108. matrix_scan();
  109. matrix_power_down();
  110. for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
  111. if (matrix_get_row(r)) return true;
  112. }
  113. return false;
  114. }
  115. /** \brief run immediately after wakeup
  116. *
  117. * FIXME: needs doc
  118. */
  119. void suspend_wakeup_init(void) {
  120. // clear keyboard state
  121. clear_keyboard();
  122. suspend_wakeup_init_quantum();
  123. }
  124. #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect)
  125. /* watchdog timeout */
  126. ISR(WDT_vect) {
  127. // compensate timer for sleep
  128. switch (wdt_timeout) {
  129. case WDTO_15MS:
  130. timer_count += 15 + 2; // WDTO_15MS + 2(from observation)
  131. break;
  132. default:;
  133. }
  134. }
  135. #endif