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