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 __attribute__ ((weak))
19 void leader_start(void) {}
21 __attribute__ ((weak))
22 void leader_end(void) {}
24 uint8_t starting_note = 0x0C;
29 bool music_activated = false;
32 static bool music_sequence_recording = false;
33 static bool music_sequence_playing = false;
34 static float music_sequence[16] = {0};
35 static uint8_t music_sequence_count = 0;
36 static uint8_t music_sequence_position = 0;
38 static uint16_t music_sequence_timer = 0;
39 static uint16_t music_sequence_interval = 100;
44 bool midi_activated = false;
49 uint16_t leader_time = 0;
51 uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
52 uint8_t leader_sequence_size = 0;
55 #define CHORDING_MAX 4
56 bool chording = false;
58 uint8_t chord_keys[CHORDING_MAX] = {0};
59 uint8_t chord_key_count = 0;
60 uint8_t chord_key_down = 0;
63 static uint8_t input_mode;
66 // Shift / paren setup
75 static bool shift_interrupted[2] = {0, 0};
77 bool keys_chord(uint8_t keys[]) {
78 uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
81 for (uint8_t i = 0; i < chord_key_count; i++) {
83 for (uint8_t j = 0; j < keys_size; j++) {
84 if (chord_keys[i] == (keys[j] & 0xFF)) {
85 in++; // detects key in chord
92 if (chord_keys[i] != 0) {
93 pass = false; // makes sure rest are blank
96 return (pass && (in == keys_size));
101 uint16_t hex_to_keycode(uint8_t hex)
105 } else if (hex < 0xA) {
106 return KC_1 + (hex - 0x1);
108 return KC_A + (hex - 0xA);
112 void set_unicode_mode(uint8_t os_target)
114 input_mode = os_target;
119 bool process_record_quantum(keyrecord_t *record) {
121 /* This gets the keycode from the key pressed */
122 keypos_t key = record->event.key;
125 #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
128 if (record->event.pressed) {
129 layer = layer_switch_get_layer(key);
130 update_source_layers_cache(key, layer);
132 layer = read_source_layers_cache(key);
134 keycode = keymap_key_to_keycode(layer, key);
136 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
139 if (!process_record_kb(keycode, record))
142 // This is how you use actions here
143 // if (keycode == KC_LEAD) {
145 // action.code = ACTION_DEFAULT_LAYER_SET(0);
146 // process_action(record, action);
151 if (keycode == MI_ON && record->event.pressed) {
152 midi_activated = true;
157 if (keycode == MI_OFF && record->event.pressed) {
158 midi_activated = false;
159 midi_send_cc(&midi_device, 0, 0x7B, 0);
163 if (midi_activated) {
164 if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
165 if (record->event.pressed) {
166 starting_note++; // Change key
167 midi_send_cc(&midi_device, 0, 0x7B, 0);
171 if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
172 if (record->event.pressed) {
173 starting_note--; // Change key
174 midi_send_cc(&midi_device, 0, 0x7B, 0);
178 if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
179 offset++; // Change scale
180 midi_send_cc(&midi_device, 0, 0x7B, 0);
183 if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
184 offset--; // Change scale
185 midi_send_cc(&midi_device, 0, 0x7B, 0);
189 // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
191 // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
193 uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
195 // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
197 if (record->event.pressed) {
198 // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
199 midi_send_noteon(&midi_device, 0, note, 127);
201 // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
202 midi_send_noteoff(&midi_device, 0, note, 127);
205 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
211 if (keycode == AU_ON && record->event.pressed) {
216 if (keycode == AU_OFF && record->event.pressed) {
221 if (keycode == AU_TOG && record->event.pressed) {
233 if (keycode == MU_ON && record->event.pressed) {
238 if (keycode == MU_OFF && record->event.pressed) {
243 if (keycode == MU_TOG && record->event.pressed) {
255 if (keycode == MUV_IN && record->event.pressed) {
261 if (keycode == MUV_DE && record->event.pressed) {
267 if (music_activated) {
269 if (keycode == KC_LCTL && record->event.pressed) { // Start recording
271 music_sequence_recording = true;
272 music_sequence_playing = false;
273 music_sequence_count = 0;
277 if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
279 music_sequence_recording = false;
280 music_sequence_playing = false;
284 if (keycode == KC_LGUI && record->event.pressed) { // Start playing
286 music_sequence_recording = false;
287 music_sequence_playing = true;
288 music_sequence_position = 0;
289 music_sequence_timer = 0;
293 if (keycode == KC_UP) {
294 if (record->event.pressed)
295 music_sequence_interval-=10;
299 if (keycode == KC_DOWN) {
300 if (record->event.pressed)
301 music_sequence_interval+=10;
305 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row));
306 if (record->event.pressed) {
307 play_note(freq, 0xF);
308 if (music_sequence_recording) {
309 music_sequence[music_sequence_count] = freq;
310 music_sequence_count++;
316 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
321 #ifndef DISABLE_LEADER
323 if (record->event.pressed) {
324 if (!leading && keycode == KC_LEAD) {
327 leader_time = timer_read();
328 leader_sequence_size = 0;
329 leader_sequence[0] = 0;
330 leader_sequence[1] = 0;
331 leader_sequence[2] = 0;
332 leader_sequence[3] = 0;
333 leader_sequence[4] = 0;
336 if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
337 leader_sequence[leader_sequence_size] = keycode;
338 leader_sequence_size++;
344 #define DISABLE_CHORDING
345 #ifndef DISABLE_CHORDING
347 if (keycode >= QK_CHORDING && keycode <= QK_CHORDING_MAX) {
348 if (record->event.pressed) {
351 for (uint8_t i = 0; i < CHORDING_MAX; i++)
356 chord_keys[chord_key_count] = (keycode & 0xFF);
363 if (chord_key_down == 0) {
366 if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
368 unregister_code(KC_A);
371 for (uint8_t i = 0; i < chord_key_count; i++) {
372 register_code(chord_keys[i]);
373 unregister_code(chord_keys[i]);
383 #ifdef UNICODE_ENABLE
385 if (keycode > QK_UNICODE && record->event.pressed) {
386 uint16_t unicode = keycode & 0x7FFF;
389 register_code(KC_LALT);
392 register_code(KC_LCTL);
393 register_code(KC_LSFT);
395 unregister_code(KC_U);
398 register_code(KC_LALT);
399 register_code(KC_PPLS);
400 unregister_code(KC_PPLS);
403 for(int i = 3; i >= 0; i--) {
404 uint8_t digit = ((unicode >> (i*4)) & 0xF);
405 register_code(hex_to_keycode(digit));
406 unregister_code(hex_to_keycode(digit));
411 unregister_code(KC_LALT);
414 unregister_code(KC_LCTL);
415 unregister_code(KC_LSFT);
422 // Shift / paren setup
426 if (record->event.pressed) {
434 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
441 if (record->event.pressed) {
442 print("\nDEBUG: enabled.\n");
447 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
448 if (record->event.pressed) {
449 // MAGIC actions (BOOTMAGIC without the boot)
450 if (!eeconfig_is_enabled()) {
454 keymap_config.raw = eeconfig_read_keymap();
455 if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
456 keymap_config.swap_control_capslock = 1;
457 } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
458 keymap_config.capslock_to_control = 1;
459 } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
460 keymap_config.swap_lalt_lgui = 1;
461 } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
462 keymap_config.swap_ralt_rgui = 1;
463 } else if (keycode == MAGIC_NO_GUI) {
464 keymap_config.no_gui = 1;
465 } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
466 keymap_config.swap_grave_esc = 1;
467 } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
468 keymap_config.swap_backslash_backspace = 1;
469 } else if (keycode == MAGIC_HOST_NKRO) {
470 keymap_config.nkro = 1;
471 } else if (keycode == MAGIC_SWAP_ALT_GUI) {
472 keymap_config.swap_lalt_lgui = 1;
473 keymap_config.swap_ralt_rgui = 1;
476 else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
477 keymap_config.swap_control_capslock = 0;
478 } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
479 keymap_config.capslock_to_control = 0;
480 } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
481 keymap_config.swap_lalt_lgui = 0;
482 } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
483 keymap_config.swap_ralt_rgui = 0;
484 } else if (keycode == MAGIC_UNNO_GUI) {
485 keymap_config.no_gui = 0;
486 } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
487 keymap_config.swap_grave_esc = 0;
488 } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
489 keymap_config.swap_backslash_backspace = 0;
490 } else if (keycode == MAGIC_UNHOST_NKRO) {
491 keymap_config.nkro = 0;
492 } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
493 keymap_config.swap_lalt_lgui = 0;
494 keymap_config.swap_ralt_rgui = 0;
496 eeconfig_update_keymap(keymap_config.raw);
501 if (record->event.pressed) {
502 shift_interrupted[0] = false;
503 register_mods(MOD_BIT(KC_LSFT));
506 if (!shift_interrupted[0]) {
507 register_code(LSPO_KEY);
508 unregister_code(LSPO_KEY);
510 unregister_mods(MOD_BIT(KC_LSFT));
517 if (record->event.pressed) {
518 shift_interrupted[1] = false;
519 register_mods(MOD_BIT(KC_RSFT));
522 if (!shift_interrupted[1]) {
523 register_code(RSPC_KEY);
524 unregister_code(RSPC_KEY);
526 unregister_mods(MOD_BIT(KC_RSFT));
532 shift_interrupted[0] = true;
533 shift_interrupted[1] = true;
538 return process_action_kb(record);
541 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
542 0, 0, 0, 0, 0, 0, 0, 0,
543 0, 0, 0, 0, 0, 0, 0, 0,
544 0, 0, 0, 0, 0, 0, 0, 0,
545 0, 0, 0, 0, 0, 0, 0, 0,
546 0, 1, 1, 1, 1, 1, 1, 0,
547 1, 1, 1, 1, 0, 0, 0, 0,
548 0, 0, 0, 0, 0, 0, 0, 0,
549 0, 0, 1, 0, 1, 0, 1, 1,
550 1, 1, 1, 1, 1, 1, 1, 1,
551 1, 1, 1, 1, 1, 1, 1, 1,
552 1, 1, 1, 1, 1, 1, 1, 1,
553 1, 1, 1, 0, 0, 0, 1, 1,
554 0, 0, 0, 0, 0, 0, 0, 0,
555 0, 0, 0, 0, 0, 0, 0, 0,
556 0, 0, 0, 0, 0, 0, 0, 0,
557 0, 0, 0, 1, 1, 1, 1, 0
560 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
561 0, 0, 0, 0, 0, 0, 0, 0,
562 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
563 0, 0, 0, 0, 0, 0, 0, 0,
564 0, 0, 0, KC_ESC, 0, 0, 0, 0,
565 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
566 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
567 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
568 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
569 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
570 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
571 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
572 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
573 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
574 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
575 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
576 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
579 /* for users whose OSes are set to Colemak */
581 #include "keymap_colemak.h"
583 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
584 0, 0, 0, 0, 0, 0, 0, 0,
585 0, 0, 0, 0, 0, 0, 0, 0,
586 0, 0, 0, 0, 0, 0, 0, 0,
587 0, 0, 0, 0, 0, 0, 0, 0,
588 0, 1, 1, 1, 1, 1, 1, 0,
589 1, 1, 1, 1, 0, 0, 0, 0,
590 0, 0, 0, 0, 0, 0, 0, 0,
591 0, 0, 1, 0, 1, 0, 1, 1,
592 1, 1, 1, 1, 1, 1, 1, 1,
593 1, 1, 1, 1, 1, 1, 1, 1,
594 1, 1, 1, 1, 1, 1, 1, 1,
595 1, 1, 1, 0, 0, 0, 1, 1,
596 0, 0, 0, 0, 0, 0, 0, 0,
597 0, 0, 0, 0, 0, 0, 0, 0,
598 0, 0, 0, 0, 0, 0, 0, 0,
599 0, 0, 0, 1, 1, 1, 1, 0
602 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
603 0, 0, 0, 0, 0, 0, 0, 0,
604 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
605 0, 0, 0, 0, 0, 0, 0, 0,
606 0, 0, 0, KC_ESC, 0, 0, 0, 0,
607 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
608 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
609 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
610 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
611 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
612 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
613 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
614 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
615 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
616 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
617 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
618 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
623 void send_string(const char *str) {
626 uint8_t ascii_code = pgm_read_byte(str);
627 if (!ascii_code) break;
628 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
629 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
630 register_code(KC_LSFT);
631 register_code(keycode);
632 unregister_code(keycode);
633 unregister_code(KC_LSFT);
636 register_code(keycode);
637 unregister_code(keycode);
643 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
644 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
651 void matrix_init_quantum() {
652 #ifdef BACKLIGHT_ENABLE
653 backlight_init_ports();
658 void matrix_scan_quantum() {
660 if (music_sequence_playing) {
661 if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
662 music_sequence_timer = timer_read();
663 stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
664 play_note(music_sequence[music_sequence_position], 0xF);
665 music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
675 bool is_music_on(void) {
676 return (music_activated != 0);
679 void music_toggle(void) {
680 if (!music_activated) {
687 void music_on(void) {
692 void music_off(void) {
700 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
702 static const uint8_t backlight_pin = BACKLIGHT_PIN;
704 #if BACKLIGHT_PIN == B7
705 # define COM1x1 COM1C1
707 #elif BACKLIGHT_PIN == B6
708 # define COM1x1 COM1B1
710 #elif BACKLIGHT_PIN == B5
711 # define COM1x1 COM1A1
714 # error "Backlight pin not supported - use B5, B6, or B7"
717 __attribute__ ((weak))
718 void backlight_init_ports(void)
721 // Setup backlight pin as output and output low.
723 _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
725 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
727 // Use full 16-bit resolution.
730 // I could write a wall of text here to explain... but TL;DW
731 // Go read the ATmega32u4 datasheet.
732 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
734 // Pin PB7 = OCR1C (Timer 1, Channel C)
735 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
736 // (i.e. start high, go low when counter matches.)
737 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
738 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
740 TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
741 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
744 #ifdef BACKLIGHT_BREATHING
745 breathing_defaults();
749 __attribute__ ((weak))
750 void backlight_set(uint8_t level)
752 // Prevent backlight blink on lowest level
754 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
757 // Turn off PWM control on backlight pin, revert to output low.
758 TCCR1A &= ~(_BV(COM1x1));
760 } else if ( level == BACKLIGHT_LEVELS ) {
761 // Turn on PWM control of backlight pin
762 TCCR1A |= _BV(COM1x1);
763 // Set the brightness
766 // Turn on PWM control of backlight pin
767 TCCR1A |= _BV(COM1x1);
768 // Set the brightness
769 OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
772 #ifdef BACKLIGHT_BREATHING
773 breathing_intensity_default();
778 #ifdef BACKLIGHT_BREATHING
780 #define BREATHING_NO_HALT 0
781 #define BREATHING_HALT_OFF 1
782 #define BREATHING_HALT_ON 2
784 static uint8_t breath_intensity;
785 static uint8_t breath_speed;
786 static uint16_t breathing_index;
787 static uint8_t breathing_halt;
789 void breathing_enable(void)
791 if (get_backlight_level() == 0)
797 // Set breathing_index to be at the midpoint (brightest point)
798 breathing_index = 0x20 << breath_speed;
801 breathing_halt = BREATHING_NO_HALT;
803 // Enable breathing interrupt
804 TIMSK1 |= _BV(OCIE1A);
807 void breathing_pulse(void)
809 if (get_backlight_level() == 0)
815 // Set breathing_index to be at the midpoint + 1 (brightest point)
816 breathing_index = 0x21 << breath_speed;
819 breathing_halt = BREATHING_HALT_ON;
821 // Enable breathing interrupt
822 TIMSK1 |= _BV(OCIE1A);
825 void breathing_disable(void)
827 // Disable breathing interrupt
828 TIMSK1 &= ~_BV(OCIE1A);
829 backlight_set(get_backlight_level());
832 void breathing_self_disable(void)
834 if (get_backlight_level() == 0)
836 breathing_halt = BREATHING_HALT_OFF;
840 breathing_halt = BREATHING_HALT_ON;
843 //backlight_set(get_backlight_level());
846 void breathing_toggle(void)
850 if (get_backlight_level() == 0)
856 // Set breathing_index to be at the midpoint + 1 (brightest point)
857 breathing_index = 0x21 << breath_speed;
860 breathing_halt = BREATHING_NO_HALT;
863 // Toggle breathing interrupt
864 TIMSK1 ^= _BV(OCIE1A);
866 // Restore backlight level
869 backlight_set(get_backlight_level());
873 bool is_breathing(void)
875 return (TIMSK1 && _BV(OCIE1A));
878 void breathing_intensity_default(void)
880 //breath_intensity = (uint8_t)((uint16_t)100 * (uint16_t)get_backlight_level() / (uint16_t)BACKLIGHT_LEVELS);
881 breath_intensity = ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2));
884 void breathing_intensity_set(uint8_t value)
886 breath_intensity = value;
889 void breathing_speed_default(void)
894 void breathing_speed_set(uint8_t value)
896 bool is_breathing_now = is_breathing();
897 uint8_t old_breath_speed = breath_speed;
899 if (is_breathing_now)
901 // Disable breathing interrupt
902 TIMSK1 &= ~_BV(OCIE1A);
905 breath_speed = value;
907 if (is_breathing_now)
909 // Adjust index to account for new speed
910 breathing_index = (( (uint8_t)( (breathing_index) >> old_breath_speed ) ) & 0x3F) << breath_speed;
912 // Enable breathing interrupt
913 TIMSK1 |= _BV(OCIE1A);
918 void breathing_speed_inc(uint8_t value)
920 if ((uint16_t)(breath_speed - value) > 10 )
922 breathing_speed_set(0);
926 breathing_speed_set(breath_speed - value);
930 void breathing_speed_dec(uint8_t value)
932 if ((uint16_t)(breath_speed + value) > 10 )
934 breathing_speed_set(10);
938 breathing_speed_set(breath_speed + value);
942 void breathing_defaults(void)
944 breathing_intensity_default();
945 breathing_speed_default();
946 breathing_halt = BREATHING_NO_HALT;
949 /* Breathing Sleep LED brighness(PWM On period) table
950 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
952 * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
953 * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
955 static const uint8_t breathing_table[64] PROGMEM = {
956 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
957 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
958 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
959 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
962 ISR(TIMER1_COMPA_vect)
964 // OCR1x = (pgm_read_byte(&breathing_table[ ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F ] )) * breath_intensity;
967 uint8_t local_index = ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F;
969 if (((breathing_halt == BREATHING_HALT_ON) && (local_index == 0x20)) || ((breathing_halt == BREATHING_HALT_OFF) && (local_index == 0x3F)))
971 // Disable breathing interrupt
972 TIMSK1 &= ~_BV(OCIE1A);
975 OCR1x = (uint16_t)(((uint16_t)pgm_read_byte(&breathing_table[local_index]) * 257)) >> breath_intensity;
985 __attribute__ ((weak))
986 void backlight_init_ports(void)
991 __attribute__ ((weak))
992 void backlight_set(uint8_t level)
1001 __attribute__ ((weak))
1002 void led_set_user(uint8_t usb_led) {
1006 __attribute__ ((weak))
1007 void led_set_kb(uint8_t usb_led) {
1008 led_set_user(usb_led);
1011 __attribute__ ((weak))
1012 void led_init_ports(void)
1017 __attribute__ ((weak))
1018 void led_set(uint8_t usb_led)
1023 // // Using PE6 Caps Lock LED
1024 // if (usb_led & (1<<USB_LED_CAPS_LOCK))
1034 // PORTE &= ~(1<<6);
1037 led_set_kb(usb_led);
1041 //------------------------------------------------------------------------------
1042 // Override these functions in your keymap file to play different tunes on
1043 // different events such as startup and bootloader jump
1045 __attribute__ ((weak))
1046 void startup_user() {}
1048 __attribute__ ((weak))
1049 void shutdown_user() {}
1051 __attribute__ ((weak))
1052 void music_on_user() {}
1054 __attribute__ ((weak))
1055 void audio_on_user() {}
1057 __attribute__ ((weak))
1058 void music_scale_user() {}
1060 //------------------------------------------------------------------------------