]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/eeconfig.c
Velocikey: Match RGB animation speed to typing speed (#3754)
[qmk_firmware.git] / tmk_core / common / eeconfig.c
1 #include <stdint.h>
2 #include <stdbool.h>
3 #include "eeprom.h"
4 #include "eeconfig.h"
5
6 #ifdef STM32_EEPROM_ENABLE
7 #include "hal.h"
8 #include "eeprom_stm32.h"
9 #endif
10
11 extern uint32_t default_layer_state;
12 /** \brief eeconfig enable
13  *
14  * FIXME: needs doc
15  */
16 __attribute__ ((weak))
17 void 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))
23 void 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  */
34 void eeconfig_init_quantum(void) {
35 #ifdef STM32_EEPROM_ENABLE
36     EEPROM_Erase();
37 #endif
38   eeprom_update_word(EECONFIG_MAGIC,          EECONFIG_MAGIC_NUMBER);
39   eeprom_update_byte(EECONFIG_DEBUG,          0);
40   eeprom_update_byte(EECONFIG_DEFAULT_LAYER,  0);
41   default_layer_state = 0;
42   eeprom_update_byte(EECONFIG_KEYMAP,         0);
43   eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
44   eeprom_update_byte(EECONFIG_BACKLIGHT,      0);
45   eeprom_update_byte(EECONFIG_AUDIO,             0xFF); // On by default
46   eeprom_update_dword(EECONFIG_RGBLIGHT,      0);
47   eeprom_update_byte(EECONFIG_STENOMODE,      0);
48   eeprom_update_dword(EECONFIG_HAPTIC,        0);
49   eeprom_update_byte(EECONFIG_VELOCIKEY,      0);
50
51   eeconfig_init_kb();
52 }
53
54 /** \brief eeconfig initialization
55  *
56  * FIXME: needs doc
57  */
58 void eeconfig_init(void) {
59
60   eeconfig_init_quantum();
61 }
62
63 /** \brief eeconfig enable
64  *
65  * FIXME: needs doc
66  */
67 void eeconfig_enable(void)
68 {
69     eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
70 }
71
72 /** \brief eeconfig disable
73  *
74  * FIXME: needs doc
75  */
76 void eeconfig_disable(void)
77 {
78 #ifdef STM32_EEPROM_ENABLE
79     EEPROM_Erase();
80 #endif
81     eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
82 }
83
84 /** \brief eeconfig is enabled
85  *
86  * FIXME: needs doc
87  */
88 bool eeconfig_is_enabled(void)
89 {
90     return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
91 }
92
93 /** \brief eeconfig is disabled
94  *
95  * FIXME: needs doc
96  */
97 bool eeconfig_is_disabled(void)
98 {
99     return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF);
100 }
101
102 /** \brief eeconfig read debug
103  *
104  * FIXME: needs doc
105  */
106 uint8_t eeconfig_read_debug(void)      { return eeprom_read_byte(EECONFIG_DEBUG); }
107 /** \brief eeconfig update debug
108  *
109  * FIXME: needs doc
110  */
111 void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val); }
112
113 /** \brief eeconfig read default layer
114  *
115  * FIXME: needs doc
116  */
117 uint8_t eeconfig_read_default_layer(void)      { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
118 /** \brief eeconfig update default layer
119  *
120  * FIXME: needs doc
121  */
122 void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); }
123
124 /** \brief eeconfig read keymap
125  *
126  * FIXME: needs doc
127  */
128 uint8_t eeconfig_read_keymap(void)      { return eeprom_read_byte(EECONFIG_KEYMAP); }
129 /** \brief eeconfig update keymap
130  *
131  * FIXME: needs doc
132  */
133 void eeconfig_update_keymap(uint8_t val) { eeprom_update_byte(EECONFIG_KEYMAP, val); }
134
135 /** \brief eeconfig read backlight
136  *
137  * FIXME: needs doc
138  */
139 uint8_t eeconfig_read_backlight(void)      { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
140 /** \brief eeconfig update backlight
141  *
142  * FIXME: needs doc
143  */
144 void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); }
145
146
147 /** \brief eeconfig read audio
148  *
149  * FIXME: needs doc
150  */
151 uint8_t eeconfig_read_audio(void)      { return eeprom_read_byte(EECONFIG_AUDIO); }
152 /** \brief eeconfig update audio
153  *
154  * FIXME: needs doc
155  */
156 void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); }
157
158
159 /** \brief eeconfig read kb
160  *
161  * FIXME: needs doc
162  */
163 uint32_t eeconfig_read_kb(void)      { return eeprom_read_dword(EECONFIG_KEYBOARD); }
164 /** \brief eeconfig update kb
165  *
166  * FIXME: needs doc
167  */
168
169 void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, val); }
170 /** \brief eeconfig read user
171  *
172  * FIXME: needs doc
173  */
174 uint32_t eeconfig_read_user(void)      { return eeprom_read_dword(EECONFIG_USER); }
175 /** \brief eeconfig update user
176  *
177  * FIXME: needs doc
178  */
179 void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); }
180
181
182 uint32_t eeconfig_read_haptic(void)      { return eeprom_read_dword(EECONFIG_HAPTIC); }
183 /** \brief eeconfig update user
184  *
185  * FIXME: needs doc
186  */
187 void eeconfig_update_haptic(uint32_t val) { eeprom_update_dword(EECONFIG_HAPTIC, val); }
188
189