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