diff options
Diffstat (limited to 'tmk_core/common')
84 files changed, 4036 insertions, 4324 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index f47fd20fc..1ba38a285 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c | |||
@@ -29,9 +29,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
29 | #include "wait.h" | 29 | #include "wait.h" |
30 | 30 | ||
31 | #ifdef DEBUG_ACTION | 31 | #ifdef DEBUG_ACTION |
32 | #include "debug.h" | 32 | # include "debug.h" |
33 | #else | 33 | #else |
34 | #include "nodebug.h" | 34 | # include "nodebug.h" |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | int tp_buttons; | 37 | int tp_buttons; |
@@ -41,24 +41,25 @@ int retro_tapping_counter = 0; | |||
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #ifdef FAUXCLICKY_ENABLE | 43 | #ifdef FAUXCLICKY_ENABLE |
44 | #include <fauxclicky.h> | 44 | # include <fauxclicky.h> |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | #ifndef TAP_CODE_DELAY | 47 | #ifndef TAP_CODE_DELAY |
48 | # define TAP_CODE_DELAY 0 | 48 | # define TAP_CODE_DELAY 0 |
49 | #endif | 49 | #endif |
50 | #ifndef TAP_HOLD_CAPS_DELAY | 50 | #ifndef TAP_HOLD_CAPS_DELAY |
51 | # define TAP_HOLD_CAPS_DELAY 80 | 51 | # define TAP_HOLD_CAPS_DELAY 80 |
52 | #endif | 52 | #endif |
53 | /** \brief Called to execute an action. | 53 | /** \brief Called to execute an action. |
54 | * | 54 | * |
55 | * FIXME: Needs documentation. | 55 | * FIXME: Needs documentation. |
56 | */ | 56 | */ |
57 | void action_exec(keyevent_t event) | 57 | void action_exec(keyevent_t event) { |
58 | { | ||
59 | if (!IS_NOEVENT(event)) { | 58 | if (!IS_NOEVENT(event)) { |
60 | dprint("\n---- action_exec: start -----\n"); | 59 | dprint("\n---- action_exec: start -----\n"); |
61 | dprint("EVENT: "); debug_event(event); dprintln(); | 60 | dprint("EVENT: "); |
61 | debug_event(event); | ||
62 | dprintln(); | ||
62 | #ifdef RETRO_TAPPING | 63 | #ifdef RETRO_TAPPING |
63 | retro_tapping_counter++; | 64 | retro_tapping_counter++; |
64 | #endif | 65 | #endif |
@@ -80,7 +81,7 @@ void action_exec(keyevent_t event) | |||
80 | } | 81 | } |
81 | #endif | 82 | #endif |
82 | 83 | ||
83 | keyrecord_t record = { .event = event }; | 84 | keyrecord_t record = {.event = event}; |
84 | 85 | ||
85 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 86 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
86 | if (has_oneshot_layer_timed_out()) { | 87 | if (has_oneshot_layer_timed_out()) { |
@@ -96,14 +97,16 @@ void action_exec(keyevent_t event) | |||
96 | #else | 97 | #else |
97 | process_record(&record); | 98 | process_record(&record); |
98 | if (!IS_NOEVENT(record.event)) { | 99 | if (!IS_NOEVENT(record.event)) { |
99 | dprint("processed: "); debug_record(record); dprintln(); | 100 | dprint("processed: "); |
101 | debug_record(record); | ||
102 | dprintln(); | ||
100 | } | 103 | } |
101 | #endif | 104 | #endif |
102 | } | 105 | } |
103 | 106 | ||
104 | #ifdef SWAP_HANDS_ENABLE | 107 | #ifdef SWAP_HANDS_ENABLE |
105 | bool swap_hands = false; | 108 | bool swap_hands = false; |
106 | bool swap_held = false; | 109 | bool swap_held = false; |
107 | 110 | ||
108 | /** \brief Process Hand Swap | 111 | /** \brief Process Hand Swap |
109 | * | 112 | * |
@@ -112,10 +115,9 @@ bool swap_held = false; | |||
112 | void process_hand_swap(keyevent_t *event) { | 115 | void process_hand_swap(keyevent_t *event) { |
113 | static swap_state_row_t swap_state[MATRIX_ROWS]; | 116 | static swap_state_row_t swap_state[MATRIX_ROWS]; |
114 | 117 | ||
115 | keypos_t pos = event->key; | 118 | keypos_t pos = event->key; |
116 | swap_state_row_t col_bit = (swap_state_row_t)1<<pos.col; | 119 | swap_state_row_t col_bit = (swap_state_row_t)1 << pos.col; |
117 | bool do_swap = event->pressed ? swap_hands : | 120 | bool do_swap = event->pressed ? swap_hands : swap_state[pos.row] & (col_bit); |
118 | swap_state[pos.row] & (col_bit); | ||
119 | 121 | ||
120 | if (do_swap) { | 122 | if (do_swap) { |
121 | event->key = hand_swap_config[pos.row][pos.col]; | 123 | event->key = hand_swap_config[pos.row][pos.col]; |
@@ -129,44 +131,36 @@ void process_hand_swap(keyevent_t *event) { | |||
129 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) | 131 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) |
130 | bool disable_action_cache = false; | 132 | bool disable_action_cache = false; |
131 | 133 | ||
132 | void process_record_nocache(keyrecord_t *record) | 134 | void process_record_nocache(keyrecord_t *record) { |
133 | { | ||
134 | disable_action_cache = true; | 135 | disable_action_cache = true; |
135 | process_record(record); | 136 | process_record(record); |
136 | disable_action_cache = false; | 137 | disable_action_cache = false; |
137 | } | 138 | } |
138 | #else | 139 | #else |
139 | void process_record_nocache(keyrecord_t *record) | 140 | void process_record_nocache(keyrecord_t *record) { process_record(record); } |
140 | { | ||
141 | process_record(record); | ||
142 | } | ||
143 | #endif | 141 | #endif |
144 | 142 | ||
145 | __attribute__ ((weak)) | 143 | __attribute__((weak)) bool process_record_quantum(keyrecord_t *record) { return true; } |
146 | bool process_record_quantum(keyrecord_t *record) { | ||
147 | return true; | ||
148 | } | ||
149 | 144 | ||
150 | #ifndef NO_ACTION_TAPPING | 145 | #ifndef NO_ACTION_TAPPING |
151 | /** \brief Allows for handling tap-hold actions immediately instead of waiting for TAPPING_TERM or another keypress. | 146 | /** \brief Allows for handling tap-hold actions immediately instead of waiting for TAPPING_TERM or another keypress. |
152 | * | 147 | * |
153 | * FIXME: Needs documentation. | 148 | * FIXME: Needs documentation. |
154 | */ | 149 | */ |
155 | void process_record_tap_hint(keyrecord_t *record) | 150 | void process_record_tap_hint(keyrecord_t *record) { |
156 | { | ||
157 | action_t action = layer_switch_get_action(record->event.key); | 151 | action_t action = layer_switch_get_action(record->event.key); |
158 | 152 | ||
159 | switch (action.kind.id) { | 153 | switch (action.kind.id) { |
160 | #ifdef SWAP_HANDS_ENABLE | 154 | # ifdef SWAP_HANDS_ENABLE |
161 | case ACT_SWAP_HANDS: | 155 | case ACT_SWAP_HANDS: |
162 | switch (action.swap.code) { | 156 | switch (action.swap.code) { |
163 | case OP_SH_TAP_TOGGLE: | 157 | case OP_SH_TAP_TOGGLE: |
164 | default: | 158 | default: |
165 | swap_hands = !swap_hands; | 159 | swap_hands = !swap_hands; |
166 | swap_held = true; | 160 | swap_held = true; |
167 | } | 161 | } |
168 | break; | 162 | break; |
169 | #endif | 163 | # endif |
170 | } | 164 | } |
171 | } | 165 | } |
172 | #endif | 166 | #endif |
@@ -175,18 +169,21 @@ void process_record_tap_hint(keyrecord_t *record) | |||
175 | * | 169 | * |
176 | * FIXME: Needs documentation. | 170 | * FIXME: Needs documentation. |
177 | */ | 171 | */ |
178 | void process_record(keyrecord_t *record) | 172 | void process_record(keyrecord_t *record) { |
179 | { | 173 | if (IS_NOEVENT(record->event)) { |
180 | if (IS_NOEVENT(record->event)) { return; } | ||
181 | |||
182 | if(!process_record_quantum(record)) | ||
183 | return; | 174 | return; |
175 | } | ||
176 | |||
177 | if (!process_record_quantum(record)) return; | ||
184 | 178 | ||
185 | action_t action = store_or_get_action(record->event.pressed, record->event.key); | 179 | action_t action = store_or_get_action(record->event.pressed, record->event.key); |
186 | dprint("ACTION: "); debug_action(action); | 180 | dprint("ACTION: "); |
181 | debug_action(action); | ||
187 | #ifndef NO_ACTION_LAYER | 182 | #ifndef NO_ACTION_LAYER |
188 | dprint(" layer_state: "); layer_debug(); | 183 | dprint(" layer_state: "); |
189 | dprint(" default_layer_state: "); default_layer_debug(); | 184 | layer_debug(); |
185 | dprint(" default_layer_state: "); | ||
186 | default_layer_debug(); | ||
190 | #endif | 187 | #endif |
191 | dprintln(); | 188 | dprintln(); |
192 | 189 | ||
@@ -197,8 +194,7 @@ void process_record(keyrecord_t *record) | |||
197 | * | 194 | * |
198 | * FIXME: Needs documentation. | 195 | * FIXME: Needs documentation. |
199 | */ | 196 | */ |
200 | void process_action(keyrecord_t *record, action_t action) | 197 | void process_action(keyrecord_t *record, action_t action) { |
201 | { | ||
202 | keyevent_t event = record->event; | 198 | keyevent_t event = record->event; |
203 | #ifndef NO_ACTION_TAPPING | 199 | #ifndef NO_ACTION_TAPPING |
204 | uint8_t tap_count = record->tap.count; | 200 | uint8_t tap_count = record->tap.count; |
@@ -221,131 +217,125 @@ void process_action(keyrecord_t *record, action_t action) | |||
221 | switch (action.kind.id) { | 217 | switch (action.kind.id) { |
222 | /* Key and Mods */ | 218 | /* Key and Mods */ |
223 | case ACT_LMODS: | 219 | case ACT_LMODS: |
224 | case ACT_RMODS: | 220 | case ACT_RMODS: { |
225 | { | 221 | uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods : action.key.mods << 4; |
226 | uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods : | 222 | if (event.pressed) { |
227 | action.key.mods<<4; | 223 | if (mods) { |
228 | if (event.pressed) { | 224 | if (IS_MOD(action.key.code) || action.key.code == KC_NO) { |
229 | if (mods) { | 225 | // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless. |
230 | if (IS_MOD(action.key.code) || action.key.code == KC_NO) { | 226 | // This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT). |
231 | // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless. | 227 | // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO). |
232 | // This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT). | 228 | add_mods(mods); |
233 | // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO). | 229 | } else { |
234 | add_mods(mods); | 230 | add_weak_mods(mods); |
235 | } else { | ||
236 | add_weak_mods(mods); | ||
237 | } | ||
238 | send_keyboard_report(); | ||
239 | } | 231 | } |
240 | register_code(action.key.code); | 232 | send_keyboard_report(); |
241 | } else { | 233 | } |
242 | unregister_code(action.key.code); | 234 | register_code(action.key.code); |
243 | if (mods) { | 235 | } else { |
244 | if (IS_MOD(action.key.code) || action.key.code == KC_NO) { | 236 | unregister_code(action.key.code); |
245 | del_mods(mods); | 237 | if (mods) { |
246 | } else { | 238 | if (IS_MOD(action.key.code) || action.key.code == KC_NO) { |
247 | del_weak_mods(mods); | 239 | del_mods(mods); |
248 | } | 240 | } else { |
249 | send_keyboard_report(); | 241 | del_weak_mods(mods); |
250 | } | 242 | } |
243 | send_keyboard_report(); | ||
251 | } | 244 | } |
252 | } | 245 | } |
253 | break; | 246 | } break; |
254 | #ifndef NO_ACTION_TAPPING | 247 | #ifndef NO_ACTION_TAPPING |
255 | case ACT_LMODS_TAP: | 248 | case ACT_LMODS_TAP: |
256 | case ACT_RMODS_TAP: | 249 | case ACT_RMODS_TAP: { |
257 | { | 250 | uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : action.key.mods << 4; |
258 | uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : | 251 | switch (action.layer_tap.code) { |
259 | action.key.mods<<4; | 252 | # ifndef NO_ACTION_ONESHOT |
260 | switch (action.layer_tap.code) { | 253 | case MODS_ONESHOT: |
261 | #ifndef NO_ACTION_ONESHOT | 254 | // Oneshot modifier |
262 | case MODS_ONESHOT: | 255 | if (event.pressed) { |
263 | // Oneshot modifier | 256 | if (tap_count == 0) { |
264 | if (event.pressed) { | 257 | dprint("MODS_TAP: Oneshot: 0\n"); |
265 | if (tap_count == 0) { | 258 | register_mods(mods | get_oneshot_mods()); |
266 | dprint("MODS_TAP: Oneshot: 0\n"); | 259 | } else if (tap_count == 1) { |
267 | register_mods(mods | get_oneshot_mods()); | 260 | dprint("MODS_TAP: Oneshot: start\n"); |
268 | } else if (tap_count == 1) { | 261 | set_oneshot_mods(mods | get_oneshot_mods()); |
269 | dprint("MODS_TAP: Oneshot: start\n"); | 262 | # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 |
270 | set_oneshot_mods(mods | get_oneshot_mods()); | 263 | } else if (tap_count == ONESHOT_TAP_TOGGLE) { |
271 | #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 | 264 | dprint("MODS_TAP: Toggling oneshot"); |
272 | } else if (tap_count == ONESHOT_TAP_TOGGLE) { | 265 | clear_oneshot_mods(); |
273 | dprint("MODS_TAP: Toggling oneshot"); | 266 | set_oneshot_locked_mods(mods); |
274 | clear_oneshot_mods(); | 267 | register_mods(mods); |
275 | set_oneshot_locked_mods(mods); | 268 | # endif |
276 | register_mods(mods); | ||
277 | #endif | ||
278 | } else { | ||
279 | register_mods(mods | get_oneshot_mods()); | ||
280 | } | ||
281 | } else { | 269 | } else { |
282 | if (tap_count == 0) { | 270 | register_mods(mods | get_oneshot_mods()); |
283 | clear_oneshot_mods(); | 271 | } |
284 | unregister_mods(mods); | 272 | } else { |
285 | } else if (tap_count == 1) { | 273 | if (tap_count == 0) { |
286 | // Retain Oneshot mods | 274 | clear_oneshot_mods(); |
287 | #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 | 275 | unregister_mods(mods); |
288 | if (mods & get_mods()) { | 276 | } else if (tap_count == 1) { |
289 | clear_oneshot_locked_mods(); | 277 | // Retain Oneshot mods |
290 | clear_oneshot_mods(); | 278 | # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 |
291 | unregister_mods(mods); | 279 | if (mods & get_mods()) { |
292 | } | 280 | clear_oneshot_locked_mods(); |
293 | } else if (tap_count == ONESHOT_TAP_TOGGLE) { | ||
294 | // Toggle Oneshot Layer | ||
295 | #endif | ||
296 | } else { | ||
297 | clear_oneshot_mods(); | 281 | clear_oneshot_mods(); |
298 | unregister_mods(mods); | 282 | unregister_mods(mods); |
299 | } | 283 | } |
284 | } else if (tap_count == ONESHOT_TAP_TOGGLE) { | ||
285 | // Toggle Oneshot Layer | ||
286 | # endif | ||
287 | } else { | ||
288 | clear_oneshot_mods(); | ||
289 | unregister_mods(mods); | ||
300 | } | 290 | } |
301 | break; | 291 | } |
302 | #endif | 292 | break; |
303 | case MODS_TAP_TOGGLE: | 293 | # endif |
304 | if (event.pressed) { | 294 | case MODS_TAP_TOGGLE: |
305 | if (tap_count <= TAPPING_TOGGLE) { | 295 | if (event.pressed) { |
296 | if (tap_count <= TAPPING_TOGGLE) { | ||
297 | register_mods(mods); | ||
298 | } | ||
299 | } else { | ||
300 | if (tap_count < TAPPING_TOGGLE) { | ||
301 | unregister_mods(mods); | ||
302 | } | ||
303 | } | ||
304 | break; | ||
305 | default: | ||
306 | if (event.pressed) { | ||
307 | if (tap_count > 0) { | ||
308 | # ifndef IGNORE_MOD_TAP_INTERRUPT | ||
309 | if (record->tap.interrupted) { | ||
310 | dprint("mods_tap: tap: cancel: add_mods\n"); | ||
311 | // ad hoc: set 0 to cancel tap | ||
312 | record->tap.count = 0; | ||
306 | register_mods(mods); | 313 | register_mods(mods); |
314 | } else | ||
315 | # endif | ||
316 | { | ||
317 | dprint("MODS_TAP: Tap: register_code\n"); | ||
318 | register_code(action.key.code); | ||
307 | } | 319 | } |
308 | } else { | 320 | } else { |
309 | if (tap_count < TAPPING_TOGGLE) { | 321 | dprint("MODS_TAP: No tap: add_mods\n"); |
310 | unregister_mods(mods); | 322 | register_mods(mods); |
311 | } | ||
312 | } | 323 | } |
313 | break; | 324 | } else { |
314 | default: | 325 | if (tap_count > 0) { |
315 | if (event.pressed) { | 326 | dprint("MODS_TAP: Tap: unregister_code\n"); |
316 | if (tap_count > 0) { | 327 | if (action.layer_tap.code == KC_CAPS) { |
317 | #ifndef IGNORE_MOD_TAP_INTERRUPT | 328 | wait_ms(TAP_HOLD_CAPS_DELAY); |
318 | if (record->tap.interrupted) { | ||
319 | dprint("mods_tap: tap: cancel: add_mods\n"); | ||
320 | // ad hoc: set 0 to cancel tap | ||
321 | record->tap.count = 0; | ||
322 | register_mods(mods); | ||
323 | } else | ||
324 | #endif | ||
325 | { | ||
326 | dprint("MODS_TAP: Tap: register_code\n"); | ||
327 | register_code(action.key.code); | ||
328 | } | ||
329 | } else { | ||
330 | dprint("MODS_TAP: No tap: add_mods\n"); | ||
331 | register_mods(mods); | ||
332 | } | 329 | } |
330 | unregister_code(action.key.code); | ||
333 | } else { | 331 | } else { |
334 | if (tap_count > 0) { | 332 | dprint("MODS_TAP: No tap: add_mods\n"); |
335 | dprint("MODS_TAP: Tap: unregister_code\n"); | 333 | unregister_mods(mods); |
336 | if (action.layer_tap.code == KC_CAPS) { | ||
337 | wait_ms(TAP_HOLD_CAPS_DELAY); | ||
338 | } | ||
339 | unregister_code(action.key.code); | ||
340 | } else { | ||
341 | dprint("MODS_TAP: No tap: add_mods\n"); | ||
342 | unregister_mods(mods); | ||
343 | } | ||
344 | } | 334 | } |
345 | break; | 335 | } |
346 | } | 336 | break; |
347 | } | 337 | } |
348 | break; | 338 | } break; |
349 | #endif | 339 | #endif |
350 | #ifdef EXTRAKEY_ENABLE | 340 | #ifdef EXTRAKEY_ENABLE |
351 | /* other HID usage */ | 341 | /* other HID usage */ |
@@ -374,13 +364,13 @@ void process_action(keyrecord_t *record, action_t action) | |||
374 | if (event.pressed) { | 364 | if (event.pressed) { |
375 | switch (action.key.code) { | 365 | switch (action.key.code) { |
376 | case KC_MS_BTN1: | 366 | case KC_MS_BTN1: |
377 | tp_buttons |= (1<<0); | 367 | tp_buttons |= (1 << 0); |
378 | break; | 368 | break; |
379 | case KC_MS_BTN2: | 369 | case KC_MS_BTN2: |
380 | tp_buttons |= (1<<1); | 370 | tp_buttons |= (1 << 1); |
381 | break; | 371 | break; |
382 | case KC_MS_BTN3: | 372 | case KC_MS_BTN3: |
383 | tp_buttons |= (1<<2); | 373 | tp_buttons |= (1 << 2); |
384 | break; | 374 | break; |
385 | default: | 375 | default: |
386 | break; | 376 | break; |
@@ -390,13 +380,13 @@ void process_action(keyrecord_t *record, action_t action) | |||
390 | } else { | 380 | } else { |
391 | switch (action.key.code) { | 381 | switch (action.key.code) { |
392 | case KC_MS_BTN1: | 382 | case KC_MS_BTN1: |
393 | tp_buttons &= ~(1<<0); | 383 | tp_buttons &= ~(1 << 0); |
394 | break; | 384 | break; |
395 | case KC_MS_BTN2: | 385 | case KC_MS_BTN2: |
396 | tp_buttons &= ~(1<<1); | 386 | tp_buttons &= ~(1 << 1); |
397 | break; | 387 | break; |
398 | case KC_MS_BTN3: | 388 | case KC_MS_BTN3: |
399 | tp_buttons &= ~(1<<2); | 389 | tp_buttons &= ~(1 << 2); |
400 | break; | 390 | break; |
401 | default: | 391 | default: |
402 | break; | 392 | break; |
@@ -411,28 +401,43 @@ void process_action(keyrecord_t *record, action_t action) | |||
411 | if (action.layer_bitop.on == 0) { | 401 | if (action.layer_bitop.on == 0) { |
412 | /* Default Layer Bitwise Operation */ | 402 | /* Default Layer Bitwise Operation */ |
413 | if (!event.pressed) { | 403 | if (!event.pressed) { |
414 | uint8_t shift = action.layer_bitop.part*4; | 404 | uint8_t shift = action.layer_bitop.part * 4; |
415 | layer_state_t bits = ((layer_state_t)action.layer_bitop.bits)<<shift; | 405 | layer_state_t bits = ((layer_state_t)action.layer_bitop.bits) << shift; |
416 | layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<<shift) : 0; | 406 | layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf) << shift) : 0; |
417 | switch (action.layer_bitop.op) { | 407 | switch (action.layer_bitop.op) { |
418 | case OP_BIT_AND: default_layer_and(bits | mask); break; | 408 | case OP_BIT_AND: |
419 | case OP_BIT_OR: default_layer_or(bits | mask); break; | 409 | default_layer_and(bits | mask); |
420 | case OP_BIT_XOR: default_layer_xor(bits | mask); break; | 410 | break; |
421 | case OP_BIT_SET: default_layer_set(bits | mask); break; | 411 | case OP_BIT_OR: |
412 | default_layer_or(bits | mask); | ||
413 | break; | ||
414 | case OP_BIT_XOR: | ||
415 | default_layer_xor(bits | mask); | ||
416 | break; | ||
417 | case OP_BIT_SET: | ||
418 | default_layer_set(bits | mask); | ||
419 | break; | ||
422 | } | 420 | } |
423 | } | 421 | } |
424 | } else { | 422 | } else { |
425 | /* Layer Bitwise Operation */ | 423 | /* Layer Bitwise Operation */ |
426 | if (event.pressed ? (action.layer_bitop.on & ON_PRESS) : | 424 | if (event.pressed ? (action.layer_bitop.on & ON_PRESS) : (action.layer_bitop.on & ON_RELEASE)) { |
427 | (action.layer_bitop.on & ON_RELEASE)) { | 425 | uint8_t shift = action.layer_bitop.part * 4; |
428 | uint8_t shift = action.layer_bitop.part*4; | 426 | layer_state_t bits = ((layer_state_t)action.layer_bitop.bits) << shift; |
429 | layer_state_t bits = ((layer_state_t)action.layer_bitop.bits)<<shift; | 427 | layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf) << shift) : 0; |
430 | layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<<shift) : 0; | ||
431 | switch (action.layer_bitop.op) { | 428 | switch (action.layer_bitop.op) { |
432 | case OP_BIT_AND: layer_and(bits | mask); break; | 429 | case OP_BIT_AND: |
433 | case OP_BIT_OR: layer_or(bits | mask); break; | 430 | layer_and(bits | mask); |
434 | case OP_BIT_XOR: layer_xor(bits | mask); break; | 431 | break; |
435 | case OP_BIT_SET: layer_state_set(bits | mask); break; | 432 | case OP_BIT_OR: |
433 | layer_or(bits | mask); | ||
434 | break; | ||
435 | case OP_BIT_XOR: | ||
436 | layer_xor(bits | mask); | ||
437 | break; | ||
438 | case OP_BIT_SET: | ||
439 | layer_state_set(bits | mask); | ||
440 | break; | ||
436 | } | 441 | } |
437 | } | 442 | } |
438 | } | 443 | } |
@@ -446,7 +451,7 @@ void process_action(keyrecord_t *record, action_t action) | |||
446 | layer_off(action.layer_mods.layer); | 451 | layer_off(action.layer_mods.layer); |
447 | } | 452 | } |
448 | break; | 453 | break; |
449 | #ifndef NO_ACTION_TAPPING | 454 | # ifndef NO_ACTION_TAPPING |
450 | case ACT_LAYER_TAP: | 455 | case ACT_LAYER_TAP: |
451 | case ACT_LAYER_TAP_EXT: | 456 | case ACT_LAYER_TAP_EXT: |
452 | switch (action.layer_tap.code) { | 457 | switch (action.layer_tap.code) { |
@@ -463,21 +468,18 @@ void process_action(keyrecord_t *record, action_t action) | |||
463 | } | 468 | } |
464 | break; | 469 | break; |
465 | case OP_ON_OFF: | 470 | case OP_ON_OFF: |
466 | event.pressed ? layer_on(action.layer_tap.val) : | 471 | event.pressed ? layer_on(action.layer_tap.val) : layer_off(action.layer_tap.val); |
467 | layer_off(action.layer_tap.val); | ||
468 | break; | 472 | break; |
469 | case OP_OFF_ON: | 473 | case OP_OFF_ON: |
470 | event.pressed ? layer_off(action.layer_tap.val) : | 474 | event.pressed ? layer_off(action.layer_tap.val) : layer_on(action.layer_tap.val); |
471 | layer_on(action.layer_tap.val); | ||
472 | break; | 475 | break; |
473 | case OP_SET_CLEAR: | 476 | case OP_SET_CLEAR: |
474 | event.pressed ? layer_move(action.layer_tap.val) : | 477 | event.pressed ? layer_move(action.layer_tap.val) : layer_clear(); |
475 | layer_clear(); | ||
476 | break; | 478 | break; |
477 | #ifndef NO_ACTION_ONESHOT | 479 | # ifndef NO_ACTION_ONESHOT |
478 | case OP_ONESHOT: | 480 | case OP_ONESHOT: |
479 | // Oneshot modifier | 481 | // Oneshot modifier |
480 | #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 | 482 | # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 |
481 | do_release_oneshot = false; | 483 | do_release_oneshot = false; |
482 | if (event.pressed) { | 484 | if (event.pressed) { |
483 | del_mods(get_oneshot_locked_mods()); | 485 | del_mods(get_oneshot_locked_mods()); |
@@ -499,7 +501,7 @@ void process_action(keyrecord_t *record, action_t action) | |||
499 | clear_oneshot_layer_state(ONESHOT_PRESSED); | 501 | clear_oneshot_layer_state(ONESHOT_PRESSED); |
500 | } | 502 | } |
501 | } | 503 | } |
502 | #else | 504 | # else |
503 | if (event.pressed) { | 505 | if (event.pressed) { |
504 | layer_on(action.layer_tap.val); | 506 | layer_on(action.layer_tap.val); |
505 | set_oneshot_layer(action.layer_tap.val, ONESHOT_START); | 507 | set_oneshot_layer(action.layer_tap.val, ONESHOT_START); |
@@ -509,9 +511,9 @@ void process_action(keyrecord_t *record, action_t action) | |||
509 | clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); | 511 | clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); |
510 | } | 512 | } |
511 | } | 513 | } |
512 | #endif | 514 | # endif |
513 | break; | 515 | break; |
514 | #endif | 516 | # endif |
515 | default: | 517 | default: |
516 | /* tap key */ | 518 | /* tap key */ |
517 | if (event.pressed) { | 519 | if (event.pressed) { |
@@ -529,7 +531,7 @@ void process_action(keyrecord_t *record, action_t action) | |||
529 | wait_ms(TAP_HOLD_CAPS_DELAY); | 531 | wait_ms(TAP_HOLD_CAPS_DELAY); |
530 | } else { | 532 | } else { |
531 | wait_ms(TAP_CODE_DELAY); | 533 | wait_ms(TAP_CODE_DELAY); |
532 | } | 534 | } |
533 | unregister_code(action.layer_tap.code); | 535 | unregister_code(action.layer_tap.code); |
534 | } else { | 536 | } else { |
535 | dprint("KEYMAP_TAP_KEY: No tap: Off on release\n"); | 537 | dprint("KEYMAP_TAP_KEY: No tap: Off on release\n"); |
@@ -539,9 +541,9 @@ void process_action(keyrecord_t *record, action_t action) | |||
539 | break; | 541 | break; |
540 | } | 542 | } |
541 | break; | 543 | break; |
542 | #endif | 544 | # endif |
543 | #endif | 545 | #endif |
544 | /* Extentions */ | 546 | /* Extentions */ |
545 | #ifndef NO_ACTION_MACRO | 547 | #ifndef NO_ACTION_MACRO |
546 | case ACT_MACRO: | 548 | case ACT_MACRO: |
547 | action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); | 549 | action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); |
@@ -599,7 +601,7 @@ void process_action(keyrecord_t *record, action_t action) | |||
599 | swap_hands = false; | 601 | swap_hands = false; |
600 | } | 602 | } |
601 | break; | 603 | break; |
602 | #ifndef NO_ACTION_TAPPING | 604 | # ifndef NO_ACTION_TAPPING |
603 | case OP_SH_TAP_TOGGLE: | 605 | case OP_SH_TAP_TOGGLE: |
604 | /* tap toggle */ | 606 | /* tap toggle */ |
605 | 607 | ||
@@ -619,23 +621,23 @@ void process_action(keyrecord_t *record, action_t action) | |||
619 | /* tap key */ | 621 | /* tap key */ |
620 | if (tap_count > 0) { | 622 | if (tap_count > 0) { |
621 | if (swap_held) { | 623 | if (swap_held) { |
622 | swap_hands = !swap_hands; // undo hold set up in _tap_hint | 624 | swap_hands = !swap_hands; // undo hold set up in _tap_hint |
623 | swap_held = false; | 625 | swap_held = false; |
624 | } | 626 | } |
625 | if (event.pressed) { | 627 | if (event.pressed) { |
626 | register_code(action.swap.code); | 628 | register_code(action.swap.code); |
627 | } else { | 629 | } else { |
628 | wait_ms(TAP_CODE_DELAY); | 630 | wait_ms(TAP_CODE_DELAY); |
629 | unregister_code(action.swap.code); | 631 | unregister_code(action.swap.code); |
630 | *record = (keyrecord_t){}; // hack: reset tap mode | 632 | *record = (keyrecord_t){}; // hack: reset tap mode |
631 | } | 633 | } |
632 | } else { | 634 | } else { |
633 | if (swap_held && !event.pressed) { | 635 | if (swap_held && !event.pressed) { |
634 | swap_hands = !swap_hands; // undo hold set up in _tap_hint | 636 | swap_hands = !swap_hands; // undo hold set up in _tap_hint |
635 | swap_held = false; | 637 | swap_held = false; |
636 | } | 638 | } |
637 | } | 639 | } |
638 | #endif | 640 | # endif |
639 | } | 641 | } |
640 | #endif | 642 | #endif |
641 | #ifndef NO_ACTION_FUNCTION | 643 | #ifndef NO_ACTION_FUNCTION |
@@ -652,10 +654,10 @@ void process_action(keyrecord_t *record, action_t action) | |||
652 | switch (action.kind.id) { | 654 | switch (action.kind.id) { |
653 | case ACT_LAYER: | 655 | case ACT_LAYER: |
654 | case ACT_LAYER_MODS: | 656 | case ACT_LAYER_MODS: |
655 | #ifndef NO_ACTION_TAPPING | 657 | # ifndef NO_ACTION_TAPPING |
656 | case ACT_LAYER_TAP: | 658 | case ACT_LAYER_TAP: |
657 | case ACT_LAYER_TAP_EXT: | 659 | case ACT_LAYER_TAP_EXT: |
658 | #endif | 660 | # endif |
659 | led_set(host_keyboard_leds()); | 661 | led_set(host_keyboard_leds()); |
660 | break; | 662 | break; |
661 | default: | 663 | default: |
@@ -664,35 +666,34 @@ void process_action(keyrecord_t *record, action_t action) | |||
664 | #endif | 666 | #endif |
665 | 667 | ||
666 | #ifndef NO_ACTION_TAPPING | 668 | #ifndef NO_ACTION_TAPPING |
667 | #ifdef RETRO_TAPPING | 669 | # ifdef RETRO_TAPPING |
668 | if (!is_tap_action(action)) { | 670 | if (!is_tap_action(action)) { |
669 | retro_tapping_counter = 0; | ||
670 | } else { | ||
671 | if (event.pressed) { | ||
672 | if (tap_count > 0) { | ||
673 | retro_tapping_counter = 0; | ||
674 | } else { | ||
675 | |||
676 | } | ||
677 | } else { | ||
678 | if (tap_count > 0) { | ||
679 | retro_tapping_counter = 0; | 671 | retro_tapping_counter = 0; |
680 | } else { | 672 | } else { |
681 | if (retro_tapping_counter == 2) { | 673 | if (event.pressed) { |
682 | tap_code(action.layer_tap.code); | 674 | if (tap_count > 0) { |
675 | retro_tapping_counter = 0; | ||
676 | } else { | ||
677 | } | ||
678 | } else { | ||
679 | if (tap_count > 0) { | ||
680 | retro_tapping_counter = 0; | ||
681 | } else { | ||
682 | if (retro_tapping_counter == 2) { | ||
683 | tap_code(action.layer_tap.code); | ||
684 | } | ||
685 | retro_tapping_counter = 0; | ||
686 | } | ||
683 | } | 687 | } |
684 | retro_tapping_counter = 0; | ||
685 | } | ||
686 | } | 688 | } |
687 | } | 689 | # endif |
688 | #endif | ||
689 | #endif | 690 | #endif |
690 | 691 | ||
691 | #ifndef NO_ACTION_ONESHOT | 692 | #ifndef NO_ACTION_ONESHOT |
692 | /* Because we switch layers after a oneshot event, we need to release the | 693 | /* Because we switch layers after a oneshot event, we need to release the |
693 | * key before we leave the layer or no key up event will be generated. | 694 | * key before we leave the layer or no key up event will be generated. |
694 | */ | 695 | */ |
695 | if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED ) ) { | 696 | if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED)) { |
696 | record->event.pressed = false; | 697 | record->event.pressed = false; |
697 | layer_on(get_oneshot_layer()); | 698 | layer_on(get_oneshot_layer()); |
698 | process_record(record); | 699 | process_record(record); |
@@ -701,25 +702,20 @@ void process_action(keyrecord_t *record, action_t action) | |||
701 | #endif | 702 | #endif |
702 | } | 703 | } |
703 | 704 | ||
704 | |||
705 | |||
706 | |||
707 | /** \brief Utilities for actions. (FIXME: Needs better description) | 705 | /** \brief Utilities for actions. (FIXME: Needs better description) |
708 | * | 706 | * |
709 | * FIXME: Needs documentation. | 707 | * FIXME: Needs documentation. |
710 | */ | 708 | */ |
711 | void register_code(uint8_t code) | 709 | void register_code(uint8_t code) { |
712 | { | ||
713 | if (code == KC_NO) { | 710 | if (code == KC_NO) { |
714 | return; | 711 | return; |
715 | } | 712 | } |
716 | |||
717 | #ifdef LOCKING_SUPPORT_ENABLE | 713 | #ifdef LOCKING_SUPPORT_ENABLE |
718 | else if (KC_LOCKING_CAPS == code) { | 714 | else if (KC_LOCKING_CAPS == code) { |
719 | #ifdef LOCKING_RESYNC_ENABLE | 715 | # ifdef LOCKING_RESYNC_ENABLE |
720 | // Resync: ignore if caps lock already is on | 716 | // Resync: ignore if caps lock already is on |
721 | if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return; | 717 | if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return; |
722 | #endif | 718 | # endif |
723 | add_key(KC_CAPSLOCK); | 719 | add_key(KC_CAPSLOCK); |
724 | send_keyboard_report(); | 720 | send_keyboard_report(); |
725 | wait_ms(100); | 721 | wait_ms(100); |
@@ -728,9 +724,9 @@ void register_code(uint8_t code) | |||
728 | } | 724 | } |
729 | 725 | ||
730 | else if (KC_LOCKING_NUM == code) { | 726 | else if (KC_LOCKING_NUM == code) { |
731 | #ifdef LOCKING_RESYNC_ENABLE | 727 | # ifdef LOCKING_RESYNC_ENABLE |
732 | if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return; | 728 | if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return; |
733 | #endif | 729 | # endif |
734 | add_key(KC_NUMLOCK); | 730 | add_key(KC_NUMLOCK); |
735 | send_keyboard_report(); | 731 | send_keyboard_report(); |
736 | wait_ms(100); | 732 | wait_ms(100); |
@@ -739,9 +735,9 @@ void register_code(uint8_t code) | |||
739 | } | 735 | } |
740 | 736 | ||
741 | else if (KC_LOCKING_SCROLL == code) { | 737 | else if (KC_LOCKING_SCROLL == code) { |
742 | #ifdef LOCKING_RESYNC_ENABLE | 738 | # ifdef LOCKING_RESYNC_ENABLE |
743 | if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return; | 739 | if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return; |
744 | #endif | 740 | # endif |
745 | add_key(KC_SCROLLLOCK); | 741 | add_key(KC_SCROLLLOCK); |
746 | send_keyboard_report(); | 742 | send_keyboard_report(); |
747 | wait_ms(100); | 743 | wait_ms(100); |
@@ -750,9 +746,10 @@ void register_code(uint8_t code) | |||
750 | } | 746 | } |
751 | #endif | 747 | #endif |
752 | 748 | ||
753 | else if IS_KEY(code) { | 749 | else if |
754 | // TODO: should push command_proc out of this block? | 750 | IS_KEY(code) { |
755 | if (command_proc(code)) return; | 751 | // TODO: should push command_proc out of this block? |
752 | if (command_proc(code)) return; | ||
756 | 753 | ||
757 | #ifndef NO_ACTION_ONESHOT | 754 | #ifndef NO_ACTION_ONESHOT |
758 | /* TODO: remove | 755 | /* TODO: remove |
@@ -769,46 +766,44 @@ void register_code(uint8_t code) | |||
769 | } else | 766 | } else |
770 | */ | 767 | */ |
771 | #endif | 768 | #endif |
772 | { | 769 | { |
773 | add_key(code); | 770 | add_key(code); |
771 | send_keyboard_report(); | ||
772 | } | ||
773 | } | ||
774 | else if | ||
775 | IS_MOD(code) { | ||
776 | add_mods(MOD_BIT(code)); | ||
774 | send_keyboard_report(); | 777 | send_keyboard_report(); |
775 | } | 778 | } |
776 | } | 779 | else if |
777 | else if IS_MOD(code) { | 780 | IS_SYSTEM(code) { host_system_send(KEYCODE2SYSTEM(code)); } |
778 | add_mods(MOD_BIT(code)); | 781 | else if |
779 | send_keyboard_report(); | 782 | IS_CONSUMER(code) { host_consumer_send(KEYCODE2CONSUMER(code)); } |
780 | } | ||
781 | else if IS_SYSTEM(code) { | ||
782 | host_system_send(KEYCODE2SYSTEM(code)); | ||
783 | } | ||
784 | else if IS_CONSUMER(code) { | ||
785 | host_consumer_send(KEYCODE2CONSUMER(code)); | ||
786 | } | ||
787 | 783 | ||
788 | #ifdef MOUSEKEY_ENABLE | 784 | #ifdef MOUSEKEY_ENABLE |
789 | else if IS_MOUSEKEY(code) { | 785 | else if |
790 | mousekey_on(code); | 786 | IS_MOUSEKEY(code) { |
791 | mousekey_send(); | 787 | mousekey_on(code); |
792 | } | 788 | mousekey_send(); |
793 | #endif | 789 | } |
790 | #endif | ||
794 | } | 791 | } |
795 | 792 | ||
796 | /** \brief Utilities for actions. (FIXME: Needs better description) | 793 | /** \brief Utilities for actions. (FIXME: Needs better description) |
797 | * | 794 | * |
798 | * FIXME: Needs documentation. | 795 | * FIXME: Needs documentation. |
799 | */ | 796 | */ |
800 | void unregister_code(uint8_t code) | 797 | void unregister_code(uint8_t code) { |
801 | { | ||
802 | if (code == KC_NO) { | 798 | if (code == KC_NO) { |
803 | return; | 799 | return; |
804 | } | 800 | } |
805 | |||
806 | #ifdef LOCKING_SUPPORT_ENABLE | 801 | #ifdef LOCKING_SUPPORT_ENABLE |
807 | else if (KC_LOCKING_CAPS == code) { | 802 | else if (KC_LOCKING_CAPS == code) { |
808 | #ifdef LOCKING_RESYNC_ENABLE | 803 | # ifdef LOCKING_RESYNC_ENABLE |
809 | // Resync: ignore if caps lock already is off | 804 | // Resync: ignore if caps lock already is off |
810 | if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return; | 805 | if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return; |
811 | #endif | 806 | # endif |
812 | add_key(KC_CAPSLOCK); | 807 | add_key(KC_CAPSLOCK); |
813 | send_keyboard_report(); | 808 | send_keyboard_report(); |
814 | del_key(KC_CAPSLOCK); | 809 | del_key(KC_CAPSLOCK); |
@@ -816,9 +811,9 @@ void unregister_code(uint8_t code) | |||
816 | } | 811 | } |
817 | 812 | ||
818 | else if (KC_LOCKING_NUM == code) { | 813 | else if (KC_LOCKING_NUM == code) { |
819 | #ifdef LOCKING_RESYNC_ENABLE | 814 | # ifdef LOCKING_RESYNC_ENABLE |
820 | if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return; | 815 | if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return; |
821 | #endif | 816 | # endif |
822 | add_key(KC_NUMLOCK); | 817 | add_key(KC_NUMLOCK); |
823 | send_keyboard_report(); | 818 | send_keyboard_report(); |
824 | del_key(KC_NUMLOCK); | 819 | del_key(KC_NUMLOCK); |
@@ -826,9 +821,9 @@ void unregister_code(uint8_t code) | |||
826 | } | 821 | } |
827 | 822 | ||
828 | else if (KC_LOCKING_SCROLL == code) { | 823 | else if (KC_LOCKING_SCROLL == code) { |
829 | #ifdef LOCKING_RESYNC_ENABLE | 824 | # ifdef LOCKING_RESYNC_ENABLE |
830 | if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return; | 825 | if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return; |
831 | #endif | 826 | # endif |
832 | add_key(KC_SCROLLLOCK); | 827 | add_key(KC_SCROLLLOCK); |
833 | send_keyboard_report(); | 828 | send_keyboard_report(); |
834 | del_key(KC_SCROLLLOCK); | 829 | del_key(KC_SCROLLLOCK); |
@@ -836,26 +831,27 @@ void unregister_code(uint8_t code) | |||
836 | } | 831 | } |
837 | #endif | 832 | #endif |
838 | 833 | ||
839 | else if IS_KEY(code) { | 834 | else if |
840 | del_key(code); | 835 | IS_KEY(code) { |
841 | send_keyboard_report(); | 836 | del_key(code); |
842 | } | 837 | send_keyboard_report(); |
843 | else if IS_MOD(code) { | 838 | } |
844 | del_mods(MOD_BIT(code)); | 839 | else if |
845 | send_keyboard_report(); | 840 | IS_MOD(code) { |
846 | } | 841 | del_mods(MOD_BIT(code)); |
847 | else if IS_SYSTEM(code) { | 842 | send_keyboard_report(); |
848 | host_system_send(0); | 843 | } |
849 | } | 844 | else if |
850 | else if IS_CONSUMER(code) { | 845 | IS_SYSTEM(code) { host_system_send(0); } |
851 | host_consumer_send(0); | 846 | else if |
852 | } | 847 | IS_CONSUMER(code) { host_consumer_send(0); } |
853 | #ifdef MOUSEKEY_ENABLE | 848 | #ifdef MOUSEKEY_ENABLE |
854 | else if IS_MOUSEKEY(code) { | 849 | else if |
855 | mousekey_off(code); | 850 | IS_MOUSEKEY(code) { |
856 | mousekey_send(); | 851 | mousekey_off(code); |
857 | } | 852 | mousekey_send(); |
858 | #endif | 853 | } |
854 | #endif | ||
859 | } | 855 | } |
860 | 856 | ||
861 | /** \brief Utilities for actions. (FIXME: Needs better description) | 857 | /** \brief Utilities for actions. (FIXME: Needs better description) |
@@ -863,21 +859,20 @@ void unregister_code(uint8_t code) | |||
863 | * FIXME: Needs documentation. | 859 | * FIXME: Needs documentation. |
864 | */ | 860 | */ |
865 | void tap_code(uint8_t code) { | 861 | void tap_code(uint8_t code) { |
866 | register_code(code); | 862 | register_code(code); |
867 | if (code == KC_CAPS) { | 863 | if (code == KC_CAPS) { |
868 | wait_ms(TAP_HOLD_CAPS_DELAY); | 864 | wait_ms(TAP_HOLD_CAPS_DELAY); |
869 | } else { | 865 | } else { |
870 | wait_ms(TAP_CODE_DELAY); | 866 | wait_ms(TAP_CODE_DELAY); |
871 | } | 867 | } |
872 | unregister_code(code); | 868 | unregister_code(code); |
873 | } | 869 | } |
874 | 870 | ||
875 | /** \brief Utilities for actions. (FIXME: Needs better description) | 871 | /** \brief Utilities for actions. (FIXME: Needs better description) |
876 | * | 872 | * |
877 | * FIXME: Needs documentation. | 873 | * FIXME: Needs documentation. |
878 | */ | 874 | */ |
879 | void register_mods(uint8_t mods) | 875 | void register_mods(uint8_t mods) { |
880 | { | ||
881 | if (mods) { | 876 | if (mods) { |
882 | add_mods(mods); | 877 | add_mods(mods); |
883 | send_keyboard_report(); | 878 | send_keyboard_report(); |
@@ -888,8 +883,7 @@ void register_mods(uint8_t mods) | |||
888 | * | 883 | * |
889 | * FIXME: Needs documentation. | 884 | * FIXME: Needs documentation. |
890 | */ | 885 | */ |
891 | void unregister_mods(uint8_t mods) | 886 | void unregister_mods(uint8_t mods) { |
892 | { | ||
893 | if (mods) { | 887 | if (mods) { |
894 | del_mods(mods); | 888 | del_mods(mods); |
895 | send_keyboard_report(); | 889 | send_keyboard_report(); |
@@ -900,8 +894,7 @@ void unregister_mods(uint8_t mods) | |||
900 | * | 894 | * |
901 | * FIXME: Needs documentation. | 895 | * FIXME: Needs documentation. |
902 | */ | 896 | */ |
903 | void clear_keyboard(void) | 897 | void clear_keyboard(void) { |
904 | { | ||
905 | clear_mods(); | 898 | clear_mods(); |
906 | clear_keyboard_but_mods(); | 899 | clear_keyboard_but_mods(); |
907 | } | 900 | } |
@@ -910,8 +903,7 @@ void clear_keyboard(void) | |||
910 | * | 903 | * |
911 | * FIXME: Needs documentation. | 904 | * FIXME: Needs documentation. |
912 | */ | 905 | */ |
913 | void clear_keyboard_but_mods(void) | 906 | void clear_keyboard_but_mods(void) { |
914 | { | ||
915 | clear_keys(); | 907 | clear_keys(); |
916 | clear_keyboard_but_mods_and_keys(); | 908 | clear_keyboard_but_mods_and_keys(); |
917 | } | 909 | } |
@@ -920,8 +912,7 @@ void clear_keyboard_but_mods(void) | |||
920 | * | 912 | * |
921 | * FIXME: Needs documentation. | 913 | * FIXME: Needs documentation. |
922 | */ | 914 | */ |
923 | void clear_keyboard_but_mods_and_keys() | 915 | void clear_keyboard_but_mods_and_keys() { |
924 | { | ||
925 | clear_weak_mods(); | 916 | clear_weak_mods(); |
926 | clear_macro_mods(); | 917 | clear_macro_mods(); |
927 | send_keyboard_report(); | 918 | send_keyboard_report(); |
@@ -939,8 +930,7 @@ void clear_keyboard_but_mods_and_keys() | |||
939 | * | 930 | * |
940 | * FIXME: Needs documentation. | 931 | * FIXME: Needs documentation. |
941 | */ | 932 | */ |
942 | bool is_tap_key(keypos_t key) | 933 | bool is_tap_key(keypos_t key) { |
943 | { | ||
944 | action_t action = layer_switch_get_action(key); | 934 | action_t action = layer_switch_get_action(key); |
945 | return is_tap_action(action); | 935 | return is_tap_action(action); |
946 | } | 936 | } |
@@ -949,8 +939,7 @@ bool is_tap_key(keypos_t key) | |||
949 | * | 939 | * |
950 | * FIXME: Needs documentation. | 940 | * FIXME: Needs documentation. |
951 | */ | 941 | */ |
952 | bool is_tap_action(action_t action) | 942 | bool is_tap_action(action_t action) { |
953 | { | ||
954 | switch (action.kind.id) { | 943 | switch (action.kind.id) { |
955 | case ACT_LMODS_TAP: | 944 | case ACT_LMODS_TAP: |
956 | case ACT_RMODS_TAP: | 945 | case ACT_RMODS_TAP: |
@@ -972,28 +961,25 @@ bool is_tap_action(action_t action) | |||
972 | return false; | 961 | return false; |
973 | case ACT_MACRO: | 962 | case ACT_MACRO: |
974 | case ACT_FUNCTION: | 963 | case ACT_FUNCTION: |
975 | if (action.func.opt & FUNC_TAP) { return true; } | 964 | if (action.func.opt & FUNC_TAP) { |
965 | return true; | ||
966 | } | ||
976 | return false; | 967 | return false; |
977 | } | 968 | } |
978 | return false; | 969 | return false; |
979 | } | 970 | } |
980 | 971 | ||
981 | |||
982 | /** \brief Debug print (FIXME: Needs better description) | 972 | /** \brief Debug print (FIXME: Needs better description) |
983 | * | 973 | * |
984 | * FIXME: Needs documentation. | 974 | * FIXME: Needs documentation. |
985 | */ | 975 | */ |
986 | void debug_event(keyevent_t event) | 976 | void debug_event(keyevent_t event) { dprintf("%04X%c(%u)", (event.key.row << 8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time); } |
987 | { | ||
988 | dprintf("%04X%c(%u)", (event.key.row<<8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time); | ||
989 | } | ||
990 | 977 | ||
991 | /** \brief Debug print (FIXME: Needs better description) | 978 | /** \brief Debug print (FIXME: Needs better description) |
992 | * | 979 | * |
993 | * FIXME: Needs documentation. | 980 | * FIXME: Needs documentation. |
994 | */ | 981 | */ |
995 | void debug_record(keyrecord_t record) | 982 | void debug_record(keyrecord_t record) { |
996 | { | ||
997 | debug_event(record.event); | 983 | debug_event(record.event); |
998 | #ifndef NO_ACTION_TAPPING | 984 | #ifndef NO_ACTION_TAPPING |
999 | dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' ')); | 985 | dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' ')); |
@@ -1004,24 +990,53 @@ void debug_record(keyrecord_t record) | |||
1004 | * | 990 | * |
1005 | * FIXME: Needs documentation. | 991 | * FIXME: Needs documentation. |
1006 | */ | 992 | */ |
1007 | void debug_action(action_t action) | 993 | void debug_action(action_t action) { |
1008 | { | ||
1009 | switch (action.kind.id) { | 994 | switch (action.kind.id) { |
1010 | case ACT_LMODS: dprint("ACT_LMODS"); break; | 995 | case ACT_LMODS: |
1011 | case ACT_RMODS: dprint("ACT_RMODS"); break; | 996 | dprint("ACT_LMODS"); |
1012 | case ACT_LMODS_TAP: dprint("ACT_LMODS_TAP"); break; | 997 | break; |
1013 | case ACT_RMODS_TAP: dprint("ACT_RMODS_TAP"); break; | 998 | case ACT_RMODS: |
1014 | case ACT_USAGE: dprint("ACT_USAGE"); break; | 999 | dprint("ACT_RMODS"); |
1015 | case ACT_MOUSEKEY: dprint("ACT_MOUSEKEY"); break; | 1000 | break; |
1016 | case ACT_LAYER: dprint("ACT_LAYER"); break; | 1001 | case ACT_LMODS_TAP: |
1017 | case ACT_LAYER_MODS: dprint("ACT_LAYER_MODS"); break; | 1002 | dprint("ACT_LMODS_TAP"); |
1018 | case ACT_LAYER_TAP: dprint("ACT_LAYER_TAP"); break; | 1003 | break; |
1019 | case ACT_LAYER_TAP_EXT: dprint("ACT_LAYER_TAP_EXT"); break; | 1004 | case ACT_RMODS_TAP: |
1020 | case ACT_MACRO: dprint("ACT_MACRO"); break; | 1005 | dprint("ACT_RMODS_TAP"); |
1021 | case ACT_COMMAND: dprint("ACT_COMMAND"); break; | 1006 | break; |
1022 | case ACT_FUNCTION: dprint("ACT_FUNCTION"); break; | 1007 | case ACT_USAGE: |
1023 | case ACT_SWAP_HANDS: dprint("ACT_SWAP_HANDS"); break; | 1008 | dprint("ACT_USAGE"); |
1024 | default: dprint("UNKNOWN"); break; | 1009 | break; |
1010 | case ACT_MOUSEKEY: | ||
1011 | dprint("ACT_MOUSEKEY"); | ||
1012 | break; | ||
1013 | case ACT_LAYER: | ||
1014 | dprint("ACT_LAYER"); | ||
1015 | break; | ||
1016 | case ACT_LAYER_MODS: | ||
1017 | dprint("ACT_LAYER_MODS"); | ||
1018 | break; | ||
1019 | case ACT_LAYER_TAP: | ||
1020 | dprint("ACT_LAYER_TAP"); | ||
1021 | break; | ||
1022 | case ACT_LAYER_TAP_EXT: | ||
1023 | dprint("ACT_LAYER_TAP_EXT"); | ||
1024 | break; | ||
1025 | case ACT_MACRO: | ||
1026 | dprint("ACT_MACRO"); | ||
1027 | break; | ||
1028 | case ACT_COMMAND: | ||
1029 | dprint("ACT_COMMAND"); | ||
1030 | break; | ||
1031 | case ACT_FUNCTION: | ||
1032 | dprint("ACT_FUNCTION"); | ||
1033 | break; | ||
1034 | case ACT_SWAP_HANDS: | ||
1035 | dprint("ACT_SWAP_HANDS"); | ||
1036 | break; | ||
1037 | default: | ||
1038 | dprint("UNKNOWN"); | ||
1039 | break; | ||
1025 | } | 1040 | } |
1026 | dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff); | 1041 | dprintf("[%X:%02X]", action.kind.param >> 8, action.kind.param & 0xff); |
1027 | } | 1042 | } |
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h index 799e3bb0e..633cedb06 100644 --- a/tmk_core/common/action.h +++ b/tmk_core/common/action.h | |||
@@ -24,23 +24,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
24 | #include "action_code.h" | 24 | #include "action_code.h" |
25 | #include "action_macro.h" | 25 | #include "action_macro.h" |
26 | 26 | ||
27 | |||
28 | #ifdef __cplusplus | 27 | #ifdef __cplusplus |
29 | extern "C" { | 28 | extern "C" { |
30 | #endif | 29 | #endif |
31 | 30 | ||
32 | /* tapping count and state */ | 31 | /* tapping count and state */ |
33 | typedef struct { | 32 | typedef struct { |
34 | bool interrupted :1; | 33 | bool interrupted : 1; |
35 | bool reserved2 :1; | 34 | bool reserved2 : 1; |
36 | bool reserved1 :1; | 35 | bool reserved1 : 1; |
37 | bool reserved0 :1; | 36 | bool reserved0 : 1; |
38 | uint8_t count :4; | 37 | uint8_t count : 4; |
39 | } tap_t; | 38 | } tap_t; |
40 | 39 | ||
41 | /* Key event container for recording */ | 40 | /* Key event container for recording */ |
42 | typedef struct { | 41 | typedef struct { |
43 | keyevent_t event; | 42 | keyevent_t event; |
44 | #ifndef NO_ACTION_TAPPING | 43 | #ifndef NO_ACTION_TAPPING |
45 | tap_t tap; | 44 | tap_t tap; |
46 | #endif | 45 | #endif |
@@ -68,17 +67,17 @@ extern bool disable_action_cache; | |||
68 | 67 | ||
69 | /* Code for handling one-handed key modifiers. */ | 68 | /* Code for handling one-handed key modifiers. */ |
70 | #ifdef SWAP_HANDS_ENABLE | 69 | #ifdef SWAP_HANDS_ENABLE |
71 | extern bool swap_hands; | 70 | extern bool swap_hands; |
72 | extern const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS]; | 71 | extern const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS]; |
73 | #if (MATRIX_COLS <= 8) | 72 | # if (MATRIX_COLS <= 8) |
74 | typedef uint8_t swap_state_row_t; | 73 | typedef uint8_t swap_state_row_t; |
75 | #elif (MATRIX_COLS <= 16) | 74 | # elif (MATRIX_COLS <= 16) |
76 | typedef uint16_t swap_state_row_t; | 75 | typedef uint16_t swap_state_row_t; |
77 | #elif (MATRIX_COLS <= 32) | 76 | # elif (MATRIX_COLS <= 32) |
78 | typedef uint32_t swap_state_row_t; | 77 | typedef uint32_t swap_state_row_t; |
79 | #else | 78 | # else |
80 | #error "MATRIX_COLS: invalid value" | 79 | # error "MATRIX_COLS: invalid value" |
81 | #endif | 80 | # endif |
82 | 81 | ||
83 | void process_hand_swap(keyevent_t *record); | 82 | void process_hand_swap(keyevent_t *record); |
84 | #endif | 83 | #endif |
@@ -91,7 +90,7 @@ void unregister_code(uint8_t code); | |||
91 | void tap_code(uint8_t code); | 90 | void tap_code(uint8_t code); |
92 | void register_mods(uint8_t mods); | 91 | void register_mods(uint8_t mods); |
93 | void unregister_mods(uint8_t mods); | 92 | void unregister_mods(uint8_t mods); |
94 | //void set_mods(uint8_t mods); | 93 | // void set_mods(uint8_t mods); |
95 | void clear_keyboard(void); | 94 | void clear_keyboard(void); |
96 | void clear_keyboard_but_mods(void); | 95 | void clear_keyboard_but_mods(void); |
97 | void clear_keyboard_but_mods_and_keys(void); | 96 | void clear_keyboard_but_mods_and_keys(void); |
@@ -112,4 +111,4 @@ void debug_action(action_t action); | |||
112 | } | 111 | } |
113 | #endif | 112 | #endif |
114 | 113 | ||
115 | #endif /* ACTION_H */ | 114 | #endif /* ACTION_H */ |
diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h index 5b5d0e566..03fcb3382 100644 --- a/tmk_core/common/action_code.h +++ b/tmk_core/common/action_code.h | |||
@@ -98,30 +98,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
98 | */ | 98 | */ |
99 | enum action_kind_id { | 99 | enum action_kind_id { |
100 | /* Key Actions */ | 100 | /* Key Actions */ |
101 | ACT_MODS = 0b0000, | 101 | ACT_MODS = 0b0000, |
102 | ACT_LMODS = 0b0000, | 102 | ACT_LMODS = 0b0000, |
103 | ACT_RMODS = 0b0001, | 103 | ACT_RMODS = 0b0001, |
104 | ACT_MODS_TAP = 0b0010, | 104 | ACT_MODS_TAP = 0b0010, |
105 | ACT_LMODS_TAP = 0b0010, | 105 | ACT_LMODS_TAP = 0b0010, |
106 | ACT_RMODS_TAP = 0b0011, | 106 | ACT_RMODS_TAP = 0b0011, |
107 | /* Other Keys */ | 107 | /* Other Keys */ |
108 | ACT_USAGE = 0b0100, | 108 | ACT_USAGE = 0b0100, |
109 | ACT_MOUSEKEY = 0b0101, | 109 | ACT_MOUSEKEY = 0b0101, |
110 | /* One-hand Support */ | 110 | /* One-hand Support */ |
111 | ACT_SWAP_HANDS = 0b0110, | 111 | ACT_SWAP_HANDS = 0b0110, |
112 | /* Layer Actions */ | 112 | /* Layer Actions */ |
113 | ACT_LAYER = 0b1000, | 113 | ACT_LAYER = 0b1000, |
114 | ACT_LAYER_MODS = 0b1001, | 114 | ACT_LAYER_MODS = 0b1001, |
115 | ACT_LAYER_TAP = 0b1010, /* Layer 0-15 */ | 115 | ACT_LAYER_TAP = 0b1010, /* Layer 0-15 */ |
116 | ACT_LAYER_TAP_EXT = 0b1011, /* Layer 16-31 */ | 116 | ACT_LAYER_TAP_EXT = 0b1011, /* Layer 16-31 */ |
117 | /* Extensions */ | 117 | /* Extensions */ |
118 | ACT_MACRO = 0b1100, | 118 | ACT_MACRO = 0b1100, |
119 | ACT_BACKLIGHT = 0b1101, | 119 | ACT_BACKLIGHT = 0b1101, |
120 | ACT_COMMAND = 0b1110, | 120 | ACT_COMMAND = 0b1110, |
121 | ACT_FUNCTION = 0b1111 | 121 | ACT_FUNCTION = 0b1111 |
122 | }; | 122 | }; |
123 | 123 | ||
124 | |||
125 | /** \brief Action Code Struct | 124 | /** \brief Action Code Struct |
126 | * | 125 | * |
127 | * NOTE: | 126 | * NOTE: |
@@ -139,66 +138,63 @@ enum action_kind_id { | |||
139 | typedef union { | 138 | typedef union { |
140 | uint16_t code; | 139 | uint16_t code; |
141 | struct action_kind { | 140 | struct action_kind { |
142 | uint16_t param :12; | 141 | uint16_t param : 12; |
143 | uint8_t id :4; | 142 | uint8_t id : 4; |
144 | } kind; | 143 | } kind; |
145 | struct action_key { | 144 | struct action_key { |
146 | uint8_t code :8; | 145 | uint8_t code : 8; |
147 | uint8_t mods :4; | 146 | uint8_t mods : 4; |
148 | uint8_t kind :4; | 147 | uint8_t kind : 4; |
149 | } key; | 148 | } key; |
150 | struct action_layer_bitop { | 149 | struct action_layer_bitop { |
151 | uint8_t bits :4; | 150 | uint8_t bits : 4; |
152 | uint8_t xbit :1; | 151 | uint8_t xbit : 1; |
153 | uint8_t part :3; | 152 | uint8_t part : 3; |
154 | uint8_t on :2; | 153 | uint8_t on : 2; |
155 | uint8_t op :2; | 154 | uint8_t op : 2; |
156 | uint8_t kind :4; | 155 | uint8_t kind : 4; |
157 | } layer_bitop; | 156 | } layer_bitop; |
158 | struct action_layer_mods | 157 | struct action_layer_mods { |
159 | { | 158 | uint8_t mods : 8; |
160 | uint8_t mods :8; | 159 | uint8_t layer : 4; |
161 | uint8_t layer :4; | 160 | uint8_t kind : 4; |
162 | uint8_t kind :4; | ||
163 | } layer_mods; | 161 | } layer_mods; |
164 | struct action_layer_tap { | 162 | struct action_layer_tap { |
165 | uint8_t code :8; | 163 | uint8_t code : 8; |
166 | uint8_t val :5; | 164 | uint8_t val : 5; |
167 | uint8_t kind :3; | 165 | uint8_t kind : 3; |
168 | } layer_tap; | 166 | } layer_tap; |
169 | struct action_usage { | 167 | struct action_usage { |
170 | uint16_t code :10; | 168 | uint16_t code : 10; |
171 | uint8_t page :2; | 169 | uint8_t page : 2; |
172 | uint8_t kind :4; | 170 | uint8_t kind : 4; |
173 | } usage; | 171 | } usage; |
174 | struct action_backlight { | 172 | struct action_backlight { |
175 | uint8_t level :8; | 173 | uint8_t level : 8; |
176 | uint8_t opt :4; | 174 | uint8_t opt : 4; |
177 | uint8_t kind :4; | 175 | uint8_t kind : 4; |
178 | } backlight; | 176 | } backlight; |
179 | struct action_command { | 177 | struct action_command { |
180 | uint8_t id :8; | 178 | uint8_t id : 8; |
181 | uint8_t opt :4; | 179 | uint8_t opt : 4; |
182 | uint8_t kind :4; | 180 | uint8_t kind : 4; |
183 | } command; | 181 | } command; |
184 | struct action_function { | 182 | struct action_function { |
185 | uint8_t id :8; | 183 | uint8_t id : 8; |
186 | uint8_t opt :4; | 184 | uint8_t opt : 4; |
187 | uint8_t kind :4; | 185 | uint8_t kind : 4; |
188 | } func; | 186 | } func; |
189 | struct action_swap { | 187 | struct action_swap { |
190 | uint8_t code :8; | 188 | uint8_t code : 8; |
191 | uint8_t opt :4; | 189 | uint8_t opt : 4; |
192 | uint8_t kind :4; | 190 | uint8_t kind : 4; |
193 | } swap; | 191 | } swap; |
194 | } action_t; | 192 | } action_t; |
195 | 193 | ||
196 | |||
197 | /* action utility */ | 194 | /* action utility */ |
198 | #define ACTION_NO 0 | 195 | #define ACTION_NO 0 |
199 | #define ACTION_TRANSPARENT 1 | 196 | #define ACTION_TRANSPARENT 1 |
200 | #define ACTION(kind, param) ((kind)<<12 | (param)) | 197 | #define ACTION(kind, param) ((kind) << 12 | (param)) |
201 | |||
202 | 198 | ||
203 | /** \brief Key Actions | 199 | /** \brief Key Actions |
204 | * | 200 | * |
@@ -220,35 +216,29 @@ enum mods_bit { | |||
220 | MOD_RGUI = 0x18, | 216 | MOD_RGUI = 0x18, |
221 | }; | 217 | }; |
222 | enum mods_codes { | 218 | enum mods_codes { |
223 | MODS_ONESHOT = 0x00, | 219 | MODS_ONESHOT = 0x00, |
224 | MODS_TAP_TOGGLE = 0x01, | 220 | MODS_TAP_TOGGLE = 0x01, |
225 | }; | 221 | }; |
226 | #define ACTION_KEY(key) ACTION(ACT_MODS, (key)) | 222 | #define ACTION_KEY(key) ACTION(ACT_MODS, (key)) |
227 | #define ACTION_MODS(mods) ACTION(ACT_MODS, ((mods)&0x1f)<<8 | 0) | 223 | #define ACTION_MODS(mods) ACTION(ACT_MODS, ((mods)&0x1f) << 8 | 0) |
228 | #define ACTION_MODS_KEY(mods, key) ACTION(ACT_MODS, ((mods)&0x1f)<<8 | (key)) | 224 | #define ACTION_MODS_KEY(mods, key) ACTION(ACT_MODS, ((mods)&0x1f) << 8 | (key)) |
229 | #define ACTION_MODS_TAP_KEY(mods, key) ACTION(ACT_MODS_TAP, ((mods)&0x1f)<<8 | (key)) | 225 | #define ACTION_MODS_TAP_KEY(mods, key) ACTION(ACT_MODS_TAP, ((mods)&0x1f) << 8 | (key)) |
230 | #define ACTION_MODS_ONESHOT(mods) ACTION(ACT_MODS_TAP, ((mods)&0x1f)<<8 | MODS_ONESHOT) | 226 | #define ACTION_MODS_ONESHOT(mods) ACTION(ACT_MODS_TAP, ((mods)&0x1f) << 8 | MODS_ONESHOT) |
231 | #define ACTION_MODS_TAP_TOGGLE(mods) ACTION(ACT_MODS_TAP, ((mods)&0x1f)<<8 | MODS_TAP_TOGGLE) | 227 | #define ACTION_MODS_TAP_TOGGLE(mods) ACTION(ACT_MODS_TAP, ((mods)&0x1f) << 8 | MODS_TAP_TOGGLE) |
232 | |||
233 | 228 | ||
234 | /** \brief Other Keys | 229 | /** \brief Other Keys |
235 | */ | 230 | */ |
236 | enum usage_pages { | 231 | enum usage_pages { PAGE_SYSTEM, PAGE_CONSUMER }; |
237 | PAGE_SYSTEM, | 232 | #define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM << 10 | (id)) |
238 | PAGE_CONSUMER | 233 | #define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER << 10 | (id)) |
239 | }; | 234 | #define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key) |
240 | #define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM<<10 | (id)) | ||
241 | #define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER<<10 | (id)) | ||
242 | #define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key) | ||
243 | |||
244 | |||
245 | 235 | ||
246 | /** \brief Layer Actions | 236 | /** \brief Layer Actions |
247 | */ | 237 | */ |
248 | enum layer_param_on { | 238 | enum layer_param_on { |
249 | ON_PRESS = 1, | 239 | ON_PRESS = 1, |
250 | ON_RELEASE = 2, | 240 | ON_RELEASE = 2, |
251 | ON_BOTH = 3, | 241 | ON_BOTH = 3, |
252 | }; | 242 | }; |
253 | 243 | ||
254 | /** \brief Layer Actions | 244 | /** \brief Layer Actions |
@@ -269,37 +259,36 @@ enum layer_param_tap_op { | |||
269 | OP_SET_CLEAR, | 259 | OP_SET_CLEAR, |
270 | OP_ONESHOT, | 260 | OP_ONESHOT, |
271 | }; | 261 | }; |
272 | #define ACTION_LAYER_BITOP(op, part, bits, on) ACTION(ACT_LAYER, (op)<<10 | (on)<<8 | (part)<<5 | ((bits)&0x1f)) | 262 | #define ACTION_LAYER_BITOP(op, part, bits, on) ACTION(ACT_LAYER, (op) << 10 | (on) << 8 | (part) << 5 | ((bits)&0x1f)) |
273 | #define ACTION_LAYER_TAP(layer, key) ACTION(ACT_LAYER_TAP, (layer)<<8 | (key)) | 263 | #define ACTION_LAYER_TAP(layer, key) ACTION(ACT_LAYER_TAP, (layer) << 8 | (key)) |
274 | /* Default Layer */ | 264 | /* Default Layer */ |
275 | #define ACTION_DEFAULT_LAYER_SET(layer) ACTION_DEFAULT_LAYER_BIT_SET((layer)/4, 1<<((layer)%4)) | 265 | #define ACTION_DEFAULT_LAYER_SET(layer) ACTION_DEFAULT_LAYER_BIT_SET((layer) / 4, 1 << ((layer) % 4)) |
276 | /* Layer Operation */ | 266 | /* Layer Operation */ |
277 | #define ACTION_LAYER_CLEAR(on) ACTION_LAYER_BIT_AND(0, 0, (on)) | 267 | #define ACTION_LAYER_CLEAR(on) ACTION_LAYER_BIT_AND(0, 0, (on)) |
278 | #define ACTION_LAYER_MOMENTARY(layer) ACTION_LAYER_ON_OFF(layer) | 268 | #define ACTION_LAYER_MOMENTARY(layer) ACTION_LAYER_ON_OFF(layer) |
279 | #define ACTION_LAYER_TOGGLE(layer) ACTION_LAYER_INVERT(layer, ON_RELEASE) | 269 | #define ACTION_LAYER_TOGGLE(layer) ACTION_LAYER_INVERT(layer, ON_RELEASE) |
280 | #define ACTION_LAYER_INVERT(layer, on) ACTION_LAYER_BIT_XOR((layer)/4, 1<<((layer)%4), (on)) | 270 | #define ACTION_LAYER_INVERT(layer, on) ACTION_LAYER_BIT_XOR((layer) / 4, 1 << ((layer) % 4), (on)) |
281 | #define ACTION_LAYER_ON(layer, on) ACTION_LAYER_BIT_OR( (layer)/4, 1<<((layer)%4), (on)) | 271 | #define ACTION_LAYER_ON(layer, on) ACTION_LAYER_BIT_OR((layer) / 4, 1 << ((layer) % 4), (on)) |
282 | #define ACTION_LAYER_OFF(layer, on) ACTION_LAYER_BIT_AND((layer)/4, ~(1<<((layer)%4)), (on)) | 272 | #define ACTION_LAYER_OFF(layer, on) ACTION_LAYER_BIT_AND((layer) / 4, ~(1 << ((layer) % 4)), (on)) |
283 | #define ACTION_LAYER_SET(layer, on) ACTION_LAYER_BIT_SET((layer)/4, 1<<((layer)%4), (on)) | 273 | #define ACTION_LAYER_SET(layer, on) ACTION_LAYER_BIT_SET((layer) / 4, 1 << ((layer) % 4), (on)) |
284 | #define ACTION_LAYER_ON_OFF(layer) ACTION_LAYER_TAP((layer), OP_ON_OFF) | 274 | #define ACTION_LAYER_ON_OFF(layer) ACTION_LAYER_TAP((layer), OP_ON_OFF) |
285 | #define ACTION_LAYER_OFF_ON(layer) ACTION_LAYER_TAP((layer), OP_OFF_ON) | 275 | #define ACTION_LAYER_OFF_ON(layer) ACTION_LAYER_TAP((layer), OP_OFF_ON) |
286 | #define ACTION_LAYER_SET_CLEAR(layer) ACTION_LAYER_TAP((layer), OP_SET_CLEAR) | 276 | #define ACTION_LAYER_SET_CLEAR(layer) ACTION_LAYER_TAP((layer), OP_SET_CLEAR) |
287 | #define ACTION_LAYER_ONESHOT(layer) ACTION_LAYER_TAP((layer), OP_ONESHOT) | 277 | #define ACTION_LAYER_ONESHOT(layer) ACTION_LAYER_TAP((layer), OP_ONESHOT) |
288 | #define ACTION_LAYER_MODS(layer, mods) ACTION(ACT_LAYER_MODS, (layer) << 8 | (mods)) | 278 | #define ACTION_LAYER_MODS(layer, mods) ACTION(ACT_LAYER_MODS, (layer) << 8 | (mods)) |
289 | /* With Tapping */ | 279 | /* With Tapping */ |
290 | #define ACTION_LAYER_TAP_KEY(layer, key) ACTION_LAYER_TAP((layer), (key)) | 280 | #define ACTION_LAYER_TAP_KEY(layer, key) ACTION_LAYER_TAP((layer), (key)) |
291 | #define ACTION_LAYER_TAP_TOGGLE(layer) ACTION_LAYER_TAP((layer), OP_TAP_TOGGLE) | 281 | #define ACTION_LAYER_TAP_TOGGLE(layer) ACTION_LAYER_TAP((layer), OP_TAP_TOGGLE) |
292 | /* Bitwise Operation */ | 282 | /* Bitwise Operation */ |
293 | #define ACTION_LAYER_BIT_AND(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_AND, (part), (bits), (on)) | 283 | #define ACTION_LAYER_BIT_AND(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_AND, (part), (bits), (on)) |
294 | #define ACTION_LAYER_BIT_OR( part, bits, on) ACTION_LAYER_BITOP(OP_BIT_OR, (part), (bits), (on)) | 284 | #define ACTION_LAYER_BIT_OR(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_OR, (part), (bits), (on)) |
295 | #define ACTION_LAYER_BIT_XOR(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), (on)) | 285 | #define ACTION_LAYER_BIT_XOR(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), (on)) |
296 | #define ACTION_LAYER_BIT_SET(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), (on)) | 286 | #define ACTION_LAYER_BIT_SET(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), (on)) |
297 | /* Default Layer Bitwise Operation */ | 287 | /* Default Layer Bitwise Operation */ |
298 | #define ACTION_DEFAULT_LAYER_BIT_AND(part, bits) ACTION_LAYER_BITOP(OP_BIT_AND, (part), (bits), 0) | 288 | #define ACTION_DEFAULT_LAYER_BIT_AND(part, bits) ACTION_LAYER_BITOP(OP_BIT_AND, (part), (bits), 0) |
299 | #define ACTION_DEFAULT_LAYER_BIT_OR( part, bits) ACTION_LAYER_BITOP(OP_BIT_OR, (part), (bits), 0) | 289 | #define ACTION_DEFAULT_LAYER_BIT_OR(part, bits) ACTION_LAYER_BITOP(OP_BIT_OR, (part), (bits), 0) |
300 | #define ACTION_DEFAULT_LAYER_BIT_XOR(part, bits) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), 0) | 290 | #define ACTION_DEFAULT_LAYER_BIT_XOR(part, bits) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), 0) |
301 | #define ACTION_DEFAULT_LAYER_BIT_SET(part, bits) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), 0) | 291 | #define ACTION_DEFAULT_LAYER_BIT_SET(part, bits) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), 0) |
302 | |||
303 | 292 | ||
304 | /** \brief Extensions | 293 | /** \brief Extensions |
305 | */ | 294 | */ |
@@ -313,25 +302,25 @@ enum backlight_opt { | |||
313 | }; | 302 | }; |
314 | 303 | ||
315 | /* Macro */ | 304 | /* Macro */ |
316 | #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) | 305 | #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) |
317 | #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) | 306 | #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP << 8 | (id)) |
318 | #define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id)) | 307 | #define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt) << 8 | (id)) |
319 | /* Backlight */ | 308 | /* Backlight */ |
320 | #define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE << 8) | 309 | #define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE << 8) |
321 | #define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE << 8) | 310 | #define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE << 8) |
322 | #define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE << 8) | 311 | #define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE << 8) |
323 | #define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8) | 312 | #define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8) |
324 | #define ACTION_BACKLIGHT_ON() ACTION(ACT_BACKLIGHT, BACKLIGHT_ON << 8) | 313 | #define ACTION_BACKLIGHT_ON() ACTION(ACT_BACKLIGHT, BACKLIGHT_ON << 8) |
325 | #define ACTION_BACKLIGHT_OFF() ACTION(ACT_BACKLIGHT, BACKLIGHT_OFF << 8) | 314 | #define ACTION_BACKLIGHT_OFF() ACTION(ACT_BACKLIGHT, BACKLIGHT_OFF << 8) |
326 | /* Command */ | 315 | /* Command */ |
327 | #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (id)) | 316 | #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt) << 8 | (id)) |
328 | /* Function */ | 317 | /* Function */ |
329 | enum function_opts { | 318 | enum function_opts { |
330 | FUNC_TAP = 0x8, /* indciates function is tappable */ | 319 | FUNC_TAP = 0x8, /* indciates function is tappable */ |
331 | }; | 320 | }; |
332 | #define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id)) | 321 | #define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id)) |
333 | #define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id)) | 322 | #define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP << 8 | (id)) |
334 | #define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id)) | 323 | #define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt) << 8 | (id)) |
335 | /* OneHand Support */ | 324 | /* OneHand Support */ |
336 | enum swap_hands_param_tap_op { | 325 | enum swap_hands_param_tap_op { |
337 | OP_SH_TOGGLE = 0xF0, | 326 | OP_SH_TOGGLE = 0xF0, |
@@ -342,13 +331,13 @@ enum swap_hands_param_tap_op { | |||
342 | OP_SH_ON, | 331 | OP_SH_ON, |
343 | }; | 332 | }; |
344 | 333 | ||
345 | #define ACTION_SWAP_HANDS() ACTION_SWAP_HANDS_ON_OFF() | 334 | #define ACTION_SWAP_HANDS() ACTION_SWAP_HANDS_ON_OFF() |
346 | #define ACTION_SWAP_HANDS_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TOGGLE) | 335 | #define ACTION_SWAP_HANDS_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TOGGLE) |
347 | #define ACTION_SWAP_HANDS_TAP_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TAP_TOGGLE) | 336 | #define ACTION_SWAP_HANDS_TAP_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TAP_TOGGLE) |
348 | #define ACTION_SWAP_HANDS_TAP_KEY(key) ACTION(ACT_SWAP_HANDS, key) | 337 | #define ACTION_SWAP_HANDS_TAP_KEY(key) ACTION(ACT_SWAP_HANDS, key) |
349 | #define ACTION_SWAP_HANDS_ON_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_ON_OFF) | 338 | #define ACTION_SWAP_HANDS_ON_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_ON_OFF) |
350 | #define ACTION_SWAP_HANDS_OFF_ON() ACTION(ACT_SWAP_HANDS, OP_SH_OFF_ON) | 339 | #define ACTION_SWAP_HANDS_OFF_ON() ACTION(ACT_SWAP_HANDS, OP_SH_OFF_ON) |
351 | #define ACTION_SWAP_HANDS_ON() ACTION(ACT_SWAP_HANDS, OP_SH_ON) | 340 | #define ACTION_SWAP_HANDS_ON() ACTION(ACT_SWAP_HANDS, OP_SH_ON) |
352 | #define ACTION_SWAP_HANDS_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_OFF) | 341 | #define ACTION_SWAP_HANDS_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_OFF) |
353 | 342 | ||
354 | #endif /* ACTION_CODE_H */ | 343 | #endif /* ACTION_CODE_H */ |
diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index dfcbc110a..07d78c56d 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c | |||
@@ -5,12 +5,11 @@ | |||
5 | #include "action_layer.h" | 5 | #include "action_layer.h" |
6 | 6 | ||
7 | #ifdef DEBUG_ACTION | 7 | #ifdef DEBUG_ACTION |
8 | #include "debug.h" | 8 | # include "debug.h" |
9 | #else | 9 | #else |
10 | #include "nodebug.h" | 10 | # include "nodebug.h" |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | |||
14 | /** \brief Default Layer State | 13 | /** \brief Default Layer State |
15 | */ | 14 | */ |
16 | layer_state_t default_layer_state = 0; | 15 | layer_state_t default_layer_state = 0; |
@@ -19,34 +18,30 @@ layer_state_t default_layer_state = 0; | |||
19 | * | 18 | * |
20 | * Run user code on default layer state change | 19 | * Run user code on default layer state change |
21 | */ | 20 | */ |
22 | __attribute__((weak)) | 21 | __attribute__((weak)) layer_state_t default_layer_state_set_user(layer_state_t state) { return state; } |
23 | layer_state_t default_layer_state_set_user(layer_state_t state) { | ||
24 | return state; | ||
25 | } | ||
26 | 22 | ||
27 | /** \brief Default Layer State Set At Keyboard Level | 23 | /** \brief Default Layer State Set At Keyboard Level |
28 | * | 24 | * |
29 | * Run keyboard code on default layer state change | 25 | * Run keyboard code on default layer state change |
30 | */ | 26 | */ |
31 | __attribute__((weak)) | 27 | __attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t state) { return default_layer_state_set_user(state); } |
32 | layer_state_t default_layer_state_set_kb(layer_state_t state) { | ||
33 | return default_layer_state_set_user(state); | ||
34 | } | ||
35 | 28 | ||
36 | /** \brief Default Layer State Set | 29 | /** \brief Default Layer State Set |
37 | * | 30 | * |
38 | * Static function to set the default layer state, prints debug info and clears keys | 31 | * Static function to set the default layer state, prints debug info and clears keys |
39 | */ | 32 | */ |
40 | static void default_layer_state_set(layer_state_t state) { | 33 | static void default_layer_state_set(layer_state_t state) { |
41 | state = default_layer_state_set_kb(state); | 34 | state = default_layer_state_set_kb(state); |
42 | debug("default_layer_state: "); | 35 | debug("default_layer_state: "); |
43 | default_layer_debug(); debug(" to "); | 36 | default_layer_debug(); |
44 | default_layer_state = state; | 37 | debug(" to "); |
45 | default_layer_debug(); debug("\n"); | 38 | default_layer_state = state; |
39 | default_layer_debug(); | ||
40 | debug("\n"); | ||
46 | #ifdef STRICT_LAYER_RELEASE | 41 | #ifdef STRICT_LAYER_RELEASE |
47 | clear_keyboard_but_mods(); // To avoid stuck keys | 42 | clear_keyboard_but_mods(); // To avoid stuck keys |
48 | #else | 43 | #else |
49 | clear_keyboard_but_mods_and_keys(); // Don't reset held keys | 44 | clear_keyboard_but_mods_and_keys(); // Don't reset held keys |
50 | #endif | 45 | #endif |
51 | } | 46 | } |
52 | 47 | ||
@@ -54,43 +49,32 @@ static void default_layer_state_set(layer_state_t state) { | |||
54 | * | 49 | * |
55 | * Print out the hex value of the 32-bit default layer state, as well as the value of the highest bit. | 50 | * Print out the hex value of the 32-bit default layer state, as well as the value of the highest bit. |
56 | */ | 51 | */ |
57 | void default_layer_debug(void) { | 52 | void default_layer_debug(void) { dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state)); } |
58 | dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state)); | ||
59 | } | ||
60 | 53 | ||
61 | /** \brief Default Layer Set | 54 | /** \brief Default Layer Set |
62 | * | 55 | * |
63 | * Sets the default layer state. | 56 | * Sets the default layer state. |
64 | */ | 57 | */ |
65 | void default_layer_set(layer_state_t state) { | 58 | void default_layer_set(layer_state_t state) { default_layer_state_set(state); } |
66 | default_layer_state_set(state); | ||
67 | } | ||
68 | 59 | ||
69 | #ifndef NO_ACTION_LAYER | 60 | #ifndef NO_ACTION_LAYER |
70 | /** \brief Default Layer Or | 61 | /** \brief Default Layer Or |
71 | * | 62 | * |
72 | * Turns on the default layer based on matching bits between specifed layer and existing layer state | 63 | * Turns on the default layer based on matching bits between specifed layer and existing layer state |
73 | */ | 64 | */ |
74 | void default_layer_or(layer_state_t state) { | 65 | void default_layer_or(layer_state_t state) { default_layer_state_set(default_layer_state | state); } |
75 | default_layer_state_set(default_layer_state | state); | ||
76 | } | ||
77 | /** \brief Default Layer And | 66 | /** \brief Default Layer And |
78 | * | 67 | * |
79 | * Turns on default layer based on matching enabled bits between specifed layer and existing layer state | 68 | * Turns on default layer based on matching enabled bits between specifed layer and existing layer state |
80 | */ | 69 | */ |
81 | void default_layer_and(layer_state_t state) { | 70 | void default_layer_and(layer_state_t state) { default_layer_state_set(default_layer_state & state); } |
82 | default_layer_state_set(default_layer_state & state); | ||
83 | } | ||
84 | /** \brief Default Layer Xor | 71 | /** \brief Default Layer Xor |
85 | * | 72 | * |
86 | * Turns on default layer based on non-matching bits between specifed layer and existing layer state | 73 | * Turns on default layer based on non-matching bits between specifed layer and existing layer state |
87 | */ | 74 | */ |
88 | void default_layer_xor(layer_state_t state) { | 75 | void default_layer_xor(layer_state_t state) { default_layer_state_set(default_layer_state ^ state); } |
89 | default_layer_state_set(default_layer_state ^ state); | ||
90 | } | ||
91 | #endif | 76 | #endif |
92 | 77 | ||
93 | |||
94 | #ifndef NO_ACTION_LAYER | 78 | #ifndef NO_ACTION_LAYER |
95 | /** \brief Keymap Layer State | 79 | /** \brief Keymap Layer State |
96 | */ | 80 | */ |
@@ -100,123 +84,101 @@ layer_state_t layer_state = 0; | |||
100 | * | 84 | * |
101 | * Runs user code on layer state change | 85 | * Runs user code on layer state change |
102 | */ | 86 | */ |
103 | __attribute__((weak)) | 87 | __attribute__((weak)) layer_state_t layer_state_set_user(layer_state_t state) { return state; } |
104 | layer_state_t layer_state_set_user(layer_state_t state) { | ||
105 | return state; | ||
106 | } | ||
107 | 88 | ||
108 | /** \brief Layer state set keyboard | 89 | /** \brief Layer state set keyboard |
109 | * | 90 | * |
110 | * Runs keyboard code on layer state change | 91 | * Runs keyboard code on layer state change |
111 | */ | 92 | */ |
112 | __attribute__((weak)) | 93 | __attribute__((weak)) layer_state_t layer_state_set_kb(layer_state_t state) { return layer_state_set_user(state); } |
113 | layer_state_t layer_state_set_kb(layer_state_t state) { | ||
114 | return layer_state_set_user(state); | ||
115 | } | ||
116 | 94 | ||
117 | /** \brief Layer state set | 95 | /** \brief Layer state set |
118 | * | 96 | * |
119 | * Sets the layer to match the specifed state (a bitmask) | 97 | * Sets the layer to match the specifed state (a bitmask) |
120 | */ | 98 | */ |
121 | void layer_state_set(layer_state_t state) { | 99 | void layer_state_set(layer_state_t state) { |
122 | state = layer_state_set_kb(state); | 100 | state = layer_state_set_kb(state); |
123 | dprint("layer_state: "); | 101 | dprint("layer_state: "); |
124 | layer_debug(); dprint(" to "); | 102 | layer_debug(); |
125 | layer_state = state; | 103 | dprint(" to "); |
126 | layer_debug(); dprintln(); | 104 | layer_state = state; |
127 | #ifdef STRICT_LAYER_RELEASE | 105 | layer_debug(); |
128 | clear_keyboard_but_mods(); // To avoid stuck keys | 106 | dprintln(); |
129 | #else | 107 | # ifdef STRICT_LAYER_RELEASE |
130 | clear_keyboard_but_mods_and_keys(); // Don't reset held keys | 108 | clear_keyboard_but_mods(); // To avoid stuck keys |
131 | #endif | 109 | # else |
110 | clear_keyboard_but_mods_and_keys(); // Don't reset held keys | ||
111 | # endif | ||
132 | } | 112 | } |
133 | 113 | ||
134 | /** \brief Layer clear | 114 | /** \brief Layer clear |
135 | * | 115 | * |
136 | * Turn off all layers | 116 | * Turn off all layers |
137 | */ | 117 | */ |
138 | void layer_clear(void) { | 118 | void layer_clear(void) { layer_state_set(0); } |
139 | layer_state_set(0); | ||
140 | } | ||
141 | 119 | ||
142 | /** \brief Layer state is | 120 | /** \brief Layer state is |
143 | * | 121 | * |
144 | * Return whether the given state is on (it might still be shadowed by a higher state, though) | 122 | * Return whether the given state is on (it might still be shadowed by a higher state, though) |
145 | */ | 123 | */ |
146 | bool layer_state_is(uint8_t layer) { | 124 | bool layer_state_is(uint8_t layer) { return layer_state_cmp(layer_state, layer); } |
147 | return layer_state_cmp(layer_state, layer); | ||
148 | } | ||
149 | 125 | ||
150 | /** \brief Layer state compare | 126 | /** \brief Layer state compare |
151 | * | 127 | * |
152 | * Used for comparing layers {mostly used for unit testing} | 128 | * Used for comparing layers {mostly used for unit testing} |
153 | */ | 129 | */ |
154 | bool layer_state_cmp(layer_state_t cmp_layer_state, uint8_t layer) { | 130 | bool layer_state_cmp(layer_state_t cmp_layer_state, uint8_t layer) { |
155 | if (!cmp_layer_state) { return layer == 0; } | 131 | if (!cmp_layer_state) { |
156 | return (cmp_layer_state & (1UL<<layer)) != 0; | 132 | return layer == 0; |
133 | } | ||
134 | return (cmp_layer_state & (1UL << layer)) != 0; | ||
157 | } | 135 | } |
158 | 136 | ||
159 | /** \brief Layer move | 137 | /** \brief Layer move |
160 | * | 138 | * |
161 | * Turns on the given layer and turn off all other layers | 139 | * Turns on the given layer and turn off all other layers |
162 | */ | 140 | */ |
163 | void layer_move(uint8_t layer) { | 141 | void layer_move(uint8_t layer) { layer_state_set(1UL << layer); } |
164 | layer_state_set(1UL<<layer); | ||
165 | } | ||
166 | 142 | ||
167 | /** \brief Layer on | 143 | /** \brief Layer on |
168 | * | 144 | * |
169 | * Turns on given layer | 145 | * Turns on given layer |
170 | */ | 146 | */ |
171 | void layer_on(uint8_t layer) { | 147 | void layer_on(uint8_t layer) { layer_state_set(layer_state | (1UL << layer)); } |
172 | layer_state_set(layer_state | (1UL<<layer)); | ||
173 | } | ||
174 | 148 | ||
175 | /** \brief Layer off | 149 | /** \brief Layer off |
176 | * | 150 | * |
177 | * Turns off given layer | 151 | * Turns off given layer |
178 | */ | 152 | */ |
179 | void layer_off(uint8_t layer) { | 153 | void layer_off(uint8_t layer) { layer_state_set(layer_state & ~(1UL << layer)); } |
180 | layer_state_set(layer_state & ~(1UL<<layer)); | ||
181 | } | ||
182 | 154 | ||
183 | /** \brief Layer invert | 155 | /** \brief Layer invert |
184 | * | 156 | * |
185 | * Toggle the given layer (set it if it's unset, or unset it if it's set) | 157 | * Toggle the given layer (set it if it's unset, or unset it if it's set) |
186 | */ | 158 | */ |
187 | void layer_invert(uint8_t layer) { | 159 | void layer_invert(uint8_t layer) { layer_state_set(layer_state ^ (1UL << layer)); } |
188 | layer_state_set(layer_state ^ (1UL<<layer)); | ||
189 | } | ||
190 | 160 | ||
191 | /** \brief Layer or | 161 | /** \brief Layer or |
192 | * | 162 | * |
193 | * Turns on layers based on matching bits between specifed layer and existing layer state | 163 | * Turns on layers based on matching bits between specifed layer and existing layer state |
194 | */ | 164 | */ |
195 | void layer_or(layer_state_t state) { | 165 | void layer_or(layer_state_t state) { layer_state_set(layer_state | state); } |
196 | layer_state_set(layer_state | state); | ||
197 | } | ||
198 | /** \brief Layer and | 166 | /** \brief Layer and |
199 | * | 167 | * |
200 | * Turns on layers based on matching enabled bits between specifed layer and existing layer state | 168 | * Turns on layers based on matching enabled bits between specifed layer and existing layer state |
201 | */ | 169 | */ |
202 | void layer_and(layer_state_t state) { | 170 | void layer_and(layer_state_t state) { layer_state_set(layer_state & state); } |
203 | layer_state_set(layer_state & state); | ||
204 | } | ||
205 | /** \brief Layer xor | 171 | /** \brief Layer xor |
206 | * | 172 | * |
207 | * Turns on layers based on non-matching bits between specifed layer and existing layer state | 173 | * Turns on layers based on non-matching bits between specifed layer and existing layer state |
208 | */ | 174 | */ |
209 | void layer_xor(layer_state_t state) { | 175 | void layer_xor(layer_state_t state) { layer_state_set(layer_state ^ state); } |
210 | layer_state_set(layer_state ^ state); | ||
211 | } | ||
212 | 176 | ||
213 | /** \brief Layer debug printing | 177 | /** \brief Layer debug printing |
214 | * | 178 | * |
215 | * Print out the hex value of the 32-bit layer state, as well as the value of the highest bit. | 179 | * Print out the hex value of the 32-bit layer state, as well as the value of the highest bit. |
216 | */ | 180 | */ |
217 | void layer_debug(void) { | 181 | void layer_debug(void) { dprintf("%08lX(%u)", layer_state, biton32(layer_state)); } |
218 | dprintf("%08lX(%u)", layer_state, biton32(layer_state)); | ||
219 | } | ||
220 | #endif | 182 | #endif |
221 | 183 | ||
222 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) | 184 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) |
@@ -230,16 +192,13 @@ uint8_t source_layers_cache[(MATRIX_ROWS * MATRIX_COLS + 7) / 8][MAX_LAYER_BITS] | |||
230 | * Updates the cached keys when changing layers | 192 | * Updates the cached keys when changing layers |
231 | */ | 193 | */ |
232 | void update_source_layers_cache(keypos_t key, uint8_t layer) { | 194 | void update_source_layers_cache(keypos_t key, uint8_t layer) { |
233 | const uint8_t key_number = key.col + (key.row * MATRIX_COLS); | 195 | const uint8_t key_number = key.col + (key.row * MATRIX_COLS); |
234 | const uint8_t storage_row = key_number / 8; | 196 | const uint8_t storage_row = key_number / 8; |
235 | const uint8_t storage_bit = key_number % 8; | 197 | const uint8_t storage_bit = key_number % 8; |
236 | 198 | ||
237 | for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) { | 199 | for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) { |
238 | source_layers_cache[storage_row][bit_number] ^= | 200 | source_layers_cache[storage_row][bit_number] ^= (-((layer & (1U << bit_number)) != 0) ^ source_layers_cache[storage_row][bit_number]) & (1U << storage_bit); |
239 | (-((layer & (1U << bit_number)) != 0) | 201 | } |
240 | ^ source_layers_cache[storage_row][bit_number]) | ||
241 | & (1U << storage_bit); | ||
242 | } | ||
243 | } | 202 | } |
244 | 203 | ||
245 | /** \brief read source layers cache | 204 | /** \brief read source layers cache |
@@ -247,19 +206,16 @@ void update_source_layers_cache(keypos_t key, uint8_t layer) { | |||
247 | * reads the cached keys stored when the layer was changed | 206 | * reads the cached keys stored when the layer was changed |
248 | */ | 207 | */ |
249 | uint8_t read_source_layers_cache(keypos_t key) { | 208 | uint8_t read_source_layers_cache(keypos_t key) { |
250 | const uint8_t key_number = key.col + (key.row * MATRIX_COLS); | 209 | const uint8_t key_number = key.col + (key.row * MATRIX_COLS); |
251 | const uint8_t storage_row = key_number / 8; | 210 | const uint8_t storage_row = key_number / 8; |
252 | const uint8_t storage_bit = key_number % 8; | 211 | const uint8_t storage_bit = key_number % 8; |
253 | uint8_t layer = 0; | 212 | uint8_t layer = 0; |
254 | 213 | ||
255 | for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) { | 214 | for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) { |
256 | layer |= | 215 | layer |= ((source_layers_cache[storage_row][bit_number] & (1U << storage_bit)) != 0) << bit_number; |
257 | ((source_layers_cache[storage_row][bit_number] | 216 | } |
258 | & (1U << storage_bit)) != 0) | 217 | |
259 | << bit_number; | 218 | return layer; |
260 | } | ||
261 | |||
262 | return layer; | ||
263 | } | 219 | } |
264 | #endif | 220 | #endif |
265 | 221 | ||
@@ -272,49 +228,47 @@ uint8_t read_source_layers_cache(keypos_t key) { | |||
272 | */ | 228 | */ |
273 | action_t store_or_get_action(bool pressed, keypos_t key) { | 229 | action_t store_or_get_action(bool pressed, keypos_t key) { |
274 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) | 230 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) |
275 | if (disable_action_cache) { | 231 | if (disable_action_cache) { |
276 | return layer_switch_get_action(key); | 232 | return layer_switch_get_action(key); |
277 | } | 233 | } |
278 | 234 | ||
279 | uint8_t layer; | 235 | uint8_t layer; |
280 | 236 | ||
281 | if (pressed) { | 237 | if (pressed) { |
282 | layer = layer_switch_get_layer(key); | 238 | layer = layer_switch_get_layer(key); |
283 | update_source_layers_cache(key, layer); | 239 | update_source_layers_cache(key, layer); |
284 | } | 240 | } else { |
285 | else { | 241 | layer = read_source_layers_cache(key); |
286 | layer = read_source_layers_cache(key); | 242 | } |
287 | } | 243 | return action_for_key(layer, key); |
288 | return action_for_key(layer, key); | ||
289 | #else | 244 | #else |
290 | return layer_switch_get_action(key); | 245 | return layer_switch_get_action(key); |
291 | #endif | 246 | #endif |
292 | } | 247 | } |
293 | 248 | ||
294 | |||
295 | /** \brief Layer switch get layer | 249 | /** \brief Layer switch get layer |
296 | * | 250 | * |
297 | * Gets the layer based on key info | 251 | * Gets the layer based on key info |
298 | */ | 252 | */ |
299 | uint8_t layer_switch_get_layer(keypos_t key) { | 253 | uint8_t layer_switch_get_layer(keypos_t key) { |
300 | #ifndef NO_ACTION_LAYER | 254 | #ifndef NO_ACTION_LAYER |
301 | action_t action; | 255 | action_t action; |
302 | action.code = ACTION_TRANSPARENT; | 256 | action.code = ACTION_TRANSPARENT; |
303 | 257 | ||
304 | layer_state_t layers = layer_state | default_layer_state; | 258 | layer_state_t layers = layer_state | default_layer_state; |
305 | /* check top layer first */ | 259 | /* check top layer first */ |
306 | for (int8_t i = sizeof(layer_state_t) * 8 - 1; i >= 0; i--) { | 260 | for (int8_t i = sizeof(layer_state_t) * 8 - 1; i >= 0; i--) { |
307 | if (layers & (1UL << i)) { | 261 | if (layers & (1UL << i)) { |
308 | action = action_for_key(i, key); | 262 | action = action_for_key(i, key); |
309 | if (action.code != ACTION_TRANSPARENT) { | 263 | if (action.code != ACTION_TRANSPARENT) { |
310 | return i; | 264 | return i; |
311 | } | 265 | } |
266 | } | ||
312 | } | 267 | } |
313 | } | 268 | /* fall back to layer 0 */ |
314 | /* fall back to layer 0 */ | 269 | return 0; |
315 | return 0; | ||
316 | #else | 270 | #else |
317 | return biton32(default_layer_state); | 271 | return biton32(default_layer_state); |
318 | #endif | 272 | #endif |
319 | } | 273 | } |
320 | 274 | ||
@@ -322,6 +276,4 @@ uint8_t layer_switch_get_layer(keypos_t key) { | |||
322 | * | 276 | * |
323 | * Gets action code based on key position | 277 | * Gets action code based on key position |
324 | */ | 278 | */ |
325 | action_t layer_switch_get_action(keypos_t key) { | 279 | action_t layer_switch_get_action(keypos_t key) { return action_for_key(layer_switch_get_layer(key), key); } |
326 | return action_for_key(layer_switch_get_layer(key), key); | ||
327 | } | ||
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index a2734a29e..fee9b244d 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h | |||
@@ -23,27 +23,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
23 | 23 | ||
24 | #if defined(LAYER_STATE_8BIT) | 24 | #if defined(LAYER_STATE_8BIT) |
25 | typedef uint8_t layer_state_t; | 25 | typedef uint8_t layer_state_t; |
26 | #define get_highest_layer(state) biton8(state) | 26 | # define get_highest_layer(state) biton8(state) |
27 | #elif defined(LAYER_STATE_16BIT) | 27 | #elif defined(LAYER_STATE_16BIT) |
28 | typedef uint16_t layer_state_t; | 28 | typedef uint16_t layer_state_t; |
29 | #define get_highest_layer(state) biton16(state) | 29 | # define get_highest_layer(state) biton16(state) |
30 | #else | 30 | #else |
31 | typedef uint32_t layer_state_t; | 31 | typedef uint32_t layer_state_t; |
32 | #define get_highest_layer(state) biton32(state) | 32 | # define get_highest_layer(state) biton32(state) |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | |||
36 | /* | 35 | /* |
37 | * Default Layer | 36 | * Default Layer |
38 | */ | 37 | */ |
39 | extern layer_state_t default_layer_state; | 38 | extern layer_state_t default_layer_state; |
40 | void default_layer_debug(void); | 39 | void default_layer_debug(void); |
41 | void default_layer_set(layer_state_t state); | 40 | void default_layer_set(layer_state_t state); |
42 | 41 | ||
43 | __attribute__((weak)) | 42 | __attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t state); |
44 | layer_state_t default_layer_state_set_kb(layer_state_t state); | 43 | __attribute__((weak)) layer_state_t default_layer_state_set_user(layer_state_t state); |
45 | __attribute__((weak)) | ||
46 | layer_state_t default_layer_state_set_user(layer_state_t state); | ||
47 | 44 | ||
48 | #ifndef NO_ACTION_LAYER | 45 | #ifndef NO_ACTION_LAYER |
49 | /* bitwise operation */ | 46 | /* bitwise operation */ |
@@ -51,12 +48,11 @@ void default_layer_or(layer_state_t state); | |||
51 | void default_layer_and(layer_state_t state); | 48 | void default_layer_and(layer_state_t state); |
52 | void default_layer_xor(layer_state_t state); | 49 | void default_layer_xor(layer_state_t state); |
53 | #else | 50 | #else |
54 | #define default_layer_or(state) | 51 | # define default_layer_or(state) |
55 | #define default_layer_and(state) | 52 | # define default_layer_and(state) |
56 | #define default_layer_xor(state) | 53 | # define default_layer_xor(state) |
57 | #endif | 54 | #endif |
58 | 55 | ||
59 | |||
60 | /* | 56 | /* |
61 | * Keymap Layer | 57 | * Keymap Layer |
62 | */ | 58 | */ |
@@ -78,21 +74,21 @@ void layer_or(layer_state_t state); | |||
78 | void layer_and(layer_state_t state); | 74 | void layer_and(layer_state_t state); |
79 | void layer_xor(layer_state_t state); | 75 | void layer_xor(layer_state_t state); |
80 | #else | 76 | #else |
81 | #define layer_state 0 | 77 | # define layer_state 0 |
82 | 78 | ||
83 | #define layer_state_set(layer) | 79 | # define layer_state_set(layer) |
84 | #define layer_state_is(layer) (layer == 0) | 80 | # define layer_state_is(layer) (layer == 0) |
85 | #define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & 1UL << layer) != 0) | 81 | # define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & 1UL << layer) != 0) |
86 | 82 | ||
87 | #define layer_debug() | 83 | # define layer_debug() |
88 | #define layer_clear() | 84 | # define layer_clear() |
89 | #define layer_move(layer) | 85 | # define layer_move(layer) |
90 | #define layer_on(layer) | 86 | # define layer_on(layer) |
91 | #define layer_off(layer) | 87 | # define layer_off(layer) |
92 | #define layer_invert(layer) | 88 | # define layer_invert(layer) |
93 | #define layer_or(state) | 89 | # define layer_or(state) |
94 | #define layer_and(state) | 90 | # define layer_and(state) |
95 | #define layer_xor(state) | 91 | # define layer_xor(state) |
96 | #endif | 92 | #endif |
97 | 93 | ||
98 | layer_state_t layer_state_set_user(layer_state_t state); | 94 | layer_state_t layer_state_set_user(layer_state_t state); |
@@ -101,8 +97,8 @@ layer_state_t layer_state_set_kb(layer_state_t state); | |||
101 | /* pressed actions cache */ | 97 | /* pressed actions cache */ |
102 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) | 98 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) |
103 | /* The number of bits needed to represent the layer number: log2(32). */ | 99 | /* The number of bits needed to represent the layer number: log2(32). */ |
104 | #define MAX_LAYER_BITS 5 | 100 | # define MAX_LAYER_BITS 5 |
105 | void update_source_layers_cache(keypos_t key, uint8_t layer); | 101 | void update_source_layers_cache(keypos_t key, uint8_t layer); |
106 | uint8_t read_source_layers_cache(keypos_t key); | 102 | uint8_t read_source_layers_cache(keypos_t key); |
107 | #endif | 103 | #endif |
108 | action_t store_or_get_action(bool pressed, keypos_t key); | 104 | action_t store_or_get_action(bool pressed, keypos_t key); |
diff --git a/tmk_core/common/action_macro.c b/tmk_core/common/action_macro.c index 12bef2958..92228c0ba 100644 --- a/tmk_core/common/action_macro.c +++ b/tmk_core/common/action_macro.c | |||
@@ -20,22 +20,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
20 | #include "wait.h" | 20 | #include "wait.h" |
21 | 21 | ||
22 | #ifdef DEBUG_ACTION | 22 | #ifdef DEBUG_ACTION |
23 | #include "debug.h" | 23 | # include "debug.h" |
24 | #else | 24 | #else |
25 | #include "nodebug.h" | 25 | # include "nodebug.h" |
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | |||
29 | #ifndef NO_ACTION_MACRO | 28 | #ifndef NO_ACTION_MACRO |
30 | 29 | ||
31 | #define MACRO_READ() (macro = MACRO_GET(macro_p++)) | 30 | # define MACRO_READ() (macro = MACRO_GET(macro_p++)) |
32 | /** \brief Action Macro Play | 31 | /** \brief Action Macro Play |
33 | * | 32 | * |
34 | * FIXME: Needs doc | 33 | * FIXME: Needs doc |
35 | */ | 34 | */ |
36 | void action_macro_play(const macro_t *macro_p) | 35 | void action_macro_play(const macro_t *macro_p) { |
37 | { | 36 | macro_t macro = END; |
38 | macro_t macro = END; | ||
39 | uint8_t interval = 0; | 37 | uint8_t interval = 0; |
40 | 38 | ||
41 | if (!macro_p) return; | 39 | if (!macro_p) return; |
@@ -64,7 +62,10 @@ void action_macro_play(const macro_t *macro_p) | |||
64 | case WAIT: | 62 | case WAIT: |
65 | MACRO_READ(); | 63 | MACRO_READ(); |
66 | dprintf("WAIT(%u)\n", macro); | 64 | dprintf("WAIT(%u)\n", macro); |
67 | { uint8_t ms = macro; while (ms--) wait_ms(1); } | 65 | { |
66 | uint8_t ms = macro; | ||
67 | while (ms--) wait_ms(1); | ||
68 | } | ||
68 | break; | 69 | break; |
69 | case INTERVAL: | 70 | case INTERVAL: |
70 | interval = MACRO_READ(); | 71 | interval = MACRO_READ(); |
@@ -76,14 +77,17 @@ void action_macro_play(const macro_t *macro_p) | |||
76 | break; | 77 | break; |
77 | case 0x84 ... 0xF3: | 78 | case 0x84 ... 0xF3: |
78 | dprintf("UP(%02X)\n", macro); | 79 | dprintf("UP(%02X)\n", macro); |
79 | unregister_code(macro&0x7F); | 80 | unregister_code(macro & 0x7F); |
80 | break; | 81 | break; |
81 | case END: | 82 | case END: |
82 | default: | 83 | default: |
83 | return; | 84 | return; |
84 | } | 85 | } |
85 | // interval | 86 | // interval |
86 | { uint8_t ms = interval; while (ms--) wait_ms(1); } | 87 | { |
88 | uint8_t ms = interval; | ||
89 | while (ms--) wait_ms(1); | ||
90 | } | ||
87 | } | 91 | } |
88 | } | 92 | } |
89 | #endif | 93 | #endif |
diff --git a/tmk_core/common/action_macro.h b/tmk_core/common/action_macro.h index f373f5068..21004ead6 100644 --- a/tmk_core/common/action_macro.h +++ b/tmk_core/common/action_macro.h | |||
@@ -19,18 +19,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
19 | #include <stdint.h> | 19 | #include <stdint.h> |
20 | #include "progmem.h" | 20 | #include "progmem.h" |
21 | 21 | ||
22 | |||
23 | |||
24 | typedef uint8_t macro_t; | 22 | typedef uint8_t macro_t; |
25 | 23 | ||
26 | #define MACRO_NONE (macro_t*)0 | 24 | #define MACRO_NONE (macro_t *)0 |
27 | #define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; }) | 25 | #define MACRO(...) \ |
28 | #define MACRO_GET(p) pgm_read_byte(p) | 26 | ({ \ |
27 | static const macro_t __m[] PROGMEM = {__VA_ARGS__}; \ | ||
28 | &__m[0]; \ | ||
29 | }) | ||
30 | #define MACRO_GET(p) pgm_read_byte(p) | ||
29 | 31 | ||
30 | // Sends press when the macro key is pressed, release when release, or tap_macro when the key has been tapped | 32 | // Sends press when the macro key is pressed, release when release, or tap_macro when the key has been tapped |
31 | #define MACRO_TAP_HOLD(record, press, release, tap_macro) ( ((record)->event.pressed) ? \ | 33 | #define MACRO_TAP_HOLD(record, press, release, tap_macro) (((record)->event.pressed) ? (((record)->tap.count <= 0 || (record)->tap.interrupted) ? (press) : MACRO_NONE) : (((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (tap_macro) : (release))) |
32 | ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? (press) : MACRO_NONE ) : \ | ||
33 | ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (tap_macro) : (release) ) ) | ||
34 | 34 | ||
35 | // Holds down the modifier mod when the macro key is held, or sends macro instead when tapped | 35 | // Holds down the modifier mod when the macro key is held, or sends macro instead when tapped |
36 | #define MACRO_TAP_HOLD_MOD(record, macro, mod) MACRO_TAP_HOLD(record, (MACRO(D(mod), END)), MACRO(U(mod), END), macro) | 36 | #define MACRO_TAP_HOLD_MOD(record, macro, mod) MACRO_TAP_HOLD(record, (MACRO(D(mod), END)), MACRO(U(mod), END), macro) |
@@ -38,25 +38,27 @@ typedef uint8_t macro_t; | |||
38 | // Holds down the modifier mod when the macro key is held, or pressed a shifted key when tapped (eg: shift+3 for #) | 38 | // Holds down the modifier mod when the macro key is held, or pressed a shifted key when tapped (eg: shift+3 for #) |
39 | #define MACRO_TAP_SHFT_KEY_HOLD_MOD(record, key, mod) MACRO_TAP_HOLD_MOD(record, (MACRO(I(10), D(LSFT), T(key), U(LSFT), END)), mod) | 39 | #define MACRO_TAP_SHFT_KEY_HOLD_MOD(record, key, mod) MACRO_TAP_HOLD_MOD(record, (MACRO(I(10), D(LSFT), T(key), U(LSFT), END)), mod) |
40 | 40 | ||
41 | |||
42 | // Momentary switch layer when held, sends macro if tapped | 41 | // Momentary switch layer when held, sends macro if tapped |
43 | #define MACRO_TAP_HOLD_LAYER(record, macro, layer) ( ((record)->event.pressed) ? \ | 42 | #define MACRO_TAP_HOLD_LAYER(record, macro, layer) \ |
44 | ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? ({layer_on((layer)); MACRO_NONE; }) : MACRO_NONE ) : \ | 43 | (((record)->event.pressed) ? (((record)->tap.count <= 0 || (record)->tap.interrupted) ? ({ \ |
45 | ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (macro) : ({layer_off((layer)); MACRO_NONE; }) ) ) | 44 | layer_on((layer)); \ |
45 | MACRO_NONE; \ | ||
46 | }) \ | ||
47 | : MACRO_NONE) \ | ||
48 | : (((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (macro) : ({ \ | ||
49 | layer_off((layer)); \ | ||
50 | MACRO_NONE; \ | ||
51 | }))) | ||
46 | 52 | ||
47 | // Momentary switch layer when held, presses a shifted key when tapped (eg: shift+3 for #) | 53 | // Momentary switch layer when held, presses a shifted key when tapped (eg: shift+3 for #) |
48 | #define MACRO_TAP_SHFT_KEY_HOLD_LAYER(record, key, layer) MACRO_TAP_HOLD_LAYER(record, MACRO(I(10), D(LSFT), T(key), U(LSFT), END), layer) | 54 | #define MACRO_TAP_SHFT_KEY_HOLD_LAYER(record, key, layer) MACRO_TAP_HOLD_LAYER(record, MACRO(I(10), D(LSFT), T(key), U(LSFT), END), layer) |
49 | |||
50 | |||
51 | 55 | ||
52 | #ifndef NO_ACTION_MACRO | 56 | #ifndef NO_ACTION_MACRO |
53 | void action_macro_play(const macro_t *macro_p); | 57 | void action_macro_play(const macro_t *macro_p); |
54 | #else | 58 | #else |
55 | #define action_macro_play(macro) | 59 | # define action_macro_play(macro) |
56 | #endif | 60 | #endif |
57 | 61 | ||
58 | |||
59 | |||
60 | /* Macro commands | 62 | /* Macro commands |
61 | * code(0x04-73) // key down(1byte) | 63 | * code(0x04-73) // key down(1byte) |
62 | * code(0x04-73) | 0x80 // key up(1byte) | 64 | * code(0x04-73) | 0x80 // key up(1byte) |
@@ -75,16 +77,16 @@ void action_macro_play(const macro_t *macro_p); | |||
75 | * conditionals | 77 | * conditionals |
76 | * loop | 78 | * loop |
77 | */ | 79 | */ |
78 | enum macro_command_id{ | 80 | enum macro_command_id { |
79 | /* 0x00 - 0x03 */ | 81 | /* 0x00 - 0x03 */ |
80 | END = 0x00, | 82 | END = 0x00, |
81 | KEY_DOWN, | 83 | KEY_DOWN, |
82 | KEY_UP, | 84 | KEY_UP, |
83 | 85 | ||
84 | /* 0x04 - 0x73 (reserved for keycode down) */ | 86 | /* 0x04 - 0x73 (reserved for keycode down) */ |
85 | 87 | ||
86 | /* 0x74 - 0x83 */ | 88 | /* 0x74 - 0x83 */ |
87 | WAIT = 0x74, | 89 | WAIT = 0x74, |
88 | INTERVAL, | 90 | INTERVAL, |
89 | 91 | ||
90 | /* 0x84 - 0xf3 (reserved for keycode up) */ | 92 | /* 0x84 - 0xf3 (reserved for keycode up) */ |
@@ -92,33 +94,31 @@ enum macro_command_id{ | |||
92 | /* 0xf4 - 0xff */ | 94 | /* 0xf4 - 0xff */ |
93 | }; | 95 | }; |
94 | 96 | ||
95 | |||
96 | /* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed | 97 | /* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed |
97 | * if keycode between 0x04 and 0x73 | 98 | * if keycode between 0x04 and 0x73 |
98 | * keycode / (keycode|0x80) | 99 | * keycode / (keycode|0x80) |
99 | * else | 100 | * else |
100 | * {KEY_DOWN, keycode} / {KEY_UP, keycode} | 101 | * {KEY_DOWN, keycode} / {KEY_UP, keycode} |
101 | */ | 102 | */ |
102 | #define DOWN(key) KEY_DOWN, (key) | 103 | #define DOWN(key) KEY_DOWN, (key) |
103 | #define UP(key) KEY_UP, (key) | 104 | #define UP(key) KEY_UP, (key) |
104 | #define TYPE(key) DOWN(key), UP(key) | 105 | #define TYPE(key) DOWN(key), UP(key) |
105 | #define WAIT(ms) WAIT, (ms) | 106 | #define WAIT(ms) WAIT, (ms) |
106 | #define INTERVAL(ms) INTERVAL, (ms) | 107 | #define INTERVAL(ms) INTERVAL, (ms) |
107 | 108 | ||
108 | /* key down */ | 109 | /* key down */ |
109 | #define D(key) DOWN(KC_##key) | 110 | #define D(key) DOWN(KC_##key) |
110 | /* key up */ | 111 | /* key up */ |
111 | #define U(key) UP(KC_##key) | 112 | #define U(key) UP(KC_##key) |
112 | /* key type */ | 113 | /* key type */ |
113 | #define T(key) TYPE(KC_##key) | 114 | #define T(key) TYPE(KC_##key) |
114 | /* wait */ | 115 | /* wait */ |
115 | #define W(ms) WAIT(ms) | 116 | #define W(ms) WAIT(ms) |
116 | /* interval */ | 117 | /* interval */ |
117 | #define I(ms) INTERVAL(ms) | 118 | #define I(ms) INTERVAL(ms) |
118 | 119 | ||
119 | /* for backward comaptibility */ | 120 | /* for backward comaptibility */ |
120 | #define MD(key) DOWN(KC_##key) | 121 | #define MD(key) DOWN(KC_##key) |
121 | #define MU(key) UP(KC_##key) | 122 | #define MU(key) UP(KC_##key) |
122 | |||
123 | 123 | ||
124 | #endif /* ACTION_MACRO_H */ | 124 | #endif /* ACTION_MACRO_H */ |
diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c index 3b67ed152..e0f524ad7 100644 --- a/tmk_core/common/action_tapping.c +++ b/tmk_core/common/action_tapping.c | |||
@@ -7,33 +7,30 @@ | |||
7 | #include "timer.h" | 7 | #include "timer.h" |
8 | 8 | ||
9 | #ifdef DEBUG_ACTION | 9 | #ifdef DEBUG_ACTION |
10 | #include "debug.h" | 10 | # include "debug.h" |
11 | #else | 11 | #else |
12 | #include "nodebug.h" | 12 | # include "nodebug.h" |
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | #ifndef NO_ACTION_TAPPING | 15 | #ifndef NO_ACTION_TAPPING |
16 | 16 | ||
17 | #define IS_TAPPING() !IS_NOEVENT(tapping_key.event) | 17 | # define IS_TAPPING() !IS_NOEVENT(tapping_key.event) |
18 | #define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed) | 18 | # define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed) |
19 | #define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed) | 19 | # define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed) |
20 | #define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k))) | 20 | # define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k))) |
21 | 21 | ||
22 | __attribute__ ((weak)) | 22 | __attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode) { return TAPPING_TERM; } |
23 | uint16_t get_tapping_term(uint16_t keycode) { | ||
24 | return TAPPING_TERM; | ||
25 | } | ||
26 | 23 | ||
27 | #ifdef TAPPING_TERM_PER_KEY | 24 | # ifdef TAPPING_TERM_PER_KEY |
28 | #define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event))) | 25 | # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event))) |
29 | #else | 26 | # else |
30 | #define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM) | 27 | # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM) |
31 | #endif | 28 | # endif |
32 | 29 | ||
33 | static keyrecord_t tapping_key = {}; | 30 | static keyrecord_t tapping_key = {}; |
34 | static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {}; | 31 | static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {}; |
35 | static uint8_t waiting_buffer_head = 0; | 32 | static uint8_t waiting_buffer_head = 0; |
36 | static uint8_t waiting_buffer_tail = 0; | 33 | static uint8_t waiting_buffer_tail = 0; |
37 | 34 | ||
38 | static bool process_tapping(keyrecord_t *record); | 35 | static bool process_tapping(keyrecord_t *record); |
39 | static bool waiting_buffer_enq(keyrecord_t record); | 36 | static bool waiting_buffer_enq(keyrecord_t record); |
@@ -44,16 +41,16 @@ static void waiting_buffer_scan_tap(void); | |||
44 | static void debug_tapping_key(void); | 41 | static void debug_tapping_key(void); |
45 | static void debug_waiting_buffer(void); | 42 | static void debug_waiting_buffer(void); |
46 | 43 | ||
47 | |||
48 | /** \brief Action Tapping Process | 44 | /** \brief Action Tapping Process |
49 | * | 45 | * |
50 | * FIXME: Needs doc | 46 | * FIXME: Needs doc |
51 | */ | 47 | */ |
52 | void action_tapping_process(keyrecord_t record) | 48 | void action_tapping_process(keyrecord_t record) { |
53 | { | ||
54 | if (process_tapping(&record)) { | 49 | if (process_tapping(&record)) { |
55 | if (!IS_NOEVENT(record.event)) { | 50 | if (!IS_NOEVENT(record.event)) { |
56 | debug("processed: "); debug_record(record); debug("\n"); | 51 | debug("processed: "); |
52 | debug_record(record); | ||
53 | debug("\n"); | ||
57 | } | 54 | } |
58 | } else { | 55 | } else { |
59 | if (!waiting_buffer_enq(record)) { | 56 | if (!waiting_buffer_enq(record)) { |
@@ -71,8 +68,11 @@ void action_tapping_process(keyrecord_t record) | |||
71 | } | 68 | } |
72 | for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) { | 69 | for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) { |
73 | if (process_tapping(&waiting_buffer[waiting_buffer_tail])) { | 70 | if (process_tapping(&waiting_buffer[waiting_buffer_tail])) { |
74 | debug("processed: waiting_buffer["); debug_dec(waiting_buffer_tail); debug("] = "); | 71 | debug("processed: waiting_buffer["); |
75 | debug_record(waiting_buffer[waiting_buffer_tail]); debug("\n\n"); | 72 | debug_dec(waiting_buffer_tail); |
73 | debug("] = "); | ||
74 | debug_record(waiting_buffer[waiting_buffer_tail]); | ||
75 | debug("\n\n"); | ||
76 | } else { | 76 | } else { |
77 | break; | 77 | break; |
78 | } | 78 | } |
@@ -82,15 +82,13 @@ void action_tapping_process(keyrecord_t record) | |||
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | |||
86 | /** \brief Tapping | 85 | /** \brief Tapping |
87 | * | 86 | * |
88 | * Rule: Tap key is typed(pressed and released) within TAPPING_TERM. | 87 | * Rule: Tap key is typed(pressed and released) within TAPPING_TERM. |
89 | * (without interfering by typing other key) | 88 | * (without interfering by typing other key) |
90 | */ | 89 | */ |
91 | /* return true when key event is processed or consumed. */ | 90 | /* return true when key event is processed or consumed. */ |
92 | bool process_tapping(keyrecord_t *keyp) | 91 | bool process_tapping(keyrecord_t *keyp) { |
93 | { | ||
94 | keyevent_t event = keyp->event; | 92 | keyevent_t event = keyp->event; |
95 | 93 | ||
96 | // if tapping | 94 | // if tapping |
@@ -113,12 +111,12 @@ bool process_tapping(keyrecord_t *keyp) | |||
113 | * This can register the key before settlement of tapping, | 111 | * This can register the key before settlement of tapping, |
114 | * useful for long TAPPING_TERM but may prevent fast typing. | 112 | * useful for long TAPPING_TERM but may prevent fast typing. |
115 | */ | 113 | */ |
116 | #if defined(TAPPING_TERM_PER_KEY) || (!defined(PER_KEY_TAPPING_TERM) && TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD) | 114 | # if defined(TAPPING_TERM_PER_KEY) || (!defined(PER_KEY_TAPPING_TERM) && TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD) |
117 | #ifdef TAPPING_TERM_PER_KEY | 115 | # ifdef TAPPING_TERM_PER_KEY |
118 | else if ( ( get_tapping_term(get_event_keycode(tapping_key.event)) >= 500) && IS_RELEASED(event) && waiting_buffer_typed(event)) | 116 | else if ((get_tapping_term(get_event_keycode(tapping_key.event)) >= 500) && IS_RELEASED(event) && waiting_buffer_typed(event)) |
119 | #else | 117 | # else |
120 | else if ( IS_RELEASED(event) && waiting_buffer_typed(event)) | 118 | else if (IS_RELEASED(event) && waiting_buffer_typed(event)) |
121 | #endif | 119 | # endif |
122 | { | 120 | { |
123 | debug("Tapping: End. No tap. Interfered by typing key\n"); | 121 | debug("Tapping: End. No tap. Interfered by typing key\n"); |
124 | process_record(&tapping_key); | 122 | process_record(&tapping_key); |
@@ -127,7 +125,7 @@ bool process_tapping(keyrecord_t *keyp) | |||
127 | // enqueue | 125 | // enqueue |
128 | return false; | 126 | return false; |
129 | } | 127 | } |
130 | #endif | 128 | # endif |
131 | /* Process release event of a key pressed before tapping starts | 129 | /* Process release event of a key pressed before tapping starts |
132 | * Without this unexpected repeating will occur with having fast repeating setting | 130 | * Without this unexpected repeating will occur with having fast repeating setting |
133 | * https://github.com/tmk/tmk_keyboard/issues/60 | 131 | * https://github.com/tmk/tmk_keyboard/issues/60 |
@@ -151,8 +149,7 @@ bool process_tapping(keyrecord_t *keyp) | |||
151 | debug("Tapping: release event of a key pressed before tapping\n"); | 149 | debug("Tapping: release event of a key pressed before tapping\n"); |
152 | process_record(keyp); | 150 | process_record(keyp); |
153 | return true; | 151 | return true; |
154 | } | 152 | } else { |
155 | else { | ||
156 | // set interrupted flag when other key preesed during tapping | 153 | // set interrupted flag when other key preesed during tapping |
157 | if (event.pressed) { | 154 | if (event.pressed) { |
158 | tapping_key.tap.interrupted = true; | 155 | tapping_key.tap.interrupted = true; |
@@ -164,23 +161,19 @@ bool process_tapping(keyrecord_t *keyp) | |||
164 | // tap_count > 0 | 161 | // tap_count > 0 |
165 | else { | 162 | else { |
166 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 163 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { |
167 | debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n"); | 164 | debug("Tapping: Tap release("); |
165 | debug_dec(tapping_key.tap.count); | ||
166 | debug(")\n"); | ||
168 | keyp->tap = tapping_key.tap; | 167 | keyp->tap = tapping_key.tap; |
169 | process_record(keyp); | 168 | process_record(keyp); |
170 | tapping_key = *keyp; | 169 | tapping_key = *keyp; |
171 | debug_tapping_key(); | 170 | debug_tapping_key(); |
172 | return true; | 171 | return true; |
173 | } | 172 | } else if (is_tap_key(event.key) && event.pressed) { |
174 | else if (is_tap_key(event.key) && event.pressed) { | ||
175 | if (tapping_key.tap.count > 1) { | 173 | if (tapping_key.tap.count > 1) { |
176 | debug("Tapping: Start new tap with releasing last tap(>1).\n"); | 174 | debug("Tapping: Start new tap with releasing last tap(>1).\n"); |
177 | // unregister key | 175 | // unregister key |
178 | process_record(&(keyrecord_t){ | 176 | process_record(&(keyrecord_t){.tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false}); |
179 | .tap = tapping_key.tap, | ||
180 | .event.key = tapping_key.event.key, | ||
181 | .event.time = event.time, | ||
182 | .event.pressed = false | ||
183 | }); | ||
184 | } else { | 177 | } else { |
185 | debug("Tapping: Start while last tap(1).\n"); | 178 | debug("Tapping: Start while last tap(1).\n"); |
186 | } | 179 | } |
@@ -188,8 +181,7 @@ bool process_tapping(keyrecord_t *keyp) | |||
188 | waiting_buffer_scan_tap(); | 181 | waiting_buffer_scan_tap(); |
189 | debug_tapping_key(); | 182 | debug_tapping_key(); |
190 | return true; | 183 | return true; |
191 | } | 184 | } else { |
192 | else { | ||
193 | if (!IS_NOEVENT(event)) { | 185 | if (!IS_NOEVENT(event)) { |
194 | debug("Tapping: key event while last tap(>0).\n"); | 186 | debug("Tapping: key event while last tap(>0).\n"); |
195 | } | 187 | } |
@@ -202,29 +194,24 @@ bool process_tapping(keyrecord_t *keyp) | |||
202 | else { | 194 | else { |
203 | if (tapping_key.tap.count == 0) { | 195 | if (tapping_key.tap.count == 0) { |
204 | debug("Tapping: End. Timeout. Not tap(0): "); | 196 | debug("Tapping: End. Timeout. Not tap(0): "); |
205 | debug_event(event); debug("\n"); | 197 | debug_event(event); |
198 | debug("\n"); | ||
206 | process_record(&tapping_key); | 199 | process_record(&tapping_key); |
207 | tapping_key = (keyrecord_t){}; | 200 | tapping_key = (keyrecord_t){}; |
208 | debug_tapping_key(); | 201 | debug_tapping_key(); |
209 | return false; | 202 | return false; |
210 | } else { | 203 | } else { |
211 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 204 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { |
212 | debug("Tapping: End. last timeout tap release(>0)."); | 205 | debug("Tapping: End. last timeout tap release(>0)."); |
213 | keyp->tap = tapping_key.tap; | 206 | keyp->tap = tapping_key.tap; |
214 | process_record(keyp); | 207 | process_record(keyp); |
215 | tapping_key = (keyrecord_t){}; | 208 | tapping_key = (keyrecord_t){}; |
216 | return true; | 209 | return true; |
217 | } | 210 | } else if (is_tap_key(event.key) && event.pressed) { |
218 | else if (is_tap_key(event.key) && event.pressed) { | ||
219 | if (tapping_key.tap.count > 1) { | 211 | if (tapping_key.tap.count > 1) { |
220 | debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); | 212 | debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); |
221 | // unregister key | 213 | // unregister key |
222 | process_record(&(keyrecord_t){ | 214 | process_record(&(keyrecord_t){.tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false}); |
223 | .tap = tapping_key.tap, | ||
224 | .event.key = tapping_key.event.key, | ||
225 | .event.time = event.time, | ||
226 | .event.pressed = false | ||
227 | }); | ||
228 | } else { | 215 | } else { |
229 | debug("Tapping: Start while last timeout tap(1).\n"); | 216 | debug("Tapping: Start while last timeout tap(1).\n"); |
230 | } | 217 | } |
@@ -232,8 +219,7 @@ bool process_tapping(keyrecord_t *keyp) | |||
232 | waiting_buffer_scan_tap(); | 219 | waiting_buffer_scan_tap(); |
233 | debug_tapping_key(); | 220 | debug_tapping_key(); |
234 | return true; | 221 | return true; |
235 | } | 222 | } else { |
236 | else { | ||
237 | if (!IS_NOEVENT(event)) { | 223 | if (!IS_NOEVENT(event)) { |
238 | debug("Tapping: key event while last timeout tap(>0).\n"); | 224 | debug("Tapping: key event while last timeout tap(>0).\n"); |
239 | } | 225 | } |
@@ -246,18 +232,20 @@ bool process_tapping(keyrecord_t *keyp) | |||
246 | if (WITHIN_TAPPING_TERM(event)) { | 232 | if (WITHIN_TAPPING_TERM(event)) { |
247 | if (event.pressed) { | 233 | if (event.pressed) { |
248 | if (IS_TAPPING_KEY(event.key)) { | 234 | if (IS_TAPPING_KEY(event.key)) { |
249 | #ifndef TAPPING_FORCE_HOLD | 235 | # ifndef TAPPING_FORCE_HOLD |
250 | if (!tapping_key.tap.interrupted && tapping_key.tap.count > 0) { | 236 | if (!tapping_key.tap.interrupted && tapping_key.tap.count > 0) { |
251 | // sequential tap. | 237 | // sequential tap. |
252 | keyp->tap = tapping_key.tap; | 238 | keyp->tap = tapping_key.tap; |
253 | if (keyp->tap.count < 15) keyp->tap.count += 1; | 239 | if (keyp->tap.count < 15) keyp->tap.count += 1; |
254 | debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n"); | 240 | debug("Tapping: Tap press("); |
241 | debug_dec(keyp->tap.count); | ||
242 | debug(")\n"); | ||
255 | process_record(keyp); | 243 | process_record(keyp); |
256 | tapping_key = *keyp; | 244 | tapping_key = *keyp; |
257 | debug_tapping_key(); | 245 | debug_tapping_key(); |
258 | return true; | 246 | return true; |
259 | } | 247 | } |
260 | #endif | 248 | # endif |
261 | // FIX: start new tap again | 249 | // FIX: start new tap again |
262 | tapping_key = *keyp; | 250 | tapping_key = *keyp; |
263 | return true; | 251 | return true; |
@@ -284,7 +272,8 @@ bool process_tapping(keyrecord_t *keyp) | |||
284 | // FIX: process_action here? | 272 | // FIX: process_action here? |
285 | // timeout. no sequential tap. | 273 | // timeout. no sequential tap. |
286 | debug("Tapping: End(Timeout after releasing last tap): "); | 274 | debug("Tapping: End(Timeout after releasing last tap): "); |
287 | debug_event(event); debug("\n"); | 275 | debug_event(event); |
276 | debug("\n"); | ||
288 | tapping_key = (keyrecord_t){}; | 277 | tapping_key = (keyrecord_t){}; |
289 | debug_tapping_key(); | 278 | debug_tapping_key(); |
290 | return false; | 279 | return false; |
@@ -306,13 +295,11 @@ bool process_tapping(keyrecord_t *keyp) | |||
306 | } | 295 | } |
307 | } | 296 | } |
308 | 297 | ||
309 | |||
310 | /** \brief Waiting buffer enq | 298 | /** \brief Waiting buffer enq |
311 | * | 299 | * |
312 | * FIXME: Needs docs | 300 | * FIXME: Needs docs |
313 | */ | 301 | */ |
314 | bool waiting_buffer_enq(keyrecord_t record) | 302 | bool waiting_buffer_enq(keyrecord_t record) { |
315 | { | ||
316 | if (IS_NOEVENT(record.event)) { | 303 | if (IS_NOEVENT(record.event)) { |
317 | return true; | 304 | return true; |
318 | } | 305 | } |
@@ -323,9 +310,10 @@ bool waiting_buffer_enq(keyrecord_t record) | |||
323 | } | 310 | } |
324 | 311 | ||
325 | waiting_buffer[waiting_buffer_head] = record; | 312 | waiting_buffer[waiting_buffer_head] = record; |
326 | waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE; | 313 | waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE; |
327 | 314 | ||
328 | debug("waiting_buffer_enq: "); debug_waiting_buffer(); | 315 | debug("waiting_buffer_enq: "); |
316 | debug_waiting_buffer(); | ||
329 | return true; | 317 | return true; |
330 | } | 318 | } |
331 | 319 | ||
@@ -333,8 +321,7 @@ bool waiting_buffer_enq(keyrecord_t record) | |||
333 | * | 321 | * |
334 | * FIXME: Needs docs | 322 | * FIXME: Needs docs |
335 | */ | 323 | */ |
336 | void waiting_buffer_clear(void) | 324 | void waiting_buffer_clear(void) { |
337 | { | ||
338 | waiting_buffer_head = 0; | 325 | waiting_buffer_head = 0; |
339 | waiting_buffer_tail = 0; | 326 | waiting_buffer_tail = 0; |
340 | } | 327 | } |
@@ -343,10 +330,9 @@ void waiting_buffer_clear(void) | |||
343 | * | 330 | * |
344 | * FIXME: Needs docs | 331 | * FIXME: Needs docs |
345 | */ | 332 | */ |
346 | bool waiting_buffer_typed(keyevent_t event) | 333 | bool waiting_buffer_typed(keyevent_t event) { |
347 | { | ||
348 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { | 334 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { |
349 | if (KEYEQ(event.key, waiting_buffer[i].event.key) && event.pressed != waiting_buffer[i].event.pressed) { | 335 | if (KEYEQ(event.key, waiting_buffer[i].event.key) && event.pressed != waiting_buffer[i].event.pressed) { |
350 | return true; | 336 | return true; |
351 | } | 337 | } |
352 | } | 338 | } |
@@ -357,9 +343,7 @@ bool waiting_buffer_typed(keyevent_t event) | |||
357 | * | 343 | * |
358 | * FIXME: Needs docs | 344 | * FIXME: Needs docs |
359 | */ | 345 | */ |
360 | __attribute__((unused)) | 346 | __attribute__((unused)) bool waiting_buffer_has_anykey_pressed(void) { |
361 | bool waiting_buffer_has_anykey_pressed(void) | ||
362 | { | ||
363 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { | 347 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { |
364 | if (waiting_buffer[i].event.pressed) return true; | 348 | if (waiting_buffer[i].event.pressed) return true; |
365 | } | 349 | } |
@@ -370,47 +354,49 @@ bool waiting_buffer_has_anykey_pressed(void) | |||
370 | * | 354 | * |
371 | * FIXME: Needs docs | 355 | * FIXME: Needs docs |
372 | */ | 356 | */ |
373 | void waiting_buffer_scan_tap(void) | 357 | void waiting_buffer_scan_tap(void) { |
374 | { | ||
375 | // tapping already is settled | 358 | // tapping already is settled |
376 | if (tapping_key.tap.count > 0) return; | 359 | if (tapping_key.tap.count > 0) return; |
377 | // invalid state: tapping_key released && tap.count == 0 | 360 | // invalid state: tapping_key released && tap.count == 0 |
378 | if (!tapping_key.event.pressed) return; | 361 | if (!tapping_key.event.pressed) return; |
379 | 362 | ||
380 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { | 363 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { |
381 | if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && | 364 | if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && !waiting_buffer[i].event.pressed && WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { |
382 | !waiting_buffer[i].event.pressed && | 365 | tapping_key.tap.count = 1; |
383 | WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { | ||
384 | tapping_key.tap.count = 1; | ||
385 | waiting_buffer[i].tap.count = 1; | 366 | waiting_buffer[i].tap.count = 1; |
386 | process_record(&tapping_key); | 367 | process_record(&tapping_key); |
387 | 368 | ||
388 | debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n"); | 369 | debug("waiting_buffer_scan_tap: found at ["); |
370 | debug_dec(i); | ||
371 | debug("]\n"); | ||
389 | debug_waiting_buffer(); | 372 | debug_waiting_buffer(); |
390 | return; | 373 | return; |
391 | } | 374 | } |
392 | } | 375 | } |
393 | } | 376 | } |
394 | 377 | ||
395 | |||
396 | /** \brief Tapping key debug print | 378 | /** \brief Tapping key debug print |
397 | * | 379 | * |
398 | * FIXME: Needs docs | 380 | * FIXME: Needs docs |
399 | */ | 381 | */ |
400 | static void debug_tapping_key(void) | 382 | static void debug_tapping_key(void) { |
401 | { | 383 | debug("TAPPING_KEY="); |
402 | debug("TAPPING_KEY="); debug_record(tapping_key); debug("\n"); | 384 | debug_record(tapping_key); |
385 | debug("\n"); | ||
403 | } | 386 | } |
404 | 387 | ||
405 | /** \brief Waiting buffer debug print | 388 | /** \brief Waiting buffer debug print |
406 | * | 389 | * |
407 | * FIXME: Needs docs | 390 | * FIXME: Needs docs |
408 | */ | 391 | */ |
409 | static void debug_waiting_buffer(void) | 392 | static void debug_waiting_buffer(void) { |
410 | { | ||
411 | debug("{ "); | 393 | debug("{ "); |
412 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { | 394 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { |
413 | debug("["); debug_dec(i); debug("]="); debug_record(waiting_buffer[i]); debug(" "); | 395 | debug("["); |
396 | debug_dec(i); | ||
397 | debug("]="); | ||
398 | debug_record(waiting_buffer[i]); | ||
399 | debug(" "); | ||
414 | } | 400 | } |
415 | debug("}\n"); | 401 | debug("}\n"); |
416 | } | 402 | } |
diff --git a/tmk_core/common/action_tapping.h b/tmk_core/common/action_tapping.h index 1db43a442..509d5eabd 100644 --- a/tmk_core/common/action_tapping.h +++ b/tmk_core/common/action_tapping.h | |||
@@ -17,27 +17,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | #ifndef ACTION_TAPPING_H | 17 | #ifndef ACTION_TAPPING_H |
18 | #define ACTION_TAPPING_H | 18 | #define ACTION_TAPPING_H |
19 | 19 | ||
20 | |||
21 | |||
22 | /* period of tapping(ms) */ | 20 | /* period of tapping(ms) */ |
23 | #ifndef TAPPING_TERM | 21 | #ifndef TAPPING_TERM |
24 | #define TAPPING_TERM 200 | 22 | # define TAPPING_TERM 200 |
25 | #endif | 23 | #endif |
26 | 24 | ||
27 | //#define RETRO_TAPPING // Tap anyway, even after TAPPING_TERM, as long as there was no interruption | 25 | //#define RETRO_TAPPING // Tap anyway, even after TAPPING_TERM, as long as there was no interruption |
28 | 26 | ||
29 | /* tap count needed for toggling a feature */ | 27 | /* tap count needed for toggling a feature */ |
30 | #ifndef TAPPING_TOGGLE | 28 | #ifndef TAPPING_TOGGLE |
31 | #define TAPPING_TOGGLE 5 | 29 | # define TAPPING_TOGGLE 5 |
32 | #endif | 30 | #endif |
33 | 31 | ||
34 | #define WAITING_BUFFER_SIZE 8 | 32 | #define WAITING_BUFFER_SIZE 8 |
35 | 33 | ||
36 | |||
37 | #ifndef NO_ACTION_TAPPING | 34 | #ifndef NO_ACTION_TAPPING |
38 | uint16_t get_event_keycode(keyevent_t event); | 35 | uint16_t get_event_keycode(keyevent_t event); |
39 | uint16_t get_tapping_term(uint16_t keycode); | 36 | uint16_t get_tapping_term(uint16_t keycode); |
40 | void action_tapping_process(keyrecord_t record); | 37 | void action_tapping_process(keyrecord_t record); |
41 | #endif | 38 | #endif |
42 | 39 | ||
43 | #endif | 40 | #endif |
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index 365ed6a1d..335aa36e6 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c | |||
@@ -24,23 +24,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
24 | 24 | ||
25 | extern keymap_config_t keymap_config; | 25 | extern keymap_config_t keymap_config; |
26 | 26 | ||
27 | 27 | static uint8_t real_mods = 0; | |
28 | static uint8_t real_mods = 0; | 28 | static uint8_t weak_mods = 0; |
29 | static uint8_t weak_mods = 0; | ||
30 | static uint8_t macro_mods = 0; | 29 | static uint8_t macro_mods = 0; |
31 | 30 | ||
32 | #ifdef USB_6KRO_ENABLE | 31 | #ifdef USB_6KRO_ENABLE |
33 | #define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) | 32 | # define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) |
34 | #define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS) | 33 | # define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS) |
35 | #define RO_INC(a) RO_ADD(a, 1) | 34 | # define RO_INC(a) RO_ADD(a, 1) |
36 | #define RO_DEC(a) RO_SUB(a, 1) | 35 | # define RO_DEC(a) RO_SUB(a, 1) |
37 | static int8_t cb_head = 0; | 36 | static int8_t cb_head = 0; |
38 | static int8_t cb_tail = 0; | 37 | static int8_t cb_tail = 0; |
39 | static int8_t cb_count = 0; | 38 | static int8_t cb_count = 0; |
40 | #endif | 39 | #endif |
41 | 40 | ||
42 | // TODO: pointer variable is not needed | 41 | // TODO: pointer variable is not needed |
43 | //report_keyboard_t keyboard_report = {}; | 42 | // report_keyboard_t keyboard_report = {}; |
44 | report_keyboard_t *keyboard_report = &(report_keyboard_t){}; | 43 | report_keyboard_t *keyboard_report = &(report_keyboard_t){}; |
45 | 44 | ||
46 | extern inline void add_key(uint8_t key); | 45 | extern inline void add_key(uint8_t key); |
@@ -48,10 +47,10 @@ extern inline void del_key(uint8_t key); | |||
48 | extern inline void clear_keys(void); | 47 | extern inline void clear_keys(void); |
49 | 48 | ||
50 | #ifndef NO_ACTION_ONESHOT | 49 | #ifndef NO_ACTION_ONESHOT |
51 | static uint8_t oneshot_mods = 0; | 50 | static uint8_t oneshot_mods = 0; |
52 | static uint8_t oneshot_locked_mods = 0; | 51 | static uint8_t oneshot_locked_mods = 0; |
53 | uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } | 52 | uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } |
54 | void set_oneshot_locked_mods(uint8_t mods) { | 53 | void set_oneshot_locked_mods(uint8_t mods) { |
55 | if (mods != oneshot_locked_mods) { | 54 | if (mods != oneshot_locked_mods) { |
56 | oneshot_locked_mods = mods; | 55 | oneshot_locked_mods = mods; |
57 | oneshot_locked_mods_changed_kb(oneshot_locked_mods); | 56 | oneshot_locked_mods_changed_kb(oneshot_locked_mods); |
@@ -63,16 +62,12 @@ void clear_oneshot_locked_mods(void) { | |||
63 | oneshot_locked_mods_changed_kb(oneshot_locked_mods); | 62 | oneshot_locked_mods_changed_kb(oneshot_locked_mods); |
64 | } | 63 | } |
65 | } | 64 | } |
66 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 65 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
67 | static uint16_t oneshot_time = 0; | 66 | static uint16_t oneshot_time = 0; |
68 | bool has_oneshot_mods_timed_out(void) { | 67 | bool has_oneshot_mods_timed_out(void) { return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT; } |
69 | return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT; | 68 | # else |
70 | } | 69 | bool has_oneshot_mods_timed_out(void) { return false; } |
71 | #else | 70 | # endif |
72 | bool has_oneshot_mods_timed_out(void) { | ||
73 | return false; | ||
74 | } | ||
75 | #endif | ||
76 | #endif | 71 | #endif |
77 | 72 | ||
78 | /* oneshot layer */ | 73 | /* oneshot layer */ |
@@ -88,44 +83,39 @@ static int8_t oneshot_layer_data = 0; | |||
88 | inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; } | 83 | inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; } |
89 | inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; } | 84 | inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; } |
90 | 85 | ||
91 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 86 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
92 | static uint16_t oneshot_layer_time = 0; | 87 | static uint16_t oneshot_layer_time = 0; |
93 | inline bool has_oneshot_layer_timed_out() { | 88 | inline bool has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); } |
94 | return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && | 89 | # endif |
95 | !(get_oneshot_layer_state() & ONESHOT_TOGGLED); | ||
96 | } | ||
97 | #endif | ||
98 | 90 | ||
99 | /** \brief Set oneshot layer | 91 | /** \brief Set oneshot layer |
100 | * | 92 | * |
101 | * FIXME: needs doc | 93 | * FIXME: needs doc |
102 | */ | 94 | */ |
103 | void set_oneshot_layer(uint8_t layer, uint8_t state) | 95 | void set_oneshot_layer(uint8_t layer, uint8_t state) { |
104 | { | ||
105 | oneshot_layer_data = layer << 3 | state; | 96 | oneshot_layer_data = layer << 3 | state; |
106 | layer_on(layer); | 97 | layer_on(layer); |
107 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 98 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
108 | oneshot_layer_time = timer_read(); | 99 | oneshot_layer_time = timer_read(); |
109 | #endif | 100 | # endif |
110 | oneshot_layer_changed_kb(get_oneshot_layer()); | 101 | oneshot_layer_changed_kb(get_oneshot_layer()); |
111 | } | 102 | } |
112 | /** \brief Reset oneshot layer | 103 | /** \brief Reset oneshot layer |
113 | * | 104 | * |
114 | * FIXME: needs doc | 105 | * FIXME: needs doc |
115 | */ | 106 | */ |
116 | void reset_oneshot_layer(void) { | 107 | void reset_oneshot_layer(void) { |
117 | oneshot_layer_data = 0; | 108 | oneshot_layer_data = 0; |
118 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 109 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
119 | oneshot_layer_time = 0; | 110 | oneshot_layer_time = 0; |
120 | #endif | 111 | # endif |
121 | oneshot_layer_changed_kb(get_oneshot_layer()); | 112 | oneshot_layer_changed_kb(get_oneshot_layer()); |
122 | } | 113 | } |
123 | /** \brief Clear oneshot layer | 114 | /** \brief Clear oneshot layer |
124 | * | 115 | * |
125 | * FIXME: needs doc | 116 | * FIXME: needs doc |
126 | */ | 117 | */ |
127 | void clear_oneshot_layer_state(oneshot_fullfillment_t state) | 118 | void clear_oneshot_layer_state(oneshot_fullfillment_t state) { |
128 | { | ||
129 | uint8_t start_state = oneshot_layer_data; | 119 | uint8_t start_state = oneshot_layer_data; |
130 | oneshot_layer_data &= ~state; | 120 | oneshot_layer_data &= ~state; |
131 | if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) { | 121 | if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) { |
@@ -137,10 +127,7 @@ void clear_oneshot_layer_state(oneshot_fullfillment_t state) | |||
137 | * | 127 | * |
138 | * FIXME: needs doc | 128 | * FIXME: needs doc |
139 | */ | 129 | */ |
140 | bool is_oneshot_layer_active(void) | 130 | bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); } |
141 | { | ||
142 | return get_oneshot_layer_state(); | ||
143 | } | ||
144 | #endif | 131 | #endif |
145 | 132 | ||
146 | /** \brief Send keyboard report | 133 | /** \brief Send keyboard report |
@@ -148,17 +135,17 @@ bool is_oneshot_layer_active(void) | |||
148 | * FIXME: needs doc | 135 | * FIXME: needs doc |
149 | */ | 136 | */ |
150 | void send_keyboard_report(void) { | 137 | void send_keyboard_report(void) { |
151 | keyboard_report->mods = real_mods; | 138 | keyboard_report->mods = real_mods; |
152 | keyboard_report->mods |= weak_mods; | 139 | keyboard_report->mods |= weak_mods; |
153 | keyboard_report->mods |= macro_mods; | 140 | keyboard_report->mods |= macro_mods; |
154 | #ifndef NO_ACTION_ONESHOT | 141 | #ifndef NO_ACTION_ONESHOT |
155 | if (oneshot_mods) { | 142 | if (oneshot_mods) { |
156 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 143 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
157 | if (has_oneshot_mods_timed_out()) { | 144 | if (has_oneshot_mods_timed_out()) { |
158 | dprintf("Oneshot: timeout\n"); | 145 | dprintf("Oneshot: timeout\n"); |
159 | clear_oneshot_mods(); | 146 | clear_oneshot_mods(); |
160 | } | 147 | } |
161 | #endif | 148 | # endif |
162 | keyboard_report->mods |= oneshot_mods; | 149 | keyboard_report->mods |= oneshot_mods; |
163 | if (has_anykey(keyboard_report)) { | 150 | if (has_anykey(keyboard_report)) { |
164 | clear_oneshot_mods(); | 151 | clear_oneshot_mods(); |
@@ -254,90 +241,72 @@ void clear_macro_mods(void) { macro_mods = 0; } | |||
254 | * FIXME: needs doc | 241 | * FIXME: needs doc |
255 | */ | 242 | */ |
256 | void set_oneshot_mods(uint8_t mods) { | 243 | void set_oneshot_mods(uint8_t mods) { |
257 | if (oneshot_mods != mods) { | 244 | if (oneshot_mods != mods) { |
258 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 245 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
259 | oneshot_time = timer_read(); | 246 | oneshot_time = timer_read(); |
260 | #endif | 247 | # endif |
261 | oneshot_mods = mods; | 248 | oneshot_mods = mods; |
262 | oneshot_mods_changed_kb(mods); | 249 | oneshot_mods_changed_kb(mods); |
263 | } | 250 | } |
264 | } | 251 | } |
265 | /** \brief clear oneshot mods | 252 | /** \brief clear oneshot mods |
266 | * | 253 | * |
267 | * FIXME: needs doc | 254 | * FIXME: needs doc |
268 | */ | 255 | */ |
269 | void clear_oneshot_mods(void) { | 256 | void clear_oneshot_mods(void) { |
270 | if (oneshot_mods) { | 257 | if (oneshot_mods) { |
271 | oneshot_mods = 0; | 258 | oneshot_mods = 0; |
272 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 259 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
273 | oneshot_time = 0; | 260 | oneshot_time = 0; |
274 | #endif | 261 | # endif |
275 | oneshot_mods_changed_kb(oneshot_mods); | 262 | oneshot_mods_changed_kb(oneshot_mods); |
276 | } | 263 | } |
277 | } | 264 | } |
278 | /** \brief get oneshot mods | 265 | /** \brief get oneshot mods |
279 | * | 266 | * |
280 | * FIXME: needs doc | 267 | * FIXME: needs doc |
281 | */ | 268 | */ |
282 | uint8_t get_oneshot_mods(void) | 269 | uint8_t get_oneshot_mods(void) { return oneshot_mods; } |
283 | { | ||
284 | return oneshot_mods; | ||
285 | } | ||
286 | #endif | 270 | #endif |
287 | 271 | ||
288 | /** \brief Called when the one shot modifiers have been changed. | 272 | /** \brief Called when the one shot modifiers have been changed. |
289 | * | 273 | * |
290 | * \param mods Contains the active modifiers active after the change. | 274 | * \param mods Contains the active modifiers active after the change. |
291 | */ | 275 | */ |
292 | __attribute__((weak)) | 276 | __attribute__((weak)) void oneshot_locked_mods_changed_user(uint8_t mods) {} |
293 | void oneshot_locked_mods_changed_user(uint8_t mods) { } | ||
294 | 277 | ||
295 | /** \brief Called when the locked one shot modifiers have been changed. | 278 | /** \brief Called when the locked one shot modifiers have been changed. |
296 | * | 279 | * |
297 | * \param mods Contains the active modifiers active after the change. | 280 | * \param mods Contains the active modifiers active after the change. |
298 | */ | 281 | */ |
299 | __attribute__((weak)) | 282 | __attribute__((weak)) void oneshot_locked_mods_changed_kb(uint8_t mods) { oneshot_locked_mods_changed_user(mods); } |
300 | void oneshot_locked_mods_changed_kb(uint8_t mods) { | ||
301 | oneshot_locked_mods_changed_user(mods); | ||
302 | } | ||
303 | 283 | ||
304 | /** \brief Called when the one shot modifiers have been changed. | 284 | /** \brief Called when the one shot modifiers have been changed. |
305 | * | 285 | * |
306 | * \param mods Contains the active modifiers active after the change. | 286 | * \param mods Contains the active modifiers active after the change. |
307 | */ | 287 | */ |
308 | __attribute__((weak)) | 288 | __attribute__((weak)) void oneshot_mods_changed_user(uint8_t mods) {} |
309 | void oneshot_mods_changed_user(uint8_t mods) { } | ||
310 | 289 | ||
311 | /** \brief Called when the one shot modifiers have been changed. | 290 | /** \brief Called when the one shot modifiers have been changed. |
312 | * | 291 | * |
313 | * \param mods Contains the active modifiers active after the change. | 292 | * \param mods Contains the active modifiers active after the change. |
314 | */ | 293 | */ |
315 | __attribute__((weak)) | 294 | __attribute__((weak)) void oneshot_mods_changed_kb(uint8_t mods) { oneshot_mods_changed_user(mods); } |
316 | void oneshot_mods_changed_kb(uint8_t mods) { | ||
317 | oneshot_mods_changed_user(mods); | ||
318 | } | ||
319 | 295 | ||
320 | /** \brief Called when the one shot layers have been changed. | 296 | /** \brief Called when the one shot layers have been changed. |
321 | * | 297 | * |
322 | * \param layer Contains the layer that is toggled on, or zero when toggled off. | 298 | * \param layer Contains the layer that is toggled on, or zero when toggled off. |
323 | */ | 299 | */ |
324 | __attribute__((weak)) | 300 | __attribute__((weak)) void oneshot_layer_changed_user(uint8_t layer) {} |
325 | void oneshot_layer_changed_user(uint8_t layer) { } | ||
326 | 301 | ||
327 | /** \brief Called when the one shot layers have been changed. | 302 | /** \brief Called when the one shot layers have been changed. |
328 | * | 303 | * |
329 | * \param layer Contains the layer that is toggled on, or zero when toggled off. | 304 | * \param layer Contains the layer that is toggled on, or zero when toggled off. |
330 | */ | 305 | */ |
331 | __attribute__((weak)) | 306 | __attribute__((weak)) void oneshot_layer_changed_kb(uint8_t layer) { oneshot_layer_changed_user(layer); } |
332 | void oneshot_layer_changed_kb(uint8_t layer) { | ||
333 | oneshot_layer_changed_user(layer); | ||
334 | } | ||
335 | 307 | ||
336 | /** \brief inspect keyboard state | 308 | /** \brief inspect keyboard state |
337 | * | 309 | * |
338 | * FIXME: needs doc | 310 | * FIXME: needs doc |
339 | */ | 311 | */ |
340 | uint8_t has_anymod(void) | 312 | uint8_t has_anymod(void) { return bitpop(real_mods); } |
341 | { | ||
342 | return bitpop(real_mods); | ||
343 | } | ||
diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h index d03f5682a..1ce03ed0e 100644 --- a/tmk_core/common/action_util.h +++ b/tmk_core/common/action_util.h | |||
@@ -29,65 +29,54 @@ extern report_keyboard_t *keyboard_report; | |||
29 | void send_keyboard_report(void); | 29 | void send_keyboard_report(void); |
30 | 30 | ||
31 | /* key */ | 31 | /* key */ |
32 | inline void add_key(uint8_t key) { | 32 | inline void add_key(uint8_t key) { add_key_to_report(keyboard_report, key); } |
33 | add_key_to_report(keyboard_report, key); | ||
34 | } | ||
35 | 33 | ||
36 | inline void del_key(uint8_t key) { | 34 | inline void del_key(uint8_t key) { del_key_from_report(keyboard_report, key); } |
37 | del_key_from_report(keyboard_report, key); | ||
38 | } | ||
39 | 35 | ||
40 | inline void clear_keys(void) { | 36 | inline void clear_keys(void) { clear_keys_from_report(keyboard_report); } |
41 | clear_keys_from_report(keyboard_report); | ||
42 | } | ||
43 | 37 | ||
44 | /* modifier */ | 38 | /* modifier */ |
45 | uint8_t get_mods(void); | 39 | uint8_t get_mods(void); |
46 | void add_mods(uint8_t mods); | 40 | void add_mods(uint8_t mods); |
47 | void del_mods(uint8_t mods); | 41 | void del_mods(uint8_t mods); |
48 | void set_mods(uint8_t mods); | 42 | void set_mods(uint8_t mods); |
49 | void clear_mods(void); | 43 | void clear_mods(void); |
50 | 44 | ||
51 | /* weak modifier */ | 45 | /* weak modifier */ |
52 | uint8_t get_weak_mods(void); | 46 | uint8_t get_weak_mods(void); |
53 | void add_weak_mods(uint8_t mods); | 47 | void add_weak_mods(uint8_t mods); |
54 | void del_weak_mods(uint8_t mods); | 48 | void del_weak_mods(uint8_t mods); |
55 | void set_weak_mods(uint8_t mods); | 49 | void set_weak_mods(uint8_t mods); |
56 | void clear_weak_mods(void); | 50 | void clear_weak_mods(void); |
57 | 51 | ||
58 | /* macro modifier */ | 52 | /* macro modifier */ |
59 | uint8_t get_macro_mods(void); | 53 | uint8_t get_macro_mods(void); |
60 | void add_macro_mods(uint8_t mods); | 54 | void add_macro_mods(uint8_t mods); |
61 | void del_macro_mods(uint8_t mods); | 55 | void del_macro_mods(uint8_t mods); |
62 | void set_macro_mods(uint8_t mods); | 56 | void set_macro_mods(uint8_t mods); |
63 | void clear_macro_mods(void); | 57 | void clear_macro_mods(void); |
64 | 58 | ||
65 | /* oneshot modifier */ | 59 | /* oneshot modifier */ |
66 | void set_oneshot_mods(uint8_t mods); | 60 | void set_oneshot_mods(uint8_t mods); |
67 | uint8_t get_oneshot_mods(void); | 61 | uint8_t get_oneshot_mods(void); |
68 | void clear_oneshot_mods(void); | 62 | void clear_oneshot_mods(void); |
69 | void oneshot_toggle(void); | 63 | void oneshot_toggle(void); |
70 | void oneshot_enable(void); | 64 | void oneshot_enable(void); |
71 | void oneshot_disable(void); | 65 | void oneshot_disable(void); |
72 | bool has_oneshot_mods_timed_out(void); | 66 | bool has_oneshot_mods_timed_out(void); |
73 | 67 | ||
74 | uint8_t get_oneshot_locked_mods(void); | 68 | uint8_t get_oneshot_locked_mods(void); |
75 | void set_oneshot_locked_mods(uint8_t mods); | 69 | void set_oneshot_locked_mods(uint8_t mods); |
76 | void clear_oneshot_locked_mods(void); | 70 | void clear_oneshot_locked_mods(void); |
77 | 71 | ||
78 | typedef enum { | 72 | typedef enum { ONESHOT_PRESSED = 0b01, ONESHOT_OTHER_KEY_PRESSED = 0b10, ONESHOT_START = 0b11, ONESHOT_TOGGLED = 0b100 } oneshot_fullfillment_t; |
79 | ONESHOT_PRESSED = 0b01, | 73 | void set_oneshot_layer(uint8_t layer, uint8_t state); |
80 | ONESHOT_OTHER_KEY_PRESSED = 0b10, | ||
81 | ONESHOT_START = 0b11, | ||
82 | ONESHOT_TOGGLED = 0b100 | ||
83 | } oneshot_fullfillment_t; | ||
84 | void set_oneshot_layer(uint8_t layer, uint8_t state); | ||
85 | uint8_t get_oneshot_layer(void); | 74 | uint8_t get_oneshot_layer(void); |
86 | void clear_oneshot_layer_state(oneshot_fullfillment_t state); | 75 | void clear_oneshot_layer_state(oneshot_fullfillment_t state); |
87 | void reset_oneshot_layer(void); | 76 | void reset_oneshot_layer(void); |
88 | bool is_oneshot_layer_active(void); | 77 | bool is_oneshot_layer_active(void); |
89 | uint8_t get_oneshot_layer_state(void); | 78 | uint8_t get_oneshot_layer_state(void); |
90 | bool has_oneshot_layer_timed_out(void); | 79 | bool has_oneshot_layer_timed_out(void); |
91 | 80 | ||
92 | void oneshot_locked_mods_changed_user(uint8_t mods); | 81 | void oneshot_locked_mods_changed_user(uint8_t mods); |
93 | void oneshot_locked_mods_changed_kb(uint8_t mods); | 82 | void oneshot_locked_mods_changed_kb(uint8_t mods); |
diff --git a/tmk_core/common/arm_atsam/bootloader.c b/tmk_core/common/arm_atsam/bootloader.c index ba71bfeb0..9015b00aa 100644 --- a/tmk_core/common/arm_atsam/bootloader.c +++ b/tmk_core/common/arm_atsam/bootloader.c | |||
@@ -18,34 +18,40 @@ | |||
18 | #include "samd51j18a.h" | 18 | #include "samd51j18a.h" |
19 | #include "md_bootloader.h" | 19 | #include "md_bootloader.h" |
20 | 20 | ||
21 | //Set watchdog timer to reset. Directs the bootloader to stay in programming mode. | 21 | // Set watchdog timer to reset. Directs the bootloader to stay in programming mode. |
22 | void bootloader_jump(void) { | 22 | void bootloader_jump(void) { |
23 | #ifdef KEYBOARD_massdrop_ctrl | 23 | #ifdef KEYBOARD_massdrop_ctrl |
24 | //CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method. | 24 | // CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method. |
25 | uint8_t ver_ram_method[] = "v2.18Jun 22 2018 17:28:08"; //The version to match (NULL terminated by compiler) | 25 | uint8_t ver_ram_method[] = "v2.18Jun 22 2018 17:28:08"; // The version to match (NULL terminated by compiler) |
26 | uint8_t *ver_check = ver_ram_method; //Pointer to version match string for traversal | 26 | uint8_t *ver_check = ver_ram_method; // Pointer to version match string for traversal |
27 | uint8_t *ver_rom = (uint8_t *)0x21A0; //Pointer to address in ROM where this specific bootloader version would exist | 27 | uint8_t *ver_rom = (uint8_t *)0x21A0; // Pointer to address in ROM where this specific bootloader version would exist |
28 | 28 | ||
29 | while (*ver_check && *ver_rom == *ver_check) { //While there are check version characters to match and bootloader's version matches check's version | 29 | while (*ver_check && *ver_rom == *ver_check) { // While there are check version characters to match and bootloader's version matches check's version |
30 | ver_check++; //Move check version pointer to next character | 30 | ver_check++; // Move check version pointer to next character |
31 | ver_rom++; //Move ROM version pointer to next character | 31 | ver_rom++; // Move ROM version pointer to next character |
32 | } | 32 | } |
33 | 33 | ||
34 | if (!*ver_check) { //If check version pointer is NULL, all characters have matched | 34 | if (!*ver_check) { // If check version pointer is NULL, all characters have matched |
35 | *MAGIC_ADDR = BOOTLOADER_MAGIC; //Set magic number into RAM | 35 | *MAGIC_ADDR = BOOTLOADER_MAGIC; // Set magic number into RAM |
36 | NVIC_SystemReset(); //Perform system reset | 36 | NVIC_SystemReset(); // Perform system reset |
37 | while (1) {} //Won't get here | 37 | while (1) { |
38 | } // Won't get here | ||
38 | } | 39 | } |
39 | #endif | 40 | #endif |
40 | 41 | ||
41 | WDT->CTRLA.bit.ENABLE = 0; | 42 | WDT->CTRLA.bit.ENABLE = 0; |
42 | while (WDT->SYNCBUSY.bit.ENABLE) {} | 43 | while (WDT->SYNCBUSY.bit.ENABLE) { |
43 | while (WDT->CTRLA.bit.ENABLE) {} | 44 | } |
44 | WDT->CONFIG.bit.WINDOW = 0; | 45 | while (WDT->CTRLA.bit.ENABLE) { |
45 | WDT->CONFIG.bit.PER = 0; | 46 | } |
47 | WDT->CONFIG.bit.WINDOW = 0; | ||
48 | WDT->CONFIG.bit.PER = 0; | ||
46 | WDT->EWCTRL.bit.EWOFFSET = 0; | 49 | WDT->EWCTRL.bit.EWOFFSET = 0; |
47 | WDT->CTRLA.bit.ENABLE = 1; | 50 | WDT->CTRLA.bit.ENABLE = 1; |
48 | while (WDT->SYNCBUSY.bit.ENABLE) {} | 51 | while (WDT->SYNCBUSY.bit.ENABLE) { |
49 | while (!WDT->CTRLA.bit.ENABLE) {} | 52 | } |
50 | while (1) {} //Wait on timeout | 53 | while (!WDT->CTRLA.bit.ENABLE) { |
54 | } | ||
55 | while (1) { | ||
56 | } // Wait on timeout | ||
51 | } | 57 | } |
diff --git a/tmk_core/common/arm_atsam/eeprom.c b/tmk_core/common/arm_atsam/eeprom.c index 61cc039ef..44a0bf4d7 100644 --- a/tmk_core/common/arm_atsam/eeprom.c +++ b/tmk_core/common/arm_atsam/eeprom.c | |||
@@ -21,78 +21,75 @@ | |||
21 | static uint8_t buffer[EEPROM_SIZE]; | 21 | static uint8_t buffer[EEPROM_SIZE]; |
22 | 22 | ||
23 | uint8_t eeprom_read_byte(const uint8_t *addr) { | 23 | uint8_t eeprom_read_byte(const uint8_t *addr) { |
24 | uintptr_t offset = (uintptr_t)addr; | 24 | uintptr_t offset = (uintptr_t)addr; |
25 | return buffer[offset]; | 25 | return buffer[offset]; |
26 | } | 26 | } |
27 | 27 | ||
28 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { | 28 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { |
29 | uintptr_t offset = (uintptr_t)addr; | 29 | uintptr_t offset = (uintptr_t)addr; |
30 | buffer[offset] = value; | 30 | buffer[offset] = value; |
31 | } | 31 | } |
32 | 32 | ||
33 | uint16_t eeprom_read_word(const uint16_t *addr) { | 33 | uint16_t eeprom_read_word(const uint16_t *addr) { |
34 | const uint8_t *p = (const uint8_t *)addr; | 34 | const uint8_t *p = (const uint8_t *)addr; |
35 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8); | 35 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8); |
36 | } | 36 | } |
37 | 37 | ||
38 | uint32_t eeprom_read_dword(const uint32_t *addr) { | 38 | uint32_t eeprom_read_dword(const uint32_t *addr) { |
39 | const uint8_t *p = (const uint8_t *)addr; | 39 | const uint8_t *p = (const uint8_t *)addr; |
40 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8) | 40 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24); |
41 | | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24); | ||
42 | } | 41 | } |
43 | 42 | ||
44 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { | 43 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { |
45 | const uint8_t *p = (const uint8_t *)addr; | 44 | const uint8_t *p = (const uint8_t *)addr; |
46 | uint8_t *dest = (uint8_t *)buf; | 45 | uint8_t * dest = (uint8_t *)buf; |
47 | while (len--) { | 46 | while (len--) { |
48 | *dest++ = eeprom_read_byte(p++); | 47 | *dest++ = eeprom_read_byte(p++); |
49 | } | 48 | } |
50 | } | 49 | } |
51 | 50 | ||
52 | void eeprom_write_word(uint16_t *addr, uint16_t value) { | 51 | void eeprom_write_word(uint16_t *addr, uint16_t value) { |
53 | uint8_t *p = (uint8_t *)addr; | 52 | uint8_t *p = (uint8_t *)addr; |
54 | eeprom_write_byte(p++, value); | 53 | eeprom_write_byte(p++, value); |
55 | eeprom_write_byte(p, value >> 8); | 54 | eeprom_write_byte(p, value >> 8); |
56 | } | 55 | } |
57 | 56 | ||
58 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { | 57 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { |
59 | uint8_t *p = (uint8_t *)addr; | 58 | uint8_t *p = (uint8_t *)addr; |
60 | eeprom_write_byte(p++, value); | 59 | eeprom_write_byte(p++, value); |
61 | eeprom_write_byte(p++, value >> 8); | 60 | eeprom_write_byte(p++, value >> 8); |
62 | eeprom_write_byte(p++, value >> 16); | 61 | eeprom_write_byte(p++, value >> 16); |
63 | eeprom_write_byte(p, value >> 24); | 62 | eeprom_write_byte(p, value >> 24); |
64 | } | 63 | } |
65 | 64 | ||
66 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { | 65 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { |
67 | uint8_t *p = (uint8_t *)addr; | 66 | uint8_t * p = (uint8_t *)addr; |
68 | const uint8_t *src = (const uint8_t *)buf; | 67 | const uint8_t *src = (const uint8_t *)buf; |
69 | while (len--) { | 68 | while (len--) { |
70 | eeprom_write_byte(p++, *src++); | 69 | eeprom_write_byte(p++, *src++); |
71 | } | 70 | } |
72 | } | 71 | } |
73 | 72 | ||
74 | void eeprom_update_byte(uint8_t *addr, uint8_t value) { | 73 | void eeprom_update_byte(uint8_t *addr, uint8_t value) { eeprom_write_byte(addr, value); } |
75 | eeprom_write_byte(addr, value); | ||
76 | } | ||
77 | 74 | ||
78 | void eeprom_update_word(uint16_t *addr, uint16_t value) { | 75 | void eeprom_update_word(uint16_t *addr, uint16_t value) { |
79 | uint8_t *p = (uint8_t *)addr; | 76 | uint8_t *p = (uint8_t *)addr; |
80 | eeprom_write_byte(p++, value); | 77 | eeprom_write_byte(p++, value); |
81 | eeprom_write_byte(p, value >> 8); | 78 | eeprom_write_byte(p, value >> 8); |
82 | } | 79 | } |
83 | 80 | ||
84 | void eeprom_update_dword(uint32_t *addr, uint32_t value) { | 81 | void eeprom_update_dword(uint32_t *addr, uint32_t value) { |
85 | uint8_t *p = (uint8_t *)addr; | 82 | uint8_t *p = (uint8_t *)addr; |
86 | eeprom_write_byte(p++, value); | 83 | eeprom_write_byte(p++, value); |
87 | eeprom_write_byte(p++, value >> 8); | 84 | eeprom_write_byte(p++, value >> 8); |
88 | eeprom_write_byte(p++, value >> 16); | 85 | eeprom_write_byte(p++, value >> 16); |
89 | eeprom_write_byte(p, value >> 24); | 86 | eeprom_write_byte(p, value >> 24); |
90 | } | 87 | } |
91 | 88 | ||
92 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { | 89 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { |
93 | uint8_t *p = (uint8_t *)addr; | 90 | uint8_t * p = (uint8_t *)addr; |
94 | const uint8_t *src = (const uint8_t *)buf; | 91 | const uint8_t *src = (const uint8_t *)buf; |
95 | while (len--) { | 92 | while (len--) { |
96 | eeprom_write_byte(p++, *src++); | 93 | eeprom_write_byte(p++, *src++); |
97 | } | 94 | } |
98 | } | 95 | } |
diff --git a/tmk_core/common/arm_atsam/printf.c b/tmk_core/common/arm_atsam/printf.c index 7f298d1fd..cd7cdb52e 100644 --- a/tmk_core/common/arm_atsam/printf.c +++ b/tmk_core/common/arm_atsam/printf.c | |||
@@ -17,50 +17,52 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #ifdef CONSOLE_ENABLE | 18 | #ifdef CONSOLE_ENABLE |
19 | 19 | ||
20 | #include "samd51j18a.h" | 20 | # include "samd51j18a.h" |
21 | #include "arm_atsam_protocol.h" | 21 | # include "arm_atsam_protocol.h" |
22 | #include "printf.h" | 22 | # include "printf.h" |
23 | #include <string.h> | 23 | # include <string.h> |
24 | #include <stdarg.h> | 24 | # include <stdarg.h> |
25 | 25 | ||
26 | void console_printf(char *fmt, ...) { | 26 | void console_printf(char *fmt, ...) { |
27 | while (udi_hid_con_b_report_trans_ongoing) {} //Wait for any previous transfers to complete | 27 | while (udi_hid_con_b_report_trans_ongoing) { |
28 | } // Wait for any previous transfers to complete | ||
28 | 29 | ||
29 | static char console_printbuf[CONSOLE_PRINTBUF_SIZE]; //Print and send buffer | 30 | static char console_printbuf[CONSOLE_PRINTBUF_SIZE]; // Print and send buffer |
30 | va_list va; | 31 | va_list va; |
31 | int result; | 32 | int result; |
32 | 33 | ||
33 | va_start(va, fmt); | 34 | va_start(va, fmt); |
34 | result = vsnprintf(console_printbuf, CONSOLE_PRINTBUF_SIZE, fmt, va); | 35 | result = vsnprintf(console_printbuf, CONSOLE_PRINTBUF_SIZE, fmt, va); |
35 | va_end(va); | 36 | va_end(va); |
36 | 37 | ||
37 | uint32_t irqflags; | 38 | uint32_t irqflags; |
38 | char *pconbuf = console_printbuf; //Pointer to start send from | 39 | char * pconbuf = console_printbuf; // Pointer to start send from |
39 | int send_out = CONSOLE_EPSIZE; //Bytes to send per transfer | 40 | int send_out = CONSOLE_EPSIZE; // Bytes to send per transfer |
40 | 41 | ||
41 | while (result > 0) { //While not error and bytes remain | 42 | while (result > 0) { // While not error and bytes remain |
42 | while (udi_hid_con_b_report_trans_ongoing) {} //Wait for any previous transfers to complete | 43 | while (udi_hid_con_b_report_trans_ongoing) { |
44 | } // Wait for any previous transfers to complete | ||
43 | 45 | ||
44 | irqflags = __get_PRIMASK(); | 46 | irqflags = __get_PRIMASK(); |
45 | __disable_irq(); | 47 | __disable_irq(); |
46 | __DMB(); | 48 | __DMB(); |
47 | 49 | ||
48 | if (result < CONSOLE_EPSIZE) { //If remaining bytes are less than console epsize | 50 | if (result < CONSOLE_EPSIZE) { // If remaining bytes are less than console epsize |
49 | memset(udi_hid_con_report, 0, CONSOLE_EPSIZE); //Clear the buffer | 51 | memset(udi_hid_con_report, 0, CONSOLE_EPSIZE); // Clear the buffer |
50 | send_out = result; //Send remaining size | 52 | send_out = result; // Send remaining size |
51 | } | 53 | } |
52 | 54 | ||
53 | memcpy(udi_hid_con_report, pconbuf, send_out); //Copy data into the send buffer | 55 | memcpy(udi_hid_con_report, pconbuf, send_out); // Copy data into the send buffer |
54 | 56 | ||
55 | udi_hid_con_b_report_valid = 1; //Set report valid | 57 | udi_hid_con_b_report_valid = 1; // Set report valid |
56 | udi_hid_con_send_report(); //Send report | 58 | udi_hid_con_send_report(); // Send report |
57 | 59 | ||
58 | __DMB(); | 60 | __DMB(); |
59 | __set_PRIMASK(irqflags); | 61 | __set_PRIMASK(irqflags); |
60 | 62 | ||
61 | result -= send_out; //Decrement result by bytes sent | 63 | result -= send_out; // Decrement result by bytes sent |
62 | pconbuf += send_out; //Increment buffer point by bytes sent | 64 | pconbuf += send_out; // Increment buffer point by bytes sent |
63 | } | 65 | } |
64 | } | 66 | } |
65 | 67 | ||
66 | #endif //CONSOLE_ENABLE | 68 | #endif // CONSOLE_ENABLE |
diff --git a/tmk_core/common/arm_atsam/printf.h b/tmk_core/common/arm_atsam/printf.h index 1f1c2280b..ad6672220 100644 --- a/tmk_core/common/arm_atsam/printf.h +++ b/tmk_core/common/arm_atsam/printf.h | |||
@@ -7,5 +7,4 @@ void console_printf(char *fmt, ...); | |||
7 | 7 | ||
8 | #define __xprintf console_printf | 8 | #define __xprintf console_printf |
9 | 9 | ||
10 | #endif //_PRINTF_H_ | 10 | #endif //_PRINTF_H_ |
11 | |||
diff --git a/tmk_core/common/arm_atsam/suspend.c b/tmk_core/common/arm_atsam/suspend.c index ecf8f0ed1..2dad00570 100644 --- a/tmk_core/common/arm_atsam/suspend.c +++ b/tmk_core/common/arm_atsam/suspend.c | |||
@@ -7,44 +7,35 @@ | |||
7 | * | 7 | * |
8 | * FIXME: needs doc | 8 | * FIXME: needs doc |
9 | */ | 9 | */ |
10 | void suspend_idle(uint8_t time) { | 10 | void suspend_idle(uint8_t time) { /* Note: Not used anywhere currently */ } |
11 | /* Note: Not used anywhere currently */ | ||
12 | } | ||
13 | 11 | ||
14 | /** \brief Run user level Power down | 12 | /** \brief Run user level Power down |
15 | * | 13 | * |
16 | * FIXME: needs doc | 14 | * FIXME: needs doc |
17 | */ | 15 | */ |
18 | __attribute__ ((weak)) | 16 | __attribute__((weak)) void suspend_power_down_user(void) {} |
19 | void suspend_power_down_user (void) { | ||
20 | |||
21 | } | ||
22 | 17 | ||
23 | /** \brief Run keyboard level Power down | 18 | /** \brief Run keyboard level Power down |
24 | * | 19 | * |
25 | * FIXME: needs doc | 20 | * FIXME: needs doc |
26 | */ | 21 | */ |
27 | __attribute__ ((weak)) | 22 | __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } |
28 | void suspend_power_down_kb(void) { | ||
29 | suspend_power_down_user(); | ||
30 | } | ||
31 | 23 | ||
32 | /** \brief Suspend power down | 24 | /** \brief Suspend power down |
33 | * | 25 | * |
34 | * FIXME: needs doc | 26 | * FIXME: needs doc |
35 | */ | 27 | */ |
36 | void suspend_power_down(void) | 28 | void suspend_power_down(void) { |
37 | { | ||
38 | #ifdef RGB_MATRIX_ENABLE | 29 | #ifdef RGB_MATRIX_ENABLE |
39 | I2C3733_Control_Set(0); //Disable LED driver | 30 | I2C3733_Control_Set(0); // Disable LED driver |
40 | #endif | 31 | #endif |
41 | 32 | ||
42 | suspend_power_down_kb(); | 33 | suspend_power_down_kb(); |
43 | } | 34 | } |
44 | 35 | ||
45 | __attribute__ ((weak)) void matrix_power_up(void) {} | 36 | __attribute__((weak)) void matrix_power_up(void) {} |
46 | __attribute__ ((weak)) void matrix_power_down(void) {} | 37 | __attribute__((weak)) void matrix_power_down(void) {} |
47 | bool suspend_wakeup_condition(void) { | 38 | bool suspend_wakeup_condition(void) { |
48 | matrix_power_up(); | 39 | matrix_power_up(); |
49 | matrix_scan(); | 40 | matrix_scan(); |
50 | matrix_power_down(); | 41 | matrix_power_down(); |
@@ -58,19 +49,13 @@ bool suspend_wakeup_condition(void) { | |||
58 | * | 49 | * |
59 | * FIXME: needs doc | 50 | * FIXME: needs doc |
60 | */ | 51 | */ |
61 | __attribute__ ((weak)) | 52 | __attribute__((weak)) void suspend_wakeup_init_user(void) {} |
62 | void suspend_wakeup_init_user(void) { | ||
63 | |||
64 | } | ||
65 | 53 | ||
66 | /** \brief run keyboard level code immediately after wakeup | 54 | /** \brief run keyboard level code immediately after wakeup |
67 | * | 55 | * |
68 | * FIXME: needs doc | 56 | * FIXME: needs doc |
69 | */ | 57 | */ |
70 | __attribute__ ((weak)) | 58 | __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } |
71 | void suspend_wakeup_init_kb(void) { | ||
72 | suspend_wakeup_init_user(); | ||
73 | } | ||
74 | 59 | ||
75 | /** \brief run immediately after wakeup | 60 | /** \brief run immediately after wakeup |
76 | * | 61 | * |
@@ -78,15 +63,14 @@ void suspend_wakeup_init_kb(void) { | |||
78 | */ | 63 | */ |
79 | void suspend_wakeup_init(void) { | 64 | void suspend_wakeup_init(void) { |
80 | #ifdef RGB_MATRIX_ENABLE | 65 | #ifdef RGB_MATRIX_ENABLE |
81 | #ifdef USE_MASSDROP_CONFIGURATOR | 66 | # ifdef USE_MASSDROP_CONFIGURATOR |
82 | if (led_enabled) { | 67 | if (led_enabled) { |
83 | I2C3733_Control_Set(1); | 68 | I2C3733_Control_Set(1); |
84 | } | 69 | } |
85 | #else | 70 | # else |
86 | I2C3733_Control_Set(1); | 71 | I2C3733_Control_Set(1); |
87 | #endif | 72 | # endif |
88 | #endif | 73 | #endif |
89 | 74 | ||
90 | suspend_wakeup_init_kb(); | 75 | suspend_wakeup_init_kb(); |
91 | } | 76 | } |
92 | |||
diff --git a/tmk_core/common/arm_atsam/timer.c b/tmk_core/common/arm_atsam/timer.c index 6c3905e30..b835dd5e7 100644 --- a/tmk_core/common/arm_atsam/timer.c +++ b/tmk_core/common/arm_atsam/timer.c | |||
@@ -2,42 +2,18 @@ | |||
2 | #include "timer.h" | 2 | #include "timer.h" |
3 | #include "tmk_core/protocol/arm_atsam/clks.h" | 3 | #include "tmk_core/protocol/arm_atsam/clks.h" |
4 | 4 | ||
5 | void set_time(uint64_t tset) | 5 | void set_time(uint64_t tset) { ms_clk = tset; } |
6 | { | 6 | |
7 | ms_clk = tset; | 7 | void timer_init(void) { timer_clear(); } |
8 | } | 8 | |
9 | 9 | uint16_t timer_read(void) { return (uint16_t)ms_clk; } | |
10 | void timer_init(void) | 10 | |
11 | { | 11 | uint32_t timer_read32(void) { return (uint32_t)ms_clk; } |
12 | timer_clear(); | 12 | |
13 | } | 13 | uint64_t timer_read64(void) { return ms_clk; } |
14 | 14 | ||
15 | uint16_t timer_read(void) | 15 | uint16_t timer_elapsed(uint16_t tlast) { return TIMER_DIFF_16(timer_read(), tlast); } |
16 | { | 16 | |
17 | return (uint16_t)ms_clk; | 17 | uint32_t timer_elapsed32(uint32_t tlast) { return TIMER_DIFF_32(timer_read32(), tlast); } |
18 | } | 18 | |
19 | 19 | void timer_clear(void) { set_time(0); } | |
20 | uint32_t timer_read32(void) | ||
21 | { | ||
22 | return (uint32_t)ms_clk; | ||
23 | } | ||
24 | |||
25 | uint64_t timer_read64(void) | ||
26 | { | ||
27 | return ms_clk; | ||
28 | } | ||
29 | |||
30 | uint16_t timer_elapsed(uint16_t tlast) | ||
31 | { | ||
32 | return TIMER_DIFF_16(timer_read(), tlast); | ||
33 | } | ||
34 | |||
35 | uint32_t timer_elapsed32(uint32_t tlast) | ||
36 | { | ||
37 | return TIMER_DIFF_32(timer_read32(), tlast); | ||
38 | } | ||
39 | |||
40 | void timer_clear(void) | ||
41 | { | ||
42 | set_time(0); | ||
43 | } | ||
diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c index 29036f7c5..5f9ecc510 100644 --- a/tmk_core/common/avr/bootloader.c +++ b/tmk_core/common/avr/bootloader.c | |||
@@ -9,10 +9,9 @@ | |||
9 | #include <avr/boot.h> | 9 | #include <avr/boot.h> |
10 | 10 | ||
11 | #ifdef PROTOCOL_LUFA | 11 | #ifdef PROTOCOL_LUFA |
12 | #include <LUFA/Drivers/USB/USB.h> | 12 | # include <LUFA/Drivers/USB/USB.h> |
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | |||
16 | /** \brief Bootloader Size in *bytes* | 15 | /** \brief Bootloader Size in *bytes* |
17 | * | 16 | * |
18 | * AVR Boot section size are defined by setting BOOTSZ fuse in fact. Consult with your MCU datasheet. | 17 | * AVR Boot section size are defined by setting BOOTSZ fuse in fact. Consult with your MCU datasheet. |
@@ -57,19 +56,19 @@ | |||
57 | #define FLASH_SIZE (FLASHEND + 1L) | 56 | #define FLASH_SIZE (FLASHEND + 1L) |
58 | 57 | ||
59 | #if !defined(BOOTLOADER_SIZE) | 58 | #if !defined(BOOTLOADER_SIZE) |
60 | uint16_t bootloader_start; | 59 | uint16_t bootloader_start; |
61 | #endif | 60 | #endif |
62 | 61 | ||
63 | #define BOOT_SIZE_256 0b110 | 62 | #define BOOT_SIZE_256 0b110 |
64 | #define BOOT_SIZE_512 0b100 | 63 | #define BOOT_SIZE_512 0b100 |
65 | #define BOOT_SIZE_1024 0b010 | 64 | #define BOOT_SIZE_1024 0b010 |
66 | #define BOOT_SIZE_2048 0b000 | 65 | #define BOOT_SIZE_2048 0b000 |
67 | 66 | ||
68 | //compatibility between ATMega8 and ATMega88 | 67 | // compatibility between ATMega8 and ATMega88 |
69 | #if !defined (MCUCSR) | 68 | #if !defined(MCUCSR) |
70 | #if defined (MCUSR) | 69 | # if defined(MCUSR) |
71 | #define MCUCSR MCUSR | 70 | # define MCUCSR MCUSR |
72 | #endif | 71 | # endif |
73 | #endif | 72 | #endif |
74 | 73 | ||
75 | /** \brief Entering the Bootloader via Software | 74 | /** \brief Entering the Bootloader via Software |
@@ -77,163 +76,223 @@ | |||
77 | * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html | 76 | * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html |
78 | */ | 77 | */ |
79 | #define BOOTLOADER_RESET_KEY 0xB007B007 | 78 | #define BOOTLOADER_RESET_KEY 0xB007B007 |
80 | uint32_t reset_key __attribute__ ((section (".noinit,\"aw\",@nobits;"))); | 79 | uint32_t reset_key __attribute__((section(".noinit,\"aw\",@nobits;"))); |
81 | 80 | ||
82 | /** \brief initialize MCU status by watchdog reset | 81 | /** \brief initialize MCU status by watchdog reset |
83 | * | 82 | * |
84 | * FIXME: needs doc | 83 | * FIXME: needs doc |
85 | */ | 84 | */ |
86 | void bootloader_jump(void) { | 85 | void bootloader_jump(void) { |
86 | #if !defined(BOOTLOADER_SIZE) | ||
87 | uint8_t high_fuse = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS); | ||
87 | 88 | ||
88 | #if !defined(BOOTLOADER_SIZE) | 89 | if (high_fuse & BOOT_SIZE_256) { |
89 | uint8_t high_fuse = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS); | 90 | bootloader_start = (FLASH_SIZE - 512) >> 1; |
90 | 91 | } else if (high_fuse & BOOT_SIZE_512) { | |
91 | if (high_fuse & BOOT_SIZE_256) { | 92 | bootloader_start = (FLASH_SIZE - 1024) >> 1; |
92 | bootloader_start = (FLASH_SIZE - 512) >> 1; | 93 | } else if (high_fuse & BOOT_SIZE_1024) { |
93 | } else if (high_fuse & BOOT_SIZE_512) { | 94 | bootloader_start = (FLASH_SIZE - 2048) >> 1; |
94 | bootloader_start = (FLASH_SIZE - 1024) >> 1; | 95 | } else { |
95 | } else if (high_fuse & BOOT_SIZE_1024) { | 96 | bootloader_start = (FLASH_SIZE - 4096) >> 1; |
96 | bootloader_start = (FLASH_SIZE - 2048) >> 1; | 97 | } |
97 | } else { | 98 | #endif |
98 | bootloader_start = (FLASH_SIZE - 4096) >> 1; | ||
99 | } | ||
100 | #endif | ||
101 | 99 | ||
102 | // Something like this might work, but it compiled larger than the block above | 100 | // Something like this might work, but it compiled larger than the block above |
103 | // bootloader_start = FLASH_SIZE - (256 << (~high_fuse & 0b110 >> 1)); | 101 | // bootloader_start = FLASH_SIZE - (256 << (~high_fuse & 0b110 >> 1)); |
104 | 102 | ||
103 | #if defined(BOOTLOADER_HALFKAY) | ||
104 | // http://www.pjrc.com/teensy/jump_to_bootloader.html | ||
105 | cli(); | ||
106 | // disable watchdog, if enabled (it's not) | ||
107 | // disable all peripherals | ||
108 | // a shutdown call might make sense here | ||
109 | UDCON = 1; | ||
110 | USBCON = (1 << FRZCLK); // disable USB | ||
111 | UCSR1B = 0; | ||
112 | _delay_ms(5); | ||
113 | # if defined(__AVR_AT90USB162__) // Teensy 1.0 | ||
114 | EIMSK = 0; | ||
115 | PCICR = 0; | ||
116 | SPCR = 0; | ||
117 | ACSR = 0; | ||
118 | EECR = 0; | ||
119 | TIMSK0 = 0; | ||
120 | TIMSK1 = 0; | ||
121 | UCSR1B = 0; | ||
122 | DDRB = 0; | ||
123 | DDRC = 0; | ||
124 | DDRD = 0; | ||
125 | PORTB = 0; | ||
126 | PORTC = 0; | ||
127 | PORTD = 0; | ||
128 | asm volatile("jmp 0x3E00"); | ||
129 | # elif defined(__AVR_ATmega32U4__) // Teensy 2.0 | ||
130 | EIMSK = 0; | ||
131 | PCICR = 0; | ||
132 | SPCR = 0; | ||
133 | ACSR = 0; | ||
134 | EECR = 0; | ||
135 | ADCSRA = 0; | ||
136 | TIMSK0 = 0; | ||
137 | TIMSK1 = 0; | ||
138 | TIMSK3 = 0; | ||
139 | TIMSK4 = 0; | ||
140 | UCSR1B = 0; | ||
141 | TWCR = 0; | ||
142 | DDRB = 0; | ||
143 | DDRC = 0; | ||
144 | DDRD = 0; | ||
145 | DDRE = 0; | ||
146 | DDRF = 0; | ||
147 | TWCR = 0; | ||
148 | PORTB = 0; | ||
149 | PORTC = 0; | ||
150 | PORTD = 0; | ||
151 | PORTE = 0; | ||
152 | PORTF = 0; | ||
153 | asm volatile("jmp 0x7E00"); | ||
154 | # elif defined(__AVR_AT90USB646__) // Teensy++ 1.0 | ||
155 | EIMSK = 0; | ||
156 | PCICR = 0; | ||
157 | SPCR = 0; | ||
158 | ACSR = 0; | ||
159 | EECR = 0; | ||
160 | ADCSRA = 0; | ||
161 | TIMSK0 = 0; | ||
162 | TIMSK1 = 0; | ||
163 | TIMSK2 = 0; | ||
164 | TIMSK3 = 0; | ||
165 | UCSR1B = 0; | ||
166 | TWCR = 0; | ||
167 | DDRA = 0; | ||
168 | DDRB = 0; | ||
169 | DDRC = 0; | ||
170 | DDRD = 0; | ||
171 | DDRE = 0; | ||
172 | DDRF = 0; | ||
173 | PORTA = 0; | ||
174 | PORTB = 0; | ||
175 | PORTC = 0; | ||
176 | PORTD = 0; | ||
177 | PORTE = 0; | ||
178 | PORTF = 0; | ||
179 | asm volatile("jmp 0xFC00"); | ||
180 | # elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0 | ||
181 | EIMSK = 0; | ||
182 | PCICR = 0; | ||
183 | SPCR = 0; | ||
184 | ACSR = 0; | ||
185 | EECR = 0; | ||
186 | ADCSRA = 0; | ||
187 | TIMSK0 = 0; | ||
188 | TIMSK1 = 0; | ||
189 | TIMSK2 = 0; | ||
190 | TIMSK3 = 0; | ||
191 | UCSR1B = 0; | ||
192 | TWCR = 0; | ||
193 | DDRA = 0; | ||
194 | DDRB = 0; | ||
195 | DDRC = 0; | ||
196 | DDRD = 0; | ||
197 | DDRE = 0; | ||
198 | DDRF = 0; | ||
199 | PORTA = 0; | ||
200 | PORTB = 0; | ||
201 | PORTC = 0; | ||
202 | PORTD = 0; | ||
203 | PORTE = 0; | ||
204 | PORTF = 0; | ||
205 | asm volatile("jmp 0x1FC00"); | ||
206 | # endif | ||
207 | |||
208 | #elif defined(BOOTLOADER_CATERINA) | ||
209 | // this block may be optional | ||
210 | // TODO: figure it out | ||
211 | |||
212 | uint16_t *const bootKeyPtr = (uint16_t *)0x0800; | ||
213 | |||
214 | // Value used by Caterina bootloader use to determine whether to run the | ||
215 | // sketch or the bootloader programmer. | ||
216 | uint16_t bootKey = 0x7777; | ||
217 | |||
218 | *bootKeyPtr = bootKey; | ||
219 | |||
220 | // setup watchdog timeout | ||
221 | wdt_enable(WDTO_60MS); | ||
105 | 222 | ||
106 | #if defined(BOOTLOADER_HALFKAY) | 223 | while (1) { |
107 | // http://www.pjrc.com/teensy/jump_to_bootloader.html | 224 | } // wait for watchdog timer to trigger |
108 | cli(); | ||
109 | // disable watchdog, if enabled (it's not) | ||
110 | // disable all peripherals | ||
111 | // a shutdown call might make sense here | ||
112 | UDCON = 1; | ||
113 | USBCON = (1<<FRZCLK); // disable USB | ||
114 | UCSR1B = 0; | ||
115 | _delay_ms(5); | ||
116 | #if defined(__AVR_AT90USB162__) // Teensy 1.0 | ||
117 | EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; | ||
118 | TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0; | ||
119 | DDRB = 0; DDRC = 0; DDRD = 0; | ||
120 | PORTB = 0; PORTC = 0; PORTD = 0; | ||
121 | asm volatile("jmp 0x3E00"); | ||
122 | #elif defined(__AVR_ATmega32U4__) // Teensy 2.0 | ||
123 | EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0; | ||
124 | TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0; | ||
125 | DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0; | ||
126 | PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; | ||
127 | asm volatile("jmp 0x7E00"); | ||
128 | #elif defined(__AVR_AT90USB646__) // Teensy++ 1.0 | ||
129 | EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0; | ||
130 | TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0; | ||
131 | DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; | ||
132 | PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; | ||
133 | asm volatile("jmp 0xFC00"); | ||
134 | #elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0 | ||
135 | EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0; | ||
136 | TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0; | ||
137 | DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; | ||
138 | PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; | ||
139 | asm volatile("jmp 0x1FC00"); | ||
140 | #endif | ||
141 | |||
142 | #elif defined(BOOTLOADER_CATERINA) | ||
143 | // this block may be optional | ||
144 | // TODO: figure it out | ||
145 | |||
146 | uint16_t *const bootKeyPtr = (uint16_t *)0x0800; | ||
147 | |||
148 | // Value used by Caterina bootloader use to determine whether to run the | ||
149 | // sketch or the bootloader programmer. | ||
150 | uint16_t bootKey = 0x7777; | ||
151 | |||
152 | *bootKeyPtr = bootKey; | ||
153 | |||
154 | // setup watchdog timeout | ||
155 | wdt_enable(WDTO_60MS); | ||
156 | |||
157 | while(1) {} // wait for watchdog timer to trigger | ||
158 | |||
159 | #elif defined(BOOTLOADER_USBASP) | ||
160 | // Taken with permission of Stephan Baerwolf from https://github.com/tinyusbboard/API/blob/master/apipage.c | ||
161 | wdt_enable(WDTO_15MS); | ||
162 | wdt_reset(); | ||
163 | asm volatile ( | ||
164 | "cli \n\t" | ||
165 | "ldi r29 , %[ramendhi] \n\t" | ||
166 | "ldi r28 , %[ramendlo] \n\t" | ||
167 | #if (FLASHEND>131071) | ||
168 | "ldi r18 , %[bootaddrhi] \n\t" | ||
169 | "st Y+, r18 \n\t" | ||
170 | #endif | ||
171 | "ldi r18 , %[bootaddrme] \n\t" | ||
172 | "st Y+, r18 \n\t" | ||
173 | "ldi r18 , %[bootaddrlo] \n\t" | ||
174 | "st Y+, r18 \n\t" | ||
175 | "out %[mcucsrio], __zero_reg__ \n\t" | ||
176 | "bootloader_startup_loop%=: \n\t" | ||
177 | "rjmp bootloader_startup_loop%= \n\t" | ||
178 | : | ||
179 | : [mcucsrio] "I" (_SFR_IO_ADDR(MCUCSR)), | ||
180 | #if (FLASHEND>131071) | ||
181 | [ramendhi] "M" (((RAMEND - 2) >> 8) & 0xff), | ||
182 | [ramendlo] "M" (((RAMEND - 2) >> 0) & 0xff), | ||
183 | [bootaddrhi] "M" ((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >>16) & 0xff), | ||
184 | #else | ||
185 | [ramendhi] "M" (((RAMEND - 1) >> 8) & 0xff), | ||
186 | [ramendlo] "M" (((RAMEND - 1) >> 0) & 0xff), | ||
187 | #endif | ||
188 | [bootaddrme] "M" ((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 8) & 0xff), | ||
189 | [bootaddrlo] "M" ((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 0) & 0xff) | ||
190 | ); | ||
191 | |||
192 | #else // Assume remaining boards are DFU, even if the flag isn't set | ||
193 | |||
194 | #if !(defined(__AVR_ATmega32A__) || defined(__AVR_ATmega328P__)) // no USB - maybe BOOTLOADER_BOOTLOADHID instead though? | ||
195 | UDCON = 1; | ||
196 | USBCON = (1<<FRZCLK); // disable USB | ||
197 | UCSR1B = 0; | ||
198 | _delay_ms(5); // 5 seems to work fine | ||
199 | #endif | ||
200 | |||
201 | #ifdef BOOTLOADER_BOOTLOADHID | ||
202 | // force bootloadHID to stay in bootloader mode, so that it waits | ||
203 | // for a new firmware to be flashed | ||
204 | eeprom_write_byte((uint8_t *)1, 0x00); | ||
205 | #endif | ||
206 | |||
207 | // watchdog reset | ||
208 | reset_key = BOOTLOADER_RESET_KEY; | ||
209 | wdt_enable(WDTO_250MS); | ||
210 | for (;;); | ||
211 | #endif | ||
212 | 225 | ||
226 | #elif defined(BOOTLOADER_USBASP) | ||
227 | // Taken with permission of Stephan Baerwolf from https://github.com/tinyusbboard/API/blob/master/apipage.c | ||
228 | wdt_enable(WDTO_15MS); | ||
229 | wdt_reset(); | ||
230 | asm volatile("cli \n\t" | ||
231 | "ldi r29 , %[ramendhi] \n\t" | ||
232 | "ldi r28 , %[ramendlo] \n\t" | ||
233 | # if (FLASHEND > 131071) | ||
234 | "ldi r18 , %[bootaddrhi] \n\t" | ||
235 | "st Y+, r18 \n\t" | ||
236 | # endif | ||
237 | "ldi r18 , %[bootaddrme] \n\t" | ||
238 | "st Y+, r18 \n\t" | ||
239 | "ldi r18 , %[bootaddrlo] \n\t" | ||
240 | "st Y+, r18 \n\t" | ||
241 | "out %[mcucsrio], __zero_reg__ \n\t" | ||
242 | "bootloader_startup_loop%=: \n\t" | ||
243 | "rjmp bootloader_startup_loop%= \n\t" | ||
244 | : | ||
245 | : [ mcucsrio ] "I"(_SFR_IO_ADDR(MCUCSR)), | ||
246 | # if (FLASHEND > 131071) | ||
247 | [ ramendhi ] "M"(((RAMEND - 2) >> 8) & 0xff), [ ramendlo ] "M"(((RAMEND - 2) >> 0) & 0xff), [ bootaddrhi ] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 16) & 0xff), | ||
248 | # else | ||
249 | [ ramendhi ] "M"(((RAMEND - 1) >> 8) & 0xff), [ ramendlo ] "M"(((RAMEND - 1) >> 0) & 0xff), | ||
250 | # endif | ||
251 | [ bootaddrme ] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 8) & 0xff), [ bootaddrlo ] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 0) & 0xff)); | ||
252 | |||
253 | #else // Assume remaining boards are DFU, even if the flag isn't set | ||
254 | |||
255 | # if !(defined(__AVR_ATmega32A__) || defined(__AVR_ATmega328P__)) // no USB - maybe BOOTLOADER_BOOTLOADHID instead though? | ||
256 | UDCON = 1; | ||
257 | USBCON = (1 << FRZCLK); // disable USB | ||
258 | UCSR1B = 0; | ||
259 | _delay_ms(5); // 5 seems to work fine | ||
260 | # endif | ||
261 | |||
262 | # ifdef BOOTLOADER_BOOTLOADHID | ||
263 | // force bootloadHID to stay in bootloader mode, so that it waits | ||
264 | // for a new firmware to be flashed | ||
265 | eeprom_write_byte((uint8_t *)1, 0x00); | ||
266 | # endif | ||
267 | |||
268 | // watchdog reset | ||
269 | reset_key = BOOTLOADER_RESET_KEY; | ||
270 | wdt_enable(WDTO_250MS); | ||
271 | for (;;) | ||
272 | ; | ||
273 | #endif | ||
213 | } | 274 | } |
214 | 275 | ||
215 | /* this runs before main() */ | 276 | /* this runs before main() */ |
216 | void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); | 277 | void bootloader_jump_after_watchdog_reset(void) __attribute__((used, naked, section(".init3"))); |
217 | void bootloader_jump_after_watchdog_reset(void) | 278 | void bootloader_jump_after_watchdog_reset(void) { |
218 | { | 279 | #ifndef BOOTLOADER_HALFKAY |
219 | #ifndef BOOTLOADER_HALFKAY | 280 | if ((MCUCSR & (1 << WDRF)) && reset_key == BOOTLOADER_RESET_KEY) { |
220 | if ((MCUCSR & (1<<WDRF)) && reset_key == BOOTLOADER_RESET_KEY) { | 281 | reset_key = 0; |
221 | reset_key = 0; | 282 | |
222 | 283 | // My custom USBasploader requires this to come up. | |
223 | // My custom USBasploader requires this to come up. | 284 | MCUCSR = 0; |
224 | MCUCSR = 0; | 285 | |
225 | 286 | // Seems like Teensy halfkay loader requires clearing WDRF and disabling watchdog. | |
226 | // Seems like Teensy halfkay loader requires clearing WDRF and disabling watchdog. | 287 | MCUCSR &= ~(1 << WDRF); |
227 | MCUCSR &= ~(1<<WDRF); | 288 | wdt_disable(); |
228 | wdt_disable(); | 289 | |
229 | 290 | // This is compled into 'icall', address should be in word unit, not byte. | |
230 | 291 | # ifdef BOOTLOADER_SIZE | |
231 | // This is compled into 'icall', address should be in word unit, not byte. | 292 | ((void (*)(void))((FLASH_SIZE - BOOTLOADER_SIZE) >> 1))(); |
232 | #ifdef BOOTLOADER_SIZE | 293 | # else |
233 | ((void (*)(void))( (FLASH_SIZE - BOOTLOADER_SIZE) >> 1))(); | 294 | asm("ijmp" ::"z"(bootloader_start)); |
234 | #else | 295 | # endif |
235 | asm("ijmp" :: "z" (bootloader_start)); | 296 | } |
236 | #endif | 297 | #endif |
237 | } | ||
238 | #endif | ||
239 | } | 298 | } |
diff --git a/tmk_core/common/avr/sleep_led.c b/tmk_core/common/avr/sleep_led.c index 0cb774c81..61fa70dc3 100644 --- a/tmk_core/common/avr/sleep_led.c +++ b/tmk_core/common/avr/sleep_led.c | |||
@@ -16,14 +16,13 @@ | |||
16 | * 256*64 interrupts/second | 16 | * 256*64 interrupts/second |
17 | * F_CPU/(256*64) clocks/interrupt | 17 | * F_CPU/(256*64) clocks/interrupt |
18 | */ | 18 | */ |
19 | #define SLEEP_LED_TIMER_TOP F_CPU/(256*64) | 19 | #define SLEEP_LED_TIMER_TOP F_CPU / (256 * 64) |
20 | 20 | ||
21 | /** \brief Sleep LED initialization | 21 | /** \brief Sleep LED initialization |
22 | * | 22 | * |
23 | * FIXME: needs doc | 23 | * FIXME: needs doc |
24 | */ | 24 | */ |
25 | void sleep_led_init(void) | 25 | void sleep_led_init(void) { |
26 | { | ||
27 | /* Timer1 setup */ | 26 | /* Timer1 setup */ |
28 | /* CTC mode */ | 27 | /* CTC mode */ |
29 | TCCR1B |= _BV(WGM12); | 28 | TCCR1B |= _BV(WGM12); |
@@ -32,17 +31,16 @@ void sleep_led_init(void) | |||
32 | /* Set TOP value */ | 31 | /* Set TOP value */ |
33 | uint8_t sreg = SREG; | 32 | uint8_t sreg = SREG; |
34 | cli(); | 33 | cli(); |
35 | OCR1AH = (SLEEP_LED_TIMER_TOP>>8)&0xff; | 34 | OCR1AH = (SLEEP_LED_TIMER_TOP >> 8) & 0xff; |
36 | OCR1AL = SLEEP_LED_TIMER_TOP&0xff; | 35 | OCR1AL = SLEEP_LED_TIMER_TOP & 0xff; |
37 | SREG = sreg; | 36 | SREG = sreg; |
38 | } | 37 | } |
39 | 38 | ||
40 | /** \brief Sleep LED enable | 39 | /** \brief Sleep LED enable |
41 | * | 40 | * |
42 | * FIXME: needs doc | 41 | * FIXME: needs doc |
43 | */ | 42 | */ |
44 | void sleep_led_enable(void) | 43 | void sleep_led_enable(void) { |
45 | { | ||
46 | /* Enable Compare Match Interrupt */ | 44 | /* Enable Compare Match Interrupt */ |
47 | TIMSK1 |= _BV(OCIE1A); | 45 | TIMSK1 |= _BV(OCIE1A); |
48 | } | 46 | } |
@@ -51,8 +49,7 @@ void sleep_led_enable(void) | |||
51 | * | 49 | * |
52 | * FIXME: needs doc | 50 | * FIXME: needs doc |
53 | */ | 51 | */ |
54 | void sleep_led_disable(void) | 52 | void sleep_led_disable(void) { |
55 | { | ||
56 | /* Disable Compare Match Interrupt */ | 53 | /* Disable Compare Match Interrupt */ |
57 | TIMSK1 &= ~_BV(OCIE1A); | 54 | TIMSK1 &= ~_BV(OCIE1A); |
58 | } | 55 | } |
@@ -61,13 +58,11 @@ void sleep_led_disable(void) | |||
61 | * | 58 | * |
62 | * FIXME: needs doc | 59 | * FIXME: needs doc |
63 | */ | 60 | */ |
64 | void sleep_led_toggle(void) | 61 | void sleep_led_toggle(void) { |
65 | { | ||
66 | /* Disable Compare Match Interrupt */ | 62 | /* Disable Compare Match Interrupt */ |
67 | TIMSK1 ^= _BV(OCIE1A); | 63 | TIMSK1 ^= _BV(OCIE1A); |
68 | } | 64 | } |
69 | 65 | ||
70 | |||
71 | /** \brief Breathing Sleep LED brighness(PWM On period) table | 66 | /** \brief Breathing Sleep LED brighness(PWM On period) table |
72 | * | 67 | * |
73 | * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle | 68 | * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle |
@@ -75,15 +70,9 @@ void sleep_led_toggle(void) | |||
75 | * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63 | 70 | * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63 |
76 | * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i } | 71 | * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i } |
77 | */ | 72 | */ |
78 | static const uint8_t breathing_table[64] PROGMEM = { | 73 | static const uint8_t breathing_table[64] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
79 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, | ||
80 | 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, | ||
81 | 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, | ||
82 | 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
83 | }; | ||
84 | 74 | ||
85 | ISR(TIMER1_COMPA_vect) | 75 | ISR(TIMER1_COMPA_vect) { |
86 | { | ||
87 | /* Software PWM | 76 | /* Software PWM |
88 | * timer:1111 1111 1111 1111 | 77 | * timer:1111 1111 1111 1111 |
89 | * \_____/\/ \_______/____ count(0-255) | 78 | * \_____/\/ \_______/____ count(0-255) |
@@ -93,17 +82,17 @@ ISR(TIMER1_COMPA_vect) | |||
93 | static union { | 82 | static union { |
94 | uint16_t row; | 83 | uint16_t row; |
95 | struct { | 84 | struct { |
96 | uint8_t count:8; | 85 | uint8_t count : 8; |
97 | uint8_t duration:2; | 86 | uint8_t duration : 2; |
98 | uint8_t index:6; | 87 | uint8_t index : 6; |
99 | } pwm; | 88 | } pwm; |
100 | } timer = { .row = 0 }; | 89 | } timer = {.row = 0}; |
101 | 90 | ||
102 | timer.row++; | 91 | timer.row++; |
103 | 92 | ||
104 | // LED on | 93 | // LED on |
105 | if (timer.pwm.count == 0) { | 94 | if (timer.pwm.count == 0) { |
106 | led_set(1<<USB_LED_CAPS_LOCK); | 95 | led_set(1 << USB_LED_CAPS_LOCK); |
107 | } | 96 | } |
108 | // LED off | 97 | // LED off |
109 | if (timer.pwm.count == pgm_read_byte(&breathing_table[timer.pwm.index])) { | 98 | if (timer.pwm.count == pgm_read_byte(&breathing_table[timer.pwm.index])) { |
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 2259201b5..574000fcd 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c | |||
@@ -13,37 +13,36 @@ | |||
13 | #include "rgblight_reconfig.h" | 13 | #include "rgblight_reconfig.h" |
14 | 14 | ||
15 | #ifdef PROTOCOL_LUFA | 15 | #ifdef PROTOCOL_LUFA |
16 | #include "lufa.h" | 16 | # include "lufa.h" |
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | #ifdef AUDIO_ENABLE | 19 | #ifdef AUDIO_ENABLE |
20 | #include "audio.h" | 20 | # include "audio.h" |
21 | #endif /* AUDIO_ENABLE */ | 21 | #endif /* AUDIO_ENABLE */ |
22 | 22 | ||
23 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 23 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
24 | #include "rgblight.h" | 24 | # include "rgblight.h" |
25 | extern rgblight_config_t rgblight_config; | 25 | extern rgblight_config_t rgblight_config; |
26 | static bool rgblight_enabled; | 26 | static bool rgblight_enabled; |
27 | static bool is_suspended; | 27 | static bool is_suspended; |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | 30 | #define wdt_intr_enable(value) \ | |
31 | #define wdt_intr_enable(value) \ | 31 | __asm__ __volatile__("in __tmp_reg__,__SREG__" \ |
32 | __asm__ __volatile__ ( \ | 32 | "\n\t" \ |
33 | "in __tmp_reg__,__SREG__" "\n\t" \ | 33 | "cli" \ |
34 | "cli" "\n\t" \ | 34 | "\n\t" \ |
35 | "wdr" "\n\t" \ | 35 | "wdr" \ |
36 | "sts %0,%1" "\n\t" \ | 36 | "\n\t" \ |
37 | "out __SREG__,__tmp_reg__" "\n\t" \ | 37 | "sts %0,%1" \ |
38 | "sts %0,%2" "\n\t" \ | 38 | "\n\t" \ |
39 | : /* no outputs */ \ | 39 | "out __SREG__,__tmp_reg__" \ |
40 | : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ | 40 | "\n\t" \ |
41 | "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ | 41 | "sts %0,%2" \ |
42 | "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ | 42 | "\n\t" \ |
43 | _BV(WDIE) | (value & 0x07)) ) \ | 43 | : /* no outputs */ \ |
44 | : "r0" \ | 44 | : "M"(_SFR_MEM_ADDR(_WD_CONTROL_REG)), "r"(_BV(_WD_CHANGE_BIT) | _BV(WDE)), "r"((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00) | _BV(WDIE) | (value & 0x07))) \ |
45 | ) | 45 | : "r0") |
46 | |||
47 | 46 | ||
48 | /** \brief Suspend idle | 47 | /** \brief Suspend idle |
49 | * | 48 | * |
@@ -58,23 +57,18 @@ void suspend_idle(uint8_t time) { | |||
58 | sleep_disable(); | 57 | sleep_disable(); |
59 | } | 58 | } |
60 | 59 | ||
61 | |||
62 | // TODO: This needs some cleanup | 60 | // TODO: This needs some cleanup |
63 | 61 | ||
64 | /** \brief Run keyboard level Power down | 62 | /** \brief Run keyboard level Power down |
65 | * | 63 | * |
66 | * FIXME: needs doc | 64 | * FIXME: needs doc |
67 | */ | 65 | */ |
68 | __attribute__ ((weak)) | 66 | __attribute__((weak)) void suspend_power_down_user(void) {} |
69 | void suspend_power_down_user (void) { } | ||
70 | /** \brief Run keyboard level Power down | 67 | /** \brief Run keyboard level Power down |
71 | * | 68 | * |
72 | * FIXME: needs doc | 69 | * FIXME: needs doc |
73 | */ | 70 | */ |
74 | __attribute__ ((weak)) | 71 | __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } |
75 | void suspend_power_down_kb(void) { | ||
76 | suspend_power_down_user(); | ||
77 | } | ||
78 | 72 | ||
79 | #ifndef NO_SUSPEND_POWER_DOWN | 73 | #ifndef NO_SUSPEND_POWER_DOWN |
80 | /** \brief Power down MCU with watchdog timer | 74 | /** \brief Power down MCU with watchdog timer |
@@ -98,43 +92,43 @@ static uint8_t wdt_timeout = 0; | |||
98 | * FIXME: needs doc | 92 | * FIXME: needs doc |
99 | */ | 93 | */ |
100 | static void power_down(uint8_t wdto) { | 94 | static void power_down(uint8_t wdto) { |
101 | #ifdef PROTOCOL_LUFA | 95 | # ifdef PROTOCOL_LUFA |
102 | if (USB_DeviceState == DEVICE_STATE_Configured) return; | 96 | if (USB_DeviceState == DEVICE_STATE_Configured) return; |
103 | #endif | 97 | # endif |
104 | wdt_timeout = wdto; | 98 | wdt_timeout = wdto; |
105 | 99 | ||
106 | // Watchdog Interrupt Mode | 100 | // Watchdog Interrupt Mode |
107 | wdt_intr_enable(wdto); | 101 | wdt_intr_enable(wdto); |
108 | 102 | ||
109 | #ifdef BACKLIGHT_ENABLE | 103 | # ifdef BACKLIGHT_ENABLE |
110 | backlight_set(0); | 104 | backlight_set(0); |
111 | #endif | 105 | # endif |
112 | 106 | ||
113 | // Turn off LED indicators | 107 | // Turn off LED indicators |
114 | uint8_t leds_off = 0; | 108 | uint8_t leds_off = 0; |
115 | #if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) | 109 | # if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) |
116 | if (is_backlight_enabled()) { | 110 | if (is_backlight_enabled()) { |
117 | // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off | 111 | // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off |
118 | leds_off |= (1<<USB_LED_CAPS_LOCK); | 112 | leds_off |= (1 << USB_LED_CAPS_LOCK); |
119 | } | 113 | } |
120 | #endif | 114 | # endif |
121 | led_set(leds_off); | 115 | led_set(leds_off); |
122 | 116 | ||
123 | #ifdef AUDIO_ENABLE | 117 | # ifdef AUDIO_ENABLE |
124 | // This sometimes disables the start-up noise, so it's been disabled | 118 | // This sometimes disables the start-up noise, so it's been disabled |
125 | // stop_all_notes(); | 119 | // stop_all_notes(); |
126 | #endif /* AUDIO_ENABLE */ | 120 | # endif /* AUDIO_ENABLE */ |
127 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 121 | # if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
128 | #ifdef RGBLIGHT_ANIMATIONS | 122 | # ifdef RGBLIGHT_ANIMATIONS |
129 | rgblight_timer_disable(); | 123 | rgblight_timer_disable(); |
130 | #endif | 124 | # endif |
131 | if (!is_suspended) { | 125 | if (!is_suspended) { |
132 | is_suspended = true; | 126 | is_suspended = true; |
133 | rgblight_enabled = rgblight_config.enable; | 127 | rgblight_enabled = rgblight_config.enable; |
134 | rgblight_disable_noeeprom(); | 128 | rgblight_disable_noeeprom(); |
135 | } | 129 | } |
136 | #endif | 130 | # endif |
137 | suspend_power_down_kb(); | 131 | suspend_power_down_kb(); |
138 | 132 | ||
139 | // TODO: more power saving | 133 | // TODO: more power saving |
140 | // See PicoPower application note | 134 | // See PicoPower application note |
@@ -158,40 +152,36 @@ static void power_down(uint8_t wdto) { | |||
158 | * FIXME: needs doc | 152 | * FIXME: needs doc |
159 | */ | 153 | */ |
160 | void suspend_power_down(void) { | 154 | void suspend_power_down(void) { |
161 | suspend_power_down_kb(); | 155 | suspend_power_down_kb(); |
162 | 156 | ||
163 | #ifndef NO_SUSPEND_POWER_DOWN | 157 | #ifndef NO_SUSPEND_POWER_DOWN |
164 | power_down(WDTO_15MS); | 158 | power_down(WDTO_15MS); |
165 | #endif | 159 | #endif |
166 | } | 160 | } |
167 | 161 | ||
168 | __attribute__ ((weak)) void matrix_power_up(void) {} | 162 | __attribute__((weak)) void matrix_power_up(void) {} |
169 | __attribute__ ((weak)) void matrix_power_down(void) {} | 163 | __attribute__((weak)) void matrix_power_down(void) {} |
170 | bool suspend_wakeup_condition(void) { | 164 | bool suspend_wakeup_condition(void) { |
171 | matrix_power_up(); | 165 | matrix_power_up(); |
172 | matrix_scan(); | 166 | matrix_scan(); |
173 | matrix_power_down(); | 167 | matrix_power_down(); |
174 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | 168 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { |
175 | if (matrix_get_row(r)) return true; | 169 | if (matrix_get_row(r)) return true; |
176 | } | 170 | } |
177 | return false; | 171 | return false; |
178 | } | 172 | } |
179 | 173 | ||
180 | /** \brief run user level code immediately after wakeup | 174 | /** \brief run user level code immediately after wakeup |
181 | * | 175 | * |
182 | * FIXME: needs doc | 176 | * FIXME: needs doc |
183 | */ | 177 | */ |
184 | __attribute__ ((weak)) | 178 | __attribute__((weak)) void suspend_wakeup_init_user(void) {} |
185 | void suspend_wakeup_init_user(void) { } | ||
186 | 179 | ||
187 | /** \brief run keyboard level code immediately after wakeup | 180 | /** \brief run keyboard level code immediately after wakeup |
188 | * | 181 | * |
189 | * FIXME: needs doc | 182 | * FIXME: needs doc |
190 | */ | 183 | */ |
191 | __attribute__ ((weak)) | 184 | __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } |
192 | void suspend_wakeup_init_kb(void) { | ||
193 | suspend_wakeup_init_user(); | ||
194 | } | ||
195 | /** \brief run immediately after wakeup | 185 | /** \brief run immediately after wakeup |
196 | * | 186 | * |
197 | * FIXME: needs doc | 187 | * FIXME: needs doc |
@@ -202,18 +192,18 @@ void suspend_wakeup_init(void) { | |||
202 | #ifdef BACKLIGHT_ENABLE | 192 | #ifdef BACKLIGHT_ENABLE |
203 | backlight_init(); | 193 | backlight_init(); |
204 | #endif | 194 | #endif |
205 | led_set(host_keyboard_leds()); | 195 | led_set(host_keyboard_leds()); |
206 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 196 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
207 | is_suspended = false; | 197 | is_suspended = false; |
208 | if (rgblight_enabled) { | 198 | if (rgblight_enabled) { |
209 | #ifdef BOOTLOADER_TEENSY | 199 | # ifdef BOOTLOADER_TEENSY |
210 | wait_ms(10); | 200 | wait_ms(10); |
211 | #endif | 201 | # endif |
212 | rgblight_enable_noeeprom(); | 202 | rgblight_enable_noeeprom(); |
213 | } | 203 | } |
214 | #ifdef RGBLIGHT_ANIMATIONS | 204 | # ifdef RGBLIGHT_ANIMATIONS |
215 | rgblight_timer_enable(); | 205 | rgblight_timer_enable(); |
216 | #endif | 206 | # endif |
217 | #endif | 207 | #endif |
218 | suspend_wakeup_init_kb(); | 208 | suspend_wakeup_init_kb(); |
219 | } | 209 | } |
@@ -226,8 +216,7 @@ ISR(WDT_vect) { | |||
226 | case WDTO_15MS: | 216 | case WDTO_15MS: |
227 | timer_count += 15 + 2; // WDTO_15MS + 2(from observation) | 217 | timer_count += 15 + 2; // WDTO_15MS + 2(from observation) |
228 | break; | 218 | break; |
229 | default: | 219 | default:; |
230 | ; | ||
231 | } | 220 | } |
232 | } | 221 | } |
233 | #endif | 222 | #endif |
diff --git a/tmk_core/common/avr/suspend_avr.h b/tmk_core/common/avr/suspend_avr.h index 357102da4..d73852ba1 100644 --- a/tmk_core/common/avr/suspend_avr.h +++ b/tmk_core/common/avr/suspend_avr.h | |||
@@ -7,21 +7,21 @@ | |||
7 | #include <avr/wdt.h> | 7 | #include <avr/wdt.h> |
8 | #include <avr/interrupt.h> | 8 | #include <avr/interrupt.h> |
9 | 9 | ||
10 | 10 | #define wdt_intr_enable(value) \ | |
11 | #define wdt_intr_enable(value) \ | 11 | __asm__ __volatile__("in __tmp_reg__,__SREG__" \ |
12 | __asm__ __volatile__ ( \ | 12 | "\n\t" \ |
13 | "in __tmp_reg__,__SREG__" "\n\t" \ | 13 | "cli" \ |
14 | "cli" "\n\t" \ | 14 | "\n\t" \ |
15 | "wdr" "\n\t" \ | 15 | "wdr" \ |
16 | "sts %0,%1" "\n\t" \ | 16 | "\n\t" \ |
17 | "out __SREG__,__tmp_reg__" "\n\t" \ | 17 | "sts %0,%1" \ |
18 | "sts %0,%2" "\n\t" \ | 18 | "\n\t" \ |
19 | : /* no outputs */ \ | 19 | "out __SREG__,__tmp_reg__" \ |
20 | : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ | 20 | "\n\t" \ |
21 | "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ | 21 | "sts %0,%2" \ |
22 | "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ | 22 | "\n\t" \ |
23 | _BV(WDIE) | (value & 0x07)) ) \ | 23 | : /* no outputs */ \ |
24 | : "r0" \ | 24 | : "M"(_SFR_MEM_ADDR(_WD_CONTROL_REG)), "r"(_BV(_WD_CHANGE_BIT) | _BV(WDE)), "r"((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00) | _BV(WDIE) | (value & 0x07))) \ |
25 | ) | 25 | : "r0") |
26 | 26 | ||
27 | #endif | 27 | #endif |
diff --git a/tmk_core/common/avr/timer.c b/tmk_core/common/avr/timer.c index b7d4f060e..63ec549df 100644 --- a/tmk_core/common/avr/timer.c +++ b/tmk_core/common/avr/timer.c | |||
@@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
22 | #include "timer_avr.h" | 22 | #include "timer_avr.h" |
23 | #include "timer.h" | 23 | #include "timer.h" |
24 | 24 | ||
25 | |||
26 | // counter resolution 1ms | 25 | // counter resolution 1ms |
27 | // NOTE: union { uint32_t timer32; struct { uint16_t dummy; uint16_t timer16; }} | 26 | // NOTE: union { uint32_t timer32; struct { uint16_t dummy; uint16_t timer16; }} |
28 | volatile uint32_t timer_count; | 27 | volatile uint32_t timer_count; |
@@ -31,8 +30,7 @@ volatile uint32_t timer_count; | |||
31 | * | 30 | * |
32 | * FIXME: needs doc | 31 | * FIXME: needs doc |
33 | */ | 32 | */ |
34 | void timer_init(void) | 33 | void timer_init(void) { |
35 | { | ||
36 | #if TIMER_PRESCALER == 1 | 34 | #if TIMER_PRESCALER == 1 |
37 | uint8_t prescaler = 0x01; | 35 | uint8_t prescaler = 0x01; |
38 | #elif TIMER_PRESCALER == 8 | 36 | #elif TIMER_PRESCALER == 8 |
@@ -44,7 +42,7 @@ void timer_init(void) | |||
44 | #elif TIMER_PRESCALER == 1024 | 42 | #elif TIMER_PRESCALER == 1024 |
45 | uint8_t prescaler = 0x05; | 43 | uint8_t prescaler = 0x05; |
46 | #else | 44 | #else |
47 | # error "Timer prescaler value is NOT vaild." | 45 | # error "Timer prescaler value is NOT vaild." |
48 | #endif | 46 | #endif |
49 | 47 | ||
50 | #ifndef __AVR_ATmega32A__ | 48 | #ifndef __AVR_ATmega32A__ |
@@ -53,13 +51,13 @@ void timer_init(void) | |||
53 | 51 | ||
54 | TCCR0B = prescaler; | 52 | TCCR0B = prescaler; |
55 | 53 | ||
56 | OCR0A = TIMER_RAW_TOP; | 54 | OCR0A = TIMER_RAW_TOP; |
57 | TIMSK0 = (1<<OCIE0A); | 55 | TIMSK0 = (1 << OCIE0A); |
58 | #else | 56 | #else |
59 | // Timer0 CTC mode | 57 | // Timer0 CTC mode |
60 | TCCR0 = (1 << WGM01) | prescaler; | 58 | TCCR0 = (1 << WGM01) | prescaler; |
61 | 59 | ||
62 | OCR0 = TIMER_RAW_TOP; | 60 | OCR0 = TIMER_RAW_TOP; |
63 | TIMSK = (1 << OCIE0); | 61 | TIMSK = (1 << OCIE0); |
64 | #endif | 62 | #endif |
65 | } | 63 | } |
@@ -68,26 +66,18 @@ void timer_init(void) | |||
68 | * | 66 | * |
69 | * FIXME: needs doc | 67 | * FIXME: needs doc |
70 | */ | 68 | */ |
71 | inline | 69 | inline void timer_clear(void) { |
72 | void timer_clear(void) | 70 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { timer_count = 0; } |
73 | { | ||
74 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { | ||
75 | timer_count = 0; | ||
76 | } | ||
77 | } | 71 | } |
78 | 72 | ||
79 | /** \brief timer read | 73 | /** \brief timer read |
80 | * | 74 | * |
81 | * FIXME: needs doc | 75 | * FIXME: needs doc |
82 | */ | 76 | */ |
83 | inline | 77 | inline uint16_t timer_read(void) { |
84 | uint16_t timer_read(void) | ||
85 | { | ||
86 | uint32_t t; | 78 | uint32_t t; |
87 | 79 | ||
88 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { | 80 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; } |
89 | t = timer_count; | ||
90 | } | ||
91 | 81 | ||
92 | return (t & 0xFFFF); | 82 | return (t & 0xFFFF); |
93 | } | 83 | } |
@@ -96,14 +86,10 @@ uint16_t timer_read(void) | |||
96 | * | 86 | * |
97 | * FIXME: needs doc | 87 | * FIXME: needs doc |
98 | */ | 88 | */ |
99 | inline | 89 | inline uint32_t timer_read32(void) { |
100 | uint32_t timer_read32(void) | ||
101 | { | ||
102 | uint32_t t; | 90 | uint32_t t; |
103 | 91 | ||
104 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { | 92 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; } |
105 | t = timer_count; | ||
106 | } | ||
107 | 93 | ||
108 | return t; | 94 | return t; |
109 | } | 95 | } |
@@ -112,14 +98,10 @@ uint32_t timer_read32(void) | |||
112 | * | 98 | * |
113 | * FIXME: needs doc | 99 | * FIXME: needs doc |
114 | */ | 100 | */ |
115 | inline | 101 | inline uint16_t timer_elapsed(uint16_t last) { |
116 | uint16_t timer_elapsed(uint16_t last) | ||
117 | { | ||
118 | uint32_t t; | 102 | uint32_t t; |
119 | 103 | ||
120 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { | 104 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; } |
121 | t = timer_count; | ||
122 | } | ||
123 | 105 | ||
124 | return TIMER_DIFF_16((t & 0xFFFF), last); | 106 | return TIMER_DIFF_16((t & 0xFFFF), last); |
125 | } | 107 | } |
@@ -128,25 +110,18 @@ uint16_t timer_elapsed(uint16_t last) | |||
128 | * | 110 | * |
129 | * FIXME: needs doc | 111 | * FIXME: needs doc |
130 | */ | 112 | */ |
131 | inline | 113 | inline uint32_t timer_elapsed32(uint32_t last) { |
132 | uint32_t timer_elapsed32(uint32_t last) | ||
133 | { | ||
134 | uint32_t t; | 114 | uint32_t t; |
135 | 115 | ||
136 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { | 116 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; } |
137 | t = timer_count; | ||
138 | } | ||
139 | 117 | ||
140 | return TIMER_DIFF_32(t, last); | 118 | return TIMER_DIFF_32(t, last); |
141 | } | 119 | } |
142 | 120 | ||
143 | // excecuted once per 1ms.(excess for just timer count?) | 121 | // excecuted once per 1ms.(excess for just timer count?) |
144 | #ifndef __AVR_ATmega32A__ | 122 | #ifndef __AVR_ATmega32A__ |
145 | #define TIMER_INTERRUPT_VECTOR TIMER0_COMPA_vect | 123 | # define TIMER_INTERRUPT_VECTOR TIMER0_COMPA_vect |
146 | #else | 124 | #else |
147 | #define TIMER_INTERRUPT_VECTOR TIMER0_COMP_vect | 125 | # define TIMER_INTERRUPT_VECTOR TIMER0_COMP_vect |
148 | #endif | 126 | #endif |
149 | ISR(TIMER_INTERRUPT_VECTOR, ISR_NOBLOCK) | 127 | ISR(TIMER_INTERRUPT_VECTOR, ISR_NOBLOCK) { timer_count++; } |
150 | { | ||
151 | timer_count++; | ||
152 | } | ||
diff --git a/tmk_core/common/avr/timer_avr.h b/tmk_core/common/avr/timer_avr.h index 0e85eb101..9aea21c65 100644 --- a/tmk_core/common/avr/timer_avr.h +++ b/tmk_core/common/avr/timer_avr.h | |||
@@ -21,22 +21,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
21 | #include <stdint.h> | 21 | #include <stdint.h> |
22 | 22 | ||
23 | #ifndef TIMER_PRESCALER | 23 | #ifndef TIMER_PRESCALER |
24 | # if F_CPU > 16000000 | 24 | # if F_CPU > 16000000 |
25 | # define TIMER_PRESCALER 256 | 25 | # define TIMER_PRESCALER 256 |
26 | # elif F_CPU > 2000000 | 26 | # elif F_CPU > 2000000 |
27 | # define TIMER_PRESCALER 64 | 27 | # define TIMER_PRESCALER 64 |
28 | # elif F_CPU > 250000 | 28 | # elif F_CPU > 250000 |
29 | # define TIMER_PRESCALER 8 | 29 | # define TIMER_PRESCALER 8 |
30 | # else | 30 | # else |
31 | # define TIMER_PRESCALER 1 | 31 | # define TIMER_PRESCALER 1 |
32 | # endif | 32 | # endif |
33 | #endif | 33 | #endif |
34 | #define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER) | 34 | #define TIMER_RAW_FREQ (F_CPU / TIMER_PRESCALER) |
35 | #define TIMER_RAW TCNT0 | 35 | #define TIMER_RAW TCNT0 |
36 | #define TIMER_RAW_TOP (TIMER_RAW_FREQ/1000) | 36 | #define TIMER_RAW_TOP (TIMER_RAW_FREQ / 1000) |
37 | 37 | ||
38 | #if (TIMER_RAW_TOP > 255) | 38 | #if (TIMER_RAW_TOP > 255) |
39 | # error "Timer0 can't count 1ms at this clock freq. Use larger prescaler." | 39 | # error "Timer0 can't count 1ms at this clock freq. Use larger prescaler." |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #endif | 42 | #endif |
diff --git a/tmk_core/common/avr/xprintf.h b/tmk_core/common/avr/xprintf.h index 08d9f93a0..70e0f8e48 100644 --- a/tmk_core/common/avr/xprintf.h +++ b/tmk_core/common/avr/xprintf.h | |||
@@ -13,7 +13,7 @@ extern "C" { | |||
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | extern void (*xfunc_out)(uint8_t); | 15 | extern void (*xfunc_out)(uint8_t); |
16 | #define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func) | 16 | #define xdev_out(func) xfunc_out = (void (*)(uint8_t))(func) |
17 | 17 | ||
18 | /* This is a pointer to user defined output function. It must be initialized | 18 | /* This is a pointer to user defined output function. It must be initialized |
19 | before using this modle. | 19 | before using this modle. |
@@ -25,13 +25,11 @@ void xputc(char chr); | |||
25 | All outputs from this module are output via this function. | 25 | All outputs from this module are output via this function. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | |||
29 | /*-----------------------------------------------------------------------------*/ | 28 | /*-----------------------------------------------------------------------------*/ |
30 | void xputs(const char *string_p); | 29 | void xputs(const char *string_p); |
31 | 30 | ||
32 | /* The string placed in the ROM is forwarded to xputc() directly. | 31 | /* The string placed in the ROM is forwarded to xputc() directly. |
33 | */ | 32 | */ |
34 | |||
35 | 33 | ||
36 | /*-----------------------------------------------------------------------------*/ | 34 | /*-----------------------------------------------------------------------------*/ |
37 | void xitoa(long value, char radix, char width); | 35 | void xitoa(long value, char radix, char width); |
@@ -49,13 +47,12 @@ void xitoa(long value, char radix, char width); | |||
49 | 0x55 2 -8 "01010101" | 47 | 0x55 2 -8 "01010101" |
50 | */ | 48 | */ |
51 | 49 | ||
52 | |||
53 | /*-----------------------------------------------------------------------------*/ | 50 | /*-----------------------------------------------------------------------------*/ |
54 | #define xprintf(format, ...) __xprintf(PSTR(format), ##__VA_ARGS__) | 51 | #define xprintf(format, ...) __xprintf(PSTR(format), ##__VA_ARGS__) |
55 | #define xsprintf(str, format, ...) __xsprintf(str, PSTR(format), ##__VA_ARGS__) | 52 | #define xsprintf(str, format, ...) __xsprintf(str, PSTR(format), ##__VA_ARGS__) |
56 | #define xfprintf(func, format, ...) __xfprintf(func, PSTR(format), ##__VA_ARGS__) | 53 | #define xfprintf(func, format, ...) __xfprintf(func, PSTR(format), ##__VA_ARGS__) |
57 | 54 | ||
58 | void __xprintf(const char *format_p, ...); /* Send formatted string to the registered device */ | 55 | void __xprintf(const char *format_p, ...); /* Send formatted string to the registered device */ |
59 | // void __xsprintf(char*, const char *format_p, ...); /* Put formatted string to the memory */ | 56 | // void __xsprintf(char*, const char *format_p, ...); /* Put formatted string to the memory */ |
60 | // void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */ | 57 | // void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */ |
61 | 58 | ||
@@ -84,7 +81,6 @@ void __xprintf(const char *format_p, ...); /* Send formatted string to the regis | |||
84 | 81 | ||
85 | */ | 82 | */ |
86 | 83 | ||
87 | |||
88 | /*-----------------------------------------------------------------------------*/ | 84 | /*-----------------------------------------------------------------------------*/ |
89 | char xatoi(char **str, long *ret); | 85 | char xatoi(char **str, long *ret); |
90 | 86 | ||
@@ -108,4 +104,3 @@ char xatoi(char **str, long *ret); | |||
108 | #endif | 104 | #endif |
109 | 105 | ||
110 | #endif | 106 | #endif |
111 | |||
diff --git a/tmk_core/common/backlight.c b/tmk_core/common/backlight.c index c0e9fb5ee..708022f68 100644 --- a/tmk_core/common/backlight.c +++ b/tmk_core/common/backlight.c | |||
@@ -25,15 +25,14 @@ backlight_config_t backlight_config; | |||
25 | * | 25 | * |
26 | * FIXME: needs doc | 26 | * FIXME: needs doc |
27 | */ | 27 | */ |
28 | void backlight_init(void) | 28 | void backlight_init(void) { |
29 | { | ||
30 | /* check signature */ | 29 | /* check signature */ |
31 | if (!eeconfig_is_enabled()) { | 30 | if (!eeconfig_is_enabled()) { |
32 | eeconfig_init(); | 31 | eeconfig_init(); |
33 | } | 32 | } |
34 | backlight_config.raw = eeconfig_read_backlight(); | 33 | backlight_config.raw = eeconfig_read_backlight(); |
35 | if (backlight_config.level > BACKLIGHT_LEVELS) { | 34 | if (backlight_config.level > BACKLIGHT_LEVELS) { |
36 | backlight_config.level = BACKLIGHT_LEVELS; | 35 | backlight_config.level = BACKLIGHT_LEVELS; |
37 | } | 36 | } |
38 | backlight_set(backlight_config.enable ? backlight_config.level : 0); | 37 | backlight_set(backlight_config.enable ? backlight_config.level : 0); |
39 | } | 38 | } |
@@ -42,10 +41,8 @@ void backlight_init(void) | |||
42 | * | 41 | * |
43 | * FIXME: needs doc | 42 | * FIXME: needs doc |
44 | */ | 43 | */ |
45 | void backlight_increase(void) | 44 | void backlight_increase(void) { |
46 | { | 45 | if (backlight_config.level < BACKLIGHT_LEVELS) { |
47 | if(backlight_config.level < BACKLIGHT_LEVELS) | ||
48 | { | ||
49 | backlight_config.level++; | 46 | backlight_config.level++; |
50 | } | 47 | } |
51 | backlight_config.enable = 1; | 48 | backlight_config.enable = 1; |
@@ -58,10 +55,8 @@ void backlight_increase(void) | |||
58 | * | 55 | * |
59 | * FIXME: needs doc | 56 | * FIXME: needs doc |
60 | */ | 57 | */ |
61 | void backlight_decrease(void) | 58 | void backlight_decrease(void) { |
62 | { | 59 | if (backlight_config.level > 0) { |
63 | if(backlight_config.level > 0) | ||
64 | { | ||
65 | backlight_config.level--; | 60 | backlight_config.level--; |
66 | backlight_config.enable = !!backlight_config.level; | 61 | backlight_config.enable = !!backlight_config.level; |
67 | eeconfig_update_backlight(backlight_config.raw); | 62 | eeconfig_update_backlight(backlight_config.raw); |
@@ -74,64 +69,56 @@ void backlight_decrease(void) | |||
74 | * | 69 | * |
75 | * FIXME: needs doc | 70 | * FIXME: needs doc |
76 | */ | 71 | */ |
77 | void backlight_toggle(void) | 72 | void backlight_toggle(void) { |
78 | { | 73 | bool enabled = backlight_config.enable; |
79 | bool enabled = backlight_config.enable; | 74 | dprintf("backlight toggle: %u\n", enabled); |
80 | dprintf("backlight toggle: %u\n", enabled); | 75 | if (enabled) |
81 | if (enabled) | 76 | backlight_disable(); |
82 | backlight_disable(); | 77 | else |
83 | else | 78 | backlight_enable(); |
84 | backlight_enable(); | ||
85 | } | 79 | } |
86 | 80 | ||
87 | /** \brief Enable backlight | 81 | /** \brief Enable backlight |
88 | * | 82 | * |
89 | * FIXME: needs doc | 83 | * FIXME: needs doc |
90 | */ | 84 | */ |
91 | void backlight_enable(void) | 85 | void backlight_enable(void) { |
92 | { | 86 | if (backlight_config.enable) return; // do nothing if backlight is already on |
93 | if (backlight_config.enable) return; // do nothing if backlight is already on | 87 | |
94 | 88 | backlight_config.enable = true; | |
95 | backlight_config.enable = true; | 89 | if (backlight_config.raw == 1) // enabled but level == 0 |
96 | if (backlight_config.raw == 1) // enabled but level == 0 | 90 | backlight_config.level = 1; |
97 | backlight_config.level = 1; | 91 | eeconfig_update_backlight(backlight_config.raw); |
98 | eeconfig_update_backlight(backlight_config.raw); | 92 | dprintf("backlight enable\n"); |
99 | dprintf("backlight enable\n"); | 93 | backlight_set(backlight_config.level); |
100 | backlight_set(backlight_config.level); | ||
101 | } | 94 | } |
102 | 95 | ||
103 | /** \brief Disable backlight | 96 | /** \brief Disable backlight |
104 | * | 97 | * |
105 | * FIXME: needs doc | 98 | * FIXME: needs doc |
106 | */ | 99 | */ |
107 | void backlight_disable(void) | 100 | void backlight_disable(void) { |
108 | { | 101 | if (!backlight_config.enable) return; // do nothing if backlight is already off |
109 | if (!backlight_config.enable) return; // do nothing if backlight is already off | 102 | |
110 | 103 | backlight_config.enable = false; | |
111 | backlight_config.enable = false; | 104 | eeconfig_update_backlight(backlight_config.raw); |
112 | eeconfig_update_backlight(backlight_config.raw); | 105 | dprintf("backlight disable\n"); |
113 | dprintf("backlight disable\n"); | 106 | backlight_set(0); |
114 | backlight_set(0); | ||
115 | } | 107 | } |
116 | 108 | ||
117 | /** /brief Get the backlight status | 109 | /** /brief Get the backlight status |
118 | * | 110 | * |
119 | * FIXME: needs doc | 111 | * FIXME: needs doc |
120 | */ | 112 | */ |
121 | bool is_backlight_enabled(void) | 113 | bool is_backlight_enabled(void) { return backlight_config.enable; } |
122 | { | ||
123 | return backlight_config.enable; | ||
124 | } | ||
125 | 114 | ||
126 | /** \brief Backlight step through levels | 115 | /** \brief Backlight step through levels |
127 | * | 116 | * |
128 | * FIXME: needs doc | 117 | * FIXME: needs doc |
129 | */ | 118 | */ |
130 | void backlight_step(void) | 119 | void backlight_step(void) { |
131 | { | ||
132 | backlight_config.level++; | 120 | backlight_config.level++; |
133 | if(backlight_config.level > BACKLIGHT_LEVELS) | 121 | if (backlight_config.level > BACKLIGHT_LEVELS) { |
134 | { | ||
135 | backlight_config.level = 0; | 122 | backlight_config.level = 0; |
136 | } | 123 | } |
137 | backlight_config.enable = !!backlight_config.level; | 124 | backlight_config.enable = !!backlight_config.level; |
@@ -144,11 +131,9 @@ void backlight_step(void) | |||
144 | * | 131 | * |
145 | * FIXME: needs doc | 132 | * FIXME: needs doc |
146 | */ | 133 | */ |
147 | void backlight_level(uint8_t level) | 134 | void backlight_level(uint8_t level) { |
148 | { | 135 | if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS; |
149 | if (level > BACKLIGHT_LEVELS) | 136 | backlight_config.level = level; |
150 | level = BACKLIGHT_LEVELS; | ||
151 | backlight_config.level = level; | ||
152 | backlight_config.enable = !!backlight_config.level; | 137 | backlight_config.enable = !!backlight_config.level; |
153 | eeconfig_update_backlight(backlight_config.raw); | 138 | eeconfig_update_backlight(backlight_config.raw); |
154 | backlight_set(backlight_config.level); | 139 | backlight_set(backlight_config.level); |
@@ -158,21 +143,17 @@ void backlight_level(uint8_t level) | |||
158 | * | 143 | * |
159 | * FIXME: needs doc | 144 | * FIXME: needs doc |
160 | */ | 145 | */ |
161 | uint8_t get_backlight_level(void) | 146 | uint8_t get_backlight_level(void) { return backlight_config.level; } |
162 | { | ||
163 | return backlight_config.level; | ||
164 | } | ||
165 | 147 | ||
166 | #ifdef BACKLIGHT_BREATHING | 148 | #ifdef BACKLIGHT_BREATHING |
167 | /** \brief Backlight breathing toggle | 149 | /** \brief Backlight breathing toggle |
168 | * | 150 | * |
169 | * FIXME: needs doc | 151 | * FIXME: needs doc |
170 | */ | 152 | */ |
171 | void backlight_toggle_breathing(void) | 153 | void backlight_toggle_breathing(void) { |
172 | { | ||
173 | bool breathing = backlight_config.breathing; | 154 | bool breathing = backlight_config.breathing; |
174 | dprintf("backlight breathing toggle: %u\n", breathing); | 155 | dprintf("backlight breathing toggle: %u\n", breathing); |
175 | if (breathing) | 156 | if (breathing) |
176 | backlight_disable_breathing(); | 157 | backlight_disable_breathing(); |
177 | else | 158 | else |
178 | backlight_enable_breathing(); | 159 | backlight_enable_breathing(); |
@@ -182,9 +163,8 @@ void backlight_toggle_breathing(void) | |||
182 | * | 163 | * |
183 | * FIXME: needs doc | 164 | * FIXME: needs doc |
184 | */ | 165 | */ |
185 | void backlight_enable_breathing(void) | 166 | void backlight_enable_breathing(void) { |
186 | { | 167 | if (backlight_config.breathing) return; // do nothing if breathing is already on |
187 | if (backlight_config.breathing) return; // do nothing if breathing is already on | ||
188 | 168 | ||
189 | backlight_config.breathing = true; | 169 | backlight_config.breathing = true; |
190 | eeconfig_update_backlight(backlight_config.raw); | 170 | eeconfig_update_backlight(backlight_config.raw); |
@@ -196,9 +176,8 @@ void backlight_enable_breathing(void) | |||
196 | * | 176 | * |
197 | * FIXME: needs doc | 177 | * FIXME: needs doc |
198 | */ | 178 | */ |
199 | void backlight_disable_breathing(void) | 179 | void backlight_disable_breathing(void) { |
200 | { | 180 | if (!backlight_config.breathing) return; // do nothing if breathing is already off |
201 | if (!backlight_config.breathing) return; // do nothing if breathing is already off | ||
202 | 181 | ||
203 | backlight_config.breathing = false; | 182 | backlight_config.breathing = false; |
204 | eeconfig_update_backlight(backlight_config.raw); | 183 | eeconfig_update_backlight(backlight_config.raw); |
@@ -210,8 +189,5 @@ void backlight_disable_breathing(void) | |||
210 | * | 189 | * |
211 | * FIXME: needs doc | 190 | * FIXME: needs doc |
212 | */ | 191 | */ |
213 | bool is_backlight_breathing(void) | 192 | bool is_backlight_breathing(void) { return backlight_config.breathing; } |
214 | { | ||
215 | return backlight_config.breathing; | ||
216 | } | ||
217 | #endif | 193 | #endif |
diff --git a/tmk_core/common/backlight.h b/tmk_core/common/backlight.h index 0a3877120..bb1f897ee 100644 --- a/tmk_core/common/backlight.h +++ b/tmk_core/common/backlight.h | |||
@@ -21,31 +21,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
21 | #include <stdbool.h> | 21 | #include <stdbool.h> |
22 | 22 | ||
23 | #ifndef BACKLIGHT_LEVELS | 23 | #ifndef BACKLIGHT_LEVELS |
24 | #define BACKLIGHT_LEVELS 3 | 24 | # define BACKLIGHT_LEVELS 3 |
25 | #elif BACKLIGHT_LEVELS > 31 | 25 | #elif BACKLIGHT_LEVELS > 31 |
26 | #error "Maximum value of BACKLIGHT_LEVELS is 31" | 26 | # error "Maximum value of BACKLIGHT_LEVELS is 31" |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | typedef union { | 29 | typedef union { |
30 | uint8_t raw; | 30 | uint8_t raw; |
31 | struct { | 31 | struct { |
32 | bool enable :1; | 32 | bool enable : 1; |
33 | bool breathing :1; | 33 | bool breathing : 1; |
34 | uint8_t reserved :1; // Reserved for possible future backlight modes | 34 | uint8_t reserved : 1; // Reserved for possible future backlight modes |
35 | uint8_t level :5; | 35 | uint8_t level : 5; |
36 | }; | 36 | }; |
37 | } backlight_config_t; | 37 | } backlight_config_t; |
38 | 38 | ||
39 | void backlight_init(void); | 39 | void backlight_init(void); |
40 | void backlight_increase(void); | 40 | void backlight_increase(void); |
41 | void backlight_decrease(void); | 41 | void backlight_decrease(void); |
42 | void backlight_toggle(void); | 42 | void backlight_toggle(void); |
43 | void backlight_enable(void); | 43 | void backlight_enable(void); |
44 | void backlight_disable(void); | 44 | void backlight_disable(void); |
45 | bool is_backlight_enabled(void); | 45 | bool is_backlight_enabled(void); |
46 | void backlight_step(void); | 46 | void backlight_step(void); |
47 | void backlight_set(uint8_t level); | 47 | void backlight_set(uint8_t level); |
48 | void backlight_level(uint8_t level); | 48 | void backlight_level(uint8_t level); |
49 | uint8_t get_backlight_level(void); | 49 | uint8_t get_backlight_level(void); |
50 | 50 | ||
51 | #ifdef BACKLIGHT_BREATHING | 51 | #ifdef BACKLIGHT_BREATHING |
diff --git a/tmk_core/common/bootloader.h b/tmk_core/common/bootloader.h index 44775039d..19260a079 100644 --- a/tmk_core/common/bootloader.h +++ b/tmk_core/common/bootloader.h | |||
@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
18 | #ifndef BOOTLOADER_H | 18 | #ifndef BOOTLOADER_H |
19 | #define BOOTLOADER_H | 19 | #define BOOTLOADER_H |
20 | 20 | ||
21 | |||
22 | /* give code for your bootloader to come up if needed */ | 21 | /* give code for your bootloader to come up if needed */ |
23 | void bootloader_jump(void); | 22 | void bootloader_jump(void); |
24 | 23 | ||
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c index cc780d17a..09b1664c9 100644 --- a/tmk_core/common/bootmagic.c +++ b/tmk_core/common/bootmagic.c | |||
@@ -16,8 +16,7 @@ keymap_config_t keymap_config; | |||
16 | * | 16 | * |
17 | * FIXME: needs doc | 17 | * FIXME: needs doc |
18 | */ | 18 | */ |
19 | void bootmagic(void) | 19 | void bootmagic(void) { |
20 | { | ||
21 | /* check signature */ | 20 | /* check signature */ |
22 | if (!eeconfig_is_enabled()) { | 21 | if (!eeconfig_is_enabled()) { |
23 | eeconfig_init(); | 22 | eeconfig_init(); |
@@ -26,7 +25,10 @@ void bootmagic(void) | |||
26 | /* do scans in case of bounce */ | 25 | /* do scans in case of bounce */ |
27 | print("bootmagic scan: ... "); | 26 | print("bootmagic scan: ... "); |
28 | uint8_t scan = 100; | 27 | uint8_t scan = 100; |
29 | while (scan--) { matrix_scan(); wait_ms(10); } | 28 | while (scan--) { |
29 | matrix_scan(); | ||
30 | wait_ms(10); | ||
31 | } | ||
30 | print("done.\n"); | 32 | print("done.\n"); |
31 | 33 | ||
32 | /* bootmagic skip */ | 34 | /* bootmagic skip */ |
@@ -89,14 +91,30 @@ void bootmagic(void) | |||
89 | 91 | ||
90 | /* default layer */ | 92 | /* default layer */ |
91 | uint8_t default_layer = 0; | 93 | uint8_t default_layer = 0; |
92 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); } | 94 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { |
93 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { default_layer |= (1<<1); } | 95 | default_layer |= (1 << 0); |
94 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { default_layer |= (1<<2); } | 96 | } |
95 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { default_layer |= (1<<3); } | 97 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { |
96 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { default_layer |= (1<<4); } | 98 | default_layer |= (1 << 1); |
97 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { default_layer |= (1<<5); } | 99 | } |
98 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { default_layer |= (1<<6); } | 100 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { |
99 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); } | 101 | default_layer |= (1 << 2); |
102 | } | ||
103 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { | ||
104 | default_layer |= (1 << 3); | ||
105 | } | ||
106 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { | ||
107 | default_layer |= (1 << 4); | ||
108 | } | ||
109 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { | ||
110 | default_layer |= (1 << 5); | ||
111 | } | ||
112 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { | ||
113 | default_layer |= (1 << 6); | ||
114 | } | ||
115 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { | ||
116 | default_layer |= (1 << 7); | ||
117 | } | ||
100 | if (default_layer) { | 118 | if (default_layer) { |
101 | eeconfig_update_default_layer(default_layer); | 119 | eeconfig_update_default_layer(default_layer); |
102 | default_layer_set((layer_state_t)default_layer); | 120 | default_layer_set((layer_state_t)default_layer); |
@@ -110,13 +128,12 @@ void bootmagic(void) | |||
110 | * | 128 | * |
111 | * FIXME: needs doc | 129 | * FIXME: needs doc |
112 | */ | 130 | */ |
113 | static bool scan_keycode(uint8_t keycode) | 131 | static bool scan_keycode(uint8_t keycode) { |
114 | { | ||
115 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | 132 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { |
116 | matrix_row_t matrix_row = matrix_get_row(r); | 133 | matrix_row_t matrix_row = matrix_get_row(r); |
117 | for (uint8_t c = 0; c < MATRIX_COLS; c++) { | 134 | for (uint8_t c = 0; c < MATRIX_COLS; c++) { |
118 | if (matrix_row & ((matrix_row_t)1<<c)) { | 135 | if (matrix_row & ((matrix_row_t)1 << c)) { |
119 | if (keycode == keymap_key_to_keycode(0, (keypos_t){ .row = r, .col = c })) { | 136 | if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) { |
120 | return true; | 137 | return true; |
121 | } | 138 | } |
122 | } | 139 | } |
@@ -129,8 +146,7 @@ static bool scan_keycode(uint8_t keycode) | |||
129 | * | 146 | * |
130 | * FIXME: needs doc | 147 | * FIXME: needs doc |
131 | */ | 148 | */ |
132 | bool bootmagic_scan_keycode(uint8_t keycode) | 149 | bool bootmagic_scan_keycode(uint8_t keycode) { |
133 | { | ||
134 | if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false; | 150 | if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false; |
135 | 151 | ||
136 | return scan_keycode(keycode); | 152 | return scan_keycode(keycode); |
diff --git a/tmk_core/common/bootmagic.h b/tmk_core/common/bootmagic.h index f3ea6a24d..fb7647257 100644 --- a/tmk_core/common/bootmagic.h +++ b/tmk_core/common/bootmagic.h | |||
@@ -1,101 +1,98 @@ | |||
1 | #ifndef BOOTMAGIC_H | 1 | #ifndef BOOTMAGIC_H |
2 | #define BOOTMAGIC_H | 2 | #define BOOTMAGIC_H |
3 | 3 | ||
4 | |||
5 | /* FIXME: Add special doxygen comments for defines here. */ | 4 | /* FIXME: Add special doxygen comments for defines here. */ |
6 | 5 | ||
7 | /* bootmagic salt key */ | 6 | /* bootmagic salt key */ |
8 | #ifndef BOOTMAGIC_KEY_SALT | 7 | #ifndef BOOTMAGIC_KEY_SALT |
9 | #define BOOTMAGIC_KEY_SALT KC_SPACE | 8 | # define BOOTMAGIC_KEY_SALT KC_SPACE |
10 | #endif | 9 | #endif |
11 | 10 | ||
12 | /* skip bootmagic and eeconfig */ | 11 | /* skip bootmagic and eeconfig */ |
13 | #ifndef BOOTMAGIC_KEY_SKIP | 12 | #ifndef BOOTMAGIC_KEY_SKIP |
14 | #define BOOTMAGIC_KEY_SKIP KC_ESC | 13 | # define BOOTMAGIC_KEY_SKIP KC_ESC |
15 | #endif | 14 | #endif |
16 | 15 | ||
17 | /* eeprom clear */ | 16 | /* eeprom clear */ |
18 | #ifndef BOOTMAGIC_KEY_EEPROM_CLEAR | 17 | #ifndef BOOTMAGIC_KEY_EEPROM_CLEAR |
19 | #define BOOTMAGIC_KEY_EEPROM_CLEAR KC_BSPACE | 18 | # define BOOTMAGIC_KEY_EEPROM_CLEAR KC_BSPACE |
20 | #endif | 19 | #endif |
21 | 20 | ||
22 | /* kick up bootloader */ | 21 | /* kick up bootloader */ |
23 | #ifndef BOOTMAGIC_KEY_BOOTLOADER | 22 | #ifndef BOOTMAGIC_KEY_BOOTLOADER |
24 | #define BOOTMAGIC_KEY_BOOTLOADER KC_B | 23 | # define BOOTMAGIC_KEY_BOOTLOADER KC_B |
25 | #endif | 24 | #endif |
26 | 25 | ||
27 | /* debug enable */ | 26 | /* debug enable */ |
28 | #ifndef BOOTMAGIC_KEY_DEBUG_ENABLE | 27 | #ifndef BOOTMAGIC_KEY_DEBUG_ENABLE |
29 | #define BOOTMAGIC_KEY_DEBUG_ENABLE KC_D | 28 | # define BOOTMAGIC_KEY_DEBUG_ENABLE KC_D |
30 | #endif | 29 | #endif |
31 | #ifndef BOOTMAGIC_KEY_DEBUG_MATRIX | 30 | #ifndef BOOTMAGIC_KEY_DEBUG_MATRIX |
32 | #define BOOTMAGIC_KEY_DEBUG_MATRIX KC_X | 31 | # define BOOTMAGIC_KEY_DEBUG_MATRIX KC_X |
33 | #endif | 32 | #endif |
34 | #ifndef BOOTMAGIC_KEY_DEBUG_KEYBOARD | 33 | #ifndef BOOTMAGIC_KEY_DEBUG_KEYBOARD |
35 | #define BOOTMAGIC_KEY_DEBUG_KEYBOARD KC_K | 34 | # define BOOTMAGIC_KEY_DEBUG_KEYBOARD KC_K |
36 | #endif | 35 | #endif |
37 | #ifndef BOOTMAGIC_KEY_DEBUG_MOUSE | 36 | #ifndef BOOTMAGIC_KEY_DEBUG_MOUSE |
38 | #define BOOTMAGIC_KEY_DEBUG_MOUSE KC_M | 37 | # define BOOTMAGIC_KEY_DEBUG_MOUSE KC_M |
39 | #endif | 38 | #endif |
40 | 39 | ||
41 | /* | 40 | /* |
42 | * keymap config | 41 | * keymap config |
43 | */ | 42 | */ |
44 | #ifndef BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK | 43 | #ifndef BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK |
45 | #define BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK KC_LCTRL | 44 | # define BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK KC_LCTRL |
46 | #endif | 45 | #endif |
47 | #ifndef BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL | 46 | #ifndef BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL |
48 | #define BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL KC_CAPSLOCK | 47 | # define BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL KC_CAPSLOCK |
49 | #endif | 48 | #endif |
50 | #ifndef BOOTMAGIC_KEY_SWAP_LALT_LGUI | 49 | #ifndef BOOTMAGIC_KEY_SWAP_LALT_LGUI |
51 | #define BOOTMAGIC_KEY_SWAP_LALT_LGUI KC_LALT | 50 | # define BOOTMAGIC_KEY_SWAP_LALT_LGUI KC_LALT |
52 | #endif | 51 | #endif |
53 | #ifndef BOOTMAGIC_KEY_SWAP_RALT_RGUI | 52 | #ifndef BOOTMAGIC_KEY_SWAP_RALT_RGUI |
54 | #define BOOTMAGIC_KEY_SWAP_RALT_RGUI KC_RALT | 53 | # define BOOTMAGIC_KEY_SWAP_RALT_RGUI KC_RALT |
55 | #endif | 54 | #endif |
56 | #ifndef BOOTMAGIC_KEY_NO_GUI | 55 | #ifndef BOOTMAGIC_KEY_NO_GUI |
57 | #define BOOTMAGIC_KEY_NO_GUI KC_LGUI | 56 | # define BOOTMAGIC_KEY_NO_GUI KC_LGUI |
58 | #endif | 57 | #endif |
59 | #ifndef BOOTMAGIC_KEY_SWAP_GRAVE_ESC | 58 | #ifndef BOOTMAGIC_KEY_SWAP_GRAVE_ESC |
60 | #define BOOTMAGIC_KEY_SWAP_GRAVE_ESC KC_GRAVE | 59 | # define BOOTMAGIC_KEY_SWAP_GRAVE_ESC KC_GRAVE |
61 | #endif | 60 | #endif |
62 | #ifndef BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE | 61 | #ifndef BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE |
63 | #define BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE KC_BSLASH | 62 | # define BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE KC_BSLASH |
64 | #endif | 63 | #endif |
65 | #ifndef BOOTMAGIC_HOST_NKRO | 64 | #ifndef BOOTMAGIC_HOST_NKRO |
66 | #define BOOTMAGIC_HOST_NKRO KC_N | 65 | # define BOOTMAGIC_HOST_NKRO KC_N |
67 | #endif | 66 | #endif |
68 | 67 | ||
69 | |||
70 | /* | 68 | /* |
71 | * change default layer | 69 | * change default layer |
72 | */ | 70 | */ |
73 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_0 | 71 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_0 |
74 | #define BOOTMAGIC_KEY_DEFAULT_LAYER_0 KC_0 | 72 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_0 KC_0 |
75 | #endif | 73 | #endif |
76 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_1 | 74 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_1 |
77 | #define BOOTMAGIC_KEY_DEFAULT_LAYER_1 KC_1 | 75 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_1 KC_1 |
78 | #endif | 76 | #endif |
79 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_2 | 77 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_2 |
80 | #define BOOTMAGIC_KEY_DEFAULT_LAYER_2 KC_2 | 78 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_2 KC_2 |
81 | #endif | 79 | #endif |
82 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_3 | 80 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_3 |
83 | #define BOOTMAGIC_KEY_DEFAULT_LAYER_3 KC_3 | 81 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_3 KC_3 |
84 | #endif | 82 | #endif |
85 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_4 | 83 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_4 |
86 | #define BOOTMAGIC_KEY_DEFAULT_LAYER_4 KC_4 | 84 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_4 KC_4 |
87 | #endif | 85 | #endif |
88 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_5 | 86 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_5 |
89 | #define BOOTMAGIC_KEY_DEFAULT_LAYER_5 KC_5 | 87 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_5 KC_5 |
90 | #endif | 88 | #endif |
91 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_6 | 89 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_6 |
92 | #define BOOTMAGIC_KEY_DEFAULT_LAYER_6 KC_6 | 90 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_6 KC_6 |
93 | #endif | 91 | #endif |
94 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7 | 92 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7 |
95 | #define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7 | 93 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7 |
96 | #endif | 94 | #endif |
97 | 95 | ||
98 | |||
99 | void bootmagic(void); | 96 | void bootmagic(void); |
100 | bool bootmagic_scan_keycode(uint8_t keycode); | 97 | bool bootmagic_scan_keycode(uint8_t keycode); |
101 | 98 | ||
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c index f9895237b..4cf5dae7e 100644 --- a/tmk_core/common/chibios/bootloader.c +++ b/tmk_core/common/chibios/bootloader.c | |||
@@ -7,63 +7,62 @@ | |||
7 | /* STM32 */ | 7 | /* STM32 */ |
8 | 8 | ||
9 | /* This code should be checked whether it runs correctly on platforms */ | 9 | /* This code should be checked whether it runs correctly on platforms */ |
10 | #define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) | 10 | # define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) |
11 | extern uint32_t __ram0_end__; | 11 | extern uint32_t __ram0_end__; |
12 | #define BOOTLOADER_MAGIC 0xDEADBEEF | 12 | # define BOOTLOADER_MAGIC 0xDEADBEEF |
13 | #define MAGIC_ADDR (unsigned long*)(SYMVAL(__ram0_end__) - 4) | 13 | # define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4) |
14 | |||
15 | 14 | ||
16 | /** \brief Jump to the bootloader | 15 | /** \brief Jump to the bootloader |
17 | * | 16 | * |
18 | * FIXME: needs doc | 17 | * FIXME: needs doc |
19 | */ | 18 | */ |
20 | void bootloader_jump(void) { | 19 | void bootloader_jump(void) { |
21 | *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader | 20 | *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader |
22 | NVIC_SystemReset(); | 21 | NVIC_SystemReset(); |
23 | } | 22 | } |
24 | 23 | ||
25 | /** \brief Enter bootloader mode if requested | 24 | /** \brief Enter bootloader mode if requested |
26 | * | 25 | * |
27 | * FIXME: needs doc | 26 | * FIXME: needs doc |
28 | */ | 27 | */ |
29 | void enter_bootloader_mode_if_requested(void) { | 28 | void enter_bootloader_mode_if_requested(void) { |
30 | unsigned long* check = MAGIC_ADDR; | 29 | unsigned long *check = MAGIC_ADDR; |
31 | if(*check == BOOTLOADER_MAGIC) { | 30 | if (*check == BOOTLOADER_MAGIC) { |
32 | *check = 0; | 31 | *check = 0; |
33 | __set_CONTROL(0); | 32 | __set_CONTROL(0); |
34 | __set_MSP(*(__IO uint32_t*)STM32_BOOTLOADER_ADDRESS); | 33 | __set_MSP(*(__IO uint32_t *)STM32_BOOTLOADER_ADDRESS); |
35 | __enable_irq(); | 34 | __enable_irq(); |
36 | 35 | ||
37 | typedef void (*BootJump_t)(void); | 36 | typedef void (*BootJump_t)(void); |
38 | BootJump_t boot_jump = *(BootJump_t*)(STM32_BOOTLOADER_ADDRESS + 4); | 37 | BootJump_t boot_jump = *(BootJump_t *)(STM32_BOOTLOADER_ADDRESS + 4); |
39 | boot_jump(); | 38 | boot_jump(); |
40 | while(1); | 39 | while (1) |
41 | } | 40 | ; |
42 | } | 41 | } |
42 | } | ||
43 | 43 | ||
44 | #elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */ | 44 | #elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */ |
45 | /* Kinetis */ | 45 | /* Kinetis */ |
46 | 46 | ||
47 | #if defined(KIIBOHD_BOOTLOADER) | 47 | # if defined(KIIBOHD_BOOTLOADER) |
48 | /* Kiibohd Bootloader (MCHCK and Infinity KB) */ | 48 | /* Kiibohd Bootloader (MCHCK and Infinity KB) */ |
49 | #define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000 | 49 | # define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000 |
50 | const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; | 50 | const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; |
51 | void bootloader_jump(void) { | 51 | void bootloader_jump(void) { |
52 | __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic)); | 52 | __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic)); |
53 | // request reset | 53 | // request reset |
54 | SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk; | 54 | SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk; |
55 | } | 55 | } |
56 | 56 | ||
57 | #else /* defined(KIIBOHD_BOOTLOADER) */ | 57 | # else /* defined(KIIBOHD_BOOTLOADER) */ |
58 | /* Default for Kinetis - expecting an ARM Teensy */ | 58 | /* Default for Kinetis - expecting an ARM Teensy */ |
59 | #include "wait.h" | 59 | # include "wait.h" |
60 | void bootloader_jump(void) { | 60 | void bootloader_jump(void) { |
61 | wait_ms(100); | 61 | wait_ms(100); |
62 | __BKPT(0); | 62 | __BKPT(0); |
63 | } | 63 | } |
64 | #endif /* defined(KIIBOHD_BOOTLOADER) */ | 64 | # endif /* defined(KIIBOHD_BOOTLOADER) */ |
65 | 65 | ||
66 | #else /* neither STM32 nor KINETIS */ | 66 | #else /* neither STM32 nor KINETIS */ |
67 | __attribute__((weak)) | 67 | __attribute__((weak)) void bootloader_jump(void) {} |
68 | void bootloader_jump(void) {} | ||
69 | #endif | 68 | #endif |
diff --git a/tmk_core/common/chibios/eeprom_stm32.c b/tmk_core/common/chibios/eeprom_stm32.c index 4b1abc968..926b581c6 100755..100644 --- a/tmk_core/common/chibios/eeprom_stm32.c +++ b/tmk_core/common/chibios/eeprom_stm32.c | |||
@@ -24,7 +24,7 @@ | |||
24 | * the functionality use the EEPROM_Init() function. Be sure that by reprogramming | 24 | * the functionality use the EEPROM_Init() function. Be sure that by reprogramming |
25 | * of the controller just affected pages will be deleted. In other case the non | 25 | * of the controller just affected pages will be deleted. In other case the non |
26 | * volatile data will be lost. | 26 | * volatile data will be lost. |
27 | ******************************************************************************/ | 27 | ******************************************************************************/ |
28 | 28 | ||
29 | /* Private macro -------------------------------------------------------------*/ | 29 | /* Private macro -------------------------------------------------------------*/ |
30 | /* Private variables ---------------------------------------------------------*/ | 30 | /* Private variables ---------------------------------------------------------*/ |
@@ -32,23 +32,22 @@ | |||
32 | 32 | ||
33 | uint8_t DataBuf[FEE_PAGE_SIZE]; | 33 | uint8_t DataBuf[FEE_PAGE_SIZE]; |
34 | /***************************************************************************** | 34 | /***************************************************************************** |
35 | * Delete Flash Space used for user Data, deletes the whole space between | 35 | * Delete Flash Space used for user Data, deletes the whole space between |
36 | * RW_PAGE_BASE_ADDRESS and the last uC Flash Page | 36 | * RW_PAGE_BASE_ADDRESS and the last uC Flash Page |
37 | ******************************************************************************/ | 37 | ******************************************************************************/ |
38 | uint16_t EEPROM_Init(void) { | 38 | uint16_t EEPROM_Init(void) { |
39 | // unlock flash | 39 | // unlock flash |
40 | FLASH_Unlock(); | 40 | FLASH_Unlock(); |
41 | 41 | ||
42 | // Clear Flags | 42 | // Clear Flags |
43 | //FLASH_ClearFlag(FLASH_SR_EOP|FLASH_SR_PGERR|FLASH_SR_WRPERR); | 43 | // FLASH_ClearFlag(FLASH_SR_EOP|FLASH_SR_PGERR|FLASH_SR_WRPERR); |
44 | 44 | ||
45 | return FEE_DENSITY_BYTES; | 45 | return FEE_DENSITY_BYTES; |
46 | } | 46 | } |
47 | /***************************************************************************** | 47 | /***************************************************************************** |
48 | * Erase the whole reserved Flash Space used for user Data | 48 | * Erase the whole reserved Flash Space used for user Data |
49 | ******************************************************************************/ | 49 | ******************************************************************************/ |
50 | void EEPROM_Erase (void) { | 50 | void EEPROM_Erase(void) { |
51 | |||
52 | int page_num = 0; | 51 | int page_num = 0; |
53 | 52 | ||
54 | // delete all pages from specified start page to the last page | 53 | // delete all pages from specified start page to the last page |
@@ -58,16 +57,15 @@ void EEPROM_Erase (void) { | |||
58 | } while (page_num < FEE_DENSITY_PAGES); | 57 | } while (page_num < FEE_DENSITY_PAGES); |
59 | } | 58 | } |
60 | /***************************************************************************** | 59 | /***************************************************************************** |
61 | * Writes once data byte to flash on specified address. If a byte is already | 60 | * Writes once data byte to flash on specified address. If a byte is already |
62 | * written, the whole page must be copied to a buffer, the byte changed and | 61 | * written, the whole page must be copied to a buffer, the byte changed and |
63 | * the manipulated buffer written after PageErase. | 62 | * the manipulated buffer written after PageErase. |
64 | *******************************************************************************/ | 63 | *******************************************************************************/ |
65 | uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) { | 64 | uint16_t EEPROM_WriteDataByte(uint16_t Address, uint8_t DataByte) { |
66 | |||
67 | FLASH_Status FlashStatus = FLASH_COMPLETE; | 65 | FLASH_Status FlashStatus = FLASH_COMPLETE; |
68 | 66 | ||
69 | uint32_t page; | 67 | uint32_t page; |
70 | int i; | 68 | int i; |
71 | 69 | ||
72 | // exit if desired address is above the limit (e.G. under 2048 Bytes for 4 pages) | 70 | // exit if desired address is above the limit (e.G. under 2048 Bytes for 4 pages) |
73 | if (Address > FEE_DENSITY_BYTES) { | 71 | if (Address > FEE_DENSITY_BYTES) { |
@@ -78,27 +76,25 @@ uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) { | |||
78 | page = FEE_ADDR_OFFSET(Address) / FEE_PAGE_SIZE; | 76 | page = FEE_ADDR_OFFSET(Address) / FEE_PAGE_SIZE; |
79 | 77 | ||
80 | // if current data is 0xFF, the byte is empty, just overwrite with the new one | 78 | // if current data is 0xFF, the byte is empty, just overwrite with the new one |
81 | if ((*(__IO uint16_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) == FEE_EMPTY_WORD) { | 79 | if ((*(__IO uint16_t *)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) == FEE_EMPTY_WORD) { |
82 | |||
83 | FlashStatus = FLASH_ProgramHalfWord(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address), (uint16_t)(0x00FF & DataByte)); | 80 | FlashStatus = FLASH_ProgramHalfWord(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address), (uint16_t)(0x00FF & DataByte)); |
84 | } else { | 81 | } else { |
85 | |||
86 | // Copy Page to a buffer | 82 | // Copy Page to a buffer |
87 | memcpy(DataBuf, (uint8_t*)FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE), FEE_PAGE_SIZE); // !!! Calculate base address for the desired page | 83 | memcpy(DataBuf, (uint8_t *)FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE), FEE_PAGE_SIZE); // !!! Calculate base address for the desired page |
88 | 84 | ||
89 | // check if new data is differ to current data, return if not, proceed if yes | 85 | // check if new data is differ to current data, return if not, proceed if yes |
90 | if (DataByte == *(__IO uint8_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) { | 86 | if (DataByte == *(__IO uint8_t *)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) { |
91 | return 0; | 87 | return 0; |
92 | } | 88 | } |
93 | 89 | ||
94 | // manipulate desired data byte in temp data array if new byte is differ to the current | 90 | // manipulate desired data byte in temp data array if new byte is differ to the current |
95 | DataBuf[FEE_ADDR_OFFSET(Address) % FEE_PAGE_SIZE] = DataByte; | 91 | DataBuf[FEE_ADDR_OFFSET(Address) % FEE_PAGE_SIZE] = DataByte; |
96 | 92 | ||
97 | //Erase Page | 93 | // Erase Page |
98 | FlashStatus = FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE)); | 94 | FlashStatus = FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE)); |
99 | 95 | ||
100 | // Write new data (whole page) to flash if data has been changed | 96 | // Write new data (whole page) to flash if data has been changed |
101 | for(i = 0; i < (FEE_PAGE_SIZE / 2); i++) { | 97 | for (i = 0; i < (FEE_PAGE_SIZE / 2); i++) { |
102 | if ((__IO uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)]) != 0xFFFF) { | 98 | if ((__IO uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)]) != 0xFFFF) { |
103 | FlashStatus = FLASH_ProgramHalfWord((FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE)) + (i * 2), (uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)])); | 99 | FlashStatus = FLASH_ProgramHalfWord((FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE)) + (i * 2), (uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)])); |
104 | } | 100 | } |
@@ -107,98 +103,86 @@ uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) { | |||
107 | return FlashStatus; | 103 | return FlashStatus; |
108 | } | 104 | } |
109 | /***************************************************************************** | 105 | /***************************************************************************** |
110 | * Read once data byte from a specified address. | 106 | * Read once data byte from a specified address. |
111 | *******************************************************************************/ | 107 | *******************************************************************************/ |
112 | uint8_t EEPROM_ReadDataByte (uint16_t Address) { | 108 | uint8_t EEPROM_ReadDataByte(uint16_t Address) { |
113 | |||
114 | uint8_t DataByte = 0xFF; | 109 | uint8_t DataByte = 0xFF; |
115 | 110 | ||
116 | // Get Byte from specified address | 111 | // Get Byte from specified address |
117 | DataByte = (*(__IO uint8_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))); | 112 | DataByte = (*(__IO uint8_t *)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))); |
118 | 113 | ||
119 | return DataByte; | 114 | return DataByte; |
120 | } | 115 | } |
121 | 116 | ||
122 | /***************************************************************************** | 117 | /***************************************************************************** |
123 | * Wrap library in AVR style functions. | 118 | * Wrap library in AVR style functions. |
124 | *******************************************************************************/ | 119 | *******************************************************************************/ |
125 | uint8_t eeprom_read_byte (const uint8_t *Address) | 120 | uint8_t eeprom_read_byte(const uint8_t *Address) { |
126 | { | 121 | const uint16_t p = (const uint32_t)Address; |
127 | const uint16_t p = (const uint32_t) Address; | ||
128 | return EEPROM_ReadDataByte(p); | 122 | return EEPROM_ReadDataByte(p); |
129 | } | 123 | } |
130 | 124 | ||
131 | void eeprom_write_byte (uint8_t *Address, uint8_t Value) | 125 | void eeprom_write_byte(uint8_t *Address, uint8_t Value) { |
132 | { | 126 | uint16_t p = (uint32_t)Address; |
133 | uint16_t p = (uint32_t) Address; | ||
134 | EEPROM_WriteDataByte(p, Value); | 127 | EEPROM_WriteDataByte(p, Value); |
135 | } | 128 | } |
136 | 129 | ||
137 | void eeprom_update_byte (uint8_t *Address, uint8_t Value) | 130 | void eeprom_update_byte(uint8_t *Address, uint8_t Value) { |
138 | { | 131 | uint16_t p = (uint32_t)Address; |
139 | uint16_t p = (uint32_t) Address; | ||
140 | EEPROM_WriteDataByte(p, Value); | 132 | EEPROM_WriteDataByte(p, Value); |
141 | } | 133 | } |
142 | 134 | ||
143 | uint16_t eeprom_read_word (const uint16_t *Address) | 135 | uint16_t eeprom_read_word(const uint16_t *Address) { |
144 | { | 136 | const uint16_t p = (const uint32_t)Address; |
145 | const uint16_t p = (const uint32_t) Address; | 137 | return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p + 1) << 8); |
146 | return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8); | ||
147 | } | 138 | } |
148 | 139 | ||
149 | void eeprom_write_word (uint16_t *Address, uint16_t Value) | 140 | void eeprom_write_word(uint16_t *Address, uint16_t Value) { |
150 | { | 141 | uint16_t p = (uint32_t)Address; |
151 | uint16_t p = (uint32_t) Address; | 142 | EEPROM_WriteDataByte(p, (uint8_t)Value); |
152 | EEPROM_WriteDataByte(p, (uint8_t) Value); | 143 | EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8)); |
153 | EEPROM_WriteDataByte(p + 1, (uint8_t) (Value >> 8)); | ||
154 | } | 144 | } |
155 | 145 | ||
156 | void eeprom_update_word (uint16_t *Address, uint16_t Value) | 146 | void eeprom_update_word(uint16_t *Address, uint16_t Value) { |
157 | { | 147 | uint16_t p = (uint32_t)Address; |
158 | uint16_t p = (uint32_t) Address; | 148 | EEPROM_WriteDataByte(p, (uint8_t)Value); |
159 | EEPROM_WriteDataByte(p, (uint8_t) Value); | 149 | EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8)); |
160 | EEPROM_WriteDataByte(p + 1, (uint8_t) (Value >> 8)); | ||
161 | } | 150 | } |
162 | 151 | ||
163 | uint32_t eeprom_read_dword (const uint32_t *Address) | 152 | uint32_t eeprom_read_dword(const uint32_t *Address) { |
164 | { | 153 | const uint16_t p = (const uint32_t)Address; |
165 | const uint16_t p = (const uint32_t) Address; | 154 | return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p + 1) << 8) | (EEPROM_ReadDataByte(p + 2) << 16) | (EEPROM_ReadDataByte(p + 3) << 24); |
166 | return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8) | ||
167 | | (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24); | ||
168 | } | 155 | } |
169 | 156 | ||
170 | void eeprom_write_dword (uint32_t *Address, uint32_t Value) | 157 | void eeprom_write_dword(uint32_t *Address, uint32_t Value) { |
171 | { | 158 | uint16_t p = (const uint32_t)Address; |
172 | uint16_t p = (const uint32_t) Address; | 159 | EEPROM_WriteDataByte(p, (uint8_t)Value); |
173 | EEPROM_WriteDataByte(p, (uint8_t) Value); | 160 | EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8)); |
174 | EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8)); | 161 | EEPROM_WriteDataByte(p + 2, (uint8_t)(Value >> 16)); |
175 | EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16)); | 162 | EEPROM_WriteDataByte(p + 3, (uint8_t)(Value >> 24)); |
176 | EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24)); | ||
177 | } | 163 | } |
178 | 164 | ||
179 | void eeprom_update_dword (uint32_t *Address, uint32_t Value) | 165 | void eeprom_update_dword(uint32_t *Address, uint32_t Value) { |
180 | { | 166 | uint16_t p = (const uint32_t)Address; |
181 | uint16_t p = (const uint32_t) Address; | 167 | uint32_t existingValue = EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p + 1) << 8) | (EEPROM_ReadDataByte(p + 2) << 16) | (EEPROM_ReadDataByte(p + 3) << 24); |
182 | uint32_t existingValue = EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8) | 168 | if (Value != existingValue) { |
183 | | (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24); | 169 | EEPROM_WriteDataByte(p, (uint8_t)Value); |
184 | if(Value != existingValue){ | 170 | EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8)); |
185 | EEPROM_WriteDataByte(p, (uint8_t) Value); | 171 | EEPROM_WriteDataByte(p + 2, (uint8_t)(Value >> 16)); |
186 | EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8)); | 172 | EEPROM_WriteDataByte(p + 3, (uint8_t)(Value >> 24)); |
187 | EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16)); | ||
188 | EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24)); | ||
189 | } | 173 | } |
190 | } | 174 | } |
191 | 175 | ||
192 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { | 176 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { |
193 | const uint8_t *p = (const uint8_t *)addr; | 177 | const uint8_t *p = (const uint8_t *)addr; |
194 | uint8_t *dest = (uint8_t *)buf; | 178 | uint8_t * dest = (uint8_t *)buf; |
195 | while (len--) { | 179 | while (len--) { |
196 | *dest++ = eeprom_read_byte(p++); | 180 | *dest++ = eeprom_read_byte(p++); |
197 | } | 181 | } |
198 | } | 182 | } |
199 | 183 | ||
200 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { | 184 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { |
201 | uint8_t *p = (uint8_t *)addr; | 185 | uint8_t * p = (uint8_t *)addr; |
202 | const uint8_t *src = (const uint8_t *)buf; | 186 | const uint8_t *src = (const uint8_t *)buf; |
203 | while (len--) { | 187 | while (len--) { |
204 | eeprom_write_byte(p++, *src++); | 188 | eeprom_write_byte(p++, *src++); |
@@ -206,7 +190,7 @@ void eeprom_write_block(const void *buf, void *addr, uint32_t len) { | |||
206 | } | 190 | } |
207 | 191 | ||
208 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { | 192 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { |
209 | uint8_t *p = (uint8_t *)addr; | 193 | uint8_t * p = (uint8_t *)addr; |
210 | const uint8_t *src = (const uint8_t *)buf; | 194 | const uint8_t *src = (const uint8_t *)buf; |
211 | while (len--) { | 195 | while (len--) { |
212 | eeprom_write_byte(p++, *src++); | 196 | eeprom_write_byte(p++, *src++); |
diff --git a/tmk_core/common/chibios/eeprom_stm32.h b/tmk_core/common/chibios/eeprom_stm32.h index 083eb16ee..e68914595 100755..100644 --- a/tmk_core/common/chibios/eeprom_stm32.h +++ b/tmk_core/common/chibios/eeprom_stm32.h | |||
@@ -31,53 +31,53 @@ | |||
31 | // HACK ALERT. This definition may not match your processor | 31 | // HACK ALERT. This definition may not match your processor |
32 | // To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc | 32 | // To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc |
33 | #if defined(EEPROM_EMU_STM32F303xC) | 33 | #if defined(EEPROM_EMU_STM32F303xC) |
34 | #define MCU_STM32F303CC | 34 | # define MCU_STM32F303CC |
35 | #elif defined(EEPROM_EMU_STM32F103xB) | 35 | #elif defined(EEPROM_EMU_STM32F103xB) |
36 | #define MCU_STM32F103RB | 36 | # define MCU_STM32F103RB |
37 | #elif defined(EEPROM_EMU_STM32F072xB) | 37 | #elif defined(EEPROM_EMU_STM32F072xB) |
38 | #define MCU_STM32F072CB | 38 | # define MCU_STM32F072CB |
39 | #else | 39 | #else |
40 | #error "not implemented." | 40 | # error "not implemented." |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #ifndef EEPROM_PAGE_SIZE | 43 | #ifndef EEPROM_PAGE_SIZE |
44 | #if defined (MCU_STM32F103RB) | 44 | # if defined(MCU_STM32F103RB) |
45 | #define FEE_PAGE_SIZE (uint16_t)0x400 // Page size = 1KByte | 45 | # define FEE_PAGE_SIZE (uint16_t)0x400 // Page size = 1KByte |
46 | #define FEE_DENSITY_PAGES 2 // How many pages are used | 46 | # define FEE_DENSITY_PAGES 2 // How many pages are used |
47 | #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) || defined (MCU_STM32F103RD) || defined (MCU_STM32F303CC) || defined(MCU_STM32F072CB) | 47 | # elif defined(MCU_STM32F103ZE) || defined(MCU_STM32F103RE) || defined(MCU_STM32F103RD) || defined(MCU_STM32F303CC) || defined(MCU_STM32F072CB) |
48 | #define FEE_PAGE_SIZE (uint16_t)0x800 // Page size = 2KByte | 48 | # define FEE_PAGE_SIZE (uint16_t)0x800 // Page size = 2KByte |
49 | #define FEE_DENSITY_PAGES 4 // How many pages are used | 49 | # define FEE_DENSITY_PAGES 4 // How many pages are used |
50 | #else | 50 | # else |
51 | #error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)." | 51 | # error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)." |
52 | #endif | 52 | # endif |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | #ifndef EEPROM_START_ADDRESS | 55 | #ifndef EEPROM_START_ADDRESS |
56 | #if defined (MCU_STM32F103RB) || defined(MCU_STM32F072CB) | 56 | # if defined(MCU_STM32F103RB) || defined(MCU_STM32F072CB) |
57 | #define FEE_MCU_FLASH_SIZE 128 // Size in Kb | 57 | # define FEE_MCU_FLASH_SIZE 128 // Size in Kb |
58 | #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) | 58 | # elif defined(MCU_STM32F103ZE) || defined(MCU_STM32F103RE) |
59 | #define FEE_MCU_FLASH_SIZE 512 // Size in Kb | 59 | # define FEE_MCU_FLASH_SIZE 512 // Size in Kb |
60 | #elif defined (MCU_STM32F103RD) | 60 | # elif defined(MCU_STM32F103RD) |
61 | #define FEE_MCU_FLASH_SIZE 384 // Size in Kb | 61 | # define FEE_MCU_FLASH_SIZE 384 // Size in Kb |
62 | #elif defined (MCU_STM32F303CC) | 62 | # elif defined(MCU_STM32F303CC) |
63 | #define FEE_MCU_FLASH_SIZE 256 // Size in Kb | 63 | # define FEE_MCU_FLASH_SIZE 256 // Size in Kb |
64 | #else | 64 | # else |
65 | #error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)." | 65 | # error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)." |
66 | #endif | 66 | # endif |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | // DONT CHANGE | 69 | // DONT CHANGE |
70 | // Choose location for the first EEPROM Page address on the top of flash | 70 | // Choose location for the first EEPROM Page address on the top of flash |
71 | #define FEE_PAGE_BASE_ADDRESS ((uint32_t)(0x8000000 + FEE_MCU_FLASH_SIZE * 1024 - FEE_DENSITY_PAGES * FEE_PAGE_SIZE)) | 71 | #define FEE_PAGE_BASE_ADDRESS ((uint32_t)(0x8000000 + FEE_MCU_FLASH_SIZE * 1024 - FEE_DENSITY_PAGES * FEE_PAGE_SIZE)) |
72 | #define FEE_DENSITY_BYTES ((FEE_PAGE_SIZE / 2) * FEE_DENSITY_PAGES - 1) | 72 | #define FEE_DENSITY_BYTES ((FEE_PAGE_SIZE / 2) * FEE_DENSITY_PAGES - 1) |
73 | #define FEE_LAST_PAGE_ADDRESS (FEE_PAGE_BASE_ADDRESS + (FEE_PAGE_SIZE * FEE_DENSITY_PAGES)) | 73 | #define FEE_LAST_PAGE_ADDRESS (FEE_PAGE_BASE_ADDRESS + (FEE_PAGE_SIZE * FEE_DENSITY_PAGES)) |
74 | #define FEE_EMPTY_WORD ((uint16_t)0xFFFF) | 74 | #define FEE_EMPTY_WORD ((uint16_t)0xFFFF) |
75 | #define FEE_ADDR_OFFSET(Address)(Address * 2) // 1Byte per Word will be saved to preserve Flash | 75 | #define FEE_ADDR_OFFSET(Address) (Address * 2) // 1Byte per Word will be saved to preserve Flash |
76 | 76 | ||
77 | // Use this function to initialize the functionality | 77 | // Use this function to initialize the functionality |
78 | uint16_t EEPROM_Init(void); | 78 | uint16_t EEPROM_Init(void); |
79 | void EEPROM_Erase (void); | 79 | void EEPROM_Erase(void); |
80 | uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte); | 80 | uint16_t EEPROM_WriteDataByte(uint16_t Address, uint8_t DataByte); |
81 | uint8_t EEPROM_ReadDataByte (uint16_t Address); | 81 | uint8_t EEPROM_ReadDataByte(uint16_t Address); |
82 | 82 | ||
83 | #endif /* __EEPROM_H */ | 83 | #endif /* __EEPROM_H */ |
diff --git a/tmk_core/common/chibios/eeprom_teensy.c b/tmk_core/common/chibios/eeprom_teensy.c index 9061b790c..a4093fb3b 100644 --- a/tmk_core/common/chibios/eeprom_teensy.c +++ b/tmk_core/common/chibios/eeprom_teensy.c | |||
@@ -21,10 +21,10 @@ | |||
21 | * permit persons to whom the Software is furnished to do so, subject to | 21 | * permit persons to whom the Software is furnished to do so, subject to |
22 | * the following conditions: | 22 | * the following conditions: |
23 | * | 23 | * |
24 | * 1. The above copyright notice and this permission notice shall be | 24 | * 1. The above copyright notice and this permission notice shall be |
25 | * included in all copies or substantial portions of the Software. | 25 | * included in all copies or substantial portions of the Software. |
26 | * | 26 | * |
27 | * 2. If the Software is incorporated into a build system that allows | 27 | * 2. If the Software is incorporated into a build system that allows |
28 | * selection among a list of target devices, then similar target | 28 | * selection among a list of target devices, then similar target |
29 | * devices manufactured by PJRC.COM must be included in the list of | 29 | * devices manufactured by PJRC.COM must be included in the list of |
30 | * target devices and selectable in the same manner. | 30 | * target devices and selectable in the same manner. |
@@ -39,7 +39,6 @@ | |||
39 | * SOFTWARE. | 39 | * SOFTWARE. |
40 | */ | 40 | */ |
41 | 41 | ||
42 | |||
43 | #if defined(K20x) /* chip selection */ | 42 | #if defined(K20x) /* chip selection */ |
44 | /* Teensy 3.0, 3.1, 3.2; mchck; infinity keyboard */ | 43 | /* Teensy 3.0, 3.1, 3.2; mchck; infinity keyboard */ |
45 | 44 | ||
@@ -51,7 +50,7 @@ | |||
51 | // (aligned to 2 or 4 byte boundaries) has twice the endurance | 50 | // (aligned to 2 or 4 byte boundaries) has twice the endurance |
52 | // compared to writing 8 bit bytes. | 51 | // compared to writing 8 bit bytes. |
53 | // | 52 | // |
54 | #define EEPROM_SIZE 32 | 53 | # define EEPROM_SIZE 32 |
55 | 54 | ||
56 | // Writing unaligned 16 or 32 bit data is handled automatically when | 55 | // Writing unaligned 16 or 32 bit data is handled automatically when |
57 | // this is defined, but at a cost of extra code size. Without this, | 56 | // this is defined, but at a cost of extra code size. Without this, |
@@ -59,286 +58,271 @@ | |||
59 | // absolutely sure all 16 and 32 bit writes will be aligned, you can | 58 | // absolutely sure all 16 and 32 bit writes will be aligned, you can |
60 | // remove the extra unnecessary code. | 59 | // remove the extra unnecessary code. |
61 | // | 60 | // |
62 | #define HANDLE_UNALIGNED_WRITES | 61 | # define HANDLE_UNALIGNED_WRITES |
63 | 62 | ||
64 | // Minimum EEPROM Endurance | 63 | // Minimum EEPROM Endurance |
65 | // ------------------------ | 64 | // ------------------------ |
66 | #if (EEPROM_SIZE == 2048) // 35000 writes/byte or 70000 writes/word | 65 | # if (EEPROM_SIZE == 2048) // 35000 writes/byte or 70000 writes/word |
67 | #define EEESIZE 0x33 | 66 | # define EEESIZE 0x33 |
68 | #elif (EEPROM_SIZE == 1024) // 75000 writes/byte or 150000 writes/word | 67 | # elif (EEPROM_SIZE == 1024) // 75000 writes/byte or 150000 writes/word |
69 | #define EEESIZE 0x34 | 68 | # define EEESIZE 0x34 |
70 | #elif (EEPROM_SIZE == 512) // 155000 writes/byte or 310000 writes/word | 69 | # elif (EEPROM_SIZE == 512) // 155000 writes/byte or 310000 writes/word |
71 | #define EEESIZE 0x35 | 70 | # define EEESIZE 0x35 |
72 | #elif (EEPROM_SIZE == 256) // 315000 writes/byte or 630000 writes/word | 71 | # elif (EEPROM_SIZE == 256) // 315000 writes/byte or 630000 writes/word |
73 | #define EEESIZE 0x36 | 72 | # define EEESIZE 0x36 |
74 | #elif (EEPROM_SIZE == 128) // 635000 writes/byte or 1270000 writes/word | 73 | # elif (EEPROM_SIZE == 128) // 635000 writes/byte or 1270000 writes/word |
75 | #define EEESIZE 0x37 | 74 | # define EEESIZE 0x37 |
76 | #elif (EEPROM_SIZE == 64) // 1275000 writes/byte or 2550000 writes/word | 75 | # elif (EEPROM_SIZE == 64) // 1275000 writes/byte or 2550000 writes/word |
77 | #define EEESIZE 0x38 | 76 | # define EEESIZE 0x38 |
78 | #elif (EEPROM_SIZE == 32) // 2555000 writes/byte or 5110000 writes/word | 77 | # elif (EEPROM_SIZE == 32) // 2555000 writes/byte or 5110000 writes/word |
79 | #define EEESIZE 0x39 | 78 | # define EEESIZE 0x39 |
80 | #endif | 79 | # endif |
81 | 80 | ||
82 | /** \brief eeprom initialization | 81 | /** \brief eeprom initialization |
83 | * | 82 | * |
84 | * FIXME: needs doc | 83 | * FIXME: needs doc |
85 | */ | 84 | */ |
86 | void eeprom_initialize(void) | 85 | void eeprom_initialize(void) { |
87 | { | 86 | uint32_t count = 0; |
88 | uint32_t count=0; | 87 | uint16_t do_flash_cmd[] = {0xf06f, 0x037f, 0x7003, 0x7803, 0xf013, 0x0f80, 0xd0fb, 0x4770}; |
89 | uint16_t do_flash_cmd[] = { | 88 | uint8_t status; |
90 | 0xf06f, 0x037f, 0x7003, 0x7803, | 89 | |
91 | 0xf013, 0x0f80, 0xd0fb, 0x4770}; | 90 | if (FTFL->FCNFG & FTFL_FCNFG_RAMRDY) { |
92 | uint8_t status; | 91 | // FlexRAM is configured as traditional RAM |
93 | 92 | // We need to reconfigure for EEPROM usage | |
94 | if (FTFL->FCNFG & FTFL_FCNFG_RAMRDY) { | 93 | FTFL->FCCOB0 = 0x80; // PGMPART = Program Partition Command |
95 | // FlexRAM is configured as traditional RAM | 94 | FTFL->FCCOB4 = EEESIZE; // EEPROM Size |
96 | // We need to reconfigure for EEPROM usage | 95 | FTFL->FCCOB5 = 0x03; // 0K for Dataflash, 32K for EEPROM backup |
97 | FTFL->FCCOB0 = 0x80; // PGMPART = Program Partition Command | 96 | __disable_irq(); |
98 | FTFL->FCCOB4 = EEESIZE; // EEPROM Size | 97 | // do_flash_cmd() must execute from RAM. Luckily the C syntax is simple... |
99 | FTFL->FCCOB5 = 0x03; // 0K for Dataflash, 32K for EEPROM backup | 98 | (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFL->FSTAT)); |
100 | __disable_irq(); | 99 | __enable_irq(); |
101 | // do_flash_cmd() must execute from RAM. Luckily the C syntax is simple... | 100 | status = FTFL->FSTAT; |
102 | (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFL->FSTAT)); | 101 | if (status & (FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL)) { |
103 | __enable_irq(); | 102 | FTFL->FSTAT = (status & (FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL)); |
104 | status = FTFL->FSTAT; | 103 | return; // error |
105 | if (status & (FTFL_FSTAT_RDCOLERR|FTFL_FSTAT_ACCERR|FTFL_FSTAT_FPVIOL)) { | 104 | } |
106 | FTFL->FSTAT = (status & (FTFL_FSTAT_RDCOLERR|FTFL_FSTAT_ACCERR|FTFL_FSTAT_FPVIOL)); | 105 | } |
107 | return; // error | 106 | // wait for eeprom to become ready (is this really necessary?) |
108 | } | 107 | while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) { |
109 | } | 108 | if (++count > 20000) break; |
110 | // wait for eeprom to become ready (is this really necessary?) | 109 | } |
111 | while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) { | 110 | } |
112 | if (++count > 20000) break; | 111 | |
113 | } | 112 | # define FlexRAM ((uint8_t *)0x14000000) |
114 | } | ||
115 | |||
116 | #define FlexRAM ((uint8_t *)0x14000000) | ||
117 | 113 | ||
118 | /** \brief eeprom read byte | 114 | /** \brief eeprom read byte |
119 | * | 115 | * |
120 | * FIXME: needs doc | 116 | * FIXME: needs doc |
121 | */ | 117 | */ |
122 | uint8_t eeprom_read_byte(const uint8_t *addr) | 118 | uint8_t eeprom_read_byte(const uint8_t *addr) { |
123 | { | 119 | uint32_t offset = (uint32_t)addr; |
124 | uint32_t offset = (uint32_t)addr; | 120 | if (offset >= EEPROM_SIZE) return 0; |
125 | if (offset >= EEPROM_SIZE) return 0; | 121 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); |
126 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); | 122 | return FlexRAM[offset]; |
127 | return FlexRAM[offset]; | ||
128 | } | 123 | } |
129 | 124 | ||
130 | /** \brief eeprom read word | 125 | /** \brief eeprom read word |
131 | * | 126 | * |
132 | * FIXME: needs doc | 127 | * FIXME: needs doc |
133 | */ | 128 | */ |
134 | uint16_t eeprom_read_word(const uint16_t *addr) | 129 | uint16_t eeprom_read_word(const uint16_t *addr) { |
135 | { | 130 | uint32_t offset = (uint32_t)addr; |
136 | uint32_t offset = (uint32_t)addr; | 131 | if (offset >= EEPROM_SIZE - 1) return 0; |
137 | if (offset >= EEPROM_SIZE-1) return 0; | 132 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); |
138 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); | 133 | return *(uint16_t *)(&FlexRAM[offset]); |
139 | return *(uint16_t *)(&FlexRAM[offset]); | ||
140 | } | 134 | } |
141 | 135 | ||
142 | /** \brief eeprom read dword | 136 | /** \brief eeprom read dword |
143 | * | 137 | * |
144 | * FIXME: needs doc | 138 | * FIXME: needs doc |
145 | */ | 139 | */ |
146 | uint32_t eeprom_read_dword(const uint32_t *addr) | 140 | uint32_t eeprom_read_dword(const uint32_t *addr) { |
147 | { | 141 | uint32_t offset = (uint32_t)addr; |
148 | uint32_t offset = (uint32_t)addr; | 142 | if (offset >= EEPROM_SIZE - 3) return 0; |
149 | if (offset >= EEPROM_SIZE-3) return 0; | 143 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); |
150 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); | 144 | return *(uint32_t *)(&FlexRAM[offset]); |
151 | return *(uint32_t *)(&FlexRAM[offset]); | ||
152 | } | 145 | } |
153 | 146 | ||
154 | /** \brief eeprom read block | 147 | /** \brief eeprom read block |
155 | * | 148 | * |
156 | * FIXME: needs doc | 149 | * FIXME: needs doc |
157 | */ | 150 | */ |
158 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) | 151 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { |
159 | { | 152 | uint32_t offset = (uint32_t)addr; |
160 | uint32_t offset = (uint32_t)addr; | 153 | uint8_t *dest = (uint8_t *)buf; |
161 | uint8_t *dest = (uint8_t *)buf; | 154 | uint32_t end = offset + len; |
162 | uint32_t end = offset + len; | 155 | |
163 | 156 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); | |
164 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); | 157 | if (end > EEPROM_SIZE) end = EEPROM_SIZE; |
165 | if (end > EEPROM_SIZE) end = EEPROM_SIZE; | 158 | while (offset < end) { |
166 | while (offset < end) { | 159 | *dest++ = FlexRAM[offset++]; |
167 | *dest++ = FlexRAM[offset++]; | 160 | } |
168 | } | ||
169 | } | 161 | } |
170 | 162 | ||
171 | /** \brief eeprom is ready | 163 | /** \brief eeprom is ready |
172 | * | 164 | * |
173 | * FIXME: needs doc | 165 | * FIXME: needs doc |
174 | */ | 166 | */ |
175 | int eeprom_is_ready(void) | 167 | int eeprom_is_ready(void) { return (FTFL->FCNFG & FTFL_FCNFG_EEERDY) ? 1 : 0; } |
176 | { | ||
177 | return (FTFL->FCNFG & FTFL_FCNFG_EEERDY) ? 1 : 0; | ||
178 | } | ||
179 | 168 | ||
180 | /** \brief flexram wait | 169 | /** \brief flexram wait |
181 | * | 170 | * |
182 | * FIXME: needs doc | 171 | * FIXME: needs doc |
183 | */ | 172 | */ |
184 | static void flexram_wait(void) | 173 | static void flexram_wait(void) { |
185 | { | 174 | while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) { |
186 | while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) { | 175 | // TODO: timeout |
187 | // TODO: timeout | 176 | } |
188 | } | ||
189 | } | 177 | } |
190 | 178 | ||
191 | /** \brief eeprom_write_byte | 179 | /** \brief eeprom_write_byte |
192 | * | 180 | * |
193 | * FIXME: needs doc | 181 | * FIXME: needs doc |
194 | */ | 182 | */ |
195 | void eeprom_write_byte(uint8_t *addr, uint8_t value) | 183 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { |
196 | { | 184 | uint32_t offset = (uint32_t)addr; |
197 | uint32_t offset = (uint32_t)addr; | ||
198 | 185 | ||
199 | if (offset >= EEPROM_SIZE) return; | 186 | if (offset >= EEPROM_SIZE) return; |
200 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); | 187 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); |
201 | if (FlexRAM[offset] != value) { | 188 | if (FlexRAM[offset] != value) { |
202 | FlexRAM[offset] = value; | 189 | FlexRAM[offset] = value; |
203 | flexram_wait(); | 190 | flexram_wait(); |
204 | } | 191 | } |
205 | } | 192 | } |
206 | 193 | ||
207 | /** \brief eeprom write word | 194 | /** \brief eeprom write word |
208 | * | 195 | * |
209 | * FIXME: needs doc | 196 | * FIXME: needs doc |
210 | */ | 197 | */ |
211 | void eeprom_write_word(uint16_t *addr, uint16_t value) | 198 | void eeprom_write_word(uint16_t *addr, uint16_t value) { |
212 | { | 199 | uint32_t offset = (uint32_t)addr; |
213 | uint32_t offset = (uint32_t)addr; | 200 | |
214 | 201 | if (offset >= EEPROM_SIZE - 1) return; | |
215 | if (offset >= EEPROM_SIZE-1) return; | 202 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); |
216 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); | 203 | # ifdef HANDLE_UNALIGNED_WRITES |
217 | #ifdef HANDLE_UNALIGNED_WRITES | 204 | if ((offset & 1) == 0) { |
218 | if ((offset & 1) == 0) { | 205 | # endif |
219 | #endif | 206 | if (*(uint16_t *)(&FlexRAM[offset]) != value) { |
220 | if (*(uint16_t *)(&FlexRAM[offset]) != value) { | 207 | *(uint16_t *)(&FlexRAM[offset]) = value; |
221 | *(uint16_t *)(&FlexRAM[offset]) = value; | 208 | flexram_wait(); |
222 | flexram_wait(); | 209 | } |
223 | } | 210 | # ifdef HANDLE_UNALIGNED_WRITES |
224 | #ifdef HANDLE_UNALIGNED_WRITES | 211 | } else { |
225 | } else { | 212 | if (FlexRAM[offset] != value) { |
226 | if (FlexRAM[offset] != value) { | 213 | FlexRAM[offset] = value; |
227 | FlexRAM[offset] = value; | 214 | flexram_wait(); |
228 | flexram_wait(); | 215 | } |
229 | } | 216 | if (FlexRAM[offset + 1] != (value >> 8)) { |
230 | if (FlexRAM[offset + 1] != (value >> 8)) { | 217 | FlexRAM[offset + 1] = value >> 8; |
231 | FlexRAM[offset + 1] = value >> 8; | 218 | flexram_wait(); |
232 | flexram_wait(); | 219 | } |
233 | } | 220 | } |
234 | } | 221 | # endif |
235 | #endif | ||
236 | } | 222 | } |
237 | 223 | ||
238 | /** \brief eeprom write dword | 224 | /** \brief eeprom write dword |
239 | * | 225 | * |
240 | * FIXME: needs doc | 226 | * FIXME: needs doc |
241 | */ | 227 | */ |
242 | void eeprom_write_dword(uint32_t *addr, uint32_t value) | 228 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { |
243 | { | 229 | uint32_t offset = (uint32_t)addr; |
244 | uint32_t offset = (uint32_t)addr; | 230 | |
245 | 231 | if (offset >= EEPROM_SIZE - 3) return; | |
246 | if (offset >= EEPROM_SIZE-3) return; | 232 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); |
247 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); | 233 | # ifdef HANDLE_UNALIGNED_WRITES |
248 | #ifdef HANDLE_UNALIGNED_WRITES | 234 | switch (offset & 3) { |
249 | switch (offset & 3) { | 235 | case 0: |
250 | case 0: | 236 | # endif |
251 | #endif | 237 | if (*(uint32_t *)(&FlexRAM[offset]) != value) { |
252 | if (*(uint32_t *)(&FlexRAM[offset]) != value) { | 238 | *(uint32_t *)(&FlexRAM[offset]) = value; |
253 | *(uint32_t *)(&FlexRAM[offset]) = value; | 239 | flexram_wait(); |
254 | flexram_wait(); | 240 | } |
255 | } | 241 | return; |
256 | return; | 242 | # ifdef HANDLE_UNALIGNED_WRITES |
257 | #ifdef HANDLE_UNALIGNED_WRITES | 243 | case 2: |
258 | case 2: | 244 | if (*(uint16_t *)(&FlexRAM[offset]) != value) { |
259 | if (*(uint16_t *)(&FlexRAM[offset]) != value) { | 245 | *(uint16_t *)(&FlexRAM[offset]) = value; |
260 | *(uint16_t *)(&FlexRAM[offset]) = value; | 246 | flexram_wait(); |
261 | flexram_wait(); | 247 | } |
262 | } | 248 | if (*(uint16_t *)(&FlexRAM[offset + 2]) != (value >> 16)) { |
263 | if (*(uint16_t *)(&FlexRAM[offset + 2]) != (value >> 16)) { | 249 | *(uint16_t *)(&FlexRAM[offset + 2]) = value >> 16; |
264 | *(uint16_t *)(&FlexRAM[offset + 2]) = value >> 16; | 250 | flexram_wait(); |
265 | flexram_wait(); | 251 | } |
266 | } | 252 | return; |
267 | return; | 253 | default: |
268 | default: | 254 | if (FlexRAM[offset] != value) { |
269 | if (FlexRAM[offset] != value) { | 255 | FlexRAM[offset] = value; |
270 | FlexRAM[offset] = value; | 256 | flexram_wait(); |
271 | flexram_wait(); | 257 | } |
272 | } | 258 | if (*(uint16_t *)(&FlexRAM[offset + 1]) != (value >> 8)) { |
273 | if (*(uint16_t *)(&FlexRAM[offset + 1]) != (value >> 8)) { | 259 | *(uint16_t *)(&FlexRAM[offset + 1]) = value >> 8; |
274 | *(uint16_t *)(&FlexRAM[offset + 1]) = value >> 8; | 260 | flexram_wait(); |
275 | flexram_wait(); | 261 | } |
276 | } | 262 | if (FlexRAM[offset + 3] != (value >> 24)) { |
277 | if (FlexRAM[offset + 3] != (value >> 24)) { | 263 | FlexRAM[offset + 3] = value >> 24; |
278 | FlexRAM[offset + 3] = value >> 24; | 264 | flexram_wait(); |
279 | flexram_wait(); | 265 | } |
280 | } | 266 | } |
281 | } | 267 | # endif |
282 | #endif | ||
283 | } | 268 | } |
284 | 269 | ||
285 | /** \brief eeprom write block | 270 | /** \brief eeprom write block |
286 | * | 271 | * |
287 | * FIXME: needs doc | 272 | * FIXME: needs doc |
288 | */ | 273 | */ |
289 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) | 274 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { |
290 | { | 275 | uint32_t offset = (uint32_t)addr; |
291 | uint32_t offset = (uint32_t)addr; | 276 | const uint8_t *src = (const uint8_t *)buf; |
292 | const uint8_t *src = (const uint8_t *)buf; | 277 | |
293 | 278 | if (offset >= EEPROM_SIZE) return; | |
294 | if (offset >= EEPROM_SIZE) return; | 279 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); |
295 | if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize(); | 280 | if (len >= EEPROM_SIZE) len = EEPROM_SIZE; |
296 | if (len >= EEPROM_SIZE) len = EEPROM_SIZE; | 281 | if (offset + len >= EEPROM_SIZE) len = EEPROM_SIZE - offset; |
297 | if (offset + len >= EEPROM_SIZE) len = EEPROM_SIZE - offset; | 282 | while (len > 0) { |
298 | while (len > 0) { | 283 | uint32_t lsb = offset & 3; |
299 | uint32_t lsb = offset & 3; | 284 | if (lsb == 0 && len >= 4) { |
300 | if (lsb == 0 && len >= 4) { | 285 | // write aligned 32 bits |
301 | // write aligned 32 bits | 286 | uint32_t val32; |
302 | uint32_t val32; | 287 | val32 = *src++; |
303 | val32 = *src++; | 288 | val32 |= (*src++ << 8); |
304 | val32 |= (*src++ << 8); | 289 | val32 |= (*src++ << 16); |
305 | val32 |= (*src++ << 16); | 290 | val32 |= (*src++ << 24); |
306 | val32 |= (*src++ << 24); | 291 | if (*(uint32_t *)(&FlexRAM[offset]) != val32) { |
307 | if (*(uint32_t *)(&FlexRAM[offset]) != val32) { | 292 | *(uint32_t *)(&FlexRAM[offset]) = val32; |
308 | *(uint32_t *)(&FlexRAM[offset]) = val32; | 293 | flexram_wait(); |
309 | flexram_wait(); | 294 | } |
310 | } | 295 | offset += 4; |
311 | offset += 4; | 296 | len -= 4; |
312 | len -= 4; | 297 | } else if ((lsb == 0 || lsb == 2) && len >= 2) { |
313 | } else if ((lsb == 0 || lsb == 2) && len >= 2) { | 298 | // write aligned 16 bits |
314 | // write aligned 16 bits | 299 | uint16_t val16; |
315 | uint16_t val16; | 300 | val16 = *src++; |
316 | val16 = *src++; | 301 | val16 |= (*src++ << 8); |
317 | val16 |= (*src++ << 8); | 302 | if (*(uint16_t *)(&FlexRAM[offset]) != val16) { |
318 | if (*(uint16_t *)(&FlexRAM[offset]) != val16) { | 303 | *(uint16_t *)(&FlexRAM[offset]) = val16; |
319 | *(uint16_t *)(&FlexRAM[offset]) = val16; | 304 | flexram_wait(); |
320 | flexram_wait(); | 305 | } |
321 | } | 306 | offset += 2; |
322 | offset += 2; | 307 | len -= 2; |
323 | len -= 2; | 308 | } else { |
324 | } else { | 309 | // write 8 bits |
325 | // write 8 bits | 310 | uint8_t val8 = *src++; |
326 | uint8_t val8 = *src++; | 311 | if (FlexRAM[offset] != val8) { |
327 | if (FlexRAM[offset] != val8) { | 312 | FlexRAM[offset] = val8; |
328 | FlexRAM[offset] = val8; | 313 | flexram_wait(); |
329 | flexram_wait(); | 314 | } |
330 | } | 315 | offset++; |
331 | offset++; | 316 | len--; |
332 | len--; | 317 | } |
333 | } | 318 | } |
334 | } | ||
335 | } | 319 | } |
336 | 320 | ||
337 | /* | 321 | /* |
338 | void do_flash_cmd(volatile uint8_t *fstat) | 322 | void do_flash_cmd(volatile uint8_t *fstat) |
339 | { | 323 | { |
340 | *fstat = 0x80; | 324 | *fstat = 0x80; |
341 | while ((*fstat & 0x80) == 0) ; // wait | 325 | while ((*fstat & 0x80) == 0) ; // wait |
342 | } | 326 | } |
343 | 00000000 <do_flash_cmd>: | 327 | 00000000 <do_flash_cmd>: |
344 | 0: f06f 037f mvn.w r3, #127 ; 0x7f | 328 | 0: f06f 037f mvn.w r3, #127 ; 0x7f |
@@ -352,128 +336,124 @@ void do_flash_cmd(volatile uint8_t *fstat) | |||
352 | #elif defined(KL2x) /* chip selection */ | 336 | #elif defined(KL2x) /* chip selection */ |
353 | /* Teensy LC (emulated) */ | 337 | /* Teensy LC (emulated) */ |
354 | 338 | ||
355 | #define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) | 339 | # define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) |
356 | 340 | ||
357 | extern uint32_t __eeprom_workarea_start__; | 341 | extern uint32_t __eeprom_workarea_start__; |
358 | extern uint32_t __eeprom_workarea_end__; | 342 | extern uint32_t __eeprom_workarea_end__; |
359 | 343 | ||
360 | #define EEPROM_SIZE 128 | 344 | # define EEPROM_SIZE 128 |
361 | 345 | ||
362 | static uint32_t flashend = 0; | 346 | static uint32_t flashend = 0; |
363 | 347 | ||
364 | void eeprom_initialize(void) | 348 | void eeprom_initialize(void) { |
365 | { | 349 | const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__); |
366 | const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__); | ||
367 | 350 | ||
368 | do { | 351 | do { |
369 | if (*p++ == 0xFFFF) { | 352 | if (*p++ == 0xFFFF) { |
370 | flashend = (uint32_t)(p - 2); | 353 | flashend = (uint32_t)(p - 2); |
371 | return; | 354 | return; |
372 | } | 355 | } |
373 | } while (p < (uint16_t *)SYMVAL(__eeprom_workarea_end__)); | 356 | } while (p < (uint16_t *)SYMVAL(__eeprom_workarea_end__)); |
374 | flashend = (uint32_t)((uint16_t *)SYMVAL(__eeprom_workarea_end__) - 1); | 357 | flashend = (uint32_t)((uint16_t *)SYMVAL(__eeprom_workarea_end__) - 1); |
375 | } | 358 | } |
376 | 359 | ||
377 | uint8_t eeprom_read_byte(const uint8_t *addr) | 360 | uint8_t eeprom_read_byte(const uint8_t *addr) { |
378 | { | 361 | uint32_t offset = (uint32_t)addr; |
379 | uint32_t offset = (uint32_t)addr; | 362 | const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__); |
380 | const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__); | 363 | const uint16_t *end = (const uint16_t *)((uint32_t)flashend); |
381 | const uint16_t *end = (const uint16_t *)((uint32_t)flashend); | 364 | uint16_t val; |
382 | uint16_t val; | 365 | uint8_t data = 0xFF; |
383 | uint8_t data=0xFF; | 366 | |
384 | 367 | if (!end) { | |
385 | if (!end) { | 368 | eeprom_initialize(); |
386 | eeprom_initialize(); | 369 | end = (const uint16_t *)((uint32_t)flashend); |
387 | end = (const uint16_t *)((uint32_t)flashend); | 370 | } |
388 | } | 371 | if (offset < EEPROM_SIZE) { |
389 | if (offset < EEPROM_SIZE) { | 372 | while (p <= end) { |
390 | while (p <= end) { | 373 | val = *p++; |
391 | val = *p++; | 374 | if ((val & 255) == offset) data = val >> 8; |
392 | if ((val & 255) == offset) data = val >> 8; | 375 | } |
393 | } | 376 | } |
394 | } | 377 | return data; |
395 | return data; | 378 | } |
396 | } | 379 | |
397 | 380 | static void flash_write(const uint16_t *code, uint32_t addr, uint32_t data) { | |
398 | static void flash_write(const uint16_t *code, uint32_t addr, uint32_t data) | 381 | // with great power comes great responsibility.... |
399 | { | 382 | uint32_t stat; |
400 | // with great power comes great responsibility.... | 383 | *(uint32_t *)&(FTFA->FCCOB3) = 0x06000000 | (addr & 0x00FFFFFC); |
401 | uint32_t stat; | 384 | *(uint32_t *)&(FTFA->FCCOB7) = data; |
402 | *(uint32_t *)&(FTFA->FCCOB3) = 0x06000000 | (addr & 0x00FFFFFC); | 385 | __disable_irq(); |
403 | *(uint32_t *)&(FTFA->FCCOB7) = data; | 386 | (*((void (*)(volatile uint8_t *))((uint32_t)code | 1)))(&(FTFA->FSTAT)); |
404 | __disable_irq(); | 387 | __enable_irq(); |
405 | (*((void (*)(volatile uint8_t *))((uint32_t)code | 1)))(&(FTFA->FSTAT)); | 388 | stat = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR | FTFA_FSTAT_ACCERR | FTFA_FSTAT_FPVIOL); |
406 | __enable_irq(); | 389 | if (stat) { |
407 | stat = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR|FTFA_FSTAT_ACCERR|FTFA_FSTAT_FPVIOL); | 390 | FTFA->FSTAT = stat; |
408 | if (stat) { | 391 | } |
409 | FTFA->FSTAT = stat; | 392 | MCM->PLACR |= MCM_PLACR_CFCC; |
410 | } | 393 | } |
411 | MCM->PLACR |= MCM_PLACR_CFCC; | 394 | |
412 | } | 395 | void eeprom_write_byte(uint8_t *addr, uint8_t data) { |
413 | 396 | uint32_t offset = (uint32_t)addr; | |
414 | void eeprom_write_byte(uint8_t *addr, uint8_t data) | 397 | const uint16_t *p, *end = (const uint16_t *)((uint32_t)flashend); |
415 | { | 398 | uint32_t i, val, flashaddr; |
416 | uint32_t offset = (uint32_t)addr; | 399 | uint16_t do_flash_cmd[] = {0x2380, 0x7003, 0x7803, 0xb25b, 0x2b00, 0xdafb, 0x4770}; |
417 | const uint16_t *p, *end = (const uint16_t *)((uint32_t)flashend); | 400 | uint8_t buf[EEPROM_SIZE]; |
418 | uint32_t i, val, flashaddr; | 401 | |
419 | uint16_t do_flash_cmd[] = { | 402 | if (offset >= EEPROM_SIZE) return; |
420 | 0x2380, 0x7003, 0x7803, 0xb25b, 0x2b00, 0xdafb, 0x4770}; | 403 | if (!end) { |
421 | uint8_t buf[EEPROM_SIZE]; | 404 | eeprom_initialize(); |
422 | 405 | end = (const uint16_t *)((uint32_t)flashend); | |
423 | if (offset >= EEPROM_SIZE) return; | 406 | } |
424 | if (!end) { | 407 | if (++end < (uint16_t *)SYMVAL(__eeprom_workarea_end__)) { |
425 | eeprom_initialize(); | 408 | val = (data << 8) | offset; |
426 | end = (const uint16_t *)((uint32_t)flashend); | 409 | flashaddr = (uint32_t)end; |
427 | } | 410 | flashend = flashaddr; |
428 | if (++end < (uint16_t *)SYMVAL(__eeprom_workarea_end__)) { | 411 | if ((flashaddr & 2) == 0) { |
429 | val = (data << 8) | offset; | 412 | val |= 0xFFFF0000; |
430 | flashaddr = (uint32_t)end; | 413 | } else { |
431 | flashend = flashaddr; | 414 | val <<= 16; |
432 | if ((flashaddr & 2) == 0) { | 415 | val |= 0x0000FFFF; |
433 | val |= 0xFFFF0000; | 416 | } |
434 | } else { | 417 | flash_write(do_flash_cmd, flashaddr, val); |
435 | val <<= 16; | 418 | } else { |
436 | val |= 0x0000FFFF; | 419 | for (i = 0; i < EEPROM_SIZE; i++) { |
437 | } | 420 | buf[i] = 0xFF; |
438 | flash_write(do_flash_cmd, flashaddr, val); | 421 | } |
439 | } else { | 422 | val = 0; |
440 | for (i=0; i < EEPROM_SIZE; i++) { | 423 | for (p = (uint16_t *)SYMVAL(__eeprom_workarea_start__); p < (uint16_t *)SYMVAL(__eeprom_workarea_end__); p++) { |
441 | buf[i] = 0xFF; | 424 | val = *p; |
442 | } | 425 | if ((val & 255) < EEPROM_SIZE) { |
443 | val = 0; | 426 | buf[val & 255] = val >> 8; |
444 | for (p = (uint16_t *)SYMVAL(__eeprom_workarea_start__); p < (uint16_t *)SYMVAL(__eeprom_workarea_end__); p++) { | 427 | } |
445 | val = *p; | 428 | } |
446 | if ((val & 255) < EEPROM_SIZE) { | 429 | buf[offset] = data; |
447 | buf[val & 255] = val >> 8; | 430 | for (flashaddr = (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__); flashaddr < (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_end__); flashaddr += 1024) { |
448 | } | 431 | *(uint32_t *)&(FTFA->FCCOB3) = 0x09000000 | flashaddr; |
449 | } | 432 | __disable_irq(); |
450 | buf[offset] = data; | 433 | (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFA->FSTAT)); |
451 | for (flashaddr=(uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__); flashaddr < (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_end__); flashaddr += 1024) { | 434 | __enable_irq(); |
452 | *(uint32_t *)&(FTFA->FCCOB3) = 0x09000000 | flashaddr; | 435 | val = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR | FTFA_FSTAT_ACCERR | FTFA_FSTAT_FPVIOL); |
453 | __disable_irq(); | 436 | ; |
454 | (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFA->FSTAT)); | 437 | if (val) FTFA->FSTAT = val; |
455 | __enable_irq(); | 438 | MCM->PLACR |= MCM_PLACR_CFCC; |
456 | val = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR|FTFA_FSTAT_ACCERR|FTFA_FSTAT_FPVIOL);; | 439 | } |
457 | if (val) FTFA->FSTAT = val; | 440 | flashaddr = (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__); |
458 | MCM->PLACR |= MCM_PLACR_CFCC; | 441 | for (i = 0; i < EEPROM_SIZE; i++) { |
459 | } | 442 | if (buf[i] == 0xFF) continue; |
460 | flashaddr=(uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__); | 443 | if ((flashaddr & 2) == 0) { |
461 | for (i=0; i < EEPROM_SIZE; i++) { | 444 | val = (buf[i] << 8) | i; |
462 | if (buf[i] == 0xFF) continue; | 445 | } else { |
463 | if ((flashaddr & 2) == 0) { | 446 | val = val | (buf[i] << 24) | (i << 16); |
464 | val = (buf[i] << 8) | i; | 447 | flash_write(do_flash_cmd, flashaddr, val); |
465 | } else { | 448 | } |
466 | val = val | (buf[i] << 24) | (i << 16); | 449 | flashaddr += 2; |
467 | flash_write(do_flash_cmd, flashaddr, val); | 450 | } |
468 | } | 451 | flashend = flashaddr; |
469 | flashaddr += 2; | 452 | if ((flashaddr & 2)) { |
470 | } | 453 | val |= 0xFFFF0000; |
471 | flashend = flashaddr; | 454 | flash_write(do_flash_cmd, flashaddr, val); |
472 | if ((flashaddr & 2)) { | 455 | } |
473 | val |= 0xFFFF0000; | 456 | } |
474 | flash_write(do_flash_cmd, flashaddr, val); | ||
475 | } | ||
476 | } | ||
477 | } | 457 | } |
478 | 458 | ||
479 | /* | 459 | /* |
@@ -492,141 +472,127 @@ void do_flash_cmd(volatile uint8_t *fstat) | |||
492 | c: 4770 bx lr | 472 | c: 4770 bx lr |
493 | */ | 473 | */ |
494 | 474 | ||
495 | 475 | uint16_t eeprom_read_word(const uint16_t *addr) { | |
496 | uint16_t eeprom_read_word(const uint16_t *addr) | 476 | const uint8_t *p = (const uint8_t *)addr; |
497 | { | 477 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8); |
498 | const uint8_t *p = (const uint8_t *)addr; | ||
499 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8); | ||
500 | } | 478 | } |
501 | 479 | ||
502 | uint32_t eeprom_read_dword(const uint32_t *addr) | 480 | uint32_t eeprom_read_dword(const uint32_t *addr) { |
503 | { | 481 | const uint8_t *p = (const uint8_t *)addr; |
504 | const uint8_t *p = (const uint8_t *)addr; | 482 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24); |
505 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8) | ||
506 | | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24); | ||
507 | } | 483 | } |
508 | 484 | ||
509 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) | 485 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { |
510 | { | 486 | const uint8_t *p = (const uint8_t *)addr; |
511 | const uint8_t *p = (const uint8_t *)addr; | 487 | uint8_t * dest = (uint8_t *)buf; |
512 | uint8_t *dest = (uint8_t *)buf; | 488 | while (len--) { |
513 | while (len--) { | 489 | *dest++ = eeprom_read_byte(p++); |
514 | *dest++ = eeprom_read_byte(p++); | 490 | } |
515 | } | ||
516 | } | 491 | } |
517 | 492 | ||
518 | int eeprom_is_ready(void) | 493 | int eeprom_is_ready(void) { return 1; } |
519 | { | ||
520 | return 1; | ||
521 | } | ||
522 | 494 | ||
523 | void eeprom_write_word(uint16_t *addr, uint16_t value) | 495 | void eeprom_write_word(uint16_t *addr, uint16_t value) { |
524 | { | 496 | uint8_t *p = (uint8_t *)addr; |
525 | uint8_t *p = (uint8_t *)addr; | 497 | eeprom_write_byte(p++, value); |
526 | eeprom_write_byte(p++, value); | 498 | eeprom_write_byte(p, value >> 8); |
527 | eeprom_write_byte(p, value >> 8); | ||
528 | } | 499 | } |
529 | 500 | ||
530 | void eeprom_write_dword(uint32_t *addr, uint32_t value) | 501 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { |
531 | { | 502 | uint8_t *p = (uint8_t *)addr; |
532 | uint8_t *p = (uint8_t *)addr; | 503 | eeprom_write_byte(p++, value); |
533 | eeprom_write_byte(p++, value); | 504 | eeprom_write_byte(p++, value >> 8); |
534 | eeprom_write_byte(p++, value >> 8); | 505 | eeprom_write_byte(p++, value >> 16); |
535 | eeprom_write_byte(p++, value >> 16); | 506 | eeprom_write_byte(p, value >> 24); |
536 | eeprom_write_byte(p, value >> 24); | ||
537 | } | 507 | } |
538 | 508 | ||
539 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) | 509 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { |
540 | { | 510 | uint8_t * p = (uint8_t *)addr; |
541 | uint8_t *p = (uint8_t *)addr; | 511 | const uint8_t *src = (const uint8_t *)buf; |
542 | const uint8_t *src = (const uint8_t *)buf; | 512 | while (len--) { |
543 | while (len--) { | 513 | eeprom_write_byte(p++, *src++); |
544 | eeprom_write_byte(p++, *src++); | 514 | } |
545 | } | ||
546 | } | 515 | } |
547 | 516 | ||
548 | #else | 517 | #else |
549 | // No EEPROM supported, so emulate it | 518 | // No EEPROM supported, so emulate it |
550 | 519 | ||
551 | #define EEPROM_SIZE 32 | 520 | # define EEPROM_SIZE 32 |
552 | static uint8_t buffer[EEPROM_SIZE]; | 521 | static uint8_t buffer[EEPROM_SIZE]; |
553 | 522 | ||
554 | uint8_t eeprom_read_byte(const uint8_t *addr) { | 523 | uint8_t eeprom_read_byte(const uint8_t *addr) { |
555 | uint32_t offset = (uint32_t)addr; | 524 | uint32_t offset = (uint32_t)addr; |
556 | return buffer[offset]; | 525 | return buffer[offset]; |
557 | } | 526 | } |
558 | 527 | ||
559 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { | 528 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { |
560 | uint32_t offset = (uint32_t)addr; | 529 | uint32_t offset = (uint32_t)addr; |
561 | buffer[offset] = value; | 530 | buffer[offset] = value; |
562 | } | 531 | } |
563 | 532 | ||
564 | uint16_t eeprom_read_word(const uint16_t *addr) { | 533 | uint16_t eeprom_read_word(const uint16_t *addr) { |
565 | const uint8_t *p = (const uint8_t *)addr; | 534 | const uint8_t *p = (const uint8_t *)addr; |
566 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8); | 535 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8); |
567 | } | 536 | } |
568 | 537 | ||
569 | uint32_t eeprom_read_dword(const uint32_t *addr) { | 538 | uint32_t eeprom_read_dword(const uint32_t *addr) { |
570 | const uint8_t *p = (const uint8_t *)addr; | 539 | const uint8_t *p = (const uint8_t *)addr; |
571 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8) | 540 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24); |
572 | | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24); | ||
573 | } | 541 | } |
574 | 542 | ||
575 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { | 543 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { |
576 | const uint8_t *p = (const uint8_t *)addr; | 544 | const uint8_t *p = (const uint8_t *)addr; |
577 | uint8_t *dest = (uint8_t *)buf; | 545 | uint8_t * dest = (uint8_t *)buf; |
578 | while (len--) { | 546 | while (len--) { |
579 | *dest++ = eeprom_read_byte(p++); | 547 | *dest++ = eeprom_read_byte(p++); |
580 | } | 548 | } |
581 | } | 549 | } |
582 | 550 | ||
583 | void eeprom_write_word(uint16_t *addr, uint16_t value) { | 551 | void eeprom_write_word(uint16_t *addr, uint16_t value) { |
584 | uint8_t *p = (uint8_t *)addr; | 552 | uint8_t *p = (uint8_t *)addr; |
585 | eeprom_write_byte(p++, value); | 553 | eeprom_write_byte(p++, value); |
586 | eeprom_write_byte(p, value >> 8); | 554 | eeprom_write_byte(p, value >> 8); |
587 | } | 555 | } |
588 | 556 | ||
589 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { | 557 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { |
590 | uint8_t *p = (uint8_t *)addr; | 558 | uint8_t *p = (uint8_t *)addr; |
591 | eeprom_write_byte(p++, value); | 559 | eeprom_write_byte(p++, value); |
592 | eeprom_write_byte(p++, value >> 8); | 560 | eeprom_write_byte(p++, value >> 8); |
593 | eeprom_write_byte(p++, value >> 16); | 561 | eeprom_write_byte(p++, value >> 16); |
594 | eeprom_write_byte(p, value >> 24); | 562 | eeprom_write_byte(p, value >> 24); |
595 | } | 563 | } |
596 | 564 | ||
597 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { | 565 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { |
598 | uint8_t *p = (uint8_t *)addr; | 566 | uint8_t * p = (uint8_t *)addr; |
599 | const uint8_t *src = (const uint8_t *)buf; | 567 | const uint8_t *src = (const uint8_t *)buf; |
600 | while (len--) { | 568 | while (len--) { |
601 | eeprom_write_byte(p++, *src++); | 569 | eeprom_write_byte(p++, *src++); |
602 | } | 570 | } |
603 | } | 571 | } |
604 | 572 | ||
605 | #endif /* chip selection */ | 573 | #endif /* chip selection */ |
606 | // The update functions just calls write for now, but could probably be optimized | 574 | // The update functions just calls write for now, but could probably be optimized |
607 | 575 | ||
608 | void eeprom_update_byte(uint8_t *addr, uint8_t value) { | 576 | void eeprom_update_byte(uint8_t *addr, uint8_t value) { eeprom_write_byte(addr, value); } |
609 | eeprom_write_byte(addr, value); | ||
610 | } | ||
611 | 577 | ||
612 | void eeprom_update_word(uint16_t *addr, uint16_t value) { | 578 | void eeprom_update_word(uint16_t *addr, uint16_t value) { |
613 | uint8_t *p = (uint8_t *)addr; | 579 | uint8_t *p = (uint8_t *)addr; |
614 | eeprom_write_byte(p++, value); | 580 | eeprom_write_byte(p++, value); |
615 | eeprom_write_byte(p, value >> 8); | 581 | eeprom_write_byte(p, value >> 8); |
616 | } | 582 | } |
617 | 583 | ||
618 | void eeprom_update_dword(uint32_t *addr, uint32_t value) { | 584 | void eeprom_update_dword(uint32_t *addr, uint32_t value) { |
619 | uint8_t *p = (uint8_t *)addr; | 585 | uint8_t *p = (uint8_t *)addr; |
620 | eeprom_write_byte(p++, value); | 586 | eeprom_write_byte(p++, value); |
621 | eeprom_write_byte(p++, value >> 8); | 587 | eeprom_write_byte(p++, value >> 8); |
622 | eeprom_write_byte(p++, value >> 16); | 588 | eeprom_write_byte(p++, value >> 16); |
623 | eeprom_write_byte(p, value >> 24); | 589 | eeprom_write_byte(p, value >> 24); |
624 | } | 590 | } |
625 | 591 | ||
626 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { | 592 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { |
627 | uint8_t *p = (uint8_t *)addr; | 593 | uint8_t * p = (uint8_t *)addr; |
628 | const uint8_t *src = (const uint8_t *)buf; | 594 | const uint8_t *src = (const uint8_t *)buf; |
629 | while (len--) { | 595 | while (len--) { |
630 | eeprom_write_byte(p++, *src++); | 596 | eeprom_write_byte(p++, *src++); |
631 | } | 597 | } |
632 | } | 598 | } |
diff --git a/tmk_core/common/chibios/flash_stm32.c b/tmk_core/common/chibios/flash_stm32.c index 832bf3908..e166fc5e6 100755..100644 --- a/tmk_core/common/chibios/flash_stm32.c +++ b/tmk_core/common/chibios/flash_stm32.c | |||
@@ -17,105 +17,95 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | #if defined(EEPROM_EMU_STM32F303xC) | 19 | #if defined(EEPROM_EMU_STM32F303xC) |
20 | #define STM32F303xC | 20 | # define STM32F303xC |
21 | #include "stm32f3xx.h" | 21 | # include "stm32f3xx.h" |
22 | #elif defined(EEPROM_EMU_STM32F103xB) | 22 | #elif defined(EEPROM_EMU_STM32F103xB) |
23 | #define STM32F103xB | 23 | # define STM32F103xB |
24 | #include "stm32f1xx.h" | 24 | # include "stm32f1xx.h" |
25 | #elif defined(EEPROM_EMU_STM32F072xB) | 25 | #elif defined(EEPROM_EMU_STM32F072xB) |
26 | #define STM32F072xB | 26 | # define STM32F072xB |
27 | #include "stm32f0xx.h" | 27 | # include "stm32f0xx.h" |
28 | #else | 28 | #else |
29 | #error "not implemented." | 29 | # error "not implemented." |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | #include "flash_stm32.h" | 32 | #include "flash_stm32.h" |
33 | 33 | ||
34 | #if defined(EEPROM_EMU_STM32F103xB) | 34 | #if defined(EEPROM_EMU_STM32F103xB) |
35 | #define FLASH_SR_WRPERR FLASH_SR_WRPRTERR | 35 | # define FLASH_SR_WRPERR FLASH_SR_WRPRTERR |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | /* Delay definition */ | 38 | /* Delay definition */ |
39 | #define EraseTimeout ((uint32_t)0x00000FFF) | 39 | #define EraseTimeout ((uint32_t)0x00000FFF) |
40 | #define ProgramTimeout ((uint32_t)0x0000001F) | 40 | #define ProgramTimeout ((uint32_t)0x0000001F) |
41 | 41 | ||
42 | #define ASSERT(exp) (void)((0)) | 42 | #define ASSERT(exp) (void)((0)) |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * @brief Inserts a time delay. | 45 | * @brief Inserts a time delay. |
46 | * @param None | 46 | * @param None |
47 | * @retval None | 47 | * @retval None |
48 | */ | 48 | */ |
49 | static void delay(void) | 49 | static void delay(void) { |
50 | { | ||
51 | __IO uint32_t i = 0; | 50 | __IO uint32_t i = 0; |
52 | for(i = 0xFF; i != 0; i--) { } | 51 | for (i = 0xFF; i != 0; i--) { |
52 | } | ||
53 | } | 53 | } |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * @brief Returns the FLASH Status. | 56 | * @brief Returns the FLASH Status. |
57 | * @param None | 57 | * @param None |
58 | * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG, | 58 | * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG, |
59 | * FLASH_ERROR_WRP or FLASH_COMPLETE | 59 | * FLASH_ERROR_WRP or FLASH_COMPLETE |
60 | */ | 60 | */ |
61 | FLASH_Status FLASH_GetStatus(void) | 61 | FLASH_Status FLASH_GetStatus(void) { |
62 | { | 62 | if ((FLASH->SR & FLASH_SR_BSY) == FLASH_SR_BSY) return FLASH_BUSY; |
63 | if ((FLASH->SR & FLASH_SR_BSY) == FLASH_SR_BSY) | ||
64 | return FLASH_BUSY; | ||
65 | 63 | ||
66 | if ((FLASH->SR & FLASH_SR_PGERR) != 0) | 64 | if ((FLASH->SR & FLASH_SR_PGERR) != 0) return FLASH_ERROR_PG; |
67 | return FLASH_ERROR_PG; | ||
68 | 65 | ||
69 | if ((FLASH->SR & FLASH_SR_WRPERR) != 0 ) | 66 | if ((FLASH->SR & FLASH_SR_WRPERR) != 0) return FLASH_ERROR_WRP; |
70 | return FLASH_ERROR_WRP; | ||
71 | 67 | ||
72 | if ((FLASH->SR & FLASH_OBR_OPTERR) != 0 ) | 68 | if ((FLASH->SR & FLASH_OBR_OPTERR) != 0) return FLASH_ERROR_OPT; |
73 | return FLASH_ERROR_OPT; | ||
74 | 69 | ||
75 | return FLASH_COMPLETE; | 70 | return FLASH_COMPLETE; |
76 | } | 71 | } |
77 | 72 | ||
78 | /** | 73 | /** |
79 | * @brief Waits for a Flash operation to complete or a TIMEOUT to occur. | 74 | * @brief Waits for a Flash operation to complete or a TIMEOUT to occur. |
80 | * @param Timeout: FLASH progamming Timeout | 75 | * @param Timeout: FLASH progamming Timeout |
81 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, | 76 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, |
82 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. | 77 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
83 | */ | 78 | */ |
84 | FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) | 79 | FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) { |
85 | { | ||
86 | FLASH_Status status; | 80 | FLASH_Status status; |
87 | 81 | ||
88 | /* Check for the Flash Status */ | 82 | /* Check for the Flash Status */ |
89 | status = FLASH_GetStatus(); | 83 | status = FLASH_GetStatus(); |
90 | /* Wait for a Flash operation to complete or a TIMEOUT to occur */ | 84 | /* Wait for a Flash operation to complete or a TIMEOUT to occur */ |
91 | while ((status == FLASH_BUSY) && (Timeout != 0x00)) | 85 | while ((status == FLASH_BUSY) && (Timeout != 0x00)) { |
92 | { | ||
93 | delay(); | 86 | delay(); |
94 | status = FLASH_GetStatus(); | 87 | status = FLASH_GetStatus(); |
95 | Timeout--; | 88 | Timeout--; |
96 | } | 89 | } |
97 | if (Timeout == 0) | 90 | if (Timeout == 0) status = FLASH_TIMEOUT; |
98 | status = FLASH_TIMEOUT; | ||
99 | /* Return the operation status */ | 91 | /* Return the operation status */ |
100 | return status; | 92 | return status; |
101 | } | 93 | } |
102 | 94 | ||
103 | /** | 95 | /** |
104 | * @brief Erases a specified FLASH page. | 96 | * @brief Erases a specified FLASH page. |
105 | * @param Page_Address: The page address to be erased. | 97 | * @param Page_Address: The page address to be erased. |
106 | * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG, | 98 | * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG, |
107 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. | 99 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
108 | */ | 100 | */ |
109 | FLASH_Status FLASH_ErasePage(uint32_t Page_Address) | 101 | FLASH_Status FLASH_ErasePage(uint32_t Page_Address) { |
110 | { | ||
111 | FLASH_Status status = FLASH_COMPLETE; | 102 | FLASH_Status status = FLASH_COMPLETE; |
112 | /* Check the parameters */ | 103 | /* Check the parameters */ |
113 | ASSERT(IS_FLASH_ADDRESS(Page_Address)); | 104 | ASSERT(IS_FLASH_ADDRESS(Page_Address)); |
114 | /* Wait for last operation to be completed */ | 105 | /* Wait for last operation to be completed */ |
115 | status = FLASH_WaitForLastOperation(EraseTimeout); | 106 | status = FLASH_WaitForLastOperation(EraseTimeout); |
116 | 107 | ||
117 | if(status == FLASH_COMPLETE) | 108 | if (status == FLASH_COMPLETE) { |
118 | { | ||
119 | /* if the previous operation is completed, proceed to erase the page */ | 109 | /* if the previous operation is completed, proceed to erase the page */ |
120 | FLASH->CR |= FLASH_CR_PER; | 110 | FLASH->CR |= FLASH_CR_PER; |
121 | FLASH->AR = Page_Address; | 111 | FLASH->AR = Page_Address; |
@@ -123,8 +113,7 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) | |||
123 | 113 | ||
124 | /* Wait for last operation to be completed */ | 114 | /* Wait for last operation to be completed */ |
125 | status = FLASH_WaitForLastOperation(EraseTimeout); | 115 | status = FLASH_WaitForLastOperation(EraseTimeout); |
126 | if(status != FLASH_TIMEOUT) | 116 | if (status != FLASH_TIMEOUT) { |
127 | { | ||
128 | /* if the erase operation is completed, disable the PER Bit */ | 117 | /* if the erase operation is completed, disable the PER Bit */ |
129 | FLASH->CR &= ~FLASH_CR_PER; | 118 | FLASH->CR &= ~FLASH_CR_PER; |
130 | } | 119 | } |
@@ -135,29 +124,25 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) | |||
135 | } | 124 | } |
136 | 125 | ||
137 | /** | 126 | /** |
138 | * @brief Programs a half word at a specified address. | 127 | * @brief Programs a half word at a specified address. |
139 | * @param Address: specifies the address to be programmed. | 128 | * @param Address: specifies the address to be programmed. |
140 | * @param Data: specifies the data to be programmed. | 129 | * @param Data: specifies the data to be programmed. |
141 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, | 130 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, |
142 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. | 131 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
143 | */ | 132 | */ |
144 | FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) | 133 | FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) { |
145 | { | ||
146 | FLASH_Status status = FLASH_BAD_ADDRESS; | 134 | FLASH_Status status = FLASH_BAD_ADDRESS; |
147 | 135 | ||
148 | if (IS_FLASH_ADDRESS(Address)) | 136 | if (IS_FLASH_ADDRESS(Address)) { |
149 | { | ||
150 | /* Wait for last operation to be completed */ | 137 | /* Wait for last operation to be completed */ |
151 | status = FLASH_WaitForLastOperation(ProgramTimeout); | 138 | status = FLASH_WaitForLastOperation(ProgramTimeout); |
152 | if(status == FLASH_COMPLETE) | 139 | if (status == FLASH_COMPLETE) { |
153 | { | ||
154 | /* if the previous operation is completed, proceed to program the new data */ | 140 | /* if the previous operation is completed, proceed to program the new data */ |
155 | FLASH->CR |= FLASH_CR_PG; | 141 | FLASH->CR |= FLASH_CR_PG; |
156 | *(__IO uint16_t*)Address = Data; | 142 | *(__IO uint16_t*)Address = Data; |
157 | /* Wait for last operation to be completed */ | 143 | /* Wait for last operation to be completed */ |
158 | status = FLASH_WaitForLastOperation(ProgramTimeout); | 144 | status = FLASH_WaitForLastOperation(ProgramTimeout); |
159 | if(status != FLASH_TIMEOUT) | 145 | if (status != FLASH_TIMEOUT) { |
160 | { | ||
161 | /* if the program operation is completed, disable the PG Bit */ | 146 | /* if the program operation is completed, disable the PG Bit */ |
162 | FLASH->CR &= ~FLASH_CR_PG; | 147 | FLASH->CR &= ~FLASH_CR_PG; |
163 | } | 148 | } |
@@ -168,39 +153,36 @@ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) | |||
168 | } | 153 | } |
169 | 154 | ||
170 | /** | 155 | /** |
171 | * @brief Unlocks the FLASH Program Erase Controller. | 156 | * @brief Unlocks the FLASH Program Erase Controller. |
172 | * @param None | 157 | * @param None |
173 | * @retval None | 158 | * @retval None |
174 | */ | 159 | */ |
175 | void FLASH_Unlock(void) | 160 | void FLASH_Unlock(void) { |
176 | { | ||
177 | /* Authorize the FPEC Access */ | 161 | /* Authorize the FPEC Access */ |
178 | FLASH->KEYR = FLASH_KEY1; | 162 | FLASH->KEYR = FLASH_KEY1; |
179 | FLASH->KEYR = FLASH_KEY2; | 163 | FLASH->KEYR = FLASH_KEY2; |
180 | } | 164 | } |
181 | 165 | ||
182 | /** | 166 | /** |
183 | * @brief Locks the FLASH Program Erase Controller. | 167 | * @brief Locks the FLASH Program Erase Controller. |
184 | * @param None | 168 | * @param None |
185 | * @retval None | 169 | * @retval None |
186 | */ | 170 | */ |
187 | void FLASH_Lock(void) | 171 | void FLASH_Lock(void) { |
188 | { | ||
189 | /* Set the Lock Bit to lock the FPEC and the FCR */ | 172 | /* Set the Lock Bit to lock the FPEC and the FCR */ |
190 | FLASH->CR |= FLASH_CR_LOCK; | 173 | FLASH->CR |= FLASH_CR_LOCK; |
191 | } | 174 | } |
192 | 175 | ||
193 | /** | 176 | /** |
194 | * @brief Clears the FLASH's pending flags. | 177 | * @brief Clears the FLASH's pending flags. |
195 | * @param FLASH_FLAG: specifies the FLASH flags to clear. | 178 | * @param FLASH_FLAG: specifies the FLASH flags to clear. |
196 | * This parameter can be any combination of the following values: | 179 | * This parameter can be any combination of the following values: |
197 | * @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag | 180 | * @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag |
198 | * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag | 181 | * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag |
199 | * @arg FLASH_FLAG_EOP: FLASH End of Programming flag | 182 | * @arg FLASH_FLAG_EOP: FLASH End of Programming flag |
200 | * @retval None | 183 | * @retval None |
201 | */ | 184 | */ |
202 | void FLASH_ClearFlag(uint32_t FLASH_FLAG) | 185 | void FLASH_ClearFlag(uint32_t FLASH_FLAG) { |
203 | { | ||
204 | /* Clear the flags */ | 186 | /* Clear the flags */ |
205 | FLASH->SR = FLASH_FLAG; | 187 | FLASH->SR = FLASH_FLAG; |
206 | } | 188 | } |
diff --git a/tmk_core/common/chibios/flash_stm32.h b/tmk_core/common/chibios/flash_stm32.h index 3c99cc566..33ab7867d 100755..100644 --- a/tmk_core/common/chibios/flash_stm32.h +++ b/tmk_core/common/chibios/flash_stm32.h | |||
@@ -10,7 +10,7 @@ | |||
10 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 10 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
11 | * DEALINGS IN THE SOFTWARE. | 11 | * DEALINGS IN THE SOFTWARE. |
12 | * | 12 | * |
13 | * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and | 13 | * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and |
14 | * https://github.com/leaflabs/libmaple | 14 | * https://github.com/leaflabs/libmaple |
15 | * | 15 | * |
16 | * Modifications for QMK and STM32F303 by Yiancar | 16 | * Modifications for QMK and STM32F303 by Yiancar |
@@ -20,22 +20,13 @@ | |||
20 | #define __FLASH_STM32_H | 20 | #define __FLASH_STM32_H |
21 | 21 | ||
22 | #ifdef __cplusplus | 22 | #ifdef __cplusplus |
23 | extern "C" { | 23 | extern "C" { |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | #include "ch.h" | 26 | #include "ch.h" |
27 | #include "hal.h" | 27 | #include "hal.h" |
28 | 28 | ||
29 | typedef enum | 29 | typedef enum { FLASH_BUSY = 1, FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_ERROR_OPT, FLASH_COMPLETE, FLASH_TIMEOUT, FLASH_BAD_ADDRESS } FLASH_Status; |
30 | { | ||
31 | FLASH_BUSY = 1, | ||
32 | FLASH_ERROR_PG, | ||
33 | FLASH_ERROR_WRP, | ||
34 | FLASH_ERROR_OPT, | ||
35 | FLASH_COMPLETE, | ||
36 | FLASH_TIMEOUT, | ||
37 | FLASH_BAD_ADDRESS | ||
38 | } FLASH_Status; | ||
39 | 30 | ||
40 | #define IS_FLASH_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x0807FFFF)) | 31 | #define IS_FLASH_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x0807FFFF)) |
41 | 32 | ||
diff --git a/tmk_core/common/chibios/printf.c b/tmk_core/common/chibios/printf.c index 72e3d4f8c..dbd059448 100644 --- a/tmk_core/common/chibios/printf.c +++ b/tmk_core/common/chibios/printf.c | |||
@@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
26 | 26 | ||
27 | #include "printf.h" | 27 | #include "printf.h" |
28 | 28 | ||
29 | typedef void (*putcf) (void*,char); | 29 | typedef void (*putcf)(void*, char); |
30 | static putcf stdout_putf; | 30 | static putcf stdout_putf; |
31 | static void* stdout_putp; | 31 | static void* stdout_putp; |
32 | 32 | ||
@@ -35,206 +35,185 @@ static void* stdout_putp; | |||
35 | 35 | ||
36 | #ifdef PRINTF_LONG_SUPPORT | 36 | #ifdef PRINTF_LONG_SUPPORT |
37 | 37 | ||
38 | static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf) | 38 | static void uli2a(unsigned long int num, unsigned int base, int uc, char* bf) { |
39 | { | 39 | int n = 0; |
40 | int n=0; | 40 | unsigned int d = 1; |
41 | unsigned int d=1; | 41 | while (num / d >= base) d *= base; |
42 | while (num/d >= base) | 42 | while (d != 0) { |
43 | d*=base; | ||
44 | while (d!=0) { | ||
45 | int dgt = num / d; | 43 | int dgt = num / d; |
46 | num%=d; | 44 | num %= d; |
47 | d/=base; | 45 | d /= base; |
48 | if (n || dgt>0|| d==0) { | 46 | if (n || dgt > 0 || d == 0) { |
49 | *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10); | 47 | *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10); |
50 | ++n; | 48 | ++n; |
51 | } | ||
52 | } | 49 | } |
53 | *bf=0; | ||
54 | } | 50 | } |
51 | *bf = 0; | ||
52 | } | ||
55 | 53 | ||
56 | static void li2a (long num, char * bf) | 54 | static void li2a(long num, char* bf) { |
57 | { | 55 | if (num < 0) { |
58 | if (num<0) { | 56 | num = -num; |
59 | num=-num; | ||
60 | *bf++ = '-'; | 57 | *bf++ = '-'; |
61 | } | ||
62 | uli2a(num,10,0,bf); | ||
63 | } | 58 | } |
59 | uli2a(num, 10, 0, bf); | ||
60 | } | ||
64 | 61 | ||
65 | #endif | 62 | #endif |
66 | 63 | ||
67 | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf) | 64 | static void ui2a(unsigned int num, unsigned int base, int uc, char* bf) { |
68 | { | 65 | int n = 0; |
69 | int n=0; | 66 | unsigned int d = 1; |
70 | unsigned int d=1; | 67 | while (num / d >= base) d *= base; |
71 | while (num/d >= base) | 68 | while (d != 0) { |
72 | d*=base; | ||
73 | while (d!=0) { | ||
74 | int dgt = num / d; | 69 | int dgt = num / d; |
75 | num%= d; | 70 | num %= d; |
76 | d/=base; | 71 | d /= base; |
77 | if (n || dgt>0 || d==0) { | 72 | if (n || dgt > 0 || d == 0) { |
78 | *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10); | 73 | *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10); |
79 | ++n; | 74 | ++n; |
80 | } | ||
81 | } | 75 | } |
82 | *bf=0; | ||
83 | } | 76 | } |
77 | *bf = 0; | ||
78 | } | ||
84 | 79 | ||
85 | static void i2a (int num, char * bf) | 80 | static void i2a(int num, char* bf) { |
86 | { | 81 | if (num < 0) { |
87 | if (num<0) { | 82 | num = -num; |
88 | num=-num; | ||
89 | *bf++ = '-'; | 83 | *bf++ = '-'; |
90 | } | ||
91 | ui2a(num,10,0,bf); | ||
92 | } | 84 | } |
93 | 85 | ui2a(num, 10, 0, bf); | |
94 | static int a2d(char ch) | 86 | } |
95 | { | 87 | |
96 | if (ch>='0' && ch<='9') | 88 | static int a2d(char ch) { |
97 | return ch-'0'; | 89 | if (ch >= '0' && ch <= '9') |
98 | else if (ch>='a' && ch<='f') | 90 | return ch - '0'; |
99 | return ch-'a'+10; | 91 | else if (ch >= 'a' && ch <= 'f') |
100 | else if (ch>='A' && ch<='F') | 92 | return ch - 'a' + 10; |
101 | return ch-'A'+10; | 93 | else if (ch >= 'A' && ch <= 'F') |
102 | else return -1; | 94 | return ch - 'A' + 10; |
95 | else | ||
96 | return -1; | ||
97 | } | ||
98 | |||
99 | static char a2i(char ch, char** src, int base, int* nump) { | ||
100 | char* p = *src; | ||
101 | int num = 0; | ||
102 | int digit; | ||
103 | while ((digit = a2d(ch)) >= 0) { | ||
104 | if (digit > base) break; | ||
105 | num = num * base + digit; | ||
106 | ch = *p++; | ||
103 | } | 107 | } |
104 | 108 | *src = p; | |
105 | static char a2i(char ch, char** src,int base,int* nump) | 109 | *nump = num; |
106 | { | ||
107 | char* p= *src; | ||
108 | int num=0; | ||
109 | int digit; | ||
110 | while ((digit=a2d(ch))>=0) { | ||
111 | if (digit>base) break; | ||
112 | num=num*base+digit; | ||
113 | ch=*p++; | ||
114 | } | ||
115 | *src=p; | ||
116 | *nump=num; | ||
117 | return ch; | 110 | return ch; |
118 | } | 111 | } |
119 | 112 | ||
120 | static void putchw(void* putp,putcf putf,int n, char z, char* bf) | 113 | static void putchw(void* putp, putcf putf, int n, char z, char* bf) { |
121 | { | 114 | char fc = z ? '0' : ' '; |
122 | char fc=z? '0' : ' '; | 115 | char ch; |
123 | char ch; | 116 | char* p = bf; |
124 | char* p=bf; | 117 | while (*p++ && n > 0) n--; |
125 | while (*p++ && n > 0) | 118 | while (n-- > 0) putf(putp, fc); |
126 | n--; | 119 | while ((ch = *bf++)) putf(putp, ch); |
127 | while (n-- > 0) | 120 | } |
128 | putf(putp,fc); | 121 | |
129 | while ((ch= *bf++)) | 122 | void tfp_format(void* putp, putcf putf, char* fmt, va_list va) { |
130 | putf(putp,ch); | ||
131 | } | ||
132 | |||
133 | void tfp_format(void* putp,putcf putf,char *fmt, va_list va) | ||
134 | { | ||
135 | char bf[12]; | 123 | char bf[12]; |
136 | |||
137 | char ch; | ||
138 | 124 | ||
125 | char ch; | ||
139 | 126 | ||
140 | while ((ch=*(fmt++))) { | 127 | while ((ch = *(fmt++))) { |
141 | if (ch!='%') | 128 | if (ch != '%') |
142 | putf(putp,ch); | 129 | putf(putp, ch); |
143 | else { | 130 | else { |
144 | char lz=0; | 131 | char lz = 0; |
145 | #ifdef PRINTF_LONG_SUPPORT | 132 | #ifdef PRINTF_LONG_SUPPORT |
146 | char lng=0; | 133 | char lng = 0; |
147 | #endif | 134 | #endif |
148 | int w=0; | 135 | int w = 0; |
149 | ch=*(fmt++); | 136 | ch = *(fmt++); |
150 | if (ch=='0') { | 137 | if (ch == '0') { |
151 | ch=*(fmt++); | 138 | ch = *(fmt++); |
152 | lz=1; | 139 | lz = 1; |
153 | } | 140 | } |
154 | if (ch>='0' && ch<='9') { | 141 | if (ch >= '0' && ch <= '9') { |
155 | ch=a2i(ch,&fmt,10,&w); | 142 | ch = a2i(ch, &fmt, 10, &w); |
156 | } | 143 | } |
157 | #ifdef PRINTF_LONG_SUPPORT | 144 | #ifdef PRINTF_LONG_SUPPORT |
158 | if (ch=='l') { | 145 | if (ch == 'l') { |
159 | ch=*(fmt++); | 146 | ch = *(fmt++); |
160 | lng=1; | 147 | lng = 1; |
161 | } | 148 | } |
162 | #endif | 149 | #endif |
163 | switch (ch) { | 150 | switch (ch) { |
164 | case 0: | 151 | case 0: |
165 | goto abort; | 152 | goto abort; |
166 | case 'u' : { | 153 | case 'u': { |
167 | #ifdef PRINTF_LONG_SUPPORT | 154 | #ifdef PRINTF_LONG_SUPPORT |
168 | if (lng) | 155 | if (lng) |
169 | uli2a(va_arg(va, unsigned long int),10,0,bf); | 156 | uli2a(va_arg(va, unsigned long int), 10, 0, bf); |
170 | else | 157 | else |
171 | #endif | 158 | #endif |
172 | ui2a(va_arg(va, unsigned int),10,0,bf); | 159 | ui2a(va_arg(va, unsigned int), 10, 0, bf); |
173 | putchw(putp,putf,w,lz,bf); | 160 | putchw(putp, putf, w, lz, bf); |
174 | break; | 161 | break; |
175 | } | 162 | } |
176 | case 'd' : { | 163 | case 'd': { |
177 | #ifdef PRINTF_LONG_SUPPORT | 164 | #ifdef PRINTF_LONG_SUPPORT |
178 | if (lng) | 165 | if (lng) |
179 | li2a(va_arg(va, unsigned long int),bf); | 166 | li2a(va_arg(va, unsigned long int), bf); |
180 | else | 167 | else |
181 | #endif | 168 | #endif |
182 | i2a(va_arg(va, int),bf); | 169 | i2a(va_arg(va, int), bf); |
183 | putchw(putp,putf,w,lz,bf); | 170 | putchw(putp, putf, w, lz, bf); |
184 | break; | 171 | break; |
185 | } | 172 | } |
186 | case 'x': case 'X' : | 173 | case 'x': |
187 | #ifdef PRINTF_LONG_SUPPORT | 174 | case 'X': |
175 | #ifdef PRINTF_LONG_SUPPORT | ||
188 | if (lng) | 176 | if (lng) |
189 | uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf); | 177 | uli2a(va_arg(va, unsigned long int), 16, (ch == 'X'), bf); |
190 | else | 178 | else |
191 | #endif | 179 | #endif |
192 | ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf); | 180 | ui2a(va_arg(va, unsigned int), 16, (ch == 'X'), bf); |
193 | putchw(putp,putf,w,lz,bf); | 181 | putchw(putp, putf, w, lz, bf); |
194 | break; | 182 | break; |
195 | case 'c' : | 183 | case 'c': |
196 | putf(putp,(char)(va_arg(va, int))); | 184 | putf(putp, (char)(va_arg(va, int))); |
197 | break; | 185 | break; |
198 | case 's' : | 186 | case 's': |
199 | putchw(putp,putf,w,0,va_arg(va, char*)); | 187 | putchw(putp, putf, w, 0, va_arg(va, char*)); |
200 | break; | 188 | break; |
201 | case '%' : | 189 | case '%': |
202 | putf(putp,ch); | 190 | putf(putp, ch); |
203 | default: | 191 | default: |
204 | break; | 192 | break; |
205 | } | ||
206 | } | 193 | } |
207 | } | 194 | } |
208 | abort:; | ||
209 | } | 195 | } |
196 | abort:; | ||
197 | } | ||
210 | 198 | ||
199 | void init_printf(void* putp, void (*putf)(void*, char)) { | ||
200 | stdout_putf = putf; | ||
201 | stdout_putp = putp; | ||
202 | } | ||
211 | 203 | ||
212 | void init_printf(void* putp,void (*putf) (void*,char)) | 204 | void tfp_printf(char* fmt, ...) { |
213 | { | ||
214 | stdout_putf=putf; | ||
215 | stdout_putp=putp; | ||
216 | } | ||
217 | |||
218 | void tfp_printf(char *fmt, ...) | ||
219 | { | ||
220 | va_list va; | 205 | va_list va; |
221 | va_start(va,fmt); | 206 | va_start(va, fmt); |
222 | tfp_format(stdout_putp,stdout_putf,fmt,va); | 207 | tfp_format(stdout_putp, stdout_putf, fmt, va); |
223 | va_end(va); | 208 | va_end(va); |
224 | } | 209 | } |
225 | |||
226 | static void putcp(void* p,char c) | ||
227 | { | ||
228 | *(*((char**)p))++ = c; | ||
229 | } | ||
230 | 210 | ||
211 | static void putcp(void* p, char c) { *(*((char**)p))++ = c; } | ||
231 | 212 | ||
232 | 213 | void tfp_sprintf(char* s, char* fmt, ...) { | |
233 | void tfp_sprintf(char* s,char *fmt, ...) | ||
234 | { | ||
235 | va_list va; | 214 | va_list va; |
236 | va_start(va,fmt); | 215 | va_start(va, fmt); |
237 | tfp_format(&s,putcp,fmt,va); | 216 | tfp_format(&s, putcp, fmt, va); |
238 | putcp(&s,0); | 217 | putcp(&s, 0); |
239 | va_end(va); | 218 | va_end(va); |
240 | } | 219 | } |
diff --git a/tmk_core/common/chibios/printf.h b/tmk_core/common/chibios/printf.h index 678a100c6..2cdf55ed9 100644 --- a/tmk_core/common/chibios/printf.h +++ b/tmk_core/common/chibios/printf.h | |||
@@ -15,7 +15,7 @@ version 2.1 of the License, or (at your option) any later version. | |||
15 | 15 | ||
16 | This library is distributed in the hope that it will be useful, | 16 | This library is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Lesser General Public License for more details. | 19 | See the GNU Lesser General Public License for more details. |
20 | 20 | ||
21 | You should have received a copy of the GNU Lesser General Public | 21 | You should have received a copy of the GNU Lesser General Public |
@@ -24,35 +24,35 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
24 | 24 | ||
25 | This library is realy just two files: 'printf.h' and 'printf.c'. | 25 | This library is realy just two files: 'printf.h' and 'printf.c'. |
26 | 26 | ||
27 | They provide a simple and small (+200 loc) printf functionality to | 27 | They provide a simple and small (+200 loc) printf functionality to |
28 | be used in embedded systems. | 28 | be used in embedded systems. |
29 | 29 | ||
30 | I've found them so usefull in debugging that I do not bother with a | 30 | I've found them so usefull in debugging that I do not bother with a |
31 | debugger at all. | 31 | debugger at all. |
32 | 32 | ||
33 | They are distributed in source form, so to use them, just compile them | 33 | They are distributed in source form, so to use them, just compile them |
34 | into your project. | 34 | into your project. |
35 | 35 | ||
36 | Two printf variants are provided: printf and sprintf. | 36 | Two printf variants are provided: printf and sprintf. |
37 | 37 | ||
38 | The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'. | 38 | The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'. |
39 | 39 | ||
40 | Zero padding and field width are also supported. | 40 | Zero padding and field width are also supported. |
41 | 41 | ||
42 | If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the | 42 | If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the |
43 | long specifier is also | 43 | long specifier is also |
44 | supported. Note that this will pull in some long math routines (pun intended!) | 44 | supported. Note that this will pull in some long math routines (pun intended!) |
45 | and thus make your executable noticably longer. | 45 | and thus make your executable noticably longer. |
46 | 46 | ||
47 | The memory foot print of course depends on the target cpu, compiler and | 47 | The memory foot print of course depends on the target cpu, compiler and |
48 | compiler options, but a rough guestimate (based on a H8S target) is about | 48 | compiler options, but a rough guestimate (based on a H8S target) is about |
49 | 1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space. | 49 | 1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space. |
50 | Not too bad. Your milage may vary. By hacking the source code you can | 50 | Not too bad. Your milage may vary. By hacking the source code you can |
51 | get rid of some hunred bytes, I'm sure, but personally I feel the balance of | 51 | get rid of some hunred bytes, I'm sure, but personally I feel the balance of |
52 | functionality and flexibility versus code size is close to optimal for | 52 | functionality and flexibility versus code size is close to optimal for |
53 | many embedded systems. | 53 | many embedded systems. |
54 | 54 | ||
55 | To use the printf you need to supply your own character output function, | 55 | To use the printf you need to supply your own character output function, |
56 | something like : | 56 | something like : |
57 | 57 | ||
58 | void putc ( void* p, char c) | 58 | void putc ( void* p, char c) |
@@ -61,25 +61,25 @@ something like : | |||
61 | SERIAL_PORT_TX_REGISTER = c; | 61 | SERIAL_PORT_TX_REGISTER = c; |
62 | } | 62 | } |
63 | 63 | ||
64 | Before you can call printf you need to initialize it to use your | 64 | Before you can call printf you need to initialize it to use your |
65 | character output function with something like: | 65 | character output function with something like: |
66 | 66 | ||
67 | init_printf(NULL,putc); | 67 | init_printf(NULL,putc); |
68 | 68 | ||
69 | Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc', | 69 | Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc', |
70 | the NULL (or any pointer) you pass into the 'init_printf' will eventually be | 70 | the NULL (or any pointer) you pass into the 'init_printf' will eventually be |
71 | passed to your 'putc' routine. This allows you to pass some storage space (or | 71 | passed to your 'putc' routine. This allows you to pass some storage space (or |
72 | anything realy) to the character output function, if necessary. | 72 | anything realy) to the character output function, if necessary. |
73 | This is not often needed but it was implemented like that because it made | 73 | This is not often needed but it was implemented like that because it made |
74 | implementing the sprintf function so neat (look at the source code). | 74 | implementing the sprintf function so neat (look at the source code). |
75 | 75 | ||
76 | The code is re-entrant, except for the 'init_printf' function, so it | 76 | The code is re-entrant, except for the 'init_printf' function, so it |
77 | is safe to call it from interupts too, although this may result in mixed output. | 77 | is safe to call it from interupts too, although this may result in mixed output. |
78 | If you rely on re-entrancy, take care that your 'putc' function is re-entrant! | 78 | If you rely on re-entrancy, take care that your 'putc' function is re-entrant! |
79 | 79 | ||
80 | The printf and sprintf functions are actually macros that translate to | 80 | The printf and sprintf functions are actually macros that translate to |
81 | 'tfp_printf' and 'tfp_sprintf'. This makes it possible | 81 | 'tfp_printf' and 'tfp_sprintf'. This makes it possible |
82 | to use them along with 'stdio.h' printf's in a single source file. | 82 | to use them along with 'stdio.h' printf's in a single source file. |
83 | You just need to undef the names before you include the 'stdio.h'. | 83 | You just need to undef the names before you include the 'stdio.h'. |
84 | Note that these are not function like macros, so if you have variables | 84 | Note that these are not function like macros, so if you have variables |
85 | or struct members with these names, things will explode in your face. | 85 | or struct members with these names, things will explode in your face. |
@@ -92,20 +92,19 @@ For further details see source code. | |||
92 | regs Kusti, 23.10.2004 | 92 | regs Kusti, 23.10.2004 |
93 | */ | 93 | */ |
94 | 94 | ||
95 | |||
96 | #ifndef __TFP_PRINTF__ | 95 | #ifndef __TFP_PRINTF__ |
97 | #define __TFP_PRINTF__ | 96 | #define __TFP_PRINTF__ |
98 | 97 | ||
99 | #include <stdarg.h> | 98 | #include <stdarg.h> |
100 | 99 | ||
101 | void init_printf(void* putp,void (*putf) (void*,char)); | 100 | void init_printf(void* putp, void (*putf)(void*, char)); |
102 | 101 | ||
103 | void tfp_printf(char *fmt, ...); | 102 | void tfp_printf(char* fmt, ...); |
104 | void tfp_sprintf(char* s,char *fmt, ...); | 103 | void tfp_sprintf(char* s, char* fmt, ...); |
105 | 104 | ||
106 | void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va); | 105 | void tfp_format(void* putp, void (*putf)(void*, char), char* fmt, va_list va); |
107 | 106 | ||
108 | #define printf tfp_printf | 107 | #define printf tfp_printf |
109 | #define sprintf tfp_sprintf | 108 | #define sprintf tfp_sprintf |
110 | 109 | ||
111 | #endif | 110 | #endif |
diff --git a/tmk_core/common/chibios/sleep_led.c b/tmk_core/common/chibios/sleep_led.c index 4c35cfcba..df1a1b5fc 100644 --- a/tmk_core/common/chibios/sleep_led.c +++ b/tmk_core/common/chibios/sleep_led.c | |||
@@ -12,14 +12,14 @@ | |||
12 | #if defined(KL2x) || defined(K20x) | 12 | #if defined(KL2x) || defined(K20x) |
13 | 13 | ||
14 | /* Use Low Power Timer (LPTMR) */ | 14 | /* Use Low Power Timer (LPTMR) */ |
15 | #define TIMER_INTERRUPT_VECTOR KINETIS_LPTMR0_IRQ_VECTOR | 15 | # define TIMER_INTERRUPT_VECTOR KINETIS_LPTMR0_IRQ_VECTOR |
16 | #define RESET_COUNTER LPTMR0->CSR |= LPTMRx_CSR_TCF | 16 | # define RESET_COUNTER LPTMR0->CSR |= LPTMRx_CSR_TCF |
17 | 17 | ||
18 | #elif defined(STM32F0XX) | 18 | #elif defined(STM32F0XX) |
19 | 19 | ||
20 | /* Use TIM14 manually */ | 20 | /* Use TIM14 manually */ |
21 | #define TIMER_INTERRUPT_VECTOR STM32_TIM14_HANDLER | 21 | # define TIMER_INTERRUPT_VECTOR STM32_TIM14_HANDLER |
22 | #define RESET_COUNTER STM32_TIM14->SR &= ~STM32_TIM_SR_UIF | 22 | # define RESET_COUNTER STM32_TIM14->SR &= ~STM32_TIM_SR_UIF |
23 | 23 | ||
24 | #endif | 24 | #endif |
25 | 25 | ||
@@ -31,39 +31,34 @@ | |||
31 | * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63 | 31 | * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63 |
32 | * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i } | 32 | * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i } |
33 | */ | 33 | */ |
34 | static const uint8_t breathing_table[64] = { | 34 | static const uint8_t breathing_table[64] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
35 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, | ||
36 | 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, | ||
37 | 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, | ||
38 | 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
39 | }; | ||
40 | 35 | ||
41 | /* interrupt handler */ | 36 | /* interrupt handler */ |
42 | OSAL_IRQ_HANDLER(TIMER_INTERRUPT_VECTOR) { | 37 | OSAL_IRQ_HANDLER(TIMER_INTERRUPT_VECTOR) { |
43 | OSAL_IRQ_PROLOGUE(); | 38 | OSAL_IRQ_PROLOGUE(); |
44 | 39 | ||
45 | /* Software PWM | 40 | /* Software PWM |
46 | * timer:1111 1111 1111 1111 | 41 | * timer:1111 1111 1111 1111 |
47 | * \_____/\/ \_______/____ count(0-255) | 42 | * \_____/\/ \_______/____ count(0-255) |
48 | * \ \______________ duration of step(4) | 43 | * \ \______________ duration of step(4) |
49 | * \__________________ index of step table(0-63) | 44 | * \__________________ index of step table(0-63) |
50 | */ | 45 | */ |
51 | 46 | ||
52 | // this works for cca 65536 irqs/sec | 47 | // this works for cca 65536 irqs/sec |
53 | static union { | 48 | static union { |
54 | uint16_t row; | 49 | uint16_t row; |
55 | struct { | 50 | struct { |
56 | uint8_t count:8; | 51 | uint8_t count : 8; |
57 | uint8_t duration:2; | 52 | uint8_t duration : 2; |
58 | uint8_t index:6; | 53 | uint8_t index : 6; |
59 | } pwm; | 54 | } pwm; |
60 | } timer = { .row = 0 }; | 55 | } timer = {.row = 0}; |
61 | 56 | ||
62 | timer.row++; | 57 | timer.row++; |
63 | 58 | ||
64 | // LED on | 59 | // LED on |
65 | if (timer.pwm.count == 0) { | 60 | if (timer.pwm.count == 0) { |
66 | led_set(1<<USB_LED_CAPS_LOCK); | 61 | led_set(1 << USB_LED_CAPS_LOCK); |
67 | } | 62 | } |
68 | // LED off | 63 | // LED off |
69 | if (timer.pwm.count == breathing_table[timer.pwm.index]) { | 64 | if (timer.pwm.count == breathing_table[timer.pwm.index]) { |
@@ -78,19 +73,18 @@ OSAL_IRQ_HANDLER(TIMER_INTERRUPT_VECTOR) { | |||
78 | 73 | ||
79 | #endif /* common parts for known platforms */ | 74 | #endif /* common parts for known platforms */ |
80 | 75 | ||
81 | |||
82 | #if defined(KL2x) || defined(K20x) /* platform selection: familiar Kinetis chips */ | 76 | #if defined(KL2x) || defined(K20x) /* platform selection: familiar Kinetis chips */ |
83 | 77 | ||
84 | /* LPTMR clock options */ | 78 | /* LPTMR clock options */ |
85 | #define LPTMR_CLOCK_MCGIRCLK 0 /* 4MHz clock */ | 79 | # define LPTMR_CLOCK_MCGIRCLK 0 /* 4MHz clock */ |
86 | #define LPTMR_CLOCK_LPO 1 /* 1kHz clock */ | 80 | # define LPTMR_CLOCK_LPO 1 /* 1kHz clock */ |
87 | #define LPTMR_CLOCK_ERCLK32K 2 /* external 32kHz crystal */ | 81 | # define LPTMR_CLOCK_ERCLK32K 2 /* external 32kHz crystal */ |
88 | #define LPTMR_CLOCK_OSCERCLK 3 /* output from OSC */ | 82 | # define LPTMR_CLOCK_OSCERCLK 3 /* output from OSC */ |
89 | 83 | ||
90 | /* Work around inconsistencies in Freescale naming */ | 84 | /* Work around inconsistencies in Freescale naming */ |
91 | #if !defined(SIM_SCGC5_LPTMR) | 85 | # if !defined(SIM_SCGC5_LPTMR) |
92 | #define SIM_SCGC5_LPTMR SIM_SCGC5_LPTIMER | 86 | # define SIM_SCGC5_LPTMR SIM_SCGC5_LPTIMER |
93 | #endif | 87 | # endif |
94 | 88 | ||
95 | /* Initialise the timer */ | 89 | /* Initialise the timer */ |
96 | void sleep_led_init(void) { | 90 | void sleep_led_init(void) { |
@@ -101,52 +95,52 @@ void sleep_led_init(void) { | |||
101 | /* Set the compare value */ | 95 | /* Set the compare value */ |
102 | LPTMR0->CMR = 0; // trigger on counter value (i.e. every time) | 96 | LPTMR0->CMR = 0; // trigger on counter value (i.e. every time) |
103 | 97 | ||
104 | /* Set up clock source and prescaler */ | 98 | /* Set up clock source and prescaler */ |
105 | /* Software PWM | 99 | /* Software PWM |
106 | * ______ ______ __ | 100 | * ______ ______ __ |
107 | * | ON |___OFF___| ON |___OFF___| .... | 101 | * | ON |___OFF___| ON |___OFF___| .... |
108 | * |<-------------->|<-------------->|<- .... | 102 | * |<-------------->|<-------------->|<- .... |
109 | * PWM period PWM period | 103 | * PWM period PWM period |
110 | * | 104 | * |
111 | * R interrupts/period[resolution] | 105 | * R interrupts/period[resolution] |
112 | * F periods/second[frequency] | 106 | * F periods/second[frequency] |
113 | * R * F interrupts/second | 107 | * R * F interrupts/second |
114 | */ | 108 | */ |
115 | 109 | ||
116 | /* === OPTION 1 === */ | 110 | /* === OPTION 1 === */ |
117 | #if 0 | 111 | # if 0 |
118 | // 1kHz LPO | 112 | // 1kHz LPO |
119 | // No prescaler => 1024 irqs/sec | 113 | // No prescaler => 1024 irqs/sec |
120 | // Note: this is too slow for a smooth breathe | 114 | // Note: this is too slow for a smooth breathe |
121 | LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_LPO)|LPTMRx_PSR_PBYP; | 115 | LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_LPO)|LPTMRx_PSR_PBYP; |
122 | #endif /* OPTION 1 */ | 116 | # endif /* OPTION 1 */ |
123 | 117 | ||
124 | /* === OPTION 2 === */ | 118 | /* === OPTION 2 === */ |
125 | #if 1 | 119 | # if 1 |
126 | // nMHz IRC (n=4 on KL25Z, KL26Z and K20x; n=2 or 8 on KL27Z) | 120 | // nMHz IRC (n=4 on KL25Z, KL26Z and K20x; n=2 or 8 on KL27Z) |
127 | MCG->C2 |= MCG_C2_IRCS; // fast (4MHz) internal ref clock | 121 | MCG->C2 |= MCG_C2_IRCS; // fast (4MHz) internal ref clock |
128 | #if defined(KL27) // divide the 8MHz IRC by 2, to have the same MCGIRCLK speed as others | 122 | # if defined(KL27) // divide the 8MHz IRC by 2, to have the same MCGIRCLK speed as others |
129 | MCG->MC |= MCG_MC_LIRC_DIV2_DIV2; | 123 | MCG->MC |= MCG_MC_LIRC_DIV2_DIV2; |
130 | #endif /* KL27 */ | 124 | # endif /* KL27 */ |
131 | MCG->C1 |= MCG_C1_IRCLKEN; // enable internal ref clock | 125 | MCG->C1 |= MCG_C1_IRCLKEN; // enable internal ref clock |
132 | // to work in stop mode, also MCG_C1_IREFSTEN | 126 | // to work in stop mode, also MCG_C1_IREFSTEN |
133 | // Divide 4MHz by 2^N (N=6) => 62500 irqs/sec => | 127 | // Divide 4MHz by 2^N (N=6) => 62500 irqs/sec => |
134 | // => approx F=61, R=256, duration = 4 | 128 | // => approx F=61, R=256, duration = 4 |
135 | LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_MCGIRCLK)|LPTMRx_PSR_PRESCALE(6); | 129 | LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_MCGIRCLK) | LPTMRx_PSR_PRESCALE(6); |
136 | #endif /* OPTION 2 */ | 130 | # endif /* OPTION 2 */ |
137 | 131 | ||
138 | /* === OPTION 3 === */ | 132 | /* === OPTION 3 === */ |
139 | #if 0 | 133 | # if 0 |
140 | // OSC output (external crystal), usually 8MHz or 16MHz | 134 | // OSC output (external crystal), usually 8MHz or 16MHz |
141 | OSC0->CR |= OSC_CR_ERCLKEN; // enable ext ref clock | 135 | OSC0->CR |= OSC_CR_ERCLKEN; // enable ext ref clock |
142 | // to work in stop mode, also OSC_CR_EREFSTEN | 136 | // to work in stop mode, also OSC_CR_EREFSTEN |
143 | // Divide by 2^N | 137 | // Divide by 2^N |
144 | LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_OSCERCLK)|LPTMRx_PSR_PRESCALE(7); | 138 | LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_OSCERCLK)|LPTMRx_PSR_PRESCALE(7); |
145 | #endif /* OPTION 3 */ | 139 | # endif /* OPTION 3 */ |
146 | /* === END OPTIONS === */ | 140 | /* === END OPTIONS === */ |
147 | 141 | ||
148 | /* Interrupt on TCF set (compare flag) */ | 142 | /* Interrupt on TCF set (compare flag) */ |
149 | nvicEnableVector(LPTMR0_IRQn, 2); // vector, priority | 143 | nvicEnableVector(LPTMR0_IRQn, 2); // vector, priority |
150 | LPTMR0->CSR |= LPTMRx_CSR_TIE; | 144 | LPTMR0->CSR |= LPTMRx_CSR_TIE; |
151 | } | 145 | } |
152 | 146 | ||
@@ -205,20 +199,14 @@ void sleep_led_toggle(void) { | |||
205 | STM32_TIM14->CR1 ^= STM32_TIM_CR1_CEN; | 199 | STM32_TIM14->CR1 ^= STM32_TIM_CR1_CEN; |
206 | } | 200 | } |
207 | 201 | ||
208 | |||
209 | #else /* platform selection: not on familiar chips */ | 202 | #else /* platform selection: not on familiar chips */ |
210 | 203 | ||
211 | void sleep_led_init(void) { | 204 | void sleep_led_init(void) {} |
212 | } | 205 | |
213 | 206 | void sleep_led_enable(void) { led_set(1 << USB_LED_CAPS_LOCK); } | |
214 | void sleep_led_enable(void) { | 207 | |
215 | led_set(1<<USB_LED_CAPS_LOCK); | 208 | void sleep_led_disable(void) { led_set(0); } |
216 | } | 209 | |
217 | |||
218 | void sleep_led_disable(void) { | ||
219 | led_set(0); | ||
220 | } | ||
221 | |||
222 | void sleep_led_toggle(void) { | 210 | void sleep_led_toggle(void) { |
223 | // not implemented | 211 | // not implemented |
224 | } | 212 | } |
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c index 6027d69b7..ae1c6f53e 100644 --- a/tmk_core/common/chibios/suspend.c +++ b/tmk_core/common/chibios/suspend.c | |||
@@ -17,49 +17,44 @@ | |||
17 | * FIXME: needs doc | 17 | * FIXME: needs doc |
18 | */ | 18 | */ |
19 | void suspend_idle(uint8_t time) { | 19 | void suspend_idle(uint8_t time) { |
20 | // TODO: this is not used anywhere - what units is 'time' in? | 20 | // TODO: this is not used anywhere - what units is 'time' in? |
21 | wait_ms(time); | 21 | wait_ms(time); |
22 | } | 22 | } |
23 | 23 | ||
24 | /** \brief Run keyboard level Power down | 24 | /** \brief Run keyboard level Power down |
25 | * | 25 | * |
26 | * FIXME: needs doc | 26 | * FIXME: needs doc |
27 | */ | 27 | */ |
28 | __attribute__ ((weak)) | 28 | __attribute__((weak)) void suspend_power_down_user(void) {} |
29 | void suspend_power_down_user (void) { } | ||
30 | /** \brief Run keyboard level Power down | 29 | /** \brief Run keyboard level Power down |
31 | * | 30 | * |
32 | * FIXME: needs doc | 31 | * FIXME: needs doc |
33 | */ | 32 | */ |
34 | __attribute__ ((weak)) | 33 | __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } |
35 | void suspend_power_down_kb(void) { | ||
36 | suspend_power_down_user(); | ||
37 | } | ||
38 | 34 | ||
39 | /** \brief suspend power down | 35 | /** \brief suspend power down |
40 | * | 36 | * |
41 | * FIXME: needs doc | 37 | * FIXME: needs doc |
42 | */ | 38 | */ |
43 | void suspend_power_down(void) { | 39 | void suspend_power_down(void) { |
44 | // TODO: figure out what to power down and how | 40 | // TODO: figure out what to power down and how |
45 | // shouldn't power down TPM/FTM if we want a breathing LED | 41 | // shouldn't power down TPM/FTM if we want a breathing LED |
46 | // also shouldn't power down USB | 42 | // also shouldn't power down USB |
47 | 43 | ||
48 | suspend_power_down_kb(); | 44 | suspend_power_down_kb(); |
49 | // on AVR, this enables the watchdog for 15ms (max), and goes to | 45 | // on AVR, this enables the watchdog for 15ms (max), and goes to |
50 | // SLEEP_MODE_PWR_DOWN | 46 | // SLEEP_MODE_PWR_DOWN |
51 | 47 | ||
52 | wait_ms(17); | 48 | wait_ms(17); |
53 | } | 49 | } |
54 | 50 | ||
55 | /** \brief suspend wakeup condition | 51 | /** \brief suspend wakeup condition |
56 | * | 52 | * |
57 | * FIXME: needs doc | 53 | * FIXME: needs doc |
58 | */ | 54 | */ |
59 | __attribute__ ((weak)) void matrix_power_up(void) {} | 55 | __attribute__((weak)) void matrix_power_up(void) {} |
60 | __attribute__ ((weak)) void matrix_power_down(void) {} | 56 | __attribute__((weak)) void matrix_power_down(void) {} |
61 | bool suspend_wakeup_condition(void) | 57 | bool suspend_wakeup_condition(void) { |
62 | { | ||
63 | matrix_power_up(); | 58 | matrix_power_up(); |
64 | matrix_scan(); | 59 | matrix_scan(); |
65 | matrix_power_down(); | 60 | matrix_power_down(); |
@@ -73,25 +68,20 @@ bool suspend_wakeup_condition(void) | |||
73 | * | 68 | * |
74 | * FIXME: needs doc | 69 | * FIXME: needs doc |
75 | */ | 70 | */ |
76 | __attribute__ ((weak)) | 71 | __attribute__((weak)) void suspend_wakeup_init_user(void) {} |
77 | void suspend_wakeup_init_user(void) { } | ||
78 | 72 | ||
79 | /** \brief run keyboard level code immediately after wakeup | 73 | /** \brief run keyboard level code immediately after wakeup |
80 | * | 74 | * |
81 | * FIXME: needs doc | 75 | * FIXME: needs doc |
82 | */ | 76 | */ |
83 | __attribute__ ((weak)) | 77 | __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } |
84 | void suspend_wakeup_init_kb(void) { | ||
85 | suspend_wakeup_init_user(); | ||
86 | } | ||
87 | 78 | ||
88 | /** \brief suspend wakeup condition | 79 | /** \brief suspend wakeup condition |
89 | * | 80 | * |
90 | * run immediately after wakeup | 81 | * run immediately after wakeup |
91 | * FIXME: needs doc | 82 | * FIXME: needs doc |
92 | */ | 83 | */ |
93 | void suspend_wakeup_init(void) | 84 | void suspend_wakeup_init(void) { |
94 | { | ||
95 | // clear keyboard state | 85 | // clear keyboard state |
96 | // need to do it manually, because we're running from ISR | 86 | // need to do it manually, because we're running from ISR |
97 | // and clear_keyboard() calls print | 87 | // and clear_keyboard() calls print |
@@ -111,5 +101,5 @@ void suspend_wakeup_init(void) | |||
111 | #ifdef BACKLIGHT_ENABLE | 101 | #ifdef BACKLIGHT_ENABLE |
112 | backlight_init(); | 102 | backlight_init(); |
113 | #endif /* BACKLIGHT_ENABLE */ | 103 | #endif /* BACKLIGHT_ENABLE */ |
114 | suspend_wakeup_init_kb(); | 104 | suspend_wakeup_init_kb(); |
115 | } | 105 | } |
diff --git a/tmk_core/common/chibios/timer.c b/tmk_core/common/chibios/timer.c index 473e533ca..1ce9d1d17 100644 --- a/tmk_core/common/chibios/timer.c +++ b/tmk_core/common/chibios/timer.c | |||
@@ -2,40 +2,32 @@ | |||
2 | 2 | ||
3 | #include "timer.h" | 3 | #include "timer.h" |
4 | 4 | ||
5 | static systime_t last_systime = 0; | 5 | static systime_t last_systime = 0; |
6 | static systime_t overflow = 0; | 6 | static systime_t overflow = 0; |
7 | static uint32_t current_time_ms = 0; | 7 | static uint32_t current_time_ms = 0; |
8 | 8 | ||
9 | void timer_init(void) { | 9 | void timer_init(void) { timer_clear(); } |
10 | timer_clear(); | ||
11 | } | ||
12 | 10 | ||
13 | void timer_clear(void) { | 11 | void timer_clear(void) { |
14 | last_systime = chVTGetSystemTime(); | 12 | last_systime = chVTGetSystemTime(); |
15 | overflow = 0; | 13 | overflow = 0; |
16 | current_time_ms = 0; | 14 | current_time_ms = 0; |
17 | } | 15 | } |
18 | 16 | ||
19 | uint16_t timer_read(void) { | 17 | uint16_t timer_read(void) { return (uint16_t)timer_read32(); } |
20 | return (uint16_t)timer_read32(); | ||
21 | } | ||
22 | 18 | ||
23 | uint32_t timer_read32(void) { | 19 | uint32_t timer_read32(void) { |
24 | // Note: We assume that the timer update is called at least once betweeen every wrap around of the system time | 20 | // Note: We assume that the timer update is called at least once betweeen every wrap around of the system time |
25 | systime_t current_systime = chVTGetSystemTime(); | 21 | systime_t current_systime = chVTGetSystemTime(); |
26 | systime_t elapsed = current_systime - last_systime + overflow; | 22 | systime_t elapsed = current_systime - last_systime + overflow; |
27 | uint32_t elapsed_ms = ST2MS(elapsed); | 23 | uint32_t elapsed_ms = ST2MS(elapsed); |
28 | current_time_ms += elapsed_ms; | 24 | current_time_ms += elapsed_ms; |
29 | overflow = elapsed - MS2ST(elapsed_ms); | 25 | overflow = elapsed - MS2ST(elapsed_ms); |
30 | last_systime = current_systime; | 26 | last_systime = current_systime; |
31 | 27 | ||
32 | return current_time_ms; | 28 | return current_time_ms; |
33 | } | 29 | } |
34 | 30 | ||
35 | uint16_t timer_elapsed(uint16_t last) { | 31 | uint16_t timer_elapsed(uint16_t last) { return timer_read() - last; } |
36 | return timer_read() - last; | ||
37 | } | ||
38 | 32 | ||
39 | uint32_t timer_elapsed32(uint32_t last) { | 33 | uint32_t timer_elapsed32(uint32_t last) { return timer_read32() - last; } |
40 | return timer_read32() - last; | ||
41 | } | ||
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c index 949615ecf..8bf72ef25 100644 --- a/tmk_core/common/command.c +++ b/tmk_core/common/command.c | |||
@@ -37,25 +37,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
37 | #include "version.h" | 37 | #include "version.h" |
38 | 38 | ||
39 | #ifdef MOUSEKEY_ENABLE | 39 | #ifdef MOUSEKEY_ENABLE |
40 | #include "mousekey.h" | 40 | # include "mousekey.h" |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #ifdef PROTOCOL_PJRC | 43 | #ifdef PROTOCOL_PJRC |
44 | #include "usb_keyboard.h" | 44 | # include "usb_keyboard.h" |
45 | #ifdef EXTRAKEY_ENABLE | 45 | # ifdef EXTRAKEY_ENABLE |
46 | #include "usb_extra.h" | 46 | # include "usb_extra.h" |
47 | #endif | 47 | # endif |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | #ifdef PROTOCOL_VUSB | 50 | #ifdef PROTOCOL_VUSB |
51 | #include "usbdrv.h" | 51 | # include "usbdrv.h" |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | #ifdef AUDIO_ENABLE | 54 | #ifdef AUDIO_ENABLE |
55 | #include "audio.h" | 55 | # include "audio.h" |
56 | #endif /* AUDIO_ENABLE */ | 56 | #endif /* AUDIO_ENABLE */ |
57 | 57 | ||
58 | |||
59 | static bool command_common(uint8_t code); | 58 | static bool command_common(uint8_t code); |
60 | static void command_common_help(void); | 59 | static void command_common_help(void); |
61 | static void print_version(void); | 60 | static void print_version(void); |
@@ -69,16 +68,12 @@ static void mousekey_console_help(void); | |||
69 | 68 | ||
70 | static void switch_default_layer(uint8_t layer); | 69 | static void switch_default_layer(uint8_t layer); |
71 | 70 | ||
72 | |||
73 | command_state_t command_state = ONESHOT; | 71 | command_state_t command_state = ONESHOT; |
74 | 72 | ||
75 | 73 | bool command_proc(uint8_t code) { | |
76 | bool command_proc(uint8_t code) | ||
77 | { | ||
78 | switch (command_state) { | 74 | switch (command_state) { |
79 | case ONESHOT: | 75 | case ONESHOT: |
80 | if (!IS_COMMAND()) | 76 | if (!IS_COMMAND()) return false; |
81 | return false; | ||
82 | return (command_extra(code) || command_common(code)); | 77 | return (command_extra(code) || command_common(code)); |
83 | break; | 78 | break; |
84 | case CONSOLE: | 79 | case CONSOLE: |
@@ -101,86 +96,63 @@ bool command_proc(uint8_t code) | |||
101 | 96 | ||
102 | /* TODO: Refactoring is needed. */ | 97 | /* TODO: Refactoring is needed. */ |
103 | /* This allows to define extra commands. return false when not processed. */ | 98 | /* This allows to define extra commands. return false when not processed. */ |
104 | bool command_extra(uint8_t code) __attribute__ ((weak)); | 99 | bool command_extra(uint8_t code) __attribute__((weak)); |
105 | bool command_extra(uint8_t code) | 100 | bool command_extra(uint8_t code) { |
106 | { | ||
107 | (void)code; | 101 | (void)code; |
108 | return false; | 102 | return false; |
109 | } | 103 | } |
110 | 104 | ||
111 | bool command_console_extra(uint8_t code) __attribute__ ((weak)); | 105 | bool command_console_extra(uint8_t code) __attribute__((weak)); |
112 | bool command_console_extra(uint8_t code) | 106 | bool command_console_extra(uint8_t code) { |
113 | { | ||
114 | (void)code; | 107 | (void)code; |
115 | return false; | 108 | return false; |
116 | } | 109 | } |
117 | 110 | ||
118 | |||
119 | /*********************************************************** | 111 | /*********************************************************** |
120 | * Command common | 112 | * Command common |
121 | ***********************************************************/ | 113 | ***********************************************************/ |
122 | static void command_common_help(void) | 114 | static void command_common_help(void) { |
123 | { | 115 | print("\n\t- Magic -\n" STR(MAGIC_KEY_DEBUG) ": Debug Message Toggle\n" STR(MAGIC_KEY_DEBUG_MATRIX) ": Matrix Debug Mode Toggle - Show keypresses in matrix grid\n" STR(MAGIC_KEY_DEBUG_KBD) ": Keyboard Debug Toggle - Show keypress report\n" STR(MAGIC_KEY_DEBUG_MOUSE) ": Debug Mouse Toggle\n" STR(MAGIC_KEY_VERSION) ": Version\n" STR(MAGIC_KEY_STATUS) ": Status\n" STR(MAGIC_KEY_CONSOLE) ": Activate Console Mode\n" |
124 | print( "\n\t- Magic -\n" | ||
125 | STR(MAGIC_KEY_DEBUG ) ": Debug Message Toggle\n" | ||
126 | STR(MAGIC_KEY_DEBUG_MATRIX) ": Matrix Debug Mode Toggle - Show keypresses in matrix grid\n" | ||
127 | STR(MAGIC_KEY_DEBUG_KBD ) ": Keyboard Debug Toggle - Show keypress report\n" | ||
128 | STR(MAGIC_KEY_DEBUG_MOUSE ) ": Debug Mouse Toggle\n" | ||
129 | STR(MAGIC_KEY_VERSION ) ": Version\n" | ||
130 | STR(MAGIC_KEY_STATUS ) ": Status\n" | ||
131 | STR(MAGIC_KEY_CONSOLE ) ": Activate Console Mode\n" | ||
132 | 116 | ||
133 | #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM | 117 | #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM |
134 | STR(MAGIC_KEY_LAYER0 ) ": Switch to Layer 0\n" | 118 | STR(MAGIC_KEY_LAYER0) ": Switch to Layer 0\n" STR(MAGIC_KEY_LAYER1) ": Switch to Layer 1\n" STR(MAGIC_KEY_LAYER2) ": Switch to Layer 2\n" STR(MAGIC_KEY_LAYER3) ": Switch to Layer 3\n" STR(MAGIC_KEY_LAYER4) ": Switch to Layer 4\n" STR(MAGIC_KEY_LAYER5) ": Switch to Layer 5\n" STR(MAGIC_KEY_LAYER6) ": Switch to Layer 6\n" STR(MAGIC_KEY_LAYER7) ": Switch to Layer 7\n" STR(MAGIC_KEY_LAYER8) ": Switch to Layer 8\n" STR(MAGIC_KEY_LAYER9) ": Switch to Layer 9\n" |
135 | STR(MAGIC_KEY_LAYER1 ) ": Switch to Layer 1\n" | ||
136 | STR(MAGIC_KEY_LAYER2 ) ": Switch to Layer 2\n" | ||
137 | STR(MAGIC_KEY_LAYER3 ) ": Switch to Layer 3\n" | ||
138 | STR(MAGIC_KEY_LAYER4 ) ": Switch to Layer 4\n" | ||
139 | STR(MAGIC_KEY_LAYER5 ) ": Switch to Layer 5\n" | ||
140 | STR(MAGIC_KEY_LAYER6 ) ": Switch to Layer 6\n" | ||
141 | STR(MAGIC_KEY_LAYER7 ) ": Switch to Layer 7\n" | ||
142 | STR(MAGIC_KEY_LAYER8 ) ": Switch to Layer 8\n" | ||
143 | STR(MAGIC_KEY_LAYER9 ) ": Switch to Layer 9\n" | ||
144 | #endif | 119 | #endif |
145 | 120 | ||
146 | #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS | 121 | #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS |
147 | "F1-F10: Switch to Layer 0-9 (F10 = L0)\n" | 122 | "F1-F10: Switch to Layer 0-9 (F10 = L0)\n" |
148 | #endif | 123 | #endif |
149 | 124 | ||
150 | #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS | 125 | #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS |
151 | "0-9: Switch to Layer 0-9\n" | 126 | "0-9: Switch to Layer 0-9\n" |
152 | #endif | 127 | #endif |
153 | 128 | ||
154 | STR(MAGIC_KEY_LAYER0_ALT ) ": Switch to Layer 0 (alternate)\n" | 129 | STR(MAGIC_KEY_LAYER0_ALT) ": Switch to Layer 0 (alternate)\n" |
155 | 130 | ||
156 | STR(MAGIC_KEY_BOOTLOADER ) ": Jump to Bootloader\n" | 131 | STR(MAGIC_KEY_BOOTLOADER) ": Jump to Bootloader\n" STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n" |
157 | STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n" | ||
158 | 132 | ||
159 | #ifdef KEYBOARD_LOCK_ENABLE | 133 | #ifdef KEYBOARD_LOCK_ENABLE |
160 | STR(MAGIC_KEY_LOCK ) ": Lock Keyboard\n" | 134 | STR(MAGIC_KEY_LOCK) ": Lock Keyboard\n" |
161 | #endif | 135 | #endif |
162 | 136 | ||
163 | STR(MAGIC_KEY_EEPROM ) ": Print EEPROM Settings\n" | 137 | STR(MAGIC_KEY_EEPROM) ": Print EEPROM Settings\n" STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n" |
164 | STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n" | ||
165 | 138 | ||
166 | #ifdef NKRO_ENABLE | 139 | #ifdef NKRO_ENABLE |
167 | STR(MAGIC_KEY_NKRO ) ": NKRO Toggle\n" | 140 | STR(MAGIC_KEY_NKRO) ": NKRO Toggle\n" |
168 | #endif | 141 | #endif |
169 | 142 | ||
170 | #ifdef SLEEP_LED_ENABLE | 143 | #ifdef SLEEP_LED_ENABLE |
171 | STR(MAGIC_KEY_SLEEP_LED ) ": Sleep LED Test\n" | 144 | STR(MAGIC_KEY_SLEEP_LED) ": Sleep LED Test\n" |
172 | #endif | 145 | #endif |
173 | ); | 146 | ); |
174 | } | 147 | } |
175 | 148 | ||
176 | static void print_version(void) | 149 | static void print_version(void) { |
177 | { | 150 | // print version & information |
178 | // print version & information | ||
179 | print("\n\t- Version -\n"); | 151 | print("\n\t- Version -\n"); |
180 | print("DESC: " STR(DESCRIPTION) "\n"); | 152 | print("DESC: " STR(DESCRIPTION) "\n"); |
181 | print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " | 153 | print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " |
182 | "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " | 154 | "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " |
183 | "VER: " STR(DEVICE_VER) "\n"); | 155 | "VER: " STR(DEVICE_VER) "\n"); |
184 | #ifdef SKIP_VERSION | 156 | #ifdef SKIP_VERSION |
185 | print("BUILD: (" __DATE__ ")\n"); | 157 | print("BUILD: (" __DATE__ ")\n"); |
186 | #else | 158 | #else |
@@ -191,51 +163,48 @@ static void print_version(void) | |||
191 | print("OPTIONS:" | 163 | print("OPTIONS:" |
192 | 164 | ||
193 | #ifdef PROTOCOL_PJRC | 165 | #ifdef PROTOCOL_PJRC |
194 | " PJRC" | 166 | " PJRC" |
195 | #endif | 167 | #endif |
196 | #ifdef PROTOCOL_LUFA | 168 | #ifdef PROTOCOL_LUFA |
197 | " LUFA" | 169 | " LUFA" |
198 | #endif | 170 | #endif |
199 | #ifdef PROTOCOL_VUSB | 171 | #ifdef PROTOCOL_VUSB |
200 | " VUSB" | 172 | " VUSB" |
201 | #endif | 173 | #endif |
202 | #ifdef BOOTMAGIC_ENABLE | 174 | #ifdef BOOTMAGIC_ENABLE |
203 | " BOOTMAGIC" | 175 | " BOOTMAGIC" |
204 | #endif | 176 | #endif |
205 | #ifdef MOUSEKEY_ENABLE | 177 | #ifdef MOUSEKEY_ENABLE |
206 | " MOUSEKEY" | 178 | " MOUSEKEY" |
207 | #endif | 179 | #endif |
208 | #ifdef EXTRAKEY_ENABLE | 180 | #ifdef EXTRAKEY_ENABLE |
209 | " EXTRAKEY" | 181 | " EXTRAKEY" |
210 | #endif | 182 | #endif |
211 | #ifdef CONSOLE_ENABLE | 183 | #ifdef CONSOLE_ENABLE |
212 | " CONSOLE" | 184 | " CONSOLE" |
213 | #endif | 185 | #endif |
214 | #ifdef COMMAND_ENABLE | 186 | #ifdef COMMAND_ENABLE |
215 | " COMMAND" | 187 | " COMMAND" |
216 | #endif | 188 | #endif |
217 | #ifdef NKRO_ENABLE | 189 | #ifdef NKRO_ENABLE |
218 | " NKRO" | 190 | " NKRO" |
219 | #endif | 191 | #endif |
220 | #ifdef KEYMAP_SECTION_ENABLE | 192 | #ifdef KEYMAP_SECTION_ENABLE |
221 | " KEYMAP_SECTION" | 193 | " KEYMAP_SECTION" |
222 | #endif | 194 | #endif |
223 | 195 | ||
224 | " " STR(BOOTLOADER_SIZE) "\n"); | 196 | " " STR(BOOTLOADER_SIZE) "\n"); |
225 | 197 | ||
226 | print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) | 198 | print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) |
227 | #if defined(__AVR__) | 199 | #if defined(__AVR__) |
228 | " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ | 200 | " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ " AVR_ARCH: avr" STR(__AVR_ARCH__) |
229 | " AVR_ARCH: avr" STR(__AVR_ARCH__) | ||
230 | #endif | 201 | #endif |
231 | "\n"); | 202 | "\n"); |
232 | 203 | ||
233 | return; | 204 | return; |
234 | } | 205 | } |
235 | 206 | ||
236 | static void print_status(void) | 207 | static void print_status(void) { |
237 | { | ||
238 | |||
239 | print("\n\t- Status -\n"); | 208 | print("\n\t- Status -\n"); |
240 | 209 | ||
241 | print_val_hex8(host_keyboard_leds()); | 210 | print_val_hex8(host_keyboard_leds()); |
@@ -258,67 +227,101 @@ static void print_status(void) | |||
258 | #endif | 227 | #endif |
259 | 228 | ||
260 | #ifdef PROTOCOL_PJRC | 229 | #ifdef PROTOCOL_PJRC |
261 | # if USB_COUNT_SOF | 230 | # if USB_COUNT_SOF |
262 | print_val_hex8(usbSofCount); | 231 | print_val_hex8(usbSofCount); |
263 | # endif | 232 | # endif |
264 | #endif | 233 | #endif |
265 | return; | 234 | return; |
266 | } | 235 | } |
267 | 236 | ||
268 | static void print_eeconfig(void) | 237 | static void print_eeconfig(void) { |
269 | { | ||
270 | |||
271 | // Print these variables if NO_PRINT or USER_PRINT are not defined. | 238 | // Print these variables if NO_PRINT or USER_PRINT are not defined. |
272 | #if !defined(NO_PRINT) && !defined(USER_PRINT) | 239 | #if !defined(NO_PRINT) && !defined(USER_PRINT) |
273 | 240 | ||
274 | print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n"); | 241 | print("default_layer: "); |
242 | print_dec(eeconfig_read_default_layer()); | ||
243 | print("\n"); | ||
275 | 244 | ||
276 | debug_config_t dc; | 245 | debug_config_t dc; |
277 | dc.raw = eeconfig_read_debug(); | 246 | dc.raw = eeconfig_read_debug(); |
278 | print("debug_config.raw: "); print_hex8(dc.raw); print("\n"); | 247 | print("debug_config.raw: "); |
279 | print(".enable: "); print_dec(dc.enable); print("\n"); | 248 | print_hex8(dc.raw); |
280 | print(".matrix: "); print_dec(dc.matrix); print("\n"); | 249 | print("\n"); |
281 | print(".keyboard: "); print_dec(dc.keyboard); print("\n"); | 250 | print(".enable: "); |
282 | print(".mouse: "); print_dec(dc.mouse); print("\n"); | 251 | print_dec(dc.enable); |
252 | print("\n"); | ||
253 | print(".matrix: "); | ||
254 | print_dec(dc.matrix); | ||
255 | print("\n"); | ||
256 | print(".keyboard: "); | ||
257 | print_dec(dc.keyboard); | ||
258 | print("\n"); | ||
259 | print(".mouse: "); | ||
260 | print_dec(dc.mouse); | ||
261 | print("\n"); | ||
283 | 262 | ||
284 | keymap_config_t kc; | 263 | keymap_config_t kc; |
285 | kc.raw = eeconfig_read_keymap(); | 264 | kc.raw = eeconfig_read_keymap(); |
286 | print("keymap_config.raw: "); print_hex8(kc.raw); print("\n"); | 265 | print("keymap_config.raw: "); |
287 | print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n"); | 266 | print_hex8(kc.raw); |
288 | print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n"); | 267 | print("\n"); |
289 | print(".swap_lctl_lgui: "); print_dec(kc.swap_lctl_lgui); print("\n"); | 268 | print(".swap_control_capslock: "); |
290 | print(".swap_rctl_rgui: "); print_dec(kc.swap_rctl_rgui); print("\n"); | 269 | print_dec(kc.swap_control_capslock); |
291 | print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n"); | 270 | print("\n"); |
292 | print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n"); | 271 | print(".capslock_to_control: "); |
293 | print(".no_gui: "); print_dec(kc.no_gui); print("\n"); | 272 | print_dec(kc.capslock_to_control); |
294 | print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n"); | 273 | print("\n"); |
295 | print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n"); | 274 | print(".swap_lctl_lgui: "); |
296 | print(".nkro: "); print_dec(kc.nkro); print("\n"); | 275 | print_dec(kc.swap_lctl_lgui); |
297 | 276 | print("\n"); | |
298 | #ifdef BACKLIGHT_ENABLE | 277 | print(".swap_rctl_rgui: "); |
278 | print_dec(kc.swap_rctl_rgui); | ||
279 | print("\n"); | ||
280 | print(".swap_lalt_lgui: "); | ||
281 | print_dec(kc.swap_lalt_lgui); | ||
282 | print("\n"); | ||
283 | print(".swap_ralt_rgui: "); | ||
284 | print_dec(kc.swap_ralt_rgui); | ||
285 | print("\n"); | ||
286 | print(".no_gui: "); | ||
287 | print_dec(kc.no_gui); | ||
288 | print("\n"); | ||
289 | print(".swap_grave_esc: "); | ||
290 | print_dec(kc.swap_grave_esc); | ||
291 | print("\n"); | ||
292 | print(".swap_backslash_backspace: "); | ||
293 | print_dec(kc.swap_backslash_backspace); | ||
294 | print("\n"); | ||
295 | print(".nkro: "); | ||
296 | print_dec(kc.nkro); | ||
297 | print("\n"); | ||
298 | |||
299 | # ifdef BACKLIGHT_ENABLE | ||
299 | backlight_config_t bc; | 300 | backlight_config_t bc; |
300 | bc.raw = eeconfig_read_backlight(); | 301 | bc.raw = eeconfig_read_backlight(); |
301 | print("backlight_config.raw: "); print_hex8(bc.raw); print("\n"); | 302 | print("backlight_config.raw: "); |
302 | print(".enable: "); print_dec(bc.enable); print("\n"); | 303 | print_hex8(bc.raw); |
303 | print(".level: "); print_dec(bc.level); print("\n"); | 304 | print("\n"); |
304 | #endif /* BACKLIGHT_ENABLE */ | 305 | print(".enable: "); |
306 | print_dec(bc.enable); | ||
307 | print("\n"); | ||
308 | print(".level: "); | ||
309 | print_dec(bc.level); | ||
310 | print("\n"); | ||
311 | # endif /* BACKLIGHT_ENABLE */ | ||
305 | 312 | ||
306 | #endif /* !NO_PRINT */ | 313 | #endif /* !NO_PRINT */ |
307 | |||
308 | } | 314 | } |
309 | 315 | ||
310 | static bool command_common(uint8_t code) | 316 | static bool command_common(uint8_t code) { |
311 | { | ||
312 | |||
313 | #ifdef KEYBOARD_LOCK_ENABLE | 317 | #ifdef KEYBOARD_LOCK_ENABLE |
314 | static host_driver_t *host_driver = 0; | 318 | static host_driver_t *host_driver = 0; |
315 | #endif | 319 | #endif |
316 | 320 | ||
317 | switch (code) { | 321 | switch (code) { |
318 | |||
319 | #ifdef SLEEP_LED_ENABLE | 322 | #ifdef SLEEP_LED_ENABLE |
320 | 323 | ||
321 | // test breathing sleep LED | 324 | // test breathing sleep LED |
322 | case MAGIC_KC(MAGIC_KEY_SLEEP_LED): | 325 | case MAGIC_KC(MAGIC_KEY_SLEEP_LED): |
323 | print("Sleep LED Test\n"); | 326 | print("Sleep LED Test\n"); |
324 | sleep_led_toggle(); | 327 | sleep_led_toggle(); |
@@ -326,21 +329,21 @@ static bool command_common(uint8_t code) | |||
326 | break; | 329 | break; |
327 | #endif | 330 | #endif |
328 | 331 | ||
329 | // print stored eeprom config | 332 | // print stored eeprom config |
330 | case MAGIC_KC(MAGIC_KEY_EEPROM): | 333 | case MAGIC_KC(MAGIC_KEY_EEPROM): |
331 | print("eeconfig:\n"); | 334 | print("eeconfig:\n"); |
332 | print_eeconfig(); | 335 | print_eeconfig(); |
333 | break; | 336 | break; |
334 | 337 | ||
335 | // clear eeprom | 338 | // clear eeprom |
336 | case MAGIC_KC(MAGIC_KEY_EEPROM_CLEAR): | 339 | case MAGIC_KC(MAGIC_KEY_EEPROM_CLEAR): |
337 | print("Clearing EEPROM\n"); | 340 | print("Clearing EEPROM\n"); |
338 | eeconfig_init(); | 341 | eeconfig_init(); |
339 | break; | 342 | break; |
340 | 343 | ||
341 | #ifdef KEYBOARD_LOCK_ENABLE | 344 | #ifdef KEYBOARD_LOCK_ENABLE |
342 | 345 | ||
343 | // lock/unlock keyboard | 346 | // lock/unlock keyboard |
344 | case MAGIC_KC(MAGIC_KEY_LOCK): | 347 | case MAGIC_KC(MAGIC_KEY_LOCK): |
345 | if (host_get_driver()) { | 348 | if (host_get_driver()) { |
346 | host_driver = host_get_driver(); | 349 | host_driver = host_get_driver(); |
@@ -354,13 +357,13 @@ static bool command_common(uint8_t code) | |||
354 | break; | 357 | break; |
355 | #endif | 358 | #endif |
356 | 359 | ||
357 | // print help | 360 | // print help |
358 | case MAGIC_KC(MAGIC_KEY_HELP): | 361 | case MAGIC_KC(MAGIC_KEY_HELP): |
359 | case MAGIC_KC(MAGIC_KEY_HELP_ALT): | 362 | case MAGIC_KC(MAGIC_KEY_HELP_ALT): |
360 | command_common_help(); | 363 | command_common_help(); |
361 | break; | 364 | break; |
362 | 365 | ||
363 | // activate console | 366 | // activate console |
364 | case MAGIC_KC(MAGIC_KEY_CONSOLE): | 367 | case MAGIC_KC(MAGIC_KEY_CONSOLE): |
365 | debug_matrix = false; | 368 | debug_matrix = false; |
366 | debug_keyboard = false; | 369 | debug_keyboard = false; |
@@ -374,15 +377,15 @@ static bool command_common(uint8_t code) | |||
374 | // jump to bootloader | 377 | // jump to bootloader |
375 | case MAGIC_KC(MAGIC_KEY_BOOTLOADER): | 378 | case MAGIC_KC(MAGIC_KEY_BOOTLOADER): |
376 | case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT): | 379 | case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT): |
377 | clear_keyboard(); // clear to prevent stuck keys | 380 | clear_keyboard(); // clear to prevent stuck keys |
378 | print("\n\nJumping to bootloader... "); | 381 | print("\n\nJumping to bootloader... "); |
379 | #ifdef AUDIO_ENABLE | 382 | #ifdef AUDIO_ENABLE |
380 | stop_all_notes(); | 383 | stop_all_notes(); |
381 | shutdown_user(); | 384 | shutdown_user(); |
382 | #else | 385 | #else |
383 | wait_ms(1000); | 386 | wait_ms(1000); |
384 | #endif | 387 | #endif |
385 | bootloader_jump(); // not return | 388 | bootloader_jump(); // not return |
386 | break; | 389 | break; |
387 | 390 | ||
388 | // debug toggle | 391 | // debug toggle |
@@ -427,25 +430,25 @@ static bool command_common(uint8_t code) | |||
427 | print("\nmouse: on\n"); | 430 | print("\nmouse: on\n"); |
428 | debug_enable = true; | 431 | debug_enable = true; |
429 | } else { | 432 | } else { |
430 | print("\nmouse: off\n"); | 433 | print("\nmouse: off\n"); |
431 | } | 434 | } |
432 | break; | 435 | break; |
433 | 436 | ||
434 | // print version | 437 | // print version |
435 | case MAGIC_KC(MAGIC_KEY_VERSION): | 438 | case MAGIC_KC(MAGIC_KEY_VERSION): |
436 | print_version(); | 439 | print_version(); |
437 | break; | 440 | break; |
438 | 441 | ||
439 | // print status | 442 | // print status |
440 | case MAGIC_KC(MAGIC_KEY_STATUS): | 443 | case MAGIC_KC(MAGIC_KEY_STATUS): |
441 | print_status(); | 444 | print_status(); |
442 | break; | 445 | break; |
443 | 446 | ||
444 | #ifdef NKRO_ENABLE | 447 | #ifdef NKRO_ENABLE |
445 | 448 | ||
446 | // NKRO toggle | 449 | // NKRO toggle |
447 | case MAGIC_KC(MAGIC_KEY_NKRO): | 450 | case MAGIC_KC(MAGIC_KEY_NKRO): |
448 | clear_keyboard(); // clear to prevent stuck keys | 451 | clear_keyboard(); // clear to prevent stuck keys |
449 | keymap_config.nkro = !keymap_config.nkro; | 452 | keymap_config.nkro = !keymap_config.nkro; |
450 | if (keymap_config.nkro) { | 453 | if (keymap_config.nkro) { |
451 | print("NKRO: on\n"); | 454 | print("NKRO: on\n"); |
@@ -455,56 +458,55 @@ static bool command_common(uint8_t code) | |||
455 | break; | 458 | break; |
456 | #endif | 459 | #endif |
457 | 460 | ||
458 | // switch layers | 461 | // switch layers |
459 | 462 | ||
460 | case MAGIC_KC(MAGIC_KEY_LAYER0_ALT): | 463 | case MAGIC_KC(MAGIC_KEY_LAYER0_ALT): |
461 | switch_default_layer(0); | 464 | switch_default_layer(0); |
462 | break; | 465 | break; |
463 | 466 | ||
464 | #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM | 467 | #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM |
465 | 468 | ||
466 | case MAGIC_KC(MAGIC_KEY_LAYER0): | 469 | case MAGIC_KC(MAGIC_KEY_LAYER0): |
467 | switch_default_layer(0); | 470 | switch_default_layer(0); |
468 | break; | 471 | break; |
469 | 472 | ||
470 | case MAGIC_KC(MAGIC_KEY_LAYER1): | 473 | case MAGIC_KC(MAGIC_KEY_LAYER1): |
471 | switch_default_layer(1); | 474 | switch_default_layer(1); |
472 | break; | 475 | break; |
473 | 476 | ||
474 | case MAGIC_KC(MAGIC_KEY_LAYER2): | 477 | case MAGIC_KC(MAGIC_KEY_LAYER2): |
475 | switch_default_layer(2); | 478 | switch_default_layer(2); |
476 | break; | 479 | break; |
477 | 480 | ||
478 | case MAGIC_KC(MAGIC_KEY_LAYER3): | 481 | case MAGIC_KC(MAGIC_KEY_LAYER3): |
479 | switch_default_layer(3); | 482 | switch_default_layer(3); |
480 | break; | 483 | break; |
481 | 484 | ||
482 | case MAGIC_KC(MAGIC_KEY_LAYER4): | 485 | case MAGIC_KC(MAGIC_KEY_LAYER4): |
483 | switch_default_layer(4); | 486 | switch_default_layer(4); |
484 | break; | 487 | break; |
485 | 488 | ||
486 | case MAGIC_KC(MAGIC_KEY_LAYER5): | 489 | case MAGIC_KC(MAGIC_KEY_LAYER5): |
487 | switch_default_layer(5); | 490 | switch_default_layer(5); |
488 | break; | 491 | break; |
489 | 492 | ||
490 | case MAGIC_KC(MAGIC_KEY_LAYER6): | 493 | case MAGIC_KC(MAGIC_KEY_LAYER6): |
491 | switch_default_layer(6); | 494 | switch_default_layer(6); |
492 | break; | 495 | break; |
493 | 496 | ||
494 | case MAGIC_KC(MAGIC_KEY_LAYER7): | 497 | case MAGIC_KC(MAGIC_KEY_LAYER7): |
495 | switch_default_layer(7); | 498 | switch_default_layer(7); |
496 | break; | 499 | break; |
497 | 500 | ||
498 | case MAGIC_KC(MAGIC_KEY_LAYER8): | 501 | case MAGIC_KC(MAGIC_KEY_LAYER8): |
499 | switch_default_layer(8); | 502 | switch_default_layer(8); |
500 | break; | 503 | break; |
501 | 504 | ||
502 | case MAGIC_KC(MAGIC_KEY_LAYER9): | 505 | case MAGIC_KC(MAGIC_KEY_LAYER9): |
503 | switch_default_layer(9); | 506 | switch_default_layer(9); |
504 | break; | 507 | break; |
505 | #endif | 508 | #endif |
506 | 509 | ||
507 | |||
508 | #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS | 510 | #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS |
509 | 511 | ||
510 | case KC_F1 ... KC_F9: | 512 | case KC_F1 ... KC_F9: |
@@ -532,12 +534,10 @@ static bool command_common(uint8_t code) | |||
532 | return true; | 534 | return true; |
533 | } | 535 | } |
534 | 536 | ||
535 | |||
536 | /*********************************************************** | 537 | /*********************************************************** |
537 | * Command console | 538 | * Command console |
538 | ***********************************************************/ | 539 | ***********************************************************/ |
539 | static void command_console_help(void) | 540 | static void command_console_help(void) { |
540 | { | ||
541 | print("\n\t- Console -\n" | 541 | print("\n\t- Console -\n" |
542 | "ESC/q: quit\n" | 542 | "ESC/q: quit\n" |
543 | #ifdef MOUSEKEY_ENABLE | 543 | #ifdef MOUSEKEY_ENABLE |
@@ -546,8 +546,7 @@ static void command_console_help(void) | |||
546 | ); | 546 | ); |
547 | } | 547 | } |
548 | 548 | ||
549 | static bool command_console(uint8_t code) | 549 | static bool command_console(uint8_t code) { |
550 | { | ||
551 | switch (code) { | 550 | switch (code) { |
552 | case KC_H: | 551 | case KC_H: |
553 | case KC_SLASH: /* ? */ | 552 | case KC_SLASH: /* ? */ |
@@ -572,32 +571,40 @@ static bool command_console(uint8_t code) | |||
572 | return true; | 571 | return true; |
573 | } | 572 | } |
574 | 573 | ||
575 | |||
576 | #ifdef MOUSEKEY_ENABLE | 574 | #ifdef MOUSEKEY_ENABLE |
577 | /*********************************************************** | 575 | /*********************************************************** |
578 | * Mousekey console | 576 | * Mousekey console |
579 | ***********************************************************/ | 577 | ***********************************************************/ |
580 | static uint8_t mousekey_param = 0; | 578 | static uint8_t mousekey_param = 0; |
581 | 579 | ||
582 | static void mousekey_param_print(void) | 580 | static void mousekey_param_print(void) { |
583 | { | ||
584 | // Print these variables if NO_PRINT or USER_PRINT are not defined. | 581 | // Print these variables if NO_PRINT or USER_PRINT are not defined. |
585 | #if !defined(NO_PRINT) && !defined(USER_PRINT) | 582 | # if !defined(NO_PRINT) && !defined(USER_PRINT) |
586 | print("\n\t- Values -\n"); | 583 | print("\n\t- Values -\n"); |
587 | print("1: delay(*10ms): "); pdec(mk_delay); print("\n"); | 584 | print("1: delay(*10ms): "); |
588 | print("2: interval(ms): "); pdec(mk_interval); print("\n"); | 585 | pdec(mk_delay); |
589 | print("3: max_speed: "); pdec(mk_max_speed); print("\n"); | 586 | print("\n"); |
590 | print("4: time_to_max: "); pdec(mk_time_to_max); print("\n"); | 587 | print("2: interval(ms): "); |
591 | print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n"); | 588 | pdec(mk_interval); |
592 | print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n"); | 589 | print("\n"); |
593 | #endif /* !NO_PRINT */ | 590 | print("3: max_speed: "); |
594 | 591 | pdec(mk_max_speed); | |
592 | print("\n"); | ||
593 | print("4: time_to_max: "); | ||
594 | pdec(mk_time_to_max); | ||
595 | print("\n"); | ||
596 | print("5: wheel_max_speed: "); | ||
597 | pdec(mk_wheel_max_speed); | ||
598 | print("\n"); | ||
599 | print("6: wheel_time_to_max: "); | ||
600 | pdec(mk_wheel_time_to_max); | ||
601 | print("\n"); | ||
602 | # endif /* !NO_PRINT */ | ||
595 | } | 603 | } |
596 | 604 | ||
597 | //#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); | 605 | //#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); |
598 | #define PRINT_SET_VAL(v) xprintf(#v " = %d\n", (v)) | 606 | # define PRINT_SET_VAL(v) xprintf(# v " = %d\n", (v)) |
599 | static void mousekey_param_inc(uint8_t param, uint8_t inc) | 607 | static void mousekey_param_inc(uint8_t param, uint8_t inc) { |
600 | { | ||
601 | switch (param) { | 608 | switch (param) { |
602 | case 1: | 609 | case 1: |
603 | if (mk_delay + inc < UINT8_MAX) | 610 | if (mk_delay + inc < UINT8_MAX) |
@@ -644,8 +651,7 @@ static void mousekey_param_inc(uint8_t param, uint8_t inc) | |||
644 | } | 651 | } |
645 | } | 652 | } |
646 | 653 | ||
647 | static void mousekey_param_dec(uint8_t param, uint8_t dec) | 654 | static void mousekey_param_dec(uint8_t param, uint8_t dec) { |
648 | { | ||
649 | switch (param) { | 655 | switch (param) { |
650 | case 1: | 656 | case 1: |
651 | if (mk_delay > dec) | 657 | if (mk_delay > dec) |
@@ -692,8 +698,7 @@ static void mousekey_param_dec(uint8_t param, uint8_t dec) | |||
692 | } | 698 | } |
693 | } | 699 | } |
694 | 700 | ||
695 | static void mousekey_console_help(void) | 701 | static void mousekey_console_help(void) { |
696 | { | ||
697 | print("\n\t- Mousekey -\n" | 702 | print("\n\t- Mousekey -\n" |
698 | "ESC/q: quit\n" | 703 | "ESC/q: quit\n" |
699 | "1: delay(*10ms)\n" | 704 | "1: delay(*10ms)\n" |
@@ -712,11 +717,11 @@ static void mousekey_console_help(void) | |||
712 | "\n" | 717 | "\n" |
713 | "speed = delta * max_speed * (repeat / time_to_max)\n"); | 718 | "speed = delta * max_speed * (repeat / time_to_max)\n"); |
714 | xprintf("where delta: cursor=%d, wheel=%d\n" | 719 | xprintf("where delta: cursor=%d, wheel=%d\n" |
715 | "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA); | 720 | "See http://en.wikipedia.org/wiki/Mouse_keys\n", |
721 | MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA); | ||
716 | } | 722 | } |
717 | 723 | ||
718 | static bool mousekey_console(uint8_t code) | 724 | static bool mousekey_console(uint8_t code) { |
719 | { | ||
720 | switch (code) { | 725 | switch (code) { |
721 | case KC_H: | 726 | case KC_H: |
722 | case KC_SLASH: /* ? */ | 727 | case KC_SLASH: /* ? */ |
@@ -756,11 +761,11 @@ static bool mousekey_console(uint8_t code) | |||
756 | mousekey_param_dec(mousekey_param, 10); | 761 | mousekey_param_dec(mousekey_param, 10); |
757 | break; | 762 | break; |
758 | case KC_D: | 763 | case KC_D: |
759 | mk_delay = MOUSEKEY_DELAY/10; | 764 | mk_delay = MOUSEKEY_DELAY / 10; |
760 | mk_interval = MOUSEKEY_INTERVAL; | 765 | mk_interval = MOUSEKEY_INTERVAL; |
761 | mk_max_speed = MOUSEKEY_MAX_SPEED; | 766 | mk_max_speed = MOUSEKEY_MAX_SPEED; |
762 | mk_time_to_max = MOUSEKEY_TIME_TO_MAX; | 767 | mk_time_to_max = MOUSEKEY_TIME_TO_MAX; |
763 | mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; | 768 | mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; |
764 | mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; | 769 | mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; |
765 | print("set default\n"); | 770 | print("set default\n"); |
766 | break; | 771 | break; |
@@ -771,36 +776,43 @@ static bool mousekey_console(uint8_t code) | |||
771 | if (mousekey_param) { | 776 | if (mousekey_param) { |
772 | xprintf("M%d> ", mousekey_param); | 777 | xprintf("M%d> ", mousekey_param); |
773 | } else { | 778 | } else { |
774 | print("M>" ); | 779 | print("M>"); |
775 | } | 780 | } |
776 | return true; | 781 | return true; |
777 | } | 782 | } |
778 | #endif | 783 | #endif |
779 | 784 | ||
780 | |||
781 | /*********************************************************** | 785 | /*********************************************************** |
782 | * Utilities | 786 | * Utilities |
783 | ***********************************************************/ | 787 | ***********************************************************/ |
784 | uint8_t numkey2num(uint8_t code) | 788 | uint8_t numkey2num(uint8_t code) { |
785 | { | ||
786 | switch (code) { | 789 | switch (code) { |
787 | case KC_1: return 1; | 790 | case KC_1: |
788 | case KC_2: return 2; | 791 | return 1; |
789 | case KC_3: return 3; | 792 | case KC_2: |
790 | case KC_4: return 4; | 793 | return 2; |
791 | case KC_5: return 5; | 794 | case KC_3: |
792 | case KC_6: return 6; | 795 | return 3; |
793 | case KC_7: return 7; | 796 | case KC_4: |
794 | case KC_8: return 8; | 797 | return 4; |
795 | case KC_9: return 9; | 798 | case KC_5: |
796 | case KC_0: return 0; | 799 | return 5; |
800 | case KC_6: | ||
801 | return 6; | ||
802 | case KC_7: | ||
803 | return 7; | ||
804 | case KC_8: | ||
805 | return 8; | ||
806 | case KC_9: | ||
807 | return 9; | ||
808 | case KC_0: | ||
809 | return 0; | ||
797 | } | 810 | } |
798 | return 0; | 811 | return 0; |
799 | } | 812 | } |
800 | 813 | ||
801 | static void switch_default_layer(uint8_t layer) | 814 | static void switch_default_layer(uint8_t layer) { |
802 | { | ||
803 | xprintf("L%d\n", layer); | 815 | xprintf("L%d\n", layer); |
804 | default_layer_set(1UL<<layer); | 816 | default_layer_set(1UL << layer); |
805 | clear_keyboard(); | 817 | clear_keyboard(); |
806 | } | 818 | } |
diff --git a/tmk_core/common/command.h b/tmk_core/common/command.h index e6e67fae4..4f77be085 100644 --- a/tmk_core/common/command.h +++ b/tmk_core/common/command.h | |||
@@ -29,135 +29,135 @@ bool command_console_extra(uint8_t code); | |||
29 | 29 | ||
30 | #ifdef COMMAND_ENABLE | 30 | #ifdef COMMAND_ENABLE |
31 | uint8_t numkey2num(uint8_t code); | 31 | uint8_t numkey2num(uint8_t code); |
32 | bool command_proc(uint8_t code); | 32 | bool command_proc(uint8_t code); |
33 | #else | 33 | #else |
34 | #define command_proc(code) false | 34 | # define command_proc(code) false |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #ifndef IS_COMMAND | 37 | #ifndef IS_COMMAND |
38 | #define IS_COMMAND() (get_mods() == MOD_MASK_SHIFT) | 38 | # define IS_COMMAND() (get_mods() == MOD_MASK_SHIFT) |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | #ifndef MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS | 41 | #ifndef MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS |
42 | #define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS true | 42 | # define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS true |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #ifndef MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS | 45 | #ifndef MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS |
46 | #define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS true | 46 | # define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS true |
47 | #endif | 47 | #endif |
48 | 48 | ||
49 | #ifndef MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM | 49 | #ifndef MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM |
50 | #define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM false | 50 | # define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM false |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | #ifndef MAGIC_KEY_HELP | 53 | #ifndef MAGIC_KEY_HELP |
54 | #define MAGIC_KEY_HELP H | 54 | # define MAGIC_KEY_HELP H |
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | #ifndef MAGIC_KEY_HELP_ALT | 57 | #ifndef MAGIC_KEY_HELP_ALT |
58 | #define MAGIC_KEY_HELP_ALT SLASH | 58 | # define MAGIC_KEY_HELP_ALT SLASH |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | #ifndef MAGIC_KEY_DEBUG | 61 | #ifndef MAGIC_KEY_DEBUG |
62 | #define MAGIC_KEY_DEBUG D | 62 | # define MAGIC_KEY_DEBUG D |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | #ifndef MAGIC_KEY_DEBUG_MATRIX | 65 | #ifndef MAGIC_KEY_DEBUG_MATRIX |
66 | #define MAGIC_KEY_DEBUG_MATRIX X | 66 | # define MAGIC_KEY_DEBUG_MATRIX X |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | #ifndef MAGIC_KEY_DEBUG_KBD | 69 | #ifndef MAGIC_KEY_DEBUG_KBD |
70 | #define MAGIC_KEY_DEBUG_KBD K | 70 | # define MAGIC_KEY_DEBUG_KBD K |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | #ifndef MAGIC_KEY_DEBUG_MOUSE | 73 | #ifndef MAGIC_KEY_DEBUG_MOUSE |
74 | #define MAGIC_KEY_DEBUG_MOUSE M | 74 | # define MAGIC_KEY_DEBUG_MOUSE M |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | #ifndef MAGIC_KEY_VERSION | 77 | #ifndef MAGIC_KEY_VERSION |
78 | #define MAGIC_KEY_VERSION V | 78 | # define MAGIC_KEY_VERSION V |
79 | #endif | 79 | #endif |
80 | 80 | ||
81 | #ifndef MAGIC_KEY_STATUS | 81 | #ifndef MAGIC_KEY_STATUS |
82 | #define MAGIC_KEY_STATUS S | 82 | # define MAGIC_KEY_STATUS S |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | #ifndef MAGIC_KEY_CONSOLE | 85 | #ifndef MAGIC_KEY_CONSOLE |
86 | #define MAGIC_KEY_CONSOLE C | 86 | # define MAGIC_KEY_CONSOLE C |
87 | #endif | 87 | #endif |
88 | 88 | ||
89 | #ifndef MAGIC_KEY_LAYER0 | 89 | #ifndef MAGIC_KEY_LAYER0 |
90 | #define MAGIC_KEY_LAYER0 0 | 90 | # define MAGIC_KEY_LAYER0 0 |
91 | #endif | 91 | #endif |
92 | 92 | ||
93 | #ifndef MAGIC_KEY_LAYER0_ALT | 93 | #ifndef MAGIC_KEY_LAYER0_ALT |
94 | #define MAGIC_KEY_LAYER0_ALT GRAVE | 94 | # define MAGIC_KEY_LAYER0_ALT GRAVE |
95 | #endif | 95 | #endif |
96 | 96 | ||
97 | #ifndef MAGIC_KEY_LAYER1 | 97 | #ifndef MAGIC_KEY_LAYER1 |
98 | #define MAGIC_KEY_LAYER1 1 | 98 | # define MAGIC_KEY_LAYER1 1 |
99 | #endif | 99 | #endif |
100 | 100 | ||
101 | #ifndef MAGIC_KEY_LAYER2 | 101 | #ifndef MAGIC_KEY_LAYER2 |
102 | #define MAGIC_KEY_LAYER2 2 | 102 | # define MAGIC_KEY_LAYER2 2 |
103 | #endif | 103 | #endif |
104 | 104 | ||
105 | #ifndef MAGIC_KEY_LAYER3 | 105 | #ifndef MAGIC_KEY_LAYER3 |
106 | #define MAGIC_KEY_LAYER3 3 | 106 | # define MAGIC_KEY_LAYER3 3 |
107 | #endif | 107 | #endif |
108 | 108 | ||
109 | #ifndef MAGIC_KEY_LAYER4 | 109 | #ifndef MAGIC_KEY_LAYER4 |
110 | #define MAGIC_KEY_LAYER4 4 | 110 | # define MAGIC_KEY_LAYER4 4 |
111 | #endif | 111 | #endif |
112 | 112 | ||
113 | #ifndef MAGIC_KEY_LAYER5 | 113 | #ifndef MAGIC_KEY_LAYER5 |
114 | #define MAGIC_KEY_LAYER5 5 | 114 | # define MAGIC_KEY_LAYER5 5 |
115 | #endif | 115 | #endif |
116 | 116 | ||
117 | #ifndef MAGIC_KEY_LAYER6 | 117 | #ifndef MAGIC_KEY_LAYER6 |
118 | #define MAGIC_KEY_LAYER6 6 | 118 | # define MAGIC_KEY_LAYER6 6 |
119 | #endif | 119 | #endif |
120 | 120 | ||
121 | #ifndef MAGIC_KEY_LAYER7 | 121 | #ifndef MAGIC_KEY_LAYER7 |
122 | #define MAGIC_KEY_LAYER7 7 | 122 | # define MAGIC_KEY_LAYER7 7 |
123 | #endif | 123 | #endif |
124 | 124 | ||
125 | #ifndef MAGIC_KEY_LAYER8 | 125 | #ifndef MAGIC_KEY_LAYER8 |
126 | #define MAGIC_KEY_LAYER8 8 | 126 | # define MAGIC_KEY_LAYER8 8 |
127 | #endif | 127 | #endif |
128 | 128 | ||
129 | #ifndef MAGIC_KEY_LAYER9 | 129 | #ifndef MAGIC_KEY_LAYER9 |
130 | #define MAGIC_KEY_LAYER9 9 | 130 | # define MAGIC_KEY_LAYER9 9 |
131 | #endif | 131 | #endif |
132 | 132 | ||
133 | #ifndef MAGIC_KEY_BOOTLOADER | 133 | #ifndef MAGIC_KEY_BOOTLOADER |
134 | #define MAGIC_KEY_BOOTLOADER B | 134 | # define MAGIC_KEY_BOOTLOADER B |
135 | #endif | 135 | #endif |
136 | 136 | ||
137 | #ifndef MAGIC_KEY_BOOTLOADER_ALT | 137 | #ifndef MAGIC_KEY_BOOTLOADER_ALT |
138 | #define MAGIC_KEY_BOOTLOADER_ALT ESC | 138 | # define MAGIC_KEY_BOOTLOADER_ALT ESC |
139 | #endif | 139 | #endif |
140 | 140 | ||
141 | #ifndef MAGIC_KEY_LOCK | 141 | #ifndef MAGIC_KEY_LOCK |
142 | #define MAGIC_KEY_LOCK CAPS | 142 | # define MAGIC_KEY_LOCK CAPS |
143 | #endif | 143 | #endif |
144 | 144 | ||
145 | #ifndef MAGIC_KEY_EEPROM | 145 | #ifndef MAGIC_KEY_EEPROM |
146 | #define MAGIC_KEY_EEPROM E | 146 | # define MAGIC_KEY_EEPROM E |
147 | #endif | 147 | #endif |
148 | 148 | ||
149 | #ifndef MAGIC_KEY_EEPROM_CLEAR | 149 | #ifndef MAGIC_KEY_EEPROM_CLEAR |
150 | #define MAGIC_KEY_EEPROM_CLEAR BSPACE | 150 | # define MAGIC_KEY_EEPROM_CLEAR BSPACE |
151 | #endif | 151 | #endif |
152 | 152 | ||
153 | #ifndef MAGIC_KEY_NKRO | 153 | #ifndef MAGIC_KEY_NKRO |
154 | #define MAGIC_KEY_NKRO N | 154 | # define MAGIC_KEY_NKRO N |
155 | #endif | 155 | #endif |
156 | 156 | ||
157 | #ifndef MAGIC_KEY_SLEEP_LED | 157 | #ifndef MAGIC_KEY_SLEEP_LED |
158 | #define MAGIC_KEY_SLEEP_LED Z | 158 | # define MAGIC_KEY_SLEEP_LED Z |
159 | 159 | ||
160 | #endif | 160 | #endif |
161 | 161 | ||
162 | #define XMAGIC_KC(key) KC_ ## key | 162 | #define XMAGIC_KC(key) KC_##key |
163 | #define MAGIC_KC(key) XMAGIC_KC(key) | 163 | #define MAGIC_KC(key) XMAGIC_KC(key) |
diff --git a/tmk_core/common/debug.c b/tmk_core/common/debug.c index 18613fc28..bea96dfc1 100644 --- a/tmk_core/common/debug.c +++ b/tmk_core/common/debug.c | |||
@@ -7,10 +7,10 @@ debug_config_t debug_config = { | |||
7 | /* GCC Bug 10676 - Using unnamed fields in initializers | 7 | /* GCC Bug 10676 - Using unnamed fields in initializers |
8 | * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676 */ | 8 | * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676 */ |
9 | #if GCC_VERSION >= 40600 | 9 | #if GCC_VERSION >= 40600 |
10 | .enable = false, | 10 | .enable = false, |
11 | .matrix = false, | 11 | .matrix = false, |
12 | .keyboard = false, | 12 | .keyboard = false, |
13 | .mouse = false, | 13 | .mouse = false, |
14 | .reserved = 0 | 14 | .reserved = 0 |
15 | #else | 15 | #else |
16 | { | 16 | { |
diff --git a/tmk_core/common/debug.h b/tmk_core/common/debug.h index 3cbe2092d..f9d611bb0 100644 --- a/tmk_core/common/debug.h +++ b/tmk_core/common/debug.h | |||
@@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
21 | #include <stdbool.h> | 21 | #include <stdbool.h> |
22 | #include "print.h" | 22 | #include "print.h" |
23 | 23 | ||
24 | |||
25 | #ifdef __cplusplus | 24 | #ifdef __cplusplus |
26 | extern "C" { | 25 | extern "C" { |
27 | #endif | 26 | #endif |
@@ -31,11 +30,11 @@ extern "C" { | |||
31 | */ | 30 | */ |
32 | typedef union { | 31 | typedef union { |
33 | struct { | 32 | struct { |
34 | bool enable:1; | 33 | bool enable : 1; |
35 | bool matrix:1; | 34 | bool matrix : 1; |
36 | bool keyboard:1; | 35 | bool keyboard : 1; |
37 | bool mouse:1; | 36 | bool mouse : 1; |
38 | uint8_t reserved:4; | 37 | uint8_t reserved : 4; |
39 | }; | 38 | }; |
40 | uint8_t raw; | 39 | uint8_t raw; |
41 | } debug_config_t; | 40 | } debug_config_t; |
@@ -47,70 +46,126 @@ extern debug_config_t debug_config; | |||
47 | #endif | 46 | #endif |
48 | 47 | ||
49 | /* for backward compatibility */ | 48 | /* for backward compatibility */ |
50 | #define debug_enable (debug_config.enable) | 49 | #define debug_enable (debug_config.enable) |
51 | #define debug_matrix (debug_config.matrix) | 50 | #define debug_matrix (debug_config.matrix) |
52 | #define debug_keyboard (debug_config.keyboard) | 51 | #define debug_keyboard (debug_config.keyboard) |
53 | #define debug_mouse (debug_config.mouse) | 52 | #define debug_mouse (debug_config.mouse) |
54 | |||
55 | 53 | ||
56 | /* | 54 | /* |
57 | * Debug print utils | 55 | * Debug print utils |
58 | */ | 56 | */ |
59 | #ifndef NO_DEBUG | 57 | #ifndef NO_DEBUG |
60 | 58 | ||
61 | #define dprint(s) do { if (debug_enable) print(s); } while (0) | 59 | # define dprint(s) \ |
62 | #define dprintln(s) do { if (debug_enable) println(s); } while (0) | 60 | do { \ |
63 | #define dprintf(fmt, ...) do { if (debug_enable) xprintf(fmt, ##__VA_ARGS__); } while (0) | 61 | if (debug_enable) print(s); \ |
64 | #define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s)) | 62 | } while (0) |
63 | # define dprintln(s) \ | ||
64 | do { \ | ||
65 | if (debug_enable) println(s); \ | ||
66 | } while (0) | ||
67 | # define dprintf(fmt, ...) \ | ||
68 | do { \ | ||
69 | if (debug_enable) xprintf(fmt, ##__VA_ARGS__); \ | ||
70 | } while (0) | ||
71 | # define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s)) | ||
65 | 72 | ||
66 | /* Deprecated. DO NOT USE these anymore, use dprintf instead. */ | 73 | /* Deprecated. DO NOT USE these anymore, use dprintf instead. */ |
67 | #define debug(s) do { if (debug_enable) print(s); } while (0) | 74 | # define debug(s) \ |
68 | #define debugln(s) do { if (debug_enable) println(s); } while (0) | 75 | do { \ |
69 | #define debug_msg(s) do { \ | 76 | if (debug_enable) print(s); \ |
70 | if (debug_enable) { \ | 77 | } while (0) |
71 | print(__FILE__); print(" at "); print_dec(__LINE__); print(" in "); print(": "); print(s); \ | 78 | # define debugln(s) \ |
72 | } \ | 79 | do { \ |
73 | } while (0) | 80 | if (debug_enable) println(s); \ |
74 | #define debug_dec(data) do { if (debug_enable) print_dec(data); } while (0) | 81 | } while (0) |
75 | #define debug_decs(data) do { if (debug_enable) print_decs(data); } while (0) | 82 | # define debug_msg(s) \ |
76 | #define debug_hex4(data) do { if (debug_enable) print_hex4(data); } while (0) | 83 | do { \ |
77 | #define debug_hex8(data) do { if (debug_enable) print_hex8(data); } while (0) | 84 | if (debug_enable) { \ |
78 | #define debug_hex16(data) do { if (debug_enable) print_hex16(data); } while (0) | 85 | print(__FILE__); \ |
79 | #define debug_hex32(data) do { if (debug_enable) print_hex32(data); } while (0) | 86 | print(" at "); \ |
80 | #define debug_bin8(data) do { if (debug_enable) print_bin8(data); } while (0) | 87 | print_dec(__LINE__); \ |
81 | #define debug_bin16(data) do { if (debug_enable) print_bin16(data); } while (0) | 88 | print(" in "); \ |
82 | #define debug_bin32(data) do { if (debug_enable) print_bin32(data); } while (0) | 89 | print(": "); \ |
83 | #define debug_bin_reverse8(data) do { if (debug_enable) print_bin_reverse8(data); } while (0) | 90 | print(s); \ |
84 | #define debug_bin_reverse16(data) do { if (debug_enable) print_bin_reverse16(data); } while (0) | 91 | } \ |
85 | #define debug_bin_reverse32(data) do { if (debug_enable) print_bin_reverse32(data); } while (0) | 92 | } while (0) |
86 | #define debug_hex(data) debug_hex8(data) | 93 | # define debug_dec(data) \ |
87 | #define debug_bin(data) debug_bin8(data) | 94 | do { \ |
88 | #define debug_bin_reverse(data) debug_bin8(data) | 95 | if (debug_enable) print_dec(data); \ |
96 | } while (0) | ||
97 | # define debug_decs(data) \ | ||
98 | do { \ | ||
99 | if (debug_enable) print_decs(data); \ | ||
100 | } while (0) | ||
101 | # define debug_hex4(data) \ | ||
102 | do { \ | ||
103 | if (debug_enable) print_hex4(data); \ | ||
104 | } while (0) | ||
105 | # define debug_hex8(data) \ | ||
106 | do { \ | ||
107 | if (debug_enable) print_hex8(data); \ | ||
108 | } while (0) | ||
109 | # define debug_hex16(data) \ | ||
110 | do { \ | ||
111 | if (debug_enable) print_hex16(data); \ | ||
112 | } while (0) | ||
113 | # define debug_hex32(data) \ | ||
114 | do { \ | ||
115 | if (debug_enable) print_hex32(data); \ | ||
116 | } while (0) | ||
117 | # define debug_bin8(data) \ | ||
118 | do { \ | ||
119 | if (debug_enable) print_bin8(data); \ | ||
120 | } while (0) | ||
121 | # define debug_bin16(data) \ | ||
122 | do { \ | ||
123 | if (debug_enable) print_bin16(data); \ | ||
124 | } while (0) | ||
125 | # define debug_bin32(data) \ | ||
126 | do { \ | ||
127 | if (debug_enable) print_bin32(data); \ | ||
128 | } while (0) | ||
129 | # define debug_bin_reverse8(data) \ | ||
130 | do { \ | ||
131 | if (debug_enable) print_bin_reverse8(data); \ | ||
132 | } while (0) | ||
133 | # define debug_bin_reverse16(data) \ | ||
134 | do { \ | ||
135 | if (debug_enable) print_bin_reverse16(data); \ | ||
136 | } while (0) | ||
137 | # define debug_bin_reverse32(data) \ | ||
138 | do { \ | ||
139 | if (debug_enable) print_bin_reverse32(data); \ | ||
140 | } while (0) | ||
141 | # define debug_hex(data) debug_hex8(data) | ||
142 | # define debug_bin(data) debug_bin8(data) | ||
143 | # define debug_bin_reverse(data) debug_bin8(data) | ||
89 | 144 | ||
90 | #else /* NO_DEBUG */ | 145 | #else /* NO_DEBUG */ |
91 | 146 | ||
92 | #define dprint(s) | 147 | # define dprint(s) |
93 | #define dprintln(s) | 148 | # define dprintln(s) |
94 | #define dprintf(fmt, ...) | 149 | # define dprintf(fmt, ...) |
95 | #define dmsg(s) | 150 | # define dmsg(s) |
96 | #define debug(s) | 151 | # define debug(s) |
97 | #define debugln(s) | 152 | # define debugln(s) |
98 | #define debug_msg(s) | 153 | # define debug_msg(s) |
99 | #define debug_dec(data) | 154 | # define debug_dec(data) |
100 | #define debug_decs(data) | 155 | # define debug_decs(data) |
101 | #define debug_hex4(data) | 156 | # define debug_hex4(data) |
102 | #define debug_hex8(data) | 157 | # define debug_hex8(data) |
103 | #define debug_hex16(data) | 158 | # define debug_hex16(data) |
104 | #define debug_hex32(data) | 159 | # define debug_hex32(data) |
105 | #define debug_bin8(data) | 160 | # define debug_bin8(data) |
106 | #define debug_bin16(data) | 161 | # define debug_bin16(data) |
107 | #define debug_bin32(data) | 162 | # define debug_bin32(data) |
108 | #define debug_bin_reverse8(data) | 163 | # define debug_bin_reverse8(data) |
109 | #define debug_bin_reverse16(data) | 164 | # define debug_bin_reverse16(data) |
110 | #define debug_bin_reverse32(data) | 165 | # define debug_bin_reverse32(data) |
111 | #define debug_hex(data) | 166 | # define debug_hex(data) |
112 | #define debug_bin(data) | 167 | # define debug_bin(data) |
113 | #define debug_bin_reverse(data) | 168 | # define debug_bin_reverse(data) |
114 | 169 | ||
115 | #endif /* NO_DEBUG */ | 170 | #endif /* NO_DEBUG */ |
116 | 171 | ||
diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index 28f5d3ad5..61aaec205 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c | |||
@@ -4,8 +4,8 @@ | |||
4 | #include "eeconfig.h" | 4 | #include "eeconfig.h" |
5 | 5 | ||
6 | #ifdef STM32_EEPROM_ENABLE | 6 | #ifdef STM32_EEPROM_ENABLE |
7 | #include "hal.h" | 7 | # include "hal.h" |
8 | #include "eeprom_stm32.h" | 8 | # include "eeprom_stm32.h" |
9 | #endif | 9 | #endif |
10 | 10 | ||
11 | extern uint32_t default_layer_state; | 11 | extern uint32_t default_layer_state; |
@@ -13,21 +13,18 @@ extern uint32_t default_layer_state; | |||
13 | * | 13 | * |
14 | * FIXME: needs doc | 14 | * FIXME: needs doc |
15 | */ | 15 | */ |
16 | __attribute__ ((weak)) | 16 | __attribute__((weak)) void eeconfig_init_user(void) { |
17 | void eeconfig_init_user(void) { | 17 | // Reset user EEPROM value to blank, rather than to a set value |
18 | // Reset user EEPROM value to blank, rather than to a set value | 18 | eeconfig_update_user(0); |
19 | eeconfig_update_user(0); | ||
20 | } | 19 | } |
21 | 20 | ||
22 | __attribute__ ((weak)) | 21 | __attribute__((weak)) void eeconfig_init_kb(void) { |
23 | void eeconfig_init_kb(void) { | 22 | // Reset Keyboard EEPROM value to blank, rather than to a set value |
24 | // Reset Keyboard EEPROM value to blank, rather than to a set value | 23 | eeconfig_update_kb(0); |
25 | eeconfig_update_kb(0); | ||
26 | 24 | ||
27 | eeconfig_init_user(); | 25 | eeconfig_init_user(); |
28 | } | 26 | } |
29 | 27 | ||
30 | |||
31 | /* | 28 | /* |
32 | * FIXME: needs doc | 29 | * FIXME: needs doc |
33 | */ | 30 | */ |
@@ -35,49 +32,42 @@ void eeconfig_init_quantum(void) { | |||
35 | #ifdef STM32_EEPROM_ENABLE | 32 | #ifdef STM32_EEPROM_ENABLE |
36 | EEPROM_Erase(); | 33 | EEPROM_Erase(); |
37 | #endif | 34 | #endif |
38 | eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); | 35 | eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); |
39 | eeprom_update_byte(EECONFIG_DEBUG, 0); | 36 | eeprom_update_byte(EECONFIG_DEBUG, 0); |
40 | eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); | 37 | eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); |
41 | default_layer_state = 0; | 38 | default_layer_state = 0; |
42 | eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0); | 39 | eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0); |
43 | eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0); | 40 | eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0); |
44 | eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0); | 41 | eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0); |
45 | eeprom_update_byte(EECONFIG_BACKLIGHT, 0); | 42 | eeprom_update_byte(EECONFIG_BACKLIGHT, 0); |
46 | eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default | 43 | eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default |
47 | eeprom_update_dword(EECONFIG_RGBLIGHT, 0); | 44 | eeprom_update_dword(EECONFIG_RGBLIGHT, 0); |
48 | eeprom_update_byte(EECONFIG_STENOMODE, 0); | 45 | eeprom_update_byte(EECONFIG_STENOMODE, 0); |
49 | eeprom_update_dword(EECONFIG_HAPTIC, 0); | 46 | eeprom_update_dword(EECONFIG_HAPTIC, 0); |
50 | eeprom_update_byte(EECONFIG_VELOCIKEY, 0); | 47 | eeprom_update_byte(EECONFIG_VELOCIKEY, 0); |
51 | eeprom_update_dword(EECONFIG_RGB_MATRIX, 0); | 48 | eeprom_update_dword(EECONFIG_RGB_MATRIX, 0); |
52 | eeprom_update_byte(EECONFIG_RGB_MATRIX_SPEED, 0); | 49 | eeprom_update_byte(EECONFIG_RGB_MATRIX_SPEED, 0); |
53 | 50 | ||
54 | eeconfig_init_kb(); | 51 | eeconfig_init_kb(); |
55 | } | 52 | } |
56 | 53 | ||
57 | /** \brief eeconfig initialization | 54 | /** \brief eeconfig initialization |
58 | * | 55 | * |
59 | * FIXME: needs doc | 56 | * FIXME: needs doc |
60 | */ | 57 | */ |
61 | void eeconfig_init(void) { | 58 | void eeconfig_init(void) { eeconfig_init_quantum(); } |
62 | |||
63 | eeconfig_init_quantum(); | ||
64 | } | ||
65 | 59 | ||
66 | /** \brief eeconfig enable | 60 | /** \brief eeconfig enable |
67 | * | 61 | * |
68 | * FIXME: needs doc | 62 | * FIXME: needs doc |
69 | */ | 63 | */ |
70 | void eeconfig_enable(void) | 64 | void eeconfig_enable(void) { eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); } |
71 | { | ||
72 | eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); | ||
73 | } | ||
74 | 65 | ||
75 | /** \brief eeconfig disable | 66 | /** \brief eeconfig disable |
76 | * | 67 | * |
77 | * FIXME: needs doc | 68 | * FIXME: needs doc |
78 | */ | 69 | */ |
79 | void eeconfig_disable(void) | 70 | void eeconfig_disable(void) { |
80 | { | ||
81 | #ifdef STM32_EEPROM_ENABLE | 71 | #ifdef STM32_EEPROM_ENABLE |
82 | EEPROM_Erase(); | 72 | EEPROM_Erase(); |
83 | #endif | 73 | #endif |
@@ -88,25 +78,19 @@ void eeconfig_disable(void) | |||
88 | * | 78 | * |
89 | * FIXME: needs doc | 79 | * FIXME: needs doc |
90 | */ | 80 | */ |
91 | bool eeconfig_is_enabled(void) | 81 | bool eeconfig_is_enabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); } |
92 | { | ||
93 | return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); | ||
94 | } | ||
95 | 82 | ||
96 | /** \brief eeconfig is disabled | 83 | /** \brief eeconfig is disabled |
97 | * | 84 | * |
98 | * FIXME: needs doc | 85 | * FIXME: needs doc |
99 | */ | 86 | */ |
100 | bool eeconfig_is_disabled(void) | 87 | bool eeconfig_is_disabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF); } |
101 | { | ||
102 | return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF); | ||
103 | } | ||
104 | 88 | ||
105 | /** \brief eeconfig read debug | 89 | /** \brief eeconfig read debug |
106 | * | 90 | * |
107 | * FIXME: needs doc | 91 | * FIXME: needs doc |
108 | */ | 92 | */ |
109 | uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); } | 93 | uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); } |
110 | /** \brief eeconfig update debug | 94 | /** \brief eeconfig update debug |
111 | * | 95 | * |
112 | * FIXME: needs doc | 96 | * FIXME: needs doc |
@@ -117,7 +101,7 @@ void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val | |||
117 | * | 101 | * |
118 | * FIXME: needs doc | 102 | * FIXME: needs doc |
119 | */ | 103 | */ |
120 | uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); } | 104 | uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); } |
121 | /** \brief eeconfig update default layer | 105 | /** \brief eeconfig update default layer |
122 | * | 106 | * |
123 | * FIXME: needs doc | 107 | * FIXME: needs doc |
@@ -128,47 +112,43 @@ void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DE | |||
128 | * | 112 | * |
129 | * FIXME: needs doc | 113 | * FIXME: needs doc |
130 | */ | 114 | */ |
131 | uint16_t eeconfig_read_keymap(void) { | 115 | uint16_t eeconfig_read_keymap(void) { return (eeprom_read_byte(EECONFIG_KEYMAP_LOWER_BYTE) | (eeprom_read_byte(EECONFIG_KEYMAP_UPPER_BYTE) << 8)); } |
132 | return ( eeprom_read_byte(EECONFIG_KEYMAP_LOWER_BYTE) | (eeprom_read_byte(EECONFIG_KEYMAP_UPPER_BYTE) << 8) ); | ||
133 | } | ||
134 | /** \brief eeconfig update keymap | 116 | /** \brief eeconfig update keymap |
135 | * | 117 | * |
136 | * FIXME: needs doc | 118 | * FIXME: needs doc |
137 | */ | 119 | */ |
138 | void eeconfig_update_keymap(uint16_t val) { | 120 | void eeconfig_update_keymap(uint16_t val) { |
139 | eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, val & 0xFF); | 121 | eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, val & 0xFF); |
140 | eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, ( val >> 8 ) & 0xFF ); | 122 | eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, (val >> 8) & 0xFF); |
141 | } | 123 | } |
142 | 124 | ||
143 | /** \brief eeconfig read backlight | 125 | /** \brief eeconfig read backlight |
144 | * | 126 | * |
145 | * FIXME: needs doc | 127 | * FIXME: needs doc |
146 | */ | 128 | */ |
147 | uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } | 129 | uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } |
148 | /** \brief eeconfig update backlight | 130 | /** \brief eeconfig update backlight |
149 | * | 131 | * |
150 | * FIXME: needs doc | 132 | * FIXME: needs doc |
151 | */ | 133 | */ |
152 | void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); } | 134 | void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); } |
153 | 135 | ||
154 | |||
155 | /** \brief eeconfig read audio | 136 | /** \brief eeconfig read audio |
156 | * | 137 | * |
157 | * FIXME: needs doc | 138 | * FIXME: needs doc |
158 | */ | 139 | */ |
159 | uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); } | 140 | uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); } |
160 | /** \brief eeconfig update audio | 141 | /** \brief eeconfig update audio |
161 | * | 142 | * |
162 | * FIXME: needs doc | 143 | * FIXME: needs doc |
163 | */ | 144 | */ |
164 | void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); } | 145 | void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); } |
165 | 146 | ||
166 | |||
167 | /** \brief eeconfig read kb | 147 | /** \brief eeconfig read kb |
168 | * | 148 | * |
169 | * FIXME: needs doc | 149 | * FIXME: needs doc |
170 | */ | 150 | */ |
171 | uint32_t eeconfig_read_kb(void) { return eeprom_read_dword(EECONFIG_KEYBOARD); } | 151 | uint32_t eeconfig_read_kb(void) { return eeprom_read_dword(EECONFIG_KEYBOARD); } |
172 | /** \brief eeconfig update kb | 152 | /** \brief eeconfig update kb |
173 | * | 153 | * |
174 | * FIXME: needs doc | 154 | * FIXME: needs doc |
@@ -179,15 +159,14 @@ void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, v | |||
179 | * | 159 | * |
180 | * FIXME: needs doc | 160 | * FIXME: needs doc |
181 | */ | 161 | */ |
182 | uint32_t eeconfig_read_user(void) { return eeprom_read_dword(EECONFIG_USER); } | 162 | uint32_t eeconfig_read_user(void) { return eeprom_read_dword(EECONFIG_USER); } |
183 | /** \brief eeconfig update user | 163 | /** \brief eeconfig update user |
184 | * | 164 | * |
185 | * FIXME: needs doc | 165 | * FIXME: needs doc |
186 | */ | 166 | */ |
187 | void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); } | 167 | void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); } |
188 | 168 | ||
189 | 169 | uint32_t eeconfig_read_haptic(void) { return eeprom_read_dword(EECONFIG_HAPTIC); } | |
190 | uint32_t eeconfig_read_haptic(void) { return eeprom_read_dword(EECONFIG_HAPTIC); } | ||
191 | /** \brief eeconfig update user | 170 | /** \brief eeconfig update user |
192 | * | 171 | * |
193 | * FIXME: needs doc | 172 | * FIXME: needs doc |
diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h index a5fc801a3..aea4eff9f 100644 --- a/tmk_core/common/eeconfig.h +++ b/tmk_core/common/eeconfig.h | |||
@@ -21,49 +21,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
21 | #include <stdint.h> | 21 | #include <stdint.h> |
22 | #include <stdbool.h> | 22 | #include <stdbool.h> |
23 | 23 | ||
24 | |||
25 | #ifndef EECONFIG_MAGIC_NUMBER | 24 | #ifndef EECONFIG_MAGIC_NUMBER |
26 | # define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEEC | 25 | # define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEEC |
27 | #endif | 26 | #endif |
28 | #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF | 27 | #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF |
29 | 28 | ||
30 | /* EEPROM parameter address */ | 29 | /* EEPROM parameter address */ |
31 | #define EECONFIG_MAGIC (uint16_t *)0 | 30 | #define EECONFIG_MAGIC (uint16_t *)0 |
32 | #define EECONFIG_DEBUG (uint8_t *)2 | 31 | #define EECONFIG_DEBUG (uint8_t *)2 |
33 | #define EECONFIG_DEFAULT_LAYER (uint8_t *)3 | 32 | #define EECONFIG_DEFAULT_LAYER (uint8_t *)3 |
34 | #define EECONFIG_KEYMAP (uint8_t *)4 | 33 | #define EECONFIG_KEYMAP (uint8_t *)4 |
35 | #define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 | 34 | #define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 |
36 | #define EECONFIG_BACKLIGHT (uint8_t *)6 | 35 | #define EECONFIG_BACKLIGHT (uint8_t *)6 |
37 | #define EECONFIG_AUDIO (uint8_t *)7 | 36 | #define EECONFIG_AUDIO (uint8_t *)7 |
38 | #define EECONFIG_RGBLIGHT (uint32_t *)8 | 37 | #define EECONFIG_RGBLIGHT (uint32_t *)8 |
39 | #define EECONFIG_UNICODEMODE (uint8_t *)12 | 38 | #define EECONFIG_UNICODEMODE (uint8_t *)12 |
40 | #define EECONFIG_STENOMODE (uint8_t *)13 | 39 | #define EECONFIG_STENOMODE (uint8_t *)13 |
41 | // EEHANDS for two handed boards | 40 | // EEHANDS for two handed boards |
42 | #define EECONFIG_HANDEDNESS (uint8_t *)14 | 41 | #define EECONFIG_HANDEDNESS (uint8_t *)14 |
43 | #define EECONFIG_KEYBOARD (uint32_t *)15 | 42 | #define EECONFIG_KEYBOARD (uint32_t *)15 |
44 | #define EECONFIG_USER (uint32_t *)19 | 43 | #define EECONFIG_USER (uint32_t *)19 |
45 | #define EECONFIG_VELOCIKEY (uint8_t *)23 | 44 | #define EECONFIG_VELOCIKEY (uint8_t *)23 |
46 | 45 | ||
47 | #define EECONFIG_HAPTIC (uint32_t *)24 | 46 | #define EECONFIG_HAPTIC (uint32_t *)24 |
48 | #define EECONFIG_RGB_MATRIX (uint32_t *)28 | 47 | #define EECONFIG_RGB_MATRIX (uint32_t *)28 |
49 | #define EECONFIG_RGB_MATRIX_SPEED (uint8_t *)32 | 48 | #define EECONFIG_RGB_MATRIX_SPEED (uint8_t *)32 |
50 | // TODO: Combine these into a single word and single block of EEPROM | 49 | // TODO: Combine these into a single word and single block of EEPROM |
51 | #define EECONFIG_KEYMAP_UPPER_BYTE (uint8_t *)33 | 50 | #define EECONFIG_KEYMAP_UPPER_BYTE (uint8_t *)33 |
52 | /* debug bit */ | 51 | /* debug bit */ |
53 | #define EECONFIG_DEBUG_ENABLE (1<<0) | 52 | #define EECONFIG_DEBUG_ENABLE (1 << 0) |
54 | #define EECONFIG_DEBUG_MATRIX (1<<1) | 53 | #define EECONFIG_DEBUG_MATRIX (1 << 1) |
55 | #define EECONFIG_DEBUG_KEYBOARD (1<<2) | 54 | #define EECONFIG_DEBUG_KEYBOARD (1 << 2) |
56 | #define EECONFIG_DEBUG_MOUSE (1<<3) | 55 | #define EECONFIG_DEBUG_MOUSE (1 << 3) |
57 | 56 | ||
58 | /* keyconf bit */ | 57 | /* keyconf bit */ |
59 | #define EECONFIG_KEYMAP_SWAP_CONTROL_CAPSLOCK (1<<0) | 58 | #define EECONFIG_KEYMAP_SWAP_CONTROL_CAPSLOCK (1 << 0) |
60 | #define EECONFIG_KEYMAP_CAPSLOCK_TO_CONTROL (1<<1) | 59 | #define EECONFIG_KEYMAP_CAPSLOCK_TO_CONTROL (1 << 1) |
61 | #define EECONFIG_KEYMAP_SWAP_LALT_LGUI (1<<2) | 60 | #define EECONFIG_KEYMAP_SWAP_LALT_LGUI (1 << 2) |
62 | #define EECONFIG_KEYMAP_SWAP_RALT_RGUI (1<<3) | 61 | #define EECONFIG_KEYMAP_SWAP_RALT_RGUI (1 << 3) |
63 | #define EECONFIG_KEYMAP_NO_GUI (1<<4) | 62 | #define EECONFIG_KEYMAP_NO_GUI (1 << 4) |
64 | #define EECONFIG_KEYMAP_SWAP_GRAVE_ESC (1<<5) | 63 | #define EECONFIG_KEYMAP_SWAP_GRAVE_ESC (1 << 5) |
65 | #define EECONFIG_KEYMAP_SWAP_BACKSLASH_BACKSPACE (1<<6) | 64 | #define EECONFIG_KEYMAP_SWAP_BACKSLASH_BACKSPACE (1 << 6) |
66 | #define EECONFIG_KEYMAP_NKRO (1<<7) | 65 | #define EECONFIG_KEYMAP_NKRO (1 << 7) |
67 | 66 | ||
68 | #define EECONFIG_KEYMAP_LOWER_BYTE EECONFIG_KEYMAP | 67 | #define EECONFIG_KEYMAP_LOWER_BYTE EECONFIG_KEYMAP |
69 | 68 | ||
@@ -80,32 +79,32 @@ void eeconfig_enable(void); | |||
80 | void eeconfig_disable(void); | 79 | void eeconfig_disable(void); |
81 | 80 | ||
82 | uint8_t eeconfig_read_debug(void); | 81 | uint8_t eeconfig_read_debug(void); |
83 | void eeconfig_update_debug(uint8_t val); | 82 | void eeconfig_update_debug(uint8_t val); |
84 | 83 | ||
85 | uint8_t eeconfig_read_default_layer(void); | 84 | uint8_t eeconfig_read_default_layer(void); |
86 | void eeconfig_update_default_layer(uint8_t val); | 85 | void eeconfig_update_default_layer(uint8_t val); |
87 | 86 | ||
88 | uint16_t eeconfig_read_keymap(void); | 87 | uint16_t eeconfig_read_keymap(void); |
89 | void eeconfig_update_keymap(uint16_t val); | 88 | void eeconfig_update_keymap(uint16_t val); |
90 | 89 | ||
91 | #ifdef BACKLIGHT_ENABLE | 90 | #ifdef BACKLIGHT_ENABLE |
92 | uint8_t eeconfig_read_backlight(void); | 91 | uint8_t eeconfig_read_backlight(void); |
93 | void eeconfig_update_backlight(uint8_t val); | 92 | void eeconfig_update_backlight(uint8_t val); |
94 | #endif | 93 | #endif |
95 | 94 | ||
96 | #ifdef AUDIO_ENABLE | 95 | #ifdef AUDIO_ENABLE |
97 | uint8_t eeconfig_read_audio(void); | 96 | uint8_t eeconfig_read_audio(void); |
98 | void eeconfig_update_audio(uint8_t val); | 97 | void eeconfig_update_audio(uint8_t val); |
99 | #endif | 98 | #endif |
100 | 99 | ||
101 | uint32_t eeconfig_read_kb(void); | 100 | uint32_t eeconfig_read_kb(void); |
102 | void eeconfig_update_kb(uint32_t val); | 101 | void eeconfig_update_kb(uint32_t val); |
103 | uint32_t eeconfig_read_user(void); | 102 | uint32_t eeconfig_read_user(void); |
104 | void eeconfig_update_user(uint32_t val); | 103 | void eeconfig_update_user(uint32_t val); |
105 | 104 | ||
106 | #ifdef HAPTIC_ENABLE | 105 | #ifdef HAPTIC_ENABLE |
107 | uint32_t eeconfig_read_haptic(void); | 106 | uint32_t eeconfig_read_haptic(void); |
108 | void eeconfig_update_haptic(uint32_t val); | 107 | void eeconfig_update_haptic(uint32_t val); |
109 | #endif | 108 | #endif |
110 | 109 | ||
111 | #endif | 110 | #endif |
diff --git a/tmk_core/common/eeprom.h b/tmk_core/common/eeprom.h index 5ae0f6eeb..fcd1667c0 100644 --- a/tmk_core/common/eeprom.h +++ b/tmk_core/common/eeprom.h | |||
@@ -2,22 +2,22 @@ | |||
2 | #define TMK_CORE_COMMON_EEPROM_H_ | 2 | #define TMK_CORE_COMMON_EEPROM_H_ |
3 | 3 | ||
4 | #if defined(__AVR__) | 4 | #if defined(__AVR__) |
5 | #include <avr/eeprom.h> | 5 | # include <avr/eeprom.h> |
6 | #else | 6 | #else |
7 | #include <stdint.h> | 7 | # include <stdint.h> |
8 | 8 | ||
9 | uint8_t eeprom_read_byte (const uint8_t *__p); | 9 | uint8_t eeprom_read_byte(const uint8_t *__p); |
10 | uint16_t eeprom_read_word (const uint16_t *__p); | 10 | uint16_t eeprom_read_word(const uint16_t *__p); |
11 | uint32_t eeprom_read_dword (const uint32_t *__p); | 11 | uint32_t eeprom_read_dword(const uint32_t *__p); |
12 | void eeprom_read_block (void *__dst, const void *__src, uint32_t __n); | 12 | void eeprom_read_block(void *__dst, const void *__src, uint32_t __n); |
13 | void eeprom_write_byte (uint8_t *__p, uint8_t __value); | 13 | void eeprom_write_byte(uint8_t *__p, uint8_t __value); |
14 | void eeprom_write_word (uint16_t *__p, uint16_t __value); | 14 | void eeprom_write_word(uint16_t *__p, uint16_t __value); |
15 | void eeprom_write_dword (uint32_t *__p, uint32_t __value); | 15 | void eeprom_write_dword(uint32_t *__p, uint32_t __value); |
16 | void eeprom_write_block (const void *__src, void *__dst, uint32_t __n); | 16 | void eeprom_write_block(const void *__src, void *__dst, uint32_t __n); |
17 | void eeprom_update_byte (uint8_t *__p, uint8_t __value); | 17 | void eeprom_update_byte(uint8_t *__p, uint8_t __value); |
18 | void eeprom_update_word (uint16_t *__p, uint16_t __value); | 18 | void eeprom_update_word(uint16_t *__p, uint16_t __value); |
19 | void eeprom_update_dword (uint32_t *__p, uint32_t __value); | 19 | void eeprom_update_dword(uint32_t *__p, uint32_t __value); |
20 | void eeprom_update_block (const void *__src, void *__dst, uint32_t __n); | 20 | void eeprom_update_block(const void *__src, void *__dst, uint32_t __n); |
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | #endif /* TMK_CORE_COMMON_EEPROM_H_ */ | 23 | #endif /* TMK_CORE_COMMON_EEPROM_H_ */ |
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c index f5d041699..ce39760a5 100644 --- a/tmk_core/common/host.c +++ b/tmk_core/common/host.c | |||
@@ -23,40 +23,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
23 | #include "debug.h" | 23 | #include "debug.h" |
24 | 24 | ||
25 | #ifdef NKRO_ENABLE | 25 | #ifdef NKRO_ENABLE |
26 | #include "keycode_config.h" | 26 | # include "keycode_config.h" |
27 | extern keymap_config_t keymap_config; | 27 | extern keymap_config_t keymap_config; |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | static host_driver_t *driver; | 30 | static host_driver_t *driver; |
31 | static uint16_t last_system_report = 0; | 31 | static uint16_t last_system_report = 0; |
32 | static uint16_t last_consumer_report = 0; | 32 | static uint16_t last_consumer_report = 0; |
33 | 33 | ||
34 | void host_set_driver(host_driver_t *d) { driver = d; } | ||
34 | 35 | ||
35 | void host_set_driver(host_driver_t *d) | 36 | host_driver_t *host_get_driver(void) { return driver; } |
36 | { | ||
37 | driver = d; | ||
38 | } | ||
39 | |||
40 | host_driver_t *host_get_driver(void) | ||
41 | { | ||
42 | return driver; | ||
43 | } | ||
44 | 37 | ||
45 | uint8_t host_keyboard_leds(void) | 38 | uint8_t host_keyboard_leds(void) { |
46 | { | ||
47 | if (!driver) return 0; | 39 | if (!driver) return 0; |
48 | return (*driver->keyboard_leds)(); | 40 | return (*driver->keyboard_leds)(); |
49 | } | 41 | } |
50 | /* send report */ | 42 | /* send report */ |
51 | void host_keyboard_send(report_keyboard_t *report) | 43 | void host_keyboard_send(report_keyboard_t *report) { |
52 | { | ||
53 | if (!driver) return; | 44 | if (!driver) return; |
54 | #if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP) | 45 | #if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP) |
55 | if (keyboard_protocol && keymap_config.nkro) { | 46 | if (keyboard_protocol && keymap_config.nkro) { |
56 | /* The callers of this function assume that report->mods is where mods go in. | 47 | /* The callers of this function assume that report->mods is where mods go in. |
57 | * But report->nkro.mods can be at a different offset if core keyboard does not have a report ID. | 48 | * But report->nkro.mods can be at a different offset if core keyboard does not have a report ID. |
58 | */ | 49 | */ |
59 | report->nkro.mods = report->mods; | 50 | report->nkro.mods = report->mods; |
60 | report->nkro.report_id = REPORT_ID_NKRO; | 51 | report->nkro.report_id = REPORT_ID_NKRO; |
61 | } else | 52 | } else |
62 | #endif | 53 | #endif |
@@ -76,8 +67,7 @@ void host_keyboard_send(report_keyboard_t *report) | |||
76 | } | 67 | } |
77 | } | 68 | } |
78 | 69 | ||
79 | void host_mouse_send(report_mouse_t *report) | 70 | void host_mouse_send(report_mouse_t *report) { |
80 | { | ||
81 | if (!driver) return; | 71 | if (!driver) return; |
82 | #ifdef MOUSE_SHARED_EP | 72 | #ifdef MOUSE_SHARED_EP |
83 | report->report_id = REPORT_ID_MOUSE; | 73 | report->report_id = REPORT_ID_MOUSE; |
@@ -85,8 +75,7 @@ void host_mouse_send(report_mouse_t *report) | |||
85 | (*driver->send_mouse)(report); | 75 | (*driver->send_mouse)(report); |
86 | } | 76 | } |
87 | 77 | ||
88 | void host_system_send(uint16_t report) | 78 | void host_system_send(uint16_t report) { |
89 | { | ||
90 | if (report == last_system_report) return; | 79 | if (report == last_system_report) return; |
91 | last_system_report = report; | 80 | last_system_report = report; |
92 | 81 | ||
@@ -94,8 +83,7 @@ void host_system_send(uint16_t report) | |||
94 | (*driver->send_system)(report); | 83 | (*driver->send_system)(report); |
95 | } | 84 | } |
96 | 85 | ||
97 | void host_consumer_send(uint16_t report) | 86 | void host_consumer_send(uint16_t report) { |
98 | { | ||
99 | if (report == last_consumer_report) return; | 87 | if (report == last_consumer_report) return; |
100 | last_consumer_report = report; | 88 | last_consumer_report = report; |
101 | 89 | ||
@@ -103,12 +91,6 @@ void host_consumer_send(uint16_t report) | |||
103 | (*driver->send_consumer)(report); | 91 | (*driver->send_consumer)(report); |
104 | } | 92 | } |
105 | 93 | ||
106 | uint16_t host_last_system_report(void) | 94 | uint16_t host_last_system_report(void) { return last_system_report; } |
107 | { | ||
108 | return last_system_report; | ||
109 | } | ||
110 | 95 | ||
111 | uint16_t host_last_consumer_report(void) | 96 | uint16_t host_last_consumer_report(void) { return last_consumer_report; } |
112 | { | ||
113 | return last_consumer_report; | ||
114 | } | ||
diff --git a/tmk_core/common/host.h b/tmk_core/common/host.h index 3d172eed6..b2a7f9842 100644 --- a/tmk_core/common/host.h +++ b/tmk_core/common/host.h | |||
@@ -22,11 +22,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
22 | #include "report.h" | 22 | #include "report.h" |
23 | #include "host_driver.h" | 23 | #include "host_driver.h" |
24 | 24 | ||
25 | #define IS_LED_ON(leds, led_name) ( (leds) & (1 << (led_name))) | 25 | #define IS_LED_ON(leds, led_name) ((leds) & (1 << (led_name))) |
26 | #define IS_LED_OFF(leds, led_name) (~(leds) & (1 << (led_name))) | 26 | #define IS_LED_OFF(leds, led_name) (~(leds) & (1 << (led_name))) |
27 | 27 | ||
28 | #define IS_HOST_LED_ON(led_name) IS_LED_ON(host_keyboard_leds(), led_name) | 28 | #define IS_HOST_LED_ON(led_name) IS_LED_ON(host_keyboard_leds(), led_name) |
29 | #define IS_HOST_LED_OFF(led_name) IS_LED_OFF(host_keyboard_leds(), led_name) | 29 | #define IS_HOST_LED_OFF(led_name) IS_LED_OFF(host_keyboard_leds(), led_name) |
30 | 30 | ||
31 | #ifdef __cplusplus | 31 | #ifdef __cplusplus |
32 | extern "C" { | 32 | extern "C" { |
@@ -36,15 +36,15 @@ extern uint8_t keyboard_idle; | |||
36 | extern uint8_t keyboard_protocol; | 36 | extern uint8_t keyboard_protocol; |
37 | 37 | ||
38 | /* host driver */ | 38 | /* host driver */ |
39 | void host_set_driver(host_driver_t *driver); | 39 | void host_set_driver(host_driver_t *driver); |
40 | host_driver_t *host_get_driver(void); | 40 | host_driver_t *host_get_driver(void); |
41 | 41 | ||
42 | /* host driver interface */ | 42 | /* host driver interface */ |
43 | uint8_t host_keyboard_leds(void); | 43 | uint8_t host_keyboard_leds(void); |
44 | void host_keyboard_send(report_keyboard_t *report); | 44 | void host_keyboard_send(report_keyboard_t *report); |
45 | void host_mouse_send(report_mouse_t *report); | 45 | void host_mouse_send(report_mouse_t *report); |
46 | void host_system_send(uint16_t data); | 46 | void host_system_send(uint16_t data); |
47 | void host_consumer_send(uint16_t data); | 47 | void host_consumer_send(uint16_t data); |
48 | 48 | ||
49 | uint16_t host_last_system_report(void); | 49 | uint16_t host_last_system_report(void); |
50 | uint16_t host_last_consumer_report(void); | 50 | uint16_t host_last_consumer_report(void); |
diff --git a/tmk_core/common/host_driver.h b/tmk_core/common/host_driver.h index e40f0bfd6..3cfec40cc 100644 --- a/tmk_core/common/host_driver.h +++ b/tmk_core/common/host_driver.h | |||
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
21 | #include <stdint.h> | 21 | #include <stdint.h> |
22 | #include "report.h" | 22 | #include "report.h" |
23 | #ifdef MIDI_ENABLE | 23 | #ifdef MIDI_ENABLE |
24 | #include "midi.h" | 24 | # include "midi.h" |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | typedef struct { | 27 | typedef struct { |
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 8f0257cf6..f4d2cd738 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c | |||
@@ -32,84 +32,82 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
32 | #include "backlight.h" | 32 | #include "backlight.h" |
33 | #include "action_layer.h" | 33 | #include "action_layer.h" |
34 | #ifdef BOOTMAGIC_ENABLE | 34 | #ifdef BOOTMAGIC_ENABLE |
35 | # include "bootmagic.h" | 35 | # include "bootmagic.h" |
36 | #else | 36 | #else |
37 | # include "magic.h" | 37 | # include "magic.h" |
38 | #endif | 38 | #endif |
39 | #ifdef MOUSEKEY_ENABLE | 39 | #ifdef MOUSEKEY_ENABLE |
40 | # include "mousekey.h" | 40 | # include "mousekey.h" |
41 | #endif | 41 | #endif |
42 | #ifdef PS2_MOUSE_ENABLE | 42 | #ifdef PS2_MOUSE_ENABLE |
43 | # include "ps2_mouse.h" | 43 | # include "ps2_mouse.h" |
44 | #endif | 44 | #endif |
45 | #ifdef SERIAL_MOUSE_ENABLE | 45 | #ifdef SERIAL_MOUSE_ENABLE |
46 | # include "serial_mouse.h" | 46 | # include "serial_mouse.h" |
47 | #endif | 47 | #endif |
48 | #ifdef ADB_MOUSE_ENABLE | 48 | #ifdef ADB_MOUSE_ENABLE |
49 | # include "adb.h" | 49 | # include "adb.h" |
50 | #endif | 50 | #endif |
51 | #ifdef RGBLIGHT_ENABLE | 51 | #ifdef RGBLIGHT_ENABLE |
52 | # include "rgblight.h" | 52 | # include "rgblight.h" |
53 | #endif | 53 | #endif |
54 | #ifdef STENO_ENABLE | 54 | #ifdef STENO_ENABLE |
55 | # include "process_steno.h" | 55 | # include "process_steno.h" |
56 | #endif | 56 | #endif |
57 | #ifdef FAUXCLICKY_ENABLE | 57 | #ifdef FAUXCLICKY_ENABLE |
58 | # include "fauxclicky.h" | 58 | # include "fauxclicky.h" |
59 | #endif | 59 | #endif |
60 | #ifdef SERIAL_LINK_ENABLE | 60 | #ifdef SERIAL_LINK_ENABLE |
61 | # include "serial_link/system/serial_link.h" | 61 | # include "serial_link/system/serial_link.h" |
62 | #endif | 62 | #endif |
63 | #ifdef VISUALIZER_ENABLE | 63 | #ifdef VISUALIZER_ENABLE |
64 | # include "visualizer/visualizer.h" | 64 | # include "visualizer/visualizer.h" |
65 | #endif | 65 | #endif |
66 | #ifdef POINTING_DEVICE_ENABLE | 66 | #ifdef POINTING_DEVICE_ENABLE |
67 | # include "pointing_device.h" | 67 | # include "pointing_device.h" |
68 | #endif | 68 | #endif |
69 | #ifdef MIDI_ENABLE | 69 | #ifdef MIDI_ENABLE |
70 | # include "process_midi.h" | 70 | # include "process_midi.h" |
71 | #endif | 71 | #endif |
72 | #ifdef HD44780_ENABLE | 72 | #ifdef HD44780_ENABLE |
73 | # include "hd44780.h" | 73 | # include "hd44780.h" |
74 | #endif | 74 | #endif |
75 | #ifdef QWIIC_ENABLE | 75 | #ifdef QWIIC_ENABLE |
76 | # include "qwiic.h" | 76 | # include "qwiic.h" |
77 | #endif | 77 | #endif |
78 | #ifdef OLED_DRIVER_ENABLE | 78 | #ifdef OLED_DRIVER_ENABLE |
79 | #include "oled_driver.h" | 79 | # include "oled_driver.h" |
80 | #endif | 80 | #endif |
81 | #ifdef VELOCIKEY_ENABLE | 81 | #ifdef VELOCIKEY_ENABLE |
82 | #include "velocikey.h" | 82 | # include "velocikey.h" |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | #ifdef MATRIX_HAS_GHOST | 85 | #ifdef MATRIX_HAS_GHOST |
86 | extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; | 86 | extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; |
87 | static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata){ | 87 | static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata) { |
88 | matrix_row_t out = 0; | 88 | matrix_row_t out = 0; |
89 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | 89 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { |
90 | //read each key in the row data and check if the keymap defines it as a real key | 90 | // read each key in the row data and check if the keymap defines it as a real key |
91 | if (pgm_read_byte(&keymaps[0][row][col]) && (rowdata & (1<<col))){ | 91 | if (pgm_read_byte(&keymaps[0][row][col]) && (rowdata & (1 << col))) { |
92 | //this creates new row data, if a key is defined in the keymap, it will be set here | 92 | // this creates new row data, if a key is defined in the keymap, it will be set here |
93 | out |= 1<<col; | 93 | out |= 1 << col; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | return out; | 96 | return out; |
97 | } | 97 | } |
98 | 98 | ||
99 | static inline bool popcount_more_than_one(matrix_row_t rowdata) | 99 | static inline bool popcount_more_than_one(matrix_row_t rowdata) { |
100 | { | 100 | rowdata &= rowdata - 1; // if there are less than two bits (keys) set, rowdata will become zero |
101 | rowdata &= rowdata-1; //if there are less than two bits (keys) set, rowdata will become zero | ||
102 | return rowdata; | 101 | return rowdata; |
103 | } | 102 | } |
104 | 103 | ||
105 | static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) | 104 | static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) { |
106 | { | ||
107 | /* No ghost exists when less than 2 keys are down on the row. | 105 | /* No ghost exists when less than 2 keys are down on the row. |
108 | If there are "active" blanks in the matrix, the key can't be pressed by the user, | 106 | If there are "active" blanks in the matrix, the key can't be pressed by the user, |
109 | there is no doubt as to which keys are really being pressed. | 107 | there is no doubt as to which keys are really being pressed. |
110 | The ghosts will be ignored, they are KC_NO. */ | 108 | The ghosts will be ignored, they are KC_NO. */ |
111 | rowdata = get_real_keys(row, rowdata); | 109 | rowdata = get_real_keys(row, rowdata); |
112 | if ((popcount_more_than_one(rowdata)) == 0){ | 110 | if ((popcount_more_than_one(rowdata)) == 0) { |
113 | return false; | 111 | return false; |
114 | } | 112 | } |
115 | /* Ghost occurs when the row shares a column line with other row, | 113 | /* Ghost occurs when the row shares a column line with other row, |
@@ -119,8 +117,8 @@ static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) | |||
119 | at least two of another row's real keys, the row will be ignored. Keep in mind, | 117 | at least two of another row's real keys, the row will be ignored. Keep in mind, |
120 | we are checking one row at a time, not all of them at once. | 118 | we are checking one row at a time, not all of them at once. |
121 | */ | 119 | */ |
122 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | 120 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { |
123 | if (i != row && popcount_more_than_one(get_real_keys(i, matrix_get_row(i)) & rowdata)){ | 121 | if (i != row && popcount_more_than_one(get_real_keys(i, matrix_get_row(i)) & rowdata)) { |
124 | return true; | 122 | return true; |
125 | } | 123 | } |
126 | } | 124 | } |
@@ -131,9 +129,7 @@ static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) | |||
131 | 129 | ||
132 | void disable_jtag(void) { | 130 | void disable_jtag(void) { |
133 | // To use PF4-7 (PC2-5 on ATmega32A), disable JTAG by writing JTD bit twice within four cycles. | 131 | // To use PF4-7 (PC2-5 on ATmega32A), disable JTAG by writing JTD bit twice within four cycles. |
134 | #if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || \ | 132 | #if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) |
135 | defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || \ | ||
136 | defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) | ||
137 | MCUCR |= _BV(JTD); | 133 | MCUCR |= _BV(JTD); |
138 | MCUCR |= _BV(JTD); | 134 | MCUCR |= _BV(JTD); |
139 | #elif defined(__AVR_ATmega32A__) | 135 | #elif defined(__AVR_ATmega32A__) |
@@ -146,43 +142,33 @@ void disable_jtag(void) { | |||
146 | * | 142 | * |
147 | * FIXME: needs doc | 143 | * FIXME: needs doc |
148 | */ | 144 | */ |
149 | __attribute__ ((weak)) | 145 | __attribute__((weak)) void matrix_setup(void) {} |
150 | void matrix_setup(void) { | ||
151 | } | ||
152 | 146 | ||
153 | /** \brief keyboard_pre_init_user | 147 | /** \brief keyboard_pre_init_user |
154 | * | 148 | * |
155 | * FIXME: needs doc | 149 | * FIXME: needs doc |
156 | */ | 150 | */ |
157 | __attribute__ ((weak)) | 151 | __attribute__((weak)) void keyboard_pre_init_user(void) {} |
158 | void keyboard_pre_init_user(void) { } | ||
159 | 152 | ||
160 | /** \brief keyboard_pre_init_kb | 153 | /** \brief keyboard_pre_init_kb |
161 | * | 154 | * |
162 | * FIXME: needs doc | 155 | * FIXME: needs doc |
163 | */ | 156 | */ |
164 | __attribute__ ((weak)) | 157 | __attribute__((weak)) void keyboard_pre_init_kb(void) { keyboard_pre_init_user(); } |
165 | void keyboard_pre_init_kb(void) { | ||
166 | keyboard_pre_init_user(); | ||
167 | } | ||
168 | 158 | ||
169 | /** \brief keyboard_post_init_user | 159 | /** \brief keyboard_post_init_user |
170 | * | 160 | * |
171 | * FIXME: needs doc | 161 | * FIXME: needs doc |
172 | */ | 162 | */ |
173 | 163 | ||
174 | __attribute__ ((weak)) | 164 | __attribute__((weak)) void keyboard_post_init_user() {} |
175 | void keyboard_post_init_user() {} | ||
176 | 165 | ||
177 | /** \brief keyboard_post_init_kb | 166 | /** \brief keyboard_post_init_kb |
178 | * | 167 | * |
179 | * FIXME: needs doc | 168 | * FIXME: needs doc |
180 | */ | 169 | */ |
181 | 170 | ||
182 | __attribute__ ((weak)) | 171 | __attribute__((weak)) void keyboard_post_init_kb(void) { keyboard_post_init_user(); } |
183 | void keyboard_post_init_kb(void) { | ||
184 | keyboard_post_init_user(); | ||
185 | } | ||
186 | 172 | ||
187 | /** \brief keyboard_setup | 173 | /** \brief keyboard_setup |
188 | * | 174 | * |
@@ -200,10 +186,7 @@ void keyboard_setup(void) { | |||
200 | * | 186 | * |
201 | * FIXME: needs doc | 187 | * FIXME: needs doc |
202 | */ | 188 | */ |
203 | __attribute__((weak)) | 189 | __attribute__((weak)) bool is_keyboard_master(void) { return true; } |
204 | bool is_keyboard_master(void) { | ||
205 | return true; | ||
206 | } | ||
207 | 190 | ||
208 | /** \brief keyboard_init | 191 | /** \brief keyboard_init |
209 | * | 192 | * |
@@ -265,12 +248,11 @@ void keyboard_init(void) { | |||
265 | * | 248 | * |
266 | * This is repeatedly called as fast as possible. | 249 | * This is repeatedly called as fast as possible. |
267 | */ | 250 | */ |
268 | void keyboard_task(void) | 251 | void keyboard_task(void) { |
269 | { | ||
270 | static matrix_row_t matrix_prev[MATRIX_ROWS]; | 252 | static matrix_row_t matrix_prev[MATRIX_ROWS]; |
271 | static uint8_t led_status = 0; | 253 | static uint8_t led_status = 0; |
272 | matrix_row_t matrix_row = 0; | 254 | matrix_row_t matrix_row = 0; |
273 | matrix_row_t matrix_change = 0; | 255 | matrix_row_t matrix_change = 0; |
274 | #ifdef QMK_KEYS_PER_SCAN | 256 | #ifdef QMK_KEYS_PER_SCAN |
275 | uint8_t keys_processed = 0; | 257 | uint8_t keys_processed = 0; |
276 | #endif | 258 | #endif |
@@ -283,28 +265,28 @@ void keyboard_task(void) | |||
283 | 265 | ||
284 | if (is_keyboard_master()) { | 266 | if (is_keyboard_master()) { |
285 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | 267 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { |
286 | matrix_row = matrix_get_row(r); | 268 | matrix_row = matrix_get_row(r); |
287 | matrix_change = matrix_row ^ matrix_prev[r]; | 269 | matrix_change = matrix_row ^ matrix_prev[r]; |
288 | if (matrix_change) { | 270 | if (matrix_change) { |
289 | #ifdef MATRIX_HAS_GHOST | 271 | #ifdef MATRIX_HAS_GHOST |
290 | if (has_ghost_in_row(r, matrix_row)) { continue; } | 272 | if (has_ghost_in_row(r, matrix_row)) { |
273 | continue; | ||
274 | } | ||
291 | #endif | 275 | #endif |
292 | if (debug_matrix) matrix_print(); | 276 | if (debug_matrix) matrix_print(); |
293 | for (uint8_t c = 0; c < MATRIX_COLS; c++) { | 277 | for (uint8_t c = 0; c < MATRIX_COLS; c++) { |
294 | if (matrix_change & ((matrix_row_t)1<<c)) { | 278 | if (matrix_change & ((matrix_row_t)1 << c)) { |
295 | action_exec((keyevent_t){ | 279 | action_exec((keyevent_t){ |
296 | .key = (keypos_t){ .row = r, .col = c }, | 280 | .key = (keypos_t){.row = r, .col = c}, .pressed = (matrix_row & ((matrix_row_t)1 << c)), .time = (timer_read() | 1) /* time should not be 0 */ |
297 | .pressed = (matrix_row & ((matrix_row_t)1<<c)), | ||
298 | .time = (timer_read() | 1) /* time should not be 0 */ | ||
299 | }); | 281 | }); |
300 | // record a processed key | 282 | // record a processed key |
301 | matrix_prev[r] ^= ((matrix_row_t)1<<c); | 283 | matrix_prev[r] ^= ((matrix_row_t)1 << c); |
302 | #ifdef QMK_KEYS_PER_SCAN | 284 | #ifdef QMK_KEYS_PER_SCAN |
303 | // only jump out if we have processed "enough" keys. | 285 | // only jump out if we have processed "enough" keys. |
304 | if (++keys_processed >= QMK_KEYS_PER_SCAN) | 286 | if (++keys_processed >= QMK_KEYS_PER_SCAN) |
305 | #endif | 287 | #endif |
306 | // process a key per task call | 288 | // process a key per task call |
307 | goto MATRIX_LOOP_END; | 289 | goto MATRIX_LOOP_END; |
308 | } | 290 | } |
309 | } | 291 | } |
310 | } | 292 | } |
@@ -315,7 +297,7 @@ void keyboard_task(void) | |||
315 | // we can get here with some keys processed now. | 297 | // we can get here with some keys processed now. |
316 | if (!keys_processed) | 298 | if (!keys_processed) |
317 | #endif | 299 | #endif |
318 | action_exec(TICK); | 300 | action_exec(TICK); |
319 | 301 | ||
320 | MATRIX_LOOP_END: | 302 | MATRIX_LOOP_END: |
321 | 303 | ||
@@ -325,11 +307,10 @@ MATRIX_LOOP_END: | |||
325 | 307 | ||
326 | #ifdef OLED_DRIVER_ENABLE | 308 | #ifdef OLED_DRIVER_ENABLE |
327 | oled_task(); | 309 | oled_task(); |
328 | #ifndef OLED_DISABLE_TIMEOUT | 310 | # ifndef OLED_DISABLE_TIMEOUT |
329 | // Wake up oled if user is using those fabulous keys! | 311 | // Wake up oled if user is using those fabulous keys! |
330 | if (ret) | 312 | if (ret) oled_on(); |
331 | oled_on(); | 313 | # endif |
332 | #endif | ||
333 | #endif | 314 | #endif |
334 | 315 | ||
335 | #ifdef MOUSEKEY_ENABLE | 316 | #ifdef MOUSEKEY_ENABLE |
@@ -350,7 +331,7 @@ MATRIX_LOOP_END: | |||
350 | #endif | 331 | #endif |
351 | 332 | ||
352 | #ifdef SERIAL_LINK_ENABLE | 333 | #ifdef SERIAL_LINK_ENABLE |
353 | serial_link_update(); | 334 | serial_link_update(); |
354 | #endif | 335 | #endif |
355 | 336 | ||
356 | #ifdef VISUALIZER_ENABLE | 337 | #ifdef VISUALIZER_ENABLE |
@@ -366,7 +347,9 @@ MATRIX_LOOP_END: | |||
366 | #endif | 347 | #endif |
367 | 348 | ||
368 | #ifdef VELOCIKEY_ENABLE | 349 | #ifdef VELOCIKEY_ENABLE |
369 | if (velocikey_enabled()) { velocikey_decelerate(); } | 350 | if (velocikey_enabled()) { |
351 | velocikey_decelerate(); | ||
352 | } | ||
370 | #endif | 353 | #endif |
371 | 354 | ||
372 | // update LED | 355 | // update LED |
@@ -380,8 +363,11 @@ MATRIX_LOOP_END: | |||
380 | * | 363 | * |
381 | * FIXME: needs doc | 364 | * FIXME: needs doc |
382 | */ | 365 | */ |
383 | void keyboard_set_leds(uint8_t leds) | 366 | void keyboard_set_leds(uint8_t leds) { |
384 | { | 367 | if (debug_keyboard) { |
385 | if (debug_keyboard) { debug("keyboard_set_led: "); debug_hex8(leds); debug("\n"); } | 368 | debug("keyboard_set_led: "); |
369 | debug_hex8(leds); | ||
370 | debug("\n"); | ||
371 | } | ||
386 | led_set(leds); | 372 | led_set(leds); |
387 | } | 373 | } |
diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h index 19f98c74e..98ceca49b 100644 --- a/tmk_core/common/keyboard.h +++ b/tmk_core/common/keyboard.h | |||
@@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
21 | #include <stdbool.h> | 21 | #include <stdbool.h> |
22 | #include <stdint.h> | 22 | #include <stdint.h> |
23 | 23 | ||
24 | |||
25 | #ifdef __cplusplus | 24 | #ifdef __cplusplus |
26 | extern "C" { | 25 | extern "C" { |
27 | #endif | 26 | #endif |
@@ -40,7 +39,7 @@ typedef struct { | |||
40 | } keyevent_t; | 39 | } keyevent_t; |
41 | 40 | ||
42 | /* equivalent test of keypos_t */ | 41 | /* equivalent test of keypos_t */ |
43 | #define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col) | 42 | #define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col) |
44 | 43 | ||
45 | /* Rules for No Event: | 44 | /* Rules for No Event: |
46 | * 1) (time == 0) to handle (keyevent_t){} as empty event | 45 | * 1) (time == 0) to handle (keyevent_t){} as empty event |
@@ -51,11 +50,8 @@ static inline bool IS_PRESSED(keyevent_t event) { return (!IS_NOEVENT(event) && | |||
51 | static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) && !event.pressed); } | 50 | static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) && !event.pressed); } |
52 | 51 | ||
53 | /* Tick event */ | 52 | /* Tick event */ |
54 | #define TICK (keyevent_t){ \ | 53 | #define TICK \ |
55 | .key = (keypos_t){ .row = 255, .col = 255 }, \ | 54 | (keyevent_t) { .key = (keypos_t){.row = 255, .col = 255}, .pressed = false, .time = (timer_read() | 1) } |
56 | .pressed = false, \ | ||
57 | .time = (timer_read() | 1) \ | ||
58 | } | ||
59 | 55 | ||
60 | /* it runs once at early stage of startup before keyboard_init. */ | 56 | /* it runs once at early stage of startup before keyboard_init. */ |
61 | void keyboard_setup(void); | 57 | void keyboard_setup(void); |
diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h index d5904276e..fd5d60680 100644 --- a/tmk_core/common/keycode.h +++ b/tmk_core/common/keycode.h | |||
@@ -26,68 +26,68 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
26 | 26 | ||
27 | /* FIXME: Add doxygen comments here */ | 27 | /* FIXME: Add doxygen comments here */ |
28 | 28 | ||
29 | #define IS_ERROR(code) (KC_ROLL_OVER <= (code) && (code) <= KC_UNDEFINED) | 29 | #define IS_ERROR(code) (KC_ROLL_OVER <= (code) && (code) <= KC_UNDEFINED) |
30 | #define IS_ANY(code) (KC_A <= (code) && (code) <= 0xFF) | 30 | #define IS_ANY(code) (KC_A <= (code) && (code) <= 0xFF) |
31 | #define IS_KEY(code) (KC_A <= (code) && (code) <= KC_EXSEL) | 31 | #define IS_KEY(code) (KC_A <= (code) && (code) <= KC_EXSEL) |
32 | #define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI) | 32 | #define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI) |
33 | 33 | ||
34 | #define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) | 34 | #define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) |
35 | #define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE) | 35 | #define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE) |
36 | #define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID) | 36 | #define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID) |
37 | 37 | ||
38 | #define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31) | 38 | #define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31) |
39 | 39 | ||
40 | #define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) | 40 | #define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) |
41 | #define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) | 41 | #define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) |
42 | #define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN5) | 42 | #define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN5) |
43 | #define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT) | 43 | #define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT) |
44 | #define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2) | 44 | #define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2) |
45 | 45 | ||
46 | #define MOD_BIT(code) (1 << MOD_INDEX(code)) | 46 | #define MOD_BIT(code) (1 << MOD_INDEX(code)) |
47 | #define MOD_INDEX(code) ((code) & 0x07) | 47 | #define MOD_INDEX(code) ((code)&0x07) |
48 | 48 | ||
49 | #define MOD_MASK_CTRL (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RCTRL)) | 49 | #define MOD_MASK_CTRL (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RCTRL)) |
50 | #define MOD_MASK_SHIFT (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) | 50 | #define MOD_MASK_SHIFT (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) |
51 | #define MOD_MASK_ALT (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) | 51 | #define MOD_MASK_ALT (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) |
52 | #define MOD_MASK_GUI (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)) | 52 | #define MOD_MASK_GUI (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)) |
53 | #define MOD_MASK_CS (MOD_MASK_CTRL | MOD_MASK_SHIFT) | 53 | #define MOD_MASK_CS (MOD_MASK_CTRL | MOD_MASK_SHIFT) |
54 | #define MOD_MASK_CA (MOD_MASK_CTRL | MOD_MASK_ALT) | 54 | #define MOD_MASK_CA (MOD_MASK_CTRL | MOD_MASK_ALT) |
55 | #define MOD_MASK_CG (MOD_MASK_CTRL | MOD_MASK_GUI) | 55 | #define MOD_MASK_CG (MOD_MASK_CTRL | MOD_MASK_GUI) |
56 | #define MOD_MASK_SA (MOD_MASK_SHIFT | MOD_MASK_ALT) | 56 | #define MOD_MASK_SA (MOD_MASK_SHIFT | MOD_MASK_ALT) |
57 | #define MOD_MASK_SG (MOD_MASK_SHIFT | MOD_MASK_GUI) | 57 | #define MOD_MASK_SG (MOD_MASK_SHIFT | MOD_MASK_GUI) |
58 | #define MOD_MASK_AG (MOD_MASK_ALT | MOD_MASK_GUI) | 58 | #define MOD_MASK_AG (MOD_MASK_ALT | MOD_MASK_GUI) |
59 | #define MOD_MASK_CSA (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT) | 59 | #define MOD_MASK_CSA (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT) |
60 | #define MOD_MASK_CSG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_GUI) | 60 | #define MOD_MASK_CSG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_GUI) |
61 | #define MOD_MASK_CAG (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI) | 61 | #define MOD_MASK_CAG (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI) |
62 | #define MOD_MASK_SAG (MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) | 62 | #define MOD_MASK_SAG (MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) |
63 | #define MOD_MASK_CSAG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) | 63 | #define MOD_MASK_CSAG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) |
64 | 64 | ||
65 | #define FN_BIT(code) (1 << FN_INDEX(code)) | 65 | #define FN_BIT(code) (1 << FN_INDEX(code)) |
66 | #define FN_INDEX(code) ((code) - KC_FN0) | 66 | #define FN_INDEX(code) ((code)-KC_FN0) |
67 | #define FN_MIN KC_FN0 | 67 | #define FN_MIN KC_FN0 |
68 | #define FN_MAX KC_FN31 | 68 | #define FN_MAX KC_FN31 |
69 | 69 | ||
70 | /* | 70 | /* |
71 | * Short names for ease of definition of keymap | 71 | * Short names for ease of definition of keymap |
72 | */ | 72 | */ |
73 | /* Transparent */ | 73 | /* Transparent */ |
74 | #define KC_TRANSPARENT 0x01 | 74 | #define KC_TRANSPARENT 0x01 |
75 | #define KC_TRNS KC_TRANSPARENT | 75 | #define KC_TRNS KC_TRANSPARENT |
76 | 76 | ||
77 | /* Punctuation */ | 77 | /* Punctuation */ |
78 | #define KC_ENT KC_ENTER | 78 | #define KC_ENT KC_ENTER |
79 | #define KC_ESC KC_ESCAPE | 79 | #define KC_ESC KC_ESCAPE |
80 | #define KC_BSPC KC_BSPACE | 80 | #define KC_BSPC KC_BSPACE |
81 | #define KC_SPC KC_SPACE | 81 | #define KC_SPC KC_SPACE |
82 | #define KC_MINS KC_MINUS | 82 | #define KC_MINS KC_MINUS |
83 | #define KC_EQL KC_EQUAL | 83 | #define KC_EQL KC_EQUAL |
84 | #define KC_LBRC KC_LBRACKET | 84 | #define KC_LBRC KC_LBRACKET |
85 | #define KC_RBRC KC_RBRACKET | 85 | #define KC_RBRC KC_RBRACKET |
86 | #define KC_BSLS KC_BSLASH | 86 | #define KC_BSLS KC_BSLASH |
87 | #define KC_NUHS KC_NONUS_HASH | 87 | #define KC_NUHS KC_NONUS_HASH |
88 | #define KC_SCLN KC_SCOLON | 88 | #define KC_SCLN KC_SCOLON |
89 | #define KC_QUOT KC_QUOTE | 89 | #define KC_QUOT KC_QUOTE |
90 | #define KC_GRV KC_GRAVE | 90 | #define KC_GRV KC_GRAVE |
91 | #define KC_COMM KC_COMMA | 91 | #define KC_COMM KC_COMMA |
92 | #define KC_SLSH KC_SLASH | 92 | #define KC_SLSH KC_SLASH |
93 | #define KC_NUBS KC_NONUS_BSLASH | 93 | #define KC_NUBS KC_NONUS_BSLASH |
@@ -104,18 +104,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
104 | /* Commands */ | 104 | /* Commands */ |
105 | #define KC_PSCR KC_PSCREEN | 105 | #define KC_PSCR KC_PSCREEN |
106 | #define KC_PAUS KC_PAUSE | 106 | #define KC_PAUS KC_PAUSE |
107 | #define KC_BRK KC_PAUSE | 107 | #define KC_BRK KC_PAUSE |
108 | #define KC_INS KC_INSERT | 108 | #define KC_INS KC_INSERT |
109 | #define KC_DEL KC_DELETE | 109 | #define KC_DEL KC_DELETE |
110 | #define KC_PGDN KC_PGDOWN | 110 | #define KC_PGDN KC_PGDOWN |
111 | #define KC_RGHT KC_RIGHT | 111 | #define KC_RGHT KC_RIGHT |
112 | #define KC_APP KC_APPLICATION | 112 | #define KC_APP KC_APPLICATION |
113 | #define KC_EXEC KC_EXECUTE | 113 | #define KC_EXEC KC_EXECUTE |
114 | #define KC_SLCT KC_SELECT | 114 | #define KC_SLCT KC_SELECT |
115 | #define KC_AGIN KC_AGAIN | 115 | #define KC_AGIN KC_AGAIN |
116 | #define KC_PSTE KC_PASTE | 116 | #define KC_PSTE KC_PASTE |
117 | #define KC_ERAS KC_ALT_ERASE | 117 | #define KC_ERAS KC_ALT_ERASE |
118 | #define KC_CLR KC_CLEAR | 118 | #define KC_CLR KC_CLEAR |
119 | 119 | ||
120 | /* Keypad */ | 120 | /* Keypad */ |
121 | #define KC_PSLS KC_KP_SLASH | 121 | #define KC_PSLS KC_KP_SLASH |
@@ -123,23 +123,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
123 | #define KC_PMNS KC_KP_MINUS | 123 | #define KC_PMNS KC_KP_MINUS |
124 | #define KC_PPLS KC_KP_PLUS | 124 | #define KC_PPLS KC_KP_PLUS |
125 | #define KC_PENT KC_KP_ENTER | 125 | #define KC_PENT KC_KP_ENTER |
126 | #define KC_P1 KC_KP_1 | 126 | #define KC_P1 KC_KP_1 |
127 | #define KC_P2 KC_KP_2 | 127 | #define KC_P2 KC_KP_2 |
128 | #define KC_P3 KC_KP_3 | 128 | #define KC_P3 KC_KP_3 |
129 | #define KC_P4 KC_KP_4 | 129 | #define KC_P4 KC_KP_4 |
130 | #define KC_P5 KC_KP_5 | 130 | #define KC_P5 KC_KP_5 |
131 | #define KC_P6 KC_KP_6 | 131 | #define KC_P6 KC_KP_6 |
132 | #define KC_P7 KC_KP_7 | 132 | #define KC_P7 KC_KP_7 |
133 | #define KC_P8 KC_KP_8 | 133 | #define KC_P8 KC_KP_8 |
134 | #define KC_P9 KC_KP_9 | 134 | #define KC_P9 KC_KP_9 |
135 | #define KC_P0 KC_KP_0 | 135 | #define KC_P0 KC_KP_0 |
136 | #define KC_PDOT KC_KP_DOT | 136 | #define KC_PDOT KC_KP_DOT |
137 | #define KC_PEQL KC_KP_EQUAL | 137 | #define KC_PEQL KC_KP_EQUAL |
138 | #define KC_PCMM KC_KP_COMMA | 138 | #define KC_PCMM KC_KP_COMMA |
139 | 139 | ||
140 | /* Japanese specific */ | 140 | /* Japanese specific */ |
141 | #define KC_ZKHK KC_GRAVE | 141 | #define KC_ZKHK KC_GRAVE |
142 | #define KC_RO KC_INT1 | 142 | #define KC_RO KC_INT1 |
143 | #define KC_KANA KC_INT2 | 143 | #define KC_KANA KC_INT2 |
144 | #define KC_JYEN KC_INT3 | 144 | #define KC_JYEN KC_INT3 |
145 | #define KC_HENK KC_INT4 | 145 | #define KC_HENK KC_INT4 |
@@ -161,7 +161,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
161 | #define KC_RWIN KC_RGUI | 161 | #define KC_RWIN KC_RGUI |
162 | 162 | ||
163 | /* Generic Desktop Page (0x01) */ | 163 | /* Generic Desktop Page (0x01) */ |
164 | #define KC_PWR KC_SYSTEM_POWER | 164 | #define KC_PWR KC_SYSTEM_POWER |
165 | #define KC_SLEP KC_SYSTEM_SLEEP | 165 | #define KC_SLEP KC_SYSTEM_SLEEP |
166 | #define KC_WAKE KC_SYSTEM_WAKE | 166 | #define KC_WAKE KC_SYSTEM_WAKE |
167 | 167 | ||
@@ -214,171 +214,171 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
214 | 214 | ||
215 | /* Keyboard/Keypad Page (0x07) */ | 215 | /* Keyboard/Keypad Page (0x07) */ |
216 | enum hid_keyboard_keypad_usage { | 216 | enum hid_keyboard_keypad_usage { |
217 | KC_NO = 0x00, | 217 | KC_NO = 0x00, |
218 | KC_ROLL_OVER, | 218 | KC_ROLL_OVER, |
219 | KC_POST_FAIL, | 219 | KC_POST_FAIL, |
220 | KC_UNDEFINED, | 220 | KC_UNDEFINED, |
221 | KC_A, | 221 | KC_A, |
222 | KC_B, | 222 | KC_B, |
223 | KC_C, | 223 | KC_C, |
224 | KC_D, | 224 | KC_D, |
225 | KC_E, | 225 | KC_E, |
226 | KC_F, | 226 | KC_F, |
227 | KC_G, | 227 | KC_G, |
228 | KC_H, | 228 | KC_H, |
229 | KC_I, | 229 | KC_I, |
230 | KC_J, | 230 | KC_J, |
231 | KC_K, | 231 | KC_K, |
232 | KC_L, | 232 | KC_L, |
233 | KC_M, //0x10 | 233 | KC_M, // 0x10 |
234 | KC_N, | 234 | KC_N, |
235 | KC_O, | 235 | KC_O, |
236 | KC_P, | 236 | KC_P, |
237 | KC_Q, | 237 | KC_Q, |
238 | KC_R, | 238 | KC_R, |
239 | KC_S, | 239 | KC_S, |
240 | KC_T, | 240 | KC_T, |
241 | KC_U, | 241 | KC_U, |
242 | KC_V, | 242 | KC_V, |
243 | KC_W, | 243 | KC_W, |
244 | KC_X, | 244 | KC_X, |
245 | KC_Y, | 245 | KC_Y, |
246 | KC_Z, | 246 | KC_Z, |
247 | KC_1, | 247 | KC_1, |
248 | KC_2, | 248 | KC_2, |
249 | KC_3, //0x20 | 249 | KC_3, // 0x20 |
250 | KC_4, | 250 | KC_4, |
251 | KC_5, | 251 | KC_5, |
252 | KC_6, | 252 | KC_6, |
253 | KC_7, | 253 | KC_7, |
254 | KC_8, | 254 | KC_8, |
255 | KC_9, | 255 | KC_9, |
256 | KC_0, | 256 | KC_0, |
257 | KC_ENTER, | 257 | KC_ENTER, |
258 | KC_ESCAPE, | 258 | KC_ESCAPE, |
259 | KC_BSPACE, | 259 | KC_BSPACE, |
260 | KC_TAB, | 260 | KC_TAB, |
261 | KC_SPACE, | 261 | KC_SPACE, |
262 | KC_MINUS, | 262 | KC_MINUS, |
263 | KC_EQUAL, | 263 | KC_EQUAL, |
264 | KC_LBRACKET, | 264 | KC_LBRACKET, |
265 | KC_RBRACKET, //0x30 | 265 | KC_RBRACKET, // 0x30 |
266 | KC_BSLASH, | 266 | KC_BSLASH, |
267 | KC_NONUS_HASH, | 267 | KC_NONUS_HASH, |
268 | KC_SCOLON, | 268 | KC_SCOLON, |
269 | KC_QUOTE, | 269 | KC_QUOTE, |
270 | KC_GRAVE, | 270 | KC_GRAVE, |
271 | KC_COMMA, | 271 | KC_COMMA, |
272 | KC_DOT, | 272 | KC_DOT, |
273 | KC_SLASH, | 273 | KC_SLASH, |
274 | KC_CAPSLOCK, | 274 | KC_CAPSLOCK, |
275 | KC_F1, | 275 | KC_F1, |
276 | KC_F2, | 276 | KC_F2, |
277 | KC_F3, | 277 | KC_F3, |
278 | KC_F4, | 278 | KC_F4, |
279 | KC_F5, | 279 | KC_F5, |
280 | KC_F6, | 280 | KC_F6, |
281 | KC_F7, //0x40 | 281 | KC_F7, // 0x40 |
282 | KC_F8, | 282 | KC_F8, |
283 | KC_F9, | 283 | KC_F9, |
284 | KC_F10, | 284 | KC_F10, |
285 | KC_F11, | 285 | KC_F11, |
286 | KC_F12, | 286 | KC_F12, |
287 | KC_PSCREEN, | 287 | KC_PSCREEN, |
288 | KC_SCROLLLOCK, | 288 | KC_SCROLLLOCK, |
289 | KC_PAUSE, | 289 | KC_PAUSE, |
290 | KC_INSERT, | 290 | KC_INSERT, |
291 | KC_HOME, | 291 | KC_HOME, |
292 | KC_PGUP, | 292 | KC_PGUP, |
293 | KC_DELETE, | 293 | KC_DELETE, |
294 | KC_END, | 294 | KC_END, |
295 | KC_PGDOWN, | 295 | KC_PGDOWN, |
296 | KC_RIGHT, | 296 | KC_RIGHT, |
297 | KC_LEFT, //0x50 | 297 | KC_LEFT, // 0x50 |
298 | KC_DOWN, | 298 | KC_DOWN, |
299 | KC_UP, | 299 | KC_UP, |
300 | KC_NUMLOCK, | 300 | KC_NUMLOCK, |
301 | KC_KP_SLASH, | 301 | KC_KP_SLASH, |
302 | KC_KP_ASTERISK, | 302 | KC_KP_ASTERISK, |
303 | KC_KP_MINUS, | 303 | KC_KP_MINUS, |
304 | KC_KP_PLUS, | 304 | KC_KP_PLUS, |
305 | KC_KP_ENTER, | 305 | KC_KP_ENTER, |
306 | KC_KP_1, | 306 | KC_KP_1, |
307 | KC_KP_2, | 307 | KC_KP_2, |
308 | KC_KP_3, | 308 | KC_KP_3, |
309 | KC_KP_4, | 309 | KC_KP_4, |
310 | KC_KP_5, | 310 | KC_KP_5, |
311 | KC_KP_6, | 311 | KC_KP_6, |
312 | KC_KP_7, | 312 | KC_KP_7, |
313 | KC_KP_8, //0x60 | 313 | KC_KP_8, // 0x60 |
314 | KC_KP_9, | 314 | KC_KP_9, |
315 | KC_KP_0, | 315 | KC_KP_0, |
316 | KC_KP_DOT, | 316 | KC_KP_DOT, |
317 | KC_NONUS_BSLASH, | 317 | KC_NONUS_BSLASH, |
318 | KC_APPLICATION, | 318 | KC_APPLICATION, |
319 | KC_POWER, | 319 | KC_POWER, |
320 | KC_KP_EQUAL, | 320 | KC_KP_EQUAL, |
321 | KC_F13, | 321 | KC_F13, |
322 | KC_F14, | 322 | KC_F14, |
323 | KC_F15, | 323 | KC_F15, |
324 | KC_F16, | 324 | KC_F16, |
325 | KC_F17, | 325 | KC_F17, |
326 | KC_F18, | 326 | KC_F18, |
327 | KC_F19, | 327 | KC_F19, |
328 | KC_F20, | 328 | KC_F20, |
329 | KC_F21, //0x70 | 329 | KC_F21, // 0x70 |
330 | KC_F22, | 330 | KC_F22, |
331 | KC_F23, | 331 | KC_F23, |
332 | KC_F24, | 332 | KC_F24, |
333 | KC_EXECUTE, | 333 | KC_EXECUTE, |
334 | KC_HELP, | 334 | KC_HELP, |
335 | KC_MENU, | 335 | KC_MENU, |
336 | KC_SELECT, | 336 | KC_SELECT, |
337 | KC_STOP, | 337 | KC_STOP, |
338 | KC_AGAIN, | 338 | KC_AGAIN, |
339 | KC_UNDO, | 339 | KC_UNDO, |
340 | KC_CUT, | 340 | KC_CUT, |
341 | KC_COPY, | 341 | KC_COPY, |
342 | KC_PASTE, | 342 | KC_PASTE, |
343 | KC_FIND, | 343 | KC_FIND, |
344 | KC__MUTE, | 344 | KC__MUTE, |
345 | KC__VOLUP, //0x80 | 345 | KC__VOLUP, // 0x80 |
346 | KC__VOLDOWN, | 346 | KC__VOLDOWN, |
347 | KC_LOCKING_CAPS, | 347 | KC_LOCKING_CAPS, |
348 | KC_LOCKING_NUM, | 348 | KC_LOCKING_NUM, |
349 | KC_LOCKING_SCROLL, | 349 | KC_LOCKING_SCROLL, |
350 | KC_KP_COMMA, | 350 | KC_KP_COMMA, |
351 | KC_KP_EQUAL_AS400, | 351 | KC_KP_EQUAL_AS400, |
352 | KC_INT1, | 352 | KC_INT1, |
353 | KC_INT2, | 353 | KC_INT2, |
354 | KC_INT3, | 354 | KC_INT3, |
355 | KC_INT4, | 355 | KC_INT4, |
356 | KC_INT5, | 356 | KC_INT5, |
357 | KC_INT6, | 357 | KC_INT6, |
358 | KC_INT7, | 358 | KC_INT7, |
359 | KC_INT8, | 359 | KC_INT8, |
360 | KC_INT9, | 360 | KC_INT9, |
361 | KC_LANG1, //0x90 | 361 | KC_LANG1, // 0x90 |
362 | KC_LANG2, | 362 | KC_LANG2, |
363 | KC_LANG3, | 363 | KC_LANG3, |
364 | KC_LANG4, | 364 | KC_LANG4, |
365 | KC_LANG5, | 365 | KC_LANG5, |
366 | KC_LANG6, | 366 | KC_LANG6, |
367 | KC_LANG7, | 367 | KC_LANG7, |
368 | KC_LANG8, | 368 | KC_LANG8, |
369 | KC_LANG9, | 369 | KC_LANG9, |
370 | KC_ALT_ERASE, | 370 | KC_ALT_ERASE, |
371 | KC_SYSREQ, | 371 | KC_SYSREQ, |
372 | KC_CANCEL, | 372 | KC_CANCEL, |
373 | KC_CLEAR, | 373 | KC_CLEAR, |
374 | KC_PRIOR, | 374 | KC_PRIOR, |
375 | KC_RETURN, | 375 | KC_RETURN, |
376 | KC_SEPARATOR, | 376 | KC_SEPARATOR, |
377 | KC_OUT, //0xA0 | 377 | KC_OUT, // 0xA0 |
378 | KC_OPER, | 378 | KC_OPER, |
379 | KC_CLEAR_AGAIN, | 379 | KC_CLEAR_AGAIN, |
380 | KC_CRSEL, | 380 | KC_CRSEL, |
381 | KC_EXSEL, | 381 | KC_EXSEL, |
382 | 382 | ||
383 | #if 0 | 383 | #if 0 |
384 | // *************************************************************** | 384 | // *************************************************************** |
@@ -435,110 +435,110 @@ enum hid_keyboard_keypad_usage { | |||
435 | KC_KP_HEXADECIMAL, | 435 | KC_KP_HEXADECIMAL, |
436 | #endif | 436 | #endif |
437 | 437 | ||
438 | /* Modifiers */ | 438 | /* Modifiers */ |
439 | KC_LCTRL = 0xE0, | 439 | KC_LCTRL = 0xE0, |
440 | KC_LSHIFT, | 440 | KC_LSHIFT, |
441 | KC_LALT, | 441 | KC_LALT, |
442 | KC_LGUI, | 442 | KC_LGUI, |
443 | KC_RCTRL, | 443 | KC_RCTRL, |
444 | KC_RSHIFT, | 444 | KC_RSHIFT, |
445 | KC_RALT, | 445 | KC_RALT, |
446 | KC_RGUI | 446 | KC_RGUI |
447 | 447 | ||
448 | // ********************************************** | 448 | // ********************************************** |
449 | // * 0xF0-0xFF are unallocated in the HID spec. * | 449 | // * 0xF0-0xFF are unallocated in the HID spec. * |
450 | // * QMK uses these for Mouse Keys - see below. * | 450 | // * QMK uses these for Mouse Keys - see below. * |
451 | // ********************************************** | 451 | // ********************************************** |
452 | }; | 452 | }; |
453 | 453 | ||
454 | /* Media and Function keys */ | 454 | /* Media and Function keys */ |
455 | enum internal_special_keycodes { | 455 | enum internal_special_keycodes { |
456 | /* Generic Desktop Page (0x01) */ | 456 | /* Generic Desktop Page (0x01) */ |
457 | KC_SYSTEM_POWER = 0xA5, | 457 | KC_SYSTEM_POWER = 0xA5, |
458 | KC_SYSTEM_SLEEP, | 458 | KC_SYSTEM_SLEEP, |
459 | KC_SYSTEM_WAKE, | 459 | KC_SYSTEM_WAKE, |
460 | 460 | ||
461 | /* Consumer Page (0x0C) */ | 461 | /* Consumer Page (0x0C) */ |
462 | KC_AUDIO_MUTE, | 462 | KC_AUDIO_MUTE, |
463 | KC_AUDIO_VOL_UP, | 463 | KC_AUDIO_VOL_UP, |
464 | KC_AUDIO_VOL_DOWN, | 464 | KC_AUDIO_VOL_DOWN, |
465 | KC_MEDIA_NEXT_TRACK, | 465 | KC_MEDIA_NEXT_TRACK, |
466 | KC_MEDIA_PREV_TRACK, | 466 | KC_MEDIA_PREV_TRACK, |
467 | KC_MEDIA_STOP, | 467 | KC_MEDIA_STOP, |
468 | KC_MEDIA_PLAY_PAUSE, | 468 | KC_MEDIA_PLAY_PAUSE, |
469 | KC_MEDIA_SELECT, | 469 | KC_MEDIA_SELECT, |
470 | KC_MEDIA_EJECT, //0xB0 | 470 | KC_MEDIA_EJECT, // 0xB0 |
471 | KC_MAIL, | 471 | KC_MAIL, |
472 | KC_CALCULATOR, | 472 | KC_CALCULATOR, |
473 | KC_MY_COMPUTER, | 473 | KC_MY_COMPUTER, |
474 | KC_WWW_SEARCH, | 474 | KC_WWW_SEARCH, |
475 | KC_WWW_HOME, | 475 | KC_WWW_HOME, |
476 | KC_WWW_BACK, | 476 | KC_WWW_BACK, |
477 | KC_WWW_FORWARD, | 477 | KC_WWW_FORWARD, |
478 | KC_WWW_STOP, | 478 | KC_WWW_STOP, |
479 | KC_WWW_REFRESH, | 479 | KC_WWW_REFRESH, |
480 | KC_WWW_FAVORITES, | 480 | KC_WWW_FAVORITES, |
481 | KC_MEDIA_FAST_FORWARD, | 481 | KC_MEDIA_FAST_FORWARD, |
482 | KC_MEDIA_REWIND, | 482 | KC_MEDIA_REWIND, |
483 | KC_BRIGHTNESS_UP, | 483 | KC_BRIGHTNESS_UP, |
484 | KC_BRIGHTNESS_DOWN, | 484 | KC_BRIGHTNESS_DOWN, |
485 | 485 | ||
486 | /* Fn keys */ | 486 | /* Fn keys */ |
487 | KC_FN0 = 0xC0, | 487 | KC_FN0 = 0xC0, |
488 | KC_FN1, | 488 | KC_FN1, |
489 | KC_FN2, | 489 | KC_FN2, |
490 | KC_FN3, | 490 | KC_FN3, |
491 | KC_FN4, | 491 | KC_FN4, |
492 | KC_FN5, | 492 | KC_FN5, |
493 | KC_FN6, | 493 | KC_FN6, |
494 | KC_FN7, | 494 | KC_FN7, |
495 | KC_FN8, | 495 | KC_FN8, |
496 | KC_FN9, | 496 | KC_FN9, |
497 | KC_FN10, | 497 | KC_FN10, |
498 | KC_FN11, | 498 | KC_FN11, |
499 | KC_FN12, | 499 | KC_FN12, |
500 | KC_FN13, | 500 | KC_FN13, |
501 | KC_FN14, | 501 | KC_FN14, |
502 | KC_FN15, | 502 | KC_FN15, |
503 | KC_FN16, //0xD0 | 503 | KC_FN16, // 0xD0 |
504 | KC_FN17, | 504 | KC_FN17, |
505 | KC_FN18, | 505 | KC_FN18, |
506 | KC_FN19, | 506 | KC_FN19, |
507 | KC_FN20, | 507 | KC_FN20, |
508 | KC_FN21, | 508 | KC_FN21, |
509 | KC_FN22, | 509 | KC_FN22, |
510 | KC_FN23, | 510 | KC_FN23, |
511 | KC_FN24, | 511 | KC_FN24, |
512 | KC_FN25, | 512 | KC_FN25, |
513 | KC_FN26, | 513 | KC_FN26, |
514 | KC_FN27, | 514 | KC_FN27, |
515 | KC_FN28, | 515 | KC_FN28, |
516 | KC_FN29, | 516 | KC_FN29, |
517 | KC_FN30, | 517 | KC_FN30, |
518 | KC_FN31 | 518 | KC_FN31 |
519 | }; | 519 | }; |
520 | 520 | ||
521 | enum mouse_keys { | 521 | enum mouse_keys { |
522 | /* Mouse Buttons */ | 522 | /* Mouse Buttons */ |
523 | KC_MS_UP = 0xF0, | 523 | KC_MS_UP = 0xF0, |
524 | KC_MS_DOWN, | 524 | KC_MS_DOWN, |
525 | KC_MS_LEFT, | 525 | KC_MS_LEFT, |
526 | KC_MS_RIGHT, | 526 | KC_MS_RIGHT, |
527 | KC_MS_BTN1, | 527 | KC_MS_BTN1, |
528 | KC_MS_BTN2, | 528 | KC_MS_BTN2, |
529 | KC_MS_BTN3, | 529 | KC_MS_BTN3, |
530 | KC_MS_BTN4, | 530 | KC_MS_BTN4, |
531 | KC_MS_BTN5, | 531 | KC_MS_BTN5, |
532 | 532 | ||
533 | /* Mouse Wheel */ | 533 | /* Mouse Wheel */ |
534 | KC_MS_WH_UP, | 534 | KC_MS_WH_UP, |
535 | KC_MS_WH_DOWN, | 535 | KC_MS_WH_DOWN, |
536 | KC_MS_WH_LEFT, | 536 | KC_MS_WH_LEFT, |
537 | KC_MS_WH_RIGHT, | 537 | KC_MS_WH_RIGHT, |
538 | 538 | ||
539 | /* Acceleration */ | 539 | /* Acceleration */ |
540 | KC_MS_ACCEL0, | 540 | KC_MS_ACCEL0, |
541 | KC_MS_ACCEL1, | 541 | KC_MS_ACCEL1, |
542 | KC_MS_ACCEL2 | 542 | KC_MS_ACCEL2 |
543 | }; | 543 | }; |
544 | #endif | 544 | #endif |
diff --git a/tmk_core/common/led.h b/tmk_core/common/led.h index c16305129..2c28fe540 100644 --- a/tmk_core/common/led.h +++ b/tmk_core/common/led.h | |||
@@ -22,12 +22,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
22 | /* FIXME: Add doxygen comments here. */ | 22 | /* FIXME: Add doxygen comments here. */ |
23 | 23 | ||
24 | /* keyboard LEDs */ | 24 | /* keyboard LEDs */ |
25 | #define USB_LED_NUM_LOCK 0 | 25 | #define USB_LED_NUM_LOCK 0 |
26 | #define USB_LED_CAPS_LOCK 1 | 26 | #define USB_LED_CAPS_LOCK 1 |
27 | #define USB_LED_SCROLL_LOCK 2 | 27 | #define USB_LED_SCROLL_LOCK 2 |
28 | #define USB_LED_COMPOSE 3 | 28 | #define USB_LED_COMPOSE 3 |
29 | #define USB_LED_KANA 4 | 29 | #define USB_LED_KANA 4 |
30 | |||
31 | 30 | ||
32 | #ifdef __cplusplus | 31 | #ifdef __cplusplus |
33 | extern "C" { | 32 | extern "C" { |
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c index 2b1a6a6ad..d8ab52573 100644 --- a/tmk_core/common/magic.c +++ b/tmk_core/common/magic.c | |||
@@ -1,7 +1,7 @@ | |||
1 | #include <stdint.h> | 1 | #include <stdint.h> |
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #if defined(__AVR__) | 3 | #if defined(__AVR__) |
4 | #include <util/delay.h> | 4 | # include <util/delay.h> |
5 | #endif | 5 | #endif |
6 | #include "matrix.h" | 6 | #include "matrix.h" |
7 | #include "bootloader.h" | 7 | #include "bootloader.h" |
@@ -18,8 +18,7 @@ keymap_config_t keymap_config; | |||
18 | * | 18 | * |
19 | * FIXME: Needs doc | 19 | * FIXME: Needs doc |
20 | */ | 20 | */ |
21 | void magic(void) | 21 | void magic(void) { |
22 | { | ||
23 | /* check signature */ | 22 | /* check signature */ |
24 | if (!eeconfig_is_enabled()) { | 23 | if (!eeconfig_is_enabled()) { |
25 | eeconfig_init(); | 24 | eeconfig_init(); |
@@ -32,7 +31,6 @@ void magic(void) | |||
32 | keymap_config.raw = eeconfig_read_keymap(); | 31 | keymap_config.raw = eeconfig_read_keymap(); |
33 | 32 | ||
34 | uint8_t default_layer = 0; | 33 | uint8_t default_layer = 0; |
35 | default_layer = eeconfig_read_default_layer(); | 34 | default_layer = eeconfig_read_default_layer(); |
36 | default_layer_set((layer_state_t)default_layer); | 35 | default_layer_set((layer_state_t)default_layer); |
37 | |||
38 | } | 36 | } |
diff --git a/tmk_core/common/matrix.h b/tmk_core/common/matrix.h index e5665bf40..7624d5137 100644 --- a/tmk_core/common/matrix.h +++ b/tmk_core/common/matrix.h | |||
@@ -20,29 +20,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
20 | #include <stdint.h> | 20 | #include <stdint.h> |
21 | #include <stdbool.h> | 21 | #include <stdbool.h> |
22 | 22 | ||
23 | |||
24 | #if (MATRIX_COLS <= 8) | 23 | #if (MATRIX_COLS <= 8) |
25 | typedef uint8_t matrix_row_t; | 24 | typedef uint8_t matrix_row_t; |
26 | #elif (MATRIX_COLS <= 16) | 25 | #elif (MATRIX_COLS <= 16) |
27 | typedef uint16_t matrix_row_t; | 26 | typedef uint16_t matrix_row_t; |
28 | #elif (MATRIX_COLS <= 32) | 27 | #elif (MATRIX_COLS <= 32) |
29 | typedef uint32_t matrix_row_t; | 28 | typedef uint32_t matrix_row_t; |
30 | #else | 29 | #else |
31 | #error "MATRIX_COLS: invalid value" | 30 | # error "MATRIX_COLS: invalid value" |
32 | #endif | 31 | #endif |
33 | 32 | ||
34 | #if (MATRIX_ROWS <= 8) | 33 | #if (MATRIX_ROWS <= 8) |
35 | typedef uint8_t matrix_col_t; | 34 | typedef uint8_t matrix_col_t; |
36 | #elif (MATRIX_ROWS <= 16) | 35 | #elif (MATRIX_ROWS <= 16) |
37 | typedef uint16_t matrix_col_t; | 36 | typedef uint16_t matrix_col_t; |
38 | #elif (MATRIX_ROWS <= 32) | 37 | #elif (MATRIX_ROWS <= 32) |
39 | typedef uint32_t matrix_col_t; | 38 | typedef uint32_t matrix_col_t; |
40 | #else | 39 | #else |
41 | #error "MATRIX_ROWS: invalid value" | 40 | # error "MATRIX_ROWS: invalid value" |
42 | #endif | 41 | #endif |
43 | 42 | ||
44 | #define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1<<col)) | 43 | #define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1 << col)) |
45 | |||
46 | 44 | ||
47 | #ifdef __cplusplus | 45 | #ifdef __cplusplus |
48 | extern "C" { | 46 | extern "C" { |
@@ -59,7 +57,7 @@ void matrix_init(void); | |||
59 | /* scan all key states on matrix */ | 57 | /* scan all key states on matrix */ |
60 | uint8_t matrix_scan(void); | 58 | uint8_t matrix_scan(void); |
61 | /* whether modified from previous scan. used after matrix_scan. */ | 59 | /* whether modified from previous scan. used after matrix_scan. */ |
62 | bool matrix_is_modified(void) __attribute__ ((deprecated)); | 60 | bool matrix_is_modified(void) __attribute__((deprecated)); |
63 | /* whether a switch is on */ | 61 | /* whether a switch is on */ |
64 | bool matrix_is_on(uint8_t row, uint8_t col); | 62 | bool matrix_is_on(uint8_t row, uint8_t col); |
65 | /* matrix state on row */ | 63 | /* matrix state on row */ |
@@ -67,7 +65,6 @@ matrix_row_t matrix_get_row(uint8_t row); | |||
67 | /* print matrix for debug */ | 65 | /* print matrix for debug */ |
68 | void matrix_print(void); | 66 | void matrix_print(void); |
69 | 67 | ||
70 | |||
71 | /* power control */ | 68 | /* power control */ |
72 | void matrix_power_up(void); | 69 | void matrix_power_up(void); |
73 | void matrix_power_down(void); | 70 | void matrix_power_down(void); |
@@ -83,8 +80,8 @@ void matrix_init_user(void); | |||
83 | void matrix_scan_user(void); | 80 | void matrix_scan_user(void); |
84 | 81 | ||
85 | #ifdef I2C_SPLIT | 82 | #ifdef I2C_SPLIT |
86 | void slave_matrix_init(void); | 83 | void slave_matrix_init(void); |
87 | uint8_t slave_matrix_scan(void); | 84 | uint8_t slave_matrix_scan(void); |
88 | #endif | 85 | #endif |
89 | 86 | ||
90 | #ifdef __cplusplus | 87 | #ifdef __cplusplus |
diff --git a/tmk_core/common/mbed/bootloader.c b/tmk_core/common/mbed/bootloader.c index b51e83943..88945eb05 100644 --- a/tmk_core/common/mbed/bootloader.c +++ b/tmk_core/common/mbed/bootloader.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #include "bootloader.h" | 1 | #include "bootloader.h" |
2 | 2 | ||
3 | |||
4 | void bootloader_jump(void) {} | 3 | void bootloader_jump(void) {} |
diff --git a/tmk_core/common/mbed/suspend.c b/tmk_core/common/mbed/suspend.c index 32651574f..3d0554f87 100644 --- a/tmk_core/common/mbed/suspend.c +++ b/tmk_core/common/mbed/suspend.c | |||
@@ -1,6 +1,5 @@ | |||
1 | #include <stdbool.h> | 1 | #include <stdbool.h> |
2 | 2 | ||
3 | |||
4 | void suspend_power_down(void) {} | 3 | void suspend_power_down(void) {} |
5 | bool suspend_wakeup_condition(void) { return true; } | 4 | bool suspend_wakeup_condition(void) { return true; } |
6 | void suspend_wakeup_init(void) {} | 5 | void suspend_wakeup_init(void) {} |
diff --git a/tmk_core/common/mbed/timer.c b/tmk_core/common/mbed/timer.c index c357ceb78..7e4070af2 100644 --- a/tmk_core/common/mbed/timer.c +++ b/tmk_core/common/mbed/timer.c | |||
@@ -5,37 +5,19 @@ | |||
5 | volatile uint32_t timer_count = 0; | 5 | volatile uint32_t timer_count = 0; |
6 | 6 | ||
7 | /* Timer interrupt handler */ | 7 | /* Timer interrupt handler */ |
8 | void SysTick_Handler(void) { | 8 | void SysTick_Handler(void) { timer_count++; } |
9 | timer_count++; | ||
10 | } | ||
11 | 9 | ||
12 | void timer_init(void) | 10 | void timer_init(void) { |
13 | { | ||
14 | timer_count = 0; | 11 | timer_count = 0; |
15 | SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */ | 12 | SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */ |
16 | } | 13 | } |
17 | 14 | ||
18 | void timer_clear(void) | 15 | void timer_clear(void) { timer_count = 0; } |
19 | { | ||
20 | timer_count = 0; | ||
21 | } | ||
22 | 16 | ||
23 | uint16_t timer_read(void) | 17 | uint16_t timer_read(void) { return (uint16_t)(timer_count & 0xFFFF); } |
24 | { | ||
25 | return (uint16_t)(timer_count & 0xFFFF); | ||
26 | } | ||
27 | 18 | ||
28 | uint32_t timer_read32(void) | 19 | uint32_t timer_read32(void) { return timer_count; } |
29 | { | ||
30 | return timer_count; | ||
31 | } | ||
32 | 20 | ||
33 | uint16_t timer_elapsed(uint16_t last) | 21 | uint16_t timer_elapsed(uint16_t last) { return TIMER_DIFF_16(timer_read(), last); } |
34 | { | ||
35 | return TIMER_DIFF_16(timer_read(), last); | ||
36 | } | ||
37 | 22 | ||
38 | uint32_t timer_elapsed32(uint32_t last) | 23 | uint32_t timer_elapsed32(uint32_t last) { return TIMER_DIFF_32(timer_read32(), last); } |
39 | { | ||
40 | return TIMER_DIFF_32(timer_read32(), last); | ||
41 | } | ||
diff --git a/tmk_core/common/mbed/xprintf.cpp b/tmk_core/common/mbed/xprintf.cpp index b1aac2c99..184b7fa7a 100644 --- a/tmk_core/common/mbed/xprintf.cpp +++ b/tmk_core/common/mbed/xprintf.cpp | |||
@@ -3,10 +3,9 @@ | |||
3 | #include "mbed.h" | 3 | #include "mbed.h" |
4 | #include "mbed/xprintf.h" | 4 | #include "mbed/xprintf.h" |
5 | 5 | ||
6 | #define STRING_STACK_LIMIT 120 | ||
6 | 7 | ||
7 | #define STRING_STACK_LIMIT 120 | 8 | // TODO |
8 | |||
9 | //TODO | ||
10 | int __xprintf(const char* format, ...) { return 0; } | 9 | int __xprintf(const char* format, ...) { return 0; } |
11 | 10 | ||
12 | #if 0 | 11 | #if 0 |
diff --git a/tmk_core/common/mbed/xprintf.h b/tmk_core/common/mbed/xprintf.h index 1e7a48c06..e27822d3a 100644 --- a/tmk_core/common/mbed/xprintf.h +++ b/tmk_core/common/mbed/xprintf.h | |||
@@ -13,5 +13,4 @@ int __xprintf(const char *format, ...); | |||
13 | } | 13 | } |
14 | #endif | 14 | #endif |
15 | 15 | ||
16 | |||
17 | #endif | 16 | #endif |
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c index bb08576b9..2df7728a4 100644 --- a/tmk_core/common/mousekey.c +++ b/tmk_core/common/mousekey.c | |||
@@ -24,25 +24,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
24 | #include "mousekey.h" | 24 | #include "mousekey.h" |
25 | 25 | ||
26 | inline int8_t times_inv_sqrt2(int8_t x) { | 26 | inline int8_t times_inv_sqrt2(int8_t x) { |
27 | // 181/256 is pretty close to 1/sqrt(2) | 27 | // 181/256 is pretty close to 1/sqrt(2) |
28 | // 0.70703125 0.707106781 | 28 | // 0.70703125 0.707106781 |
29 | // 1 too small for x=99 and x=198 | 29 | // 1 too small for x=99 and x=198 |
30 | // This ends up being a mult and discard lower 8 bits | 30 | // This ends up being a mult and discard lower 8 bits |
31 | return (x * 181) >> 8; | 31 | return (x * 181) >> 8; |
32 | } | 32 | } |
33 | 33 | ||
34 | static report_mouse_t mouse_report = {0}; | 34 | static report_mouse_t mouse_report = {0}; |
35 | static void mousekey_debug(void); | 35 | static void mousekey_debug(void); |
36 | static uint8_t mousekey_accel = 0; | 36 | static uint8_t mousekey_accel = 0; |
37 | static uint8_t mousekey_repeat = 0; | 37 | static uint8_t mousekey_repeat = 0; |
38 | static uint16_t last_timer = 0; | 38 | static uint16_t last_timer = 0; |
39 | |||
40 | |||
41 | 39 | ||
42 | #ifndef MK_3_SPEED | 40 | #ifndef MK_3_SPEED |
43 | 41 | ||
44 | |||
45 | |||
46 | /* | 42 | /* |
47 | * Mouse keys acceleration algorithm | 43 | * Mouse keys acceleration algorithm |
48 | * http://en.wikipedia.org/wiki/Mouse_keys | 44 | * http://en.wikipedia.org/wiki/Mouse_keys |
@@ -50,7 +46,7 @@ static uint16_t last_timer = 0; | |||
50 | * speed = delta * max_speed * (repeat / time_to_max)**((1000+curve)/1000) | 46 | * speed = delta * max_speed * (repeat / time_to_max)**((1000+curve)/1000) |
51 | */ | 47 | */ |
52 | /* milliseconds between the initial key press and first repeated motion event (0-2550) */ | 48 | /* milliseconds between the initial key press and first repeated motion event (0-2550) */ |
53 | uint8_t mk_delay = MOUSEKEY_DELAY/10; | 49 | uint8_t mk_delay = MOUSEKEY_DELAY / 10; |
54 | /* milliseconds between repeated motion events (0-255) */ | 50 | /* milliseconds between repeated motion events (0-255) */ |
55 | uint8_t mk_interval = MOUSEKEY_INTERVAL; | 51 | uint8_t mk_interval = MOUSEKEY_INTERVAL; |
56 | /* steady speed (in action_delta units) applied each event (0-255) */ | 52 | /* steady speed (in action_delta units) applied each event (0-255) */ |
@@ -58,268 +54,320 @@ uint8_t mk_max_speed = MOUSEKEY_MAX_SPEED; | |||
58 | /* number of events (count) accelerating to steady speed (0-255) */ | 54 | /* number of events (count) accelerating to steady speed (0-255) */ |
59 | uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX; | 55 | uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX; |
60 | /* ramp used to reach maximum pointer speed (NOT SUPPORTED) */ | 56 | /* ramp used to reach maximum pointer speed (NOT SUPPORTED) */ |
61 | //int8_t mk_curve = 0; | 57 | // int8_t mk_curve = 0; |
62 | /* wheel params */ | 58 | /* wheel params */ |
63 | uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; | 59 | uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; |
64 | uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; | 60 | uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; |
65 | 61 | ||
66 | static uint8_t move_unit(void) { | 62 | static uint8_t move_unit(void) { |
67 | uint16_t unit; | 63 | uint16_t unit; |
68 | if (mousekey_accel & (1<<0)) { | 64 | if (mousekey_accel & (1 << 0)) { |
69 | unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/4; | 65 | unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 4; |
70 | } else if (mousekey_accel & (1<<1)) { | 66 | } else if (mousekey_accel & (1 << 1)) { |
71 | unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/2; | 67 | unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 2; |
72 | } else if (mousekey_accel & (1<<2)) { | 68 | } else if (mousekey_accel & (1 << 2)) { |
73 | unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed); | 69 | unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed); |
74 | } else if (mousekey_repeat == 0) { | 70 | } else if (mousekey_repeat == 0) { |
75 | unit = MOUSEKEY_MOVE_DELTA; | 71 | unit = MOUSEKEY_MOVE_DELTA; |
76 | } else if (mousekey_repeat >= mk_time_to_max) { | 72 | } else if (mousekey_repeat >= mk_time_to_max) { |
77 | unit = MOUSEKEY_MOVE_DELTA * mk_max_speed; | 73 | unit = MOUSEKEY_MOVE_DELTA * mk_max_speed; |
78 | } else { | 74 | } else { |
79 | unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max; | 75 | unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max; |
80 | } | 76 | } |
81 | return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit)); | 77 | return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit)); |
82 | } | 78 | } |
83 | 79 | ||
84 | static uint8_t wheel_unit(void) { | 80 | static uint8_t wheel_unit(void) { |
85 | uint16_t unit; | 81 | uint16_t unit; |
86 | if (mousekey_accel & (1<<0)) { | 82 | if (mousekey_accel & (1 << 0)) { |
87 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/4; | 83 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 4; |
88 | } else if (mousekey_accel & (1<<1)) { | 84 | } else if (mousekey_accel & (1 << 1)) { |
89 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/2; | 85 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2; |
90 | } else if (mousekey_accel & (1<<2)) { | 86 | } else if (mousekey_accel & (1 << 2)) { |
91 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed); | 87 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed); |
92 | } else if (mousekey_repeat == 0) { | 88 | } else if (mousekey_repeat == 0) { |
93 | unit = MOUSEKEY_WHEEL_DELTA; | 89 | unit = MOUSEKEY_WHEEL_DELTA; |
94 | } else if (mousekey_repeat >= mk_wheel_time_to_max) { | 90 | } else if (mousekey_repeat >= mk_wheel_time_to_max) { |
95 | unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed; | 91 | unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed; |
96 | } else { | 92 | } else { |
97 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max; | 93 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max; |
98 | } | 94 | } |
99 | return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit)); | 95 | return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit)); |
100 | } | 96 | } |
101 | 97 | ||
102 | void mousekey_task(void) { | 98 | void mousekey_task(void) { |
103 | if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay*10)) { | 99 | if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay * 10)) { |
104 | return; | 100 | return; |
105 | } | 101 | } |
106 | if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) { | 102 | if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) { |
107 | return; | 103 | return; |
108 | } | 104 | } |
109 | if (mousekey_repeat != UINT8_MAX) mousekey_repeat++; | 105 | if (mousekey_repeat != UINT8_MAX) mousekey_repeat++; |
110 | if (mouse_report.x > 0) mouse_report.x = move_unit(); | 106 | if (mouse_report.x > 0) mouse_report.x = move_unit(); |
111 | if (mouse_report.x < 0) mouse_report.x = move_unit() * -1; | 107 | if (mouse_report.x < 0) mouse_report.x = move_unit() * -1; |
112 | if (mouse_report.y > 0) mouse_report.y = move_unit(); | 108 | if (mouse_report.y > 0) mouse_report.y = move_unit(); |
113 | if (mouse_report.y < 0) mouse_report.y = move_unit() * -1; | 109 | if (mouse_report.y < 0) mouse_report.y = move_unit() * -1; |
114 | /* diagonal move [1/sqrt(2)] */ | 110 | /* diagonal move [1/sqrt(2)] */ |
115 | if (mouse_report.x && mouse_report.y) { | 111 | if (mouse_report.x && mouse_report.y) { |
116 | mouse_report.x = times_inv_sqrt2(mouse_report.x); | 112 | mouse_report.x = times_inv_sqrt2(mouse_report.x); |
117 | if (mouse_report.x == 0) { mouse_report.x = 1; } | 113 | if (mouse_report.x == 0) { |
118 | mouse_report.y = times_inv_sqrt2(mouse_report.y); | 114 | mouse_report.x = 1; |
119 | if (mouse_report.y == 0) { mouse_report.y = 1; } | 115 | } |
120 | } | 116 | mouse_report.y = times_inv_sqrt2(mouse_report.y); |
121 | if (mouse_report.v > 0) mouse_report.v = wheel_unit(); | 117 | if (mouse_report.y == 0) { |
122 | if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1; | 118 | mouse_report.y = 1; |
123 | if (mouse_report.h > 0) mouse_report.h = wheel_unit(); | 119 | } |
124 | if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1; | 120 | } |
125 | mousekey_send(); | 121 | if (mouse_report.v > 0) mouse_report.v = wheel_unit(); |
122 | if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1; | ||
123 | if (mouse_report.h > 0) mouse_report.h = wheel_unit(); | ||
124 | if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1; | ||
125 | mousekey_send(); | ||
126 | } | 126 | } |
127 | 127 | ||
128 | void mousekey_on(uint8_t code) { | 128 | void mousekey_on(uint8_t code) { |
129 | if (code == KC_MS_UP) mouse_report.y = move_unit() * -1; | 129 | if (code == KC_MS_UP) |
130 | else if (code == KC_MS_DOWN) mouse_report.y = move_unit(); | 130 | mouse_report.y = move_unit() * -1; |
131 | else if (code == KC_MS_LEFT) mouse_report.x = move_unit() * -1; | 131 | else if (code == KC_MS_DOWN) |
132 | else if (code == KC_MS_RIGHT) mouse_report.x = move_unit(); | 132 | mouse_report.y = move_unit(); |
133 | else if (code == KC_MS_WH_UP) mouse_report.v = wheel_unit(); | 133 | else if (code == KC_MS_LEFT) |
134 | else if (code == KC_MS_WH_DOWN) mouse_report.v = wheel_unit() * -1; | 134 | mouse_report.x = move_unit() * -1; |
135 | else if (code == KC_MS_WH_LEFT) mouse_report.h = wheel_unit() * -1; | 135 | else if (code == KC_MS_RIGHT) |
136 | else if (code == KC_MS_WH_RIGHT) mouse_report.h = wheel_unit(); | 136 | mouse_report.x = move_unit(); |
137 | else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1; | 137 | else if (code == KC_MS_WH_UP) |
138 | else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2; | 138 | mouse_report.v = wheel_unit(); |
139 | else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3; | 139 | else if (code == KC_MS_WH_DOWN) |
140 | else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4; | 140 | mouse_report.v = wheel_unit() * -1; |
141 | else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5; | 141 | else if (code == KC_MS_WH_LEFT) |
142 | else if (code == KC_MS_ACCEL0) mousekey_accel |= (1<<0); | 142 | mouse_report.h = wheel_unit() * -1; |
143 | else if (code == KC_MS_ACCEL1) mousekey_accel |= (1<<1); | 143 | else if (code == KC_MS_WH_RIGHT) |
144 | else if (code == KC_MS_ACCEL2) mousekey_accel |= (1<<2); | 144 | mouse_report.h = wheel_unit(); |
145 | else if (code == KC_MS_BTN1) | ||
146 | mouse_report.buttons |= MOUSE_BTN1; | ||
147 | else if (code == KC_MS_BTN2) | ||
148 | mouse_report.buttons |= MOUSE_BTN2; | ||
149 | else if (code == KC_MS_BTN3) | ||
150 | mouse_report.buttons |= MOUSE_BTN3; | ||
151 | else if (code == KC_MS_BTN4) | ||
152 | mouse_report.buttons |= MOUSE_BTN4; | ||
153 | else if (code == KC_MS_BTN5) | ||
154 | mouse_report.buttons |= MOUSE_BTN5; | ||
155 | else if (code == KC_MS_ACCEL0) | ||
156 | mousekey_accel |= (1 << 0); | ||
157 | else if (code == KC_MS_ACCEL1) | ||
158 | mousekey_accel |= (1 << 1); | ||
159 | else if (code == KC_MS_ACCEL2) | ||
160 | mousekey_accel |= (1 << 2); | ||
145 | } | 161 | } |
146 | 162 | ||
147 | void mousekey_off(uint8_t code) { | 163 | void mousekey_off(uint8_t code) { |
148 | if (code == KC_MS_UP && mouse_report.y < 0) mouse_report.y = 0; | 164 | if (code == KC_MS_UP && mouse_report.y < 0) |
149 | else if (code == KC_MS_DOWN && mouse_report.y > 0) mouse_report.y = 0; | 165 | mouse_report.y = 0; |
150 | else if (code == KC_MS_LEFT && mouse_report.x < 0) mouse_report.x = 0; | 166 | else if (code == KC_MS_DOWN && mouse_report.y > 0) |
151 | else if (code == KC_MS_RIGHT && mouse_report.x > 0) mouse_report.x = 0; | 167 | mouse_report.y = 0; |
152 | else if (code == KC_MS_WH_UP && mouse_report.v > 0) mouse_report.v = 0; | 168 | else if (code == KC_MS_LEFT && mouse_report.x < 0) |
153 | else if (code == KC_MS_WH_DOWN && mouse_report.v < 0) mouse_report.v = 0; | 169 | mouse_report.x = 0; |
154 | else if (code == KC_MS_WH_LEFT && mouse_report.h < 0) mouse_report.h = 0; | 170 | else if (code == KC_MS_RIGHT && mouse_report.x > 0) |
155 | else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) mouse_report.h = 0; | 171 | mouse_report.x = 0; |
156 | else if (code == KC_MS_BTN1) mouse_report.buttons &= ~MOUSE_BTN1; | 172 | else if (code == KC_MS_WH_UP && mouse_report.v > 0) |
157 | else if (code == KC_MS_BTN2) mouse_report.buttons &= ~MOUSE_BTN2; | 173 | mouse_report.v = 0; |
158 | else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3; | 174 | else if (code == KC_MS_WH_DOWN && mouse_report.v < 0) |
159 | else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4; | 175 | mouse_report.v = 0; |
160 | else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5; | 176 | else if (code == KC_MS_WH_LEFT && mouse_report.h < 0) |
161 | else if (code == KC_MS_ACCEL0) mousekey_accel &= ~(1<<0); | 177 | mouse_report.h = 0; |
162 | else if (code == KC_MS_ACCEL1) mousekey_accel &= ~(1<<1); | 178 | else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) |
163 | else if (code == KC_MS_ACCEL2) mousekey_accel &= ~(1<<2); | 179 | mouse_report.h = 0; |
164 | if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) | 180 | else if (code == KC_MS_BTN1) |
165 | mousekey_repeat = 0; | 181 | mouse_report.buttons &= ~MOUSE_BTN1; |
182 | else if (code == KC_MS_BTN2) | ||
183 | mouse_report.buttons &= ~MOUSE_BTN2; | ||
184 | else if (code == KC_MS_BTN3) | ||
185 | mouse_report.buttons &= ~MOUSE_BTN3; | ||
186 | else if (code == KC_MS_BTN4) | ||
187 | mouse_report.buttons &= ~MOUSE_BTN4; | ||
188 | else if (code == KC_MS_BTN5) | ||
189 | mouse_report.buttons &= ~MOUSE_BTN5; | ||
190 | else if (code == KC_MS_ACCEL0) | ||
191 | mousekey_accel &= ~(1 << 0); | ||
192 | else if (code == KC_MS_ACCEL1) | ||
193 | mousekey_accel &= ~(1 << 1); | ||
194 | else if (code == KC_MS_ACCEL2) | ||
195 | mousekey_accel &= ~(1 << 2); | ||
196 | if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) mousekey_repeat = 0; | ||
166 | } | 197 | } |
167 | 198 | ||
199 | #else /* #ifndef MK_3_SPEED */ | ||
168 | 200 | ||
169 | 201 | enum { mkspd_unmod, mkspd_0, mkspd_1, mkspd_2, mkspd_COUNT }; | |
170 | 202 | # ifndef MK_MOMENTARY_ACCEL | |
171 | #else /* #ifndef MK_3_SPEED */ | 203 | static uint8_t mk_speed = mkspd_1; |
172 | 204 | # else | |
173 | 205 | static uint8_t mk_speed = mkspd_unmod; | |
174 | |||
175 | enum { | ||
176 | mkspd_unmod, | ||
177 | mkspd_0, | ||
178 | mkspd_1, | ||
179 | mkspd_2, | ||
180 | mkspd_COUNT | ||
181 | }; | ||
182 | #ifndef MK_MOMENTARY_ACCEL | ||
183 | static uint8_t mk_speed = mkspd_1; | ||
184 | #else | ||
185 | static uint8_t mk_speed = mkspd_unmod; | ||
186 | static uint8_t mkspd_DEFAULT = mkspd_unmod; | 206 | static uint8_t mkspd_DEFAULT = mkspd_unmod; |
187 | #endif | 207 | # endif |
188 | static uint16_t last_timer_c = 0; | 208 | static uint16_t last_timer_c = 0; |
189 | static uint16_t last_timer_w = 0; | 209 | static uint16_t last_timer_w = 0; |
190 | uint16_t c_offsets[mkspd_COUNT] = { | 210 | uint16_t c_offsets[mkspd_COUNT] = {MK_C_OFFSET_UNMOD, MK_C_OFFSET_0, MK_C_OFFSET_1, MK_C_OFFSET_2}; |
191 | MK_C_OFFSET_UNMOD, MK_C_OFFSET_0, MK_C_OFFSET_1, MK_C_OFFSET_2 | 211 | uint16_t c_intervals[mkspd_COUNT] = {MK_C_INTERVAL_UNMOD, MK_C_INTERVAL_0, MK_C_INTERVAL_1, MK_C_INTERVAL_2}; |
192 | }; | 212 | uint16_t w_offsets[mkspd_COUNT] = {MK_W_OFFSET_UNMOD, MK_W_OFFSET_0, MK_W_OFFSET_1, MK_W_OFFSET_2}; |
193 | uint16_t c_intervals[mkspd_COUNT] = { | 213 | uint16_t w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0, MK_W_INTERVAL_1, MK_W_INTERVAL_2}; |
194 | MK_C_INTERVAL_UNMOD, MK_C_INTERVAL_0, MK_C_INTERVAL_1, MK_C_INTERVAL_2 | ||
195 | }; | ||
196 | uint16_t w_offsets[mkspd_COUNT] = { | ||
197 | MK_W_OFFSET_UNMOD, MK_W_OFFSET_0, MK_W_OFFSET_1, MK_W_OFFSET_2 | ||
198 | }; | ||
199 | uint16_t w_intervals[mkspd_COUNT] = { | ||
200 | MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0, MK_W_INTERVAL_1, MK_W_INTERVAL_2 | ||
201 | }; | ||
202 | |||
203 | 214 | ||
204 | void mousekey_task(void) { | 215 | void mousekey_task(void) { |
205 | // report cursor and scroll movement independently | 216 | // report cursor and scroll movement independently |
206 | report_mouse_t const tmpmr = mouse_report; | 217 | report_mouse_t const tmpmr = mouse_report; |
207 | if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) { | 218 | if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) { |
208 | mouse_report.h = 0; | 219 | mouse_report.h = 0; |
209 | mouse_report.v = 0; | 220 | mouse_report.v = 0; |
210 | mousekey_send(); | 221 | mousekey_send(); |
211 | last_timer_c = last_timer; | 222 | last_timer_c = last_timer; |
212 | mouse_report = tmpmr; | 223 | mouse_report = tmpmr; |
213 | } | 224 | } |
214 | if ((mouse_report.h || mouse_report.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) { | 225 | if ((mouse_report.h || mouse_report.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) { |
215 | mouse_report.x = 0; | 226 | mouse_report.x = 0; |
216 | mouse_report.y = 0; | 227 | mouse_report.y = 0; |
217 | mousekey_send(); | 228 | mousekey_send(); |
218 | last_timer_w = last_timer; | 229 | last_timer_w = last_timer; |
219 | mouse_report = tmpmr; | 230 | mouse_report = tmpmr; |
220 | } | 231 | } |
221 | } | 232 | } |
222 | 233 | ||
223 | void adjust_speed(void) { | 234 | void adjust_speed(void) { |
224 | uint16_t const c_offset = c_offsets[mk_speed]; | 235 | uint16_t const c_offset = c_offsets[mk_speed]; |
225 | uint16_t const w_offset = w_offsets[mk_speed]; | 236 | uint16_t const w_offset = w_offsets[mk_speed]; |
226 | if (mouse_report.x > 0) mouse_report.x = c_offset; | 237 | if (mouse_report.x > 0) mouse_report.x = c_offset; |
227 | if (mouse_report.x < 0) mouse_report.x = c_offset * -1; | 238 | if (mouse_report.x < 0) mouse_report.x = c_offset * -1; |
228 | if (mouse_report.y > 0) mouse_report.y = c_offset; | 239 | if (mouse_report.y > 0) mouse_report.y = c_offset; |
229 | if (mouse_report.y < 0) mouse_report.y = c_offset * -1; | 240 | if (mouse_report.y < 0) mouse_report.y = c_offset * -1; |
230 | if (mouse_report.h > 0) mouse_report.h = w_offset; | 241 | if (mouse_report.h > 0) mouse_report.h = w_offset; |
231 | if (mouse_report.h < 0) mouse_report.h = w_offset * -1; | 242 | if (mouse_report.h < 0) mouse_report.h = w_offset * -1; |
232 | if (mouse_report.v > 0) mouse_report.v = w_offset; | 243 | if (mouse_report.v > 0) mouse_report.v = w_offset; |
233 | if (mouse_report.v < 0) mouse_report.v = w_offset * -1; | 244 | if (mouse_report.v < 0) mouse_report.v = w_offset * -1; |
234 | // adjust for diagonals | 245 | // adjust for diagonals |
235 | if (mouse_report.x && mouse_report.y) { | 246 | if (mouse_report.x && mouse_report.y) { |
236 | mouse_report.x = times_inv_sqrt2(mouse_report.x); | 247 | mouse_report.x = times_inv_sqrt2(mouse_report.x); |
237 | if (mouse_report.x == 0) { mouse_report.x = 1; } | 248 | if (mouse_report.x == 0) { |
238 | mouse_report.y = times_inv_sqrt2(mouse_report.y); | 249 | mouse_report.x = 1; |
239 | if (mouse_report.y == 0) { mouse_report.y = 1; } | 250 | } |
240 | } | 251 | mouse_report.y = times_inv_sqrt2(mouse_report.y); |
241 | if (mouse_report.h && mouse_report.v) { | 252 | if (mouse_report.y == 0) { |
242 | mouse_report.h = times_inv_sqrt2(mouse_report.h); | 253 | mouse_report.y = 1; |
243 | mouse_report.v = times_inv_sqrt2(mouse_report.v); | 254 | } |
244 | } | 255 | } |
256 | if (mouse_report.h && mouse_report.v) { | ||
257 | mouse_report.h = times_inv_sqrt2(mouse_report.h); | ||
258 | mouse_report.v = times_inv_sqrt2(mouse_report.v); | ||
259 | } | ||
245 | } | 260 | } |
246 | 261 | ||
247 | void mousekey_on(uint8_t code) { | 262 | void mousekey_on(uint8_t code) { |
248 | uint16_t const c_offset = c_offsets[mk_speed]; | 263 | uint16_t const c_offset = c_offsets[mk_speed]; |
249 | uint16_t const w_offset = w_offsets[mk_speed]; | 264 | uint16_t const w_offset = w_offsets[mk_speed]; |
250 | uint8_t const old_speed = mk_speed; | 265 | uint8_t const old_speed = mk_speed; |
251 | if (code == KC_MS_UP) mouse_report.y = c_offset * -1; | 266 | if (code == KC_MS_UP) |
252 | else if (code == KC_MS_DOWN) mouse_report.y = c_offset; | 267 | mouse_report.y = c_offset * -1; |
253 | else if (code == KC_MS_LEFT) mouse_report.x = c_offset * -1; | 268 | else if (code == KC_MS_DOWN) |
254 | else if (code == KC_MS_RIGHT) mouse_report.x = c_offset; | 269 | mouse_report.y = c_offset; |
255 | else if (code == KC_MS_WH_UP) mouse_report.v = w_offset; | 270 | else if (code == KC_MS_LEFT) |
256 | else if (code == KC_MS_WH_DOWN) mouse_report.v = w_offset * -1; | 271 | mouse_report.x = c_offset * -1; |
257 | else if (code == KC_MS_WH_LEFT) mouse_report.h = w_offset * -1; | 272 | else if (code == KC_MS_RIGHT) |
258 | else if (code == KC_MS_WH_RIGHT) mouse_report.h = w_offset; | 273 | mouse_report.x = c_offset; |
259 | else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1; | 274 | else if (code == KC_MS_WH_UP) |
260 | else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2; | 275 | mouse_report.v = w_offset; |
261 | else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3; | 276 | else if (code == KC_MS_WH_DOWN) |
262 | else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4; | 277 | mouse_report.v = w_offset * -1; |
263 | else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5; | 278 | else if (code == KC_MS_WH_LEFT) |
264 | else if (code == KC_MS_ACCEL0) mk_speed = mkspd_0; | 279 | mouse_report.h = w_offset * -1; |
265 | else if (code == KC_MS_ACCEL1) mk_speed = mkspd_1; | 280 | else if (code == KC_MS_WH_RIGHT) |
266 | else if (code == KC_MS_ACCEL2) mk_speed = mkspd_2; | 281 | mouse_report.h = w_offset; |
267 | if (mk_speed != old_speed) adjust_speed(); | 282 | else if (code == KC_MS_BTN1) |
283 | mouse_report.buttons |= MOUSE_BTN1; | ||
284 | else if (code == KC_MS_BTN2) | ||
285 | mouse_report.buttons |= MOUSE_BTN2; | ||
286 | else if (code == KC_MS_BTN3) | ||
287 | mouse_report.buttons |= MOUSE_BTN3; | ||
288 | else if (code == KC_MS_BTN4) | ||
289 | mouse_report.buttons |= MOUSE_BTN4; | ||
290 | else if (code == KC_MS_BTN5) | ||
291 | mouse_report.buttons |= MOUSE_BTN5; | ||
292 | else if (code == KC_MS_ACCEL0) | ||
293 | mk_speed = mkspd_0; | ||
294 | else if (code == KC_MS_ACCEL1) | ||
295 | mk_speed = mkspd_1; | ||
296 | else if (code == KC_MS_ACCEL2) | ||
297 | mk_speed = mkspd_2; | ||
298 | if (mk_speed != old_speed) adjust_speed(); | ||
268 | } | 299 | } |
269 | 300 | ||
270 | void mousekey_off(uint8_t code) { | 301 | void mousekey_off(uint8_t code) { |
271 | #ifdef MK_MOMENTARY_ACCEL | 302 | # ifdef MK_MOMENTARY_ACCEL |
272 | uint8_t const old_speed = mk_speed; | 303 | uint8_t const old_speed = mk_speed; |
273 | #endif | 304 | # endif |
274 | if (code == KC_MS_UP && mouse_report.y < 0) mouse_report.y = 0; | 305 | if (code == KC_MS_UP && mouse_report.y < 0) |
275 | else if (code == KC_MS_DOWN && mouse_report.y > 0) mouse_report.y = 0; | 306 | mouse_report.y = 0; |
276 | else if (code == KC_MS_LEFT && mouse_report.x < 0) mouse_report.x = 0; | 307 | else if (code == KC_MS_DOWN && mouse_report.y > 0) |
277 | else if (code == KC_MS_RIGHT && mouse_report.x > 0) mouse_report.x = 0; | 308 | mouse_report.y = 0; |
278 | else if (code == KC_MS_WH_UP && mouse_report.v > 0) mouse_report.v = 0; | 309 | else if (code == KC_MS_LEFT && mouse_report.x < 0) |
279 | else if (code == KC_MS_WH_DOWN && mouse_report.v < 0) mouse_report.v = 0; | 310 | mouse_report.x = 0; |
280 | else if (code == KC_MS_WH_LEFT && mouse_report.h < 0) mouse_report.h = 0; | 311 | else if (code == KC_MS_RIGHT && mouse_report.x > 0) |
281 | else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) mouse_report.h = 0; | 312 | mouse_report.x = 0; |
282 | else if (code == KC_MS_BTN1) mouse_report.buttons &= ~MOUSE_BTN1; | 313 | else if (code == KC_MS_WH_UP && mouse_report.v > 0) |
283 | else if (code == KC_MS_BTN2) mouse_report.buttons &= ~MOUSE_BTN2; | 314 | mouse_report.v = 0; |
284 | else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3; | 315 | else if (code == KC_MS_WH_DOWN && mouse_report.v < 0) |
285 | else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4; | 316 | mouse_report.v = 0; |
286 | else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5; | 317 | else if (code == KC_MS_WH_LEFT && mouse_report.h < 0) |
287 | #ifdef MK_MOMENTARY_ACCEL | 318 | mouse_report.h = 0; |
288 | else if (code == KC_MS_ACCEL0) mk_speed = mkspd_DEFAULT; | 319 | else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) |
289 | else if (code == KC_MS_ACCEL1) mk_speed = mkspd_DEFAULT; | 320 | mouse_report.h = 0; |
290 | else if (code == KC_MS_ACCEL2) mk_speed = mkspd_DEFAULT; | 321 | else if (code == KC_MS_BTN1) |
291 | if (mk_speed != old_speed) adjust_speed(); | 322 | mouse_report.buttons &= ~MOUSE_BTN1; |
292 | #endif | 323 | else if (code == KC_MS_BTN2) |
324 | mouse_report.buttons &= ~MOUSE_BTN2; | ||
325 | else if (code == KC_MS_BTN3) | ||
326 | mouse_report.buttons &= ~MOUSE_BTN3; | ||
327 | else if (code == KC_MS_BTN4) | ||
328 | mouse_report.buttons &= ~MOUSE_BTN4; | ||
329 | else if (code == KC_MS_BTN5) | ||
330 | mouse_report.buttons &= ~MOUSE_BTN5; | ||
331 | # ifdef MK_MOMENTARY_ACCEL | ||
332 | else if (code == KC_MS_ACCEL0) | ||
333 | mk_speed = mkspd_DEFAULT; | ||
334 | else if (code == KC_MS_ACCEL1) | ||
335 | mk_speed = mkspd_DEFAULT; | ||
336 | else if (code == KC_MS_ACCEL2) | ||
337 | mk_speed = mkspd_DEFAULT; | ||
338 | if (mk_speed != old_speed) adjust_speed(); | ||
339 | # endif | ||
293 | } | 340 | } |
294 | 341 | ||
295 | |||
296 | |||
297 | |||
298 | #endif /* #ifndef MK_3_SPEED */ | 342 | #endif /* #ifndef MK_3_SPEED */ |
299 | 343 | ||
300 | |||
301 | |||
302 | |||
303 | void mousekey_send(void) { | 344 | void mousekey_send(void) { |
304 | mousekey_debug(); | 345 | mousekey_debug(); |
305 | host_mouse_send(&mouse_report); | 346 | host_mouse_send(&mouse_report); |
306 | last_timer = timer_read(); | 347 | last_timer = timer_read(); |
307 | } | 348 | } |
308 | 349 | ||
309 | void mousekey_clear(void) { | 350 | void mousekey_clear(void) { |
310 | mouse_report = (report_mouse_t){}; | 351 | mouse_report = (report_mouse_t){}; |
311 | mousekey_repeat = 0; | 352 | mousekey_repeat = 0; |
312 | mousekey_accel = 0; | 353 | mousekey_accel = 0; |
313 | } | 354 | } |
314 | 355 | ||
315 | static void mousekey_debug(void) { | 356 | static void mousekey_debug(void) { |
316 | if (!debug_mouse) return; | 357 | if (!debug_mouse) return; |
317 | print("mousekey [btn|x y v h](rep/acl): ["); | 358 | print("mousekey [btn|x y v h](rep/acl): ["); |
318 | phex(mouse_report.buttons); print("|"); | 359 | phex(mouse_report.buttons); |
319 | print_decs(mouse_report.x); print(" "); | 360 | print("|"); |
320 | print_decs(mouse_report.y); print(" "); | 361 | print_decs(mouse_report.x); |
321 | print_decs(mouse_report.v); print(" "); | 362 | print(" "); |
322 | print_decs(mouse_report.h); print("]("); | 363 | print_decs(mouse_report.y); |
323 | print_dec(mousekey_repeat); print("/"); | 364 | print(" "); |
324 | print_dec(mousekey_accel); print(")\n"); | 365 | print_decs(mouse_report.v); |
366 | print(" "); | ||
367 | print_decs(mouse_report.h); | ||
368 | print("]("); | ||
369 | print_dec(mousekey_repeat); | ||
370 | print("/"); | ||
371 | print_dec(mousekey_accel); | ||
372 | print(")\n"); | ||
325 | } | 373 | } |
diff --git a/tmk_core/common/mousekey.h b/tmk_core/common/mousekey.h index 89c1eaf11..48946987c 100644 --- a/tmk_core/common/mousekey.h +++ b/tmk_core/common/mousekey.h | |||
@@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #ifndef MOUSEKEY_H | 18 | #ifndef MOUSEKEY_H |
19 | #define MOUSEKEY_H | 19 | # define MOUSEKEY_H |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | #include <stdbool.h> | 22 | #include <stdbool.h> |
@@ -25,94 +25,94 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
25 | #ifndef MK_3_SPEED | 25 | #ifndef MK_3_SPEED |
26 | 26 | ||
27 | /* max value on report descriptor */ | 27 | /* max value on report descriptor */ |
28 | #ifndef MOUSEKEY_MOVE_MAX | 28 | # ifndef MOUSEKEY_MOVE_MAX |
29 | #define MOUSEKEY_MOVE_MAX 127 | 29 | # define MOUSEKEY_MOVE_MAX 127 |
30 | #elif MOUSEKEY_MOVE_MAX > 127 | 30 | # elif MOUSEKEY_MOVE_MAX > 127 |
31 | #error MOUSEKEY_MOVE_MAX needs to be smaller than 127 | 31 | # error MOUSEKEY_MOVE_MAX needs to be smaller than 127 |
32 | #endif | 32 | # endif |
33 | 33 | ||
34 | #ifndef MOUSEKEY_WHEEL_MAX | 34 | # ifndef MOUSEKEY_WHEEL_MAX |
35 | #define MOUSEKEY_WHEEL_MAX 127 | 35 | # define MOUSEKEY_WHEEL_MAX 127 |
36 | #elif MOUSEKEY_WHEEL_MAX > 127 | 36 | # elif MOUSEKEY_WHEEL_MAX > 127 |
37 | #error MOUSEKEY_WHEEL_MAX needs to be smaller than 127 | 37 | # error MOUSEKEY_WHEEL_MAX needs to be smaller than 127 |
38 | #endif | 38 | # endif |
39 | 39 | ||
40 | #ifndef MOUSEKEY_MOVE_DELTA | 40 | # ifndef MOUSEKEY_MOVE_DELTA |
41 | #define MOUSEKEY_MOVE_DELTA 5 | 41 | # define MOUSEKEY_MOVE_DELTA 5 |
42 | #endif | 42 | # endif |
43 | #ifndef MOUSEKEY_WHEEL_DELTA | 43 | # ifndef MOUSEKEY_WHEEL_DELTA |
44 | #define MOUSEKEY_WHEEL_DELTA 1 | 44 | # define MOUSEKEY_WHEEL_DELTA 1 |
45 | #endif | 45 | # endif |
46 | #ifndef MOUSEKEY_DELAY | 46 | # ifndef MOUSEKEY_DELAY |
47 | #define MOUSEKEY_DELAY 300 | 47 | # define MOUSEKEY_DELAY 300 |
48 | #endif | 48 | # endif |
49 | #ifndef MOUSEKEY_INTERVAL | 49 | # ifndef MOUSEKEY_INTERVAL |
50 | #define MOUSEKEY_INTERVAL 50 | 50 | # define MOUSEKEY_INTERVAL 50 |
51 | #endif | 51 | # endif |
52 | #ifndef MOUSEKEY_MAX_SPEED | 52 | # ifndef MOUSEKEY_MAX_SPEED |
53 | #define MOUSEKEY_MAX_SPEED 10 | 53 | # define MOUSEKEY_MAX_SPEED 10 |
54 | #endif | 54 | # endif |
55 | #ifndef MOUSEKEY_TIME_TO_MAX | 55 | # ifndef MOUSEKEY_TIME_TO_MAX |
56 | #define MOUSEKEY_TIME_TO_MAX 20 | 56 | # define MOUSEKEY_TIME_TO_MAX 20 |
57 | #endif | 57 | # endif |
58 | #ifndef MOUSEKEY_WHEEL_MAX_SPEED | 58 | # ifndef MOUSEKEY_WHEEL_MAX_SPEED |
59 | #define MOUSEKEY_WHEEL_MAX_SPEED 8 | 59 | # define MOUSEKEY_WHEEL_MAX_SPEED 8 |
60 | #endif | 60 | # endif |
61 | #ifndef MOUSEKEY_WHEEL_TIME_TO_MAX | 61 | # ifndef MOUSEKEY_WHEEL_TIME_TO_MAX |
62 | #define MOUSEKEY_WHEEL_TIME_TO_MAX 40 | 62 | # define MOUSEKEY_WHEEL_TIME_TO_MAX 40 |
63 | #endif | 63 | # endif |
64 | 64 | ||
65 | #else /* #ifndef MK_3_SPEED */ | 65 | #else /* #ifndef MK_3_SPEED */ |
66 | 66 | ||
67 | #ifndef MK_C_OFFSET_UNMOD | 67 | # ifndef MK_C_OFFSET_UNMOD |
68 | #define MK_C_OFFSET_UNMOD 16 | 68 | # define MK_C_OFFSET_UNMOD 16 |
69 | #endif | 69 | # endif |
70 | #ifndef MK_C_INTERVAL_UNMOD | 70 | # ifndef MK_C_INTERVAL_UNMOD |
71 | #define MK_C_INTERVAL_UNMOD 16 | 71 | # define MK_C_INTERVAL_UNMOD 16 |
72 | #endif | 72 | # endif |
73 | #ifndef MK_C_OFFSET_0 | 73 | # ifndef MK_C_OFFSET_0 |
74 | #define MK_C_OFFSET_0 1 | 74 | # define MK_C_OFFSET_0 1 |
75 | #endif | 75 | # endif |
76 | #ifndef MK_C_INTERVAL_0 | 76 | # ifndef MK_C_INTERVAL_0 |
77 | #define MK_C_INTERVAL_0 32 | 77 | # define MK_C_INTERVAL_0 32 |
78 | #endif | 78 | # endif |
79 | #ifndef MK_C_OFFSET_1 | 79 | # ifndef MK_C_OFFSET_1 |
80 | #define MK_C_OFFSET_1 4 | 80 | # define MK_C_OFFSET_1 4 |
81 | #endif | 81 | # endif |
82 | #ifndef MK_C_INTERVAL_1 | 82 | # ifndef MK_C_INTERVAL_1 |
83 | #define MK_C_INTERVAL_1 16 | 83 | # define MK_C_INTERVAL_1 16 |
84 | #endif | 84 | # endif |
85 | #ifndef MK_C_OFFSET_2 | 85 | # ifndef MK_C_OFFSET_2 |
86 | #define MK_C_OFFSET_2 32 | 86 | # define MK_C_OFFSET_2 32 |
87 | #endif | 87 | # endif |
88 | #ifndef MK_C_INTERVAL_2 | 88 | # ifndef MK_C_INTERVAL_2 |
89 | #define MK_C_INTERVAL_2 16 | 89 | # define MK_C_INTERVAL_2 16 |
90 | #endif | 90 | # endif |
91 | 91 | ||
92 | #ifndef MK_W_OFFSET_UNMOD | 92 | # ifndef MK_W_OFFSET_UNMOD |
93 | #define MK_W_OFFSET_UNMOD 1 | 93 | # define MK_W_OFFSET_UNMOD 1 |
94 | #endif | 94 | # endif |
95 | #ifndef MK_W_INTERVAL_UNMOD | 95 | # ifndef MK_W_INTERVAL_UNMOD |
96 | #define MK_W_INTERVAL_UNMOD 40 | 96 | # define MK_W_INTERVAL_UNMOD 40 |
97 | #endif | 97 | # endif |
98 | #ifndef MK_W_OFFSET_0 | 98 | # ifndef MK_W_OFFSET_0 |
99 | #define MK_W_OFFSET_0 1 | 99 | # define MK_W_OFFSET_0 1 |
100 | #endif | 100 | # endif |
101 | #ifndef MK_W_INTERVAL_0 | 101 | # ifndef MK_W_INTERVAL_0 |
102 | #define MK_W_INTERVAL_0 360 | 102 | # define MK_W_INTERVAL_0 360 |
103 | #endif | 103 | # endif |
104 | #ifndef MK_W_OFFSET_1 | 104 | # ifndef MK_W_OFFSET_1 |
105 | #define MK_W_OFFSET_1 1 | 105 | # define MK_W_OFFSET_1 1 |
106 | #endif | 106 | # endif |
107 | #ifndef MK_W_INTERVAL_1 | 107 | # ifndef MK_W_INTERVAL_1 |
108 | #define MK_W_INTERVAL_1 120 | 108 | # define MK_W_INTERVAL_1 120 |
109 | #endif | 109 | # endif |
110 | #ifndef MK_W_OFFSET_2 | 110 | # ifndef MK_W_OFFSET_2 |
111 | #define MK_W_OFFSET_2 1 | 111 | # define MK_W_OFFSET_2 1 |
112 | #endif | 112 | # endif |
113 | #ifndef MK_W_INTERVAL_2 | 113 | # ifndef MK_W_INTERVAL_2 |
114 | #define MK_W_INTERVAL_2 20 | 114 | # define MK_W_INTERVAL_2 20 |
115 | #endif | 115 | # endif |
116 | 116 | ||
117 | #endif /* #ifndef MK_3_SPEED */ | 117 | #endif /* #ifndef MK_3_SPEED */ |
118 | 118 | ||
diff --git a/tmk_core/common/nodebug.h b/tmk_core/common/nodebug.h index 5e18656e5..b9c8b3ac0 100644 --- a/tmk_core/common/nodebug.h +++ b/tmk_core/common/nodebug.h | |||
@@ -19,11 +19,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
19 | #define NODEBUG_H | 19 | #define NODEBUG_H |
20 | 20 | ||
21 | #ifndef NO_DEBUG | 21 | #ifndef NO_DEBUG |
22 | #define NO_DEBUG | 22 | # define NO_DEBUG |
23 | #include "debug.h" | 23 | # include "debug.h" |
24 | #undef NO_DEBUG | 24 | # undef NO_DEBUG |
25 | #else | 25 | #else |
26 | #include "debug.h" | 26 | # include "debug.h" |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | #endif | 29 | #endif |
diff --git a/tmk_core/common/print.c b/tmk_core/common/print.c index 00489557f..07aef0b0e 100644 --- a/tmk_core/common/print.c +++ b/tmk_core/common/print.c | |||
@@ -2,17 +2,17 @@ | |||
2 | /* Very basic print functions, intended to be used with usb_debug_only.c | 2 | /* Very basic print functions, intended to be used with usb_debug_only.c |
3 | * http://www.pjrc.com/teensy/ | 3 | * http://www.pjrc.com/teensy/ |
4 | * Copyright (c) 2008 PJRC.COM, LLC | 4 | * Copyright (c) 2008 PJRC.COM, LLC |
5 | * | 5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to deal | 7 | * of this software and associated documentation files (the "Software"), to deal |
8 | * in the Software without restriction, including without limitation the rights | 8 | * in the Software without restriction, including without limitation the rights |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 | * copies of the Software, and to permit persons to whom the Software is | 10 | * copies of the Software, and to permit persons to whom the Software is |
11 | * furnished to do so, subject to the following conditions: | 11 | * furnished to do so, subject to the following conditions: |
12 | * | 12 | * |
13 | * The above copyright notice and this permission notice shall be included in | 13 | * The above copyright notice and this permission notice shall be included in |
14 | * all copies or substantial portions of the Software. | 14 | * all copies or substantial portions of the Software. |
15 | * | 15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
@@ -25,28 +25,23 @@ | |||
25 | #include <stdint.h> | 25 | #include <stdint.h> |
26 | #include "print.h" | 26 | #include "print.h" |
27 | 27 | ||
28 | |||
29 | #ifndef NO_PRINT | 28 | #ifndef NO_PRINT |
30 | 29 | ||
31 | #if defined(__AVR__) | 30 | # if defined(__AVR__) |
32 | |||
33 | #define sendchar(c) xputc(c) | ||
34 | 31 | ||
32 | # define sendchar(c) xputc(c) | ||
35 | 33 | ||
36 | void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) | 34 | void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { xdev_out(sendchar_func); } |
37 | { | ||
38 | xdev_out(sendchar_func); | ||
39 | } | ||
40 | 35 | ||
41 | #elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */ | 36 | # elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */ |
42 | 37 | ||
43 | // don't need anything extra | 38 | // don't need anything extra |
44 | 39 | ||
45 | #elif defined(__arm__) /* __AVR__ */ | 40 | # elif defined(__arm__) /* __AVR__ */ |
46 | 41 | ||
47 | // TODO | 42 | // TODO |
48 | //void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { } | 43 | // void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { } |
49 | 44 | ||
50 | #endif /* __AVR__ */ | 45 | # endif /* __AVR__ */ |
51 | 46 | ||
52 | #endif | 47 | #endif |
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h index 2d7184bd0..20189838f 100644 --- a/tmk_core/common/print.h +++ b/tmk_core/common/print.h | |||
@@ -30,137 +30,136 @@ | |||
30 | #include "util.h" | 30 | #include "util.h" |
31 | 31 | ||
32 | #if defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM) | 32 | #if defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM) |
33 | #define PSTR(x) x | 33 | # define PSTR(x) x |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | |||
37 | #ifndef NO_PRINT | 36 | #ifndef NO_PRINT |
38 | 37 | ||
39 | #if defined(__AVR__) /* __AVR__ */ | 38 | # if defined(__AVR__) /* __AVR__ */ |
40 | 39 | ||
41 | # include "avr/xprintf.h" | 40 | # include "avr/xprintf.h" |
42 | 41 | ||
43 | # ifdef USER_PRINT /* USER_PRINT */ | 42 | # ifdef USER_PRINT /* USER_PRINT */ |
44 | 43 | ||
45 | // Remove normal print defines | 44 | // Remove normal print defines |
46 | # define print(s) | 45 | # define print(s) |
47 | # define println(s) | 46 | # define println(s) |
48 | # undef xprintf | 47 | # undef xprintf |
49 | # define xprintf(fmt, ...) | 48 | # define xprintf(fmt, ...) |
50 | 49 | ||
51 | // Create user print defines | 50 | // Create user print defines |
52 | # define uprint(s) xputs(PSTR(s)) | 51 | # define uprint(s) xputs(PSTR(s)) |
53 | # define uprintln(s) xputs(PSTR(s "\r\n")) | 52 | # define uprintln(s) xputs(PSTR(s "\r\n")) |
54 | # define uprintf(fmt, ...) __xprintf(PSTR(fmt), ##__VA_ARGS__) | 53 | # define uprintf(fmt, ...) __xprintf(PSTR(fmt), ##__VA_ARGS__) |
55 | 54 | ||
56 | # else /* NORMAL PRINT */ | 55 | # else /* NORMAL PRINT */ |
57 | 56 | ||
58 | // Create user & normal print defines | 57 | // Create user & normal print defines |
59 | # define print(s) xputs(PSTR(s)) | 58 | # define print(s) xputs(PSTR(s)) |
60 | # define println(s) xputs(PSTR(s "\r\n")) | 59 | # define println(s) xputs(PSTR(s "\r\n")) |
61 | # define uprint(s) print(s) | 60 | # define uprint(s) print(s) |
62 | # define uprintln(s) println(s) | 61 | # define uprintln(s) println(s) |
63 | # define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__) | 62 | # define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__) |
64 | 63 | ||
65 | # endif /* USER_PRINT / NORMAL PRINT */ | 64 | # endif /* USER_PRINT / NORMAL PRINT */ |
66 | 65 | ||
67 | # ifdef __cplusplus | 66 | # ifdef __cplusplus |
68 | extern "C" | 67 | extern "C" |
69 | # endif | 68 | # endif |
70 | 69 | ||
71 | /* function pointer of sendchar to be used by print utility */ | 70 | /* function pointer of sendchar to be used by print utility */ |
72 | void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); | 71 | void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); |
73 | 72 | ||
74 | #elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */ | 73 | # elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */ |
75 | 74 | ||
76 | #ifndef TERMINAL_ENABLE | 75 | # ifndef TERMINAL_ENABLE |
77 | # include "chibios/printf.h" | 76 | # include "chibios/printf.h" |
78 | #endif | 77 | # endif |
79 | 78 | ||
80 | # ifdef USER_PRINT /* USER_PRINT */ | 79 | # ifdef USER_PRINT /* USER_PRINT */ |
81 | 80 | ||
82 | // Remove normal print defines | 81 | // Remove normal print defines |
83 | # define print(s) | 82 | # define print(s) |
84 | # define println(s) | 83 | # define println(s) |
85 | # define xprintf(fmt, ...) | 84 | # define xprintf(fmt, ...) |
86 | 85 | ||
87 | // Create user print defines | 86 | // Create user print defines |
88 | # define uprint(s) printf(s) | 87 | # define uprint(s) printf(s) |
89 | # define uprintln(s) printf(s "\r\n") | 88 | # define uprintln(s) printf(s "\r\n") |
90 | # define uprintf printf | 89 | # define uprintf printf |
91 | 90 | ||
92 | # else /* NORMAL PRINT */ | 91 | # else /* NORMAL PRINT */ |
93 | 92 | ||
94 | // Create user & normal print defines | 93 | // Create user & normal print defines |
95 | # define print(s) printf(s) | 94 | # define print(s) printf(s) |
96 | # define println(s) printf(s "\r\n") | 95 | # define println(s) printf(s "\r\n") |
97 | # define xprintf printf | 96 | # define xprintf printf |
98 | # define uprint(s) printf(s) | 97 | # define uprint(s) printf(s) |
99 | # define uprintln(s) printf(s "\r\n") | 98 | # define uprintln(s) printf(s "\r\n") |
100 | # define uprintf printf | 99 | # define uprintf printf |
101 | 100 | ||
102 | # endif /* USER_PRINT / NORMAL PRINT */ | 101 | # endif /* USER_PRINT / NORMAL PRINT */ |
103 | 102 | ||
104 | #elif defined(PROTOCOL_ARM_ATSAM) /* PROTOCOL_ARM_ATSAM */ | 103 | # elif defined(PROTOCOL_ARM_ATSAM) /* PROTOCOL_ARM_ATSAM */ |
105 | 104 | ||
106 | # include "arm_atsam/printf.h" | 105 | # include "arm_atsam/printf.h" |
107 | 106 | ||
108 | # ifdef USER_PRINT /* USER_PRINT */ | 107 | # ifdef USER_PRINT /* USER_PRINT */ |
109 | 108 | ||
110 | // Remove normal print defines | 109 | // Remove normal print defines |
111 | # define print(s) | 110 | # define print(s) |
112 | # define println(s) | 111 | # define println(s) |
113 | # define xprintf(fmt, ...) | 112 | # define xprintf(fmt, ...) |
114 | 113 | ||
115 | // Create user print defines | 114 | // Create user print defines |
116 | # define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | 115 | # define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) |
117 | # define uprint(s) xprintf(s) | 116 | # define uprint(s) xprintf(s) |
118 | # define uprintln(s) xprintf(s "\r\n") | 117 | # define uprintln(s) xprintf(s "\r\n") |
119 | 118 | ||
120 | # else /* NORMAL PRINT */ | 119 | # else /* NORMAL PRINT */ |
121 | 120 | ||
122 | // Create user & normal print defines | 121 | // Create user & normal print defines |
123 | # define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | 122 | # define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) |
124 | # define print(s) xprintf(s) | 123 | # define print(s) xprintf(s) |
125 | # define println(s) xprintf(s "\r\n") | 124 | # define println(s) xprintf(s "\r\n") |
126 | # define uprint(s) print(s) | 125 | # define uprint(s) print(s) |
127 | # define uprintln(s) println(s) | 126 | # define uprintln(s) println(s) |
128 | # define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__) | 127 | # define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__) |
129 | 128 | ||
130 | # endif /* USER_PRINT / NORMAL PRINT */ | 129 | # endif /* USER_PRINT / NORMAL PRINT */ |
131 | 130 | ||
132 | #elif defined(__arm__) /* __arm__ */ | 131 | # elif defined(__arm__) /* __arm__ */ |
133 | 132 | ||
134 | # include "mbed/xprintf.h" | 133 | # include "mbed/xprintf.h" |
135 | 134 | ||
136 | # ifdef USER_PRINT /* USER_PRINT */ | 135 | # ifdef USER_PRINT /* USER_PRINT */ |
137 | 136 | ||
138 | // Remove normal print defines | 137 | // Remove normal print defines |
139 | # define print(s) | 138 | # define print(s) |
140 | # define println(s) | 139 | # define println(s) |
141 | # define xprintf(fmt, ...) | 140 | # define xprintf(fmt, ...) |
142 | 141 | ||
143 | // Create user print defines | 142 | // Create user print defines |
144 | # define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | 143 | # define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) |
145 | # define uprint(s) xprintf(s) | 144 | # define uprint(s) xprintf(s) |
146 | # define uprintln(s) xprintf(s "\r\n") | 145 | # define uprintln(s) xprintf(s "\r\n") |
147 | 146 | ||
148 | # else /* NORMAL PRINT */ | 147 | # else /* NORMAL PRINT */ |
149 | 148 | ||
150 | // Create user & normal print defines | 149 | // Create user & normal print defines |
151 | # define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | 150 | # define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) |
152 | # define print(s) xprintf(s) | 151 | # define print(s) xprintf(s) |
153 | # define println(s) xprintf(s "\r\n") | 152 | # define println(s) xprintf(s "\r\n") |
154 | # define uprint(s) print(s) | 153 | # define uprint(s) print(s) |
155 | # define uprintln(s) println(s) | 154 | # define uprintln(s) println(s) |
156 | # define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__) | 155 | # define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__) |
157 | 156 | ||
158 | # endif /* USER_PRINT / NORMAL PRINT */ | 157 | # endif /* USER_PRINT / NORMAL PRINT */ |
159 | 158 | ||
160 | /* TODO: to select output destinations: UART/USBSerial */ | 159 | /* TODO: to select output destinations: UART/USBSerial */ |
161 | # define print_set_sendchar(func) | 160 | # define print_set_sendchar(func) |
162 | 161 | ||
163 | #endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM / __arm__ */ | 162 | # endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM / __arm__ */ |
164 | 163 | ||
165 | // User print disables the normal print messages in the body of QMK/TMK code and | 164 | // User print disables the normal print messages in the body of QMK/TMK code and |
166 | // is meant as a lightweight alternative to NOPRINT. Use it when you only want to do | 165 | // is meant as a lightweight alternative to NOPRINT. Use it when you only want to do |
@@ -169,141 +168,140 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); | |||
169 | // | 168 | // |
170 | // !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!! | 169 | // !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!! |
171 | // | 170 | // |
172 | #ifdef USER_PRINT | 171 | # ifdef USER_PRINT |
173 | 172 | ||
174 | // Disable normal print | 173 | // Disable normal print |
175 | #define print_dec(data) | 174 | # define print_dec(data) |
176 | #define print_decs(data) | 175 | # define print_decs(data) |
177 | #define print_hex4(data) | 176 | # define print_hex4(data) |
178 | #define print_hex8(data) | 177 | # define print_hex8(data) |
179 | #define print_hex16(data) | 178 | # define print_hex16(data) |
180 | #define print_hex32(data) | 179 | # define print_hex32(data) |
181 | #define print_bin4(data) | 180 | # define print_bin4(data) |
182 | #define print_bin8(data) | 181 | # define print_bin8(data) |
183 | #define print_bin16(data) | 182 | # define print_bin16(data) |
184 | #define print_bin32(data) | 183 | # define print_bin32(data) |
185 | #define print_bin_reverse8(data) | 184 | # define print_bin_reverse8(data) |
186 | #define print_bin_reverse16(data) | 185 | # define print_bin_reverse16(data) |
187 | #define print_bin_reverse32(data) | 186 | # define print_bin_reverse32(data) |
188 | #define print_val_dec(v) | 187 | # define print_val_dec(v) |
189 | #define print_val_decs(v) | 188 | # define print_val_decs(v) |
190 | #define print_val_hex8(v) | 189 | # define print_val_hex8(v) |
191 | #define print_val_hex16(v) | 190 | # define print_val_hex16(v) |
192 | #define print_val_hex32(v) | 191 | # define print_val_hex32(v) |
193 | #define print_val_bin8(v) | 192 | # define print_val_bin8(v) |
194 | #define print_val_bin16(v) | 193 | # define print_val_bin16(v) |
195 | #define print_val_bin32(v) | 194 | # define print_val_bin32(v) |
196 | #define print_val_bin_reverse8(v) | 195 | # define print_val_bin_reverse8(v) |
197 | #define print_val_bin_reverse16(v) | 196 | # define print_val_bin_reverse16(v) |
198 | #define print_val_bin_reverse32(v) | 197 | # define print_val_bin_reverse32(v) |
199 | 198 | ||
200 | #else /* NORMAL_PRINT */ | 199 | # else /* NORMAL_PRINT */ |
201 | 200 | ||
202 | //Enable normal print | 201 | // Enable normal print |
203 | /* decimal */ | 202 | /* decimal */ |
204 | #define print_dec(i) xprintf("%u", i) | 203 | # define print_dec(i) xprintf("%u", i) |
205 | #define print_decs(i) xprintf("%d", i) | 204 | # define print_decs(i) xprintf("%d", i) |
206 | /* hex */ | 205 | /* hex */ |
207 | #define print_hex4(i) xprintf("%X", i) | 206 | # define print_hex4(i) xprintf("%X", i) |
208 | #define print_hex8(i) xprintf("%02X", i) | 207 | # define print_hex8(i) xprintf("%02X", i) |
209 | #define print_hex16(i) xprintf("%04X", i) | 208 | # define print_hex16(i) xprintf("%04X", i) |
210 | #define print_hex32(i) xprintf("%08lX", i) | 209 | # define print_hex32(i) xprintf("%08lX", i) |
211 | /* binary */ | 210 | /* binary */ |
212 | #define print_bin4(i) xprintf("%04b", i) | 211 | # define print_bin4(i) xprintf("%04b", i) |
213 | #define print_bin8(i) xprintf("%08b", i) | 212 | # define print_bin8(i) xprintf("%08b", i) |
214 | #define print_bin16(i) xprintf("%016b", i) | 213 | # define print_bin16(i) xprintf("%016b", i) |
215 | #define print_bin32(i) xprintf("%032lb", i) | 214 | # define print_bin32(i) xprintf("%032lb", i) |
216 | #define print_bin_reverse8(i) xprintf("%08b", bitrev(i)) | 215 | # define print_bin_reverse8(i) xprintf("%08b", bitrev(i)) |
217 | #define print_bin_reverse16(i) xprintf("%016b", bitrev16(i)) | 216 | # define print_bin_reverse16(i) xprintf("%016b", bitrev16(i)) |
218 | #define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i)) | 217 | # define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i)) |
219 | /* print value utility */ | 218 | /* print value utility */ |
220 | #define print_val_dec(v) xprintf(#v ": %u\n", v) | 219 | # define print_val_dec(v) xprintf(# v ": %u\n", v) |
221 | #define print_val_decs(v) xprintf(#v ": %d\n", v) | 220 | # define print_val_decs(v) xprintf(# v ": %d\n", v) |
222 | #define print_val_hex8(v) xprintf(#v ": %X\n", v) | 221 | # define print_val_hex8(v) xprintf(# v ": %X\n", v) |
223 | #define print_val_hex16(v) xprintf(#v ": %02X\n", v) | 222 | # define print_val_hex16(v) xprintf(# v ": %02X\n", v) |
224 | #define print_val_hex32(v) xprintf(#v ": %04lX\n", v) | 223 | # define print_val_hex32(v) xprintf(# v ": %04lX\n", v) |
225 | #define print_val_bin8(v) xprintf(#v ": %08b\n", v) | 224 | # define print_val_bin8(v) xprintf(# v ": %08b\n", v) |
226 | #define print_val_bin16(v) xprintf(#v ": %016b\n", v) | 225 | # define print_val_bin16(v) xprintf(# v ": %016b\n", v) |
227 | #define print_val_bin32(v) xprintf(#v ": %032lb\n", v) | 226 | # define print_val_bin32(v) xprintf(# v ": %032lb\n", v) |
228 | #define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v)) | 227 | # define print_val_bin_reverse8(v) xprintf(# v ": %08b\n", bitrev(v)) |
229 | #define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v)) | 228 | # define print_val_bin_reverse16(v) xprintf(# v ": %016b\n", bitrev16(v)) |
230 | #define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v)) | 229 | # define print_val_bin_reverse32(v) xprintf(# v ": %032lb\n", bitrev32(v)) |
231 | 230 | ||
232 | #endif /* USER_PRINT / NORMAL_PRINT */ | 231 | # endif /* USER_PRINT / NORMAL_PRINT */ |
233 | 232 | ||
234 | // User Print | 233 | // User Print |
235 | 234 | ||
236 | /* decimal */ | 235 | /* decimal */ |
237 | #define uprint_dec(i) uprintf("%u", i) | 236 | # define uprint_dec(i) uprintf("%u", i) |
238 | #define uprint_decs(i) uprintf("%d", i) | 237 | # define uprint_decs(i) uprintf("%d", i) |
239 | /* hex */ | 238 | /* hex */ |
240 | #define uprint_hex4(i) uprintf("%X", i) | 239 | # define uprint_hex4(i) uprintf("%X", i) |
241 | #define uprint_hex8(i) uprintf("%02X", i) | 240 | # define uprint_hex8(i) uprintf("%02X", i) |
242 | #define uprint_hex16(i) uprintf("%04X", i) | 241 | # define uprint_hex16(i) uprintf("%04X", i) |
243 | #define uprint_hex32(i) uprintf("%08lX", i) | 242 | # define uprint_hex32(i) uprintf("%08lX", i) |
244 | /* binary */ | 243 | /* binary */ |
245 | #define uprint_bin4(i) uprintf("%04b", i) | 244 | # define uprint_bin4(i) uprintf("%04b", i) |
246 | #define uprint_bin8(i) uprintf("%08b", i) | 245 | # define uprint_bin8(i) uprintf("%08b", i) |
247 | #define uprint_bin16(i) uprintf("%016b", i) | 246 | # define uprint_bin16(i) uprintf("%016b", i) |
248 | #define uprint_bin32(i) uprintf("%032lb", i) | 247 | # define uprint_bin32(i) uprintf("%032lb", i) |
249 | #define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i)) | 248 | # define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i)) |
250 | #define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i)) | 249 | # define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i)) |
251 | #define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i)) | 250 | # define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i)) |
252 | /* print value utility */ | 251 | /* print value utility */ |
253 | #define uprint_val_dec(v) uprintf(#v ": %u\n", v) | 252 | # define uprint_val_dec(v) uprintf(# v ": %u\n", v) |
254 | #define uprint_val_decs(v) uprintf(#v ": %d\n", v) | 253 | # define uprint_val_decs(v) uprintf(# v ": %d\n", v) |
255 | #define uprint_val_hex8(v) uprintf(#v ": %X\n", v) | 254 | # define uprint_val_hex8(v) uprintf(# v ": %X\n", v) |
256 | #define uprint_val_hex16(v) uprintf(#v ": %02X\n", v) | 255 | # define uprint_val_hex16(v) uprintf(# v ": %02X\n", v) |
257 | #define uprint_val_hex32(v) uprintf(#v ": %04lX\n", v) | 256 | # define uprint_val_hex32(v) uprintf(# v ": %04lX\n", v) |
258 | #define uprint_val_bin8(v) uprintf(#v ": %08b\n", v) | 257 | # define uprint_val_bin8(v) uprintf(# v ": %08b\n", v) |
259 | #define uprint_val_bin16(v) uprintf(#v ": %016b\n", v) | 258 | # define uprint_val_bin16(v) uprintf(# v ": %016b\n", v) |
260 | #define uprint_val_bin32(v) uprintf(#v ": %032lb\n", v) | 259 | # define uprint_val_bin32(v) uprintf(# v ": %032lb\n", v) |
261 | #define uprint_val_bin_reverse8(v) uprintf(#v ": %08b\n", bitrev(v)) | 260 | # define uprint_val_bin_reverse8(v) uprintf(# v ": %08b\n", bitrev(v)) |
262 | #define uprint_val_bin_reverse16(v) uprintf(#v ": %016b\n", bitrev16(v)) | 261 | # define uprint_val_bin_reverse16(v) uprintf(# v ": %016b\n", bitrev16(v)) |
263 | #define uprint_val_bin_reverse32(v) uprintf(#v ": %032lb\n", bitrev32(v)) | 262 | # define uprint_val_bin_reverse32(v) uprintf(# v ": %032lb\n", bitrev32(v)) |
264 | 263 | ||
265 | #else /* NO_PRINT */ | 264 | #else /* NO_PRINT */ |
266 | |||
267 | #define xprintf(fmt, ...) | ||
268 | #define print(s) | ||
269 | #define println(s) | ||
270 | #define print_set_sendchar(func) | ||
271 | #define print_dec(data) | ||
272 | #define print_decs(data) | ||
273 | #define print_hex4(data) | ||
274 | #define print_hex8(data) | ||
275 | #define print_hex16(data) | ||
276 | #define print_hex32(data) | ||
277 | #define print_bin4(data) | ||
278 | #define print_bin8(data) | ||
279 | #define print_bin16(data) | ||
280 | #define print_bin32(data) | ||
281 | #define print_bin_reverse8(data) | ||
282 | #define print_bin_reverse16(data) | ||
283 | #define print_bin_reverse32(data) | ||
284 | #define print_val_dec(v) | ||
285 | #define print_val_decs(v) | ||
286 | #define print_val_hex8(v) | ||
287 | #define print_val_hex16(v) | ||
288 | #define print_val_hex32(v) | ||
289 | #define print_val_bin8(v) | ||
290 | #define print_val_bin16(v) | ||
291 | #define print_val_bin32(v) | ||
292 | #define print_val_bin_reverse8(v) | ||
293 | #define print_val_bin_reverse16(v) | ||
294 | #define print_val_bin_reverse32(v) | ||
295 | |||
296 | #endif /* NO_PRINT */ | ||
297 | 265 | ||
266 | # define xprintf(fmt, ...) | ||
267 | # define print(s) | ||
268 | # define println(s) | ||
269 | # define print_set_sendchar(func) | ||
270 | # define print_dec(data) | ||
271 | # define print_decs(data) | ||
272 | # define print_hex4(data) | ||
273 | # define print_hex8(data) | ||
274 | # define print_hex16(data) | ||
275 | # define print_hex32(data) | ||
276 | # define print_bin4(data) | ||
277 | # define print_bin8(data) | ||
278 | # define print_bin16(data) | ||
279 | # define print_bin32(data) | ||
280 | # define print_bin_reverse8(data) | ||
281 | # define print_bin_reverse16(data) | ||
282 | # define print_bin_reverse32(data) | ||
283 | # define print_val_dec(v) | ||
284 | # define print_val_decs(v) | ||
285 | # define print_val_hex8(v) | ||
286 | # define print_val_hex16(v) | ||
287 | # define print_val_hex32(v) | ||
288 | # define print_val_bin8(v) | ||
289 | # define print_val_bin16(v) | ||
290 | # define print_val_bin32(v) | ||
291 | # define print_val_bin_reverse8(v) | ||
292 | # define print_val_bin_reverse16(v) | ||
293 | # define print_val_bin_reverse32(v) | ||
294 | |||
295 | #endif /* NO_PRINT */ | ||
298 | 296 | ||
299 | /* Backward compatiblitly for old name */ | 297 | /* Backward compatiblitly for old name */ |
300 | #define pdec(data) print_dec(data) | 298 | #define pdec(data) print_dec(data) |
301 | #define pdec16(data) print_dec(data) | 299 | #define pdec16(data) print_dec(data) |
302 | #define phex(data) print_hex8(data) | 300 | #define phex(data) print_hex8(data) |
303 | #define phex16(data) print_hex16(data) | 301 | #define phex16(data) print_hex16(data) |
304 | #define pbin(data) print_bin8(data) | 302 | #define pbin(data) print_bin8(data) |
305 | #define pbin16(data) print_bin16(data) | 303 | #define pbin16(data) print_bin16(data) |
306 | #define pbin_reverse(data) print_bin_reverse8(data) | 304 | #define pbin_reverse(data) print_bin_reverse8(data) |
307 | #define pbin_reverse16(data) print_bin_reverse16(data) | 305 | #define pbin_reverse16(data) print_bin_reverse16(data) |
308 | 306 | ||
309 | #endif | 307 | #endif |
diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h index de9313839..88373f478 100644 --- a/tmk_core/common/progmem.h +++ b/tmk_core/common/progmem.h | |||
@@ -2,12 +2,12 @@ | |||
2 | #define PROGMEM_H 1 | 2 | #define PROGMEM_H 1 |
3 | 3 | ||
4 | #if defined(__AVR__) | 4 | #if defined(__AVR__) |
5 | # include <avr/pgmspace.h> | 5 | # include <avr/pgmspace.h> |
6 | #else | 6 | #else |
7 | # define PROGMEM | 7 | # define PROGMEM |
8 | # define pgm_read_byte(p) *((unsigned char*)(p)) | 8 | # define pgm_read_byte(p) *((unsigned char*)(p)) |
9 | # define pgm_read_word(p) *((uint16_t*)(p)) | 9 | # define pgm_read_word(p) *((uint16_t*)(p)) |
10 | # define pgm_read_dword(p) *((uint32_t*)(p)) | 10 | # define pgm_read_dword(p) *((uint32_t*)(p)) |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | #endif | 13 | #endif |
diff --git a/tmk_core/common/raw_hid.h b/tmk_core/common/raw_hid.h index 86da02fd1..c579157f1 100644 --- a/tmk_core/common/raw_hid.h +++ b/tmk_core/common/raw_hid.h | |||
@@ -1,8 +1,8 @@ | |||
1 | #ifndef _RAW_HID_H_ | 1 | #ifndef _RAW_HID_H_ |
2 | #define _RAW_HID_H_ | 2 | #define _RAW_HID_H_ |
3 | 3 | ||
4 | void raw_hid_receive( uint8_t *data, uint8_t length ); | 4 | void raw_hid_receive(uint8_t *data, uint8_t length); |
5 | 5 | ||
6 | void raw_hid_send( uint8_t *data, uint8_t length ); | 6 | void raw_hid_send(uint8_t *data, uint8_t length); |
7 | 7 | ||
8 | #endif | 8 | #endif |
diff --git a/tmk_core/common/report.c b/tmk_core/common/report.c index 6a06b70c6..f4758b48e 100644 --- a/tmk_core/common/report.c +++ b/tmk_core/common/report.c | |||
@@ -25,20 +25,18 @@ | |||
25 | * | 25 | * |
26 | * FIXME: Needs doc | 26 | * FIXME: Needs doc |
27 | */ | 27 | */ |
28 | uint8_t has_anykey(report_keyboard_t* keyboard_report) | 28 | uint8_t has_anykey(report_keyboard_t* keyboard_report) { |
29 | { | 29 | uint8_t cnt = 0; |
30 | uint8_t cnt = 0; | 30 | uint8_t* p = keyboard_report->keys; |
31 | uint8_t *p = keyboard_report->keys; | 31 | uint8_t lp = sizeof(keyboard_report->keys); |
32 | uint8_t lp = sizeof(keyboard_report->keys); | ||
33 | #ifdef NKRO_ENABLE | 32 | #ifdef NKRO_ENABLE |
34 | if (keyboard_protocol && keymap_config.nkro) { | 33 | if (keyboard_protocol && keymap_config.nkro) { |
35 | p = keyboard_report->nkro.bits; | 34 | p = keyboard_report->nkro.bits; |
36 | lp = sizeof(keyboard_report->nkro.bits); | 35 | lp = sizeof(keyboard_report->nkro.bits); |
37 | } | 36 | } |
38 | #endif | 37 | #endif |
39 | while (lp--) { | 38 | while (lp--) { |
40 | if (*p++) | 39 | if (*p++) cnt++; |
41 | cnt++; | ||
42 | } | 40 | } |
43 | return cnt; | 41 | return cnt; |
44 | } | 42 | } |
@@ -47,14 +45,13 @@ uint8_t has_anykey(report_keyboard_t* keyboard_report) | |||
47 | * | 45 | * |
48 | * FIXME: Needs doc | 46 | * FIXME: Needs doc |
49 | */ | 47 | */ |
50 | uint8_t get_first_key(report_keyboard_t* keyboard_report) | 48 | uint8_t get_first_key(report_keyboard_t* keyboard_report) { |
51 | { | ||
52 | #ifdef NKRO_ENABLE | 49 | #ifdef NKRO_ENABLE |
53 | if (keyboard_protocol && keymap_config.nkro) { | 50 | if (keyboard_protocol && keymap_config.nkro) { |
54 | uint8_t i = 0; | 51 | uint8_t i = 0; |
55 | for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) | 52 | for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) |
56 | ; | 53 | ; |
57 | return i<<3 | biton(keyboard_report->nkro.bits[i]); | 54 | return i << 3 | biton(keyboard_report->nkro.bits[i]); |
58 | } | 55 | } |
59 | #endif | 56 | #endif |
60 | #ifdef USB_6KRO_ENABLE | 57 | #ifdef USB_6KRO_ENABLE |
@@ -75,10 +72,9 @@ uint8_t get_first_key(report_keyboard_t* keyboard_report) | |||
75 | * | 72 | * |
76 | * FIXME: Needs doc | 73 | * FIXME: Needs doc |
77 | */ | 74 | */ |
78 | void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) | 75 | void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) { |
79 | { | ||
80 | #ifdef USB_6KRO_ENABLE | 76 | #ifdef USB_6KRO_ENABLE |
81 | int8_t i = cb_head; | 77 | int8_t i = cb_head; |
82 | int8_t empty = -1; | 78 | int8_t empty = -1; |
83 | if (cb_count) { | 79 | if (cb_count) { |
84 | do { | 80 | do { |
@@ -97,18 +93,16 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) | |||
97 | // pop head when has no empty space | 93 | // pop head when has no empty space |
98 | cb_head = RO_INC(cb_head); | 94 | cb_head = RO_INC(cb_head); |
99 | cb_count--; | 95 | cb_count--; |
100 | } | 96 | } else { |
101 | else { | ||
102 | // left shift when has empty space | 97 | // left shift when has empty space |
103 | uint8_t offset = 1; | 98 | uint8_t offset = 1; |
104 | i = RO_INC(empty); | 99 | i = RO_INC(empty); |
105 | do { | 100 | do { |
106 | if (keyboard_report->keys[i] != 0) { | 101 | if (keyboard_report->keys[i] != 0) { |
107 | keyboard_report->keys[empty] = keyboard_report->keys[i]; | 102 | keyboard_report->keys[empty] = keyboard_report->keys[i]; |
108 | keyboard_report->keys[i] = 0; | 103 | keyboard_report->keys[i] = 0; |
109 | empty = RO_INC(empty); | 104 | empty = RO_INC(empty); |
110 | } | 105 | } else { |
111 | else { | ||
112 | offset++; | 106 | offset++; |
113 | } | 107 | } |
114 | i = RO_INC(i); | 108 | i = RO_INC(i); |
@@ -120,10 +114,10 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) | |||
120 | } | 114 | } |
121 | // add to tail | 115 | // add to tail |
122 | keyboard_report->keys[cb_tail] = code; | 116 | keyboard_report->keys[cb_tail] = code; |
123 | cb_tail = RO_INC(cb_tail); | 117 | cb_tail = RO_INC(cb_tail); |
124 | cb_count++; | 118 | cb_count++; |
125 | #else | 119 | #else |
126 | int8_t i = 0; | 120 | int8_t i = 0; |
127 | int8_t empty = -1; | 121 | int8_t empty = -1; |
128 | for (; i < KEYBOARD_REPORT_KEYS; i++) { | 122 | for (; i < KEYBOARD_REPORT_KEYS; i++) { |
129 | if (keyboard_report->keys[i] == code) { | 123 | if (keyboard_report->keys[i] == code) { |
@@ -145,8 +139,7 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) | |||
145 | * | 139 | * |
146 | * FIXME: Needs doc | 140 | * FIXME: Needs doc |
147 | */ | 141 | */ |
148 | void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) | 142 | void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) { |
149 | { | ||
150 | #ifdef USB_6KRO_ENABLE | 143 | #ifdef USB_6KRO_ENABLE |
151 | uint8_t i = cb_head; | 144 | uint8_t i = cb_head; |
152 | if (cb_count) { | 145 | if (cb_count) { |
@@ -186,10 +179,9 @@ void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) | |||
186 | * | 179 | * |
187 | * FIXME: Needs doc | 180 | * FIXME: Needs doc |
188 | */ | 181 | */ |
189 | void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code) | 182 | void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code) { |
190 | { | 183 | if ((code >> 3) < KEYBOARD_REPORT_BITS) { |
191 | if ((code>>3) < KEYBOARD_REPORT_BITS) { | 184 | keyboard_report->nkro.bits[code >> 3] |= 1 << (code & 7); |
192 | keyboard_report->nkro.bits[code>>3] |= 1<<(code&7); | ||
193 | } else { | 185 | } else { |
194 | dprintf("add_key_bit: can't add: %02X\n", code); | 186 | dprintf("add_key_bit: can't add: %02X\n", code); |
195 | } | 187 | } |
@@ -199,10 +191,9 @@ void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code) | |||
199 | * | 191 | * |
200 | * FIXME: Needs doc | 192 | * FIXME: Needs doc |
201 | */ | 193 | */ |
202 | void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) | 194 | void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) { |
203 | { | 195 | if ((code >> 3) < KEYBOARD_REPORT_BITS) { |
204 | if ((code>>3) < KEYBOARD_REPORT_BITS) { | 196 | keyboard_report->nkro.bits[code >> 3] &= ~(1 << (code & 7)); |
205 | keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7)); | ||
206 | } else { | 197 | } else { |
207 | dprintf("del_key_bit: can't del: %02X\n", code); | 198 | dprintf("del_key_bit: can't del: %02X\n", code); |
208 | } | 199 | } |
@@ -213,8 +204,7 @@ void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) | |||
213 | * | 204 | * |
214 | * FIXME: Needs doc | 205 | * FIXME: Needs doc |
215 | */ | 206 | */ |
216 | void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key) | 207 | void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key) { |
217 | { | ||
218 | #ifdef NKRO_ENABLE | 208 | #ifdef NKRO_ENABLE |
219 | if (keyboard_protocol && keymap_config.nkro) { | 209 | if (keyboard_protocol && keymap_config.nkro) { |
220 | add_key_bit(keyboard_report, key); | 210 | add_key_bit(keyboard_report, key); |
@@ -228,8 +218,7 @@ void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key) | |||
228 | * | 218 | * |
229 | * FIXME: Needs doc | 219 | * FIXME: Needs doc |
230 | */ | 220 | */ |
231 | void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key) | 221 | void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key) { |
232 | { | ||
233 | #ifdef NKRO_ENABLE | 222 | #ifdef NKRO_ENABLE |
234 | if (keyboard_protocol && keymap_config.nkro) { | 223 | if (keyboard_protocol && keymap_config.nkro) { |
235 | del_key_bit(keyboard_report, key); | 224 | del_key_bit(keyboard_report, key); |
@@ -243,8 +232,7 @@ void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key) | |||
243 | * | 232 | * |
244 | * FIXME: Needs doc | 233 | * FIXME: Needs doc |
245 | */ | 234 | */ |
246 | void clear_keys_from_report(report_keyboard_t* keyboard_report) | 235 | void clear_keys_from_report(report_keyboard_t* keyboard_report) { |
247 | { | ||
248 | // not clear mods | 236 | // not clear mods |
249 | #ifdef NKRO_ENABLE | 237 | #ifdef NKRO_ENABLE |
250 | if (keyboard_protocol && keymap_config.nkro) { | 238 | if (keyboard_protocol && keymap_config.nkro) { |
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index e7c31bd37..ccc6d599b 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h | |||
@@ -21,90 +21,88 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
21 | #include <stdint.h> | 21 | #include <stdint.h> |
22 | #include "keycode.h" | 22 | #include "keycode.h" |
23 | 23 | ||
24 | |||
25 | /* report id */ | 24 | /* report id */ |
26 | #define REPORT_ID_KEYBOARD 1 | 25 | #define REPORT_ID_KEYBOARD 1 |
27 | #define REPORT_ID_MOUSE 2 | 26 | #define REPORT_ID_MOUSE 2 |
28 | #define REPORT_ID_SYSTEM 3 | 27 | #define REPORT_ID_SYSTEM 3 |
29 | #define REPORT_ID_CONSUMER 4 | 28 | #define REPORT_ID_CONSUMER 4 |
30 | #define REPORT_ID_NKRO 5 | 29 | #define REPORT_ID_NKRO 5 |
31 | 30 | ||
32 | /* mouse buttons */ | 31 | /* mouse buttons */ |
33 | #define MOUSE_BTN1 (1<<0) | 32 | #define MOUSE_BTN1 (1 << 0) |
34 | #define MOUSE_BTN2 (1<<1) | 33 | #define MOUSE_BTN2 (1 << 1) |
35 | #define MOUSE_BTN3 (1<<2) | 34 | #define MOUSE_BTN3 (1 << 2) |
36 | #define MOUSE_BTN4 (1<<3) | 35 | #define MOUSE_BTN4 (1 << 3) |
37 | #define MOUSE_BTN5 (1<<4) | 36 | #define MOUSE_BTN5 (1 << 4) |
38 | 37 | ||
39 | /* Consumer Page(0x0C) | 38 | /* Consumer Page(0x0C) |
40 | * following are supported by Windows: http://msdn.microsoft.com/en-us/windows/hardware/gg463372.aspx | 39 | * following are supported by Windows: http://msdn.microsoft.com/en-us/windows/hardware/gg463372.aspx |
41 | * see also https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/display-brightness-control | 40 | * see also https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/display-brightness-control |
42 | */ | 41 | */ |
43 | #define AUDIO_MUTE 0x00E2 | 42 | #define AUDIO_MUTE 0x00E2 |
44 | #define AUDIO_VOL_UP 0x00E9 | 43 | #define AUDIO_VOL_UP 0x00E9 |
45 | #define AUDIO_VOL_DOWN 0x00EA | 44 | #define AUDIO_VOL_DOWN 0x00EA |
46 | #define TRANSPORT_NEXT_TRACK 0x00B5 | 45 | #define TRANSPORT_NEXT_TRACK 0x00B5 |
47 | #define TRANSPORT_PREV_TRACK 0x00B6 | 46 | #define TRANSPORT_PREV_TRACK 0x00B6 |
48 | #define TRANSPORT_STOP 0x00B7 | 47 | #define TRANSPORT_STOP 0x00B7 |
49 | #define TRANSPORT_STOP_EJECT 0x00CC | 48 | #define TRANSPORT_STOP_EJECT 0x00CC |
50 | #define TRANSPORT_PLAY_PAUSE 0x00CD | 49 | #define TRANSPORT_PLAY_PAUSE 0x00CD |
51 | #define BRIGHTNESS_UP 0x006F | 50 | #define BRIGHTNESS_UP 0x006F |
52 | #define BRIGHTNESS_DOWN 0x0070 | 51 | #define BRIGHTNESS_DOWN 0x0070 |
53 | /* application launch */ | 52 | /* application launch */ |
54 | #define AL_CC_CONFIG 0x0183 | 53 | #define AL_CC_CONFIG 0x0183 |
55 | #define AL_EMAIL 0x018A | 54 | #define AL_EMAIL 0x018A |
56 | #define AL_CALCULATOR 0x0192 | 55 | #define AL_CALCULATOR 0x0192 |
57 | #define AL_LOCAL_BROWSER 0x0194 | 56 | #define AL_LOCAL_BROWSER 0x0194 |
58 | /* application control */ | 57 | /* application control */ |
59 | #define AC_SEARCH 0x0221 | 58 | #define AC_SEARCH 0x0221 |
60 | #define AC_HOME 0x0223 | 59 | #define AC_HOME 0x0223 |
61 | #define AC_BACK 0x0224 | 60 | #define AC_BACK 0x0224 |
62 | #define AC_FORWARD 0x0225 | 61 | #define AC_FORWARD 0x0225 |
63 | #define AC_STOP 0x0226 | 62 | #define AC_STOP 0x0226 |
64 | #define AC_REFRESH 0x0227 | 63 | #define AC_REFRESH 0x0227 |
65 | #define AC_BOOKMARKS 0x022A | 64 | #define AC_BOOKMARKS 0x022A |
66 | /* supplement for Bluegiga iWRAP HID(not supported by Windows?) */ | 65 | /* supplement for Bluegiga iWRAP HID(not supported by Windows?) */ |
67 | #define AL_LOCK 0x019E | 66 | #define AL_LOCK 0x019E |
68 | #define TRANSPORT_RECORD 0x00B2 | 67 | #define TRANSPORT_RECORD 0x00B2 |
69 | #define TRANSPORT_FAST_FORWARD 0x00B3 | 68 | #define TRANSPORT_FAST_FORWARD 0x00B3 |
70 | #define TRANSPORT_REWIND 0x00B4 | 69 | #define TRANSPORT_REWIND 0x00B4 |
71 | #define TRANSPORT_EJECT 0x00B8 | 70 | #define TRANSPORT_EJECT 0x00B8 |
72 | #define AC_MINIMIZE 0x0206 | 71 | #define AC_MINIMIZE 0x0206 |
73 | 72 | ||
74 | /* Generic Desktop Page(0x01) - system power control */ | 73 | /* Generic Desktop Page(0x01) - system power control */ |
75 | #define SYSTEM_POWER_DOWN 0x0081 | 74 | #define SYSTEM_POWER_DOWN 0x0081 |
76 | #define SYSTEM_SLEEP 0x0082 | 75 | #define SYSTEM_SLEEP 0x0082 |
77 | #define SYSTEM_WAKE_UP 0x0083 | 76 | #define SYSTEM_WAKE_UP 0x0083 |
78 | |||
79 | 77 | ||
80 | #define NKRO_SHARED_EP | 78 | #define NKRO_SHARED_EP |
81 | /* key report size(NKRO or boot mode) */ | 79 | /* key report size(NKRO or boot mode) */ |
82 | #if defined(NKRO_ENABLE) | 80 | #if defined(NKRO_ENABLE) |
83 | #if defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS) | 81 | # if defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS) |
84 | #include "protocol/usb_descriptor.h" | 82 | # include "protocol/usb_descriptor.h" |
85 | #define KEYBOARD_REPORT_BITS (SHARED_EPSIZE - 2) | 83 | # define KEYBOARD_REPORT_BITS (SHARED_EPSIZE - 2) |
86 | #elif defined(PROTOCOL_ARM_ATSAM) | 84 | # elif defined(PROTOCOL_ARM_ATSAM) |
87 | #include "protocol/arm_atsam/usb/udi_device_epsize.h" | 85 | # include "protocol/arm_atsam/usb/udi_device_epsize.h" |
88 | #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) | 86 | # define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) |
89 | #undef NKRO_SHARED_EP | 87 | # undef NKRO_SHARED_EP |
90 | #undef MOUSE_SHARED_EP | 88 | # undef MOUSE_SHARED_EP |
91 | #else | 89 | # else |
92 | #error "NKRO not supported with this protocol" | 90 | # error "NKRO not supported with this protocol" |
93 | #endif | 91 | # endif |
94 | #endif | 92 | #endif |
95 | 93 | ||
96 | #ifdef KEYBOARD_SHARED_EP | 94 | #ifdef KEYBOARD_SHARED_EP |
97 | # define KEYBOARD_REPORT_SIZE 9 | 95 | # define KEYBOARD_REPORT_SIZE 9 |
98 | #else | 96 | #else |
99 | # define KEYBOARD_REPORT_SIZE 8 | 97 | # define KEYBOARD_REPORT_SIZE 8 |
100 | #endif | 98 | #endif |
101 | 99 | ||
102 | #define KEYBOARD_REPORT_KEYS 6 | 100 | #define KEYBOARD_REPORT_KEYS 6 |
103 | 101 | ||
104 | /* VUSB hardcodes keyboard and mouse+extrakey only */ | 102 | /* VUSB hardcodes keyboard and mouse+extrakey only */ |
105 | #if defined(PROTOCOL_VUSB) | 103 | #if defined(PROTOCOL_VUSB) |
106 | #undef KEYBOARD_SHARED_EP | 104 | # undef KEYBOARD_SHARED_EP |
107 | #undef MOUSE_SHARED_EP | 105 | # undef MOUSE_SHARED_EP |
108 | #endif | 106 | #endif |
109 | 107 | ||
110 | #ifdef __cplusplus | 108 | #ifdef __cplusplus |
@@ -143,58 +141,32 @@ typedef union { | |||
143 | }; | 141 | }; |
144 | #ifdef NKRO_ENABLE | 142 | #ifdef NKRO_ENABLE |
145 | struct nkro_report { | 143 | struct nkro_report { |
146 | #ifdef NKRO_SHARED_EP | 144 | # ifdef NKRO_SHARED_EP |
147 | uint8_t report_id; | 145 | uint8_t report_id; |
148 | #endif | 146 | # endif |
149 | uint8_t mods; | 147 | uint8_t mods; |
150 | uint8_t bits[KEYBOARD_REPORT_BITS]; | 148 | uint8_t bits[KEYBOARD_REPORT_BITS]; |
151 | } nkro; | 149 | } nkro; |
152 | #endif | 150 | #endif |
153 | } __attribute__ ((packed)) report_keyboard_t; | 151 | } __attribute__((packed)) report_keyboard_t; |
154 | 152 | ||
155 | typedef struct { | 153 | typedef struct { |
156 | #ifdef MOUSE_SHARED_EP | 154 | #ifdef MOUSE_SHARED_EP |
157 | uint8_t report_id; | 155 | uint8_t report_id; |
158 | #endif | 156 | #endif |
159 | uint8_t buttons; | 157 | uint8_t buttons; |
160 | int8_t x; | 158 | int8_t x; |
161 | int8_t y; | 159 | int8_t y; |
162 | int8_t v; | 160 | int8_t v; |
163 | int8_t h; | 161 | int8_t h; |
164 | } __attribute__ ((packed)) report_mouse_t; | 162 | } __attribute__((packed)) report_mouse_t; |
165 | |||
166 | 163 | ||
167 | /* keycode to system usage */ | 164 | /* keycode to system usage */ |
168 | #define KEYCODE2SYSTEM(key) \ | 165 | #define KEYCODE2SYSTEM(key) (key == KC_SYSTEM_POWER ? SYSTEM_POWER_DOWN : (key == KC_SYSTEM_SLEEP ? SYSTEM_SLEEP : (key == KC_SYSTEM_WAKE ? SYSTEM_WAKE_UP : 0))) |
169 | (key == KC_SYSTEM_POWER ? SYSTEM_POWER_DOWN : \ | ||
170 | (key == KC_SYSTEM_SLEEP ? SYSTEM_SLEEP : \ | ||
171 | (key == KC_SYSTEM_WAKE ? SYSTEM_WAKE_UP : 0))) | ||
172 | 166 | ||
173 | /* keycode to consumer usage */ | 167 | /* keycode to consumer usage */ |
174 | #define KEYCODE2CONSUMER(key) \ | 168 | #define KEYCODE2CONSUMER(key) \ |
175 | (key == KC_AUDIO_MUTE ? AUDIO_MUTE : \ | 169 | (key == KC_AUDIO_MUTE ? AUDIO_MUTE : (key == KC_AUDIO_VOL_UP ? AUDIO_VOL_UP : (key == KC_AUDIO_VOL_DOWN ? AUDIO_VOL_DOWN : (key == KC_MEDIA_NEXT_TRACK ? TRANSPORT_NEXT_TRACK : (key == KC_MEDIA_PREV_TRACK ? TRANSPORT_PREV_TRACK : (key == KC_MEDIA_FAST_FORWARD ? TRANSPORT_FAST_FORWARD : (key == KC_MEDIA_REWIND ? TRANSPORT_REWIND : (key == KC_MEDIA_STOP ? TRANSPORT_STOP : (key == KC_MEDIA_EJECT ? TRANSPORT_STOP_EJECT : (key == KC_MEDIA_PLAY_PAUSE ? TRANSPORT_PLAY_PAUSE : (key == KC_MEDIA_SELECT ? AL_CC_CONFIG : (key == KC_MAIL ? AL_EMAIL : (key == KC_CALCULATOR ? AL_CALCULATOR : (key == KC_MY_COMPUTER ? AL_LOCAL_BROWSER : (key == KC_WWW_SEARCH ? AC_SEARCH : (key == KC_WWW_HOME ? AC_HOME : (key == KC_WWW_BACK ? AC_BACK : (key == KC_WWW_FORWARD ? AC_FORWARD : (key == KC_WWW_STOP ? AC_STOP : (key == KC_WWW_REFRESH ? AC_REFRESH : (key == KC_BRIGHTNESS_UP ? BRIGHTNESS_UP : (key == KC_BRIGHTNESS_DOWN ? BRIGHTNESS_DOWN : (key == KC_WWW_FAVORITES ? AC_BOOKMARKS : 0))))))))))))))))))))))) |
176 | (key == KC_AUDIO_VOL_UP ? AUDIO_VOL_UP : \ | ||
177 | (key == KC_AUDIO_VOL_DOWN ? AUDIO_VOL_DOWN : \ | ||
178 | (key == KC_MEDIA_NEXT_TRACK ? TRANSPORT_NEXT_TRACK : \ | ||
179 | (key == KC_MEDIA_PREV_TRACK ? TRANSPORT_PREV_TRACK : \ | ||
180 | (key == KC_MEDIA_FAST_FORWARD ? TRANSPORT_FAST_FORWARD : \ | ||
181 | (key == KC_MEDIA_REWIND ? TRANSPORT_REWIND : \ | ||
182 | (key == KC_MEDIA_STOP ? TRANSPORT_STOP : \ | ||
183 | (key == KC_MEDIA_EJECT ? TRANSPORT_STOP_EJECT : \ | ||
184 | (key == KC_MEDIA_PLAY_PAUSE ? TRANSPORT_PLAY_PAUSE : \ | ||
185 | (key == KC_MEDIA_SELECT ? AL_CC_CONFIG : \ | ||
186 | (key == KC_MAIL ? AL_EMAIL : \ | ||
187 | (key == KC_CALCULATOR ? AL_CALCULATOR : \ | ||
188 | (key == KC_MY_COMPUTER ? AL_LOCAL_BROWSER : \ | ||
189 | (key == KC_WWW_SEARCH ? AC_SEARCH : \ | ||
190 | (key == KC_WWW_HOME ? AC_HOME : \ | ||
191 | (key == KC_WWW_BACK ? AC_BACK : \ | ||
192 | (key == KC_WWW_FORWARD ? AC_FORWARD : \ | ||
193 | (key == KC_WWW_STOP ? AC_STOP : \ | ||
194 | (key == KC_WWW_REFRESH ? AC_REFRESH : \ | ||
195 | (key == KC_BRIGHTNESS_UP ? BRIGHTNESS_UP : \ | ||
196 | (key == KC_BRIGHTNESS_DOWN ? BRIGHTNESS_DOWN : \ | ||
197 | (key == KC_WWW_FAVORITES ? AC_BOOKMARKS : 0))))))))))))))))))))))) | ||
198 | 170 | ||
199 | uint8_t has_anykey(report_keyboard_t* keyboard_report); | 171 | uint8_t has_anykey(report_keyboard_t* keyboard_report); |
200 | uint8_t get_first_key(report_keyboard_t* keyboard_report); | 172 | uint8_t get_first_key(report_keyboard_t* keyboard_report); |
diff --git a/tmk_core/common/sendchar.h b/tmk_core/common/sendchar.h index 7a64d00c7..bd7b94fd9 100644 --- a/tmk_core/common/sendchar.h +++ b/tmk_core/common/sendchar.h | |||
@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
20 | 20 | ||
21 | #include <stdint.h> | 21 | #include <stdint.h> |
22 | 22 | ||
23 | |||
24 | #ifdef __cplusplus | 23 | #ifdef __cplusplus |
25 | extern "C" { | 24 | extern "C" { |
26 | #endif | 25 | #endif |
diff --git a/tmk_core/common/sendchar_null.c b/tmk_core/common/sendchar_null.c index 293330622..f6cab1b9d 100644 --- a/tmk_core/common/sendchar_null.c +++ b/tmk_core/common/sendchar_null.c | |||
@@ -16,8 +16,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | #include "sendchar.h" | 17 | #include "sendchar.h" |
18 | 18 | ||
19 | 19 | int8_t sendchar(uint8_t c) { return 0; } | |
20 | int8_t sendchar(uint8_t c) | ||
21 | { | ||
22 | return 0; | ||
23 | } | ||
diff --git a/tmk_core/common/sendchar_uart.c b/tmk_core/common/sendchar_uart.c index 0241859eb..2fc48baff 100644 --- a/tmk_core/common/sendchar_uart.c +++ b/tmk_core/common/sendchar_uart.c | |||
@@ -17,9 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | #include "uart.h" | 17 | #include "uart.h" |
18 | #include "sendchar.h" | 18 | #include "sendchar.h" |
19 | 19 | ||
20 | 20 | int8_t sendchar(uint8_t c) { | |
21 | int8_t sendchar(uint8_t c) | ||
22 | { | ||
23 | uart_putchar(c); | 21 | uart_putchar(c); |
24 | return 0; | 22 | return 0; |
25 | } | 23 | } |
diff --git a/tmk_core/common/sleep_led.h b/tmk_core/common/sleep_led.h index 6bdcf558a..d160213f1 100644 --- a/tmk_core/common/sleep_led.h +++ b/tmk_core/common/sleep_led.h | |||
@@ -1,7 +1,6 @@ | |||
1 | #ifndef SLEEP_LED_H | 1 | #ifndef SLEEP_LED_H |
2 | #define SLEEP_LED_H | 2 | #define SLEEP_LED_H |
3 | 3 | ||
4 | |||
5 | #ifdef SLEEP_LED_ENABLE | 4 | #ifdef SLEEP_LED_ENABLE |
6 | 5 | ||
7 | void sleep_led_init(void); | 6 | void sleep_led_init(void); |
@@ -11,10 +10,10 @@ void sleep_led_toggle(void); | |||
11 | 10 | ||
12 | #else | 11 | #else |
13 | 12 | ||
14 | #define sleep_led_init() | 13 | # define sleep_led_init() |
15 | #define sleep_led_enable() | 14 | # define sleep_led_enable() |
16 | #define sleep_led_disable() | 15 | # define sleep_led_disable() |
17 | #define sleep_led_toggle() | 16 | # define sleep_led_toggle() |
18 | 17 | ||
19 | #endif | 18 | #endif |
20 | 19 | ||
diff --git a/tmk_core/common/suspend.h b/tmk_core/common/suspend.h index c3e444708..87f5025da 100644 --- a/tmk_core/common/suspend.h +++ b/tmk_core/common/suspend.h | |||
@@ -4,7 +4,6 @@ | |||
4 | #include <stdint.h> | 4 | #include <stdint.h> |
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | 6 | ||
7 | |||
8 | void suspend_idle(uint8_t timeout); | 7 | void suspend_idle(uint8_t timeout); |
9 | void suspend_power_down(void); | 8 | void suspend_power_down(void); |
10 | bool suspend_wakeup_condition(void); | 9 | bool suspend_wakeup_condition(void); |
@@ -12,7 +11,7 @@ void suspend_wakeup_init(void); | |||
12 | 11 | ||
13 | void suspend_wakeup_init_user(void); | 12 | void suspend_wakeup_init_user(void); |
14 | void suspend_wakeup_init_kb(void); | 13 | void suspend_wakeup_init_kb(void); |
15 | void suspend_power_down_user (void); | 14 | void suspend_power_down_user(void); |
16 | void suspend_power_down_kb(void); | 15 | void suspend_power_down_kb(void); |
17 | 16 | ||
18 | #endif | 17 | #endif |
diff --git a/tmk_core/common/test/eeprom.c b/tmk_core/common/test/eeprom.c index 61cc039ef..44a0bf4d7 100644 --- a/tmk_core/common/test/eeprom.c +++ b/tmk_core/common/test/eeprom.c | |||
@@ -21,78 +21,75 @@ | |||
21 | static uint8_t buffer[EEPROM_SIZE]; | 21 | static uint8_t buffer[EEPROM_SIZE]; |
22 | 22 | ||
23 | uint8_t eeprom_read_byte(const uint8_t *addr) { | 23 | uint8_t eeprom_read_byte(const uint8_t *addr) { |
24 | uintptr_t offset = (uintptr_t)addr; | 24 | uintptr_t offset = (uintptr_t)addr; |
25 | return buffer[offset]; | 25 | return buffer[offset]; |
26 | } | 26 | } |
27 | 27 | ||
28 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { | 28 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { |
29 | uintptr_t offset = (uintptr_t)addr; | 29 | uintptr_t offset = (uintptr_t)addr; |
30 | buffer[offset] = value; | 30 | buffer[offset] = value; |
31 | } | 31 | } |
32 | 32 | ||
33 | uint16_t eeprom_read_word(const uint16_t *addr) { | 33 | uint16_t eeprom_read_word(const uint16_t *addr) { |
34 | const uint8_t *p = (const uint8_t *)addr; | 34 | const uint8_t *p = (const uint8_t *)addr; |
35 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8); | 35 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8); |
36 | } | 36 | } |
37 | 37 | ||
38 | uint32_t eeprom_read_dword(const uint32_t *addr) { | 38 | uint32_t eeprom_read_dword(const uint32_t *addr) { |
39 | const uint8_t *p = (const uint8_t *)addr; | 39 | const uint8_t *p = (const uint8_t *)addr; |
40 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8) | 40 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24); |
41 | | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24); | ||
42 | } | 41 | } |
43 | 42 | ||
44 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { | 43 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { |
45 | const uint8_t *p = (const uint8_t *)addr; | 44 | const uint8_t *p = (const uint8_t *)addr; |
46 | uint8_t *dest = (uint8_t *)buf; | 45 | uint8_t * dest = (uint8_t *)buf; |
47 | while (len--) { | 46 | while (len--) { |
48 | *dest++ = eeprom_read_byte(p++); | 47 | *dest++ = eeprom_read_byte(p++); |
49 | } | 48 | } |
50 | } | 49 | } |
51 | 50 | ||
52 | void eeprom_write_word(uint16_t *addr, uint16_t value) { | 51 | void eeprom_write_word(uint16_t *addr, uint16_t value) { |
53 | uint8_t *p = (uint8_t *)addr; | 52 | uint8_t *p = (uint8_t *)addr; |
54 | eeprom_write_byte(p++, value); | 53 | eeprom_write_byte(p++, value); |
55 | eeprom_write_byte(p, value >> 8); | 54 | eeprom_write_byte(p, value >> 8); |
56 | } | 55 | } |
57 | 56 | ||
58 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { | 57 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { |
59 | uint8_t *p = (uint8_t *)addr; | 58 | uint8_t *p = (uint8_t *)addr; |
60 | eeprom_write_byte(p++, value); | 59 | eeprom_write_byte(p++, value); |
61 | eeprom_write_byte(p++, value >> 8); | 60 | eeprom_write_byte(p++, value >> 8); |
62 | eeprom_write_byte(p++, value >> 16); | 61 | eeprom_write_byte(p++, value >> 16); |
63 | eeprom_write_byte(p, value >> 24); | 62 | eeprom_write_byte(p, value >> 24); |
64 | } | 63 | } |
65 | 64 | ||
66 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { | 65 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { |
67 | uint8_t *p = (uint8_t *)addr; | 66 | uint8_t * p = (uint8_t *)addr; |
68 | const uint8_t *src = (const uint8_t *)buf; | 67 | const uint8_t *src = (const uint8_t *)buf; |
69 | while (len--) { | 68 | while (len--) { |
70 | eeprom_write_byte(p++, *src++); | 69 | eeprom_write_byte(p++, *src++); |
71 | } | 70 | } |
72 | } | 71 | } |
73 | 72 | ||
74 | void eeprom_update_byte(uint8_t *addr, uint8_t value) { | 73 | void eeprom_update_byte(uint8_t *addr, uint8_t value) { eeprom_write_byte(addr, value); } |
75 | eeprom_write_byte(addr, value); | ||
76 | } | ||
77 | 74 | ||
78 | void eeprom_update_word(uint16_t *addr, uint16_t value) { | 75 | void eeprom_update_word(uint16_t *addr, uint16_t value) { |
79 | uint8_t *p = (uint8_t *)addr; | 76 | uint8_t *p = (uint8_t *)addr; |
80 | eeprom_write_byte(p++, value); | 77 | eeprom_write_byte(p++, value); |
81 | eeprom_write_byte(p, value >> 8); | 78 | eeprom_write_byte(p, value >> 8); |
82 | } | 79 | } |
83 | 80 | ||
84 | void eeprom_update_dword(uint32_t *addr, uint32_t value) { | 81 | void eeprom_update_dword(uint32_t *addr, uint32_t value) { |
85 | uint8_t *p = (uint8_t *)addr; | 82 | uint8_t *p = (uint8_t *)addr; |
86 | eeprom_write_byte(p++, value); | 83 | eeprom_write_byte(p++, value); |
87 | eeprom_write_byte(p++, value >> 8); | 84 | eeprom_write_byte(p++, value >> 8); |
88 | eeprom_write_byte(p++, value >> 16); | 85 | eeprom_write_byte(p++, value >> 16); |
89 | eeprom_write_byte(p, value >> 24); | 86 | eeprom_write_byte(p, value >> 24); |
90 | } | 87 | } |
91 | 88 | ||
92 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { | 89 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { |
93 | uint8_t *p = (uint8_t *)addr; | 90 | uint8_t * p = (uint8_t *)addr; |
94 | const uint8_t *src = (const uint8_t *)buf; | 91 | const uint8_t *src = (const uint8_t *)buf; |
95 | while (len--) { | 92 | while (len--) { |
96 | eeprom_write_byte(p++, *src++); | 93 | eeprom_write_byte(p++, *src++); |
97 | } | 94 | } |
98 | } | 95 | } |
diff --git a/tmk_core/common/test/suspend.c b/tmk_core/common/test/suspend.c index 01d1930ea..76b705967 100644 --- a/tmk_core/common/test/suspend.c +++ b/tmk_core/common/test/suspend.c | |||
@@ -13,5 +13,3 @@ | |||
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ | 15 | */ |
16 | |||
17 | |||
diff --git a/tmk_core/common/test/timer.c b/tmk_core/common/test/timer.c index 19e79e1f5..3c786ae29 100644 --- a/tmk_core/common/test/timer.c +++ b/tmk_core/common/test/timer.c | |||
@@ -18,9 +18,9 @@ | |||
18 | 18 | ||
19 | static uint32_t current_time = 0; | 19 | static uint32_t current_time = 0; |
20 | 20 | ||
21 | void timer_init(void) {current_time = 0;} | 21 | void timer_init(void) { current_time = 0; } |
22 | 22 | ||
23 | void timer_clear(void) {current_time = 0;} | 23 | void timer_clear(void) { current_time = 0; } |
24 | 24 | ||
25 | uint16_t timer_read(void) { return current_time & 0xFFFF; } | 25 | uint16_t timer_read(void) { return current_time & 0xFFFF; } |
26 | uint32_t timer_read32(void) { return current_time; } | 26 | uint32_t timer_read32(void) { return current_time; } |
@@ -30,6 +30,4 @@ uint32_t timer_elapsed32(uint32_t last) { return TIMER_DIFF_32(timer_read32(), l | |||
30 | void set_time(uint32_t t) { current_time = t; } | 30 | void set_time(uint32_t t) { current_time = t; } |
31 | void advance_time(uint32_t ms) { current_time += ms; } | 31 | void advance_time(uint32_t ms) { current_time += ms; } |
32 | 32 | ||
33 | void wait_ms(uint32_t ms) { | 33 | void wait_ms(uint32_t ms) { advance_time(ms); } \ No newline at end of file |
34 | advance_time(ms); | ||
35 | } \ No newline at end of file | ||
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h index a8dd85663..853cb9839 100644 --- a/tmk_core/common/timer.h +++ b/tmk_core/common/timer.h | |||
@@ -22,16 +22,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
22 | #include <stdbool.h> | 22 | #include <stdbool.h> |
23 | 23 | ||
24 | #if defined(__AVR__) | 24 | #if defined(__AVR__) |
25 | #include "avr/timer_avr.h" | 25 | # include "avr/timer_avr.h" |
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | 28 | #define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) | |
29 | #define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) | 29 | #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) |
30 | #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) | 30 | #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) |
31 | #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) | 31 | #define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) |
32 | #define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) | 32 | #define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b) |
33 | #define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b) | ||
34 | |||
35 | 33 | ||
36 | #ifdef __cplusplus | 34 | #ifdef __cplusplus |
37 | extern "C" { | 35 | extern "C" { |
@@ -39,23 +37,17 @@ extern "C" { | |||
39 | 37 | ||
40 | extern volatile uint32_t timer_count; | 38 | extern volatile uint32_t timer_count; |
41 | 39 | ||
42 | 40 | void timer_init(void); | |
43 | void timer_init(void); | 41 | void timer_clear(void); |
44 | void timer_clear(void); | ||
45 | uint16_t timer_read(void); | 42 | uint16_t timer_read(void); |
46 | uint32_t timer_read32(void); | 43 | uint32_t timer_read32(void); |
47 | uint16_t timer_elapsed(uint16_t last); | 44 | uint16_t timer_elapsed(uint16_t last); |
48 | uint32_t timer_elapsed32(uint32_t last); | 45 | uint32_t timer_elapsed32(uint32_t last); |
49 | 46 | ||
50 | // Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value) | 47 | // Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value) |
51 | inline bool timer_expired(uint16_t current, uint16_t last) | 48 | inline bool timer_expired(uint16_t current, uint16_t last) { return current - last < 0x8000; } |
52 | { | ||
53 | return current - last < 0x8000; | ||
54 | } | ||
55 | 49 | ||
56 | inline bool timer_expired32(uint32_t current, uint32_t future) { | 50 | inline bool timer_expired32(uint32_t current, uint32_t future) { return current - future < 0x80000000; } |
57 | return current - future < 0x80000000; | ||
58 | } | ||
59 | 51 | ||
60 | #ifdef __cplusplus | 52 | #ifdef __cplusplus |
61 | } | 53 | } |
diff --git a/tmk_core/common/uart.c b/tmk_core/common/uart.c index c17649b08..f2e4bc4f3 100644 --- a/tmk_core/common/uart.c +++ b/tmk_core/common/uart.c | |||
@@ -3,17 +3,17 @@ | |||
3 | /* UART Example for Teensy USB Development Board | 3 | /* UART Example for Teensy USB Development Board |
4 | * http://www.pjrc.com/teensy/ | 4 | * http://www.pjrc.com/teensy/ |
5 | * Copyright (c) 2009 PJRC.COM, LLC | 5 | * Copyright (c) 2009 PJRC.COM, LLC |
6 | * | 6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | * of this software and associated documentation files (the "Software"), to deal | 8 | * of this software and associated documentation files (the "Software"), to deal |
9 | * in the Software without restriction, including without limitation the rights | 9 | * in the Software without restriction, including without limitation the rights |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11 | * copies of the Software, and to permit persons to whom the Software is | 11 | * copies of the Software, and to permit persons to whom the Software is |
12 | * furnished to do so, subject to the following conditions: | 12 | * furnished to do so, subject to the following conditions: |
13 | * | 13 | * |
14 | * The above copyright notice and this permission notice shall be included in | 14 | * The above copyright notice and this permission notice shall be included in |
15 | * all copies or substantial portions of the Software. | 15 | * all copies or substantial portions of the Software. |
16 | * | 16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
@@ -26,7 +26,6 @@ | |||
26 | // Version 1.0: Initial Release | 26 | // Version 1.0: Initial Release |
27 | // Version 1.1: Add support for Teensy 2.0, minor optimizations | 27 | // Version 1.1: Add support for Teensy 2.0, minor optimizations |
28 | 28 | ||
29 | |||
30 | #include <avr/io.h> | 29 | #include <avr/io.h> |
31 | #include <avr/interrupt.h> | 30 | #include <avr/interrupt.h> |
32 | 31 | ||
@@ -44,86 +43,81 @@ static volatile uint8_t rx_buffer_head; | |||
44 | static volatile uint8_t rx_buffer_tail; | 43 | static volatile uint8_t rx_buffer_tail; |
45 | 44 | ||
46 | // Initialize the UART | 45 | // Initialize the UART |
47 | void uart_init(uint32_t baud) | 46 | void uart_init(uint32_t baud) { |
48 | { | 47 | cli(); |
49 | cli(); | 48 | UBRR0 = (F_CPU / 4 / baud - 1) / 2; |
50 | UBRR0 = (F_CPU / 4 / baud - 1) / 2; | 49 | UCSR0A = (1 << U2X0); |
51 | UCSR0A = (1<<U2X0); | 50 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); |
52 | UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0); | 51 | UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); |
53 | UCSR0C = (1<<UCSZ01) | (1<<UCSZ00); | 52 | tx_buffer_head = tx_buffer_tail = 0; |
54 | tx_buffer_head = tx_buffer_tail = 0; | 53 | rx_buffer_head = rx_buffer_tail = 0; |
55 | rx_buffer_head = rx_buffer_tail = 0; | 54 | sei(); |
56 | sei(); | ||
57 | } | 55 | } |
58 | 56 | ||
59 | // Transmit a byte | 57 | // Transmit a byte |
60 | void uart_putchar(uint8_t c) | 58 | void uart_putchar(uint8_t c) { |
61 | { | 59 | uint8_t i; |
62 | uint8_t i; | 60 | |
63 | 61 | i = tx_buffer_head + 1; | |
64 | i = tx_buffer_head + 1; | 62 | if (i >= TX_BUFFER_SIZE) i = 0; |
65 | if (i >= TX_BUFFER_SIZE) i = 0; | 63 | while (tx_buffer_tail == i) |
66 | while (tx_buffer_tail == i) ; // wait until space in buffer | 64 | ; // wait until space in buffer |
67 | //cli(); | 65 | // cli(); |
68 | tx_buffer[i] = c; | 66 | tx_buffer[i] = c; |
69 | tx_buffer_head = i; | 67 | tx_buffer_head = i; |
70 | UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0) | (1<<UDRIE0); | 68 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0) | (1 << UDRIE0); |
71 | //sei(); | 69 | // sei(); |
72 | } | 70 | } |
73 | 71 | ||
74 | // Receive a byte | 72 | // Receive a byte |
75 | uint8_t uart_getchar(void) | 73 | uint8_t uart_getchar(void) { |
76 | { | 74 | uint8_t c, i; |
77 | uint8_t c, i; | 75 | |
78 | 76 | while (rx_buffer_head == rx_buffer_tail) | |
79 | while (rx_buffer_head == rx_buffer_tail) ; // wait for character | 77 | ; // wait for character |
80 | i = rx_buffer_tail + 1; | 78 | i = rx_buffer_tail + 1; |
81 | if (i >= RX_BUFFER_SIZE) i = 0; | 79 | if (i >= RX_BUFFER_SIZE) i = 0; |
82 | c = rx_buffer[i]; | 80 | c = rx_buffer[i]; |
83 | rx_buffer_tail = i; | 81 | rx_buffer_tail = i; |
84 | return c; | 82 | return c; |
85 | } | 83 | } |
86 | 84 | ||
87 | // Return the number of bytes waiting in the receive buffer. | 85 | // Return the number of bytes waiting in the receive buffer. |
88 | // Call this before uart_getchar() to check if it will need | 86 | // Call this before uart_getchar() to check if it will need |
89 | // to wait for a byte to arrive. | 87 | // to wait for a byte to arrive. |
90 | uint8_t uart_available(void) | 88 | uint8_t uart_available(void) { |
91 | { | 89 | uint8_t head, tail; |
92 | uint8_t head, tail; | 90 | |
93 | 91 | head = rx_buffer_head; | |
94 | head = rx_buffer_head; | 92 | tail = rx_buffer_tail; |
95 | tail = rx_buffer_tail; | 93 | if (head >= tail) return head - tail; |
96 | if (head >= tail) return head - tail; | 94 | return RX_BUFFER_SIZE + head - tail; |
97 | return RX_BUFFER_SIZE + head - tail; | ||
98 | } | 95 | } |
99 | 96 | ||
100 | // Transmit Interrupt | 97 | // Transmit Interrupt |
101 | ISR(USART_UDRE_vect) | 98 | ISR(USART_UDRE_vect) { |
102 | { | 99 | uint8_t i; |
103 | uint8_t i; | 100 | |
104 | 101 | if (tx_buffer_head == tx_buffer_tail) { | |
105 | if (tx_buffer_head == tx_buffer_tail) { | 102 | // buffer is empty, disable transmit interrupt |
106 | // buffer is empty, disable transmit interrupt | 103 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); |
107 | UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0); | 104 | } else { |
108 | } else { | 105 | i = tx_buffer_tail + 1; |
109 | i = tx_buffer_tail + 1; | 106 | if (i >= TX_BUFFER_SIZE) i = 0; |
110 | if (i >= TX_BUFFER_SIZE) i = 0; | 107 | UDR0 = tx_buffer[i]; |
111 | UDR0 = tx_buffer[i]; | 108 | tx_buffer_tail = i; |
112 | tx_buffer_tail = i; | 109 | } |
113 | } | ||
114 | } | 110 | } |
115 | 111 | ||
116 | // Receive Interrupt | 112 | // Receive Interrupt |
117 | ISR(USART_RX_vect) | 113 | ISR(USART_RX_vect) { |
118 | { | 114 | uint8_t c, i; |
119 | uint8_t c, i; | 115 | |
120 | 116 | c = UDR0; | |
121 | c = UDR0; | 117 | i = rx_buffer_head + 1; |
122 | i = rx_buffer_head + 1; | 118 | if (i >= RX_BUFFER_SIZE) i = 0; |
123 | if (i >= RX_BUFFER_SIZE) i = 0; | 119 | if (i != rx_buffer_tail) { |
124 | if (i != rx_buffer_tail) { | 120 | rx_buffer[i] = c; |
125 | rx_buffer[i] = c; | 121 | rx_buffer_head = i; |
126 | rx_buffer_head = i; | 122 | } |
127 | } | ||
128 | } | 123 | } |
129 | |||
diff --git a/tmk_core/common/uart.h b/tmk_core/common/uart.h index 41136a396..59a1a7cd1 100644 --- a/tmk_core/common/uart.h +++ b/tmk_core/common/uart.h | |||
@@ -3,8 +3,8 @@ | |||
3 | 3 | ||
4 | #include <stdint.h> | 4 | #include <stdint.h> |
5 | 5 | ||
6 | void uart_init(uint32_t baud); | 6 | void uart_init(uint32_t baud); |
7 | void uart_putchar(uint8_t c); | 7 | void uart_putchar(uint8_t c); |
8 | uint8_t uart_getchar(void); | 8 | uint8_t uart_getchar(void); |
9 | uint8_t uart_available(void); | 9 | uint8_t uart_available(void); |
10 | 10 | ||
diff --git a/tmk_core/common/util.c b/tmk_core/common/util.c index 7e0d54299..f4f018de8 100644 --- a/tmk_core/common/util.c +++ b/tmk_core/common/util.c | |||
@@ -18,84 +18,106 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
18 | #include "util.h" | 18 | #include "util.h" |
19 | 19 | ||
20 | // bit population - return number of on-bit | 20 | // bit population - return number of on-bit |
21 | uint8_t bitpop(uint8_t bits) | 21 | uint8_t bitpop(uint8_t bits) { |
22 | { | ||
23 | uint8_t c; | 22 | uint8_t c; |
24 | for (c = 0; bits; c++) | 23 | for (c = 0; bits; c++) bits &= bits - 1; |
25 | bits &= bits - 1; | ||
26 | return c; | 24 | return c; |
27 | /* | 25 | /* |
28 | const uint8_t bit_count[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; | 26 | const uint8_t bit_count[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; |
29 | return bit_count[bits>>4] + bit_count[bits&0x0F] | 27 | return bit_count[bits>>4] + bit_count[bits&0x0F] |
30 | */ | 28 | */ |
31 | } | 29 | } |
32 | 30 | ||
33 | uint8_t bitpop16(uint16_t bits) | 31 | uint8_t bitpop16(uint16_t bits) { |
34 | { | ||
35 | uint8_t c; | 32 | uint8_t c; |
36 | for (c = 0; bits; c++) | 33 | for (c = 0; bits; c++) bits &= bits - 1; |
37 | bits &= bits - 1; | ||
38 | return c; | 34 | return c; |
39 | } | 35 | } |
40 | 36 | ||
41 | uint8_t bitpop32(uint32_t bits) | 37 | uint8_t bitpop32(uint32_t bits) { |
42 | { | ||
43 | uint8_t c; | 38 | uint8_t c; |
44 | for (c = 0; bits; c++) | 39 | for (c = 0; bits; c++) bits &= bits - 1; |
45 | bits &= bits - 1; | ||
46 | return c; | 40 | return c; |
47 | } | 41 | } |
48 | 42 | ||
49 | // most significant on-bit - return highest location of on-bit | 43 | // most significant on-bit - return highest location of on-bit |
50 | // NOTE: return 0 when bit0 is on or all bits are off | 44 | // NOTE: return 0 when bit0 is on or all bits are off |
51 | uint8_t biton(uint8_t bits) | 45 | uint8_t biton(uint8_t bits) { |
52 | { | ||
53 | uint8_t n = 0; | 46 | uint8_t n = 0; |
54 | if (bits >> 4) { bits >>= 4; n += 4;} | 47 | if (bits >> 4) { |
55 | if (bits >> 2) { bits >>= 2; n += 2;} | 48 | bits >>= 4; |
56 | if (bits >> 1) { bits >>= 1; n += 1;} | 49 | n += 4; |
50 | } | ||
51 | if (bits >> 2) { | ||
52 | bits >>= 2; | ||
53 | n += 2; | ||
54 | } | ||
55 | if (bits >> 1) { | ||
56 | bits >>= 1; | ||
57 | n += 1; | ||
58 | } | ||
57 | return n; | 59 | return n; |
58 | } | 60 | } |
59 | 61 | ||
60 | uint8_t biton16(uint16_t bits) | 62 | uint8_t biton16(uint16_t bits) { |
61 | { | ||
62 | uint8_t n = 0; | 63 | uint8_t n = 0; |
63 | if (bits >> 8) { bits >>= 8; n += 8;} | 64 | if (bits >> 8) { |
64 | if (bits >> 4) { bits >>= 4; n += 4;} | 65 | bits >>= 8; |
65 | if (bits >> 2) { bits >>= 2; n += 2;} | 66 | n += 8; |
66 | if (bits >> 1) { bits >>= 1; n += 1;} | 67 | } |
68 | if (bits >> 4) { | ||
69 | bits >>= 4; | ||
70 | n += 4; | ||
71 | } | ||
72 | if (bits >> 2) { | ||
73 | bits >>= 2; | ||
74 | n += 2; | ||
75 | } | ||
76 | if (bits >> 1) { | ||
77 | bits >>= 1; | ||
78 | n += 1; | ||
79 | } | ||
67 | return n; | 80 | return n; |
68 | } | 81 | } |
69 | 82 | ||
70 | uint8_t biton32(uint32_t bits) | 83 | uint8_t biton32(uint32_t bits) { |
71 | { | ||
72 | uint8_t n = 0; | 84 | uint8_t n = 0; |
73 | if (bits >>16) { bits >>=16; n +=16;} | 85 | if (bits >> 16) { |
74 | if (bits >> 8) { bits >>= 8; n += 8;} | 86 | bits >>= 16; |
75 | if (bits >> 4) { bits >>= 4; n += 4;} | 87 | n += 16; |
76 | if (bits >> 2) { bits >>= 2; n += 2;} | 88 | } |
77 | if (bits >> 1) { bits >>= 1; n += 1;} | 89 | if (bits >> 8) { |
90 | bits >>= 8; | ||
91 | n += 8; | ||
92 | } | ||
93 | if (bits >> 4) { | ||
94 | bits >>= 4; | ||
95 | n += 4; | ||
96 | } | ||
97 | if (bits >> 2) { | ||
98 | bits >>= 2; | ||
99 | n += 2; | ||
100 | } | ||
101 | if (bits >> 1) { | ||
102 | bits >>= 1; | ||
103 | n += 1; | ||
104 | } | ||
78 | return n; | 105 | return n; |
79 | } | 106 | } |
80 | 107 | ||
81 | 108 | uint8_t bitrev(uint8_t bits) { | |
82 | 109 | bits = (bits & 0x0f) << 4 | (bits & 0xf0) >> 4; | |
83 | uint8_t bitrev(uint8_t bits) | 110 | bits = (bits & 0b00110011) << 2 | (bits & 0b11001100) >> 2; |
84 | { | 111 | bits = (bits & 0b01010101) << 1 | (bits & 0b10101010) >> 1; |
85 | bits = (bits & 0x0f)<<4 | (bits & 0xf0)>>4; | ||
86 | bits = (bits & 0b00110011)<<2 | (bits & 0b11001100)>>2; | ||
87 | bits = (bits & 0b01010101)<<1 | (bits & 0b10101010)>>1; | ||
88 | return bits; | 112 | return bits; |
89 | } | 113 | } |
90 | 114 | ||
91 | uint16_t bitrev16(uint16_t bits) | 115 | uint16_t bitrev16(uint16_t bits) { |
92 | { | 116 | bits = bitrev(bits & 0x00ff) << 8 | bitrev((bits & 0xff00) >> 8); |
93 | bits = bitrev(bits & 0x00ff)<<8 | bitrev((bits & 0xff00)>>8); | ||
94 | return bits; | 117 | return bits; |
95 | } | 118 | } |
96 | 119 | ||
97 | uint32_t bitrev32(uint32_t bits) | 120 | uint32_t bitrev32(uint32_t bits) { |
98 | { | 121 | bits = (uint32_t)bitrev16(bits & 0x0000ffff) << 16 | bitrev16((bits & 0xffff0000) >> 16); |
99 | bits = (uint32_t)bitrev16(bits & 0x0000ffff)<<16 | bitrev16((bits & 0xffff0000)>>16); | ||
100 | return bits; | 122 | return bits; |
101 | } | 123 | } |
diff --git a/tmk_core/common/util.h b/tmk_core/common/util.h index 7451cc084..5706b047d 100644 --- a/tmk_core/common/util.h +++ b/tmk_core/common/util.h | |||
@@ -22,12 +22,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
22 | 22 | ||
23 | // convert to L string | 23 | // convert to L string |
24 | #define LSTR(s) XLSTR(s) | 24 | #define LSTR(s) XLSTR(s) |
25 | #define XLSTR(s) L ## #s | 25 | #define XLSTR(s) L## #s |
26 | // convert to string | 26 | // convert to string |
27 | #define STR(s) XSTR(s) | 27 | #define STR(s) XSTR(s) |
28 | #define XSTR(s) #s | 28 | #define XSTR(s) #s |
29 | 29 | ||
30 | |||
31 | uint8_t bitpop(uint8_t bits); | 30 | uint8_t bitpop(uint8_t bits); |
32 | uint8_t bitpop16(uint16_t bits); | 31 | uint8_t bitpop16(uint16_t bits); |
33 | uint8_t bitpop32(uint32_t bits); | 32 | uint8_t bitpop32(uint32_t bits); |
diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index 9aed372b7..cb1f386a6 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h | |||
@@ -8,22 +8,36 @@ extern "C" { | |||
8 | #endif | 8 | #endif |
9 | 9 | ||
10 | #if defined(__AVR__) | 10 | #if defined(__AVR__) |
11 | # include <util/delay.h> | 11 | # include <util/delay.h> |
12 | # define wait_ms(ms) _delay_ms(ms) | 12 | # define wait_ms(ms) _delay_ms(ms) |
13 | # define wait_us(us) _delay_us(us) | 13 | # define wait_us(us) _delay_us(us) |
14 | #elif defined PROTOCOL_CHIBIOS | 14 | #elif defined PROTOCOL_CHIBIOS |
15 | # include "ch.h" | 15 | # include "ch.h" |
16 | # define wait_ms(ms) do { if (ms != 0) { chThdSleepMilliseconds(ms); } else { chThdSleepMicroseconds(1); } } while (0) | 16 | # define wait_ms(ms) \ |
17 | # define wait_us(us) do { if (us != 0) { chThdSleepMicroseconds(us); } else { chThdSleepMicroseconds(1); } } while (0) | 17 | do { \ |
18 | if (ms != 0) { \ | ||
19 | chThdSleepMilliseconds(ms); \ | ||
20 | } else { \ | ||
21 | chThdSleepMicroseconds(1); \ | ||
22 | } \ | ||
23 | } while (0) | ||
24 | # define wait_us(us) \ | ||
25 | do { \ | ||
26 | if (us != 0) { \ | ||
27 | chThdSleepMicroseconds(us); \ | ||
28 | } else { \ | ||
29 | chThdSleepMicroseconds(1); \ | ||
30 | } \ | ||
31 | } while (0) | ||
18 | #elif defined PROTOCOL_ARM_ATSAM | 32 | #elif defined PROTOCOL_ARM_ATSAM |
19 | # include "clks.h" | 33 | # include "clks.h" |
20 | # define wait_ms(ms) CLK_delay_ms(ms) | 34 | # define wait_ms(ms) CLK_delay_ms(ms) |
21 | # define wait_us(us) CLK_delay_us(us) | 35 | # define wait_us(us) CLK_delay_us(us) |
22 | #elif defined(__arm__) | 36 | #elif defined(__arm__) |
23 | # include "wait_api.h" | 37 | # include "wait_api.h" |
24 | #else // Unit tests | 38 | #else // Unit tests |
25 | void wait_ms(uint32_t ms); | 39 | void wait_ms(uint32_t ms); |
26 | #define wait_us(us) wait_ms(us / 1000) | 40 | # define wait_us(us) wait_ms(us / 1000) |
27 | #endif | 41 | #endif |
28 | 42 | ||
29 | #ifdef __cplusplus | 43 | #ifdef __cplusplus |