via.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. #define VIA_EEPROM_CONFIG_END (VIA_EEPROM_CUSTOM_CONFIG_ADDR + VIA_EEPROM_CUSTOM_CONFIG_SIZE)
  49. // This is changed only when the command IDs change,
  50. // so VIA Configurator can detect compatible firmware.
  51. #define VIA_PROTOCOL_VERSION 0x000B
  52. // This is a version number for the firmware for the keyboard.
  53. // It can be used to ensure the VIA keyboard definition and the firmware
  54. // have the same version, especially if there are changes to custom values.
  55. // Define this in config.h to override and bump this number.
  56. // This is *not* required if the keyboard is only using basic functionality
  57. // and not using custom values for lighting, rotary encoders, etc.
  58. #ifndef VIA_FIRMWARE_VERSION
  59. # define VIA_FIRMWARE_VERSION 0x00000000
  60. #endif
  61. enum via_command_id {
  62. id_get_protocol_version = 0x01, // always 0x01
  63. id_get_keyboard_value = 0x02,
  64. id_set_keyboard_value = 0x03,
  65. id_dynamic_keymap_get_keycode = 0x04,
  66. id_dynamic_keymap_set_keycode = 0x05,
  67. id_dynamic_keymap_reset = 0x06,
  68. id_custom_set_value = 0x07,
  69. id_custom_get_value = 0x08,
  70. id_custom_save = 0x09,
  71. id_eeprom_reset = 0x0A,
  72. id_bootloader_jump = 0x0B,
  73. id_dynamic_keymap_macro_get_count = 0x0C,
  74. id_dynamic_keymap_macro_get_buffer_size = 0x0D,
  75. id_dynamic_keymap_macro_get_buffer = 0x0E,
  76. id_dynamic_keymap_macro_set_buffer = 0x0F,
  77. id_dynamic_keymap_macro_reset = 0x10,
  78. id_dynamic_keymap_get_layer_count = 0x11,
  79. id_dynamic_keymap_get_buffer = 0x12,
  80. id_dynamic_keymap_set_buffer = 0x13,
  81. id_dynamic_keymap_get_encoder = 0x14,
  82. id_dynamic_keymap_set_encoder = 0x15,
  83. id_unhandled = 0xFF,
  84. };
  85. enum via_keyboard_value_id {
  86. id_uptime = 0x01,
  87. id_layout_options = 0x02,
  88. id_switch_matrix_state = 0x03,
  89. id_firmware_version = 0x04,
  90. id_device_indication = 0x05,
  91. };
  92. enum via_channel_id {
  93. id_custom_channel = 0,
  94. id_qmk_backlight_channel = 1,
  95. id_qmk_rgblight_channel = 2,
  96. id_qmk_rgb_matrix_channel = 3,
  97. id_qmk_audio_channel = 4,
  98. };
  99. enum via_qmk_backlight_value {
  100. id_qmk_backlight_brightness = 1,
  101. id_qmk_backlight_effect = 2,
  102. };
  103. enum via_qmk_rgblight_value {
  104. id_qmk_rgblight_brightness = 1,
  105. id_qmk_rgblight_effect = 2,
  106. id_qmk_rgblight_effect_speed = 3,
  107. id_qmk_rgblight_color = 4,
  108. };
  109. enum via_qmk_rgb_matrix_value {
  110. id_qmk_rgb_matrix_brightness = 1,
  111. id_qmk_rgb_matrix_effect = 2,
  112. id_qmk_rgb_matrix_effect_speed = 3,
  113. id_qmk_rgb_matrix_color = 4,
  114. };
  115. enum via_qmk_audio_value {
  116. id_qmk_audio_enable = 1,
  117. id_qmk_audio_clicky_enable = 2,
  118. };
  119. enum via_keycodes {
  120. FN_MO13 = QK_MACRO,
  121. FN_MO23,
  122. MACRO00,
  123. MACRO01,
  124. MACRO02,
  125. MACRO03,
  126. MACRO04,
  127. MACRO05,
  128. MACRO06,
  129. MACRO07,
  130. MACRO08,
  131. MACRO09,
  132. MACRO10,
  133. MACRO11,
  134. MACRO12,
  135. MACRO13,
  136. MACRO14,
  137. MACRO15,
  138. };
  139. enum user_keycodes {
  140. USER00 = QK_USER,
  141. USER01,
  142. USER02,
  143. USER03,
  144. USER04,
  145. USER05,
  146. USER06,
  147. USER07,
  148. USER08,
  149. USER09,
  150. USER10,
  151. USER11,
  152. USER12,
  153. USER13,
  154. USER14,
  155. USER15,
  156. };
  157. // Can be called in an overriding via_init_kb() to test if keyboard level code usage of
  158. // EEPROM is invalid and use/save defaults.
  159. bool via_eeprom_is_valid(void);
  160. // Sets VIA/keyboard level usage of EEPROM to valid/invalid
  161. // Keyboard level code (eg. via_init_kb()) should not call this
  162. void via_eeprom_set_valid(bool valid);
  163. // Called by QMK core to initialize dynamic keymaps etc.
  164. void eeconfig_init_via(void);
  165. void via_init(void);
  166. // Used by VIA to store and retrieve the layout options.
  167. uint32_t via_get_layout_options(void);
  168. void via_set_layout_options(uint32_t value);
  169. void via_set_layout_options_kb(uint32_t value);
  170. // Used by VIA to tell a device to flash LEDs (or do something else) when that
  171. // device becomes the active device being configured, on startup or switching
  172. // between devices.
  173. void via_set_device_indication(uint8_t value);
  174. // Called by QMK core to process VIA-specific keycodes.
  175. bool process_record_via(uint16_t keycode, keyrecord_t *record);
  176. // These are made external so that keyboard level custom value handlers can use them.
  177. #if defined(BACKLIGHT_ENABLE)
  178. void via_qmk_backlight_command(uint8_t *data, uint8_t length);
  179. void via_qmk_backlight_set_value(uint8_t *data);
  180. void via_qmk_backlight_get_value(uint8_t *data);
  181. void via_qmk_backlight_save(void);
  182. #endif
  183. #if defined(RGBLIGHT_ENABLE)
  184. void via_qmk_rgblight_command(uint8_t *data, uint8_t length);
  185. void via_qmk_rgblight_set_value(uint8_t *data);
  186. void via_qmk_rgblight_get_value(uint8_t *data);
  187. void via_qmk_rgblight_save(void);
  188. #endif
  189. #if defined(RGB_MATRIX_ENABLE)
  190. void via_qmk_rgb_matrix_command(uint8_t *data, uint8_t length);
  191. void via_qmk_rgb_matrix_set_value(uint8_t *data);
  192. void via_qmk_rgb_matrix_get_value(uint8_t *data);
  193. void via_qmk_rgb_matrix_save(void);
  194. #endif
  195. #if defined(AUDIO_ENABLE)
  196. void via_qmk_audio_command(uint8_t *data, uint8_t length);
  197. void via_qmk_audio_set_value(uint8_t *data);
  198. void via_qmk_audio_get_value(uint8_t *data);
  199. void via_qmk_audio_save(void);
  200. #endif