aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/custom_quantum_functions.md140
-rw-r--r--keyboards/ergodox_ez/keymaps/rgb_layer/config.h24
-rw-r--r--keyboards/ergodox_ez/keymaps/rgb_layer/keymap.c271
-rw-r--r--quantum/quantum.c3
-rw-r--r--tmk_core/common/eeconfig.c103
-rw-r--r--tmk_core/common/eeconfig.h44
6 files changed, 545 insertions, 40 deletions
diff --git a/docs/custom_quantum_functions.md b/docs/custom_quantum_functions.md
index 10c5c75a2..f8b84cd6b 100644
--- a/docs/custom_quantum_functions.md
+++ b/docs/custom_quantum_functions.md
@@ -244,3 +244,143 @@ uint32_t layer_state_set_user(uint32_t state) {
244* Keymap: `uint32_t layer_state_set_user(uint32_t state)` 244* Keymap: `uint32_t layer_state_set_user(uint32_t state)`
245 245
246The `state` is the bitmask of the active layers, as explained in the [Keymap Overview](keymap.md#keymap-layer-status) 246The `state` is the bitmask of the active layers, as explained in the [Keymap Overview](keymap.md#keymap-layer-status)
247
248
249# Persistent Configuration (EEPROM)
250
251This allows you to configure persistent settings for your keyboard. These settings are stored in the EEPROM of your controller, and are retained even after power loss. The settings can be read with `eeconfig_read_kb` and `eeconfig_read_user`, and can be written to using `eeconfig_update_kb` and `eeconfig_update_user`. This is useful for features that you want to be able to toggle (like toggling rgb layer indication). Additionally, you can use `eeconfig_init_kb` and `eeconfig_init_user` to set the default values for the EEPROM.
252
253The complicated part here, is that there are a bunch of ways that you can store and access data via EEPROM, and there is no "correct" way to do this. However, you only have a DWORD (4 bytes) for each function.
254
255Keep in mind that EEPROM has a limited number of writes. While this is very high, it's not the only thing writing to the EEPROM, and if you write too often, you can potentially drastically shorten the life of your MCU.
256
257* If you don't understand the example, then you may want to avoid using this feature, as it is rather complicated.
258
259### Example Implementation
260
261This is an example of how to add settings, and read and write it. We're using the user keymap for the example here. This is a complex function, and has a lot going on. In fact, it uses a lot of the above functions to work!
262
263
264In your keymap.c file, add this to the top:
265```
266typedef union {
267 uint32_t raw;
268 struct {
269 bool rgb_layer_change :1;
270 };
271} user_config_t;
272
273user_config_t user_config;
274```
275
276This sets up a 32 bit structure that we can store settings with in memory, and write to the EEPROM. Using this removes the need to define variables, since they're defined in this structure. Remember that `bool` (boolean) values use 1 bit, `uint8_t` uses 8 bits, `uint16_t` uses up 16 bits. You can mix and match, but changing the order can cause issues, as it will change the values that are read and written.
277
278We're using `rgb_layer_change`, for the `layer_state_set_*` function, and use `matrix_init_user` and `process_record_user` to configure everything.
279
280Now, using the `matrix_init_user` code above, you want to add `eeconfig_read_user()` to it, to populate the structure you've just created. And you can then immediately use this structure to control functionality in your keymap. And It should look like:
281```
282void matrix_init_user(void) {
283 // Call the keymap level matrix init.
284
285 // Read the user config from EEPROM
286 user_config.raw = eeconfig_read_user();
287
288 // Set default layer, if enabled
289 if (user_config.rgb_layer_change) {
290 rgblight_enable_noeeprom();
291 rgblight_sethsv_noeeprom_cyan();
292 rgblight_mode_noeeprom(1);
293 }
294}
295```
296The above function will use the EEPROM config immediately after reading it, to set the default layer's RGB color. The "raw" value of it is converted in a usable structure based on the "union" that you created above.
297
298```
299uint32_t layer_state_set_user(uint32_t state) {
300 switch (biton32(state)) {
301 case _RAISE:
302 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_magenta(); rgblight_mode_noeeprom(1); }
303 break;
304 case _LOWER:
305 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_red(); rgblight_mode_noeeprom(1); }
306 break;
307 case _PLOVER:
308 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_green(); rgblight_mode_noeeprom(1); }
309 break;
310 case _ADJUST:
311 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_white(); rgblight_mode_noeeprom(1); }
312 break;
313 default: // for any other layers, or the default layer
314 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_cyan(); rgblight_mode_noeeprom(1); }
315 break;
316 }
317 return state;
318}
319```
320This will cause the RGB underglow to be changed ONLY if the value was enabled. Now to configure this value, create a new keycode for `process_record_user` called `RGB_LYR` and `EPRM`. Additionally, we want to make sure that if you use the normal RGB codes, that it turns off Using the example above, make it look this:
321```
322
323bool process_record_user(uint16_t keycode, keyrecord_t *record) {
324 switch (keycode) {
325 case FOO:
326 if (record->event.pressed) {
327 // Do something when pressed
328 } else {
329 // Do something else when release
330 }
331 return false; // Skip all further processing of this key
332 case KC_ENTER:
333 // Play a tone when enter is pressed
334 if (record->event.pressed) {
335 PLAY_NOTE_ARRAY(tone_qwerty);
336 }
337 return true; // Let QMK send the enter press/release events
338 case EPRM:
339 if (record->event.pressed) {
340 eeconfig_init(); // resets the EEPROM to default
341 }
342 return false;
343 case RGB_LYR: // This allows me to use underglow as layer indication, or as normal
344 if (record->event.pressed) {
345 user_config.rgb_layer_change ^= 1; // Toggles the status
346 eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
347 if (user_config.rgb_layer_change) { // if layer state indication is enabled,
348 layer_state_set(layer_state); // then immediately update the layer color
349 }
350 }
351 return false; break;
352 case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // For any of the RGB codes (see quantum_keycodes.h, L400 for reference)
353 if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
354 if (user_config.rgb_layer_change) { // only if this is enabled
355 user_config.rgb_layer_change = false; // disable it, and
356 eeconfig_update_user(user_config.raw); // write the setings to EEPROM
357 }
358 }
359 return true; break;
360 default:
361 return true; // Process all other keycodes normally
362 }
363}
364```
365And lastly, you want to add the `eeconfig_init_user` function, so that when the EEPROM is reset, you can specify default values, and even custom actions. For example, if you want to set rgb layer indication by default, and save the default valued.
366
367```
368void eeconfig_init_user(void) { // EEPROM is getting reset!
369 user_config.rgb_layer_change = true; // We want this enabled by default
370 eeconfig_update_user(user_config.raw); // Write default value to EEPROM now
371
372 // use the non noeeprom versions, to write these values to EEPROM too
373 rgblight_enable(); // Enable RGB by default
374 rgblight_sethsv_cyan(); // Set it to CYAN by default
375 rgblight_mode(1); // set to solid by default
376}
377```
378
379And you're done. The RGB layer indication will only work if you want it to. And it will be saved, even after unplugging the board. And if you use any of the RGB codes, it will disable the layer indication, so that it stays on the mode and color that you set it to.
380
381### 'EECONFIG' Function Documentation
382
383* Keyboard/Revision: `void eeconfig_init_kb(void)`, `uint32_t eeconfig_read_kb(void)` and `void eeconfig_update_kb(uint32_t val)`
384* Keymap: `void eeconfig_init_user(void)`, `uint32_t eeconfig_read_user(void)` and `void eeconfig_update_user(uint32_t val)`
385
386The `val` is the value of the data that you want to write to EEPROM. And the `eeconfig_read_*` function return a 32 bit (DWORD) value from the EEPROM.
diff --git a/keyboards/ergodox_ez/keymaps/rgb_layer/config.h b/keyboards/ergodox_ez/keymaps/rgb_layer/config.h
new file mode 100644
index 000000000..59302b800
--- /dev/null
+++ b/keyboards/ergodox_ez/keymaps/rgb_layer/config.h
@@ -0,0 +1,24 @@
1#ifndef KEYMAP_CONFIG_H
2#define KEYMAP_CONFIG_H
3
4
5 #define RGBLIGHT_SLEEP
6
7
8#ifndef QMK_KEYS_PER_SCAN
9#define QMK_KEYS_PER_SCAN 4
10#endif // !QMK_KEYS_PER_SCAN
11
12#define IGNORE_MOD_TAP_INTERRUPT
13#undef PERMISSIVE_HOLD
14#undef PREVENT_STUCK_MODIFIERS
15
16
17#define FORCE_NKRO
18
19#ifndef TAPPING_TOGGLE
20#define TAPPING_TOGGLE 1
21#endif
22
23#endif // !USERSPACE_CONFIG_H
24
diff --git a/keyboards/ergodox_ez/keymaps/rgb_layer/keymap.c b/keyboards/ergodox_ez/keymaps/rgb_layer/keymap.c
new file mode 100644
index 000000000..384d7d094
--- /dev/null
+++ b/keyboards/ergodox_ez/keymaps/rgb_layer/keymap.c
@@ -0,0 +1,271 @@
1#include QMK_KEYBOARD_H
2#include "version.h"
3
4#define BASE 0 // default layer
5#define SYMB 1 // symbols
6#define MDIA 2 // media keys
7
8enum custom_keycodes {
9 PLACEHOLDER = SAFE_RANGE, // can always be here
10 EPRM,
11 VRSN,
12 RGB_SLD,
13 RGB_LYR
14};
15
16typedef union {
17 uint32_t raw;
18 struct {
19 bool rgb_layer_change :1;
20 };
21} user_config_t;
22
23user_config_t user_config;
24
25const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
26/* Keymap 0: Basic layer
27 *
28 * ,--------------------------------------------------. ,--------------------------------------------------.
29 * | = | 1 | 2 | 3 | 4 | 5 | LEFT | | RIGHT| 6 | 7 | 8 | 9 | 0 | - |
30 * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
31 * | Del | Q | W | E | R | T | L1 | | L1 | Y | U | I | O | P | \ |
32 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
33 * | BkSp | A | S | D | F | G |------| |------| H | J | K | L |; / L2|' / Cmd |
34 * |--------+------+------+------+------+------| Hyper| | Meh |------+------+------+------+------+--------|
35 * | LShift |Z/Ctrl| X | C | V | B | | | | N | M | , | . |//Ctrl| RShift |
36 * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
37 * |Grv/L1| '" |AltShf| Left | Right| | Up | Down | [ | ] | ~L1 |
38 * `----------------------------------' `----------------------------------'
39 * ,-------------. ,-------------.
40 * | App | LGui | | Alt |Ctrl/Esc|
41 * ,------|------|------| |------+--------+------.
42 * | | | Home | | PgUp | | |
43 * | Space|Backsp|------| |------| Tab |Enter |
44 * | |ace | End | | PgDn | | |
45 * `--------------------' `----------------------'
46 */
47// If it accepts an argument (i.e, is a function), it doesn't need KC_.
48// Otherwise, it needs KC_*
49[BASE] = LAYOUT_ergodox( // layer 0 : default
50 // left hand
51 KC_EQL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT,
52 KC_DELT, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(SYMB),
53 KC_BSPC, KC_A, KC_S, KC_D, KC_F, KC_G,
54 KC_LSFT, CTL_T(KC_Z), KC_X, KC_C, KC_V, KC_B, ALL_T(KC_NO),
55 LT(SYMB,KC_GRV),KC_QUOT, LALT(KC_LSFT), KC_LEFT,KC_RGHT,
56 ALT_T(KC_APP), KC_LGUI,
57 KC_HOME,
58 KC_SPC,KC_BSPC,KC_END,
59 // right hand
60 KC_RGHT, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,
61 TG(SYMB), KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS,
62 KC_H, KC_J, KC_K, KC_L, LT(MDIA, KC_SCLN),GUI_T(KC_QUOT),
63 MEH_T(KC_NO),KC_N, KC_M, KC_COMM,KC_DOT, CTL_T(KC_SLSH), KC_RSFT,
64 KC_UP, KC_DOWN,KC_LBRC,KC_RBRC, TT(SYMB),
65 KC_LALT, CTL_T(KC_ESC),
66 KC_PGUP,
67 KC_PGDN,KC_TAB, KC_ENT
68 ),
69/* Keymap 1: Symbol Layer
70 *
71 * ,---------------------------------------------------. ,--------------------------------------------------.
72 * |Version | F1 | F2 | F3 | F4 | F5 | | | | F6 | F7 | F8 | F9 | F10 | F11 |
73 * |---------+------+------+------+------+------+------| |------+------+------+------+------+------+--------|
74 * | | ! | @ | { | } | | | | | | Up | 7 | 8 | 9 | * | F12 |
75 * |---------+------+------+------+------+------| | | |------+------+------+------+------+--------|
76 * | | # | $ | ( | ) | ` |------| |------| Down | 4 | 5 | 6 | + | |
77 * |---------+------+------+------+------+------| | | |------+------+------+------+------+--------|
78 * | | % | ^ | [ | ] | ~ | | | | & | 1 | 2 | 3 | \ | |
79 * `---------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
80 * | EPRM | | | | | | | . | 0 | = | |
81 * `-----------------------------------' `----------------------------------'
82 * ,-------------. ,-------------.
83 * |Animat| LYR | |Toggle|Solid |
84 * ,------|------|------| |------+------+------.
85 * |Bright|Bright| | | |Hue- |Hue+ |
86 * |ness- |ness+ |------| |------| | |
87 * | | | | | | | |
88 * `--------------------' `--------------------'
89 */
90// SYMBOLS
91[SYMB] = LAYOUT_ergodox(
92 // left hand
93 VRSN, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_TRNS,
94 RESET, KC_EXLM,KC_AT, KC_LCBR,KC_RCBR,KC_PIPE,KC_TRNS,
95 KC_TRNS,KC_HASH,KC_DLR, KC_LPRN,KC_RPRN,KC_GRV,
96 EPRM,KC_PERC,KC_CIRC,KC_LBRC,KC_RBRC,KC_TILD,KC_TRNS,
97 KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,
98 RGB_MOD,RGB_LYR,
99 KC_TRNS,
100 RGB_VAD,RGB_VAI,KC_TRNS,
101 // right hand
102 KC_TRNS, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
103 KC_TRNS, KC_UP, KC_7, KC_8, KC_9, KC_ASTR, KC_F12,
104 KC_DOWN, KC_4, KC_5, KC_6, KC_PLUS, KC_TRNS,
105 KC_TRNS, KC_AMPR, KC_1, KC_2, KC_3, KC_BSLS, KC_TRNS,
106 KC_TRNS,KC_DOT, KC_0, KC_EQL, KC_TRNS,
107 RGB_TOG, RGB_SLD,
108 KC_TRNS,
109 KC_TRNS, RGB_HUD, RGB_HUI
110),
111/* Keymap 2: Media and mouse keys
112 *
113 * ,--------------------------------------------------. ,--------------------------------------------------.
114 * | | | | | | | | | | | | | | | |
115 * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
116 * | | | | MsUp | | | | | | | | | | | |
117 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
118 * | | |MsLeft|MsDown|MsRght| |------| |------| | | | | | Play |
119 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
120 * | | | | | | | | | | | | Prev | Next | | |
121 * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
122 * | | | | Lclk | Rclk | |VolUp |VolDn | Mute | | |
123 * `----------------------------------' `----------------------------------'
124 * ,-------------. ,-------------.
125 * | | | | | |
126 * ,------|------|------| |------+------+------.
127 * | | | | | | |Brwser|
128 * | | |------| |------| |Back |
129 * | | | | | | | |
130 * `--------------------' `--------------------'
131 */
132// MEDIA AND MOUSE
133[MDIA] = LAYOUT_ergodox(
134 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
135 KC_TRNS, KC_TRNS, KC_TRNS, KC_MS_U, KC_TRNS, KC_TRNS, KC_TRNS,
136 KC_TRNS, KC_TRNS, KC_MS_L, KC_MS_D, KC_MS_R, KC_TRNS,
137 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
138 KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN1, KC_BTN2,
139 KC_TRNS, KC_TRNS,
140 KC_TRNS,
141 KC_TRNS, KC_TRNS, KC_TRNS,
142 // right hand
143 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
144 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
145 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY,
146 KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_TRNS, KC_TRNS,
147 KC_VOLU, KC_VOLD, KC_MUTE, KC_TRNS, KC_TRNS,
148 KC_TRNS, KC_TRNS,
149 KC_TRNS,
150 KC_TRNS, KC_TRNS, KC_WBAK
151),
152};
153
154void eeconfig_init_user(void) {
155 rgblight_enable();
156 rgblight_sethsv_cyan();
157 rgblight_mode(1);
158 user_config.rgb_layer_change = true;
159 eeconfig_update_user(user_config.raw);
160}
161
162
163bool process_record_user(uint16_t keycode, keyrecord_t *record) {
164 switch (keycode) {
165 // dynamically generate these.
166 case EPRM:
167 if (record->event.pressed) {
168 eeconfig_init();
169 }
170 return false;
171 break;
172 case VRSN:
173 if (record->event.pressed) {
174 SEND_STRING (QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION);
175 }
176 return false;
177 break;
178 case RGB_SLD:
179 if (record->event.pressed) {
180 #ifdef RGBLIGHT_ENABLE
181 rgblight_mode(1);
182 #endif
183 }
184 return false;
185 break;
186 case RGB_LYR: // This allows me to use underglow as layer indication, or as normal
187 if (record->event.pressed) {
188 user_config.rgb_layer_change ^= 1; // Toggles the status
189 eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
190 if (user_config.rgb_layer_change) { // if layer state indication is enabled,
191 layer_state_set(layer_state); // then immediately update the layer color
192 }
193 }
194 return false; break;
195 case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // For any of the RGB codes (see quantum_keycodes.h, L400 for reference)
196 if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
197 if (user_config.rgb_layer_change) { // only if this is enabled
198 user_config.rgb_layer_change = false; // disable it, and
199 eeconfig_update_user(user_config.raw); // write the setings to EEPROM
200 }
201 }
202 return true; break;
203 }
204 return true;
205}
206
207void matrix_init_user(void) {
208 // Call the keymap level matrix init.
209
210 // Read the user config from EEPROM
211 user_config.raw = eeconfig_read_user();
212
213 // Set default layer, if enabled
214 if (user_config.rgb_layer_change) {
215 rgblight_enable_noeeprom();
216 rgblight_sethsv_noeeprom_cyan();
217 rgblight_mode_noeeprom(1);
218 }
219}
220
221// Runs constantly in the background, in a loop.
222void matrix_scan_user(void) {
223
224};
225
226uint32_t layer_state_set_user(uint32_t state) {
227 ergodox_board_led_off();
228 ergodox_right_led_1_off();
229 ergodox_right_led_2_off();
230 ergodox_right_led_3_off();
231 switch (biton32(state)) {
232 case SYMB:
233 ergodox_right_led_1_on();
234 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_red(); rgblight_mode_noeeprom(1); }
235 break;
236 case MDIA:
237 ergodox_right_led_2_on();
238 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_green(); rgblight_mode_noeeprom(1); }
239 break;
240 case 3:
241 ergodox_right_led_3_on();
242 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_blue(); rgblight_mode_noeeprom(1); }
243 break;
244 case 4:
245 ergodox_right_led_1_on();
246 ergodox_right_led_2_on();
247 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_orange(); rgblight_mode_noeeprom(1); }
248 break;
249 case 5:
250 ergodox_right_led_1_on();
251 ergodox_right_led_3_on();
252 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_yellow(); rgblight_mode_noeeprom(1); }
253 break;
254 case 6:
255 ergodox_right_led_2_on();
256 ergodox_right_led_3_on();
257 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_pink(); rgblight_mode_noeeprom(1); }
258 break;
259 case 7:
260 ergodox_right_led_1_on();
261 ergodox_right_led_2_on();
262 ergodox_right_led_3_on();
263 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_white(); rgblight_mode_noeeprom(1); }
264 break;
265 default: // for any other layers, or the default layer
266 if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom_cyan(); rgblight_mode_noeeprom(1); }
267 break;
268 }
269 return state;
270}
271
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 84ccbdeab..eed59f811 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -945,6 +945,9 @@ void tap_random_base64(void) {
945} 945}
946 946
947void matrix_init_quantum() { 947void matrix_init_quantum() {
948 if (!eeconfig_is_enabled() && !eeconfig_is_disabled()) {
949 eeconfig_init();
950 }
948 #ifdef BACKLIGHT_ENABLE 951 #ifdef BACKLIGHT_ENABLE
949 backlight_init_ports(); 952 backlight_init_ports();
950 #endif 953 #endif
diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c
index 35de574a9..0fec410a9 100644
--- a/tmk_core/common/eeconfig.c
+++ b/tmk_core/common/eeconfig.c
@@ -8,32 +8,54 @@
8#include "eeprom_stm32.h" 8#include "eeprom_stm32.h"
9#endif 9#endif
10 10
11/** \brief eeconfig initialization 11extern uint32_t default_layer_state;
12/** \brief eeconfig enable
12 * 13 *
13 * FIXME: needs doc 14 * FIXME: needs doc
14 */ 15 */
15void eeconfig_init(void) 16__attribute__ ((weak))
16{ 17void eeconfig_init_user(void) {
18 // Reset user EEPROM value to blank, rather than to a set value
19 eeconfig_update_user(0);
20}
21
22__attribute__ ((weak))
23void eeconfig_init_kb(void) {
24 // Reset Keyboard EEPROM value to blank, rather than to a set value
25 eeconfig_update_kb(0);
26
27 eeconfig_init_user();
28}
29
30
31/*
32 * FIXME: needs doc
33 */
34void eeconfig_init_quantum(void) {
17#ifdef STM32F303xC 35#ifdef STM32F303xC
18 EEPROM_format(); 36 EEPROM_format();
19#endif 37#endif
20 eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); 38 eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
21 eeprom_update_byte(EECONFIG_DEBUG, 0); 39 eeprom_update_byte(EECONFIG_DEBUG, 0);
22 eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); 40 eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
23 eeprom_update_byte(EECONFIG_KEYMAP, 0); 41 default_layer_state = 0;
24 eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0); 42 eeprom_update_byte(EECONFIG_KEYMAP, 0);
25#ifdef BACKLIGHT_ENABLE 43 eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
26 eeprom_update_byte(EECONFIG_BACKLIGHT, 0); 44 eeprom_update_byte(EECONFIG_BACKLIGHT, 0);
27#endif 45 eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default
28#ifdef AUDIO_ENABLE 46 eeprom_update_dword(EECONFIG_RGBLIGHT, 0);
29 eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default 47 eeprom_update_byte(EECONFIG_STENOMODE, 0);
30#endif 48
31#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) 49 eeconfig_init_kb();
32 eeprom_update_dword(EECONFIG_RGBLIGHT, 0); 50}
33#endif 51
34#ifdef STENO_ENABLE 52/** \brief eeconfig initialization
35 eeprom_update_byte(EECONFIG_STENOMODE, 0); 53 *
36#endif 54 * FIXME: needs doc
55 */
56void eeconfig_init(void) {
57
58 eeconfig_init_quantum();
37} 59}
38 60
39/** \brief eeconfig enable 61/** \brief eeconfig enable
@@ -54,7 +76,7 @@ void eeconfig_disable(void)
54#ifdef STM32F303xC 76#ifdef STM32F303xC
55 EEPROM_format(); 77 EEPROM_format();
56#endif 78#endif
57 eeprom_update_word(EECONFIG_MAGIC, 0xFFFF); 79 eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
58} 80}
59 81
60/** \brief eeconfig is enabled 82/** \brief eeconfig is enabled
@@ -66,6 +88,15 @@ bool eeconfig_is_enabled(void)
66 return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); 88 return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
67} 89}
68 90
91/** \brief eeconfig is disabled
92 *
93 * FIXME: needs doc
94 */
95bool eeconfig_is_disabled(void)
96{
97 return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF);
98}
99
69/** \brief eeconfig read debug 100/** \brief eeconfig read debug
70 * 101 *
71 * FIXME: needs doc 102 * FIXME: needs doc
@@ -99,7 +130,6 @@ uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMA
99 */ 130 */
100void eeconfig_update_keymap(uint8_t val) { eeprom_update_byte(EECONFIG_KEYMAP, val); } 131void eeconfig_update_keymap(uint8_t val) { eeprom_update_byte(EECONFIG_KEYMAP, val); }
101 132
102#ifdef BACKLIGHT_ENABLE
103/** \brief eeconfig read backlight 133/** \brief eeconfig read backlight
104 * 134 *
105 * FIXME: needs doc 135 * FIXME: needs doc
@@ -110,9 +140,8 @@ uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BA
110 * FIXME: needs doc 140 * FIXME: needs doc
111 */ 141 */
112void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); } 142void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); }
113#endif
114 143
115#ifdef AUDIO_ENABLE 144
116/** \brief eeconfig read audio 145/** \brief eeconfig read audio
117 * 146 *
118 * FIXME: needs doc 147 * FIXME: needs doc
@@ -123,4 +152,28 @@ uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO)
123 * FIXME: needs doc 152 * FIXME: needs doc
124 */ 153 */
125void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); } 154void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); }
126#endif 155
156
157/** \brief eeconfig read kb
158 *
159 * FIXME: needs doc
160 */
161uint32_t eeconfig_read_kb(void) { return eeprom_read_dword(EECONFIG_KEYBOARD); }
162/** \brief eeconfig update kb
163 *
164 * FIXME: needs doc
165 */
166
167void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, val); }
168/** \brief eeconfig read user
169 *
170 * FIXME: needs doc
171 */
172uint32_t eeconfig_read_user(void) { return eeprom_read_dword(EECONFIG_USER); }
173/** \brief eeconfig update user
174 *
175 * FIXME: needs doc
176 */
177void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); }
178
179
diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h
index fa498df48..a45cb8b12 100644
--- a/tmk_core/common/eeconfig.h
+++ b/tmk_core/common/eeconfig.h
@@ -23,36 +23,41 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
23 23
24 24
25#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED 25#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED
26#define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF
26 27
27/* eeprom parameteter address */ 28/* eeprom parameteter address */
28#if !defined(STM32F303xC) 29#if !defined(STM32F303xC)
29#define EECONFIG_MAGIC (uint16_t *)0 30#define EECONFIG_MAGIC (uint16_t *)0
30#define EECONFIG_DEBUG (uint8_t *)2 31#define EECONFIG_DEBUG (uint8_t *)2
31#define EECONFIG_DEFAULT_LAYER (uint8_t *)3 32#define EECONFIG_DEFAULT_LAYER (uint8_t *)3
32#define EECONFIG_KEYMAP (uint8_t *)4 33#define EECONFIG_KEYMAP (uint8_t *)4
33#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 34#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5
34#define EECONFIG_BACKLIGHT (uint8_t *)6 35#define EECONFIG_BACKLIGHT (uint8_t *)6
35#define EECONFIG_AUDIO (uint8_t *)7 36#define EECONFIG_AUDIO (uint8_t *)7
36#define EECONFIG_RGBLIGHT (uint32_t *)8 37#define EECONFIG_RGBLIGHT (uint32_t *)8
37#define EECONFIG_UNICODEMODE (uint8_t *)12 38#define EECONFIG_UNICODEMODE (uint8_t *)12
38#define EECONFIG_STENOMODE (uint8_t *)13 39#define EECONFIG_STENOMODE (uint8_t *)13
39// EEHANDS for two handed boards 40// EEHANDS for two handed boards
40#define EECONFIG_HANDEDNESS (uint8_t *)14 41#define EECONFIG_HANDEDNESS (uint8_t *)14
42#define EECONFIG_KEYBOARD (uint32_t *)15
43#define EECONFIG_USER (uint32_t *)19
41 44
42#else 45#else
43/* STM32F3 uses 16byte block. Reconfigure memory map */ 46/* STM32F3 uses 16byte block. Reconfigure memory map */
44#define EECONFIG_MAGIC (uint16_t *)0 47#define EECONFIG_MAGIC (uint16_t *)0
45#define EECONFIG_DEBUG (uint8_t *)1 48#define EECONFIG_DEBUG (uint8_t *)1
46#define EECONFIG_DEFAULT_LAYER (uint8_t *)2 49#define EECONFIG_DEFAULT_LAYER (uint8_t *)2
47#define EECONFIG_KEYMAP (uint8_t *)3 50#define EECONFIG_KEYMAP (uint8_t *)3
48#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)4 51#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)4
49#define EECONFIG_BACKLIGHT (uint8_t *)5 52#define EECONFIG_BACKLIGHT (uint8_t *)5
50#define EECONFIG_AUDIO (uint8_t *)6 53#define EECONFIG_AUDIO (uint8_t *)6
51#define EECONFIG_RGBLIGHT (uint32_t *)7 54#define EECONFIG_RGBLIGHT (uint32_t *)7
52#define EECONFIG_UNICODEMODE (uint8_t *)9 55#define EECONFIG_UNICODEMODE (uint8_t *)9
53#define EECONFIG_STENOMODE (uint8_t *)10 56#define EECONFIG_STENOMODE (uint8_t *)10
54// EEHANDS for two handed boards 57// EEHANDS for two handed boards
55#define EECONFIG_HANDEDNESS (uint8_t *)11 58#define EECONFIG_HANDEDNESS (uint8_t *)11
59#define EECONFIG_KEYBOARD (uint32_t *)12
60#define EECONFIG_USER (uint32_t *)14
56#endif 61#endif
57 62
58/* debug bit */ 63/* debug bit */
@@ -73,8 +78,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
73 78
74 79
75bool eeconfig_is_enabled(void); 80bool eeconfig_is_enabled(void);
81bool eeconfig_is_disabled(void);
76 82
77void eeconfig_init(void); 83void eeconfig_init(void);
84void eeconfig_init_quantum(void);
85void eeconfig_init_kb(void);
86void eeconfig_init_user(void);
78 87
79void eeconfig_enable(void); 88void eeconfig_enable(void);
80 89
@@ -99,4 +108,9 @@ uint8_t eeconfig_read_audio(void);
99void eeconfig_update_audio(uint8_t val); 108void eeconfig_update_audio(uint8_t val);
100#endif 109#endif
101 110
111uint32_t eeconfig_read_kb(void);
112void eeconfig_update_kb(uint32_t val);
113uint32_t eeconfig_read_user(void);
114void eeconfig_update_user(uint32_t val);
115
102#endif 116#endif