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.

204 lines
7.5 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. #include "action.h"
  19. // Keyboard level code can change where VIA stores the magic.
  20. // The magic is the build date YYMMDD encoded as BCD in 3 bytes,
  21. // thus installing firmware built on a different date to the one
  22. // already installed can be detected and the EEPROM data is reset.
  23. // The only reason this is important is in case EEPROM usage changes
  24. // and the EEPROM was not explicitly reset by bootmagic lite.
  25. #ifndef VIA_EEPROM_MAGIC_ADDR
  26. # define VIA_EEPROM_MAGIC_ADDR (EECONFIG_SIZE)
  27. #endif
  28. #define VIA_EEPROM_LAYOUT_OPTIONS_ADDR (VIA_EEPROM_MAGIC_ADDR + 3)
  29. // Changing the layout options size after release will invalidate EEPROM,
  30. // but this is something that should be set correctly on initial implementation.
  31. // 1 byte is enough for most uses (i.e. 8 binary states, or 6 binary + 1 ternary/quaternary )
  32. #ifndef VIA_EEPROM_LAYOUT_OPTIONS_SIZE
  33. # define VIA_EEPROM_LAYOUT_OPTIONS_SIZE 1
  34. #endif
  35. // Allow override of the layout options default value.
  36. // This requires advanced knowledge of how VIA stores layout options
  37. // and is only really useful for setting a boolean layout option
  38. // state to true by default.
  39. #ifndef VIA_EEPROM_LAYOUT_OPTIONS_DEFAULT
  40. # define VIA_EEPROM_LAYOUT_OPTIONS_DEFAULT 0x00000000
  41. #endif
  42. // The end of the EEPROM memory used by VIA
  43. // By default, dynamic keymaps will start at this if there is no
  44. // custom config
  45. #define VIA_EEPROM_CUSTOM_CONFIG_ADDR (VIA_EEPROM_LAYOUT_OPTIONS_ADDR + VIA_EEPROM_LAYOUT_OPTIONS_SIZE)
  46. #ifndef VIA_EEPROM_CUSTOM_CONFIG_SIZE
  47. # define VIA_EEPROM_CUSTOM_CONFIG_SIZE 0
  48. #endif
  49. #define VIA_EEPROM_CONFIG_END (VIA_EEPROM_CUSTOM_CONFIG_ADDR + VIA_EEPROM_CUSTOM_CONFIG_SIZE)
  50. // This is changed only when the command IDs change,
  51. // so VIA Configurator can detect compatible firmware.
  52. #define VIA_PROTOCOL_VERSION 0x000C
  53. // This is a version number for the firmware for the keyboard.
  54. // It can be used to ensure the VIA keyboard definition and the firmware
  55. // have the same version, especially if there are changes to custom values.
  56. // Define this in config.h to override and bump this number.
  57. // This is *not* required if the keyboard is only using basic functionality
  58. // and not using custom values for lighting, rotary encoders, etc.
  59. #ifndef VIA_FIRMWARE_VERSION
  60. # define VIA_FIRMWARE_VERSION 0x00000000
  61. #endif
  62. enum via_command_id {
  63. id_get_protocol_version = 0x01, // always 0x01
  64. id_get_keyboard_value = 0x02,
  65. id_set_keyboard_value = 0x03,
  66. id_dynamic_keymap_get_keycode = 0x04,
  67. id_dynamic_keymap_set_keycode = 0x05,
  68. id_dynamic_keymap_reset = 0x06,
  69. id_custom_set_value = 0x07,
  70. id_custom_get_value = 0x08,
  71. id_custom_save = 0x09,
  72. id_eeprom_reset = 0x0A,
  73. id_bootloader_jump = 0x0B,
  74. id_dynamic_keymap_macro_get_count = 0x0C,
  75. id_dynamic_keymap_macro_get_buffer_size = 0x0D,
  76. id_dynamic_keymap_macro_get_buffer = 0x0E,
  77. id_dynamic_keymap_macro_set_buffer = 0x0F,
  78. id_dynamic_keymap_macro_reset = 0x10,
  79. id_dynamic_keymap_get_layer_count = 0x11,
  80. id_dynamic_keymap_get_buffer = 0x12,
  81. id_dynamic_keymap_set_buffer = 0x13,
  82. id_dynamic_keymap_get_encoder = 0x14,
  83. id_dynamic_keymap_set_encoder = 0x15,
  84. id_unhandled = 0xFF,
  85. };
  86. enum via_keyboard_value_id {
  87. id_uptime = 0x01,
  88. id_layout_options = 0x02,
  89. id_switch_matrix_state = 0x03,
  90. id_firmware_version = 0x04,
  91. id_device_indication = 0x05,
  92. };
  93. enum via_channel_id {
  94. id_custom_channel = 0,
  95. id_qmk_backlight_channel = 1,
  96. id_qmk_rgblight_channel = 2,
  97. id_qmk_rgb_matrix_channel = 3,
  98. id_qmk_audio_channel = 4,
  99. id_qmk_led_matrix_channel = 5,
  100. };
  101. enum via_qmk_backlight_value {
  102. id_qmk_backlight_brightness = 1,
  103. id_qmk_backlight_effect = 2,
  104. };
  105. enum via_qmk_rgblight_value {
  106. id_qmk_rgblight_brightness = 1,
  107. id_qmk_rgblight_effect = 2,
  108. id_qmk_rgblight_effect_speed = 3,
  109. id_qmk_rgblight_color = 4,
  110. };
  111. enum via_qmk_rgb_matrix_value {
  112. id_qmk_rgb_matrix_brightness = 1,
  113. id_qmk_rgb_matrix_effect = 2,
  114. id_qmk_rgb_matrix_effect_speed = 3,
  115. id_qmk_rgb_matrix_color = 4,
  116. };
  117. enum via_qmk_led_matrix_value {
  118. id_qmk_led_matrix_brightness = 1,
  119. id_qmk_led_matrix_effect = 2,
  120. id_qmk_led_matrix_effect_speed = 3,
  121. };
  122. enum via_qmk_audio_value {
  123. id_qmk_audio_enable = 1,
  124. id_qmk_audio_clicky_enable = 2,
  125. };
  126. // Can be called in an overriding via_init_kb() to test if keyboard level code usage of
  127. // EEPROM is invalid and use/save defaults.
  128. bool via_eeprom_is_valid(void);
  129. // Sets VIA/keyboard level usage of EEPROM to valid/invalid
  130. // Keyboard level code (eg. via_init_kb()) should not call this
  131. void via_eeprom_set_valid(bool valid);
  132. // Called by QMK core to initialize dynamic keymaps etc.
  133. void eeconfig_init_via(void);
  134. void via_init(void);
  135. // Used by VIA to store and retrieve the layout options.
  136. uint32_t via_get_layout_options(void);
  137. void via_set_layout_options(uint32_t value);
  138. void via_set_layout_options_kb(uint32_t value);
  139. // Used by VIA to tell a device to flash LEDs (or do something else) when that
  140. // device becomes the active device being configured, on startup or switching
  141. // between devices.
  142. void via_set_device_indication(uint8_t value);
  143. // Called by QMK core to process VIA-specific keycodes.
  144. bool process_record_via(uint16_t keycode, keyrecord_t *record);
  145. // These are made external so that keyboard level custom value handlers can use them.
  146. #if defined(BACKLIGHT_ENABLE)
  147. void via_qmk_backlight_command(uint8_t *data, uint8_t length);
  148. void via_qmk_backlight_set_value(uint8_t *data);
  149. void via_qmk_backlight_get_value(uint8_t *data);
  150. void via_qmk_backlight_save(void);
  151. #endif
  152. #if defined(RGBLIGHT_ENABLE)
  153. void via_qmk_rgblight_command(uint8_t *data, uint8_t length);
  154. void via_qmk_rgblight_set_value(uint8_t *data);
  155. void via_qmk_rgblight_get_value(uint8_t *data);
  156. void via_qmk_rgblight_save(void);
  157. #endif
  158. #if defined(RGB_MATRIX_ENABLE)
  159. void via_qmk_rgb_matrix_command(uint8_t *data, uint8_t length);
  160. void via_qmk_rgb_matrix_set_value(uint8_t *data);
  161. void via_qmk_rgb_matrix_get_value(uint8_t *data);
  162. void via_qmk_rgb_matrix_save(void);
  163. #endif
  164. #if defined(LED_MATRIX_ENABLE)
  165. void via_qmk_led_matrix_command(uint8_t *data, uint8_t length);
  166. void via_qmk_led_matrix_set_value(uint8_t *data);
  167. void via_qmk_led_matrix_get_value(uint8_t *data);
  168. void via_qmk_led_matrix_save(void);
  169. #endif
  170. #if defined(AUDIO_ENABLE)
  171. void via_qmk_audio_command(uint8_t *data, uint8_t length);
  172. void via_qmk_audio_set_value(uint8_t *data);
  173. void via_qmk_audio_get_value(uint8_t *data);
  174. void via_qmk_audio_save(void);
  175. #endif