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) &&
94 // Shift / paren setup
98 if (record->event.pressed) {
104 if (record->event.pressed) {
105 print("\nDEBUG: enabled.\n");
110 #ifdef RGBLIGHT_ENABLE
112 if (record->event.pressed) {
118 if (record->event.pressed) {
124 if (record->event.pressed) {
125 rgblight_increase_hue();
130 if (record->event.pressed) {
131 rgblight_decrease_hue();
136 if (record->event.pressed) {
137 rgblight_increase_sat();
142 if (record->event.pressed) {
143 rgblight_decrease_sat();
148 if (record->event.pressed) {
149 rgblight_increase_val();
154 if (record->event.pressed) {
155 rgblight_decrease_val();
160 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
161 if (record->event.pressed) {
162 // MAGIC actions (BOOTMAGIC without the boot)
163 if (!eeconfig_is_enabled()) {
167 keymap_config.raw = eeconfig_read_keymap();
168 if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
169 keymap_config.swap_control_capslock = 1;
170 } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
171 keymap_config.capslock_to_control = 1;
172 } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
173 keymap_config.swap_lalt_lgui = 1;
174 } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
175 keymap_config.swap_ralt_rgui = 1;
176 } else if (keycode == MAGIC_NO_GUI) {
177 keymap_config.no_gui = 1;
178 } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
179 keymap_config.swap_grave_esc = 1;
180 } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
181 keymap_config.swap_backslash_backspace = 1;
182 } else if (keycode == MAGIC_HOST_NKRO) {
183 keymap_config.nkro = 1;
184 } else if (keycode == MAGIC_SWAP_ALT_GUI) {
185 keymap_config.swap_lalt_lgui = 1;
186 keymap_config.swap_ralt_rgui = 1;
189 else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
190 keymap_config.swap_control_capslock = 0;
191 } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
192 keymap_config.capslock_to_control = 0;
193 } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
194 keymap_config.swap_lalt_lgui = 0;
195 } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
196 keymap_config.swap_ralt_rgui = 0;
197 } else if (keycode == MAGIC_UNNO_GUI) {
198 keymap_config.no_gui = 0;
199 } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
200 keymap_config.swap_grave_esc = 0;
201 } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
202 keymap_config.swap_backslash_backspace = 0;
203 } else if (keycode == MAGIC_UNHOST_NKRO) {
204 keymap_config.nkro = 0;
205 } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
206 keymap_config.swap_lalt_lgui = 0;
207 keymap_config.swap_ralt_rgui = 0;
209 eeconfig_update_keymap(keymap_config.raw);
214 if (record->event.pressed) {
215 shift_interrupted[0] = false;
216 register_mods(MOD_BIT(KC_LSFT));
219 #ifdef DISABLE_SPACE_CADET_ROLLOVER
220 if (get_mods() & MOD_BIT(KC_RSFT)) {
221 shift_interrupted[0] = true;
222 shift_interrupted[1] = true;
225 if (!shift_interrupted[0]) {
226 register_code(LSPO_KEY);
227 unregister_code(LSPO_KEY);
229 unregister_mods(MOD_BIT(KC_LSFT));
236 if (record->event.pressed) {
237 shift_interrupted[1] = false;
238 register_mods(MOD_BIT(KC_RSFT));
241 #ifdef DISABLE_SPACE_CADET_ROLLOVER
242 if (get_mods() & MOD_BIT(KC_LSFT)) {
243 shift_interrupted[0] = true;
244 shift_interrupted[1] = true;
247 if (!shift_interrupted[1]) {
248 register_code(RSPC_KEY);
249 unregister_code(RSPC_KEY);
251 unregister_mods(MOD_BIT(KC_RSFT));
257 shift_interrupted[0] = true;
258 shift_interrupted[1] = true;
263 return process_action_kb(record);
266 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
267 0, 0, 0, 0, 0, 0, 0, 0,
268 0, 0, 0, 0, 0, 0, 0, 0,
269 0, 0, 0, 0, 0, 0, 0, 0,
270 0, 0, 0, 0, 0, 0, 0, 0,
271 0, 1, 1, 1, 1, 1, 1, 0,
272 1, 1, 1, 1, 0, 0, 0, 0,
273 0, 0, 0, 0, 0, 0, 0, 0,
274 0, 0, 1, 0, 1, 0, 1, 1,
275 1, 1, 1, 1, 1, 1, 1, 1,
276 1, 1, 1, 1, 1, 1, 1, 1,
277 1, 1, 1, 1, 1, 1, 1, 1,
278 1, 1, 1, 0, 0, 0, 1, 1,
279 0, 0, 0, 0, 0, 0, 0, 0,
280 0, 0, 0, 0, 0, 0, 0, 0,
281 0, 0, 0, 0, 0, 0, 0, 0,
282 0, 0, 0, 1, 1, 1, 1, 0
285 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
286 0, 0, 0, 0, 0, 0, 0, 0,
287 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
288 0, 0, 0, 0, 0, 0, 0, 0,
289 0, 0, 0, KC_ESC, 0, 0, 0, 0,
290 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
291 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
292 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
293 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
294 KC_2, 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_6, KC_MINS,
298 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
299 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
300 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
301 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
304 /* for users whose OSes are set to Colemak */
306 #include "keymap_colemak.h"
308 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
309 0, 0, 0, 0, 0, 0, 0, 0,
310 0, 0, 0, 0, 0, 0, 0, 0,
311 0, 0, 0, 0, 0, 0, 0, 0,
312 0, 0, 0, 0, 0, 0, 0, 0,
313 0, 1, 1, 1, 1, 1, 1, 0,
314 1, 1, 1, 1, 0, 0, 0, 0,
315 0, 0, 0, 0, 0, 0, 0, 0,
316 0, 0, 1, 0, 1, 0, 1, 1,
317 1, 1, 1, 1, 1, 1, 1, 1,
318 1, 1, 1, 1, 1, 1, 1, 1,
319 1, 1, 1, 1, 1, 1, 1, 1,
320 1, 1, 1, 0, 0, 0, 1, 1,
321 0, 0, 0, 0, 0, 0, 0, 0,
322 0, 0, 0, 0, 0, 0, 0, 0,
323 0, 0, 0, 0, 0, 0, 0, 0,
324 0, 0, 0, 1, 1, 1, 1, 0
327 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
328 0, 0, 0, 0, 0, 0, 0, 0,
329 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
330 0, 0, 0, 0, 0, 0, 0, 0,
331 0, 0, 0, KC_ESC, 0, 0, 0, 0,
332 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
333 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
334 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
335 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
336 KC_2, 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_6, KC_MINS,
340 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
341 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
342 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
343 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
348 void send_string(const char *str) {
351 uint8_t ascii_code = pgm_read_byte(str);
352 if (!ascii_code) break;
353 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
354 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
355 register_code(KC_LSFT);
356 register_code(keycode);
357 unregister_code(keycode);
358 unregister_code(KC_LSFT);
361 register_code(keycode);
362 unregister_code(keycode);
368 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
369 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
376 void tap_random_base64(void) {
377 #if defined(__AVR_ATmega32U4__)
378 uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
380 uint8_t key = rand() % 64;
384 register_code(KC_LSFT);
385 register_code(key + KC_A);
386 unregister_code(key + KC_A);
387 unregister_code(KC_LSFT);
390 register_code(key - 26 + KC_A);
391 unregister_code(key - 26 + KC_A);
395 unregister_code(KC_0);
398 register_code(key - 53 + KC_1);
399 unregister_code(key - 53 + KC_1);
402 register_code(KC_LSFT);
403 register_code(KC_EQL);
404 unregister_code(KC_EQL);
405 unregister_code(KC_LSFT);
408 register_code(KC_SLSH);
409 unregister_code(KC_SLSH);
414 void matrix_init_quantum() {
415 #ifdef BACKLIGHT_ENABLE
416 backlight_init_ports();
421 void matrix_scan_quantum() {
426 #ifdef TAP_DANCE_ENABLE
427 matrix_scan_tap_dance();
432 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
434 static const uint8_t backlight_pin = BACKLIGHT_PIN;
436 #if BACKLIGHT_PIN == B7
437 # define COM1x1 COM1C1
439 #elif BACKLIGHT_PIN == B6
440 # define COM1x1 COM1B1
442 #elif BACKLIGHT_PIN == B5
443 # define COM1x1 COM1A1
446 # error "Backlight pin not supported - use B5, B6, or B7"
449 __attribute__ ((weak))
450 void backlight_init_ports(void)
453 // Setup backlight pin as output and output low.
455 _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
457 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
459 // Use full 16-bit resolution.
462 // I could write a wall of text here to explain... but TL;DW
463 // Go read the ATmega32u4 datasheet.
464 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
466 // Pin PB7 = OCR1C (Timer 1, Channel C)
467 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
468 // (i.e. start high, go low when counter matches.)
469 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
470 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
472 TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
473 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
476 #ifdef BACKLIGHT_BREATHING
477 breathing_defaults();
481 __attribute__ ((weak))
482 void backlight_set(uint8_t level)
484 // Prevent backlight blink on lowest level
486 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
489 // Turn off PWM control on backlight pin, revert to output low.
490 TCCR1A &= ~(_BV(COM1x1));
492 } else if ( level == BACKLIGHT_LEVELS ) {
493 // Turn on PWM control of backlight pin
494 TCCR1A |= _BV(COM1x1);
495 // Set the brightness
498 // Turn on PWM control of backlight pin
499 TCCR1A |= _BV(COM1x1);
500 // Set the brightness
501 OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
504 #ifdef BACKLIGHT_BREATHING
505 breathing_intensity_default();
510 #ifdef BACKLIGHT_BREATHING
512 #define BREATHING_NO_HALT 0
513 #define BREATHING_HALT_OFF 1
514 #define BREATHING_HALT_ON 2
516 static uint8_t breath_intensity;
517 static uint8_t breath_speed;
518 static uint16_t breathing_index;
519 static uint8_t breathing_halt;
521 void breathing_enable(void)
523 if (get_backlight_level() == 0)
529 // Set breathing_index to be at the midpoint (brightest point)
530 breathing_index = 0x20 << breath_speed;
533 breathing_halt = BREATHING_NO_HALT;
535 // Enable breathing interrupt
536 TIMSK1 |= _BV(OCIE1A);
539 void breathing_pulse(void)
541 if (get_backlight_level() == 0)
547 // Set breathing_index to be at the midpoint + 1 (brightest point)
548 breathing_index = 0x21 << breath_speed;
551 breathing_halt = BREATHING_HALT_ON;
553 // Enable breathing interrupt
554 TIMSK1 |= _BV(OCIE1A);
557 void breathing_disable(void)
559 // Disable breathing interrupt
560 TIMSK1 &= ~_BV(OCIE1A);
561 backlight_set(get_backlight_level());
564 void breathing_self_disable(void)
566 if (get_backlight_level() == 0)
568 breathing_halt = BREATHING_HALT_OFF;
572 breathing_halt = BREATHING_HALT_ON;
575 //backlight_set(get_backlight_level());
578 void breathing_toggle(void)
582 if (get_backlight_level() == 0)
588 // Set breathing_index to be at the midpoint + 1 (brightest point)
589 breathing_index = 0x21 << breath_speed;
592 breathing_halt = BREATHING_NO_HALT;
595 // Toggle breathing interrupt
596 TIMSK1 ^= _BV(OCIE1A);
598 // Restore backlight level
601 backlight_set(get_backlight_level());
605 bool is_breathing(void)
607 return (TIMSK1 && _BV(OCIE1A));
610 void breathing_intensity_default(void)
612 //breath_intensity = (uint8_t)((uint16_t)100 * (uint16_t)get_backlight_level() / (uint16_t)BACKLIGHT_LEVELS);
613 breath_intensity = ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2));
616 void breathing_intensity_set(uint8_t value)
618 breath_intensity = value;
621 void breathing_speed_default(void)
626 void breathing_speed_set(uint8_t value)
628 bool is_breathing_now = is_breathing();
629 uint8_t old_breath_speed = breath_speed;
631 if (is_breathing_now)
633 // Disable breathing interrupt
634 TIMSK1 &= ~_BV(OCIE1A);
637 breath_speed = value;
639 if (is_breathing_now)
641 // Adjust index to account for new speed
642 breathing_index = (( (uint8_t)( (breathing_index) >> old_breath_speed ) ) & 0x3F) << breath_speed;
644 // Enable breathing interrupt
645 TIMSK1 |= _BV(OCIE1A);
650 void breathing_speed_inc(uint8_t value)
652 if ((uint16_t)(breath_speed - value) > 10 )
654 breathing_speed_set(0);
658 breathing_speed_set(breath_speed - value);
662 void breathing_speed_dec(uint8_t value)
664 if ((uint16_t)(breath_speed + value) > 10 )
666 breathing_speed_set(10);
670 breathing_speed_set(breath_speed + value);
674 void breathing_defaults(void)
676 breathing_intensity_default();
677 breathing_speed_default();
678 breathing_halt = BREATHING_NO_HALT;
681 /* Breathing Sleep LED brighness(PWM On period) table
682 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
684 * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
685 * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
687 static const uint8_t breathing_table[64] PROGMEM = {
688 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
689 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
690 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
691 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
694 ISR(TIMER1_COMPA_vect)
696 // OCR1x = (pgm_read_byte(&breathing_table[ ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F ] )) * breath_intensity;
699 uint8_t local_index = ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F;
701 if (((breathing_halt == BREATHING_HALT_ON) && (local_index == 0x20)) || ((breathing_halt == BREATHING_HALT_OFF) && (local_index == 0x3F)))
703 // Disable breathing interrupt
704 TIMSK1 &= ~_BV(OCIE1A);
707 OCR1x = (uint16_t)(((uint16_t)pgm_read_byte(&breathing_table[local_index]) * 257)) >> breath_intensity;
717 __attribute__ ((weak))
718 void backlight_init_ports(void)
723 __attribute__ ((weak))
724 void backlight_set(uint8_t level)
733 __attribute__ ((weak))
734 void led_set_user(uint8_t usb_led) {
738 __attribute__ ((weak))
739 void led_set_kb(uint8_t usb_led) {
740 led_set_user(usb_led);
743 __attribute__ ((weak))
744 void led_init_ports(void)
749 __attribute__ ((weak))
750 void led_set(uint8_t usb_led)
755 // // Using PE6 Caps Lock LED
756 // if (usb_led & (1<<USB_LED_CAPS_LOCK))
773 //------------------------------------------------------------------------------
774 // Override these functions in your keymap file to play different tunes on
775 // different events such as startup and bootloader jump
777 __attribute__ ((weak))
778 void startup_user() {}
780 __attribute__ ((weak))
781 void shutdown_user() {}
783 //------------------------------------------------------------------------------