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.

164 lines
5.3 KiB

  1. /* Copyright 2019 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. #pragma once
  17. #include "eeconfig.h" // for EECONFIG_SIZE
  18. // Keyboard level code can change where VIA stores the magic.
  19. // The magic is the build date YYMMDD encoded as BCD in 3 bytes,
  20. // thus installing firmware built on a different date to the one
  21. // already installed can be detected and the EEPROM data is reset.
  22. // The only reason this is important is in case EEPROM usage changes
  23. // and the EEPROM was not explicitly reset by bootmagic lite.
  24. #ifndef VIA_EEPROM_MAGIC_ADDR
  25. # define VIA_EEPROM_MAGIC_ADDR (EECONFIG_SIZE)
  26. #endif
  27. #define VIA_EEPROM_LAYOUT_OPTIONS_ADDR (VIA_EEPROM_MAGIC_ADDR + 3)
  28. // Changing the layout options size after release will invalidate EEPROM,
  29. // but this is something that should be set correctly on initial implementation.
  30. // 1 byte is enough for most uses (i.e. 8 binary states, or 6 binary + 1 ternary/quaternary )
  31. #ifndef VIA_EEPROM_LAYOUT_OPTIONS_SIZE
  32. # define VIA_EEPROM_LAYOUT_OPTIONS_SIZE 1
  33. #endif
  34. // Allow override of the layout options default value.
  35. // This requires advanced knowledge of how VIA stores layout options
  36. // and is only really useful for setting a boolean layout option
  37. // state to true by default.
  38. #ifndef VIA_EEPROM_LAYOUT_OPTIONS_DEFAULT
  39. # define VIA_EEPROM_LAYOUT_OPTIONS_DEFAULT 0x00000000
  40. #endif
  41. // The end of the EEPROM memory used by VIA
  42. // By default, dynamic keymaps will start at this if there is no
  43. // custom config
  44. #define VIA_EEPROM_CUSTOM_CONFIG_ADDR (VIA_EEPROM_LAYOUT_OPTIONS_ADDR + VIA_EEPROM_LAYOUT_OPTIONS_SIZE)
  45. #ifndef VIA_EEPROM_CUSTOM_CONFIG_SIZE
  46. # define VIA_EEPROM_CUSTOM_CONFIG_SIZE 0
  47. #endif
  48. // This is changed only when the command IDs change,
  49. // so VIA Configurator can detect compatible firmware.
  50. #define VIA_PROTOCOL_VERSION 0x0009
  51. enum via_command_id {
  52. id_get_protocol_version = 0x01, // always 0x01
  53. id_get_keyboard_value = 0x02,
  54. id_set_keyboard_value = 0x03,
  55. id_dynamic_keymap_get_keycode = 0x04,
  56. id_dynamic_keymap_set_keycode = 0x05,
  57. id_dynamic_keymap_reset = 0x06,
  58. id_lighting_set_value = 0x07,
  59. id_lighting_get_value = 0x08,
  60. id_lighting_save = 0x09,
  61. id_eeprom_reset = 0x0A,
  62. id_bootloader_jump = 0x0B,
  63. id_dynamic_keymap_macro_get_count = 0x0C,
  64. id_dynamic_keymap_macro_get_buffer_size = 0x0D,
  65. id_dynamic_keymap_macro_get_buffer = 0x0E,
  66. id_dynamic_keymap_macro_set_buffer = 0x0F,
  67. id_dynamic_keymap_macro_reset = 0x10,
  68. id_dynamic_keymap_get_layer_count = 0x11,
  69. id_dynamic_keymap_get_buffer = 0x12,
  70. id_dynamic_keymap_set_buffer = 0x13,
  71. id_unhandled = 0xFF,
  72. };
  73. enum via_keyboard_value_id {
  74. id_uptime = 0x01, //
  75. id_layout_options = 0x02,
  76. id_switch_matrix_state = 0x03
  77. };
  78. enum via_lighting_value {
  79. // QMK BACKLIGHT
  80. id_qmk_backlight_brightness = 0x09,
  81. id_qmk_backlight_effect = 0x0A,
  82. // QMK RGBLIGHT
  83. id_qmk_rgblight_brightness = 0x80,
  84. id_qmk_rgblight_effect = 0x81,
  85. id_qmk_rgblight_effect_speed = 0x82,
  86. id_qmk_rgblight_color = 0x83,
  87. };
  88. // Can't use SAFE_RANGE here, it might change if someone adds
  89. // new values to enum quantum_keycodes.
  90. // Need to keep checking 0x5F10 is still in the safe range.
  91. // TODO: merge this into quantum_keycodes
  92. // Backlight keycodes are in range 0x5F00-0x5F0F
  93. enum via_keycodes {
  94. FN_MO13 = 0x5F10,
  95. FN_MO23,
  96. MACRO00,
  97. MACRO01,
  98. MACRO02,
  99. MACRO03,
  100. MACRO04,
  101. MACRO05,
  102. MACRO06,
  103. MACRO07,
  104. MACRO08,
  105. MACRO09,
  106. MACRO10,
  107. MACRO11,
  108. MACRO12,
  109. MACRO13,
  110. MACRO14,
  111. MACRO15,
  112. };
  113. enum user_keycodes {
  114. USER00 = 0x5F80,
  115. USER01,
  116. USER02,
  117. USER03,
  118. USER04,
  119. USER05,
  120. USER06,
  121. USER07,
  122. USER08,
  123. USER09,
  124. USER10,
  125. USER11,
  126. USER12,
  127. USER13,
  128. USER14,
  129. USER15,
  130. };
  131. // Can be called in an overriding via_init_kb() to test if keyboard level code usage of
  132. // EEPROM is invalid and use/save defaults.
  133. bool via_eeprom_is_valid(void);
  134. // Sets VIA/keyboard level usage of EEPROM to valid/invalid
  135. // Keyboard level code (eg. via_init_kb()) should not call this
  136. void via_eeprom_set_valid(bool valid);
  137. // Called by QMK core to initialize dynamic keymaps etc.
  138. void eeconfig_init_via(void);
  139. void via_init(void);
  140. // Used by VIA to store and retrieve the layout options.
  141. uint32_t via_get_layout_options(void);
  142. void via_set_layout_options(uint32_t value);
  143. // Called by QMK core to process VIA-specific keycodes.
  144. bool process_record_via(uint16_t keycode, keyrecord_t *record);