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)
49 /* TODO: Use store_or_get_action() or a similar function. */
50 if (!disable_action_cache) {
53 if (record->event.pressed) {
54 layer = layer_switch_get_layer(key);
55 update_source_layers_cache(key, layer);
57 layer = read_source_layers_cache(key);
59 keycode = keymap_key_to_keycode(layer, key);
62 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
64 // This is how you use actions here
65 // if (keycode == KC_LEAD) {
67 // action.code = ACTION_DEFAULT_LAYER_SET(0);
68 // process_action(record, action);
73 process_record_kb(keycode, record) &&
75 process_midi(keycode, record) &&
78 process_music(keycode, record) &&
80 #ifdef TAP_DANCE_ENABLE
81 process_tap_dance(keycode, record) &&
83 #ifndef DISABLE_LEADER
84 process_leader(keycode, record) &&
86 #ifndef DISABLE_CHORDING
87 process_chording(keycode, record) &&
90 process_unicode(keycode, record) &&
93 process_ucis(keycode, record) &&
99 // Shift / paren setup
103 if (record->event.pressed) {
109 if (record->event.pressed) {
110 print("\nDEBUG: enabled.\n");
115 #ifdef RGBLIGHT_ENABLE
117 if (record->event.pressed) {
123 if (record->event.pressed) {
129 if (record->event.pressed) {
130 rgblight_increase_hue();
135 if (record->event.pressed) {
136 rgblight_decrease_hue();
141 if (record->event.pressed) {
142 rgblight_increase_sat();
147 if (record->event.pressed) {
148 rgblight_decrease_sat();
153 if (record->event.pressed) {
154 rgblight_increase_val();
159 if (record->event.pressed) {
160 rgblight_decrease_val();
165 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
166 if (record->event.pressed) {
167 // MAGIC actions (BOOTMAGIC without the boot)
168 if (!eeconfig_is_enabled()) {
172 keymap_config.raw = eeconfig_read_keymap();
173 if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
174 keymap_config.swap_control_capslock = 1;
175 } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
176 keymap_config.capslock_to_control = 1;
177 } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
178 keymap_config.swap_lalt_lgui = 1;
179 } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
180 keymap_config.swap_ralt_rgui = 1;
181 } else if (keycode == MAGIC_NO_GUI) {
182 keymap_config.no_gui = 1;
183 } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
184 keymap_config.swap_grave_esc = 1;
185 } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
186 keymap_config.swap_backslash_backspace = 1;
187 } else if (keycode == MAGIC_HOST_NKRO) {
188 keymap_config.nkro = 1;
189 } else if (keycode == MAGIC_SWAP_ALT_GUI) {
190 keymap_config.swap_lalt_lgui = 1;
191 keymap_config.swap_ralt_rgui = 1;
194 else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
195 keymap_config.swap_control_capslock = 0;
196 } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
197 keymap_config.capslock_to_control = 0;
198 } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
199 keymap_config.swap_lalt_lgui = 0;
200 } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
201 keymap_config.swap_ralt_rgui = 0;
202 } else if (keycode == MAGIC_UNNO_GUI) {
203 keymap_config.no_gui = 0;
204 } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
205 keymap_config.swap_grave_esc = 0;
206 } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
207 keymap_config.swap_backslash_backspace = 0;
208 } else if (keycode == MAGIC_UNHOST_NKRO) {
209 keymap_config.nkro = 0;
210 } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
211 keymap_config.swap_lalt_lgui = 0;
212 keymap_config.swap_ralt_rgui = 0;
214 eeconfig_update_keymap(keymap_config.raw);
219 if (record->event.pressed) {
220 shift_interrupted[0] = false;
221 register_mods(MOD_BIT(KC_LSFT));
224 #ifdef DISABLE_SPACE_CADET_ROLLOVER
225 if (get_mods() & MOD_BIT(KC_RSFT)) {
226 shift_interrupted[0] = true;
227 shift_interrupted[1] = true;
230 if (!shift_interrupted[0]) {
231 register_code(LSPO_KEY);
232 unregister_code(LSPO_KEY);
234 unregister_mods(MOD_BIT(KC_LSFT));
241 if (record->event.pressed) {
242 shift_interrupted[1] = false;
243 register_mods(MOD_BIT(KC_RSFT));
246 #ifdef DISABLE_SPACE_CADET_ROLLOVER
247 if (get_mods() & MOD_BIT(KC_LSFT)) {
248 shift_interrupted[0] = true;
249 shift_interrupted[1] = true;
252 if (!shift_interrupted[1]) {
253 register_code(RSPC_KEY);
254 unregister_code(RSPC_KEY);
256 unregister_mods(MOD_BIT(KC_RSFT));
262 shift_interrupted[0] = true;
263 shift_interrupted[1] = true;
268 return process_action_kb(record);
271 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
272 0, 0, 0, 0, 0, 0, 0, 0,
273 0, 0, 0, 0, 0, 0, 0, 0,
274 0, 0, 0, 0, 0, 0, 0, 0,
275 0, 0, 0, 0, 0, 0, 0, 0,
276 0, 1, 1, 1, 1, 1, 1, 0,
277 1, 1, 1, 1, 0, 0, 0, 0,
278 0, 0, 0, 0, 0, 0, 0, 0,
279 0, 0, 1, 0, 1, 0, 1, 1,
280 1, 1, 1, 1, 1, 1, 1, 1,
281 1, 1, 1, 1, 1, 1, 1, 1,
282 1, 1, 1, 1, 1, 1, 1, 1,
283 1, 1, 1, 0, 0, 0, 1, 1,
284 0, 0, 0, 0, 0, 0, 0, 0,
285 0, 0, 0, 0, 0, 0, 0, 0,
286 0, 0, 0, 0, 0, 0, 0, 0,
287 0, 0, 0, 1, 1, 1, 1, 0
290 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
291 0, 0, 0, 0, 0, 0, 0, 0,
292 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
293 0, 0, 0, 0, 0, 0, 0, 0,
294 0, 0, 0, KC_ESC, 0, 0, 0, 0,
295 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
296 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
297 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
298 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
299 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
300 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
301 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
302 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
303 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
304 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
305 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
306 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
309 /* for users whose OSes are set to Colemak */
311 #include "keymap_colemak.h"
313 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
314 0, 0, 0, 0, 0, 0, 0, 0,
315 0, 0, 0, 0, 0, 0, 0, 0,
316 0, 0, 0, 0, 0, 0, 0, 0,
317 0, 0, 0, 0, 0, 0, 0, 0,
318 0, 1, 1, 1, 1, 1, 1, 0,
319 1, 1, 1, 1, 0, 0, 0, 0,
320 0, 0, 0, 0, 0, 0, 0, 0,
321 0, 0, 1, 0, 1, 0, 1, 1,
322 1, 1, 1, 1, 1, 1, 1, 1,
323 1, 1, 1, 1, 1, 1, 1, 1,
324 1, 1, 1, 1, 1, 1, 1, 1,
325 1, 1, 1, 0, 0, 0, 1, 1,
326 0, 0, 0, 0, 0, 0, 0, 0,
327 0, 0, 0, 0, 0, 0, 0, 0,
328 0, 0, 0, 0, 0, 0, 0, 0,
329 0, 0, 0, 1, 1, 1, 1, 0
332 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
333 0, 0, 0, 0, 0, 0, 0, 0,
334 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
335 0, 0, 0, 0, 0, 0, 0, 0,
336 0, 0, 0, KC_ESC, 0, 0, 0, 0,
337 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
338 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
339 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
340 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
341 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
342 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
343 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
344 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
345 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
346 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
347 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
348 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
353 void send_string(const char *str) {
356 uint8_t ascii_code = pgm_read_byte(str);
357 if (!ascii_code) break;
358 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
359 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
360 register_code(KC_LSFT);
361 register_code(keycode);
362 unregister_code(keycode);
363 unregister_code(KC_LSFT);
366 register_code(keycode);
367 unregister_code(keycode);
373 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
374 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
381 void tap_random_base64(void) {
382 #if defined(__AVR_ATmega32U4__)
383 uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
385 uint8_t key = rand() % 64;
389 register_code(KC_LSFT);
390 register_code(key + KC_A);
391 unregister_code(key + KC_A);
392 unregister_code(KC_LSFT);
395 register_code(key - 26 + KC_A);
396 unregister_code(key - 26 + KC_A);
400 unregister_code(KC_0);
403 register_code(key - 53 + KC_1);
404 unregister_code(key - 53 + KC_1);
407 register_code(KC_LSFT);
408 register_code(KC_EQL);
409 unregister_code(KC_EQL);
410 unregister_code(KC_LSFT);
413 register_code(KC_SLSH);
414 unregister_code(KC_SLSH);
419 void matrix_init_quantum() {
420 #ifdef BACKLIGHT_ENABLE
421 backlight_init_ports();
426 void matrix_scan_quantum() {
431 #ifdef TAP_DANCE_ENABLE
432 matrix_scan_tap_dance();
437 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
439 static const uint8_t backlight_pin = BACKLIGHT_PIN;
441 #if BACKLIGHT_PIN == B7
442 # define COM1x1 COM1C1
444 #elif BACKLIGHT_PIN == B6
445 # define COM1x1 COM1B1
447 #elif BACKLIGHT_PIN == B5
448 # define COM1x1 COM1A1
451 # error "Backlight pin not supported - use B5, B6, or B7"
454 __attribute__ ((weak))
455 void backlight_init_ports(void)
458 // Setup backlight pin as output and output low.
460 _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
462 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
464 // Use full 16-bit resolution.
467 // I could write a wall of text here to explain... but TL;DW
468 // Go read the ATmega32u4 datasheet.
469 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
471 // Pin PB7 = OCR1C (Timer 1, Channel C)
472 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
473 // (i.e. start high, go low when counter matches.)
474 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
475 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
477 TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
478 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
481 #ifdef BACKLIGHT_BREATHING
482 breathing_defaults();
486 __attribute__ ((weak))
487 void backlight_set(uint8_t level)
489 // Prevent backlight blink on lowest level
491 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
494 // Turn off PWM control on backlight pin, revert to output low.
495 TCCR1A &= ~(_BV(COM1x1));
497 } else if ( level == BACKLIGHT_LEVELS ) {
498 // Turn on PWM control of backlight pin
499 TCCR1A |= _BV(COM1x1);
500 // Set the brightness
503 // Turn on PWM control of backlight pin
504 TCCR1A |= _BV(COM1x1);
505 // Set the brightness
506 OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
509 #ifdef BACKLIGHT_BREATHING
510 breathing_intensity_default();
515 #ifdef BACKLIGHT_BREATHING
517 #define BREATHING_NO_HALT 0
518 #define BREATHING_HALT_OFF 1
519 #define BREATHING_HALT_ON 2
521 static uint8_t breath_intensity;
522 static uint8_t breath_speed;
523 static uint16_t breathing_index;
524 static uint8_t breathing_halt;
526 void breathing_enable(void)
528 if (get_backlight_level() == 0)
534 // Set breathing_index to be at the midpoint (brightest point)
535 breathing_index = 0x20 << breath_speed;
538 breathing_halt = BREATHING_NO_HALT;
540 // Enable breathing interrupt
541 TIMSK1 |= _BV(OCIE1A);
544 void breathing_pulse(void)
546 if (get_backlight_level() == 0)
552 // Set breathing_index to be at the midpoint + 1 (brightest point)
553 breathing_index = 0x21 << breath_speed;
556 breathing_halt = BREATHING_HALT_ON;
558 // Enable breathing interrupt
559 TIMSK1 |= _BV(OCIE1A);
562 void breathing_disable(void)
564 // Disable breathing interrupt
565 TIMSK1 &= ~_BV(OCIE1A);
566 backlight_set(get_backlight_level());
569 void breathing_self_disable(void)
571 if (get_backlight_level() == 0)
573 breathing_halt = BREATHING_HALT_OFF;
577 breathing_halt = BREATHING_HALT_ON;
580 //backlight_set(get_backlight_level());
583 void breathing_toggle(void)
587 if (get_backlight_level() == 0)
593 // Set breathing_index to be at the midpoint + 1 (brightest point)
594 breathing_index = 0x21 << breath_speed;
597 breathing_halt = BREATHING_NO_HALT;
600 // Toggle breathing interrupt
601 TIMSK1 ^= _BV(OCIE1A);
603 // Restore backlight level
606 backlight_set(get_backlight_level());
610 bool is_breathing(void)
612 return (TIMSK1 && _BV(OCIE1A));
615 void breathing_intensity_default(void)
617 //breath_intensity = (uint8_t)((uint16_t)100 * (uint16_t)get_backlight_level() / (uint16_t)BACKLIGHT_LEVELS);
618 breath_intensity = ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2));
621 void breathing_intensity_set(uint8_t value)
623 breath_intensity = value;
626 void breathing_speed_default(void)
631 void breathing_speed_set(uint8_t value)
633 bool is_breathing_now = is_breathing();
634 uint8_t old_breath_speed = breath_speed;
636 if (is_breathing_now)
638 // Disable breathing interrupt
639 TIMSK1 &= ~_BV(OCIE1A);
642 breath_speed = value;
644 if (is_breathing_now)
646 // Adjust index to account for new speed
647 breathing_index = (( (uint8_t)( (breathing_index) >> old_breath_speed ) ) & 0x3F) << breath_speed;
649 // Enable breathing interrupt
650 TIMSK1 |= _BV(OCIE1A);
655 void breathing_speed_inc(uint8_t value)
657 if ((uint16_t)(breath_speed - value) > 10 )
659 breathing_speed_set(0);
663 breathing_speed_set(breath_speed - value);
667 void breathing_speed_dec(uint8_t value)
669 if ((uint16_t)(breath_speed + value) > 10 )
671 breathing_speed_set(10);
675 breathing_speed_set(breath_speed + value);
679 void breathing_defaults(void)
681 breathing_intensity_default();
682 breathing_speed_default();
683 breathing_halt = BREATHING_NO_HALT;
686 /* Breathing Sleep LED brighness(PWM On period) table
687 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
689 * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
690 * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
692 static const uint8_t breathing_table[64] PROGMEM = {
693 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
694 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
695 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
696 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
699 ISR(TIMER1_COMPA_vect)
701 // OCR1x = (pgm_read_byte(&breathing_table[ ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F ] )) * breath_intensity;
704 uint8_t local_index = ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F;
706 if (((breathing_halt == BREATHING_HALT_ON) && (local_index == 0x20)) || ((breathing_halt == BREATHING_HALT_OFF) && (local_index == 0x3F)))
708 // Disable breathing interrupt
709 TIMSK1 &= ~_BV(OCIE1A);
712 OCR1x = (uint16_t)(((uint16_t)pgm_read_byte(&breathing_table[local_index]) * 257)) >> breath_intensity;
722 __attribute__ ((weak))
723 void backlight_init_ports(void)
728 __attribute__ ((weak))
729 void backlight_set(uint8_t level)
738 __attribute__ ((weak))
739 void led_set_user(uint8_t usb_led) {
743 __attribute__ ((weak))
744 void led_set_kb(uint8_t usb_led) {
745 led_set_user(usb_led);
748 __attribute__ ((weak))
749 void led_init_ports(void)
754 __attribute__ ((weak))
755 void led_set(uint8_t usb_led)
760 // // Using PE6 Caps Lock LED
761 // if (usb_led & (1<<USB_LED_CAPS_LOCK))
778 //------------------------------------------------------------------------------
779 // Override these functions in your keymap file to play different tunes on
780 // different events such as startup and bootloader jump
782 __attribute__ ((weak))
783 void startup_user() {}
785 __attribute__ ((weak))
786 void shutdown_user() {}
788 //------------------------------------------------------------------------------