1 #include <avr/sfr_defs.h>
2 #include <avr/timer_avr.h>
7 #include "../lfkeyboards/issi.h"
8 #include "../lfkeyboards/TWIlib.h"
9 #include "../lfkeyboards/lighting.h"
12 float test_sound[][2] = SONG(STARTUP_SOUND);
13 #include <audio/audio.h>
16 uint16_t click_hz = CLICK_HZ;
17 uint16_t click_time = CLICK_MS;
18 uint8_t click_toggle = CLICK_ENABLED;
21 void matrix_init_kb(void)
23 // put your keyboard start-up code here
24 // runs once when the firmware starts up
29 PLAY_NOTE_ARRAY(test_sound, false, STACCATO);
34 // If we're not using the audio pin, drive it low
43 void matrix_scan_kb(void)
45 #ifdef WATCHDOG_ENABLE
49 // switch/underglow lighting update
50 static uint32_t issi_device = 0;
51 static uint32_t twi_last_ready = 0;
52 if(twi_last_ready > 1000){
53 // Its been way too long since the last ISSI update, reset the I2C bus and start again
54 dprintf("TWI failed to recover, TWI re-init\n");
61 // If the i2c bus is available, kick off the issi update, alternate between devices
62 update_issi(issi_device, issi_device);
75 void click(uint16_t freq, uint16_t duration){
77 if(freq >= 100 && freq <= 20000 && duration < 100){
79 for (uint16_t i = 0; i < duration; i++){
87 bool process_record_kb(uint16_t keycode, keyrecord_t* record)
89 // Test code that turns on the switch led for the key that is pressed
90 // set_backlight_by_keymap(record->event.key.col, record->event.key.row);
91 if (click_toggle && record->event.pressed){
92 click(click_hz, click_time);
94 if (keycode == RESET) {
98 return process_record_user(keycode, record);
101 void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
106 if(id == LFK_ESC_TILDE){
107 // Send ~ on shift-esc
108 void (*method)(uint8_t) = (event->event.pressed) ? &add_key : &del_key;
109 uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
110 method(shifted ? KC_GRAVE : KC_ESCAPE);
111 send_keyboard_report();
112 }else if(event->event.pressed){
114 case LFK_SET_DEFAULT_LAYER:
115 // set/save the current base layer to eeprom, falls through to LFK_CLEAR
116 eeconfig_update_default_layer(1UL << opt);
117 default_layer_set(1UL << opt);
119 // Go back to default layer
123 case LFK_CLICK_FREQ_LOWER:
124 sign = -1; // continue to next statement
125 case LFK_CLICK_FREQ_HIGHER:
126 click_hz += sign * 100;
127 click(click_hz, click_time);
129 case LFK_CLICK_TOGGLE:
140 case LFK_CLICK_TIME_SHORTER:
141 sign = -1; // continue to next statement
142 case LFK_CLICK_TIME_LONGER:
144 click(click_hz, click_time);
147 case LFK_DEBUG_SETTINGS:
149 dprintf(" toggle: %d\n", click_toggle);
150 dprintf(" freq(hz): %d\n", click_hz);
151 dprintf(" duration(ms): %d\n", click_time);
157 void reset_keyboard_kb(){
158 #ifdef WATCHDOG_ENABLE
166 void led_set_kb(uint8_t usb_led)
168 // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
170 led_set_user(usb_led);
174 const uint8_t switch_matrices[] = {0, 1};
175 const uint8_t rgb_matrices[] = {6, 7};
176 const uint8_t rgb_sequence[] = {
177 24, 23, 22, 21, 20, 19, 18, 17, 1, 2, 3, 4, 5,
178 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 9