3 #include "outputselect.h"
7 #define TAPPING_TERM 200
10 #include "backlight.h"
11 extern backlight_config_t backlight_config;
13 #ifdef FAUXCLICKY_ENABLE
14 #include "fauxclicky.h"
17 static void do_code16 (uint16_t code, void (*f) (uint8_t)) {
19 case QK_MODS ... QK_MODS_MAX:
34 if (code < QK_RMODS_MIN) return;
46 static inline void qk_register_weak_mods(uint8_t kc) {
47 add_weak_mods(MOD_BIT(kc));
48 send_keyboard_report();
51 static inline void qk_unregister_weak_mods(uint8_t kc) {
52 del_weak_mods(MOD_BIT(kc));
53 send_keyboard_report();
56 static inline void qk_register_mods(uint8_t kc) {
57 add_weak_mods(MOD_BIT(kc));
58 send_keyboard_report();
61 static inline void qk_unregister_mods(uint8_t kc) {
62 del_weak_mods(MOD_BIT(kc));
63 send_keyboard_report();
66 void register_code16 (uint16_t code) {
67 if (IS_MOD(code) || code == KC_NO) {
68 do_code16 (code, qk_register_mods);
70 do_code16 (code, qk_register_weak_mods);
75 void unregister_code16 (uint16_t code) {
76 unregister_code (code);
77 if (IS_MOD(code) || code == KC_NO) {
78 do_code16 (code, qk_unregister_mods);
80 do_code16 (code, qk_unregister_weak_mods);
84 __attribute__ ((weak))
85 bool process_action_kb(keyrecord_t *record) {
89 __attribute__ ((weak))
90 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
91 return process_record_user(keycode, record);
94 __attribute__ ((weak))
95 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
99 void reset_keyboard(void) {
106 #ifdef CATERINA_BOOTLOADER
107 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
112 // Shift / paren setup
115 #define LSPO_KEY KC_9
118 #define RSPC_KEY KC_0
121 static bool shift_interrupted[2] = {0, 0};
122 static uint16_t scs_timer = 0;
124 bool process_record_quantum(keyrecord_t *record) {
126 /* This gets the keycode from the key pressed */
127 keypos_t key = record->event.key;
130 #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
131 /* TODO: Use store_or_get_action() or a similar function. */
132 if (!disable_action_cache) {
135 if (record->event.pressed) {
136 layer = layer_switch_get_layer(key);
137 update_source_layers_cache(key, layer);
139 layer = read_source_layers_cache(key);
141 keycode = keymap_key_to_keycode(layer, key);
144 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
146 // This is how you use actions here
147 // if (keycode == KC_LEAD) {
149 // action.code = ACTION_DEFAULT_LAYER_SET(0);
150 // process_action(record, action);
155 process_record_kb(keycode, record) &&
157 process_midi(keycode, record) &&
160 process_music(keycode, record) &&
162 #ifdef TAP_DANCE_ENABLE
163 process_tap_dance(keycode, record) &&
165 #ifndef DISABLE_LEADER
166 process_leader(keycode, record) &&
168 #ifndef DISABLE_CHORDING
169 process_chording(keycode, record) &&
172 process_combo(keycode, record) &&
174 #ifdef UNICODE_ENABLE
175 process_unicode(keycode, record) &&
178 process_ucis(keycode, record) &&
180 #ifdef PRINTING_ENABLE
181 process_printer(keycode, record) &&
183 #ifdef UNICODEMAP_ENABLE
184 process_unicode_map(keycode, record) &&
190 // Shift / paren setup
194 if (record->event.pressed) {
200 if (record->event.pressed) {
201 print("\nDEBUG: enabled.\n");
206 #ifdef FAUXCLICKY_ENABLE
208 if (record->event.pressed) {
214 if (record->event.pressed) {
220 if (record->event.pressed) {
226 #ifdef RGBLIGHT_ENABLE
228 if (record->event.pressed) {
234 if (record->event.pressed) {
240 if (record->event.pressed) {
241 rgblight_increase_hue();
246 if (record->event.pressed) {
247 rgblight_decrease_hue();
252 if (record->event.pressed) {
253 rgblight_increase_sat();
258 if (record->event.pressed) {
259 rgblight_decrease_sat();
264 if (record->event.pressed) {
265 rgblight_increase_val();
270 if (record->event.pressed) {
271 rgblight_decrease_val();
278 if (record->event.pressed) {
279 set_output(OUTPUT_AUTO);
284 if (record->event.pressed) {
285 set_output(OUTPUT_USB);
289 #ifdef BLUETOOTH_ENABLE
291 if (record->event.pressed) {
292 set_output(OUTPUT_BLUETOOTH);
298 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO:
299 if (record->event.pressed) {
300 // MAGIC actions (BOOTMAGIC without the boot)
301 if (!eeconfig_is_enabled()) {
305 keymap_config.raw = eeconfig_read_keymap();
308 case MAGIC_SWAP_CONTROL_CAPSLOCK:
309 keymap_config.swap_control_capslock = true;
311 case MAGIC_CAPSLOCK_TO_CONTROL:
312 keymap_config.capslock_to_control = true;
314 case MAGIC_SWAP_LALT_LGUI:
315 keymap_config.swap_lalt_lgui = true;
317 case MAGIC_SWAP_RALT_RGUI:
318 keymap_config.swap_ralt_rgui = true;
321 keymap_config.no_gui = true;
323 case MAGIC_SWAP_GRAVE_ESC:
324 keymap_config.swap_grave_esc = true;
326 case MAGIC_SWAP_BACKSLASH_BACKSPACE:
327 keymap_config.swap_backslash_backspace = true;
329 case MAGIC_HOST_NKRO:
330 keymap_config.nkro = true;
332 case MAGIC_SWAP_ALT_GUI:
333 keymap_config.swap_lalt_lgui = true;
334 keymap_config.swap_ralt_rgui = true;
336 case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
337 keymap_config.swap_control_capslock = false;
339 case MAGIC_UNCAPSLOCK_TO_CONTROL:
340 keymap_config.capslock_to_control = false;
342 case MAGIC_UNSWAP_LALT_LGUI:
343 keymap_config.swap_lalt_lgui = false;
345 case MAGIC_UNSWAP_RALT_RGUI:
346 keymap_config.swap_ralt_rgui = false;
349 keymap_config.no_gui = false;
351 case MAGIC_UNSWAP_GRAVE_ESC:
352 keymap_config.swap_grave_esc = false;
354 case MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
355 keymap_config.swap_backslash_backspace = false;
357 case MAGIC_UNHOST_NKRO:
358 keymap_config.nkro = false;
360 case MAGIC_UNSWAP_ALT_GUI:
361 keymap_config.swap_lalt_lgui = false;
362 keymap_config.swap_ralt_rgui = false;
364 case MAGIC_TOGGLE_NKRO:
365 keymap_config.nkro = !keymap_config.nkro;
370 eeconfig_update_keymap(keymap_config.raw);
371 clear_keyboard(); // clear to prevent stuck keys
377 if (record->event.pressed) {
378 shift_interrupted[0] = false;
379 scs_timer = timer_read ();
380 register_mods(MOD_BIT(KC_LSFT));
383 #ifdef DISABLE_SPACE_CADET_ROLLOVER
384 if (get_mods() & MOD_BIT(KC_RSFT)) {
385 shift_interrupted[0] = true;
386 shift_interrupted[1] = true;
389 if (!shift_interrupted[0] && timer_elapsed(scs_timer) < TAPPING_TERM) {
390 register_code(LSPO_KEY);
391 unregister_code(LSPO_KEY);
393 unregister_mods(MOD_BIT(KC_LSFT));
400 if (record->event.pressed) {
401 shift_interrupted[1] = false;
402 scs_timer = timer_read ();
403 register_mods(MOD_BIT(KC_RSFT));
406 #ifdef DISABLE_SPACE_CADET_ROLLOVER
407 if (get_mods() & MOD_BIT(KC_LSFT)) {
408 shift_interrupted[0] = true;
409 shift_interrupted[1] = true;
412 if (!shift_interrupted[1] && timer_elapsed(scs_timer) < TAPPING_TERM) {
413 register_code(RSPC_KEY);
414 unregister_code(RSPC_KEY);
416 unregister_mods(MOD_BIT(KC_RSFT));
422 shift_interrupted[0] = true;
423 shift_interrupted[1] = true;
428 return process_action_kb(record);
431 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
432 0, 0, 0, 0, 0, 0, 0, 0,
433 0, 0, 0, 0, 0, 0, 0, 0,
434 0, 0, 0, 0, 0, 0, 0, 0,
435 0, 0, 0, 0, 0, 0, 0, 0,
436 0, 1, 1, 1, 1, 1, 1, 0,
437 1, 1, 1, 1, 0, 0, 0, 0,
438 0, 0, 0, 0, 0, 0, 0, 0,
439 0, 0, 1, 0, 1, 0, 1, 1,
440 1, 1, 1, 1, 1, 1, 1, 1,
441 1, 1, 1, 1, 1, 1, 1, 1,
442 1, 1, 1, 1, 1, 1, 1, 1,
443 1, 1, 1, 0, 0, 0, 1, 1,
444 0, 0, 0, 0, 0, 0, 0, 0,
445 0, 0, 0, 0, 0, 0, 0, 0,
446 0, 0, 0, 0, 0, 0, 0, 0,
447 0, 0, 0, 1, 1, 1, 1, 0
450 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
451 0, 0, 0, 0, 0, 0, 0, 0,
452 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
453 0, 0, 0, 0, 0, 0, 0, 0,
454 0, 0, 0, KC_ESC, 0, 0, 0, 0,
455 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
456 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
457 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
458 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
459 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
460 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
461 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
462 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
463 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
464 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
465 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
466 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
469 /* for users whose OSes are set to Colemak */
471 #include "keymap_colemak.h"
473 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
474 0, 0, 0, 0, 0, 0, 0, 0,
475 0, 0, 0, 0, 0, 0, 0, 0,
476 0, 0, 0, 0, 0, 0, 0, 0,
477 0, 0, 0, 0, 0, 0, 0, 0,
478 0, 1, 1, 1, 1, 1, 1, 0,
479 1, 1, 1, 1, 0, 0, 0, 0,
480 0, 0, 0, 0, 0, 0, 0, 0,
481 0, 0, 1, 0, 1, 0, 1, 1,
482 1, 1, 1, 1, 1, 1, 1, 1,
483 1, 1, 1, 1, 1, 1, 1, 1,
484 1, 1, 1, 1, 1, 1, 1, 1,
485 1, 1, 1, 0, 0, 0, 1, 1,
486 0, 0, 0, 0, 0, 0, 0, 0,
487 0, 0, 0, 0, 0, 0, 0, 0,
488 0, 0, 0, 0, 0, 0, 0, 0,
489 0, 0, 0, 1, 1, 1, 1, 0
492 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
493 0, 0, 0, 0, 0, 0, 0, 0,
494 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
495 0, 0, 0, 0, 0, 0, 0, 0,
496 0, 0, 0, KC_ESC, 0, 0, 0, 0,
497 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
498 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
499 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
500 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
501 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
502 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
503 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
504 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
505 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
506 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
507 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
508 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
513 void send_string(const char *str) {
516 uint8_t ascii_code = pgm_read_byte(str);
517 if (!ascii_code) break;
518 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
519 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
520 register_code(KC_LSFT);
521 register_code(keycode);
522 unregister_code(keycode);
523 unregister_code(KC_LSFT);
526 register_code(keycode);
527 unregister_code(keycode);
533 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
534 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
541 void tap_random_base64(void) {
542 #if defined(__AVR_ATmega32U4__)
543 uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
545 uint8_t key = rand() % 64;
549 register_code(KC_LSFT);
550 register_code(key + KC_A);
551 unregister_code(key + KC_A);
552 unregister_code(KC_LSFT);
555 register_code(key - 26 + KC_A);
556 unregister_code(key - 26 + KC_A);
560 unregister_code(KC_0);
563 register_code(key - 53 + KC_1);
564 unregister_code(key - 53 + KC_1);
567 register_code(KC_LSFT);
568 register_code(KC_EQL);
569 unregister_code(KC_EQL);
570 unregister_code(KC_LSFT);
573 register_code(KC_SLSH);
574 unregister_code(KC_SLSH);
579 void matrix_init_quantum() {
580 #ifdef BACKLIGHT_ENABLE
581 backlight_init_ports();
586 void matrix_scan_quantum() {
591 #ifdef TAP_DANCE_ENABLE
592 matrix_scan_tap_dance();
599 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
606 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
608 static const uint8_t backlight_pin = BACKLIGHT_PIN;
610 #if BACKLIGHT_PIN == B7
611 # define COM1x1 COM1C1
613 #elif BACKLIGHT_PIN == B6
614 # define COM1x1 COM1B1
616 #elif BACKLIGHT_PIN == B5
617 # define COM1x1 COM1A1
620 # define NO_BACKLIGHT_CLOCK
623 #ifndef BACKLIGHT_ON_STATE
624 #define BACKLIGHT_ON_STATE 0
627 __attribute__ ((weak))
628 void backlight_init_ports(void)
631 // Setup backlight pin as output and output to on state.
633 _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
634 #if BACKLIGHT_ON_STATE == 0
636 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
639 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
642 #ifndef NO_BACKLIGHT_CLOCK
643 // Use full 16-bit resolution.
646 // I could write a wall of text here to explain... but TL;DW
647 // Go read the ATmega32u4 datasheet.
648 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
650 // Pin PB7 = OCR1C (Timer 1, Channel C)
651 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
652 // (i.e. start high, go low when counter matches.)
653 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
654 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
656 TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
657 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
661 #ifdef BACKLIGHT_BREATHING
662 breathing_defaults();
666 __attribute__ ((weak))
667 void backlight_set(uint8_t level)
669 // Prevent backlight blink on lowest level
670 // #if BACKLIGHT_ON_STATE == 0
672 // _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
675 // _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
679 #ifndef NO_BACKLIGHT_CLOCK
680 // Turn off PWM control on backlight pin, revert to output low.
681 TCCR1A &= ~(_BV(COM1x1));
684 // #if BACKLIGHT_ON_STATE == 0
686 // _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
689 // _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
693 #ifndef NO_BACKLIGHT_CLOCK
694 else if ( level == BACKLIGHT_LEVELS ) {
695 // Turn on PWM control of backlight pin
696 TCCR1A |= _BV(COM1x1);
697 // Set the brightness
701 // Turn on PWM control of backlight pin
702 TCCR1A |= _BV(COM1x1);
703 // Set the brightness
704 OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
708 #ifdef BACKLIGHT_BREATHING
709 breathing_intensity_default();
713 uint8_t backlight_tick = 0;
715 void backlight_task(void) {
716 #ifdef NO_BACKLIGHT_CLOCK
717 if ((0xFFFF >> ((BACKLIGHT_LEVELS - backlight_config.level) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) {
718 #if BACKLIGHT_ON_STATE == 0
720 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
723 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
726 #if BACKLIGHT_ON_STATE == 0
728 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
731 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
734 backlight_tick = (backlight_tick + 1) % 16;
738 #ifdef BACKLIGHT_BREATHING
740 #define BREATHING_NO_HALT 0
741 #define BREATHING_HALT_OFF 1
742 #define BREATHING_HALT_ON 2
744 static uint8_t breath_intensity;
745 static uint8_t breath_speed;
746 static uint16_t breathing_index;
747 static uint8_t breathing_halt;
749 void breathing_enable(void)
751 if (get_backlight_level() == 0)
757 // Set breathing_index to be at the midpoint (brightest point)
758 breathing_index = 0x20 << breath_speed;
761 breathing_halt = BREATHING_NO_HALT;
763 // Enable breathing interrupt
764 TIMSK1 |= _BV(OCIE1A);
767 void breathing_pulse(void)
769 if (get_backlight_level() == 0)
775 // Set breathing_index to be at the midpoint + 1 (brightest point)
776 breathing_index = 0x21 << breath_speed;
779 breathing_halt = BREATHING_HALT_ON;
781 // Enable breathing interrupt
782 TIMSK1 |= _BV(OCIE1A);
785 void breathing_disable(void)
787 // Disable breathing interrupt
788 TIMSK1 &= ~_BV(OCIE1A);
789 backlight_set(get_backlight_level());
792 void breathing_self_disable(void)
794 if (get_backlight_level() == 0)
796 breathing_halt = BREATHING_HALT_OFF;
800 breathing_halt = BREATHING_HALT_ON;
803 //backlight_set(get_backlight_level());
806 void breathing_toggle(void)
810 if (get_backlight_level() == 0)
816 // Set breathing_index to be at the midpoint + 1 (brightest point)
817 breathing_index = 0x21 << breath_speed;
820 breathing_halt = BREATHING_NO_HALT;
823 // Toggle breathing interrupt
824 TIMSK1 ^= _BV(OCIE1A);
826 // Restore backlight level
829 backlight_set(get_backlight_level());
833 bool is_breathing(void)
835 return (TIMSK1 && _BV(OCIE1A));
838 void breathing_intensity_default(void)
840 //breath_intensity = (uint8_t)((uint16_t)100 * (uint16_t)get_backlight_level() / (uint16_t)BACKLIGHT_LEVELS);
841 breath_intensity = ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2));
844 void breathing_intensity_set(uint8_t value)
846 breath_intensity = value;
849 void breathing_speed_default(void)
854 void breathing_speed_set(uint8_t value)
856 bool is_breathing_now = is_breathing();
857 uint8_t old_breath_speed = breath_speed;
859 if (is_breathing_now)
861 // Disable breathing interrupt
862 TIMSK1 &= ~_BV(OCIE1A);
865 breath_speed = value;
867 if (is_breathing_now)
869 // Adjust index to account for new speed
870 breathing_index = (( (uint8_t)( (breathing_index) >> old_breath_speed ) ) & 0x3F) << breath_speed;
872 // Enable breathing interrupt
873 TIMSK1 |= _BV(OCIE1A);
878 void breathing_speed_inc(uint8_t value)
880 if ((uint16_t)(breath_speed - value) > 10 )
882 breathing_speed_set(0);
886 breathing_speed_set(breath_speed - value);
890 void breathing_speed_dec(uint8_t value)
892 if ((uint16_t)(breath_speed + value) > 10 )
894 breathing_speed_set(10);
898 breathing_speed_set(breath_speed + value);
902 void breathing_defaults(void)
904 breathing_intensity_default();
905 breathing_speed_default();
906 breathing_halt = BREATHING_NO_HALT;
909 /* Breathing Sleep LED brighness(PWM On period) table
910 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
912 * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
913 * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
915 static const uint8_t breathing_table[64] PROGMEM = {
916 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
917 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
918 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
919 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
922 ISR(TIMER1_COMPA_vect)
924 // OCR1x = (pgm_read_byte(&breathing_table[ ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F ] )) * breath_intensity;
927 uint8_t local_index = ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F;
929 if (((breathing_halt == BREATHING_HALT_ON) && (local_index == 0x20)) || ((breathing_halt == BREATHING_HALT_OFF) && (local_index == 0x3F)))
931 // Disable breathing interrupt
932 TIMSK1 &= ~_BV(OCIE1A);
935 OCR1x = (uint16_t)(((uint16_t)pgm_read_byte(&breathing_table[local_index]) * 257)) >> breath_intensity;
945 __attribute__ ((weak))
946 void backlight_init_ports(void)
951 __attribute__ ((weak))
952 void backlight_set(uint8_t level)
960 // Functions for spitting out values
963 void send_dword(uint32_t number) { // this might not actually work
964 uint16_t word = (number >> 16);
966 send_word(number & 0xFFFFUL);
969 void send_word(uint16_t number) {
970 uint8_t byte = number >> 8;
972 send_byte(number & 0xFF);
975 void send_byte(uint8_t number) {
976 uint8_t nibble = number >> 4;
978 send_nibble(number & 0xF);
981 void send_nibble(uint8_t number) {
985 unregister_code(KC_0);
988 register_code(KC_1 + (number - 1));
989 unregister_code(KC_1 + (number - 1));
992 register_code(KC_A + (number - 0xA));
993 unregister_code(KC_A + (number - 0xA));
999 __attribute__((weak))
1000 uint16_t hex_to_keycode(uint8_t hex)
1004 } else if (hex < 0xA) {
1005 return KC_1 + (hex - 0x1);
1007 return KC_A + (hex - 0xA);
1011 void api_send_unicode(uint32_t unicode) {
1014 dword_to_bytes(unicode, chunk);
1015 MT_SEND_DATA(DT_UNICODE, chunk, 5);
1019 __attribute__ ((weak))
1020 void led_set_user(uint8_t usb_led) {
1024 __attribute__ ((weak))
1025 void led_set_kb(uint8_t usb_led) {
1026 led_set_user(usb_led);
1029 __attribute__ ((weak))
1030 void led_init_ports(void)
1035 __attribute__ ((weak))
1036 void led_set(uint8_t usb_led)
1041 // // Using PE6 Caps Lock LED
1042 // if (usb_led & (1<<USB_LED_CAPS_LOCK))
1052 // PORTE &= ~(1<<6);
1055 led_set_kb(usb_led);
1059 //------------------------------------------------------------------------------
1060 // Override these functions in your keymap file to play different tunes on
1061 // different events such as startup and bootloader jump
1063 __attribute__ ((weak))
1064 void startup_user() {}
1066 __attribute__ ((weak))
1067 void shutdown_user() {}
1069 //------------------------------------------------------------------------------