aboutsummaryrefslogtreecommitdiff
path: root/quantum/eeconfig.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/eeconfig.c')
-rw-r--r--quantum/eeconfig.c211
1 files changed, 211 insertions, 0 deletions
diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c
new file mode 100644
index 000000000..ffa56ab56
--- /dev/null
+++ b/quantum/eeconfig.c
@@ -0,0 +1,211 @@
1#include <stdint.h>
2#include <stdbool.h>
3#include "eeprom.h"
4#include "eeconfig.h"
5#include "action_layer.h"
6
7#ifdef STM32_EEPROM_ENABLE
8# include <hal.h>
9# include "eeprom_stm32.h"
10#endif
11
12#if defined(EEPROM_DRIVER)
13# include "eeprom_driver.h"
14#endif
15
16#if defined(HAPTIC_ENABLE)
17# include "haptic.h"
18#endif
19
20/** \brief eeconfig enable
21 *
22 * FIXME: needs doc
23 */
24__attribute__((weak)) void eeconfig_init_user(void) {
25 // Reset user EEPROM value to blank, rather than to a set value
26 eeconfig_update_user(0);
27}
28
29__attribute__((weak)) void eeconfig_init_kb(void) {
30 // Reset Keyboard EEPROM value to blank, rather than to a set value
31 eeconfig_update_kb(0);
32
33 eeconfig_init_user();
34}
35
36/*
37 * FIXME: needs doc
38 */
39void eeconfig_init_quantum(void) {
40#ifdef STM32_EEPROM_ENABLE
41 EEPROM_Erase();
42#endif
43#if defined(EEPROM_DRIVER)
44 eeprom_driver_erase();
45#endif
46 eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
47 eeprom_update_byte(EECONFIG_DEBUG, 0);
48 eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
49 default_layer_state = 0;
50 eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0);
51 eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0);
52 eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
53 eeprom_update_byte(EECONFIG_BACKLIGHT, 0);
54 eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default
55 eeprom_update_dword(EECONFIG_RGBLIGHT, 0);
56 eeprom_update_byte(EECONFIG_STENOMODE, 0);
57 eeprom_update_dword(EECONFIG_HAPTIC, 0);
58 eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
59 eeprom_update_dword(EECONFIG_RGB_MATRIX, 0);
60 eeprom_update_word(EECONFIG_RGB_MATRIX_EXTENDED, 0);
61
62 // TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS
63 // within the emulated eeprom via dfu-util or another tool
64#if defined INIT_EE_HANDS_LEFT
65# pragma message "Faking EE_HANDS for left hand"
66 eeprom_update_byte(EECONFIG_HANDEDNESS, 1);
67#elif defined INIT_EE_HANDS_RIGHT
68# pragma message "Faking EE_HANDS for right hand"
69 eeprom_update_byte(EECONFIG_HANDEDNESS, 0);
70#endif
71
72#if defined(HAPTIC_ENABLE)
73 haptic_reset();
74#else
75 // this is used in case haptic is disabled, but we still want sane defaults
76 // in the haptic configuration eeprom. All zero will trigger a haptic_reset
77 // when a haptic-enabled firmware is loaded onto the keyboard.
78 eeprom_update_dword(EECONFIG_HAPTIC, 0);
79#endif
80
81 eeconfig_init_kb();
82}
83
84/** \brief eeconfig initialization
85 *
86 * FIXME: needs doc
87 */
88void eeconfig_init(void) { eeconfig_init_quantum(); }
89
90/** \brief eeconfig enable
91 *
92 * FIXME: needs doc
93 */
94void eeconfig_enable(void) { eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); }
95
96/** \brief eeconfig disable
97 *
98 * FIXME: needs doc
99 */
100void eeconfig_disable(void) {
101#ifdef STM32_EEPROM_ENABLE
102 EEPROM_Erase();
103#endif
104#if defined(EEPROM_DRIVER)
105 eeprom_driver_erase();
106#endif
107 eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
108}
109
110/** \brief eeconfig is enabled
111 *
112 * FIXME: needs doc
113 */
114bool eeconfig_is_enabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); }
115
116/** \brief eeconfig is disabled
117 *
118 * FIXME: needs doc
119 */
120bool eeconfig_is_disabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF); }
121
122/** \brief eeconfig read debug
123 *
124 * FIXME: needs doc
125 */
126uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }
127/** \brief eeconfig update debug
128 *
129 * FIXME: needs doc
130 */
131void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val); }
132
133/** \brief eeconfig read default layer
134 *
135 * FIXME: needs doc
136 */
137uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
138/** \brief eeconfig update default layer
139 *
140 * FIXME: needs doc
141 */
142void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); }
143
144/** \brief eeconfig read keymap
145 *
146 * FIXME: needs doc
147 */
148uint16_t eeconfig_read_keymap(void) { return (eeprom_read_byte(EECONFIG_KEYMAP_LOWER_BYTE) | (eeprom_read_byte(EECONFIG_KEYMAP_UPPER_BYTE) << 8)); }
149/** \brief eeconfig update keymap
150 *
151 * FIXME: needs doc
152 */
153void eeconfig_update_keymap(uint16_t val) {
154 eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, val & 0xFF);
155 eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, (val >> 8) & 0xFF);
156}
157
158/** \brief eeconfig read audio
159 *
160 * FIXME: needs doc
161 */
162uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); }
163/** \brief eeconfig update audio
164 *
165 * FIXME: needs doc
166 */
167void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); }
168
169/** \brief eeconfig read kb
170 *
171 * FIXME: needs doc
172 */
173uint32_t eeconfig_read_kb(void) { return eeprom_read_dword(EECONFIG_KEYBOARD); }
174/** \brief eeconfig update kb
175 *
176 * FIXME: needs doc
177 */
178void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, val); }
179
180/** \brief eeconfig read user
181 *
182 * FIXME: needs doc
183 */
184uint32_t eeconfig_read_user(void) { return eeprom_read_dword(EECONFIG_USER); }
185/** \brief eeconfig update user
186 *
187 * FIXME: needs doc
188 */
189void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); }
190
191/** \brief eeconfig read haptic
192 *
193 * FIXME: needs doc
194 */
195uint32_t eeconfig_read_haptic(void) { return eeprom_read_dword(EECONFIG_HAPTIC); }
196/** \brief eeconfig update haptic
197 *
198 * FIXME: needs doc
199 */
200void eeconfig_update_haptic(uint32_t val) { eeprom_update_dword(EECONFIG_HAPTIC, val); }
201
202/** \brief eeconfig read split handedness
203 *
204 * FIXME: needs doc
205 */
206bool eeconfig_read_handedness(void) { return !!eeprom_read_byte(EECONFIG_HANDEDNESS); }
207/** \brief eeconfig update split handedness
208 *
209 * FIXME: needs doc
210 */
211void eeconfig_update_handedness(bool val) { eeprom_update_byte(EECONFIG_HANDEDNESS, !!val); }