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 void reset_keyboard(void) {
25 #ifdef CATERINA_BOOTLOADER
26 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
31 // Shift / paren setup
40 static bool shift_interrupted[2] = {0, 0};
42 bool process_record_quantum(keyrecord_t *record) {
44 /* This gets the keycode from the key pressed */
45 keypos_t key = record->event.key;
48 #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
51 if (record->event.pressed) {
52 layer = layer_switch_get_layer(key);
53 update_source_layers_cache(key, layer);
55 layer = read_source_layers_cache(key);
57 keycode = keymap_key_to_keycode(layer, key);
59 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
62 // This is how you use actions here
63 // if (keycode == KC_LEAD) {
65 // action.code = ACTION_DEFAULT_LAYER_SET(0);
66 // process_action(record, action);
71 process_record_kb(keycode, record) &&
73 process_midi(keycode, record) &&
76 process_music(keycode, record) &&
78 #ifdef TAP_DANCE_ENABLE
79 process_tap_dance(keycode, record) &&
81 #ifndef DISABLE_LEADER
82 process_leader(keycode, record) &&
84 #ifndef DISABLE_CHORDING
85 process_chording(keycode, record) &&
88 process_unicode(keycode, record) &&
91 process_ucis(keycode, record) &&
97 // Shift / paren setup
101 if (record->event.pressed) {
107 if (record->event.pressed) {
108 print("\nDEBUG: enabled.\n");
113 #ifdef RGBLIGHT_ENABLE
115 if (record->event.pressed) {
121 if (record->event.pressed) {
127 if (record->event.pressed) {
128 rgblight_increase_hue();
133 if (record->event.pressed) {
134 rgblight_decrease_hue();
139 if (record->event.pressed) {
140 rgblight_increase_sat();
145 if (record->event.pressed) {
146 rgblight_decrease_sat();
151 if (record->event.pressed) {
152 rgblight_increase_val();
157 if (record->event.pressed) {
158 rgblight_decrease_val();
163 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
164 if (record->event.pressed) {
165 // MAGIC actions (BOOTMAGIC without the boot)
166 if (!eeconfig_is_enabled()) {
170 keymap_config.raw = eeconfig_read_keymap();
171 if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
172 keymap_config.swap_control_capslock = 1;
173 } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
174 keymap_config.capslock_to_control = 1;
175 } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
176 keymap_config.swap_lalt_lgui = 1;
177 } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
178 keymap_config.swap_ralt_rgui = 1;
179 } else if (keycode == MAGIC_NO_GUI) {
180 keymap_config.no_gui = 1;
181 } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
182 keymap_config.swap_grave_esc = 1;
183 } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
184 keymap_config.swap_backslash_backspace = 1;
185 } else if (keycode == MAGIC_HOST_NKRO) {
186 keymap_config.nkro = 1;
187 } else if (keycode == MAGIC_SWAP_ALT_GUI) {
188 keymap_config.swap_lalt_lgui = 1;
189 keymap_config.swap_ralt_rgui = 1;
192 else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
193 keymap_config.swap_control_capslock = 0;
194 } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
195 keymap_config.capslock_to_control = 0;
196 } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
197 keymap_config.swap_lalt_lgui = 0;
198 } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
199 keymap_config.swap_ralt_rgui = 0;
200 } else if (keycode == MAGIC_UNNO_GUI) {
201 keymap_config.no_gui = 0;
202 } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
203 keymap_config.swap_grave_esc = 0;
204 } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
205 keymap_config.swap_backslash_backspace = 0;
206 } else if (keycode == MAGIC_UNHOST_NKRO) {
207 keymap_config.nkro = 0;
208 } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
209 keymap_config.swap_lalt_lgui = 0;
210 keymap_config.swap_ralt_rgui = 0;
212 eeconfig_update_keymap(keymap_config.raw);
217 if (record->event.pressed) {
218 shift_interrupted[0] = false;
219 register_mods(MOD_BIT(KC_LSFT));
222 #ifdef DISABLE_SPACE_CADET_ROLLOVER
223 if (get_mods() & MOD_BIT(KC_RSFT)) {
224 shift_interrupted[0] = true;
225 shift_interrupted[1] = true;
228 if (!shift_interrupted[0]) {
229 register_code(LSPO_KEY);
230 unregister_code(LSPO_KEY);
232 unregister_mods(MOD_BIT(KC_LSFT));
239 if (record->event.pressed) {
240 shift_interrupted[1] = false;
241 register_mods(MOD_BIT(KC_RSFT));
244 #ifdef DISABLE_SPACE_CADET_ROLLOVER
245 if (get_mods() & MOD_BIT(KC_LSFT)) {
246 shift_interrupted[0] = true;
247 shift_interrupted[1] = true;
250 if (!shift_interrupted[1]) {
251 register_code(RSPC_KEY);
252 unregister_code(RSPC_KEY);
254 unregister_mods(MOD_BIT(KC_RSFT));
260 shift_interrupted[0] = true;
261 shift_interrupted[1] = true;
266 return process_action_kb(record);
269 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
270 0, 0, 0, 0, 0, 0, 0, 0,
271 0, 0, 0, 0, 0, 0, 0, 0,
272 0, 0, 0, 0, 0, 0, 0, 0,
273 0, 0, 0, 0, 0, 0, 0, 0,
274 0, 1, 1, 1, 1, 1, 1, 0,
275 1, 1, 1, 1, 0, 0, 0, 0,
276 0, 0, 0, 0, 0, 0, 0, 0,
277 0, 0, 1, 0, 1, 0, 1, 1,
278 1, 1, 1, 1, 1, 1, 1, 1,
279 1, 1, 1, 1, 1, 1, 1, 1,
280 1, 1, 1, 1, 1, 1, 1, 1,
281 1, 1, 1, 0, 0, 0, 1, 1,
282 0, 0, 0, 0, 0, 0, 0, 0,
283 0, 0, 0, 0, 0, 0, 0, 0,
284 0, 0, 0, 0, 0, 0, 0, 0,
285 0, 0, 0, 1, 1, 1, 1, 0
288 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
289 0, 0, 0, 0, 0, 0, 0, 0,
290 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
291 0, 0, 0, 0, 0, 0, 0, 0,
292 0, 0, 0, KC_ESC, 0, 0, 0, 0,
293 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
294 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
295 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
296 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
297 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
298 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
299 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
300 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
301 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
302 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
303 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
304 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
307 /* for users whose OSes are set to Colemak */
309 #include "keymap_colemak.h"
311 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
312 0, 0, 0, 0, 0, 0, 0, 0,
313 0, 0, 0, 0, 0, 0, 0, 0,
314 0, 0, 0, 0, 0, 0, 0, 0,
315 0, 0, 0, 0, 0, 0, 0, 0,
316 0, 1, 1, 1, 1, 1, 1, 0,
317 1, 1, 1, 1, 0, 0, 0, 0,
318 0, 0, 0, 0, 0, 0, 0, 0,
319 0, 0, 1, 0, 1, 0, 1, 1,
320 1, 1, 1, 1, 1, 1, 1, 1,
321 1, 1, 1, 1, 1, 1, 1, 1,
322 1, 1, 1, 1, 1, 1, 1, 1,
323 1, 1, 1, 0, 0, 0, 1, 1,
324 0, 0, 0, 0, 0, 0, 0, 0,
325 0, 0, 0, 0, 0, 0, 0, 0,
326 0, 0, 0, 0, 0, 0, 0, 0,
327 0, 0, 0, 1, 1, 1, 1, 0
330 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
331 0, 0, 0, 0, 0, 0, 0, 0,
332 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
333 0, 0, 0, 0, 0, 0, 0, 0,
334 0, 0, 0, KC_ESC, 0, 0, 0, 0,
335 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
336 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
337 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
338 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
339 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
340 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
341 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
342 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
343 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
344 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
345 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
346 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
351 void send_string(const char *str) {
354 uint8_t ascii_code = pgm_read_byte(str);
355 if (!ascii_code) break;
356 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
357 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
358 register_code(KC_LSFT);
359 register_code(keycode);
360 unregister_code(keycode);
361 unregister_code(KC_LSFT);
364 register_code(keycode);
365 unregister_code(keycode);
371 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
372 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
379 void tap_random_base64(void) {
380 #if defined(__AVR_ATmega32U4__)
381 uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
383 uint8_t key = rand() % 64;
387 register_code(KC_LSFT);
388 register_code(key + KC_A);
389 unregister_code(key + KC_A);
390 unregister_code(KC_LSFT);
393 register_code(key - 26 + KC_A);
394 unregister_code(key - 26 + KC_A);
398 unregister_code(KC_0);
401 register_code(key - 53 + KC_1);
402 unregister_code(key - 53 + KC_1);
405 register_code(KC_LSFT);
406 register_code(KC_EQL);
407 unregister_code(KC_EQL);
408 unregister_code(KC_LSFT);
411 register_code(KC_SLSH);
412 unregister_code(KC_SLSH);
417 void matrix_init_quantum() {
418 #ifdef BACKLIGHT_ENABLE
419 backlight_init_ports();
424 void matrix_scan_quantum() {
429 #ifdef TAP_DANCE_ENABLE
430 matrix_scan_tap_dance();
435 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
437 static const uint8_t backlight_pin = BACKLIGHT_PIN;
439 #if BACKLIGHT_PIN == B7
440 # define COM1x1 COM1C1
442 #elif BACKLIGHT_PIN == B6
443 # define COM1x1 COM1B1
445 #elif BACKLIGHT_PIN == B5
446 # define COM1x1 COM1A1
449 # error "Backlight pin not supported - use B5, B6, or B7"
452 __attribute__ ((weak))
453 void backlight_init_ports(void)
456 // Setup backlight pin as output and output low.
458 _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
460 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
462 // Use full 16-bit resolution.
465 // I could write a wall of text here to explain... but TL;DW
466 // Go read the ATmega32u4 datasheet.
467 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
469 // Pin PB7 = OCR1C (Timer 1, Channel C)
470 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
471 // (i.e. start high, go low when counter matches.)
472 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
473 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
475 TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
476 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
479 #ifdef BACKLIGHT_BREATHING
480 breathing_defaults();
484 __attribute__ ((weak))
485 void backlight_set(uint8_t level)
487 // Prevent backlight blink on lowest level
489 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
492 // Turn off PWM control on backlight pin, revert to output low.
493 TCCR1A &= ~(_BV(COM1x1));
495 } else if ( level == BACKLIGHT_LEVELS ) {
496 // Turn on PWM control of backlight pin
497 TCCR1A |= _BV(COM1x1);
498 // Set the brightness
501 // Turn on PWM control of backlight pin
502 TCCR1A |= _BV(COM1x1);
503 // Set the brightness
504 OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
507 #ifdef BACKLIGHT_BREATHING
508 breathing_intensity_default();
513 #ifdef BACKLIGHT_BREATHING
515 #define BREATHING_NO_HALT 0
516 #define BREATHING_HALT_OFF 1
517 #define BREATHING_HALT_ON 2
519 static uint8_t breath_intensity;
520 static uint8_t breath_speed;
521 static uint16_t breathing_index;
522 static uint8_t breathing_halt;
524 void breathing_enable(void)
526 if (get_backlight_level() == 0)
532 // Set breathing_index to be at the midpoint (brightest point)
533 breathing_index = 0x20 << breath_speed;
536 breathing_halt = BREATHING_NO_HALT;
538 // Enable breathing interrupt
539 TIMSK1 |= _BV(OCIE1A);
542 void breathing_pulse(void)
544 if (get_backlight_level() == 0)
550 // Set breathing_index to be at the midpoint + 1 (brightest point)
551 breathing_index = 0x21 << breath_speed;
554 breathing_halt = BREATHING_HALT_ON;
556 // Enable breathing interrupt
557 TIMSK1 |= _BV(OCIE1A);
560 void breathing_disable(void)
562 // Disable breathing interrupt
563 TIMSK1 &= ~_BV(OCIE1A);
564 backlight_set(get_backlight_level());
567 void breathing_self_disable(void)
569 if (get_backlight_level() == 0)
571 breathing_halt = BREATHING_HALT_OFF;
575 breathing_halt = BREATHING_HALT_ON;
578 //backlight_set(get_backlight_level());
581 void breathing_toggle(void)
585 if (get_backlight_level() == 0)
591 // Set breathing_index to be at the midpoint + 1 (brightest point)
592 breathing_index = 0x21 << breath_speed;
595 breathing_halt = BREATHING_NO_HALT;
598 // Toggle breathing interrupt
599 TIMSK1 ^= _BV(OCIE1A);
601 // Restore backlight level
604 backlight_set(get_backlight_level());
608 bool is_breathing(void)
610 return (TIMSK1 && _BV(OCIE1A));
613 void breathing_intensity_default(void)
615 //breath_intensity = (uint8_t)((uint16_t)100 * (uint16_t)get_backlight_level() / (uint16_t)BACKLIGHT_LEVELS);
616 breath_intensity = ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2));
619 void breathing_intensity_set(uint8_t value)
621 breath_intensity = value;
624 void breathing_speed_default(void)
629 void breathing_speed_set(uint8_t value)
631 bool is_breathing_now = is_breathing();
632 uint8_t old_breath_speed = breath_speed;
634 if (is_breathing_now)
636 // Disable breathing interrupt
637 TIMSK1 &= ~_BV(OCIE1A);
640 breath_speed = value;
642 if (is_breathing_now)
644 // Adjust index to account for new speed
645 breathing_index = (( (uint8_t)( (breathing_index) >> old_breath_speed ) ) & 0x3F) << breath_speed;
647 // Enable breathing interrupt
648 TIMSK1 |= _BV(OCIE1A);
653 void breathing_speed_inc(uint8_t value)
655 if ((uint16_t)(breath_speed - value) > 10 )
657 breathing_speed_set(0);
661 breathing_speed_set(breath_speed - value);
665 void breathing_speed_dec(uint8_t value)
667 if ((uint16_t)(breath_speed + value) > 10 )
669 breathing_speed_set(10);
673 breathing_speed_set(breath_speed + value);
677 void breathing_defaults(void)
679 breathing_intensity_default();
680 breathing_speed_default();
681 breathing_halt = BREATHING_NO_HALT;
684 /* Breathing Sleep LED brighness(PWM On period) table
685 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
687 * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
688 * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
690 static const uint8_t breathing_table[64] PROGMEM = {
691 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
692 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
693 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
694 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
697 ISR(TIMER1_COMPA_vect)
699 // OCR1x = (pgm_read_byte(&breathing_table[ ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F ] )) * breath_intensity;
702 uint8_t local_index = ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F;
704 if (((breathing_halt == BREATHING_HALT_ON) && (local_index == 0x20)) || ((breathing_halt == BREATHING_HALT_OFF) && (local_index == 0x3F)))
706 // Disable breathing interrupt
707 TIMSK1 &= ~_BV(OCIE1A);
710 OCR1x = (uint16_t)(((uint16_t)pgm_read_byte(&breathing_table[local_index]) * 257)) >> breath_intensity;
720 __attribute__ ((weak))
721 void backlight_init_ports(void)
726 __attribute__ ((weak))
727 void backlight_set(uint8_t level)
736 __attribute__ ((weak))
737 void led_set_user(uint8_t usb_led) {
741 __attribute__ ((weak))
742 void led_set_kb(uint8_t usb_led) {
743 led_set_user(usb_led);
746 __attribute__ ((weak))
747 void led_init_ports(void)
752 __attribute__ ((weak))
753 void led_set(uint8_t usb_led)
758 // // Using PE6 Caps Lock LED
759 // if (usb_led & (1<<USB_LED_CAPS_LOCK))
776 //------------------------------------------------------------------------------
777 // Override these functions in your keymap file to play different tunes on
778 // different events such as startup and bootloader jump
780 __attribute__ ((weak))
781 void startup_user() {}
783 __attribute__ ((weak))
784 void shutdown_user() {}
786 //------------------------------------------------------------------------------