]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/eeconfig.c
30dc7a48d4c711032ddee08812b33d0b9dc0b83b
[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 #ifdef EECONFIG_RGB_MATRIX
51   eeprom_update_dword(EECONFIG_RGB_MATRIX,    0);
52 #endif
53
54   eeconfig_init_kb();
55 }
56
57 /** \brief eeconfig initialization
58  *
59  * FIXME: needs doc
60  */
61 void eeconfig_init(void) {
62
63   eeconfig_init_quantum();
64 }
65
66 /** \brief eeconfig enable
67  *
68  * FIXME: needs doc
69  */
70 void eeconfig_enable(void)
71 {
72     eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
73 }
74
75 /** \brief eeconfig disable
76  *
77  * FIXME: needs doc
78  */
79 void eeconfig_disable(void)
80 {
81 #ifdef STM32_EEPROM_ENABLE
82     EEPROM_Erase();
83 #endif
84     eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
85 }
86
87 /** \brief eeconfig is enabled
88  *
89  * FIXME: needs doc
90  */
91 bool eeconfig_is_enabled(void)
92 {
93     return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
94 }
95
96 /** \brief eeconfig is disabled
97  *
98  * FIXME: needs doc
99  */
100 bool eeconfig_is_disabled(void)
101 {
102     return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF);
103 }
104
105 /** \brief eeconfig read debug
106  *
107  * FIXME: needs doc
108  */
109 uint8_t eeconfig_read_debug(void)      { return eeprom_read_byte(EECONFIG_DEBUG); }
110 /** \brief eeconfig update debug
111  *
112  * FIXME: needs doc
113  */
114 void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val); }
115
116 /** \brief eeconfig read default layer
117  *
118  * FIXME: needs doc
119  */
120 uint8_t eeconfig_read_default_layer(void)      { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
121 /** \brief eeconfig update default layer
122  *
123  * FIXME: needs doc
124  */
125 void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); }
126
127 /** \brief eeconfig read keymap
128  *
129  * FIXME: needs doc
130  */
131 uint8_t eeconfig_read_keymap(void)      { return eeprom_read_byte(EECONFIG_KEYMAP); }
132 /** \brief eeconfig update keymap
133  *
134  * FIXME: needs doc
135  */
136 void eeconfig_update_keymap(uint8_t val) { eeprom_update_byte(EECONFIG_KEYMAP, val); }
137
138 /** \brief eeconfig read backlight
139  *
140  * FIXME: needs doc
141  */
142 uint8_t eeconfig_read_backlight(void)      { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
143 /** \brief eeconfig update backlight
144  *
145  * FIXME: needs doc
146  */
147 void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); }
148
149
150 /** \brief eeconfig read audio
151  *
152  * FIXME: needs doc
153  */
154 uint8_t eeconfig_read_audio(void)      { return eeprom_read_byte(EECONFIG_AUDIO); }
155 /** \brief eeconfig update audio
156  *
157  * FIXME: needs doc
158  */
159 void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); }
160
161
162 /** \brief eeconfig read kb
163  *
164  * FIXME: needs doc
165  */
166 uint32_t eeconfig_read_kb(void)      { return eeprom_read_dword(EECONFIG_KEYBOARD); }
167 /** \brief eeconfig update kb
168  *
169  * FIXME: needs doc
170  */
171
172 void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, val); }
173 /** \brief eeconfig read user
174  *
175  * FIXME: needs doc
176  */
177 uint32_t eeconfig_read_user(void)      { return eeprom_read_dword(EECONFIG_USER); }
178 /** \brief eeconfig update user
179  *
180  * FIXME: needs doc
181  */
182 void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); }
183
184
185 uint32_t eeconfig_read_haptic(void)      { return eeprom_read_dword(EECONFIG_HAPTIC); }
186 /** \brief eeconfig update user
187  *
188  * FIXME: needs doc
189  */
190 void eeconfig_update_haptic(uint32_t val) { eeprom_update_dword(EECONFIG_HAPTIC, val); }