via.h 6.8 KB

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