4 bool process_action_kb(keyrecord_t *record) {
9 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
10 return process_record_user(keycode, record);
13 __attribute__ ((weak))
14 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
18 // Shift / paren setup
27 static bool shift_interrupted[2] = {0, 0};
29 bool process_record_quantum(keyrecord_t *record) {
31 /* This gets the keycode from the key pressed */
32 keypos_t key = record->event.key;
35 #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
38 if (record->event.pressed) {
39 layer = layer_switch_get_layer(key);
40 update_source_layers_cache(key, layer);
42 layer = read_source_layers_cache(key);
44 keycode = keymap_key_to_keycode(layer, key);
46 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
49 // This is how you use actions here
50 // if (keycode == KC_LEAD) {
52 // action.code = ACTION_DEFAULT_LAYER_SET(0);
53 // process_action(record, action);
58 process_record_kb(keycode, record) &&
60 process_midi(keycode, record) &&
63 process_music(keycode, record) &&
65 #ifdef TAP_DANCE_ENABLE
66 process_tap_dance(keycode, record) &&
68 #ifndef DISABLE_LEADER
69 process_leader(keycode, record) &&
71 #ifndef DISABLE_CHORDING
72 process_chording(keycode, record) &&
75 process_unicode(keycode, record) &&
81 // Shift / paren setup
85 if (record->event.pressed) {
92 #ifdef CATERINA_BOOTLOADER
93 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
100 if (record->event.pressed) {
101 print("\nDEBUG: enabled.\n");
106 #ifdef RGBLIGHT_ENABLE
108 if (record->event.pressed) {
114 if (record->event.pressed) {
120 if (record->event.pressed) {
121 rgblight_increase_hue();
126 if (record->event.pressed) {
127 rgblight_decrease_hue();
132 if (record->event.pressed) {
133 rgblight_increase_sat();
138 if (record->event.pressed) {
139 rgblight_decrease_sat();
144 if (record->event.pressed) {
145 rgblight_increase_val();
150 if (record->event.pressed) {
151 rgblight_decrease_val();
156 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
157 if (record->event.pressed) {
158 // MAGIC actions (BOOTMAGIC without the boot)
159 if (!eeconfig_is_enabled()) {
163 keymap_config.raw = eeconfig_read_keymap();
164 if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
165 keymap_config.swap_control_capslock = 1;
166 } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
167 keymap_config.capslock_to_control = 1;
168 } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
169 keymap_config.swap_lalt_lgui = 1;
170 } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
171 keymap_config.swap_ralt_rgui = 1;
172 } else if (keycode == MAGIC_NO_GUI) {
173 keymap_config.no_gui = 1;
174 } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
175 keymap_config.swap_grave_esc = 1;
176 } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
177 keymap_config.swap_backslash_backspace = 1;
178 } else if (keycode == MAGIC_HOST_NKRO) {
179 keymap_config.nkro = 1;
180 } else if (keycode == MAGIC_SWAP_ALT_GUI) {
181 keymap_config.swap_lalt_lgui = 1;
182 keymap_config.swap_ralt_rgui = 1;
185 else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
186 keymap_config.swap_control_capslock = 0;
187 } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
188 keymap_config.capslock_to_control = 0;
189 } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
190 keymap_config.swap_lalt_lgui = 0;
191 } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
192 keymap_config.swap_ralt_rgui = 0;
193 } else if (keycode == MAGIC_UNNO_GUI) {
194 keymap_config.no_gui = 0;
195 } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
196 keymap_config.swap_grave_esc = 0;
197 } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
198 keymap_config.swap_backslash_backspace = 0;
199 } else if (keycode == MAGIC_UNHOST_NKRO) {
200 keymap_config.nkro = 0;
201 } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
202 keymap_config.swap_lalt_lgui = 0;
203 keymap_config.swap_ralt_rgui = 0;
205 eeconfig_update_keymap(keymap_config.raw);
210 if (record->event.pressed) {
211 shift_interrupted[0] = false;
212 register_mods(MOD_BIT(KC_LSFT));
215 if (!shift_interrupted[0]) {
216 register_code(LSPO_KEY);
217 unregister_code(LSPO_KEY);
219 unregister_mods(MOD_BIT(KC_LSFT));
226 if (record->event.pressed) {
227 shift_interrupted[1] = false;
228 register_mods(MOD_BIT(KC_RSFT));
231 if (!shift_interrupted[1]) {
232 register_code(RSPC_KEY);
233 unregister_code(RSPC_KEY);
235 unregister_mods(MOD_BIT(KC_RSFT));
241 shift_interrupted[0] = true;
242 shift_interrupted[1] = true;
247 return process_action_kb(record);
250 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
251 0, 0, 0, 0, 0, 0, 0, 0,
252 0, 0, 0, 0, 0, 0, 0, 0,
253 0, 0, 0, 0, 0, 0, 0, 0,
254 0, 0, 0, 0, 0, 0, 0, 0,
255 0, 1, 1, 1, 1, 1, 1, 0,
256 1, 1, 1, 1, 0, 0, 0, 0,
257 0, 0, 0, 0, 0, 0, 0, 0,
258 0, 0, 1, 0, 1, 0, 1, 1,
259 1, 1, 1, 1, 1, 1, 1, 1,
260 1, 1, 1, 1, 1, 1, 1, 1,
261 1, 1, 1, 1, 1, 1, 1, 1,
262 1, 1, 1, 0, 0, 0, 1, 1,
263 0, 0, 0, 0, 0, 0, 0, 0,
264 0, 0, 0, 0, 0, 0, 0, 0,
265 0, 0, 0, 0, 0, 0, 0, 0,
266 0, 0, 0, 1, 1, 1, 1, 0
269 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
270 0, 0, 0, 0, 0, 0, 0, 0,
271 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
272 0, 0, 0, 0, 0, 0, 0, 0,
273 0, 0, 0, KC_ESC, 0, 0, 0, 0,
274 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
275 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
276 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
277 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
278 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
279 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
280 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
281 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
282 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
283 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
284 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
285 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
288 /* for users whose OSes are set to Colemak */
290 #include "keymap_colemak.h"
292 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
293 0, 0, 0, 0, 0, 0, 0, 0,
294 0, 0, 0, 0, 0, 0, 0, 0,
295 0, 0, 0, 0, 0, 0, 0, 0,
296 0, 0, 0, 0, 0, 0, 0, 0,
297 0, 1, 1, 1, 1, 1, 1, 0,
298 1, 1, 1, 1, 0, 0, 0, 0,
299 0, 0, 0, 0, 0, 0, 0, 0,
300 0, 0, 1, 0, 1, 0, 1, 1,
301 1, 1, 1, 1, 1, 1, 1, 1,
302 1, 1, 1, 1, 1, 1, 1, 1,
303 1, 1, 1, 1, 1, 1, 1, 1,
304 1, 1, 1, 0, 0, 0, 1, 1,
305 0, 0, 0, 0, 0, 0, 0, 0,
306 0, 0, 0, 0, 0, 0, 0, 0,
307 0, 0, 0, 0, 0, 0, 0, 0,
308 0, 0, 0, 1, 1, 1, 1, 0
311 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
312 0, 0, 0, 0, 0, 0, 0, 0,
313 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
314 0, 0, 0, 0, 0, 0, 0, 0,
315 0, 0, 0, KC_ESC, 0, 0, 0, 0,
316 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
317 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
318 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
319 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
320 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
321 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
322 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
323 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
324 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
325 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
326 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
327 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
332 void send_string(const char *str) {
335 uint8_t ascii_code = pgm_read_byte(str);
336 if (!ascii_code) break;
337 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
338 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
339 register_code(KC_LSFT);
340 register_code(keycode);
341 unregister_code(keycode);
342 unregister_code(KC_LSFT);
345 register_code(keycode);
346 unregister_code(keycode);
352 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
353 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
360 void tap_random_base64(void) {
361 #if defined(__AVR_ATmega32U4__)
362 uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
364 uint8_t key = rand() % 64;
368 register_code(KC_LSFT);
369 register_code(key + KC_A);
370 unregister_code(key + KC_A);
371 unregister_code(KC_LSFT);
374 register_code(key - 26 + KC_A);
375 unregister_code(key - 26 + KC_A);
379 unregister_code(KC_0);
382 register_code(key - 53 + KC_1);
383 unregister_code(key - 53 + KC_1);
386 register_code(KC_LSFT);
387 register_code(KC_EQL);
388 unregister_code(KC_EQL);
389 unregister_code(KC_LSFT);
392 register_code(KC_SLSH);
393 unregister_code(KC_SLSH);
398 void matrix_init_quantum() {
399 #ifdef BACKLIGHT_ENABLE
400 backlight_init_ports();
405 void matrix_scan_quantum() {
410 #ifdef TAP_DANCE_ENABLE
411 matrix_scan_tap_dance();
416 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
418 static const uint8_t backlight_pin = BACKLIGHT_PIN;
420 #if BACKLIGHT_PIN == B7
421 # define COM1x1 COM1C1
423 #elif BACKLIGHT_PIN == B6
424 # define COM1x1 COM1B1
426 #elif BACKLIGHT_PIN == B5
427 # define COM1x1 COM1A1
430 # error "Backlight pin not supported - use B5, B6, or B7"
433 __attribute__ ((weak))
434 void backlight_init_ports(void)
437 // Setup backlight pin as output and output low.
439 _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
441 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
443 // Use full 16-bit resolution.
446 // I could write a wall of text here to explain... but TL;DW
447 // Go read the ATmega32u4 datasheet.
448 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
450 // Pin PB7 = OCR1C (Timer 1, Channel C)
451 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
452 // (i.e. start high, go low when counter matches.)
453 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
454 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
456 TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
457 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
460 #ifdef BACKLIGHT_BREATHING
461 breathing_defaults();
465 __attribute__ ((weak))
466 void backlight_set(uint8_t level)
468 // Prevent backlight blink on lowest level
470 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
473 // Turn off PWM control on backlight pin, revert to output low.
474 TCCR1A &= ~(_BV(COM1x1));
476 } else if ( level == BACKLIGHT_LEVELS ) {
477 // Turn on PWM control of backlight pin
478 TCCR1A |= _BV(COM1x1);
479 // Set the brightness
482 // Turn on PWM control of backlight pin
483 TCCR1A |= _BV(COM1x1);
484 // Set the brightness
485 OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
488 #ifdef BACKLIGHT_BREATHING
489 breathing_intensity_default();
494 #ifdef BACKLIGHT_BREATHING
496 #define BREATHING_NO_HALT 0
497 #define BREATHING_HALT_OFF 1
498 #define BREATHING_HALT_ON 2
500 static uint8_t breath_intensity;
501 static uint8_t breath_speed;
502 static uint16_t breathing_index;
503 static uint8_t breathing_halt;
505 void breathing_enable(void)
507 if (get_backlight_level() == 0)
513 // Set breathing_index to be at the midpoint (brightest point)
514 breathing_index = 0x20 << breath_speed;
517 breathing_halt = BREATHING_NO_HALT;
519 // Enable breathing interrupt
520 TIMSK1 |= _BV(OCIE1A);
523 void breathing_pulse(void)
525 if (get_backlight_level() == 0)
531 // Set breathing_index to be at the midpoint + 1 (brightest point)
532 breathing_index = 0x21 << breath_speed;
535 breathing_halt = BREATHING_HALT_ON;
537 // Enable breathing interrupt
538 TIMSK1 |= _BV(OCIE1A);
541 void breathing_disable(void)
543 // Disable breathing interrupt
544 TIMSK1 &= ~_BV(OCIE1A);
545 backlight_set(get_backlight_level());
548 void breathing_self_disable(void)
550 if (get_backlight_level() == 0)
552 breathing_halt = BREATHING_HALT_OFF;
556 breathing_halt = BREATHING_HALT_ON;
559 //backlight_set(get_backlight_level());
562 void breathing_toggle(void)
566 if (get_backlight_level() == 0)
572 // Set breathing_index to be at the midpoint + 1 (brightest point)
573 breathing_index = 0x21 << breath_speed;
576 breathing_halt = BREATHING_NO_HALT;
579 // Toggle breathing interrupt
580 TIMSK1 ^= _BV(OCIE1A);
582 // Restore backlight level
585 backlight_set(get_backlight_level());
589 bool is_breathing(void)
591 return (TIMSK1 && _BV(OCIE1A));
594 void breathing_intensity_default(void)
596 //breath_intensity = (uint8_t)((uint16_t)100 * (uint16_t)get_backlight_level() / (uint16_t)BACKLIGHT_LEVELS);
597 breath_intensity = ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2));
600 void breathing_intensity_set(uint8_t value)
602 breath_intensity = value;
605 void breathing_speed_default(void)
610 void breathing_speed_set(uint8_t value)
612 bool is_breathing_now = is_breathing();
613 uint8_t old_breath_speed = breath_speed;
615 if (is_breathing_now)
617 // Disable breathing interrupt
618 TIMSK1 &= ~_BV(OCIE1A);
621 breath_speed = value;
623 if (is_breathing_now)
625 // Adjust index to account for new speed
626 breathing_index = (( (uint8_t)( (breathing_index) >> old_breath_speed ) ) & 0x3F) << breath_speed;
628 // Enable breathing interrupt
629 TIMSK1 |= _BV(OCIE1A);
634 void breathing_speed_inc(uint8_t value)
636 if ((uint16_t)(breath_speed - value) > 10 )
638 breathing_speed_set(0);
642 breathing_speed_set(breath_speed - value);
646 void breathing_speed_dec(uint8_t value)
648 if ((uint16_t)(breath_speed + value) > 10 )
650 breathing_speed_set(10);
654 breathing_speed_set(breath_speed + value);
658 void breathing_defaults(void)
660 breathing_intensity_default();
661 breathing_speed_default();
662 breathing_halt = BREATHING_NO_HALT;
665 /* Breathing Sleep LED brighness(PWM On period) table
666 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
668 * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
669 * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
671 static const uint8_t breathing_table[64] PROGMEM = {
672 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
673 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
674 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
675 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
678 ISR(TIMER1_COMPA_vect)
680 // OCR1x = (pgm_read_byte(&breathing_table[ ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F ] )) * breath_intensity;
683 uint8_t local_index = ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F;
685 if (((breathing_halt == BREATHING_HALT_ON) && (local_index == 0x20)) || ((breathing_halt == BREATHING_HALT_OFF) && (local_index == 0x3F)))
687 // Disable breathing interrupt
688 TIMSK1 &= ~_BV(OCIE1A);
691 OCR1x = (uint16_t)(((uint16_t)pgm_read_byte(&breathing_table[local_index]) * 257)) >> breath_intensity;
701 __attribute__ ((weak))
702 void backlight_init_ports(void)
707 __attribute__ ((weak))
708 void backlight_set(uint8_t level)
717 __attribute__ ((weak))
718 void led_set_user(uint8_t usb_led) {
722 __attribute__ ((weak))
723 void led_set_kb(uint8_t usb_led) {
724 led_set_user(usb_led);
727 __attribute__ ((weak))
728 void led_init_ports(void)
733 __attribute__ ((weak))
734 void led_set(uint8_t usb_led)
739 // // Using PE6 Caps Lock LED
740 // if (usb_led & (1<<USB_LED_CAPS_LOCK))
757 //------------------------------------------------------------------------------
758 // Override these functions in your keymap file to play different tunes on
759 // different events such as startup and bootloader jump
761 __attribute__ ((weak))
762 void startup_user() {}
764 __attribute__ ((weak))
765 void shutdown_user() {}
767 //------------------------------------------------------------------------------