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.

305 lines
12 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
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. /* Copyright 2017 Jason Williams (Wilba)
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "keymap.h" // to get keymaps[][][]
  17. #include "eeprom.h"
  18. #include "progmem.h" // to read default from flash
  19. #include "quantum.h" // for send_string()
  20. #include "dynamic_keymap.h"
  21. #include "via.h" // for default VIA_EEPROM_ADDR_END
  22. #ifdef ENCODER_ENABLE
  23. # include "encoder.h"
  24. #else
  25. # define NUM_ENCODERS 0
  26. #endif
  27. #ifndef DYNAMIC_KEYMAP_LAYER_COUNT
  28. # define DYNAMIC_KEYMAP_LAYER_COUNT 4
  29. #endif
  30. #ifndef DYNAMIC_KEYMAP_MACRO_COUNT
  31. # define DYNAMIC_KEYMAP_MACRO_COUNT 16
  32. #endif
  33. #ifndef TOTAL_EEPROM_BYTE_COUNT
  34. # error Unknown total EEPROM size. Cannot derive maximum for dynamic keymaps.
  35. #endif
  36. #ifndef DYNAMIC_KEYMAP_EEPROM_MAX_ADDR
  37. # define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR (TOTAL_EEPROM_BYTE_COUNT - 1)
  38. #endif
  39. #if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > (TOTAL_EEPROM_BYTE_COUNT - 1)
  40. # pragma message STR(DYNAMIC_KEYMAP_EEPROM_MAX_ADDR) " > " STR((TOTAL_EEPROM_BYTE_COUNT - 1))
  41. # error DYNAMIC_KEYMAP_EEPROM_MAX_ADDR is configured to use more space than what is available for the selected EEPROM driver
  42. #endif
  43. // Due to usage of uint16_t check for max 65535
  44. #if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > 65535
  45. # pragma message STR(DYNAMIC_KEYMAP_EEPROM_MAX_ADDR) " > 65535"
  46. # error DYNAMIC_KEYMAP_EEPROM_MAX_ADDR must be less than 65536
  47. #endif
  48. // If DYNAMIC_KEYMAP_EEPROM_ADDR not explicitly defined in config.h,
  49. // default it start after VIA_EEPROM_CUSTOM_ADDR+VIA_EEPROM_CUSTOM_SIZE
  50. #ifndef DYNAMIC_KEYMAP_EEPROM_ADDR
  51. # ifdef VIA_EEPROM_CUSTOM_CONFIG_ADDR
  52. # define DYNAMIC_KEYMAP_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR + VIA_EEPROM_CUSTOM_CONFIG_SIZE)
  53. # else
  54. # error DYNAMIC_KEYMAP_EEPROM_ADDR not defined
  55. # endif
  56. #endif
  57. // Dynamic encoders starts after dynamic keymaps
  58. #ifndef DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR
  59. # define DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR (DYNAMIC_KEYMAP_EEPROM_ADDR + (DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2))
  60. #endif
  61. // Dynamic macro starts after dynamic encoders, but only when using ENCODER_MAP
  62. #ifdef ENCODER_MAP_ENABLE
  63. # ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
  64. # define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR + (DYNAMIC_KEYMAP_LAYER_COUNT * NUM_ENCODERS * 2 * 2))
  65. # endif // DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
  66. #else // ENCODER_MAP_ENABLE
  67. # ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
  68. # define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR)
  69. # endif // DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
  70. #endif // ENCODER_MAP_ENABLE
  71. // Sanity check that dynamic keymaps fit in available EEPROM
  72. // If there's not 100 bytes available for macros, then something is wrong.
  73. // The keyboard should override DYNAMIC_KEYMAP_LAYER_COUNT to reduce it,
  74. // or DYNAMIC_KEYMAP_EEPROM_MAX_ADDR to increase it, *only if* the microcontroller has
  75. // more than the default.
  76. _Static_assert((DYNAMIC_KEYMAP_EEPROM_MAX_ADDR) - (DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR) >= 100, "Dynamic keymaps are configured to use more EEPROM than is available.");
  77. // Dynamic macros are stored after the keymaps and use what is available
  78. // up to and including DYNAMIC_KEYMAP_EEPROM_MAX_ADDR.
  79. #ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE
  80. # define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE (DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + 1)
  81. #endif
  82. uint8_t dynamic_keymap_get_layer_count(void) {
  83. return DYNAMIC_KEYMAP_LAYER_COUNT;
  84. }
  85. void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column) {
  86. // TODO: optimize this with some left shifts
  87. return ((void *)DYNAMIC_KEYMAP_EEPROM_ADDR) + (layer * MATRIX_ROWS * MATRIX_COLS * 2) + (row * MATRIX_COLS * 2) + (column * 2);
  88. }
  89. uint16_t dynamic_keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t column) {
  90. if (layer >= DYNAMIC_KEYMAP_LAYER_COUNT || row >= MATRIX_ROWS || column >= MATRIX_COLS) return KC_NO;
  91. void *address = dynamic_keymap_key_to_eeprom_address(layer, row, column);
  92. // Big endian, so we can read/write EEPROM directly from host if we want
  93. uint16_t keycode = eeprom_read_byte(address) << 8;
  94. keycode |= eeprom_read_byte(address + 1);
  95. return keycode;
  96. }
  97. void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode) {
  98. if (layer >= DYNAMIC_KEYMAP_LAYER_COUNT || row >= MATRIX_ROWS || column >= MATRIX_COLS) return;
  99. void *address = dynamic_keymap_key_to_eeprom_address(layer, row, column);
  100. // Big endian, so we can read/write EEPROM directly from host if we want
  101. eeprom_update_byte(address, (uint8_t)(keycode >> 8));
  102. eeprom_update_byte(address + 1, (uint8_t)(keycode & 0xFF));
  103. }
  104. #ifdef ENCODER_MAP_ENABLE
  105. void *dynamic_keymap_encoder_to_eeprom_address(uint8_t layer, uint8_t encoder_id) {
  106. return ((void *)DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR) + (layer * NUM_ENCODERS * 2 * 2) + (encoder_id * 2 * 2);
  107. }
  108. uint16_t dynamic_keymap_get_encoder(uint8_t layer, uint8_t encoder_id, bool clockwise) {
  109. if (layer >= DYNAMIC_KEYMAP_LAYER_COUNT || encoder_id >= NUM_ENCODERS) return KC_NO;
  110. void *address = dynamic_keymap_encoder_to_eeprom_address(layer, encoder_id);
  111. // Big endian, so we can read/write EEPROM directly from host if we want
  112. uint16_t keycode = ((uint16_t)eeprom_read_byte(address + (clockwise ? 0 : 2))) << 8;
  113. keycode |= eeprom_read_byte(address + (clockwise ? 0 : 2) + 1);
  114. return keycode;
  115. }
  116. void dynamic_keymap_set_encoder(uint8_t layer, uint8_t encoder_id, bool clockwise, uint16_t keycode) {
  117. if (layer >= DYNAMIC_KEYMAP_LAYER_COUNT || encoder_id >= NUM_ENCODERS) return;
  118. void *address = dynamic_keymap_encoder_to_eeprom_address(layer, encoder_id);
  119. // Big endian, so we can read/write EEPROM directly from host if we want
  120. eeprom_update_byte(address + (clockwise ? 0 : 2), (uint8_t)(keycode >> 8));
  121. eeprom_update_byte(address + (clockwise ? 0 : 2) + 1, (uint8_t)(keycode & 0xFF));
  122. }
  123. #endif // ENCODER_MAP_ENABLE
  124. void dynamic_keymap_reset(void) {
  125. // Reset the keymaps in EEPROM to what is in flash.
  126. // All keyboards using dynamic keymaps should define a layout
  127. // for the same number of layers as DYNAMIC_KEYMAP_LAYER_COUNT.
  128. for (int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) {
  129. for (int row = 0; row < MATRIX_ROWS; row++) {
  130. for (int column = 0; column < MATRIX_COLS; column++) {
  131. dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column]));
  132. }
  133. }
  134. #ifdef ENCODER_MAP_ENABLE
  135. for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) {
  136. dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0]));
  137. dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1]));
  138. }
  139. #endif // ENCODER_MAP_ENABLE
  140. }
  141. }
  142. void dynamic_keymap_get_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
  143. uint16_t dynamic_keymap_eeprom_size = DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2;
  144. void * source = (void *)(DYNAMIC_KEYMAP_EEPROM_ADDR + offset);
  145. uint8_t *target = data;
  146. for (uint16_t i = 0; i < size; i++) {
  147. if (offset + i < dynamic_keymap_eeprom_size) {
  148. *target = eeprom_read_byte(source);
  149. } else {
  150. *target = 0x00;
  151. }
  152. source++;
  153. target++;
  154. }
  155. }
  156. void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
  157. uint16_t dynamic_keymap_eeprom_size = DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2;
  158. void * target = (void *)(DYNAMIC_KEYMAP_EEPROM_ADDR + offset);
  159. uint8_t *source = data;
  160. for (uint16_t i = 0; i < size; i++) {
  161. if (offset + i < dynamic_keymap_eeprom_size) {
  162. eeprom_update_byte(target, *source);
  163. }
  164. source++;
  165. target++;
  166. }
  167. }
  168. // This overrides the one in quantum/keymap_common.c
  169. uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
  170. if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
  171. return dynamic_keymap_get_keycode(layer, key.row, key.col);
  172. }
  173. #ifdef ENCODER_MAP_ENABLE
  174. else if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row == KEYLOC_ENCODER_CW && key.col < NUM_ENCODERS) {
  175. return dynamic_keymap_get_encoder(layer, key.col, true);
  176. } else if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row == KEYLOC_ENCODER_CCW && key.col < NUM_ENCODERS) {
  177. return dynamic_keymap_get_encoder(layer, key.col, false);
  178. }
  179. #endif // ENCODER_MAP_ENABLE
  180. return KC_NO;
  181. }
  182. uint8_t dynamic_keymap_macro_get_count(void) {
  183. return DYNAMIC_KEYMAP_MACRO_COUNT;
  184. }
  185. uint16_t dynamic_keymap_macro_get_buffer_size(void) {
  186. return DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE;
  187. }
  188. void dynamic_keymap_macro_get_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
  189. void * source = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + offset);
  190. uint8_t *target = data;
  191. for (uint16_t i = 0; i < size; i++) {
  192. if (offset + i < DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE) {
  193. *target = eeprom_read_byte(source);
  194. } else {
  195. *target = 0x00;
  196. }
  197. source++;
  198. target++;
  199. }
  200. }
  201. void dynamic_keymap_macro_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
  202. void * target = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + offset);
  203. uint8_t *source = data;
  204. for (uint16_t i = 0; i < size; i++) {
  205. if (offset + i < DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE) {
  206. eeprom_update_byte(target, *source);
  207. }
  208. source++;
  209. target++;
  210. }
  211. }
  212. void dynamic_keymap_macro_reset(void) {
  213. void *p = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR);
  214. void *end = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE);
  215. while (p != end) {
  216. eeprom_update_byte(p, 0);
  217. ++p;
  218. }
  219. }
  220. void dynamic_keymap_macro_send(uint8_t id) {
  221. if (id >= DYNAMIC_KEYMAP_MACRO_COUNT) {
  222. return;
  223. }
  224. // Check the last byte of the buffer.
  225. // If it's not zero, then we are in the middle
  226. // of buffer writing, possibly an aborted buffer
  227. // write. So do nothing.
  228. void *p = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE - 1);
  229. if (eeprom_read_byte(p) != 0) {
  230. return;
  231. }
  232. // Skip N null characters
  233. // p will then point to the Nth macro
  234. p = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR);
  235. void *end = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE);
  236. while (id > 0) {
  237. // If we are past the end of the buffer, then the buffer
  238. // contents are garbage, i.e. there were not DYNAMIC_KEYMAP_MACRO_COUNT
  239. // nulls in the buffer.
  240. if (p == end) {
  241. return;
  242. }
  243. if (eeprom_read_byte(p) == 0) {
  244. --id;
  245. }
  246. ++p;
  247. }
  248. // Send the macro string one or three chars at a time
  249. // by making temporary 1 or 3 char strings
  250. char data[4] = {0, 0, 0, 0};
  251. // We already checked there was a null at the end of
  252. // the buffer, so this cannot go past the end
  253. while (1) {
  254. data[0] = eeprom_read_byte(p++);
  255. data[1] = 0;
  256. // Stop at the null terminator of this macro string
  257. if (data[0] == 0) {
  258. break;
  259. }
  260. // If the char is magic (tap, down, up),
  261. // add the next char (key to use) and send a 3 char string.
  262. if (data[0] == SS_TAP_CODE || data[0] == SS_DOWN_CODE || data[0] == SS_UP_CODE) {
  263. data[1] = data[0];
  264. data[0] = SS_QMK_PREFIX;
  265. data[2] = eeprom_read_byte(p++);
  266. if (data[2] == 0) {
  267. break;
  268. }
  269. }
  270. send_string(data);
  271. }
  272. }