diff options
| author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
| commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
| tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /quantum/quantum.c | |
| parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
| download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip | |
clang-format changes
Diffstat (limited to 'quantum/quantum.c')
| -rw-r--r-- | quantum/quantum.c | 2495 |
1 files changed, 1181 insertions, 1314 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index cbd1f9df0..61e9003b7 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -17,97 +17,89 @@ | |||
| 17 | #include "quantum.h" | 17 | #include "quantum.h" |
| 18 | 18 | ||
| 19 | #if !defined(RGBLIGHT_ENABLE) && !defined(RGB_MATRIX_ENABLE) | 19 | #if !defined(RGBLIGHT_ENABLE) && !defined(RGB_MATRIX_ENABLE) |
| 20 | #include "rgb.h" | 20 | # include "rgb.h" |
| 21 | #endif | 21 | #endif |
| 22 | 22 | ||
| 23 | #ifdef PROTOCOL_LUFA | 23 | #ifdef PROTOCOL_LUFA |
| 24 | #include "outputselect.h" | 24 | # include "outputselect.h" |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | #ifndef BREATHING_PERIOD | 27 | #ifndef BREATHING_PERIOD |
| 28 | #define BREATHING_PERIOD 6 | 28 | # define BREATHING_PERIOD 6 |
| 29 | #endif | 29 | #endif |
| 30 | 30 | ||
| 31 | #include "backlight.h" | 31 | #include "backlight.h" |
| 32 | extern backlight_config_t backlight_config; | 32 | extern backlight_config_t backlight_config; |
| 33 | 33 | ||
| 34 | #ifdef FAUXCLICKY_ENABLE | 34 | #ifdef FAUXCLICKY_ENABLE |
| 35 | #include "fauxclicky.h" | 35 | # include "fauxclicky.h" |
| 36 | #endif | 36 | #endif |
| 37 | 37 | ||
| 38 | #ifdef API_ENABLE | 38 | #ifdef API_ENABLE |
| 39 | #include "api.h" | 39 | # include "api.h" |
| 40 | #endif | 40 | #endif |
| 41 | 41 | ||
| 42 | #ifdef MIDI_ENABLE | 42 | #ifdef MIDI_ENABLE |
| 43 | #include "process_midi.h" | 43 | # include "process_midi.h" |
| 44 | #endif | 44 | #endif |
| 45 | 45 | ||
| 46 | #ifdef VELOCIKEY_ENABLE | 46 | #ifdef VELOCIKEY_ENABLE |
| 47 | #include "velocikey.h" | 47 | # include "velocikey.h" |
| 48 | #endif | 48 | #endif |
| 49 | 49 | ||
| 50 | #ifdef HAPTIC_ENABLE | 50 | #ifdef HAPTIC_ENABLE |
| 51 | #include "haptic.h" | 51 | # include "haptic.h" |
| 52 | #endif | 52 | #endif |
| 53 | 53 | ||
| 54 | #ifdef ENCODER_ENABLE | 54 | #ifdef ENCODER_ENABLE |
| 55 | #include "encoder.h" | 55 | # include "encoder.h" |
| 56 | #endif | 56 | #endif |
| 57 | 57 | ||
| 58 | #ifdef AUDIO_ENABLE | 58 | #ifdef AUDIO_ENABLE |
| 59 | #ifndef GOODBYE_SONG | 59 | # ifndef GOODBYE_SONG |
| 60 | #define GOODBYE_SONG SONG(GOODBYE_SOUND) | 60 | # define GOODBYE_SONG SONG(GOODBYE_SOUND) |
| 61 | #endif | 61 | # endif |
| 62 | #ifndef AG_NORM_SONG | 62 | # ifndef AG_NORM_SONG |
| 63 | #define AG_NORM_SONG SONG(AG_NORM_SOUND) | 63 | # define AG_NORM_SONG SONG(AG_NORM_SOUND) |
| 64 | #endif | 64 | # endif |
| 65 | #ifndef AG_SWAP_SONG | 65 | # ifndef AG_SWAP_SONG |
| 66 | #define AG_SWAP_SONG SONG(AG_SWAP_SOUND) | 66 | # define AG_SWAP_SONG SONG(AG_SWAP_SOUND) |
| 67 | #endif | 67 | # endif |
| 68 | #ifndef CG_NORM_SONG | 68 | # ifndef CG_NORM_SONG |
| 69 | #define CG_NORM_SONG SONG(AG_NORM_SOUND) | 69 | # define CG_NORM_SONG SONG(AG_NORM_SOUND) |
| 70 | #endif | 70 | # endif |
| 71 | #ifndef CG_SWAP_SONG | 71 | # ifndef CG_SWAP_SONG |
| 72 | #define CG_SWAP_SONG SONG(AG_SWAP_SOUND) | 72 | # define CG_SWAP_SONG SONG(AG_SWAP_SOUND) |
| 73 | #endif | 73 | # endif |
| 74 | float goodbye_song[][2] = GOODBYE_SONG; | 74 | float goodbye_song[][2] = GOODBYE_SONG; |
| 75 | float ag_norm_song[][2] = AG_NORM_SONG; | 75 | float ag_norm_song[][2] = AG_NORM_SONG; |
| 76 | float ag_swap_song[][2] = AG_SWAP_SONG; | 76 | float ag_swap_song[][2] = AG_SWAP_SONG; |
| 77 | float cg_norm_song[][2] = CG_NORM_SONG; | 77 | float cg_norm_song[][2] = CG_NORM_SONG; |
| 78 | float cg_swap_song[][2] = CG_SWAP_SONG; | 78 | float cg_swap_song[][2] = CG_SWAP_SONG; |
| 79 | #ifdef DEFAULT_LAYER_SONGS | 79 | # ifdef DEFAULT_LAYER_SONGS |
| 80 | float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS; | 80 | float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS; |
| 81 | #endif | 81 | # endif |
| 82 | #endif | 82 | #endif |
| 83 | 83 | ||
| 84 | static void do_code16 (uint16_t code, void (*f) (uint8_t)) { | 84 | static void do_code16(uint16_t code, void (*f)(uint8_t)) { |
| 85 | switch (code) { | 85 | switch (code) { |
| 86 | case QK_MODS ... QK_MODS_MAX: | 86 | case QK_MODS ... QK_MODS_MAX: |
| 87 | break; | 87 | break; |
| 88 | default: | 88 | default: |
| 89 | return; | 89 | return; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | if (code & QK_LCTL) | 92 | if (code & QK_LCTL) f(KC_LCTL); |
| 93 | f(KC_LCTL); | 93 | if (code & QK_LSFT) f(KC_LSFT); |
| 94 | if (code & QK_LSFT) | 94 | if (code & QK_LALT) f(KC_LALT); |
| 95 | f(KC_LSFT); | 95 | if (code & QK_LGUI) f(KC_LGUI); |
| 96 | if (code & QK_LALT) | 96 | |
| 97 | f(KC_LALT); | 97 | if (code < QK_RMODS_MIN) return; |
| 98 | if (code & QK_LGUI) | 98 | |
| 99 | f(KC_LGUI); | 99 | if (code & QK_RCTL) f(KC_RCTL); |
| 100 | 100 | if (code & QK_RSFT) f(KC_RSFT); | |
| 101 | if (code < QK_RMODS_MIN) return; | 101 | if (code & QK_RALT) f(KC_RALT); |
| 102 | 102 | if (code & QK_RGUI) f(KC_RGUI); | |
| 103 | if (code & QK_RCTL) | ||
| 104 | f(KC_RCTL); | ||
| 105 | if (code & QK_RSFT) | ||
| 106 | f(KC_RSFT); | ||
| 107 | if (code & QK_RALT) | ||
| 108 | f(KC_RALT); | ||
| 109 | if (code & QK_RGUI) | ||
| 110 | f(KC_RGUI); | ||
| 111 | } | 103 | } |
| 112 | 104 | ||
| 113 | static inline void qk_register_weak_mods(uint8_t kc) { | 105 | static inline void qk_register_weak_mods(uint8_t kc) { |
| @@ -130,74 +122,64 @@ static inline void qk_unregister_mods(uint8_t kc) { | |||
| 130 | send_keyboard_report(); | 122 | send_keyboard_report(); |
| 131 | } | 123 | } |
| 132 | 124 | ||
| 133 | void register_code16 (uint16_t code) { | 125 | void register_code16(uint16_t code) { |
| 134 | if (IS_MOD(code) || code == KC_NO) { | 126 | if (IS_MOD(code) || code == KC_NO) { |
| 135 | do_code16 (code, qk_register_mods); | 127 | do_code16(code, qk_register_mods); |
| 136 | } else { | 128 | } else { |
| 137 | do_code16 (code, qk_register_weak_mods); | 129 | do_code16(code, qk_register_weak_mods); |
| 138 | } | 130 | } |
| 139 | register_code (code); | 131 | register_code(code); |
| 140 | } | 132 | } |
| 141 | 133 | ||
| 142 | void unregister_code16 (uint16_t code) { | 134 | void unregister_code16(uint16_t code) { |
| 143 | unregister_code (code); | 135 | unregister_code(code); |
| 144 | if (IS_MOD(code) || code == KC_NO) { | 136 | if (IS_MOD(code) || code == KC_NO) { |
| 145 | do_code16 (code, qk_unregister_mods); | 137 | do_code16(code, qk_unregister_mods); |
| 146 | } else { | 138 | } else { |
| 147 | do_code16 (code, qk_unregister_weak_mods); | 139 | do_code16(code, qk_unregister_weak_mods); |
| 148 | } | 140 | } |
| 149 | } | 141 | } |
| 150 | 142 | ||
| 151 | void tap_code16(uint16_t code) { | 143 | void tap_code16(uint16_t code) { |
| 152 | register_code16(code); | 144 | register_code16(code); |
| 153 | #if TAP_CODE_DELAY > 0 | 145 | #if TAP_CODE_DELAY > 0 |
| 154 | wait_ms(TAP_CODE_DELAY); | 146 | wait_ms(TAP_CODE_DELAY); |
| 155 | #endif | 147 | #endif |
| 156 | unregister_code16(code); | 148 | unregister_code16(code); |
| 157 | } | 149 | } |
| 158 | 150 | ||
| 159 | __attribute__ ((weak)) | 151 | __attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } |
| 160 | bool process_action_kb(keyrecord_t *record) { | ||
| 161 | return true; | ||
| 162 | } | ||
| 163 | 152 | ||
| 164 | __attribute__ ((weak)) | 153 | __attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); } |
| 165 | bool process_record_kb(uint16_t keycode, keyrecord_t *record) { | ||
| 166 | return process_record_user(keycode, record); | ||
| 167 | } | ||
| 168 | 154 | ||
| 169 | __attribute__ ((weak)) | 155 | __attribute__((weak)) bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; } |
| 170 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
| 171 | return true; | ||
| 172 | } | ||
| 173 | 156 | ||
| 174 | void reset_keyboard(void) { | 157 | void reset_keyboard(void) { |
| 175 | clear_keyboard(); | 158 | clear_keyboard(); |
| 176 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) | 159 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) |
| 177 | process_midi_all_notes_off(); | 160 | process_midi_all_notes_off(); |
| 178 | #endif | 161 | #endif |
| 179 | #ifdef AUDIO_ENABLE | 162 | #ifdef AUDIO_ENABLE |
| 180 | #ifndef NO_MUSIC_MODE | 163 | # ifndef NO_MUSIC_MODE |
| 181 | music_all_notes_off(); | 164 | music_all_notes_off(); |
| 182 | #endif | 165 | # endif |
| 183 | uint16_t timer_start = timer_read(); | 166 | uint16_t timer_start = timer_read(); |
| 184 | PLAY_SONG(goodbye_song); | 167 | PLAY_SONG(goodbye_song); |
| 185 | shutdown_user(); | 168 | shutdown_user(); |
| 186 | while(timer_elapsed(timer_start) < 250) | 169 | while (timer_elapsed(timer_start) < 250) wait_ms(1); |
| 187 | wait_ms(1); | 170 | stop_all_notes(); |
| 188 | stop_all_notes(); | ||
| 189 | #else | 171 | #else |
| 190 | shutdown_user(); | 172 | shutdown_user(); |
| 191 | wait_ms(250); | 173 | wait_ms(250); |
| 192 | #endif | 174 | #endif |
| 193 | #ifdef HAPTIC_ENABLE | 175 | #ifdef HAPTIC_ENABLE |
| 194 | haptic_shutdown(); | 176 | haptic_shutdown(); |
| 195 | #endif | 177 | #endif |
| 196 | // this is also done later in bootloader.c - not sure if it's neccesary here | 178 | // this is also done later in bootloader.c - not sure if it's neccesary here |
| 197 | #ifdef BOOTLOADER_CATERINA | 179 | #ifdef BOOTLOADER_CATERINA |
| 198 | *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific | 180 | *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific |
| 199 | #endif | 181 | #endif |
| 200 | bootloader_jump(); | 182 | bootloader_jump(); |
| 201 | } | 183 | } |
| 202 | 184 | ||
| 203 | /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise. | 185 | /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise. |
| @@ -206,31 +188,27 @@ void reset_keyboard(void) { | |||
| 206 | static bool grave_esc_was_shifted = false; | 188 | static bool grave_esc_was_shifted = false; |
| 207 | 189 | ||
| 208 | /* Convert record into usable keycode via the contained event. */ | 190 | /* Convert record into usable keycode via the contained event. */ |
| 209 | uint16_t get_record_keycode(keyrecord_t *record) { | 191 | uint16_t get_record_keycode(keyrecord_t *record) { return get_event_keycode(record->event); } |
| 210 | return get_event_keycode(record->event); | ||
| 211 | } | ||
| 212 | |||
| 213 | 192 | ||
| 214 | /* Convert event into usable keycode. Checks the layer cache to ensure that it | 193 | /* Convert event into usable keycode. Checks the layer cache to ensure that it |
| 215 | * retains the correct keycode after a layer change, if the key is still pressed. | 194 | * retains the correct keycode after a layer change, if the key is still pressed. |
| 216 | */ | 195 | */ |
| 217 | uint16_t get_event_keycode(keyevent_t event) { | 196 | uint16_t get_event_keycode(keyevent_t event) { |
| 218 | 197 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) | |
| 219 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) | ||
| 220 | /* TODO: Use store_or_get_action() or a similar function. */ | 198 | /* TODO: Use store_or_get_action() or a similar function. */ |
| 221 | if (!disable_action_cache) { | 199 | if (!disable_action_cache) { |
| 222 | uint8_t layer; | 200 | uint8_t layer; |
| 223 | 201 | ||
| 224 | if (event.pressed) { | 202 | if (event.pressed) { |
| 225 | layer = layer_switch_get_layer(event.key); | 203 | layer = layer_switch_get_layer(event.key); |
| 226 | update_source_layers_cache(event.key, layer); | 204 | update_source_layers_cache(event.key, layer); |
| 227 | } else { | 205 | } else { |
| 228 | layer = read_source_layers_cache(event.key); | 206 | layer = read_source_layers_cache(event.key); |
| 229 | } | 207 | } |
| 230 | return keymap_key_to_keycode(layer, event.key); | 208 | return keymap_key_to_keycode(layer, event.key); |
| 231 | } else | 209 | } else |
| 232 | #endif | 210 | #endif |
| 233 | return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key); | 211 | return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key); |
| 234 | } | 212 | } |
| 235 | 213 | ||
| 236 | /* Main keycode processing function. Hands off handling to other functions, | 214 | /* Main keycode processing function. Hands off handling to other functions, |
| @@ -247,629 +225,582 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 247 | // return false; | 225 | // return false; |
| 248 | // } | 226 | // } |
| 249 | 227 | ||
| 250 | #ifdef VELOCIKEY_ENABLE | 228 | #ifdef VELOCIKEY_ENABLE |
| 251 | if (velocikey_enabled() && record->event.pressed) { velocikey_accelerate(); } | 229 | if (velocikey_enabled() && record->event.pressed) { |
| 252 | #endif | 230 | velocikey_accelerate(); |
| 231 | } | ||
| 232 | #endif | ||
| 253 | 233 | ||
| 254 | #ifdef TAP_DANCE_ENABLE | 234 | #ifdef TAP_DANCE_ENABLE |
| 255 | preprocess_tap_dance(keycode, record); | 235 | preprocess_tap_dance(keycode, record); |
| 256 | #endif | 236 | #endif |
| 257 | |||
| 258 | if (!( | ||
| 259 | #if defined(KEY_LOCK_ENABLE) | ||
| 260 | // Must run first to be able to mask key_up events. | ||
| 261 | process_key_lock(&keycode, record) && | ||
| 262 | #endif | ||
| 263 | #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) | ||
| 264 | process_clicky(keycode, record) && | ||
| 265 | #endif //AUDIO_CLICKY | ||
| 266 | #ifdef HAPTIC_ENABLE | ||
| 267 | process_haptic(keycode, record) && | ||
| 268 | #endif //HAPTIC_ENABLE | ||
| 269 | #if defined(RGB_MATRIX_ENABLE) | ||
| 270 | process_rgb_matrix(keycode, record) && | ||
| 271 | #endif | ||
| 272 | process_record_kb(keycode, record) && | ||
| 273 | #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) | ||
| 274 | process_midi(keycode, record) && | ||
| 275 | #endif | ||
| 276 | #ifdef AUDIO_ENABLE | ||
| 277 | process_audio(keycode, record) && | ||
| 278 | #endif | ||
| 279 | #ifdef STENO_ENABLE | ||
| 280 | process_steno(keycode, record) && | ||
| 281 | #endif | ||
| 282 | #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE) | ||
| 283 | process_music(keycode, record) && | ||
| 284 | #endif | ||
| 285 | #ifdef TAP_DANCE_ENABLE | ||
| 286 | process_tap_dance(keycode, record) && | ||
| 287 | #endif | ||
| 288 | #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) | ||
| 289 | process_unicode_common(keycode, record) && | ||
| 290 | #endif | ||
| 291 | #ifdef LEADER_ENABLE | ||
| 292 | process_leader(keycode, record) && | ||
| 293 | #endif | ||
| 294 | #ifdef COMBO_ENABLE | ||
| 295 | process_combo(keycode, record) && | ||
| 296 | #endif | ||
| 297 | #ifdef PRINTING_ENABLE | ||
| 298 | process_printer(keycode, record) && | ||
| 299 | #endif | ||
| 300 | #ifdef AUTO_SHIFT_ENABLE | ||
| 301 | process_auto_shift(keycode, record) && | ||
| 302 | #endif | ||
| 303 | #ifdef TERMINAL_ENABLE | ||
| 304 | process_terminal(keycode, record) && | ||
| 305 | #endif | ||
| 306 | #ifdef SPACE_CADET_ENABLE | ||
| 307 | process_space_cadet(keycode, record) && | ||
| 308 | #endif | ||
| 309 | true)) { | ||
| 310 | return false; | ||
| 311 | } | ||
| 312 | |||
| 313 | // Shift / paren setup | ||
| 314 | |||
| 315 | switch(keycode) { | ||
| 316 | case RESET: | ||
| 317 | if (record->event.pressed) { | ||
| 318 | reset_keyboard(); | ||
| 319 | } | ||
| 320 | return false; | ||
| 321 | case DEBUG: | ||
| 322 | if (record->event.pressed) { | ||
| 323 | debug_enable ^= 1; | ||
| 324 | if (debug_enable) { | ||
| 325 | print("DEBUG: enabled.\n"); | ||
| 326 | } else { | ||
| 327 | print("DEBUG: disabled.\n"); | ||
| 328 | } | ||
| 329 | } | ||
| 330 | return false; | ||
| 331 | case EEPROM_RESET: | ||
| 332 | if (record->event.pressed) { | ||
| 333 | eeconfig_init(); | ||
| 334 | } | ||
| 335 | return false; | ||
| 336 | #ifdef FAUXCLICKY_ENABLE | ||
| 337 | case FC_TOG: | ||
| 338 | if (record->event.pressed) { | ||
| 339 | FAUXCLICKY_TOGGLE; | ||
| 340 | } | ||
| 341 | return false; | ||
| 342 | case FC_ON: | ||
| 343 | if (record->event.pressed) { | ||
| 344 | FAUXCLICKY_ON; | ||
| 345 | } | ||
| 346 | return false; | ||
| 347 | case FC_OFF: | ||
| 348 | if (record->event.pressed) { | ||
| 349 | FAUXCLICKY_OFF; | ||
| 350 | } | ||
| 351 | return false; | ||
| 352 | #endif | ||
| 353 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | ||
| 354 | case RGB_TOG: | ||
| 355 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 356 | #ifndef SPLIT_KEYBOARD | ||
| 357 | if (record->event.pressed) { | ||
| 358 | #else | ||
| 359 | if (!record->event.pressed) { | ||
| 360 | #endif | ||
| 361 | rgblight_toggle(); | ||
| 362 | } | ||
| 363 | return false; | ||
| 364 | case RGB_MODE_FORWARD: | ||
| 365 | if (record->event.pressed) { | ||
| 366 | uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT)); | ||
| 367 | if(shifted) { | ||
| 368 | rgblight_step_reverse(); | ||
| 369 | } | ||
| 370 | else { | ||
| 371 | rgblight_step(); | ||
| 372 | } | ||
| 373 | } | ||
| 374 | return false; | ||
| 375 | case RGB_MODE_REVERSE: | ||
| 376 | if (record->event.pressed) { | ||
| 377 | uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT)); | ||
| 378 | if(shifted) { | ||
| 379 | rgblight_step(); | ||
| 380 | } | ||
| 381 | else { | ||
| 382 | rgblight_step_reverse(); | ||
| 383 | } | ||
| 384 | } | ||
| 385 | return false; | ||
| 386 | case RGB_HUI: | ||
| 387 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 388 | #ifndef SPLIT_KEYBOARD | ||
| 389 | if (record->event.pressed) { | ||
| 390 | #else | ||
| 391 | if (!record->event.pressed) { | ||
| 392 | #endif | ||
| 393 | rgblight_increase_hue(); | ||
| 394 | } | ||
| 395 | return false; | ||
| 396 | case RGB_HUD: | ||
| 397 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 398 | #ifndef SPLIT_KEYBOARD | ||
| 399 | if (record->event.pressed) { | ||
| 400 | #else | ||
| 401 | if (!record->event.pressed) { | ||
| 402 | #endif | ||
| 403 | rgblight_decrease_hue(); | ||
| 404 | } | ||
| 405 | return false; | ||
| 406 | case RGB_SAI: | ||
| 407 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 408 | #ifndef SPLIT_KEYBOARD | ||
| 409 | if (record->event.pressed) { | ||
| 410 | #else | ||
| 411 | if (!record->event.pressed) { | ||
| 412 | #endif | ||
| 413 | rgblight_increase_sat(); | ||
| 414 | } | ||
| 415 | return false; | ||
| 416 | case RGB_SAD: | ||
| 417 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 418 | #ifndef SPLIT_KEYBOARD | ||
| 419 | if (record->event.pressed) { | ||
| 420 | #else | ||
| 421 | if (!record->event.pressed) { | ||
| 422 | #endif | ||
| 423 | rgblight_decrease_sat(); | ||
| 424 | } | ||
| 425 | return false; | ||
| 426 | case RGB_VAI: | ||
| 427 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 428 | #ifndef SPLIT_KEYBOARD | ||
| 429 | if (record->event.pressed) { | ||
| 430 | #else | ||
| 431 | if (!record->event.pressed) { | ||
| 432 | #endif | ||
| 433 | rgblight_increase_val(); | ||
| 434 | } | ||
| 435 | return false; | ||
| 436 | case RGB_VAD: | ||
| 437 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 438 | #ifndef SPLIT_KEYBOARD | ||
| 439 | if (record->event.pressed) { | ||
| 440 | #else | ||
| 441 | if (!record->event.pressed) { | ||
| 442 | #endif | ||
| 443 | rgblight_decrease_val(); | ||
| 444 | } | ||
| 445 | return false; | ||
| 446 | case RGB_SPI: | ||
| 447 | if (record->event.pressed) { | ||
| 448 | rgblight_increase_speed(); | ||
| 449 | } | ||
| 450 | return false; | ||
| 451 | case RGB_SPD: | ||
| 452 | if (record->event.pressed) { | ||
| 453 | rgblight_decrease_speed(); | ||
| 454 | } | ||
| 455 | return false; | ||
| 456 | case RGB_MODE_PLAIN: | ||
| 457 | if (record->event.pressed) { | ||
| 458 | rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); | ||
| 459 | } | ||
| 460 | return false; | ||
| 461 | case RGB_MODE_BREATHE: | ||
| 462 | #ifdef RGBLIGHT_EFFECT_BREATHING | ||
| 463 | if (record->event.pressed) { | ||
| 464 | if ((RGBLIGHT_MODE_BREATHING <= rgblight_get_mode()) && | ||
| 465 | (rgblight_get_mode() < RGBLIGHT_MODE_BREATHING_end)) { | ||
| 466 | rgblight_step(); | ||
| 467 | } else { | ||
| 468 | rgblight_mode(RGBLIGHT_MODE_BREATHING); | ||
| 469 | } | ||
| 470 | } | ||
| 471 | #endif | ||
| 472 | return false; | ||
| 473 | case RGB_MODE_RAINBOW: | ||
| 474 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD | ||
| 475 | if (record->event.pressed) { | ||
| 476 | if ((RGBLIGHT_MODE_RAINBOW_MOOD <= rgblight_get_mode()) && | ||
| 477 | (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_MOOD_end)) { | ||
| 478 | rgblight_step(); | ||
| 479 | } else { | ||
| 480 | rgblight_mode(RGBLIGHT_MODE_RAINBOW_MOOD); | ||
| 481 | } | ||
| 482 | } | ||
| 483 | #endif | ||
| 484 | return false; | ||
| 485 | case RGB_MODE_SWIRL: | ||
| 486 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL | ||
| 487 | if (record->event.pressed) { | ||
| 488 | if ((RGBLIGHT_MODE_RAINBOW_SWIRL <= rgblight_get_mode()) && | ||
| 489 | (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_SWIRL_end)) { | ||
| 490 | rgblight_step(); | ||
| 491 | } else { | ||
| 492 | rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL); | ||
| 493 | } | ||
| 494 | } | ||
| 495 | #endif | ||
| 496 | return false; | ||
| 497 | case RGB_MODE_SNAKE: | ||
| 498 | #ifdef RGBLIGHT_EFFECT_SNAKE | ||
| 499 | if (record->event.pressed) { | ||
| 500 | if ((RGBLIGHT_MODE_SNAKE <= rgblight_get_mode()) && | ||
| 501 | (rgblight_get_mode() < RGBLIGHT_MODE_SNAKE_end)) { | ||
| 502 | rgblight_step(); | ||
| 503 | } else { | ||
| 504 | rgblight_mode(RGBLIGHT_MODE_SNAKE); | ||
| 505 | } | ||
| 506 | } | ||
| 507 | #endif | ||
| 508 | return false; | ||
| 509 | case RGB_MODE_KNIGHT: | ||
| 510 | #ifdef RGBLIGHT_EFFECT_KNIGHT | ||
| 511 | if (record->event.pressed) { | ||
| 512 | if ((RGBLIGHT_MODE_KNIGHT <= rgblight_get_mode()) && | ||
| 513 | (rgblight_get_mode() < RGBLIGHT_MODE_KNIGHT_end)) { | ||
| 514 | rgblight_step(); | ||
| 515 | } else { | ||
| 516 | rgblight_mode(RGBLIGHT_MODE_KNIGHT); | ||
| 517 | } | ||
| 518 | } | ||
| 519 | #endif | ||
| 520 | return false; | ||
| 521 | case RGB_MODE_XMAS: | ||
| 522 | #ifdef RGBLIGHT_EFFECT_CHRISTMAS | ||
| 523 | if (record->event.pressed) { | ||
| 524 | rgblight_mode(RGBLIGHT_MODE_CHRISTMAS); | ||
| 525 | } | ||
| 526 | #endif | ||
| 527 | return false; | ||
| 528 | case RGB_MODE_GRADIENT: | ||
| 529 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT | ||
| 530 | if (record->event.pressed) { | ||
| 531 | if ((RGBLIGHT_MODE_STATIC_GRADIENT <= rgblight_get_mode()) && | ||
| 532 | (rgblight_get_mode() < RGBLIGHT_MODE_STATIC_GRADIENT_end)) { | ||
| 533 | rgblight_step(); | ||
| 534 | } else { | ||
| 535 | rgblight_mode(RGBLIGHT_MODE_STATIC_GRADIENT); | ||
| 536 | } | ||
| 537 | } | ||
| 538 | #endif | ||
| 539 | return false; | ||
| 540 | case RGB_MODE_RGBTEST: | ||
| 541 | #ifdef RGBLIGHT_EFFECT_RGB_TEST | ||
| 542 | if (record->event.pressed) { | ||
| 543 | rgblight_mode(RGBLIGHT_MODE_RGB_TEST); | ||
| 544 | } | ||
| 545 | #endif | ||
| 546 | return false; | ||
| 547 | #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | ||
| 548 | #ifdef VELOCIKEY_ENABLE | ||
| 549 | case VLK_TOG: | ||
| 550 | if (record->event.pressed) { | ||
| 551 | velocikey_toggle(); | ||
| 552 | } | ||
| 553 | return false; | ||
| 554 | #endif | ||
| 555 | #ifdef PROTOCOL_LUFA | ||
| 556 | case OUT_AUTO: | ||
| 557 | if (record->event.pressed) { | ||
| 558 | set_output(OUTPUT_AUTO); | ||
| 559 | } | ||
| 560 | return false; | ||
| 561 | case OUT_USB: | ||
| 562 | if (record->event.pressed) { | ||
| 563 | set_output(OUTPUT_USB); | ||
| 564 | } | ||
| 565 | return false; | ||
| 566 | #ifdef BLUETOOTH_ENABLE | ||
| 567 | case OUT_BT: | ||
| 568 | if (record->event.pressed) { | ||
| 569 | set_output(OUTPUT_BLUETOOTH); | ||
| 570 | } | ||
| 571 | return false; | ||
| 572 | #endif | ||
| 573 | #endif | ||
| 574 | case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI: | ||
| 575 | case MAGIC_SWAP_LCTL_LGUI ... MAGIC_TOGGLE_CTL_GUI: | ||
| 576 | if (record->event.pressed) { | ||
| 577 | // MAGIC actions (BOOTMAGIC without the boot) | ||
| 578 | if (!eeconfig_is_enabled()) { | ||
| 579 | eeconfig_init(); | ||
| 580 | } | ||
| 581 | /* keymap config */ | ||
| 582 | keymap_config.raw = eeconfig_read_keymap(); | ||
| 583 | switch (keycode) | ||
| 584 | { | ||
| 585 | case MAGIC_SWAP_CONTROL_CAPSLOCK: | ||
| 586 | keymap_config.swap_control_capslock = true; | ||
| 587 | break; | ||
| 588 | case MAGIC_CAPSLOCK_TO_CONTROL: | ||
| 589 | keymap_config.capslock_to_control = true; | ||
| 590 | break; | ||
| 591 | case MAGIC_SWAP_LALT_LGUI: | ||
| 592 | keymap_config.swap_lalt_lgui = true; | ||
| 593 | break; | ||
| 594 | case MAGIC_SWAP_RALT_RGUI: | ||
| 595 | keymap_config.swap_ralt_rgui = true; | ||
| 596 | break; | ||
| 597 | case MAGIC_SWAP_LCTL_LGUI: | ||
| 598 | keymap_config.swap_lctl_lgui = true; | ||
| 599 | break; | ||
| 600 | case MAGIC_SWAP_RCTL_RGUI: | ||
| 601 | keymap_config.swap_rctl_rgui = true; | ||
| 602 | break; | ||
| 603 | case MAGIC_NO_GUI: | ||
| 604 | keymap_config.no_gui = true; | ||
| 605 | break; | ||
| 606 | case MAGIC_SWAP_GRAVE_ESC: | ||
| 607 | keymap_config.swap_grave_esc = true; | ||
| 608 | break; | ||
| 609 | case MAGIC_SWAP_BACKSLASH_BACKSPACE: | ||
| 610 | keymap_config.swap_backslash_backspace = true; | ||
| 611 | break; | ||
| 612 | case MAGIC_HOST_NKRO: | ||
| 613 | keymap_config.nkro = true; | ||
| 614 | break; | ||
| 615 | case MAGIC_SWAP_ALT_GUI: | ||
| 616 | keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true; | ||
| 617 | #ifdef AUDIO_ENABLE | ||
| 618 | PLAY_SONG(ag_swap_song); | ||
| 619 | #endif | ||
| 620 | break; | ||
| 621 | case MAGIC_SWAP_CTL_GUI: | ||
| 622 | keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true; | ||
| 623 | #ifdef AUDIO_ENABLE | ||
| 624 | PLAY_SONG(cg_swap_song); | ||
| 625 | #endif | ||
| 626 | break; | ||
| 627 | case MAGIC_UNSWAP_CONTROL_CAPSLOCK: | ||
| 628 | keymap_config.swap_control_capslock = false; | ||
| 629 | break; | ||
| 630 | case MAGIC_UNCAPSLOCK_TO_CONTROL: | ||
| 631 | keymap_config.capslock_to_control = false; | ||
| 632 | break; | ||
| 633 | case MAGIC_UNSWAP_LALT_LGUI: | ||
| 634 | keymap_config.swap_lalt_lgui = false; | ||
| 635 | break; | ||
| 636 | case MAGIC_UNSWAP_RALT_RGUI: | ||
| 637 | keymap_config.swap_ralt_rgui = false; | ||
| 638 | break; | ||
| 639 | case MAGIC_UNSWAP_LCTL_LGUI: | ||
| 640 | keymap_config.swap_lctl_lgui = false; | ||
| 641 | break; | ||
| 642 | case MAGIC_UNSWAP_RCTL_RGUI: | ||
| 643 | keymap_config.swap_rctl_rgui = false; | ||
| 644 | break; | ||
| 645 | case MAGIC_UNNO_GUI: | ||
| 646 | keymap_config.no_gui = false; | ||
| 647 | break; | ||
| 648 | case MAGIC_UNSWAP_GRAVE_ESC: | ||
| 649 | keymap_config.swap_grave_esc = false; | ||
| 650 | break; | ||
| 651 | case MAGIC_UNSWAP_BACKSLASH_BACKSPACE: | ||
| 652 | keymap_config.swap_backslash_backspace = false; | ||
| 653 | break; | ||
| 654 | case MAGIC_UNHOST_NKRO: | ||
| 655 | keymap_config.nkro = false; | ||
| 656 | break; | ||
| 657 | case MAGIC_UNSWAP_ALT_GUI: | ||
| 658 | keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false; | ||
| 659 | #ifdef AUDIO_ENABLE | ||
| 660 | PLAY_SONG(ag_norm_song); | ||
| 661 | #endif | ||
| 662 | break; | ||
| 663 | case MAGIC_UNSWAP_CTL_GUI: | ||
| 664 | keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false; | ||
| 665 | #ifdef AUDIO_ENABLE | ||
| 666 | PLAY_SONG(cg_norm_song); | ||
| 667 | #endif | ||
| 668 | break; | ||
| 669 | case MAGIC_TOGGLE_ALT_GUI: | ||
| 670 | keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; | ||
| 671 | keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui; | ||
| 672 | #ifdef AUDIO_ENABLE | ||
| 673 | if (keymap_config.swap_ralt_rgui) { | ||
| 674 | PLAY_SONG(ag_swap_song); | ||
| 675 | } else { | ||
| 676 | PLAY_SONG(ag_norm_song); | ||
| 677 | } | ||
| 678 | #endif | ||
| 679 | break; | ||
| 680 | case MAGIC_TOGGLE_CTL_GUI: | ||
| 681 | keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui; | ||
| 682 | keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui; | ||
| 683 | #ifdef AUDIO_ENABLE | ||
| 684 | if (keymap_config.swap_rctl_rgui) { | ||
| 685 | PLAY_SONG(cg_swap_song); | ||
| 686 | } else { | ||
| 687 | PLAY_SONG(cg_norm_song); | ||
| 688 | } | ||
| 689 | #endif | ||
| 690 | break; | ||
| 691 | case MAGIC_TOGGLE_NKRO: | ||
| 692 | keymap_config.nkro = !keymap_config.nkro; | ||
| 693 | break; | ||
| 694 | default: | ||
| 695 | break; | ||
| 696 | } | ||
| 697 | eeconfig_update_keymap(keymap_config.raw); | ||
| 698 | clear_keyboard(); // clear to prevent stuck keys | ||
| 699 | 237 | ||
| 238 | if (!( | ||
| 239 | #if defined(KEY_LOCK_ENABLE) | ||
| 240 | // Must run first to be able to mask key_up events. | ||
| 241 | process_key_lock(&keycode, record) && | ||
| 242 | #endif | ||
| 243 | #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) | ||
| 244 | process_clicky(keycode, record) && | ||
| 245 | #endif // AUDIO_CLICKY | ||
| 246 | #ifdef HAPTIC_ENABLE | ||
| 247 | process_haptic(keycode, record) && | ||
| 248 | #endif // HAPTIC_ENABLE | ||
| 249 | #if defined(RGB_MATRIX_ENABLE) | ||
| 250 | process_rgb_matrix(keycode, record) && | ||
| 251 | #endif | ||
| 252 | process_record_kb(keycode, record) && | ||
| 253 | #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) | ||
| 254 | process_midi(keycode, record) && | ||
| 255 | #endif | ||
| 256 | #ifdef AUDIO_ENABLE | ||
| 257 | process_audio(keycode, record) && | ||
| 258 | #endif | ||
| 259 | #ifdef STENO_ENABLE | ||
| 260 | process_steno(keycode, record) && | ||
| 261 | #endif | ||
| 262 | #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE) | ||
| 263 | process_music(keycode, record) && | ||
| 264 | #endif | ||
| 265 | #ifdef TAP_DANCE_ENABLE | ||
| 266 | process_tap_dance(keycode, record) && | ||
| 267 | #endif | ||
| 268 | #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) | ||
| 269 | process_unicode_common(keycode, record) && | ||
| 270 | #endif | ||
| 271 | #ifdef LEADER_ENABLE | ||
| 272 | process_leader(keycode, record) && | ||
| 273 | #endif | ||
| 274 | #ifdef COMBO_ENABLE | ||
| 275 | process_combo(keycode, record) && | ||
| 276 | #endif | ||
| 277 | #ifdef PRINTING_ENABLE | ||
| 278 | process_printer(keycode, record) && | ||
| 279 | #endif | ||
| 280 | #ifdef AUTO_SHIFT_ENABLE | ||
| 281 | process_auto_shift(keycode, record) && | ||
| 282 | #endif | ||
| 283 | #ifdef TERMINAL_ENABLE | ||
| 284 | process_terminal(keycode, record) && | ||
| 285 | #endif | ||
| 286 | #ifdef SPACE_CADET_ENABLE | ||
| 287 | process_space_cadet(keycode, record) && | ||
| 288 | #endif | ||
| 289 | true)) { | ||
| 700 | return false; | 290 | return false; |
| 701 | } | 291 | } |
| 702 | break; | ||
| 703 | 292 | ||
| 704 | case GRAVE_ESC: { | 293 | // Shift / paren setup |
| 705 | uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT) | 294 | |
| 706 | |MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI))); | 295 | switch (keycode) { |
| 296 | case RESET: | ||
| 297 | if (record->event.pressed) { | ||
| 298 | reset_keyboard(); | ||
| 299 | } | ||
| 300 | return false; | ||
| 301 | case DEBUG: | ||
| 302 | if (record->event.pressed) { | ||
| 303 | debug_enable ^= 1; | ||
| 304 | if (debug_enable) { | ||
| 305 | print("DEBUG: enabled.\n"); | ||
| 306 | } else { | ||
| 307 | print("DEBUG: disabled.\n"); | ||
| 308 | } | ||
| 309 | } | ||
| 310 | return false; | ||
| 311 | case EEPROM_RESET: | ||
| 312 | if (record->event.pressed) { | ||
| 313 | eeconfig_init(); | ||
| 314 | } | ||
| 315 | return false; | ||
| 316 | #ifdef FAUXCLICKY_ENABLE | ||
| 317 | case FC_TOG: | ||
| 318 | if (record->event.pressed) { | ||
| 319 | FAUXCLICKY_TOGGLE; | ||
| 320 | } | ||
| 321 | return false; | ||
| 322 | case FC_ON: | ||
| 323 | if (record->event.pressed) { | ||
| 324 | FAUXCLICKY_ON; | ||
| 325 | } | ||
| 326 | return false; | ||
| 327 | case FC_OFF: | ||
| 328 | if (record->event.pressed) { | ||
| 329 | FAUXCLICKY_OFF; | ||
| 330 | } | ||
| 331 | return false; | ||
| 332 | #endif | ||
| 333 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | ||
| 334 | case RGB_TOG: | ||
| 335 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 336 | # ifndef SPLIT_KEYBOARD | ||
| 337 | if (record->event.pressed) { | ||
| 338 | # else | ||
| 339 | if (!record->event.pressed) { | ||
| 340 | # endif | ||
| 341 | rgblight_toggle(); | ||
| 342 | } | ||
| 343 | return false; | ||
| 344 | case RGB_MODE_FORWARD: | ||
| 345 | if (record->event.pressed) { | ||
| 346 | uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)); | ||
| 347 | if (shifted) { | ||
| 348 | rgblight_step_reverse(); | ||
| 349 | } else { | ||
| 350 | rgblight_step(); | ||
| 351 | } | ||
| 352 | } | ||
| 353 | return false; | ||
| 354 | case RGB_MODE_REVERSE: | ||
| 355 | if (record->event.pressed) { | ||
| 356 | uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)); | ||
| 357 | if (shifted) { | ||
| 358 | rgblight_step(); | ||
| 359 | } else { | ||
| 360 | rgblight_step_reverse(); | ||
| 361 | } | ||
| 362 | } | ||
| 363 | return false; | ||
| 364 | case RGB_HUI: | ||
| 365 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 366 | # ifndef SPLIT_KEYBOARD | ||
| 367 | if (record->event.pressed) { | ||
| 368 | # else | ||
| 369 | if (!record->event.pressed) { | ||
| 370 | # endif | ||
| 371 | rgblight_increase_hue(); | ||
| 372 | } | ||
| 373 | return false; | ||
| 374 | case RGB_HUD: | ||
| 375 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 376 | # ifndef SPLIT_KEYBOARD | ||
| 377 | if (record->event.pressed) { | ||
| 378 | # else | ||
| 379 | if (!record->event.pressed) { | ||
| 380 | # endif | ||
| 381 | rgblight_decrease_hue(); | ||
| 382 | } | ||
| 383 | return false; | ||
| 384 | case RGB_SAI: | ||
| 385 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 386 | # ifndef SPLIT_KEYBOARD | ||
| 387 | if (record->event.pressed) { | ||
| 388 | # else | ||
| 389 | if (!record->event.pressed) { | ||
| 390 | # endif | ||
| 391 | rgblight_increase_sat(); | ||
| 392 | } | ||
| 393 | return false; | ||
| 394 | case RGB_SAD: | ||
| 395 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 396 | # ifndef SPLIT_KEYBOARD | ||
| 397 | if (record->event.pressed) { | ||
| 398 | # else | ||
| 399 | if (!record->event.pressed) { | ||
| 400 | # endif | ||
| 401 | rgblight_decrease_sat(); | ||
| 402 | } | ||
| 403 | return false; | ||
| 404 | case RGB_VAI: | ||
| 405 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 406 | # ifndef SPLIT_KEYBOARD | ||
| 407 | if (record->event.pressed) { | ||
| 408 | # else | ||
| 409 | if (!record->event.pressed) { | ||
| 410 | # endif | ||
| 411 | rgblight_increase_val(); | ||
| 412 | } | ||
| 413 | return false; | ||
| 414 | case RGB_VAD: | ||
| 415 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 416 | # ifndef SPLIT_KEYBOARD | ||
| 417 | if (record->event.pressed) { | ||
| 418 | # else | ||
| 419 | if (!record->event.pressed) { | ||
| 420 | # endif | ||
| 421 | rgblight_decrease_val(); | ||
| 422 | } | ||
| 423 | return false; | ||
| 424 | case RGB_SPI: | ||
| 425 | if (record->event.pressed) { | ||
| 426 | rgblight_increase_speed(); | ||
| 427 | } | ||
| 428 | return false; | ||
| 429 | case RGB_SPD: | ||
| 430 | if (record->event.pressed) { | ||
| 431 | rgblight_decrease_speed(); | ||
| 432 | } | ||
| 433 | return false; | ||
| 434 | case RGB_MODE_PLAIN: | ||
| 435 | if (record->event.pressed) { | ||
| 436 | rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); | ||
| 437 | } | ||
| 438 | return false; | ||
| 439 | case RGB_MODE_BREATHE: | ||
| 440 | # ifdef RGBLIGHT_EFFECT_BREATHING | ||
| 441 | if (record->event.pressed) { | ||
| 442 | if ((RGBLIGHT_MODE_BREATHING <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_BREATHING_end)) { | ||
| 443 | rgblight_step(); | ||
| 444 | } else { | ||
| 445 | rgblight_mode(RGBLIGHT_MODE_BREATHING); | ||
| 446 | } | ||
| 447 | } | ||
| 448 | # endif | ||
| 449 | return false; | ||
| 450 | case RGB_MODE_RAINBOW: | ||
| 451 | # ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD | ||
| 452 | if (record->event.pressed) { | ||
| 453 | if ((RGBLIGHT_MODE_RAINBOW_MOOD <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_MOOD_end)) { | ||
| 454 | rgblight_step(); | ||
| 455 | } else { | ||
| 456 | rgblight_mode(RGBLIGHT_MODE_RAINBOW_MOOD); | ||
| 457 | } | ||
| 458 | } | ||
| 459 | # endif | ||
| 460 | return false; | ||
| 461 | case RGB_MODE_SWIRL: | ||
| 462 | # ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL | ||
| 463 | if (record->event.pressed) { | ||
| 464 | if ((RGBLIGHT_MODE_RAINBOW_SWIRL <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_SWIRL_end)) { | ||
| 465 | rgblight_step(); | ||
| 466 | } else { | ||
| 467 | rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL); | ||
| 468 | } | ||
| 469 | } | ||
| 470 | # endif | ||
| 471 | return false; | ||
| 472 | case RGB_MODE_SNAKE: | ||
| 473 | # ifdef RGBLIGHT_EFFECT_SNAKE | ||
| 474 | if (record->event.pressed) { | ||
| 475 | if ((RGBLIGHT_MODE_SNAKE <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_SNAKE_end)) { | ||
| 476 | rgblight_step(); | ||
| 477 | } else { | ||
| 478 | rgblight_mode(RGBLIGHT_MODE_SNAKE); | ||
| 479 | } | ||
| 480 | } | ||
| 481 | # endif | ||
| 482 | return false; | ||
| 483 | case RGB_MODE_KNIGHT: | ||
| 484 | # ifdef RGBLIGHT_EFFECT_KNIGHT | ||
| 485 | if (record->event.pressed) { | ||
| 486 | if ((RGBLIGHT_MODE_KNIGHT <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_KNIGHT_end)) { | ||
| 487 | rgblight_step(); | ||
| 488 | } else { | ||
| 489 | rgblight_mode(RGBLIGHT_MODE_KNIGHT); | ||
| 490 | } | ||
| 491 | } | ||
| 492 | # endif | ||
| 493 | return false; | ||
| 494 | case RGB_MODE_XMAS: | ||
| 495 | # ifdef RGBLIGHT_EFFECT_CHRISTMAS | ||
| 496 | if (record->event.pressed) { | ||
| 497 | rgblight_mode(RGBLIGHT_MODE_CHRISTMAS); | ||
| 498 | } | ||
| 499 | # endif | ||
| 500 | return false; | ||
| 501 | case RGB_MODE_GRADIENT: | ||
| 502 | # ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT | ||
| 503 | if (record->event.pressed) { | ||
| 504 | if ((RGBLIGHT_MODE_STATIC_GRADIENT <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_STATIC_GRADIENT_end)) { | ||
| 505 | rgblight_step(); | ||
| 506 | } else { | ||
| 507 | rgblight_mode(RGBLIGHT_MODE_STATIC_GRADIENT); | ||
| 508 | } | ||
| 509 | } | ||
| 510 | # endif | ||
| 511 | return false; | ||
| 512 | case RGB_MODE_RGBTEST: | ||
| 513 | # ifdef RGBLIGHT_EFFECT_RGB_TEST | ||
| 514 | if (record->event.pressed) { | ||
| 515 | rgblight_mode(RGBLIGHT_MODE_RGB_TEST); | ||
| 516 | } | ||
| 517 | # endif | ||
| 518 | return false; | ||
| 519 | #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | ||
| 520 | #ifdef VELOCIKEY_ENABLE | ||
| 521 | case VLK_TOG: | ||
| 522 | if (record->event.pressed) { | ||
| 523 | velocikey_toggle(); | ||
| 524 | } | ||
| 525 | return false; | ||
| 526 | #endif | ||
| 527 | #ifdef PROTOCOL_LUFA | ||
| 528 | case OUT_AUTO: | ||
| 529 | if (record->event.pressed) { | ||
| 530 | set_output(OUTPUT_AUTO); | ||
| 531 | } | ||
| 532 | return false; | ||
| 533 | case OUT_USB: | ||
| 534 | if (record->event.pressed) { | ||
| 535 | set_output(OUTPUT_USB); | ||
| 536 | } | ||
| 537 | return false; | ||
| 538 | # ifdef BLUETOOTH_ENABLE | ||
| 539 | case OUT_BT: | ||
| 540 | if (record->event.pressed) { | ||
| 541 | set_output(OUTPUT_BLUETOOTH); | ||
| 542 | } | ||
| 543 | return false; | ||
| 544 | # endif | ||
| 545 | #endif | ||
| 546 | case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI: | ||
| 547 | case MAGIC_SWAP_LCTL_LGUI ... MAGIC_TOGGLE_CTL_GUI: | ||
| 548 | if (record->event.pressed) { | ||
| 549 | // MAGIC actions (BOOTMAGIC without the boot) | ||
| 550 | if (!eeconfig_is_enabled()) { | ||
| 551 | eeconfig_init(); | ||
| 552 | } | ||
| 553 | /* keymap config */ | ||
| 554 | keymap_config.raw = eeconfig_read_keymap(); | ||
| 555 | switch (keycode) { | ||
| 556 | case MAGIC_SWAP_CONTROL_CAPSLOCK: | ||
| 557 | keymap_config.swap_control_capslock = true; | ||
| 558 | break; | ||
| 559 | case MAGIC_CAPSLOCK_TO_CONTROL: | ||
| 560 | keymap_config.capslock_to_control = true; | ||
| 561 | break; | ||
| 562 | case MAGIC_SWAP_LALT_LGUI: | ||
| 563 | keymap_config.swap_lalt_lgui = true; | ||
| 564 | break; | ||
| 565 | case MAGIC_SWAP_RALT_RGUI: | ||
| 566 | keymap_config.swap_ralt_rgui = true; | ||
| 567 | break; | ||
| 568 | case MAGIC_SWAP_LCTL_LGUI: | ||
| 569 | keymap_config.swap_lctl_lgui = true; | ||
| 570 | break; | ||
| 571 | case MAGIC_SWAP_RCTL_RGUI: | ||
| 572 | keymap_config.swap_rctl_rgui = true; | ||
| 573 | break; | ||
| 574 | case MAGIC_NO_GUI: | ||
| 575 | keymap_config.no_gui = true; | ||
| 576 | break; | ||
| 577 | case MAGIC_SWAP_GRAVE_ESC: | ||
| 578 | keymap_config.swap_grave_esc = true; | ||
| 579 | break; | ||
| 580 | case MAGIC_SWAP_BACKSLASH_BACKSPACE: | ||
| 581 | keymap_config.swap_backslash_backspace = true; | ||
| 582 | break; | ||
| 583 | case MAGIC_HOST_NKRO: | ||
| 584 | keymap_config.nkro = true; | ||
| 585 | break; | ||
| 586 | case MAGIC_SWAP_ALT_GUI: | ||
| 587 | keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true; | ||
| 588 | #ifdef AUDIO_ENABLE | ||
| 589 | PLAY_SONG(ag_swap_song); | ||
| 590 | #endif | ||
| 591 | break; | ||
| 592 | case MAGIC_SWAP_CTL_GUI: | ||
| 593 | keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true; | ||
| 594 | #ifdef AUDIO_ENABLE | ||
| 595 | PLAY_SONG(cg_swap_song); | ||
| 596 | #endif | ||
| 597 | break; | ||
| 598 | case MAGIC_UNSWAP_CONTROL_CAPSLOCK: | ||
| 599 | keymap_config.swap_control_capslock = false; | ||
| 600 | break; | ||
| 601 | case MAGIC_UNCAPSLOCK_TO_CONTROL: | ||
| 602 | keymap_config.capslock_to_control = false; | ||
| 603 | break; | ||
| 604 | case MAGIC_UNSWAP_LALT_LGUI: | ||
| 605 | keymap_config.swap_lalt_lgui = false; | ||
| 606 | break; | ||
| 607 | case MAGIC_UNSWAP_RALT_RGUI: | ||
| 608 | keymap_config.swap_ralt_rgui = false; | ||
| 609 | break; | ||
| 610 | case MAGIC_UNSWAP_LCTL_LGUI: | ||
| 611 | keymap_config.swap_lctl_lgui = false; | ||
| 612 | break; | ||
| 613 | case MAGIC_UNSWAP_RCTL_RGUI: | ||
| 614 | keymap_config.swap_rctl_rgui = false; | ||
| 615 | break; | ||
| 616 | case MAGIC_UNNO_GUI: | ||
| 617 | keymap_config.no_gui = false; | ||
| 618 | break; | ||
| 619 | case MAGIC_UNSWAP_GRAVE_ESC: | ||
| 620 | keymap_config.swap_grave_esc = false; | ||
| 621 | break; | ||
| 622 | case MAGIC_UNSWAP_BACKSLASH_BACKSPACE: | ||
| 623 | keymap_config.swap_backslash_backspace = false; | ||
| 624 | break; | ||
| 625 | case MAGIC_UNHOST_NKRO: | ||
| 626 | keymap_config.nkro = false; | ||
| 627 | break; | ||
| 628 | case MAGIC_UNSWAP_ALT_GUI: | ||
| 629 | keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false; | ||
| 630 | #ifdef AUDIO_ENABLE | ||
| 631 | PLAY_SONG(ag_norm_song); | ||
| 632 | #endif | ||
| 633 | break; | ||
| 634 | case MAGIC_UNSWAP_CTL_GUI: | ||
| 635 | keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false; | ||
| 636 | #ifdef AUDIO_ENABLE | ||
| 637 | PLAY_SONG(cg_norm_song); | ||
| 638 | #endif | ||
| 639 | break; | ||
| 640 | case MAGIC_TOGGLE_ALT_GUI: | ||
| 641 | keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; | ||
| 642 | keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui; | ||
| 643 | #ifdef AUDIO_ENABLE | ||
| 644 | if (keymap_config.swap_ralt_rgui) { | ||
| 645 | PLAY_SONG(ag_swap_song); | ||
| 646 | } else { | ||
| 647 | PLAY_SONG(ag_norm_song); | ||
| 648 | } | ||
| 649 | #endif | ||
| 650 | break; | ||
| 651 | case MAGIC_TOGGLE_CTL_GUI: | ||
| 652 | keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui; | ||
| 653 | keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui; | ||
| 654 | #ifdef AUDIO_ENABLE | ||
| 655 | if (keymap_config.swap_rctl_rgui) { | ||
| 656 | PLAY_SONG(cg_swap_song); | ||
| 657 | } else { | ||
| 658 | PLAY_SONG(cg_norm_song); | ||
| 659 | } | ||
| 660 | #endif | ||
| 661 | break; | ||
| 662 | case MAGIC_TOGGLE_NKRO: | ||
| 663 | keymap_config.nkro = !keymap_config.nkro; | ||
| 664 | break; | ||
| 665 | default: | ||
| 666 | break; | ||
| 667 | } | ||
| 668 | eeconfig_update_keymap(keymap_config.raw); | ||
| 669 | clear_keyboard(); // clear to prevent stuck keys | ||
| 670 | |||
| 671 | return false; | ||
| 672 | } | ||
| 673 | break; | ||
| 674 | |||
| 675 | case GRAVE_ESC: { | ||
| 676 | uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT) | MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))); | ||
| 707 | 677 | ||
| 708 | #ifdef GRAVE_ESC_ALT_OVERRIDE | 678 | #ifdef GRAVE_ESC_ALT_OVERRIDE |
| 709 | // if ALT is pressed, ESC is always sent | 679 | // if ALT is pressed, ESC is always sent |
| 710 | // this is handy for the cmd+opt+esc shortcut on macOS, among other things. | 680 | // this is handy for the cmd+opt+esc shortcut on macOS, among other things. |
| 711 | if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) { | 681 | if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) { |
| 712 | shifted = 0; | 682 | shifted = 0; |
| 713 | } | 683 | } |
| 714 | #endif | 684 | #endif |
| 715 | 685 | ||
| 716 | #ifdef GRAVE_ESC_CTRL_OVERRIDE | 686 | #ifdef GRAVE_ESC_CTRL_OVERRIDE |
| 717 | // if CTRL is pressed, ESC is always sent | 687 | // if CTRL is pressed, ESC is always sent |
| 718 | // this is handy for the ctrl+shift+esc shortcut on windows, among other things. | 688 | // this is handy for the ctrl+shift+esc shortcut on windows, among other things. |
| 719 | if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) { | 689 | if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) { |
| 720 | shifted = 0; | 690 | shifted = 0; |
| 721 | } | 691 | } |
| 722 | #endif | 692 | #endif |
| 723 | 693 | ||
| 724 | #ifdef GRAVE_ESC_GUI_OVERRIDE | 694 | #ifdef GRAVE_ESC_GUI_OVERRIDE |
| 725 | // if GUI is pressed, ESC is always sent | 695 | // if GUI is pressed, ESC is always sent |
| 726 | if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) { | 696 | if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) { |
| 727 | shifted = 0; | 697 | shifted = 0; |
| 728 | } | 698 | } |
| 729 | #endif | 699 | #endif |
| 730 | 700 | ||
| 731 | #ifdef GRAVE_ESC_SHIFT_OVERRIDE | 701 | #ifdef GRAVE_ESC_SHIFT_OVERRIDE |
| 732 | // if SHIFT is pressed, ESC is always sent | 702 | // if SHIFT is pressed, ESC is always sent |
| 733 | if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) { | 703 | if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) { |
| 734 | shifted = 0; | 704 | shifted = 0; |
| 735 | } | 705 | } |
| 736 | #endif | 706 | #endif |
| 737 | 707 | ||
| 738 | if (record->event.pressed) { | 708 | if (record->event.pressed) { |
| 739 | grave_esc_was_shifted = shifted; | 709 | grave_esc_was_shifted = shifted; |
| 740 | add_key(shifted ? KC_GRAVE : KC_ESCAPE); | 710 | add_key(shifted ? KC_GRAVE : KC_ESCAPE); |
| 741 | } | 711 | } else { |
| 742 | else { | 712 | del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE); |
| 743 | del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE); | 713 | } |
| 744 | } | 714 | |
| 745 | 715 | send_keyboard_report(); | |
| 746 | send_keyboard_report(); | 716 | return false; |
| 747 | return false; | 717 | } |
| 748 | } | ||
| 749 | 718 | ||
| 750 | #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING) | 719 | #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING) |
| 751 | case BL_BRTG: { | 720 | case BL_BRTG: { |
| 752 | if (record->event.pressed) { | 721 | if (record->event.pressed) { |
| 753 | backlight_toggle_breathing(); | 722 | backlight_toggle_breathing(); |
| 754 | } | 723 | } |
| 755 | return false; | 724 | return false; |
| 756 | } | 725 | } |
| 757 | #endif | 726 | #endif |
| 758 | } | 727 | } |
| 759 | |||
| 760 | return process_action_kb(record); | ||
| 761 | } | ||
| 762 | 728 | ||
| 763 | __attribute__ ((weak)) | 729 | return process_action_kb(record); |
| 764 | const bool ascii_to_shift_lut[128] PROGMEM = { | ||
| 765 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 766 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 767 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 768 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 769 | |||
| 770 | 0, 1, 1, 1, 1, 1, 1, 0, | ||
| 771 | 1, 1, 1, 1, 0, 0, 0, 0, | ||
| 772 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 773 | 0, 0, 1, 0, 1, 0, 1, 1, | ||
| 774 | 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 775 | 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 776 | 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 777 | 1, 1, 1, 0, 0, 0, 1, 1, | ||
| 778 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 779 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 780 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 781 | 0, 0, 0, 1, 1, 1, 1, 0 | ||
| 782 | }; | ||
| 783 | |||
| 784 | __attribute__ ((weak)) | ||
| 785 | const bool ascii_to_altgr_lut[128] PROGMEM = { | ||
| 786 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 787 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 788 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 789 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 790 | |||
| 791 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 792 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 793 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 794 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 795 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 796 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 797 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 798 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 799 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 800 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 801 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 802 | 0, 0, 0, 0, 0, 0, 0, 0 | ||
| 803 | }; | ||
| 804 | |||
| 805 | __attribute__ ((weak)) | ||
| 806 | const uint8_t ascii_to_keycode_lut[128] PROGMEM = { | ||
| 807 | // NUL SOH STX ETX EOT ENQ ACK BEL | ||
| 808 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
| 809 | // BS TAB LF VT FF CR SO SI | ||
| 810 | KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
| 811 | // DLE DC1 DC2 DC3 DC4 NAK SYN ETB | ||
| 812 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
| 813 | // CAN EM SUB ESC FS GS RS US | ||
| 814 | XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
| 815 | |||
| 816 | // ! " # $ % & ' | ||
| 817 | KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT, | ||
| 818 | // ( ) * + , - . / | ||
| 819 | KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH, | ||
| 820 | // 0 1 2 3 4 5 6 7 | ||
| 821 | KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, | ||
| 822 | // 8 9 : ; < = > ? | ||
| 823 | KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH, | ||
| 824 | // @ A B C D E F G | ||
| 825 | KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, | ||
| 826 | // H I J K L M N O | ||
| 827 | KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, | ||
| 828 | // P Q R S T U V W | ||
| 829 | KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, | ||
| 830 | // X Y Z [ \ ] ^ _ | ||
| 831 | KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS, | ||
| 832 | // ` a b c d e f g | ||
| 833 | KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, | ||
| 834 | // h i j k l m n o | ||
| 835 | KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, | ||
| 836 | // p q r s t u v w | ||
| 837 | KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, | ||
| 838 | // x y z { | } ~ DEL | ||
| 839 | KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL | ||
| 840 | }; | ||
| 841 | |||
| 842 | void send_string(const char *str) { | ||
| 843 | send_string_with_delay(str, 0); | ||
| 844 | } | 730 | } |
| 845 | 731 | ||
| 846 | void send_string_P(const char *str) { | 732 | __attribute__((weak)) const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 847 | send_string_with_delay_P(str, 0); | 733 | |
| 848 | } | 734 | 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}; |
| 735 | |||
| 736 | __attribute__((weak)) const bool ascii_to_altgr_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 737 | |||
| 738 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
| 739 | |||
| 740 | __attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = {// NUL SOH STX ETX EOT ENQ ACK BEL | ||
| 741 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
| 742 | // BS TAB LF VT FF CR SO SI | ||
| 743 | KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
| 744 | // DLE DC1 DC2 DC3 DC4 NAK SYN ETB | ||
| 745 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
| 746 | // CAN EM SUB ESC FS GS RS US | ||
| 747 | XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
| 748 | |||
| 749 | // ! " # $ % & ' | ||
| 750 | KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT, | ||
| 751 | // ( ) * + , - . / | ||
| 752 | KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH, | ||
| 753 | // 0 1 2 3 4 5 6 7 | ||
| 754 | KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, | ||
| 755 | // 8 9 : ; < = > ? | ||
| 756 | KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH, | ||
| 757 | // @ A B C D E F G | ||
| 758 | KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, | ||
| 759 | // H I J K L M N O | ||
| 760 | KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, | ||
| 761 | // P Q R S T U V W | ||
| 762 | KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, | ||
| 763 | // X Y Z [ \ ] ^ _ | ||
| 764 | KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS, | ||
| 765 | // ` a b c d e f g | ||
| 766 | KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, | ||
| 767 | // h i j k l m n o | ||
| 768 | KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, | ||
| 769 | // p q r s t u v w | ||
| 770 | KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, | ||
| 771 | // x y z { | } ~ DEL | ||
| 772 | KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL}; | ||
| 773 | |||
| 774 | void send_string(const char *str) { send_string_with_delay(str, 0); } | ||
| 775 | |||
| 776 | void send_string_P(const char *str) { send_string_with_delay_P(str, 0); } | ||
| 849 | 777 | ||
| 850 | void send_string_with_delay(const char *str, uint8_t interval) { | 778 | void send_string_with_delay(const char *str, uint8_t interval) { |
| 851 | while (1) { | 779 | while (1) { |
| 852 | char ascii_code = *str; | 780 | char ascii_code = *str; |
| 853 | if (!ascii_code) break; | 781 | if (!ascii_code) break; |
| 854 | if (ascii_code == SS_TAP_CODE) { | 782 | if (ascii_code == SS_TAP_CODE) { |
| 855 | // tap | 783 | // tap |
| 856 | uint8_t keycode = *(++str); | 784 | uint8_t keycode = *(++str); |
| 857 | register_code(keycode); | 785 | register_code(keycode); |
| 858 | unregister_code(keycode); | 786 | unregister_code(keycode); |
| 859 | } else if (ascii_code == SS_DOWN_CODE) { | 787 | } else if (ascii_code == SS_DOWN_CODE) { |
| 860 | // down | 788 | // down |
| 861 | uint8_t keycode = *(++str); | 789 | uint8_t keycode = *(++str); |
| 862 | register_code(keycode); | 790 | register_code(keycode); |
| 863 | } else if (ascii_code == SS_UP_CODE) { | 791 | } else if (ascii_code == SS_UP_CODE) { |
| 864 | // up | 792 | // up |
| 865 | uint8_t keycode = *(++str); | 793 | uint8_t keycode = *(++str); |
| 866 | unregister_code(keycode); | 794 | unregister_code(keycode); |
| 867 | } else { | 795 | } else { |
| 868 | send_char(ascii_code); | 796 | send_char(ascii_code); |
| 869 | } | 797 | } |
| 870 | ++str; | 798 | ++str; |
| 871 | // interval | 799 | // interval |
| 872 | { uint8_t ms = interval; while (ms--) wait_ms(1); } | 800 | { |
| 801 | uint8_t ms = interval; | ||
| 802 | while (ms--) wait_ms(1); | ||
| 803 | } | ||
| 873 | } | 804 | } |
| 874 | } | 805 | } |
| 875 | 806 | ||
| @@ -878,201 +809,201 @@ void send_string_with_delay_P(const char *str, uint8_t interval) { | |||
| 878 | char ascii_code = pgm_read_byte(str); | 809 | char ascii_code = pgm_read_byte(str); |
| 879 | if (!ascii_code) break; | 810 | if (!ascii_code) break; |
| 880 | if (ascii_code == SS_TAP_CODE) { | 811 | if (ascii_code == SS_TAP_CODE) { |
| 881 | // tap | 812 | // tap |
| 882 | uint8_t keycode = pgm_read_byte(++str); | 813 | uint8_t keycode = pgm_read_byte(++str); |
| 883 | register_code(keycode); | 814 | register_code(keycode); |
| 884 | unregister_code(keycode); | 815 | unregister_code(keycode); |
| 885 | } else if (ascii_code == SS_DOWN_CODE) { | 816 | } else if (ascii_code == SS_DOWN_CODE) { |
| 886 | // down | 817 | // down |
| 887 | uint8_t keycode = pgm_read_byte(++str); | 818 | uint8_t keycode = pgm_read_byte(++str); |
| 888 | register_code(keycode); | 819 | register_code(keycode); |
| 889 | } else if (ascii_code == SS_UP_CODE) { | 820 | } else if (ascii_code == SS_UP_CODE) { |
| 890 | // up | 821 | // up |
| 891 | uint8_t keycode = pgm_read_byte(++str); | 822 | uint8_t keycode = pgm_read_byte(++str); |
| 892 | unregister_code(keycode); | 823 | unregister_code(keycode); |
| 893 | } else { | 824 | } else { |
| 894 | send_char(ascii_code); | 825 | send_char(ascii_code); |
| 895 | } | 826 | } |
| 896 | ++str; | 827 | ++str; |
| 897 | // interval | 828 | // interval |
| 898 | { uint8_t ms = interval; while (ms--) wait_ms(1); } | 829 | { |
| 830 | uint8_t ms = interval; | ||
| 831 | while (ms--) wait_ms(1); | ||
| 832 | } | ||
| 899 | } | 833 | } |
| 900 | } | 834 | } |
| 901 | 835 | ||
| 902 | void send_char(char ascii_code) { | 836 | void send_char(char ascii_code) { |
| 903 | uint8_t keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]); | 837 | uint8_t keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]); |
| 904 | bool is_shifted = pgm_read_byte(&ascii_to_shift_lut[(uint8_t)ascii_code]); | 838 | bool is_shifted = pgm_read_byte(&ascii_to_shift_lut[(uint8_t)ascii_code]); |
| 905 | bool is_altgred = pgm_read_byte(&ascii_to_altgr_lut[(uint8_t)ascii_code]); | 839 | bool is_altgred = pgm_read_byte(&ascii_to_altgr_lut[(uint8_t)ascii_code]); |
| 906 | 840 | ||
| 907 | if (is_shifted) { | 841 | if (is_shifted) { |
| 908 | register_code(KC_LSFT); | 842 | register_code(KC_LSFT); |
| 909 | } | 843 | } |
| 910 | if (is_altgred) { | 844 | if (is_altgred) { |
| 911 | register_code(KC_RALT); | 845 | register_code(KC_RALT); |
| 912 | } | 846 | } |
| 913 | tap_code(keycode); | 847 | tap_code(keycode); |
| 914 | if (is_altgred) { | 848 | if (is_altgred) { |
| 915 | unregister_code(KC_RALT); | 849 | unregister_code(KC_RALT); |
| 916 | } | 850 | } |
| 917 | if (is_shifted) { | 851 | if (is_shifted) { |
| 918 | unregister_code(KC_LSFT); | 852 | unregister_code(KC_LSFT); |
| 919 | } | 853 | } |
| 920 | } | 854 | } |
| 921 | 855 | ||
| 922 | void set_single_persistent_default_layer(uint8_t default_layer) { | 856 | void set_single_persistent_default_layer(uint8_t default_layer) { |
| 923 | #if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS) | 857 | #if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS) |
| 924 | PLAY_SONG(default_layer_songs[default_layer]); | 858 | PLAY_SONG(default_layer_songs[default_layer]); |
| 925 | #endif | 859 | #endif |
| 926 | eeconfig_update_default_layer(1U<<default_layer); | 860 | eeconfig_update_default_layer(1U << default_layer); |
| 927 | default_layer_set(1U<<default_layer); | 861 | default_layer_set(1U << default_layer); |
| 928 | } | 862 | } |
| 929 | 863 | ||
| 930 | layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3) { | 864 | layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3) { |
| 931 | layer_state_t mask12 = (1UL << layer1) | (1UL << layer2); | 865 | layer_state_t mask12 = (1UL << layer1) | (1UL << layer2); |
| 932 | layer_state_t mask3 = 1UL << layer3; | 866 | layer_state_t mask3 = 1UL << layer3; |
| 933 | return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3); | 867 | return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3); |
| 934 | } | 868 | } |
| 935 | 869 | ||
| 936 | void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { | 870 | void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3)); } |
| 937 | layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3)); | ||
| 938 | } | ||
| 939 | 871 | ||
| 940 | void tap_random_base64(void) { | 872 | void tap_random_base64(void) { |
| 941 | #if defined(__AVR_ATmega32U4__) | 873 | #if defined(__AVR_ATmega32U4__) |
| 942 | uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64; | 874 | uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64; |
| 943 | #else | 875 | #else |
| 944 | uint8_t key = rand() % 64; | 876 | uint8_t key = rand() % 64; |
| 945 | #endif | 877 | #endif |
| 946 | switch (key) { | 878 | switch (key) { |
| 947 | case 0 ... 25: | 879 | case 0 ... 25: |
| 948 | register_code(KC_LSFT); | 880 | register_code(KC_LSFT); |
| 949 | register_code(key + KC_A); | 881 | register_code(key + KC_A); |
| 950 | unregister_code(key + KC_A); | 882 | unregister_code(key + KC_A); |
| 951 | unregister_code(KC_LSFT); | 883 | unregister_code(KC_LSFT); |
| 952 | break; | 884 | break; |
| 953 | case 26 ... 51: | 885 | case 26 ... 51: |
| 954 | register_code(key - 26 + KC_A); | 886 | register_code(key - 26 + KC_A); |
| 955 | unregister_code(key - 26 + KC_A); | 887 | unregister_code(key - 26 + KC_A); |
| 956 | break; | 888 | break; |
| 957 | case 52: | 889 | case 52: |
| 958 | register_code(KC_0); | 890 | register_code(KC_0); |
| 959 | unregister_code(KC_0); | 891 | unregister_code(KC_0); |
| 960 | break; | 892 | break; |
| 961 | case 53 ... 61: | 893 | case 53 ... 61: |
| 962 | register_code(key - 53 + KC_1); | 894 | register_code(key - 53 + KC_1); |
| 963 | unregister_code(key - 53 + KC_1); | 895 | unregister_code(key - 53 + KC_1); |
| 964 | break; | 896 | break; |
| 965 | case 62: | 897 | case 62: |
| 966 | register_code(KC_LSFT); | 898 | register_code(KC_LSFT); |
| 967 | register_code(KC_EQL); | 899 | register_code(KC_EQL); |
| 968 | unregister_code(KC_EQL); | 900 | unregister_code(KC_EQL); |
| 969 | unregister_code(KC_LSFT); | 901 | unregister_code(KC_LSFT); |
| 970 | break; | 902 | break; |
| 971 | case 63: | 903 | case 63: |
| 972 | register_code(KC_SLSH); | 904 | register_code(KC_SLSH); |
| 973 | unregister_code(KC_SLSH); | 905 | unregister_code(KC_SLSH); |
| 974 | break; | 906 | break; |
| 975 | } | 907 | } |
| 976 | } | 908 | } |
| 977 | 909 | ||
| 978 | __attribute__((weak)) | 910 | __attribute__((weak)) void bootmagic_lite(void) { |
| 979 | void bootmagic_lite(void) { | 911 | // The lite version of TMK's bootmagic based on Wilba. |
| 980 | // The lite version of TMK's bootmagic based on Wilba. | 912 | // 100% less potential for accidentally making the |
| 981 | // 100% less potential for accidentally making the | 913 | // keyboard do stupid things. |
| 982 | // keyboard do stupid things. | ||
| 983 | 914 | ||
| 984 | // We need multiple scans because debouncing can't be turned off. | 915 | // We need multiple scans because debouncing can't be turned off. |
| 985 | matrix_scan(); | 916 | matrix_scan(); |
| 986 | #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0 | 917 | #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0 |
| 987 | wait_ms(DEBOUNCING_DELAY * 2); | 918 | wait_ms(DEBOUNCING_DELAY * 2); |
| 988 | #elif defined(DEBOUNCE) && DEBOUNCE > 0 | 919 | #elif defined(DEBOUNCE) && DEBOUNCE > 0 |
| 989 | wait_ms(DEBOUNCE * 2); | 920 | wait_ms(DEBOUNCE * 2); |
| 990 | #else | 921 | #else |
| 991 | wait_ms(30); | 922 | wait_ms(30); |
| 992 | #endif | 923 | #endif |
| 993 | matrix_scan(); | 924 | matrix_scan(); |
| 994 | 925 | ||
| 995 | // If the Esc and space bar are held down on power up, | 926 | // If the Esc and space bar are held down on power up, |
| 996 | // reset the EEPROM valid state and jump to bootloader. | 927 | // reset the EEPROM valid state and jump to bootloader. |
| 997 | // Assumes Esc is at [0,0]. | 928 | // Assumes Esc is at [0,0]. |
| 998 | // This isn't very generalized, but we need something that doesn't | 929 | // This isn't very generalized, but we need something that doesn't |
| 999 | // rely on user's keymaps in firmware or EEPROM. | 930 | // rely on user's keymaps in firmware or EEPROM. |
| 1000 | if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) { | 931 | if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) { |
| 1001 | eeconfig_disable(); | 932 | eeconfig_disable(); |
| 1002 | // Jump to bootloader. | 933 | // Jump to bootloader. |
| 1003 | bootloader_jump(); | 934 | bootloader_jump(); |
| 1004 | } | 935 | } |
| 1005 | } | 936 | } |
| 1006 | 937 | ||
| 1007 | void matrix_init_quantum() { | 938 | void matrix_init_quantum() { |
| 1008 | #ifdef BOOTMAGIC_LITE | 939 | #ifdef BOOTMAGIC_LITE |
| 1009 | bootmagic_lite(); | 940 | bootmagic_lite(); |
| 1010 | #endif | 941 | #endif |
| 1011 | if (!eeconfig_is_enabled()) { | 942 | if (!eeconfig_is_enabled()) { |
| 1012 | eeconfig_init(); | 943 | eeconfig_init(); |
| 1013 | } | 944 | } |
| 1014 | #ifdef BACKLIGHT_ENABLE | 945 | #ifdef BACKLIGHT_ENABLE |
| 1015 | #ifdef LED_MATRIX_ENABLE | 946 | # ifdef LED_MATRIX_ENABLE |
| 1016 | led_matrix_init(); | 947 | led_matrix_init(); |
| 1017 | #else | 948 | # else |
| 1018 | backlight_init_ports(); | 949 | backlight_init_ports(); |
| 1019 | #endif | 950 | # endif |
| 1020 | #endif | 951 | #endif |
| 1021 | #ifdef AUDIO_ENABLE | 952 | #ifdef AUDIO_ENABLE |
| 1022 | audio_init(); | 953 | audio_init(); |
| 1023 | #endif | 954 | #endif |
| 1024 | #ifdef RGB_MATRIX_ENABLE | 955 | #ifdef RGB_MATRIX_ENABLE |
| 1025 | rgb_matrix_init(); | 956 | rgb_matrix_init(); |
| 1026 | #endif | 957 | #endif |
| 1027 | #ifdef ENCODER_ENABLE | 958 | #ifdef ENCODER_ENABLE |
| 1028 | encoder_init(); | 959 | encoder_init(); |
| 1029 | #endif | 960 | #endif |
| 1030 | #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) | 961 | #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) |
| 1031 | unicode_input_mode_init(); | 962 | unicode_input_mode_init(); |
| 1032 | #endif | 963 | #endif |
| 1033 | #ifdef HAPTIC_ENABLE | 964 | #ifdef HAPTIC_ENABLE |
| 1034 | haptic_init(); | 965 | haptic_init(); |
| 1035 | #endif | 966 | #endif |
| 1036 | #ifdef OUTPUT_AUTO_ENABLE | 967 | #ifdef OUTPUT_AUTO_ENABLE |
| 1037 | set_output(OUTPUT_AUTO); | 968 | set_output(OUTPUT_AUTO); |
| 1038 | #endif | 969 | #endif |
| 1039 | matrix_init_kb(); | 970 | matrix_init_kb(); |
| 1040 | } | 971 | } |
| 1041 | 972 | ||
| 1042 | void matrix_scan_quantum() { | 973 | void matrix_scan_quantum() { |
| 1043 | #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) | 974 | #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) |
| 1044 | matrix_scan_music(); | 975 | matrix_scan_music(); |
| 1045 | #endif | 976 | #endif |
| 1046 | 977 | ||
| 1047 | #ifdef TAP_DANCE_ENABLE | 978 | #ifdef TAP_DANCE_ENABLE |
| 1048 | matrix_scan_tap_dance(); | 979 | matrix_scan_tap_dance(); |
| 1049 | #endif | 980 | #endif |
| 1050 | 981 | ||
| 1051 | #ifdef COMBO_ENABLE | 982 | #ifdef COMBO_ENABLE |
| 1052 | matrix_scan_combo(); | 983 | matrix_scan_combo(); |
| 1053 | #endif | 984 | #endif |
| 1054 | 985 | ||
| 1055 | #if defined(BACKLIGHT_ENABLE) | 986 | #if defined(BACKLIGHT_ENABLE) |
| 1056 | #if defined(LED_MATRIX_ENABLE) | 987 | # if defined(LED_MATRIX_ENABLE) |
| 1057 | led_matrix_task(); | 988 | led_matrix_task(); |
| 1058 | #elif defined(BACKLIGHT_PIN) | 989 | # elif defined(BACKLIGHT_PIN) |
| 1059 | backlight_task(); | 990 | backlight_task(); |
| 1060 | #endif | 991 | # endif |
| 1061 | #endif | 992 | #endif |
| 1062 | 993 | ||
| 1063 | #ifdef RGB_MATRIX_ENABLE | 994 | #ifdef RGB_MATRIX_ENABLE |
| 1064 | rgb_matrix_task(); | 995 | rgb_matrix_task(); |
| 1065 | #endif | 996 | #endif |
| 1066 | 997 | ||
| 1067 | #ifdef ENCODER_ENABLE | 998 | #ifdef ENCODER_ENABLE |
| 1068 | encoder_read(); | 999 | encoder_read(); |
| 1069 | #endif | 1000 | #endif |
| 1070 | 1001 | ||
| 1071 | #ifdef HAPTIC_ENABLE | 1002 | #ifdef HAPTIC_ENABLE |
| 1072 | haptic_task(); | 1003 | haptic_task(); |
| 1073 | #endif | 1004 | #endif |
| 1074 | 1005 | ||
| 1075 | matrix_scan_kb(); | 1006 | matrix_scan_kb(); |
| 1076 | } | 1007 | } |
| 1077 | #if defined(BACKLIGHT_ENABLE) && (defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS)) | 1008 | #if defined(BACKLIGHT_ENABLE) && (defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS)) |
| 1078 | 1009 | ||
| @@ -1084,241 +1015,219 @@ void matrix_scan_quantum() { | |||
| 1084 | // depends on the Audio setup (Audio wins over Backlight). | 1015 | // depends on the Audio setup (Audio wins over Backlight). |
| 1085 | // 3. Full software PWM, driven by the matrix scan, if both timers are used by Audio. | 1016 | // 3. Full software PWM, driven by the matrix scan, if both timers are used by Audio. |
| 1086 | 1017 | ||
| 1087 | #if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) \ | 1018 | # if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) && (BACKLIGHT_PIN == B5 || BACKLIGHT_PIN == B6 || BACKLIGHT_PIN == B7) |
| 1088 | || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) \ | 1019 | # define HARDWARE_PWM |
| 1089 | || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) \ | 1020 | # define ICRx ICR1 |
| 1090 | && (BACKLIGHT_PIN == B5 || BACKLIGHT_PIN == B6 || BACKLIGHT_PIN == B7) | 1021 | # define TCCRxA TCCR1A |
| 1091 | #define HARDWARE_PWM | 1022 | # define TCCRxB TCCR1B |
| 1092 | #define ICRx ICR1 | 1023 | # define TIMERx_OVF_vect TIMER1_OVF_vect |
| 1093 | #define TCCRxA TCCR1A | 1024 | # define TIMSKx TIMSK1 |
| 1094 | #define TCCRxB TCCR1B | 1025 | # define TOIEx TOIE1 |
| 1095 | #define TIMERx_OVF_vect TIMER1_OVF_vect | 1026 | |
| 1096 | #define TIMSKx TIMSK1 | 1027 | # if BACKLIGHT_PIN == B5 |
| 1097 | #define TOIEx TOIE1 | 1028 | # define COMxx1 COM1A1 |
| 1098 | 1029 | # define OCRxx OCR1A | |
| 1099 | #if BACKLIGHT_PIN == B5 | 1030 | # elif BACKLIGHT_PIN == B6 |
| 1100 | #define COMxx1 COM1A1 | 1031 | # define COMxx1 COM1B1 |
| 1101 | #define OCRxx OCR1A | 1032 | # define OCRxx OCR1B |
| 1102 | #elif BACKLIGHT_PIN == B6 | 1033 | # elif BACKLIGHT_PIN == B7 |
| 1103 | #define COMxx1 COM1B1 | 1034 | # define COMxx1 COM1C1 |
| 1104 | #define OCRxx OCR1B | 1035 | # define OCRxx OCR1C |
| 1105 | #elif BACKLIGHT_PIN == B7 | 1036 | # endif |
| 1106 | #define COMxx1 COM1C1 | 1037 | # elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) && (BACKLIGHT_PIN == C4 || BACKLIGHT_PIN == C5 || BACKLIGHT_PIN == C6) |
| 1107 | #define OCRxx OCR1C | 1038 | # define HARDWARE_PWM |
| 1108 | #endif | 1039 | # define ICRx ICR3 |
| 1109 | #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) \ | 1040 | # define TCCRxA TCCR3A |
| 1110 | || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) \ | 1041 | # define TCCRxB TCCR3B |
| 1111 | || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) \ | 1042 | # define TIMERx_OVF_vect TIMER3_OVF_vect |
| 1112 | && (BACKLIGHT_PIN == C4 || BACKLIGHT_PIN == C5 || BACKLIGHT_PIN == C6) | 1043 | # define TIMSKx TIMSK3 |
| 1113 | #define HARDWARE_PWM | 1044 | # define TOIEx TOIE3 |
| 1114 | #define ICRx ICR3 | 1045 | |
| 1115 | #define TCCRxA TCCR3A | 1046 | # if BACKLIGHT_PIN == C4 |
| 1116 | #define TCCRxB TCCR3B | 1047 | # if (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) |
| 1117 | #define TIMERx_OVF_vect TIMER3_OVF_vect | 1048 | # error This MCU has no C4 pin! |
| 1118 | #define TIMSKx TIMSK3 | 1049 | # else |
| 1119 | #define TOIEx TOIE3 | 1050 | # define COMxx1 COM3C1 |
| 1120 | 1051 | # define OCRxx OCR3C | |
| 1121 | #if BACKLIGHT_PIN == C4 | 1052 | # endif |
| 1122 | #if (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) | 1053 | # elif BACKLIGHT_PIN == C5 |
| 1123 | #error This MCU has no C4 pin! | 1054 | # if (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) |
| 1124 | #else | 1055 | # error This MCU has no C5 pin! |
| 1125 | #define COMxx1 COM3C1 | 1056 | # else |
| 1126 | #define OCRxx OCR3C | 1057 | # define COMxx1 COM3B1 |
| 1127 | #endif | 1058 | # define OCRxx OCR3B |
| 1128 | #elif BACKLIGHT_PIN == C5 | 1059 | # endif |
| 1129 | #if (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) | 1060 | # elif BACKLIGHT_PIN == C6 |
| 1130 | #error This MCU has no C5 pin! | 1061 | # define COMxx1 COM3A1 |
| 1131 | #else | 1062 | # define OCRxx OCR3A |
| 1132 | #define COMxx1 COM3B1 | 1063 | # endif |
| 1133 | #define OCRxx OCR3B | 1064 | # elif (defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__)) && (BACKLIGHT_PIN == B7 || BACKLIGHT_PIN == C5 || BACKLIGHT_PIN == C6) |
| 1134 | #endif | 1065 | # define HARDWARE_PWM |
| 1135 | #elif BACKLIGHT_PIN == C6 | 1066 | # define ICRx ICR1 |
| 1136 | #define COMxx1 COM3A1 | 1067 | # define TCCRxA TCCR1A |
| 1137 | #define OCRxx OCR3A | 1068 | # define TCCRxB TCCR1B |
| 1138 | #endif | 1069 | # define TIMERx_OVF_vect TIMER1_OVF_vect |
| 1139 | #elif (defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__)) \ | 1070 | # define TIMSKx TIMSK1 |
| 1140 | && (BACKLIGHT_PIN == B7 || BACKLIGHT_PIN == C5 || BACKLIGHT_PIN == C6) | 1071 | # define TOIEx TOIE1 |
| 1141 | #define HARDWARE_PWM | 1072 | |
| 1142 | #define ICRx ICR1 | 1073 | # if BACKLIGHT_PIN == B7 |
| 1143 | #define TCCRxA TCCR1A | 1074 | # define COMxx1 COM1C1 |
| 1144 | #define TCCRxB TCCR1B | 1075 | # define OCRxx OCR1C |
| 1145 | #define TIMERx_OVF_vect TIMER1_OVF_vect | 1076 | # elif BACKLIGHT_PIN == C5 |
| 1146 | #define TIMSKx TIMSK1 | 1077 | # define COMxx1 COM1B1 |
| 1147 | #define TOIEx TOIE1 | 1078 | # define OCRxx OCR1B |
| 1148 | 1079 | # elif BACKLIGHT_PIN == C6 | |
| 1149 | #if BACKLIGHT_PIN == B7 | 1080 | # define COMxx1 COM1A1 |
| 1150 | #define COMxx1 COM1C1 | 1081 | # define OCRxx OCR1A |
| 1151 | #define OCRxx OCR1C | 1082 | # endif |
| 1152 | #elif BACKLIGHT_PIN == C5 | 1083 | # elif defined(__AVR_ATmega32A__) && (BACKLIGHT_PIN == D4 || BACKLIGHT_PIN == D5) |
| 1153 | #define COMxx1 COM1B1 | 1084 | # define HARDWARE_PWM |
| 1154 | #define OCRxx OCR1B | 1085 | # define ICRx ICR1 |
| 1155 | #elif BACKLIGHT_PIN == C6 | 1086 | # define TCCRxA TCCR1A |
| 1156 | #define COMxx1 COM1A1 | 1087 | # define TCCRxB TCCR1B |
| 1157 | #define OCRxx OCR1A | 1088 | # define TIMERx_OVF_vect TIMER1_OVF_vect |
| 1158 | #endif | 1089 | # define TIMSKx TIMSK |
| 1159 | #elif defined(__AVR_ATmega32A__) \ | 1090 | # define TOIEx TOIE1 |
| 1160 | && (BACKLIGHT_PIN == D4 || BACKLIGHT_PIN == D5) | 1091 | |
| 1161 | #define HARDWARE_PWM | 1092 | # if BACKLIGHT_PIN == D4 |
| 1162 | #define ICRx ICR1 | 1093 | # define COMxx1 COM1B1 |
| 1163 | #define TCCRxA TCCR1A | 1094 | # define OCRxx OCR1B |
| 1164 | #define TCCRxB TCCR1B | 1095 | # elif BACKLIGHT_PIN == D5 |
| 1165 | #define TIMERx_OVF_vect TIMER1_OVF_vect | 1096 | # define COMxx1 COM1A1 |
| 1166 | #define TIMSKx TIMSK | 1097 | # define OCRxx OCR1A |
| 1167 | #define TOIEx TOIE1 | 1098 | # endif |
| 1168 | 1099 | # else | |
| 1169 | #if BACKLIGHT_PIN == D4 | 1100 | # if !defined(BACKLIGHT_CUSTOM_DRIVER) |
| 1170 | #define COMxx1 COM1B1 | 1101 | # if !defined(B5_AUDIO) && !defined(B6_AUDIO) && !defined(B7_AUDIO) |
| 1171 | #define OCRxx OCR1B | 1102 | // Timer 1 is not in use by Audio feature, Backlight can use it |
| 1172 | #elif BACKLIGHT_PIN == D5 | 1103 | # pragma message "Using hardware timer 1 with software PWM" |
| 1173 | #define COMxx1 COM1A1 | 1104 | # define HARDWARE_PWM |
| 1174 | #define OCRxx OCR1A | 1105 | # define BACKLIGHT_PWM_TIMER |
| 1175 | #endif | 1106 | # define ICRx ICR1 |
| 1176 | #else | 1107 | # define TCCRxA TCCR1A |
| 1177 | #if !defined(BACKLIGHT_CUSTOM_DRIVER) | 1108 | # define TCCRxB TCCR1B |
| 1178 | #if !defined(B5_AUDIO) && !defined(B6_AUDIO) && !defined(B7_AUDIO) | 1109 | # define TIMERx_COMPA_vect TIMER1_COMPA_vect |
| 1179 | // Timer 1 is not in use by Audio feature, Backlight can use it | 1110 | # define TIMERx_OVF_vect TIMER1_OVF_vect |
| 1180 | #pragma message "Using hardware timer 1 with software PWM" | 1111 | # if defined(__AVR_ATmega32A__) // This MCU has only one TIMSK register |
| 1181 | #define HARDWARE_PWM | 1112 | # define TIMSKx TIMSK |
| 1182 | #define BACKLIGHT_PWM_TIMER | 1113 | # else |
| 1183 | #define ICRx ICR1 | 1114 | # define TIMSKx TIMSK1 |
| 1184 | #define TCCRxA TCCR1A | 1115 | # endif |
| 1185 | #define TCCRxB TCCR1B | 1116 | # define TOIEx TOIE1 |
| 1186 | #define TIMERx_COMPA_vect TIMER1_COMPA_vect | 1117 | |
| 1187 | #define TIMERx_OVF_vect TIMER1_OVF_vect | 1118 | # define OCIExA OCIE1A |
| 1188 | #if defined(__AVR_ATmega32A__) // This MCU has only one TIMSK register | 1119 | # define OCRxx OCR1A |
| 1189 | #define TIMSKx TIMSK | 1120 | # elif !defined(C6_AUDIO) && !defined(C5_AUDIO) && !defined(C4_AUDIO) |
| 1190 | #else | 1121 | # pragma message "Using hardware timer 3 with software PWM" |
| 1191 | #define TIMSKx TIMSK1 | 1122 | // Timer 3 is not in use by Audio feature, Backlight can use it |
| 1192 | #endif | 1123 | # define HARDWARE_PWM |
| 1193 | #define TOIEx TOIE1 | 1124 | # define BACKLIGHT_PWM_TIMER |
| 1194 | 1125 | # define ICRx ICR1 | |
| 1195 | #define OCIExA OCIE1A | 1126 | # define TCCRxA TCCR3A |
| 1196 | #define OCRxx OCR1A | 1127 | # define TCCRxB TCCR3B |
| 1197 | #elif !defined(C6_AUDIO) && !defined(C5_AUDIO) && !defined(C4_AUDIO) | 1128 | # define TIMERx_COMPA_vect TIMER3_COMPA_vect |
| 1198 | #pragma message "Using hardware timer 3 with software PWM" | 1129 | # define TIMERx_OVF_vect TIMER3_OVF_vect |
| 1199 | // Timer 3 is not in use by Audio feature, Backlight can use it | 1130 | # define TIMSKx TIMSK3 |
| 1200 | #define HARDWARE_PWM | 1131 | # define TOIEx TOIE3 |
| 1201 | #define BACKLIGHT_PWM_TIMER | 1132 | |
| 1202 | #define ICRx ICR1 | 1133 | # define OCIExA OCIE3A |
| 1203 | #define TCCRxA TCCR3A | 1134 | # define OCRxx OCR3A |
| 1204 | #define TCCRxB TCCR3B | 1135 | # else |
| 1205 | #define TIMERx_COMPA_vect TIMER3_COMPA_vect | 1136 | # pragma message "Audio in use - using pure software PWM" |
| 1206 | #define TIMERx_OVF_vect TIMER3_OVF_vect | 1137 | # define NO_HARDWARE_PWM |
| 1207 | #define TIMSKx TIMSK3 | 1138 | # endif |
| 1208 | #define TOIEx TOIE3 | 1139 | # else |
| 1209 | 1140 | # pragma message "Custom driver defined - using pure software PWM" | |
| 1210 | #define OCIExA OCIE3A | 1141 | # define NO_HARDWARE_PWM |
| 1211 | #define OCRxx OCR3A | 1142 | # endif |
| 1212 | #else | 1143 | # endif |
| 1213 | #pragma message "Audio in use - using pure software PWM" | 1144 | |
| 1214 | #define NO_HARDWARE_PWM | 1145 | # ifndef BACKLIGHT_ON_STATE |
| 1215 | #endif | 1146 | # define BACKLIGHT_ON_STATE 0 |
| 1216 | #else | 1147 | # endif |
| 1217 | #pragma message "Custom driver defined - using pure software PWM" | ||
| 1218 | #define NO_HARDWARE_PWM | ||
| 1219 | #endif | ||
| 1220 | #endif | ||
| 1221 | |||
| 1222 | #ifndef BACKLIGHT_ON_STATE | ||
| 1223 | #define BACKLIGHT_ON_STATE 0 | ||
| 1224 | #endif | ||
| 1225 | 1148 | ||
| 1226 | void backlight_on(uint8_t backlight_pin) { | 1149 | void backlight_on(uint8_t backlight_pin) { |
| 1227 | #if BACKLIGHT_ON_STATE == 0 | 1150 | # if BACKLIGHT_ON_STATE == 0 |
| 1228 | writePinLow(backlight_pin); | 1151 | writePinLow(backlight_pin); |
| 1229 | #else | 1152 | # else |
| 1230 | writePinHigh(backlight_pin); | 1153 | writePinHigh(backlight_pin); |
| 1231 | #endif | 1154 | # endif |
| 1232 | } | 1155 | } |
| 1233 | 1156 | ||
| 1234 | void backlight_off(uint8_t backlight_pin) { | 1157 | void backlight_off(uint8_t backlight_pin) { |
| 1235 | #if BACKLIGHT_ON_STATE == 0 | 1158 | # if BACKLIGHT_ON_STATE == 0 |
| 1236 | writePinHigh(backlight_pin); | 1159 | writePinHigh(backlight_pin); |
| 1237 | #else | 1160 | # else |
| 1238 | writePinLow(backlight_pin); | 1161 | writePinLow(backlight_pin); |
| 1239 | #endif | 1162 | # endif |
| 1240 | } | 1163 | } |
| 1241 | 1164 | ||
| 1242 | 1165 | # if defined(NO_HARDWARE_PWM) || defined(BACKLIGHT_PWM_TIMER) // pwm through software | |
| 1243 | #if defined(NO_HARDWARE_PWM) || defined(BACKLIGHT_PWM_TIMER) // pwm through software | ||
| 1244 | 1166 | ||
| 1245 | // we support multiple backlight pins | 1167 | // we support multiple backlight pins |
| 1246 | #ifndef BACKLIGHT_LED_COUNT | 1168 | # ifndef BACKLIGHT_LED_COUNT |
| 1247 | #define BACKLIGHT_LED_COUNT 1 | 1169 | # define BACKLIGHT_LED_COUNT 1 |
| 1248 | #endif | 1170 | # endif |
| 1249 | 1171 | ||
| 1250 | #if BACKLIGHT_LED_COUNT == 1 | 1172 | # if BACKLIGHT_LED_COUNT == 1 |
| 1251 | #define BACKLIGHT_PIN_INIT { BACKLIGHT_PIN } | 1173 | # define BACKLIGHT_PIN_INIT \ |
| 1252 | #else | 1174 | { BACKLIGHT_PIN } |
| 1253 | #define BACKLIGHT_PIN_INIT BACKLIGHT_PINS | 1175 | # else |
| 1254 | #endif | 1176 | # define BACKLIGHT_PIN_INIT BACKLIGHT_PINS |
| 1255 | 1177 | # endif | |
| 1256 | #define FOR_EACH_LED(x) \ | 1178 | |
| 1257 | for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) \ | 1179 | # define FOR_EACH_LED(x) \ |
| 1258 | { \ | 1180 | for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \ |
| 1259 | uint8_t backlight_pin = backlight_pins[i]; \ | 1181 | uint8_t backlight_pin = backlight_pins[i]; \ |
| 1260 | { \ | 1182 | { x } \ |
| 1261 | x \ | 1183 | } |
| 1262 | } \ | ||
| 1263 | } | ||
| 1264 | 1184 | ||
| 1265 | static const uint8_t backlight_pins[BACKLIGHT_LED_COUNT] = BACKLIGHT_PIN_INIT; | 1185 | static const uint8_t backlight_pins[BACKLIGHT_LED_COUNT] = BACKLIGHT_PIN_INIT; |
| 1266 | 1186 | ||
| 1267 | #else // full hardware PWM | 1187 | # else // full hardware PWM |
| 1268 | 1188 | ||
| 1269 | // we support only one backlight pin | 1189 | // we support only one backlight pin |
| 1270 | static const uint8_t backlight_pin = BACKLIGHT_PIN; | 1190 | static const uint8_t backlight_pin = BACKLIGHT_PIN; |
| 1271 | #define FOR_EACH_LED(x) x | 1191 | # define FOR_EACH_LED(x) x |
| 1272 | 1192 | ||
| 1273 | #endif | 1193 | # endif |
| 1274 | 1194 | ||
| 1275 | #ifdef NO_HARDWARE_PWM | 1195 | # ifdef NO_HARDWARE_PWM |
| 1276 | __attribute__((weak)) | 1196 | __attribute__((weak)) void backlight_init_ports(void) { |
| 1277 | void backlight_init_ports(void) | 1197 | // Setup backlight pin as output and output to on state. |
| 1278 | { | 1198 | FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) |
| 1279 | // Setup backlight pin as output and output to on state. | 1199 | |
| 1280 | FOR_EACH_LED( | 1200 | # ifdef BACKLIGHT_BREATHING |
| 1281 | setPinOutput(backlight_pin); | 1201 | if (is_backlight_breathing()) { |
| 1282 | backlight_on(backlight_pin); | 1202 | breathing_enable(); |
| 1283 | ) | 1203 | } |
| 1284 | 1204 | # endif | |
| 1285 | #ifdef BACKLIGHT_BREATHING | ||
| 1286 | if (is_backlight_breathing()) { | ||
| 1287 | breathing_enable(); | ||
| 1288 | } | ||
| 1289 | #endif | ||
| 1290 | } | 1205 | } |
| 1291 | 1206 | ||
| 1292 | __attribute__ ((weak)) | 1207 | __attribute__((weak)) void backlight_set(uint8_t level) {} |
| 1293 | void backlight_set(uint8_t level) {} | ||
| 1294 | 1208 | ||
| 1295 | uint8_t backlight_tick = 0; | 1209 | uint8_t backlight_tick = 0; |
| 1296 | 1210 | ||
| 1297 | #ifndef BACKLIGHT_CUSTOM_DRIVER | 1211 | # ifndef BACKLIGHT_CUSTOM_DRIVER |
| 1298 | void backlight_task(void) { | 1212 | void backlight_task(void) { |
| 1299 | if ((0xFFFF >> ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) { | 1213 | if ((0xFFFF >> ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) { |
| 1300 | FOR_EACH_LED( | 1214 | FOR_EACH_LED(backlight_on(backlight_pin);) |
| 1301 | backlight_on(backlight_pin); | 1215 | } else { |
| 1302 | ) | 1216 | FOR_EACH_LED(backlight_off(backlight_pin);) |
| 1303 | } | 1217 | } |
| 1304 | else { | 1218 | backlight_tick = (backlight_tick + 1) % 16; |
| 1305 | FOR_EACH_LED( | ||
| 1306 | backlight_off(backlight_pin); | ||
| 1307 | ) | ||
| 1308 | } | ||
| 1309 | backlight_tick = (backlight_tick + 1) % 16; | ||
| 1310 | } | 1219 | } |
| 1311 | #endif | 1220 | # endif |
| 1312 | 1221 | ||
| 1313 | #ifdef BACKLIGHT_BREATHING | 1222 | # ifdef BACKLIGHT_BREATHING |
| 1314 | #ifndef BACKLIGHT_CUSTOM_DRIVER | 1223 | # ifndef BACKLIGHT_CUSTOM_DRIVER |
| 1315 | #error "Backlight breathing only available with hardware PWM. Please disable." | 1224 | # error "Backlight breathing only available with hardware PWM. Please disable." |
| 1316 | #endif | 1225 | # endif |
| 1317 | #endif | 1226 | # endif |
| 1318 | 1227 | ||
| 1319 | #else // hardware pwm through timer | 1228 | # else // hardware pwm through timer |
| 1320 | 1229 | ||
| 1321 | #ifdef BACKLIGHT_PWM_TIMER | 1230 | # ifdef BACKLIGHT_PWM_TIMER |
| 1322 | 1231 | ||
| 1323 | // The idea of software PWM assisted by hardware timers is the following | 1232 | // The idea of software PWM assisted by hardware timers is the following |
| 1324 | // we use the hardware timer in fast PWM mode like for hardware PWM, but | 1233 | // we use the hardware timer in fast PWM mode like for hardware PWM, but |
| @@ -1334,189 +1243,177 @@ void backlight_task(void) { | |||
| 1334 | // The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz. | 1243 | // The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz. |
| 1335 | 1244 | ||
| 1336 | // Triggered when the counter reaches the OCRx value | 1245 | // Triggered when the counter reaches the OCRx value |
| 1337 | ISR(TIMERx_COMPA_vect) { | 1246 | ISR(TIMERx_COMPA_vect) { FOR_EACH_LED(backlight_off(backlight_pin);) } |
| 1338 | FOR_EACH_LED( | ||
| 1339 | backlight_off(backlight_pin); | ||
| 1340 | ) | ||
| 1341 | } | ||
| 1342 | 1247 | ||
| 1343 | // Triggered when the counter reaches the TOP value | 1248 | // Triggered when the counter reaches the TOP value |
| 1344 | // this one triggers at F_CPU/65536 =~ 244 Hz | 1249 | // this one triggers at F_CPU/65536 =~ 244 Hz |
| 1345 | ISR(TIMERx_OVF_vect) { | 1250 | ISR(TIMERx_OVF_vect) { |
| 1346 | #ifdef BACKLIGHT_BREATHING | 1251 | # ifdef BACKLIGHT_BREATHING |
| 1347 | if(is_breathing()) { | 1252 | if (is_breathing()) { |
| 1348 | breathing_task(); | 1253 | breathing_task(); |
| 1349 | } | 1254 | } |
| 1350 | #endif | 1255 | # endif |
| 1351 | // for very small values of OCRxx (or backlight level) | 1256 | // for very small values of OCRxx (or backlight level) |
| 1352 | // we can't guarantee this whole code won't execute | 1257 | // we can't guarantee this whole code won't execute |
| 1353 | // at the same time as the compare match interrupt | 1258 | // at the same time as the compare match interrupt |
| 1354 | // which means that we might turn on the leds while | 1259 | // which means that we might turn on the leds while |
| 1355 | // trying to turn them off, leading to flickering | 1260 | // trying to turn them off, leading to flickering |
| 1356 | // artifacts (especially while breathing, because breathing_task | 1261 | // artifacts (especially while breathing, because breathing_task |
| 1357 | // takes many computation cycles). | 1262 | // takes many computation cycles). |
| 1358 | // so better not turn them on while the counter TOP is very low. | 1263 | // so better not turn them on while the counter TOP is very low. |
| 1359 | if (OCRxx > 256) { | 1264 | if (OCRxx > 256) { |
| 1360 | FOR_EACH_LED( | 1265 | FOR_EACH_LED(backlight_on(backlight_pin);) |
| 1361 | backlight_on(backlight_pin); | 1266 | } |
| 1362 | ) | ||
| 1363 | } | ||
| 1364 | } | 1267 | } |
| 1365 | 1268 | ||
| 1366 | #endif | 1269 | # endif |
| 1367 | 1270 | ||
| 1368 | #define TIMER_TOP 0xFFFFU | 1271 | # define TIMER_TOP 0xFFFFU |
| 1369 | 1272 | ||
| 1370 | // See http://jared.geek.nz/2013/feb/linear-led-pwm | 1273 | // See http://jared.geek.nz/2013/feb/linear-led-pwm |
| 1371 | static uint16_t cie_lightness(uint16_t v) { | 1274 | static uint16_t cie_lightness(uint16_t v) { |
| 1372 | if (v <= 5243) // if below 8% of max | 1275 | if (v <= 5243) // if below 8% of max |
| 1373 | return v / 9; // same as dividing by 900% | 1276 | return v / 9; // same as dividing by 900% |
| 1374 | else { | 1277 | else { |
| 1375 | uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare | 1278 | uint32_t y = (((uint32_t)v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare |
| 1376 | // to get a useful result with integer division, we shift left in the expression above | 1279 | // to get a useful result with integer division, we shift left in the expression above |
| 1377 | // and revert what we've done again after squaring. | 1280 | // and revert what we've done again after squaring. |
| 1378 | y = y * y * y >> 8; | 1281 | y = y * y * y >> 8; |
| 1379 | if (y > 0xFFFFUL) // prevent overflow | 1282 | if (y > 0xFFFFUL) // prevent overflow |
| 1380 | return 0xFFFFU; | 1283 | return 0xFFFFU; |
| 1381 | else | 1284 | else |
| 1382 | return (uint16_t) y; | 1285 | return (uint16_t)y; |
| 1383 | } | 1286 | } |
| 1384 | } | 1287 | } |
| 1385 | 1288 | ||
| 1386 | // range for val is [0..TIMER_TOP]. PWM pin is high while the timer count is below val. | 1289 | // range for val is [0..TIMER_TOP]. PWM pin is high while the timer count is below val. |
| 1387 | static inline void set_pwm(uint16_t val) { | 1290 | static inline void set_pwm(uint16_t val) { OCRxx = val; } |
| 1388 | OCRxx = val; | 1291 | |
| 1389 | } | 1292 | # ifndef BACKLIGHT_CUSTOM_DRIVER |
| 1390 | 1293 | __attribute__((weak)) void backlight_set(uint8_t level) { | |
| 1391 | #ifndef BACKLIGHT_CUSTOM_DRIVER | 1294 | if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS; |
| 1392 | __attribute__ ((weak)) | 1295 | |
| 1393 | void backlight_set(uint8_t level) { | 1296 | if (level == 0) { |
| 1394 | if (level > BACKLIGHT_LEVELS) | 1297 | # ifdef BACKLIGHT_PWM_TIMER |
| 1395 | level = BACKLIGHT_LEVELS; | 1298 | if (OCRxx) { |
| 1396 | 1299 | TIMSKx &= ~(_BV(OCIExA)); | |
| 1397 | if (level == 0) { | 1300 | TIMSKx &= ~(_BV(TOIEx)); |
| 1398 | #ifdef BACKLIGHT_PWM_TIMER | 1301 | FOR_EACH_LED(backlight_off(backlight_pin);) |
| 1399 | if (OCRxx) { | 1302 | } |
| 1400 | TIMSKx &= ~(_BV(OCIExA)); | 1303 | # else |
| 1401 | TIMSKx &= ~(_BV(TOIEx)); | 1304 | // Turn off PWM control on backlight pin |
| 1402 | FOR_EACH_LED( | 1305 | TCCRxA &= ~(_BV(COMxx1)); |
| 1403 | backlight_off(backlight_pin); | 1306 | # endif |
| 1404 | ) | 1307 | } else { |
| 1405 | } | 1308 | # ifdef BACKLIGHT_PWM_TIMER |
| 1406 | #else | 1309 | if (!OCRxx) { |
| 1407 | // Turn off PWM control on backlight pin | 1310 | TIMSKx |= _BV(OCIExA); |
| 1408 | TCCRxA &= ~(_BV(COMxx1)); | 1311 | TIMSKx |= _BV(TOIEx); |
| 1409 | #endif | 1312 | } |
| 1410 | } else { | 1313 | # else |
| 1411 | #ifdef BACKLIGHT_PWM_TIMER | 1314 | // Turn on PWM control of backlight pin |
| 1412 | if (!OCRxx) { | 1315 | TCCRxA |= _BV(COMxx1); |
| 1413 | TIMSKx |= _BV(OCIExA); | 1316 | # endif |
| 1414 | TIMSKx |= _BV(TOIEx); | 1317 | } |
| 1415 | } | 1318 | // Set the brightness |
| 1416 | #else | 1319 | set_pwm(cie_lightness(TIMER_TOP * (uint32_t)level / BACKLIGHT_LEVELS)); |
| 1417 | // Turn on PWM control of backlight pin | ||
| 1418 | TCCRxA |= _BV(COMxx1); | ||
| 1419 | #endif | ||
| 1420 | } | ||
| 1421 | // Set the brightness | ||
| 1422 | set_pwm(cie_lightness(TIMER_TOP * (uint32_t)level / BACKLIGHT_LEVELS)); | ||
| 1423 | } | 1320 | } |
| 1424 | 1321 | ||
| 1425 | void backlight_task(void) {} | 1322 | void backlight_task(void) {} |
| 1426 | #endif // BACKLIGHT_CUSTOM_DRIVER | 1323 | # endif // BACKLIGHT_CUSTOM_DRIVER |
| 1427 | 1324 | ||
| 1428 | #ifdef BACKLIGHT_BREATHING | 1325 | # ifdef BACKLIGHT_BREATHING |
| 1429 | 1326 | ||
| 1430 | #define BREATHING_NO_HALT 0 | 1327 | # define BREATHING_NO_HALT 0 |
| 1431 | #define BREATHING_HALT_OFF 1 | 1328 | # define BREATHING_HALT_OFF 1 |
| 1432 | #define BREATHING_HALT_ON 2 | 1329 | # define BREATHING_HALT_ON 2 |
| 1433 | #define BREATHING_STEPS 128 | 1330 | # define BREATHING_STEPS 128 |
| 1434 | 1331 | ||
| 1435 | static uint8_t breathing_period = BREATHING_PERIOD; | 1332 | static uint8_t breathing_period = BREATHING_PERIOD; |
| 1436 | static uint8_t breathing_halt = BREATHING_NO_HALT; | 1333 | static uint8_t breathing_halt = BREATHING_NO_HALT; |
| 1437 | static uint16_t breathing_counter = 0; | 1334 | static uint16_t breathing_counter = 0; |
| 1438 | 1335 | ||
| 1439 | #ifdef BACKLIGHT_PWM_TIMER | 1336 | # ifdef BACKLIGHT_PWM_TIMER |
| 1440 | static bool breathing = false; | 1337 | static bool breathing = false; |
| 1441 | 1338 | ||
| 1442 | bool is_breathing(void) { | 1339 | bool is_breathing(void) { return breathing; } |
| 1443 | return breathing; | 1340 | |
| 1444 | } | 1341 | # define breathing_interrupt_enable() \ |
| 1445 | 1342 | do { \ | |
| 1446 | #define breathing_interrupt_enable() do { breathing = true; } while (0) | 1343 | breathing = true; \ |
| 1447 | #define breathing_interrupt_disable() do { breathing = false; } while (0) | 1344 | } while (0) |
| 1448 | #else | 1345 | # define breathing_interrupt_disable() \ |
| 1449 | 1346 | do { \ | |
| 1450 | bool is_breathing(void) { | 1347 | breathing = false; \ |
| 1451 | return !!(TIMSKx & _BV(TOIEx)); | 1348 | } while (0) |
| 1452 | } | 1349 | # else |
| 1453 | 1350 | ||
| 1454 | #define breathing_interrupt_enable() do {TIMSKx |= _BV(TOIEx);} while (0) | 1351 | bool is_breathing(void) { return !!(TIMSKx & _BV(TOIEx)); } |
| 1455 | #define breathing_interrupt_disable() do {TIMSKx &= ~_BV(TOIEx);} while (0) | 1352 | |
| 1456 | #endif | 1353 | # define breathing_interrupt_enable() \ |
| 1457 | 1354 | do { \ | |
| 1458 | #define breathing_min() do {breathing_counter = 0;} while (0) | 1355 | TIMSKx |= _BV(TOIEx); \ |
| 1459 | #define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0) | 1356 | } while (0) |
| 1460 | 1357 | # define breathing_interrupt_disable() \ | |
| 1461 | void breathing_enable(void) | 1358 | do { \ |
| 1462 | { | 1359 | TIMSKx &= ~_BV(TOIEx); \ |
| 1463 | breathing_counter = 0; | 1360 | } while (0) |
| 1464 | breathing_halt = BREATHING_NO_HALT; | 1361 | # endif |
| 1465 | breathing_interrupt_enable(); | 1362 | |
| 1363 | # define breathing_min() \ | ||
| 1364 | do { \ | ||
| 1365 | breathing_counter = 0; \ | ||
| 1366 | } while (0) | ||
| 1367 | # define breathing_max() \ | ||
| 1368 | do { \ | ||
| 1369 | breathing_counter = breathing_period * 244 / 2; \ | ||
| 1370 | } while (0) | ||
| 1371 | |||
| 1372 | void breathing_enable(void) { | ||
| 1373 | breathing_counter = 0; | ||
| 1374 | breathing_halt = BREATHING_NO_HALT; | ||
| 1375 | breathing_interrupt_enable(); | ||
| 1466 | } | 1376 | } |
| 1467 | 1377 | ||
| 1468 | void breathing_pulse(void) | 1378 | void breathing_pulse(void) { |
| 1469 | { | ||
| 1470 | if (get_backlight_level() == 0) | 1379 | if (get_backlight_level() == 0) |
| 1471 | breathing_min(); | 1380 | breathing_min(); |
| 1472 | else | 1381 | else |
| 1473 | breathing_max(); | 1382 | breathing_max(); |
| 1474 | breathing_halt = BREATHING_HALT_ON; | 1383 | breathing_halt = BREATHING_HALT_ON; |
| 1475 | breathing_interrupt_enable(); | 1384 | breathing_interrupt_enable(); |
| 1476 | } | 1385 | } |
| 1477 | 1386 | ||
| 1478 | void breathing_disable(void) | 1387 | void breathing_disable(void) { |
| 1479 | { | ||
| 1480 | breathing_interrupt_disable(); | 1388 | breathing_interrupt_disable(); |
| 1481 | // Restore backlight level | 1389 | // Restore backlight level |
| 1482 | backlight_set(get_backlight_level()); | 1390 | backlight_set(get_backlight_level()); |
| 1483 | } | 1391 | } |
| 1484 | 1392 | ||
| 1485 | void breathing_self_disable(void) | 1393 | void breathing_self_disable(void) { |
| 1486 | { | 1394 | if (get_backlight_level() == 0) |
| 1487 | if (get_backlight_level() == 0) | 1395 | breathing_halt = BREATHING_HALT_OFF; |
| 1488 | breathing_halt = BREATHING_HALT_OFF; | 1396 | else |
| 1489 | else | 1397 | breathing_halt = BREATHING_HALT_ON; |
| 1490 | breathing_halt = BREATHING_HALT_ON; | ||
| 1491 | } | 1398 | } |
| 1492 | 1399 | ||
| 1493 | void breathing_toggle(void) { | 1400 | void breathing_toggle(void) { |
| 1494 | if (is_breathing()) | 1401 | if (is_breathing()) |
| 1495 | breathing_disable(); | 1402 | breathing_disable(); |
| 1496 | else | 1403 | else |
| 1497 | breathing_enable(); | 1404 | breathing_enable(); |
| 1498 | } | 1405 | } |
| 1499 | 1406 | ||
| 1500 | void breathing_period_set(uint8_t value) | 1407 | void breathing_period_set(uint8_t value) { |
| 1501 | { | 1408 | if (!value) value = 1; |
| 1502 | if (!value) | 1409 | breathing_period = value; |
| 1503 | value = 1; | ||
| 1504 | breathing_period = value; | ||
| 1505 | } | 1410 | } |
| 1506 | 1411 | ||
| 1507 | void breathing_period_default(void) { | 1412 | void breathing_period_default(void) { breathing_period_set(BREATHING_PERIOD); } |
| 1508 | breathing_period_set(BREATHING_PERIOD); | ||
| 1509 | } | ||
| 1510 | 1413 | ||
| 1511 | void breathing_period_inc(void) | 1414 | void breathing_period_inc(void) { breathing_period_set(breathing_period + 1); } |
| 1512 | { | ||
| 1513 | breathing_period_set(breathing_period+1); | ||
| 1514 | } | ||
| 1515 | 1415 | ||
| 1516 | void breathing_period_dec(void) | 1416 | void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); } |
| 1517 | { | ||
| 1518 | breathing_period_set(breathing_period-1); | ||
| 1519 | } | ||
| 1520 | 1417 | ||
| 1521 | /* To generate breathing curve in python: | 1418 | /* To generate breathing curve in python: |
| 1522 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] | 1419 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] |
| @@ -1524,100 +1421,88 @@ void breathing_period_dec(void) | |||
| 1524 | static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | 1421 | static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 1525 | 1422 | ||
| 1526 | // Use this before the cie_lightness function. | 1423 | // Use this before the cie_lightness function. |
| 1527 | static inline uint16_t scale_backlight(uint16_t v) { | 1424 | static inline uint16_t scale_backlight(uint16_t v) { return v / BACKLIGHT_LEVELS * get_backlight_level(); } |
| 1528 | return v / BACKLIGHT_LEVELS * get_backlight_level(); | ||
| 1529 | } | ||
| 1530 | 1425 | ||
| 1531 | #ifdef BACKLIGHT_PWM_TIMER | 1426 | # ifdef BACKLIGHT_PWM_TIMER |
| 1532 | void breathing_task(void) | 1427 | void breathing_task(void) |
| 1533 | #else | 1428 | # else |
| 1534 | /* Assuming a 16MHz CPU clock and a timer that resets at 64k (ICR1), the following interrupt handler will run | 1429 | /* Assuming a 16MHz CPU clock and a timer that resets at 64k (ICR1), the following interrupt handler will run |
| 1535 | * about 244 times per second. | 1430 | * about 244 times per second. |
| 1536 | */ | 1431 | */ |
| 1537 | ISR(TIMERx_OVF_vect) | 1432 | ISR(TIMERx_OVF_vect) |
| 1538 | #endif | 1433 | # endif |
| 1539 | { | 1434 | { |
| 1540 | uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; | 1435 | uint16_t interval = (uint16_t)breathing_period * 244 / BREATHING_STEPS; |
| 1541 | // resetting after one period to prevent ugly reset at overflow. | 1436 | // resetting after one period to prevent ugly reset at overflow. |
| 1542 | breathing_counter = (breathing_counter + 1) % (breathing_period * 244); | 1437 | breathing_counter = (breathing_counter + 1) % (breathing_period * 244); |
| 1543 | uint8_t index = breathing_counter / interval % BREATHING_STEPS; | 1438 | uint8_t index = breathing_counter / interval % BREATHING_STEPS; |
| 1544 | |||
| 1545 | if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || | ||
| 1546 | ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) | ||
| 1547 | { | ||
| 1548 | breathing_interrupt_disable(); | ||
| 1549 | } | ||
| 1550 | |||
| 1551 | set_pwm(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U))); | ||
| 1552 | } | ||
| 1553 | 1439 | ||
| 1554 | #endif // BACKLIGHT_BREATHING | 1440 | if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) { |
| 1441 | breathing_interrupt_disable(); | ||
| 1442 | } | ||
| 1555 | 1443 | ||
| 1556 | __attribute__ ((weak)) | 1444 | set_pwm(cie_lightness(scale_backlight((uint16_t)pgm_read_byte(&breathing_table[index]) * 0x0101U))); |
| 1557 | void backlight_init_ports(void) | 1445 | } |
| 1558 | { | 1446 | |
| 1559 | // Setup backlight pin as output and output to on state. | 1447 | # endif // BACKLIGHT_BREATHING |
| 1560 | FOR_EACH_LED( | 1448 | |
| 1561 | setPinOutput(backlight_pin); | 1449 | __attribute__((weak)) void backlight_init_ports(void) { |
| 1562 | backlight_on(backlight_pin); | 1450 | // Setup backlight pin as output and output to on state. |
| 1563 | ) | 1451 | FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) |
| 1564 | 1452 | ||
| 1565 | // I could write a wall of text here to explain... but TL;DW | 1453 | // I could write a wall of text here to explain... but TL;DW |
| 1566 | // Go read the ATmega32u4 datasheet. | 1454 | // Go read the ATmega32u4 datasheet. |
| 1567 | // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on | 1455 | // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on |
| 1568 | 1456 | ||
| 1569 | #ifdef BACKLIGHT_PWM_TIMER | 1457 | # ifdef BACKLIGHT_PWM_TIMER |
| 1570 | // TimerX setup, Fast PWM mode count to TOP set in ICRx | 1458 | // TimerX setup, Fast PWM mode count to TOP set in ICRx |
| 1571 | TCCRxA = _BV(WGM11); // = 0b00000010; | 1459 | TCCRxA = _BV(WGM11); // = 0b00000010; |
| 1572 | // clock select clk/1 | 1460 | // clock select clk/1 |
| 1573 | TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | 1461 | TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; |
| 1574 | #else // hardware PWM | 1462 | # else // hardware PWM |
| 1575 | // Pin PB7 = OCR1C (Timer 1, Channel C) | 1463 | // Pin PB7 = OCR1C (Timer 1, Channel C) |
| 1576 | // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 | 1464 | // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 |
| 1577 | // (i.e. start high, go low when counter matches.) | 1465 | // (i.e. start high, go low when counter matches.) |
| 1578 | // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 | 1466 | // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 |
| 1579 | // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 | 1467 | // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 |
| 1580 | 1468 | ||
| 1581 | /* | 1469 | /* |
| 1582 | 14.8.3: | 1470 | 14.8.3: |
| 1583 | "In fast PWM mode, the compare units allow generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to two will produce a non-inverted PWM [..]." | 1471 | "In fast PWM mode, the compare units allow generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to two will produce a non-inverted PWM [..]." |
| 1584 | "In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGMn3:0 = 5, 6, or 7), the value in ICRn (WGMn3:0 = 14), or the value in OCRnA (WGMn3:0 = 15)." | 1472 | "In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGMn3:0 = 5, 6, or 7), the value in ICRn (WGMn3:0 = 14), or the value in OCRnA (WGMn3:0 = 15)." |
| 1585 | */ | 1473 | */ |
| 1586 | TCCRxA = _BV(COMxx1) | _BV(WGM11); // = 0b00001010; | 1474 | TCCRxA = _BV(COMxx1) | _BV(WGM11); // = 0b00001010; |
| 1587 | TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | 1475 | TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; |
| 1588 | #endif | 1476 | # endif |
| 1589 | // Use full 16-bit resolution. Counter counts to ICR1 before reset to 0. | 1477 | // Use full 16-bit resolution. Counter counts to ICR1 before reset to 0. |
| 1590 | ICRx = TIMER_TOP; | 1478 | ICRx = TIMER_TOP; |
| 1591 | 1479 | ||
| 1592 | backlight_init(); | 1480 | backlight_init(); |
| 1593 | #ifdef BACKLIGHT_BREATHING | 1481 | # ifdef BACKLIGHT_BREATHING |
| 1594 | if (is_backlight_breathing()) { | 1482 | if (is_backlight_breathing()) { |
| 1595 | breathing_enable(); | 1483 | breathing_enable(); |
| 1596 | } | 1484 | } |
| 1597 | #endif | 1485 | # endif |
| 1598 | } | 1486 | } |
| 1599 | 1487 | ||
| 1600 | #endif // hardware backlight | 1488 | # endif // hardware backlight |
| 1601 | 1489 | ||
| 1602 | #else // no backlight | 1490 | #else // no backlight |
| 1603 | 1491 | ||
| 1604 | __attribute__ ((weak)) | 1492 | __attribute__((weak)) void backlight_init_ports(void) {} |
| 1605 | void backlight_init_ports(void) {} | ||
| 1606 | 1493 | ||
| 1607 | __attribute__ ((weak)) | 1494 | __attribute__((weak)) void backlight_set(uint8_t level) {} |
| 1608 | void backlight_set(uint8_t level) {} | ||
| 1609 | 1495 | ||
| 1610 | #endif // backlight | 1496 | #endif // backlight |
| 1611 | 1497 | ||
| 1612 | #ifdef HD44780_ENABLED | 1498 | #ifdef HD44780_ENABLED |
| 1613 | #include "hd44780.h" | 1499 | # include "hd44780.h" |
| 1614 | #endif | 1500 | #endif |
| 1615 | 1501 | ||
| 1616 | |||
| 1617 | // Functions for spitting out values | 1502 | // Functions for spitting out values |
| 1618 | // | 1503 | // |
| 1619 | 1504 | ||
| 1620 | void send_dword(uint32_t number) { // this might not actually work | 1505 | void send_dword(uint32_t number) { // this might not actually work |
| 1621 | uint16_t word = (number >> 16); | 1506 | uint16_t word = (number >> 16); |
| 1622 | send_word(word); | 1507 | send_word(word); |
| 1623 | send_word(number & 0xFFFFUL); | 1508 | send_word(number & 0xFFFFUL); |
| @@ -1652,18 +1537,15 @@ void send_nibble(uint8_t number) { | |||
| 1652 | } | 1537 | } |
| 1653 | } | 1538 | } |
| 1654 | 1539 | ||
| 1655 | 1540 | __attribute__((weak)) uint16_t hex_to_keycode(uint8_t hex) { | |
| 1656 | __attribute__((weak)) | 1541 | hex = hex & 0xF; |
| 1657 | uint16_t hex_to_keycode(uint8_t hex) | 1542 | if (hex == 0x0) { |
| 1658 | { | 1543 | return KC_0; |
| 1659 | hex = hex & 0xF; | 1544 | } else if (hex < 0xA) { |
| 1660 | if (hex == 0x0) { | 1545 | return KC_1 + (hex - 0x1); |
| 1661 | return KC_0; | 1546 | } else { |
| 1662 | } else if (hex < 0xA) { | 1547 | return KC_A + (hex - 0xA); |
| 1663 | return KC_1 + (hex - 0x1); | 1548 | } |
| 1664 | } else { | ||
| 1665 | return KC_A + (hex - 0xA); | ||
| 1666 | } | ||
| 1667 | } | 1549 | } |
| 1668 | 1550 | ||
| 1669 | void api_send_unicode(uint32_t unicode) { | 1551 | void api_send_unicode(uint32_t unicode) { |
| @@ -1674,55 +1556,40 @@ void api_send_unicode(uint32_t unicode) { | |||
| 1674 | #endif | 1556 | #endif |
| 1675 | } | 1557 | } |
| 1676 | 1558 | ||
| 1677 | __attribute__ ((weak)) | 1559 | __attribute__((weak)) void led_set_user(uint8_t usb_led) {} |
| 1678 | void led_set_user(uint8_t usb_led) { | ||
| 1679 | 1560 | ||
| 1680 | } | 1561 | __attribute__((weak)) void led_set_kb(uint8_t usb_led) { led_set_user(usb_led); } |
| 1681 | 1562 | ||
| 1682 | __attribute__ ((weak)) | 1563 | __attribute__((weak)) void led_init_ports(void) {} |
| 1683 | void led_set_kb(uint8_t usb_led) { | ||
| 1684 | led_set_user(usb_led); | ||
| 1685 | } | ||
| 1686 | 1564 | ||
| 1687 | __attribute__ ((weak)) | 1565 | __attribute__((weak)) void led_set(uint8_t usb_led) { |
| 1688 | void led_init_ports(void) | ||
| 1689 | { | ||
| 1690 | |||
| 1691 | } | ||
| 1692 | |||
| 1693 | __attribute__ ((weak)) | ||
| 1694 | void led_set(uint8_t usb_led) | ||
| 1695 | { | ||
| 1696 | #if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) | 1566 | #if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) |
| 1697 | // Use backlight as Caps Lock indicator | 1567 | // Use backlight as Caps Lock indicator |
| 1698 | uint8_t bl_toggle_lvl = 0; | 1568 | uint8_t bl_toggle_lvl = 0; |
| 1699 | 1569 | ||
| 1700 | if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK) && !backlight_config.enable) { | 1570 | if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK) && !backlight_config.enable) { |
| 1701 | // Turning Caps Lock ON and backlight is disabled in config | 1571 | // Turning Caps Lock ON and backlight is disabled in config |
| 1702 | // Toggling backlight to the brightest level | 1572 | // Toggling backlight to the brightest level |
| 1703 | bl_toggle_lvl = BACKLIGHT_LEVELS; | 1573 | bl_toggle_lvl = BACKLIGHT_LEVELS; |
| 1704 | } else if (IS_LED_OFF(usb_led, USB_LED_CAPS_LOCK) && backlight_config.enable) { | 1574 | } else if (IS_LED_OFF(usb_led, USB_LED_CAPS_LOCK) && backlight_config.enable) { |
| 1705 | // Turning Caps Lock OFF and backlight is enabled in config | 1575 | // Turning Caps Lock OFF and backlight is enabled in config |
| 1706 | // Toggling backlight and restoring config level | 1576 | // Toggling backlight and restoring config level |
| 1707 | bl_toggle_lvl = backlight_config.level; | 1577 | bl_toggle_lvl = backlight_config.level; |
| 1708 | } | 1578 | } |
| 1709 | 1579 | ||
| 1710 | // Set level without modify backlight_config to keep ability to restore state | 1580 | // Set level without modify backlight_config to keep ability to restore state |
| 1711 | backlight_set(bl_toggle_lvl); | 1581 | backlight_set(bl_toggle_lvl); |
| 1712 | #endif | 1582 | #endif |
| 1713 | 1583 | ||
| 1714 | led_set_kb(usb_led); | 1584 | led_set_kb(usb_led); |
| 1715 | } | 1585 | } |
| 1716 | 1586 | ||
| 1717 | |||
| 1718 | //------------------------------------------------------------------------------ | 1587 | //------------------------------------------------------------------------------ |
| 1719 | // Override these functions in your keymap file to play different tunes on | 1588 | // Override these functions in your keymap file to play different tunes on |
| 1720 | // different events such as startup and bootloader jump | 1589 | // different events such as startup and bootloader jump |
| 1721 | 1590 | ||
| 1722 | __attribute__ ((weak)) | 1591 | __attribute__((weak)) void startup_user() {} |
| 1723 | void startup_user() {} | ||
| 1724 | 1592 | ||
| 1725 | __attribute__ ((weak)) | 1593 | __attribute__((weak)) void shutdown_user() {} |
| 1726 | void shutdown_user() {} | ||
| 1727 | 1594 | ||
| 1728 | //------------------------------------------------------------------------------ | 1595 | //------------------------------------------------------------------------------ |
