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) {
101 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_ENABLE_BASIC))
102 music_all_notes_off();
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) &&
156 #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
157 process_midi(keycode, record) &&
160 process_audio(keycode, record) &&
162 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
163 process_music(keycode, record) &&
165 #ifdef TAP_DANCE_ENABLE
166 process_tap_dance(keycode, record) &&
168 #ifndef DISABLE_LEADER
169 process_leader(keycode, record) &&
171 #ifndef DISABLE_CHORDING
172 process_chording(keycode, record) &&
175 process_combo(keycode, record) &&
177 #ifdef UNICODE_ENABLE
178 process_unicode(keycode, record) &&
181 process_ucis(keycode, record) &&
183 #ifdef PRINTING_ENABLE
184 process_printer(keycode, record) &&
186 #ifdef UNICODEMAP_ENABLE
187 process_unicode_map(keycode, record) &&
193 // Shift / paren setup
197 if (record->event.pressed) {
203 if (record->event.pressed) {
204 print("\nDEBUG: enabled.\n");
209 #ifdef FAUXCLICKY_ENABLE
211 if (record->event.pressed) {
217 if (record->event.pressed) {
223 if (record->event.pressed) {
229 #ifdef RGBLIGHT_ENABLE
231 if (record->event.pressed) {
237 if (record->event.pressed) {
243 if (record->event.pressed) {
244 rgblight_increase_hue();
249 if (record->event.pressed) {
250 rgblight_decrease_hue();
255 if (record->event.pressed) {
256 rgblight_increase_sat();
261 if (record->event.pressed) {
262 rgblight_decrease_sat();
267 if (record->event.pressed) {
268 rgblight_increase_val();
273 if (record->event.pressed) {
274 rgblight_decrease_val();
281 if (record->event.pressed) {
282 set_output(OUTPUT_AUTO);
287 if (record->event.pressed) {
288 set_output(OUTPUT_USB);
292 #ifdef BLUETOOTH_ENABLE
294 if (record->event.pressed) {
295 set_output(OUTPUT_BLUETOOTH);
301 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO:
302 if (record->event.pressed) {
303 // MAGIC actions (BOOTMAGIC without the boot)
304 if (!eeconfig_is_enabled()) {
308 keymap_config.raw = eeconfig_read_keymap();
311 case MAGIC_SWAP_CONTROL_CAPSLOCK:
312 keymap_config.swap_control_capslock = true;
314 case MAGIC_CAPSLOCK_TO_CONTROL:
315 keymap_config.capslock_to_control = true;
317 case MAGIC_SWAP_LALT_LGUI:
318 keymap_config.swap_lalt_lgui = true;
320 case MAGIC_SWAP_RALT_RGUI:
321 keymap_config.swap_ralt_rgui = true;
324 keymap_config.no_gui = true;
326 case MAGIC_SWAP_GRAVE_ESC:
327 keymap_config.swap_grave_esc = true;
329 case MAGIC_SWAP_BACKSLASH_BACKSPACE:
330 keymap_config.swap_backslash_backspace = true;
332 case MAGIC_HOST_NKRO:
333 keymap_config.nkro = true;
335 case MAGIC_SWAP_ALT_GUI:
336 keymap_config.swap_lalt_lgui = true;
337 keymap_config.swap_ralt_rgui = true;
339 case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
340 keymap_config.swap_control_capslock = false;
342 case MAGIC_UNCAPSLOCK_TO_CONTROL:
343 keymap_config.capslock_to_control = false;
345 case MAGIC_UNSWAP_LALT_LGUI:
346 keymap_config.swap_lalt_lgui = false;
348 case MAGIC_UNSWAP_RALT_RGUI:
349 keymap_config.swap_ralt_rgui = false;
352 keymap_config.no_gui = false;
354 case MAGIC_UNSWAP_GRAVE_ESC:
355 keymap_config.swap_grave_esc = false;
357 case MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
358 keymap_config.swap_backslash_backspace = false;
360 case MAGIC_UNHOST_NKRO:
361 keymap_config.nkro = false;
363 case MAGIC_UNSWAP_ALT_GUI:
364 keymap_config.swap_lalt_lgui = false;
365 keymap_config.swap_ralt_rgui = false;
367 case MAGIC_TOGGLE_NKRO:
368 keymap_config.nkro = !keymap_config.nkro;
373 eeconfig_update_keymap(keymap_config.raw);
374 clear_keyboard(); // clear to prevent stuck keys
380 if (record->event.pressed) {
381 shift_interrupted[0] = false;
382 scs_timer = timer_read ();
383 register_mods(MOD_BIT(KC_LSFT));
386 #ifdef DISABLE_SPACE_CADET_ROLLOVER
387 if (get_mods() & MOD_BIT(KC_RSFT)) {
388 shift_interrupted[0] = true;
389 shift_interrupted[1] = true;
392 if (!shift_interrupted[0] && timer_elapsed(scs_timer) < TAPPING_TERM) {
393 register_code(LSPO_KEY);
394 unregister_code(LSPO_KEY);
396 unregister_mods(MOD_BIT(KC_LSFT));
403 if (record->event.pressed) {
404 shift_interrupted[1] = false;
405 scs_timer = timer_read ();
406 register_mods(MOD_BIT(KC_RSFT));
409 #ifdef DISABLE_SPACE_CADET_ROLLOVER
410 if (get_mods() & MOD_BIT(KC_LSFT)) {
411 shift_interrupted[0] = true;
412 shift_interrupted[1] = true;
415 if (!shift_interrupted[1] && timer_elapsed(scs_timer) < TAPPING_TERM) {
416 register_code(RSPC_KEY);
417 unregister_code(RSPC_KEY);
419 unregister_mods(MOD_BIT(KC_RSFT));
425 shift_interrupted[0] = true;
426 shift_interrupted[1] = true;
431 return process_action_kb(record);
434 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
435 0, 0, 0, 0, 0, 0, 0, 0,
436 0, 0, 0, 0, 0, 0, 0, 0,
437 0, 0, 0, 0, 0, 0, 0, 0,
438 0, 0, 0, 0, 0, 0, 0, 0,
439 0, 1, 1, 1, 1, 1, 1, 0,
440 1, 1, 1, 1, 0, 0, 0, 0,
441 0, 0, 0, 0, 0, 0, 0, 0,
442 0, 0, 1, 0, 1, 0, 1, 1,
443 1, 1, 1, 1, 1, 1, 1, 1,
444 1, 1, 1, 1, 1, 1, 1, 1,
445 1, 1, 1, 1, 1, 1, 1, 1,
446 1, 1, 1, 0, 0, 0, 1, 1,
447 0, 0, 0, 0, 0, 0, 0, 0,
448 0, 0, 0, 0, 0, 0, 0, 0,
449 0, 0, 0, 0, 0, 0, 0, 0,
450 0, 0, 0, 1, 1, 1, 1, 0
453 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
454 0, 0, 0, 0, 0, 0, 0, 0,
455 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
456 0, 0, 0, 0, 0, 0, 0, 0,
457 0, 0, 0, KC_ESC, 0, 0, 0, 0,
458 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
459 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
460 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
461 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
462 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
463 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
464 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
465 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
466 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
467 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
468 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
469 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
472 /* for users whose OSes are set to Colemak */
474 #include "keymap_colemak.h"
476 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
477 0, 0, 0, 0, 0, 0, 0, 0,
478 0, 0, 0, 0, 0, 0, 0, 0,
479 0, 0, 0, 0, 0, 0, 0, 0,
480 0, 0, 0, 0, 0, 0, 0, 0,
481 0, 1, 1, 1, 1, 1, 1, 0,
482 1, 1, 1, 1, 0, 0, 0, 0,
483 0, 0, 0, 0, 0, 0, 0, 0,
484 0, 0, 1, 0, 1, 0, 1, 1,
485 1, 1, 1, 1, 1, 1, 1, 1,
486 1, 1, 1, 1, 1, 1, 1, 1,
487 1, 1, 1, 1, 1, 1, 1, 1,
488 1, 1, 1, 0, 0, 0, 1, 1,
489 0, 0, 0, 0, 0, 0, 0, 0,
490 0, 0, 0, 0, 0, 0, 0, 0,
491 0, 0, 0, 0, 0, 0, 0, 0,
492 0, 0, 0, 1, 1, 1, 1, 0
495 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
496 0, 0, 0, 0, 0, 0, 0, 0,
497 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
498 0, 0, 0, 0, 0, 0, 0, 0,
499 0, 0, 0, KC_ESC, 0, 0, 0, 0,
500 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
501 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
502 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
503 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
504 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
505 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
506 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
507 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
508 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
509 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
510 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
511 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
516 void send_string(const char *str) {
519 uint8_t ascii_code = pgm_read_byte(str);
520 if (!ascii_code) break;
521 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
522 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
523 register_code(KC_LSFT);
524 register_code(keycode);
525 unregister_code(keycode);
526 unregister_code(KC_LSFT);
529 register_code(keycode);
530 unregister_code(keycode);
536 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
537 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
544 void tap_random_base64(void) {
545 #if defined(__AVR_ATmega32U4__)
546 uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
548 uint8_t key = rand() % 64;
552 register_code(KC_LSFT);
553 register_code(key + KC_A);
554 unregister_code(key + KC_A);
555 unregister_code(KC_LSFT);
558 register_code(key - 26 + KC_A);
559 unregister_code(key - 26 + KC_A);
563 unregister_code(KC_0);
566 register_code(key - 53 + KC_1);
567 unregister_code(key - 53 + KC_1);
570 register_code(KC_LSFT);
571 register_code(KC_EQL);
572 unregister_code(KC_EQL);
573 unregister_code(KC_LSFT);
576 register_code(KC_SLSH);
577 unregister_code(KC_SLSH);
582 void matrix_init_quantum() {
583 #ifdef BACKLIGHT_ENABLE
584 backlight_init_ports();
589 void matrix_scan_quantum() {
594 #ifdef TAP_DANCE_ENABLE
595 matrix_scan_tap_dance();
602 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
609 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
611 static const uint8_t backlight_pin = BACKLIGHT_PIN;
613 #if BACKLIGHT_PIN == B7
614 # define COM1x1 COM1C1
616 #elif BACKLIGHT_PIN == B6
617 # define COM1x1 COM1B1
619 #elif BACKLIGHT_PIN == B5
620 # define COM1x1 COM1A1
623 # define NO_BACKLIGHT_CLOCK
626 #ifndef BACKLIGHT_ON_STATE
627 #define BACKLIGHT_ON_STATE 0
630 __attribute__ ((weak))
631 void backlight_init_ports(void)
634 // Setup backlight pin as output and output to on state.
636 _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
637 #if BACKLIGHT_ON_STATE == 0
639 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
642 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
645 #ifndef NO_BACKLIGHT_CLOCK
646 // Use full 16-bit resolution.
649 // I could write a wall of text here to explain... but TL;DW
650 // Go read the ATmega32u4 datasheet.
651 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
653 // Pin PB7 = OCR1C (Timer 1, Channel C)
654 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
655 // (i.e. start high, go low when counter matches.)
656 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
657 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
659 TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
660 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
664 #ifdef BACKLIGHT_BREATHING
665 breathing_defaults();
669 __attribute__ ((weak))
670 void backlight_set(uint8_t level)
672 // Prevent backlight blink on lowest level
673 // #if BACKLIGHT_ON_STATE == 0
675 // _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
678 // _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
682 #ifndef NO_BACKLIGHT_CLOCK
683 // Turn off PWM control on backlight pin, revert to output low.
684 TCCR1A &= ~(_BV(COM1x1));
687 // #if BACKLIGHT_ON_STATE == 0
689 // _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
692 // _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
696 #ifndef NO_BACKLIGHT_CLOCK
697 else if ( level == BACKLIGHT_LEVELS ) {
698 // Turn on PWM control of backlight pin
699 TCCR1A |= _BV(COM1x1);
700 // Set the brightness
704 // Turn on PWM control of backlight pin
705 TCCR1A |= _BV(COM1x1);
706 // Set the brightness
707 OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
711 #ifdef BACKLIGHT_BREATHING
712 breathing_intensity_default();
716 uint8_t backlight_tick = 0;
718 void backlight_task(void) {
719 #ifdef NO_BACKLIGHT_CLOCK
720 if ((0xFFFF >> ((BACKLIGHT_LEVELS - backlight_config.level) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) {
721 #if BACKLIGHT_ON_STATE == 0
723 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
726 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
729 #if BACKLIGHT_ON_STATE == 0
731 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
734 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
737 backlight_tick = (backlight_tick + 1) % 16;
741 #ifdef BACKLIGHT_BREATHING
743 #define BREATHING_NO_HALT 0
744 #define BREATHING_HALT_OFF 1
745 #define BREATHING_HALT_ON 2
747 static uint8_t breath_intensity;
748 static uint8_t breath_speed;
749 static uint16_t breathing_index;
750 static uint8_t breathing_halt;
752 void breathing_enable(void)
754 if (get_backlight_level() == 0)
760 // Set breathing_index to be at the midpoint (brightest point)
761 breathing_index = 0x20 << breath_speed;
764 breathing_halt = BREATHING_NO_HALT;
766 // Enable breathing interrupt
767 TIMSK1 |= _BV(OCIE1A);
770 void breathing_pulse(void)
772 if (get_backlight_level() == 0)
778 // Set breathing_index to be at the midpoint + 1 (brightest point)
779 breathing_index = 0x21 << breath_speed;
782 breathing_halt = BREATHING_HALT_ON;
784 // Enable breathing interrupt
785 TIMSK1 |= _BV(OCIE1A);
788 void breathing_disable(void)
790 // Disable breathing interrupt
791 TIMSK1 &= ~_BV(OCIE1A);
792 backlight_set(get_backlight_level());
795 void breathing_self_disable(void)
797 if (get_backlight_level() == 0)
799 breathing_halt = BREATHING_HALT_OFF;
803 breathing_halt = BREATHING_HALT_ON;
806 //backlight_set(get_backlight_level());
809 void breathing_toggle(void)
813 if (get_backlight_level() == 0)
819 // Set breathing_index to be at the midpoint + 1 (brightest point)
820 breathing_index = 0x21 << breath_speed;
823 breathing_halt = BREATHING_NO_HALT;
826 // Toggle breathing interrupt
827 TIMSK1 ^= _BV(OCIE1A);
829 // Restore backlight level
832 backlight_set(get_backlight_level());
836 bool is_breathing(void)
838 return (TIMSK1 && _BV(OCIE1A));
841 void breathing_intensity_default(void)
843 //breath_intensity = (uint8_t)((uint16_t)100 * (uint16_t)get_backlight_level() / (uint16_t)BACKLIGHT_LEVELS);
844 breath_intensity = ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2));
847 void breathing_intensity_set(uint8_t value)
849 breath_intensity = value;
852 void breathing_speed_default(void)
857 void breathing_speed_set(uint8_t value)
859 bool is_breathing_now = is_breathing();
860 uint8_t old_breath_speed = breath_speed;
862 if (is_breathing_now)
864 // Disable breathing interrupt
865 TIMSK1 &= ~_BV(OCIE1A);
868 breath_speed = value;
870 if (is_breathing_now)
872 // Adjust index to account for new speed
873 breathing_index = (( (uint8_t)( (breathing_index) >> old_breath_speed ) ) & 0x3F) << breath_speed;
875 // Enable breathing interrupt
876 TIMSK1 |= _BV(OCIE1A);
881 void breathing_speed_inc(uint8_t value)
883 if ((uint16_t)(breath_speed - value) > 10 )
885 breathing_speed_set(0);
889 breathing_speed_set(breath_speed - value);
893 void breathing_speed_dec(uint8_t value)
895 if ((uint16_t)(breath_speed + value) > 10 )
897 breathing_speed_set(10);
901 breathing_speed_set(breath_speed + value);
905 void breathing_defaults(void)
907 breathing_intensity_default();
908 breathing_speed_default();
909 breathing_halt = BREATHING_NO_HALT;
912 /* Breathing Sleep LED brighness(PWM On period) table
913 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
915 * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
916 * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
918 static const uint8_t breathing_table[64] PROGMEM = {
919 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
920 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
921 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
922 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
925 ISR(TIMER1_COMPA_vect)
927 // OCR1x = (pgm_read_byte(&breathing_table[ ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F ] )) * breath_intensity;
930 uint8_t local_index = ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F;
932 if (((breathing_halt == BREATHING_HALT_ON) && (local_index == 0x20)) || ((breathing_halt == BREATHING_HALT_OFF) && (local_index == 0x3F)))
934 // Disable breathing interrupt
935 TIMSK1 &= ~_BV(OCIE1A);
938 OCR1x = (uint16_t)(((uint16_t)pgm_read_byte(&breathing_table[local_index]) * 257)) >> breath_intensity;
948 __attribute__ ((weak))
949 void backlight_init_ports(void)
954 __attribute__ ((weak))
955 void backlight_set(uint8_t level)
963 // Functions for spitting out values
966 void send_dword(uint32_t number) { // this might not actually work
967 uint16_t word = (number >> 16);
969 send_word(number & 0xFFFFUL);
972 void send_word(uint16_t number) {
973 uint8_t byte = number >> 8;
975 send_byte(number & 0xFF);
978 void send_byte(uint8_t number) {
979 uint8_t nibble = number >> 4;
981 send_nibble(number & 0xF);
984 void send_nibble(uint8_t number) {
988 unregister_code(KC_0);
991 register_code(KC_1 + (number - 1));
992 unregister_code(KC_1 + (number - 1));
995 register_code(KC_A + (number - 0xA));
996 unregister_code(KC_A + (number - 0xA));
1002 __attribute__((weak))
1003 uint16_t hex_to_keycode(uint8_t hex)
1007 } else if (hex < 0xA) {
1008 return KC_1 + (hex - 0x1);
1010 return KC_A + (hex - 0xA);
1014 void api_send_unicode(uint32_t unicode) {
1017 dword_to_bytes(unicode, chunk);
1018 MT_SEND_DATA(DT_UNICODE, chunk, 5);
1022 __attribute__ ((weak))
1023 void led_set_user(uint8_t usb_led) {
1027 __attribute__ ((weak))
1028 void led_set_kb(uint8_t usb_led) {
1029 led_set_user(usb_led);
1032 __attribute__ ((weak))
1033 void led_init_ports(void)
1038 __attribute__ ((weak))
1039 void led_set(uint8_t usb_led)
1044 // // Using PE6 Caps Lock LED
1045 // if (usb_led & (1<<USB_LED_CAPS_LOCK))
1055 // PORTE &= ~(1<<6);
1058 led_set_kb(usb_led);
1062 //------------------------------------------------------------------------------
1063 // Override these functions in your keymap file to play different tunes on
1064 // different events such as startup and bootloader jump
1066 __attribute__ ((weak))
1067 void startup_user() {}
1069 __attribute__ ((weak))
1070 void shutdown_user() {}
1072 //------------------------------------------------------------------------------