3 #include "outputselect.h"
7 #define TAPPING_TERM 200
11 #include "backlight.h"
12 extern backlight_config_t backlight_config;
14 #ifdef FAUXCLICKY_ENABLE
15 #include "fauxclicky.h"
17 >>>>>>> 49e72632d2200fc3bf71d5ced2aa43058da3b2e0
19 static void do_code16 (uint16_t code, void (*f) (uint8_t)) {
21 case QK_MODS ... QK_MODS_MAX:
36 if (code < QK_RMODS_MIN) return;
48 static inline void qk_register_weak_mods(uint8_t kc) {
49 add_weak_mods(MOD_BIT(kc));
50 send_keyboard_report();
53 static inline void qk_unregister_weak_mods(uint8_t kc) {
54 del_weak_mods(MOD_BIT(kc));
55 send_keyboard_report();
58 static inline void qk_register_mods(uint8_t kc) {
59 add_weak_mods(MOD_BIT(kc));
60 send_keyboard_report();
63 static inline void qk_unregister_mods(uint8_t kc) {
64 del_weak_mods(MOD_BIT(kc));
65 send_keyboard_report();
68 void register_code16 (uint16_t code) {
69 if (IS_MOD(code) || code == KC_NO) {
70 do_code16 (code, qk_register_mods);
72 do_code16 (code, qk_register_weak_mods);
77 void unregister_code16 (uint16_t code) {
78 unregister_code (code);
79 if (IS_MOD(code) || code == KC_NO) {
80 do_code16 (code, qk_unregister_mods);
82 do_code16 (code, qk_unregister_weak_mods);
86 __attribute__ ((weak))
87 bool process_action_kb(keyrecord_t *record) {
91 __attribute__ ((weak))
92 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
93 return process_record_user(keycode, record);
96 __attribute__ ((weak))
97 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
101 void reset_keyboard(void) {
108 #ifdef CATERINA_BOOTLOADER
109 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
114 // Shift / paren setup
117 #define LSPO_KEY KC_9
120 #define RSPC_KEY KC_0
123 static bool shift_interrupted[2] = {0, 0};
124 static uint16_t scs_timer = 0;
126 bool process_record_quantum(keyrecord_t *record) {
128 /* This gets the keycode from the key pressed */
129 keypos_t key = record->event.key;
132 #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
133 /* TODO: Use store_or_get_action() or a similar function. */
134 if (!disable_action_cache) {
137 if (record->event.pressed) {
138 layer = layer_switch_get_layer(key);
139 update_source_layers_cache(key, layer);
141 layer = read_source_layers_cache(key);
143 keycode = keymap_key_to_keycode(layer, key);
146 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
148 // This is how you use actions here
149 // if (keycode == KC_LEAD) {
151 // action.code = ACTION_DEFAULT_LAYER_SET(0);
152 // process_action(record, action);
157 process_record_kb(keycode, record) &&
159 process_midi(keycode, record) &&
162 process_music(keycode, record) &&
164 #ifdef TAP_DANCE_ENABLE
165 process_tap_dance(keycode, record) &&
167 #ifndef DISABLE_LEADER
168 process_leader(keycode, record) &&
170 #ifndef DISABLE_CHORDING
171 process_chording(keycode, record) &&
174 process_combo(keycode, record) &&
176 #ifdef UNICODE_ENABLE
177 process_unicode(keycode, record) &&
180 process_ucis(keycode, record) &&
182 #ifdef PRINTING_ENABLE
183 process_printer(keycode, record) &&
185 #ifdef UNICODEMAP_ENABLE
186 process_unicode_map(keycode, record) &&
192 // Shift / paren setup
196 if (record->event.pressed) {
202 if (record->event.pressed) {
203 print("\nDEBUG: enabled.\n");
208 #ifdef FAUXCLICKY_ENABLE
210 if (record->event.pressed) {
216 if (record->event.pressed) {
222 if (record->event.pressed) {
228 #ifdef RGBLIGHT_ENABLE
230 if (record->event.pressed) {
236 if (record->event.pressed) {
242 if (record->event.pressed) {
243 rgblight_increase_hue();
248 if (record->event.pressed) {
249 rgblight_decrease_hue();
254 if (record->event.pressed) {
255 rgblight_increase_sat();
260 if (record->event.pressed) {
261 rgblight_decrease_sat();
266 if (record->event.pressed) {
267 rgblight_increase_val();
272 if (record->event.pressed) {
273 rgblight_decrease_val();
280 if (record->event.pressed) {
281 set_output(OUTPUT_AUTO);
286 if (record->event.pressed) {
287 set_output(OUTPUT_USB);
291 #ifdef BLUETOOTH_ENABLE
293 if (record->event.pressed) {
294 set_output(OUTPUT_BLUETOOTH);
299 #ifdef ADAFRUIT_BLE_ENABLE
301 if (record->event.pressed) {
302 set_output(OUTPUT_ADAFRUIT_BLE);
308 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO:
309 if (record->event.pressed) {
310 // MAGIC actions (BOOTMAGIC without the boot)
311 if (!eeconfig_is_enabled()) {
315 keymap_config.raw = eeconfig_read_keymap();
318 case MAGIC_SWAP_CONTROL_CAPSLOCK:
319 keymap_config.swap_control_capslock = true;
321 case MAGIC_CAPSLOCK_TO_CONTROL:
322 keymap_config.capslock_to_control = true;
324 case MAGIC_SWAP_LALT_LGUI:
325 keymap_config.swap_lalt_lgui = true;
327 case MAGIC_SWAP_RALT_RGUI:
328 keymap_config.swap_ralt_rgui = true;
331 keymap_config.no_gui = true;
333 case MAGIC_SWAP_GRAVE_ESC:
334 keymap_config.swap_grave_esc = true;
336 case MAGIC_SWAP_BACKSLASH_BACKSPACE:
337 keymap_config.swap_backslash_backspace = true;
339 case MAGIC_HOST_NKRO:
340 keymap_config.nkro = true;
342 case MAGIC_SWAP_ALT_GUI:
343 keymap_config.swap_lalt_lgui = true;
344 keymap_config.swap_ralt_rgui = true;
346 case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
347 keymap_config.swap_control_capslock = false;
349 case MAGIC_UNCAPSLOCK_TO_CONTROL:
350 keymap_config.capslock_to_control = false;
352 case MAGIC_UNSWAP_LALT_LGUI:
353 keymap_config.swap_lalt_lgui = false;
355 case MAGIC_UNSWAP_RALT_RGUI:
356 keymap_config.swap_ralt_rgui = false;
359 keymap_config.no_gui = false;
361 case MAGIC_UNSWAP_GRAVE_ESC:
362 keymap_config.swap_grave_esc = false;
364 case MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
365 keymap_config.swap_backslash_backspace = false;
367 case MAGIC_UNHOST_NKRO:
368 keymap_config.nkro = false;
370 case MAGIC_UNSWAP_ALT_GUI:
371 keymap_config.swap_lalt_lgui = false;
372 keymap_config.swap_ralt_rgui = false;
374 case MAGIC_TOGGLE_NKRO:
375 keymap_config.nkro = !keymap_config.nkro;
380 eeconfig_update_keymap(keymap_config.raw);
381 clear_keyboard(); // clear to prevent stuck keys
387 if (record->event.pressed) {
388 shift_interrupted[0] = false;
389 scs_timer = timer_read ();
390 register_mods(MOD_BIT(KC_LSFT));
393 #ifdef DISABLE_SPACE_CADET_ROLLOVER
394 if (get_mods() & MOD_BIT(KC_RSFT)) {
395 shift_interrupted[0] = true;
396 shift_interrupted[1] = true;
399 if (!shift_interrupted[0] && timer_elapsed(scs_timer) < TAPPING_TERM) {
400 register_code(LSPO_KEY);
401 unregister_code(LSPO_KEY);
403 unregister_mods(MOD_BIT(KC_LSFT));
410 if (record->event.pressed) {
411 shift_interrupted[1] = false;
412 scs_timer = timer_read ();
413 register_mods(MOD_BIT(KC_RSFT));
416 #ifdef DISABLE_SPACE_CADET_ROLLOVER
417 if (get_mods() & MOD_BIT(KC_LSFT)) {
418 shift_interrupted[0] = true;
419 shift_interrupted[1] = true;
422 if (!shift_interrupted[1] && timer_elapsed(scs_timer) < TAPPING_TERM) {
423 register_code(RSPC_KEY);
424 unregister_code(RSPC_KEY);
426 unregister_mods(MOD_BIT(KC_RSFT));
432 shift_interrupted[0] = true;
433 shift_interrupted[1] = true;
438 return process_action_kb(record);
441 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
442 0, 0, 0, 0, 0, 0, 0, 0,
443 0, 0, 0, 0, 0, 0, 0, 0,
444 0, 0, 0, 0, 0, 0, 0, 0,
445 0, 0, 0, 0, 0, 0, 0, 0,
446 0, 1, 1, 1, 1, 1, 1, 0,
447 1, 1, 1, 1, 0, 0, 0, 0,
448 0, 0, 0, 0, 0, 0, 0, 0,
449 0, 0, 1, 0, 1, 0, 1, 1,
450 1, 1, 1, 1, 1, 1, 1, 1,
451 1, 1, 1, 1, 1, 1, 1, 1,
452 1, 1, 1, 1, 1, 1, 1, 1,
453 1, 1, 1, 0, 0, 0, 1, 1,
454 0, 0, 0, 0, 0, 0, 0, 0,
455 0, 0, 0, 0, 0, 0, 0, 0,
456 0, 0, 0, 0, 0, 0, 0, 0,
457 0, 0, 0, 1, 1, 1, 1, 0
460 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
461 0, 0, 0, 0, 0, 0, 0, 0,
462 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
463 0, 0, 0, 0, 0, 0, 0, 0,
464 0, 0, 0, KC_ESC, 0, 0, 0, 0,
465 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
466 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
467 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
468 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
469 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
470 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
471 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
472 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
473 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
474 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
475 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
476 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
479 /* for users whose OSes are set to Colemak */
481 #include "keymap_colemak.h"
483 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
484 0, 0, 0, 0, 0, 0, 0, 0,
485 0, 0, 0, 0, 0, 0, 0, 0,
486 0, 0, 0, 0, 0, 0, 0, 0,
487 0, 0, 0, 0, 0, 0, 0, 0,
488 0, 1, 1, 1, 1, 1, 1, 0,
489 1, 1, 1, 1, 0, 0, 0, 0,
490 0, 0, 0, 0, 0, 0, 0, 0,
491 0, 0, 1, 0, 1, 0, 1, 1,
492 1, 1, 1, 1, 1, 1, 1, 1,
493 1, 1, 1, 1, 1, 1, 1, 1,
494 1, 1, 1, 1, 1, 1, 1, 1,
495 1, 1, 1, 0, 0, 0, 1, 1,
496 0, 0, 0, 0, 0, 0, 0, 0,
497 0, 0, 0, 0, 0, 0, 0, 0,
498 0, 0, 0, 0, 0, 0, 0, 0,
499 0, 0, 0, 1, 1, 1, 1, 0
502 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
503 0, 0, 0, 0, 0, 0, 0, 0,
504 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
505 0, 0, 0, 0, 0, 0, 0, 0,
506 0, 0, 0, KC_ESC, 0, 0, 0, 0,
507 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
508 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
509 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
510 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
511 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
512 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
513 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
514 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
515 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
516 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
517 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
518 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
523 void send_string(const char *str) {
526 uint8_t ascii_code = pgm_read_byte(str);
527 if (!ascii_code) break;
528 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
529 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
530 register_code(KC_LSFT);
531 register_code(keycode);
532 unregister_code(keycode);
533 unregister_code(KC_LSFT);
536 register_code(keycode);
537 unregister_code(keycode);
543 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
544 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
551 void tap_random_base64(void) {
552 #if defined(__AVR_ATmega32U4__)
553 uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
555 uint8_t key = rand() % 64;
559 register_code(KC_LSFT);
560 register_code(key + KC_A);
561 unregister_code(key + KC_A);
562 unregister_code(KC_LSFT);
565 register_code(key - 26 + KC_A);
566 unregister_code(key - 26 + KC_A);
570 unregister_code(KC_0);
573 register_code(key - 53 + KC_1);
574 unregister_code(key - 53 + KC_1);
577 register_code(KC_LSFT);
578 register_code(KC_EQL);
579 unregister_code(KC_EQL);
580 unregister_code(KC_LSFT);
583 register_code(KC_SLSH);
584 unregister_code(KC_SLSH);
589 void matrix_init_quantum() {
590 #ifdef BACKLIGHT_ENABLE
591 backlight_init_ports();
596 void matrix_scan_quantum() {
601 #ifdef TAP_DANCE_ENABLE
602 matrix_scan_tap_dance();
609 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
616 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
618 static const uint8_t backlight_pin = BACKLIGHT_PIN;
620 #if BACKLIGHT_PIN == B7
621 # define COM1x1 COM1C1
623 #elif BACKLIGHT_PIN == B6
624 # define COM1x1 COM1B1
626 #elif BACKLIGHT_PIN == B5
627 # define COM1x1 COM1A1
630 # define NO_BACKLIGHT_CLOCK
633 #ifndef BACKLIGHT_ON_STATE
634 #define BACKLIGHT_ON_STATE 0
637 __attribute__ ((weak))
638 void backlight_init_ports(void)
641 // Setup backlight pin as output and output to on state.
643 _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
644 #if BACKLIGHT_ON_STATE == 0
646 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
649 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
652 #ifndef NO_BACKLIGHT_CLOCK
653 // Use full 16-bit resolution.
656 // I could write a wall of text here to explain... but TL;DW
657 // Go read the ATmega32u4 datasheet.
658 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
660 // Pin PB7 = OCR1C (Timer 1, Channel C)
661 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
662 // (i.e. start high, go low when counter matches.)
663 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
664 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
666 TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
667 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
671 #ifdef BACKLIGHT_BREATHING
672 breathing_defaults();
676 __attribute__ ((weak))
677 void backlight_set(uint8_t level)
679 // Prevent backlight blink on lowest level
680 // #if BACKLIGHT_ON_STATE == 0
682 // _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
685 // _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
689 #ifndef NO_BACKLIGHT_CLOCK
690 // Turn off PWM control on backlight pin, revert to output low.
691 TCCR1A &= ~(_BV(COM1x1));
694 // #if BACKLIGHT_ON_STATE == 0
696 // _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
699 // _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
703 #ifndef NO_BACKLIGHT_CLOCK
704 else if ( level == BACKLIGHT_LEVELS ) {
705 // Turn on PWM control of backlight pin
706 TCCR1A |= _BV(COM1x1);
707 // Set the brightness
711 // Turn on PWM control of backlight pin
712 TCCR1A |= _BV(COM1x1);
713 // Set the brightness
714 OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
718 #ifdef BACKLIGHT_BREATHING
719 breathing_intensity_default();
723 uint8_t backlight_tick = 0;
725 void backlight_task(void) {
726 #ifdef NO_BACKLIGHT_CLOCK
727 if ((0xFFFF >> ((BACKLIGHT_LEVELS - backlight_config.level) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) {
728 #if BACKLIGHT_ON_STATE == 0
730 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
733 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
736 #if BACKLIGHT_ON_STATE == 0
738 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
741 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
744 backlight_tick = (backlight_tick + 1) % 16;
748 #ifdef BACKLIGHT_BREATHING
750 #define BREATHING_NO_HALT 0
751 #define BREATHING_HALT_OFF 1
752 #define BREATHING_HALT_ON 2
754 static uint8_t breath_intensity;
755 static uint8_t breath_speed;
756 static uint16_t breathing_index;
757 static uint8_t breathing_halt;
759 void breathing_enable(void)
761 if (get_backlight_level() == 0)
767 // Set breathing_index to be at the midpoint (brightest point)
768 breathing_index = 0x20 << breath_speed;
771 breathing_halt = BREATHING_NO_HALT;
773 // Enable breathing interrupt
774 TIMSK1 |= _BV(OCIE1A);
777 void breathing_pulse(void)
779 if (get_backlight_level() == 0)
785 // Set breathing_index to be at the midpoint + 1 (brightest point)
786 breathing_index = 0x21 << breath_speed;
789 breathing_halt = BREATHING_HALT_ON;
791 // Enable breathing interrupt
792 TIMSK1 |= _BV(OCIE1A);
795 void breathing_disable(void)
797 // Disable breathing interrupt
798 TIMSK1 &= ~_BV(OCIE1A);
799 backlight_set(get_backlight_level());
802 void breathing_self_disable(void)
804 if (get_backlight_level() == 0)
806 breathing_halt = BREATHING_HALT_OFF;
810 breathing_halt = BREATHING_HALT_ON;
813 //backlight_set(get_backlight_level());
816 void breathing_toggle(void)
820 if (get_backlight_level() == 0)
826 // Set breathing_index to be at the midpoint + 1 (brightest point)
827 breathing_index = 0x21 << breath_speed;
830 breathing_halt = BREATHING_NO_HALT;
833 // Toggle breathing interrupt
834 TIMSK1 ^= _BV(OCIE1A);
836 // Restore backlight level
839 backlight_set(get_backlight_level());
843 bool is_breathing(void)
845 return (TIMSK1 && _BV(OCIE1A));
848 void breathing_intensity_default(void)
850 //breath_intensity = (uint8_t)((uint16_t)100 * (uint16_t)get_backlight_level() / (uint16_t)BACKLIGHT_LEVELS);
851 breath_intensity = ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2));
854 void breathing_intensity_set(uint8_t value)
856 breath_intensity = value;
859 void breathing_speed_default(void)
864 void breathing_speed_set(uint8_t value)
866 bool is_breathing_now = is_breathing();
867 uint8_t old_breath_speed = breath_speed;
869 if (is_breathing_now)
871 // Disable breathing interrupt
872 TIMSK1 &= ~_BV(OCIE1A);
875 breath_speed = value;
877 if (is_breathing_now)
879 // Adjust index to account for new speed
880 breathing_index = (( (uint8_t)( (breathing_index) >> old_breath_speed ) ) & 0x3F) << breath_speed;
882 // Enable breathing interrupt
883 TIMSK1 |= _BV(OCIE1A);
888 void breathing_speed_inc(uint8_t value)
890 if ((uint16_t)(breath_speed - value) > 10 )
892 breathing_speed_set(0);
896 breathing_speed_set(breath_speed - value);
900 void breathing_speed_dec(uint8_t value)
902 if ((uint16_t)(breath_speed + value) > 10 )
904 breathing_speed_set(10);
908 breathing_speed_set(breath_speed + value);
912 void breathing_defaults(void)
914 breathing_intensity_default();
915 breathing_speed_default();
916 breathing_halt = BREATHING_NO_HALT;
919 /* Breathing Sleep LED brighness(PWM On period) table
920 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
922 * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
923 * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
925 static const uint8_t breathing_table[64] PROGMEM = {
926 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
927 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
928 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
929 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
932 ISR(TIMER1_COMPA_vect)
934 // OCR1x = (pgm_read_byte(&breathing_table[ ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F ] )) * breath_intensity;
937 uint8_t local_index = ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F;
939 if (((breathing_halt == BREATHING_HALT_ON) && (local_index == 0x20)) || ((breathing_halt == BREATHING_HALT_OFF) && (local_index == 0x3F)))
941 // Disable breathing interrupt
942 TIMSK1 &= ~_BV(OCIE1A);
945 OCR1x = (uint16_t)(((uint16_t)pgm_read_byte(&breathing_table[local_index]) * 257)) >> breath_intensity;
955 __attribute__ ((weak))
956 void backlight_init_ports(void)
961 __attribute__ ((weak))
962 void backlight_set(uint8_t level)
970 // Functions for spitting out values
973 void send_dword(uint32_t number) { // this might not actually work
974 uint16_t word = (number >> 16);
976 send_word(number & 0xFFFFUL);
979 void send_word(uint16_t number) {
980 uint8_t byte = number >> 8;
982 send_byte(number & 0xFF);
985 void send_byte(uint8_t number) {
986 uint8_t nibble = number >> 4;
988 send_nibble(number & 0xF);
991 void send_nibble(uint8_t number) {
995 unregister_code(KC_0);
998 register_code(KC_1 + (number - 1));
999 unregister_code(KC_1 + (number - 1));
1002 register_code(KC_A + (number - 0xA));
1003 unregister_code(KC_A + (number - 0xA));
1009 __attribute__((weak))
1010 uint16_t hex_to_keycode(uint8_t hex)
1014 } else if (hex < 0xA) {
1015 return KC_1 + (hex - 0x1);
1017 return KC_A + (hex - 0xA);
1021 void api_send_unicode(uint32_t unicode) {
1024 dword_to_bytes(unicode, chunk);
1025 MT_SEND_DATA(DT_UNICODE, chunk, 5);
1029 __attribute__ ((weak))
1030 void led_set_user(uint8_t usb_led) {
1034 __attribute__ ((weak))
1035 void led_set_kb(uint8_t usb_led) {
1036 led_set_user(usb_led);
1039 __attribute__ ((weak))
1040 void led_init_ports(void)
1045 __attribute__ ((weak))
1046 void led_set(uint8_t usb_led)
1051 // // Using PE6 Caps Lock LED
1052 // if (usb_led & (1<<USB_LED_CAPS_LOCK))
1062 // PORTE &= ~(1<<6);
1065 led_set_kb(usb_led);
1069 //------------------------------------------------------------------------------
1070 // Override these functions in your keymap file to play different tunes on
1071 // different events such as startup and bootloader jump
1073 __attribute__ ((weak))
1074 void startup_user() {}
1076 __attribute__ ((weak))
1077 void shutdown_user() {}
1079 //------------------------------------------------------------------------------