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.

123 lines
2.6 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 "suspend.h"
  6. #include "action.h"
  7. #include "timer.h"
  8. #ifdef PROTOCOL_LUFA
  9. # include "lufa.h"
  10. #endif
  11. #ifdef PROTOCOL_VUSB
  12. # include "vusb.h"
  13. #endif
  14. // TODO: This needs some cleanup
  15. #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect)
  16. // clang-format off
  17. #define wdt_intr_enable(value) \
  18. __asm__ __volatile__ ( \
  19. "in __tmp_reg__,__SREG__" "\n\t" \
  20. "cli" "\n\t" \
  21. "wdr" "\n\t" \
  22. "sts %0,%1" "\n\t" \
  23. "out __SREG__,__tmp_reg__" "\n\t" \
  24. "sts %0,%2" "\n\t" \
  25. : /* no outputs */ \
  26. : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
  27. "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
  28. "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | _BV(WDIE) | (value & 0x07))) \
  29. : "r0" \
  30. )
  31. // clang-format on
  32. /** \brief Power down MCU with watchdog timer
  33. *
  34. * wdto: watchdog timer timeout defined in <avr/wdt.h>
  35. * WDTO_15MS
  36. * WDTO_30MS
  37. * WDTO_60MS
  38. * WDTO_120MS
  39. * WDTO_250MS
  40. * WDTO_500MS
  41. * WDTO_1S
  42. * WDTO_2S
  43. * WDTO_4S
  44. * WDTO_8S
  45. */
  46. static uint8_t wdt_timeout = 0;
  47. /** \brief Power down
  48. *
  49. * FIXME: needs doc
  50. */
  51. static void power_down(uint8_t wdto) {
  52. wdt_timeout = wdto;
  53. // Watchdog Interrupt Mode
  54. wdt_intr_enable(wdto);
  55. // TODO: more power saving
  56. // See PicoPower application note
  57. // - I/O port input with pullup
  58. // - prescale clock
  59. // - BOD disable
  60. // - Power Reduction Register PRR
  61. set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  62. sleep_enable();
  63. sei();
  64. sleep_cpu();
  65. sleep_disable();
  66. // Disable watchdog after sleep
  67. wdt_disable();
  68. }
  69. /* watchdog timeout */
  70. ISR(WDT_vect) {
  71. // compensate timer for sleep
  72. switch (wdt_timeout) {
  73. case WDTO_15MS:
  74. timer_count += 15 + 2; // WDTO_15MS + 2(from observation)
  75. break;
  76. default:;
  77. }
  78. }
  79. #endif
  80. /** \brief Suspend power down
  81. *
  82. * FIXME: needs doc
  83. */
  84. void suspend_power_down(void) {
  85. #ifdef PROTOCOL_LUFA
  86. if (USB_DeviceState == DEVICE_STATE_Configured) return;
  87. #endif
  88. #ifdef PROTOCOL_VUSB
  89. if (!vusb_suspended) return;
  90. #endif
  91. suspend_power_down_quantum();
  92. #ifndef NO_SUSPEND_POWER_DOWN
  93. // Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt)
  94. # if defined(WDT_vect)
  95. power_down(WDTO_15MS);
  96. # endif
  97. #endif
  98. }
  99. /** \brief run immediately after wakeup
  100. *
  101. * FIXME: needs doc
  102. */
  103. void suspend_wakeup_init(void) {
  104. // clear keyboard state
  105. clear_keyboard();
  106. suspend_wakeup_init_quantum();
  107. }