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.

225 lines
7.4 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
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
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_avr.h"
  8. #include "suspend.h"
  9. #include "timer.h"
  10. #include "led.h"
  11. #include "host.h"
  12. #include "rgblight_reconfig.h"
  13. #ifdef PROTOCOL_LUFA
  14. # include "lufa.h"
  15. #endif
  16. #ifdef BACKLIGHT_ENABLE
  17. # include "backlight.h"
  18. #endif
  19. #ifdef AUDIO_ENABLE
  20. # include "audio.h"
  21. #endif /* AUDIO_ENABLE */
  22. #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
  23. # include "rgblight.h"
  24. extern rgblight_config_t rgblight_config;
  25. static bool rgblight_enabled;
  26. static bool is_suspended;
  27. #endif
  28. #define wdt_intr_enable(value) \
  29. __asm__ __volatile__("in __tmp_reg__,__SREG__" \
  30. "\n\t" \
  31. "cli" \
  32. "\n\t" \
  33. "wdr" \
  34. "\n\t" \
  35. "sts %0,%1" \
  36. "\n\t" \
  37. "out __SREG__,__tmp_reg__" \
  38. "\n\t" \
  39. "sts %0,%2" \
  40. "\n\t" \
  41. : /* no outputs */ \
  42. : "M"(_SFR_MEM_ADDR(_WD_CONTROL_REG)), "r"(_BV(_WD_CHANGE_BIT) | _BV(WDE)), "r"((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00) | _BV(WDIE) | (value & 0x07))) \
  43. : "r0")
  44. /** \brief Suspend idle
  45. *
  46. * FIXME: needs doc
  47. */
  48. void suspend_idle(uint8_t time) {
  49. cli();
  50. set_sleep_mode(SLEEP_MODE_IDLE);
  51. sleep_enable();
  52. sei();
  53. sleep_cpu();
  54. sleep_disable();
  55. }
  56. // TODO: This needs some cleanup
  57. /** \brief Run keyboard level Power down
  58. *
  59. * FIXME: needs doc
  60. */
  61. __attribute__((weak)) void suspend_power_down_user(void) {}
  62. /** \brief Run keyboard level Power down
  63. *
  64. * FIXME: needs doc
  65. */
  66. __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); }
  67. #ifndef NO_SUSPEND_POWER_DOWN
  68. /** \brief Power down MCU with watchdog timer
  69. *
  70. * wdto: watchdog timer timeout defined in <avr/wdt.h>
  71. * WDTO_15MS
  72. * WDTO_30MS
  73. * WDTO_60MS
  74. * WDTO_120MS
  75. * WDTO_250MS
  76. * WDTO_500MS
  77. * WDTO_1S
  78. * WDTO_2S
  79. * WDTO_4S
  80. * WDTO_8S
  81. */
  82. static uint8_t wdt_timeout = 0;
  83. /** \brief Power down
  84. *
  85. * FIXME: needs doc
  86. */
  87. static void power_down(uint8_t wdto) {
  88. # ifdef PROTOCOL_LUFA
  89. if (USB_DeviceState == DEVICE_STATE_Configured) return;
  90. # endif
  91. wdt_timeout = wdto;
  92. // Watchdog Interrupt Mode
  93. wdt_intr_enable(wdto);
  94. # ifdef BACKLIGHT_ENABLE
  95. backlight_set(0);
  96. # endif
  97. // Turn off LED indicators
  98. uint8_t leds_off = 0;
  99. # if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
  100. if (is_backlight_enabled()) {
  101. // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
  102. leds_off |= (1 << USB_LED_CAPS_LOCK);
  103. }
  104. # endif
  105. led_set(leds_off);
  106. # ifdef AUDIO_ENABLE
  107. // This sometimes disables the start-up noise, so it's been disabled
  108. // stop_all_notes();
  109. # endif /* AUDIO_ENABLE */
  110. # if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
  111. # ifdef RGBLIGHT_ANIMATIONS
  112. rgblight_timer_disable();
  113. # endif
  114. if (!is_suspended) {
  115. is_suspended = true;
  116. rgblight_enabled = rgblight_config.enable;
  117. rgblight_disable_noeeprom();
  118. }
  119. # endif
  120. suspend_power_down_kb();
  121. // TODO: more power saving
  122. // See PicoPower application note
  123. // - I/O port input with pullup
  124. // - prescale clock
  125. // - BOD disable
  126. // - Power Reduction Register PRR
  127. set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  128. sleep_enable();
  129. sei();
  130. sleep_cpu();
  131. sleep_disable();
  132. // Disable watchdog after sleep
  133. wdt_disable();
  134. }
  135. #endif
  136. /** \brief Suspend power down
  137. *
  138. * FIXME: needs doc
  139. */
  140. void suspend_power_down(void) {
  141. suspend_power_down_kb();
  142. #ifndef NO_SUSPEND_POWER_DOWN
  143. power_down(WDTO_15MS);
  144. #endif
  145. }
  146. __attribute__((weak)) void matrix_power_up(void) {}
  147. __attribute__((weak)) void matrix_power_down(void) {}
  148. bool suspend_wakeup_condition(void) {
  149. matrix_power_up();
  150. matrix_scan();
  151. matrix_power_down();
  152. for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
  153. if (matrix_get_row(r)) return true;
  154. }
  155. return false;
  156. }
  157. /** \brief run user level code immediately after wakeup
  158. *
  159. * FIXME: needs doc
  160. */
  161. __attribute__((weak)) void suspend_wakeup_init_user(void) {}
  162. /** \brief run keyboard level code immediately after wakeup
  163. *
  164. * FIXME: needs doc
  165. */
  166. __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); }
  167. /** \brief run immediately after wakeup
  168. *
  169. * FIXME: needs doc
  170. */
  171. void suspend_wakeup_init(void) {
  172. // clear keyboard state
  173. clear_keyboard();
  174. #ifdef BACKLIGHT_ENABLE
  175. backlight_init();
  176. #endif
  177. led_set(host_keyboard_leds());
  178. #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
  179. is_suspended = false;
  180. if (rgblight_enabled) {
  181. # ifdef BOOTLOADER_TEENSY
  182. wait_ms(10);
  183. # endif
  184. rgblight_enable_noeeprom();
  185. }
  186. # ifdef RGBLIGHT_ANIMATIONS
  187. rgblight_timer_enable();
  188. # endif
  189. #endif
  190. suspend_wakeup_init_kb();
  191. }
  192. #ifndef NO_SUSPEND_POWER_DOWN
  193. /* watchdog timeout */
  194. ISR(WDT_vect) {
  195. // compensate timer for sleep
  196. switch (wdt_timeout) {
  197. case WDTO_15MS:
  198. timer_count += 15 + 2; // WDTO_15MS + 2(from observation)
  199. break;
  200. default:;
  201. }
  202. }
  203. #endif