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