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 #ifdef DISABLE_SPACE_CADET_ROLLOVER
216 if (get_mods() & MOD_BIT(KC_RSFT)) {
217 shift_interrupted[0] = true;
218 shift_interrupted[1] = true;
221 if (!shift_interrupted[0]) {
222 register_code(LSPO_KEY);
223 unregister_code(LSPO_KEY);
225 unregister_mods(MOD_BIT(KC_LSFT));
232 if (record->event.pressed) {
233 shift_interrupted[1] = false;
234 register_mods(MOD_BIT(KC_RSFT));
237 #ifdef DISABLE_SPACE_CADET_ROLLOVER
238 if (get_mods() & MOD_BIT(KC_LSFT)) {
239 shift_interrupted[0] = true;
240 shift_interrupted[1] = true;
243 if (!shift_interrupted[1]) {
244 register_code(RSPC_KEY);
245 unregister_code(RSPC_KEY);
247 unregister_mods(MOD_BIT(KC_RSFT));
253 shift_interrupted[0] = true;
254 shift_interrupted[1] = true;
259 return process_action_kb(record);
262 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
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, 0, 0, 0, 0, 0,
267 0, 1, 1, 1, 1, 1, 1, 0,
268 1, 1, 1, 1, 0, 0, 0, 0,
269 0, 0, 0, 0, 0, 0, 0, 0,
270 0, 0, 1, 0, 1, 0, 1, 1,
271 1, 1, 1, 1, 1, 1, 1, 1,
272 1, 1, 1, 1, 1, 1, 1, 1,
273 1, 1, 1, 1, 1, 1, 1, 1,
274 1, 1, 1, 0, 0, 0, 1, 1,
275 0, 0, 0, 0, 0, 0, 0, 0,
276 0, 0, 0, 0, 0, 0, 0, 0,
277 0, 0, 0, 0, 0, 0, 0, 0,
278 0, 0, 0, 1, 1, 1, 1, 0
281 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
282 0, 0, 0, 0, 0, 0, 0, 0,
283 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
284 0, 0, 0, 0, 0, 0, 0, 0,
285 0, 0, 0, KC_ESC, 0, 0, 0, 0,
286 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
287 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
288 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
289 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
290 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
291 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
292 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
293 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
294 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
295 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
296 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
297 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
300 /* for users whose OSes are set to Colemak */
302 #include "keymap_colemak.h"
304 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
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, 0, 0, 0, 0, 0,
309 0, 1, 1, 1, 1, 1, 1, 0,
310 1, 1, 1, 1, 0, 0, 0, 0,
311 0, 0, 0, 0, 0, 0, 0, 0,
312 0, 0, 1, 0, 1, 0, 1, 1,
313 1, 1, 1, 1, 1, 1, 1, 1,
314 1, 1, 1, 1, 1, 1, 1, 1,
315 1, 1, 1, 1, 1, 1, 1, 1,
316 1, 1, 1, 0, 0, 0, 1, 1,
317 0, 0, 0, 0, 0, 0, 0, 0,
318 0, 0, 0, 0, 0, 0, 0, 0,
319 0, 0, 0, 0, 0, 0, 0, 0,
320 0, 0, 0, 1, 1, 1, 1, 0
323 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
324 0, 0, 0, 0, 0, 0, 0, 0,
325 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
326 0, 0, 0, 0, 0, 0, 0, 0,
327 0, 0, 0, KC_ESC, 0, 0, 0, 0,
328 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
329 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
330 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
331 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
332 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
333 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
334 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
335 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
336 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
337 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
338 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
339 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
344 void send_string(const char *str) {
347 uint8_t ascii_code = pgm_read_byte(str);
348 if (!ascii_code) break;
349 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
350 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
351 register_code(KC_LSFT);
352 register_code(keycode);
353 unregister_code(keycode);
354 unregister_code(KC_LSFT);
357 register_code(keycode);
358 unregister_code(keycode);
364 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
365 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
372 void tap_random_base64(void) {
373 #if defined(__AVR_ATmega32U4__)
374 uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
376 uint8_t key = rand() % 64;
380 register_code(KC_LSFT);
381 register_code(key + KC_A);
382 unregister_code(key + KC_A);
383 unregister_code(KC_LSFT);
386 register_code(key - 26 + KC_A);
387 unregister_code(key - 26 + KC_A);
391 unregister_code(KC_0);
394 register_code(key - 53 + KC_1);
395 unregister_code(key - 53 + KC_1);
398 register_code(KC_LSFT);
399 register_code(KC_EQL);
400 unregister_code(KC_EQL);
401 unregister_code(KC_LSFT);
404 register_code(KC_SLSH);
405 unregister_code(KC_SLSH);
410 void matrix_init_quantum() {
411 #ifdef BACKLIGHT_ENABLE
412 backlight_init_ports();
417 void matrix_scan_quantum() {
422 #ifdef TAP_DANCE_ENABLE
423 matrix_scan_tap_dance();
428 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
430 static const uint8_t backlight_pin = BACKLIGHT_PIN;
432 #if BACKLIGHT_PIN == B7
433 # define COM1x1 COM1C1
435 #elif BACKLIGHT_PIN == B6
436 # define COM1x1 COM1B1
438 #elif BACKLIGHT_PIN == B5
439 # define COM1x1 COM1A1
442 # error "Backlight pin not supported - use B5, B6, or B7"
445 __attribute__ ((weak))
446 void backlight_init_ports(void)
449 // Setup backlight pin as output and output low.
451 _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
453 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
455 // Use full 16-bit resolution.
458 // I could write a wall of text here to explain... but TL;DW
459 // Go read the ATmega32u4 datasheet.
460 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
462 // Pin PB7 = OCR1C (Timer 1, Channel C)
463 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
464 // (i.e. start high, go low when counter matches.)
465 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
466 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
468 TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
469 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
472 #ifdef BACKLIGHT_BREATHING
473 breathing_defaults();
477 __attribute__ ((weak))
478 void backlight_set(uint8_t level)
480 // Prevent backlight blink on lowest level
482 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
485 // Turn off PWM control on backlight pin, revert to output low.
486 TCCR1A &= ~(_BV(COM1x1));
488 } else if ( level == BACKLIGHT_LEVELS ) {
489 // Turn on PWM control of backlight pin
490 TCCR1A |= _BV(COM1x1);
491 // Set the brightness
494 // Turn on PWM control of backlight pin
495 TCCR1A |= _BV(COM1x1);
496 // Set the brightness
497 OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
500 #ifdef BACKLIGHT_BREATHING
501 breathing_intensity_default();
506 #ifdef BACKLIGHT_BREATHING
508 #define BREATHING_NO_HALT 0
509 #define BREATHING_HALT_OFF 1
510 #define BREATHING_HALT_ON 2
512 static uint8_t breath_intensity;
513 static uint8_t breath_speed;
514 static uint16_t breathing_index;
515 static uint8_t breathing_halt;
517 void breathing_enable(void)
519 if (get_backlight_level() == 0)
525 // Set breathing_index to be at the midpoint (brightest point)
526 breathing_index = 0x20 << breath_speed;
529 breathing_halt = BREATHING_NO_HALT;
531 // Enable breathing interrupt
532 TIMSK1 |= _BV(OCIE1A);
535 void breathing_pulse(void)
537 if (get_backlight_level() == 0)
543 // Set breathing_index to be at the midpoint + 1 (brightest point)
544 breathing_index = 0x21 << breath_speed;
547 breathing_halt = BREATHING_HALT_ON;
549 // Enable breathing interrupt
550 TIMSK1 |= _BV(OCIE1A);
553 void breathing_disable(void)
555 // Disable breathing interrupt
556 TIMSK1 &= ~_BV(OCIE1A);
557 backlight_set(get_backlight_level());
560 void breathing_self_disable(void)
562 if (get_backlight_level() == 0)
564 breathing_halt = BREATHING_HALT_OFF;
568 breathing_halt = BREATHING_HALT_ON;
571 //backlight_set(get_backlight_level());
574 void breathing_toggle(void)
578 if (get_backlight_level() == 0)
584 // Set breathing_index to be at the midpoint + 1 (brightest point)
585 breathing_index = 0x21 << breath_speed;
588 breathing_halt = BREATHING_NO_HALT;
591 // Toggle breathing interrupt
592 TIMSK1 ^= _BV(OCIE1A);
594 // Restore backlight level
597 backlight_set(get_backlight_level());
601 bool is_breathing(void)
603 return (TIMSK1 && _BV(OCIE1A));
606 void breathing_intensity_default(void)
608 //breath_intensity = (uint8_t)((uint16_t)100 * (uint16_t)get_backlight_level() / (uint16_t)BACKLIGHT_LEVELS);
609 breath_intensity = ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2));
612 void breathing_intensity_set(uint8_t value)
614 breath_intensity = value;
617 void breathing_speed_default(void)
622 void breathing_speed_set(uint8_t value)
624 bool is_breathing_now = is_breathing();
625 uint8_t old_breath_speed = breath_speed;
627 if (is_breathing_now)
629 // Disable breathing interrupt
630 TIMSK1 &= ~_BV(OCIE1A);
633 breath_speed = value;
635 if (is_breathing_now)
637 // Adjust index to account for new speed
638 breathing_index = (( (uint8_t)( (breathing_index) >> old_breath_speed ) ) & 0x3F) << breath_speed;
640 // Enable breathing interrupt
641 TIMSK1 |= _BV(OCIE1A);
646 void breathing_speed_inc(uint8_t value)
648 if ((uint16_t)(breath_speed - value) > 10 )
650 breathing_speed_set(0);
654 breathing_speed_set(breath_speed - value);
658 void breathing_speed_dec(uint8_t value)
660 if ((uint16_t)(breath_speed + value) > 10 )
662 breathing_speed_set(10);
666 breathing_speed_set(breath_speed + value);
670 void breathing_defaults(void)
672 breathing_intensity_default();
673 breathing_speed_default();
674 breathing_halt = BREATHING_NO_HALT;
677 /* Breathing Sleep LED brighness(PWM On period) table
678 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
680 * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
681 * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
683 static const uint8_t breathing_table[64] PROGMEM = {
684 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
685 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
686 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
687 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
690 ISR(TIMER1_COMPA_vect)
692 // OCR1x = (pgm_read_byte(&breathing_table[ ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F ] )) * breath_intensity;
695 uint8_t local_index = ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F;
697 if (((breathing_halt == BREATHING_HALT_ON) && (local_index == 0x20)) || ((breathing_halt == BREATHING_HALT_OFF) && (local_index == 0x3F)))
699 // Disable breathing interrupt
700 TIMSK1 &= ~_BV(OCIE1A);
703 OCR1x = (uint16_t)(((uint16_t)pgm_read_byte(&breathing_table[local_index]) * 257)) >> breath_intensity;
713 __attribute__ ((weak))
714 void backlight_init_ports(void)
719 __attribute__ ((weak))
720 void backlight_set(uint8_t level)
729 __attribute__ ((weak))
730 void led_set_user(uint8_t usb_led) {
734 __attribute__ ((weak))
735 void led_set_kb(uint8_t usb_led) {
736 led_set_user(usb_led);
739 __attribute__ ((weak))
740 void led_init_ports(void)
745 __attribute__ ((weak))
746 void led_set(uint8_t usb_led)
751 // // Using PE6 Caps Lock LED
752 // if (usb_led & (1<<USB_LED_CAPS_LOCK))
769 //------------------------------------------------------------------------------
770 // Override these functions in your keymap file to play different tunes on
771 // different events such as startup and bootloader jump
773 __attribute__ ((weak))
774 void startup_user() {}
776 __attribute__ ((weak))
777 void shutdown_user() {}
779 //------------------------------------------------------------------------------