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