1 #include <avr/sfr_defs.h>
2 #include <avr/timer_avr.h>
12 uint16_t click_hz = CLICK_HZ;
13 uint16_t click_time = CLICK_MS;
14 uint8_t click_toggle = CLICK_ENABLED;
17 void matrix_init_kb(void)
21 // If we're not using the audio pin, drive it low
29 #ifdef WATCHDOG_ENABLE
30 // This is done after turning the layer LED red, if we're caught in a loop
31 // we should get a flashing red light
32 wdt_enable(WDTO_500MS);
37 void matrix_scan_kb(void)
39 #ifdef WATCHDOG_ENABLE
43 // switch/underglow lighting update
44 static uint32_t issi_device = 0;
45 static uint32_t twi_last_ready = 0;
46 if(twi_last_ready > 1000){
47 // Its been way too long since the last ISSI update, reset the I2C bus and start again
48 dprintf("TWI failed to recover, TWI re-init\n");
55 // If the i2c bus is available, kick off the issi update, alternate between devices
56 update_issi(issi_device, issi_device);
69 void click(uint16_t freq, uint16_t duration){
71 if(freq >= 100 && freq <= 20000 && duration < 100){
73 for (uint16_t i = 0; i < duration; i++){
81 bool process_record_kb(uint16_t keycode, keyrecord_t* record)
83 if (click_toggle && record->event.pressed){
84 click(click_hz, click_time);
86 if (keycode == RESET) {
90 return process_record_user(keycode, record);
93 void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
98 if(id == LFK_ESC_TILDE){
99 // Send ~ on shift-esc
100 void (*method)(uint8_t) = (event->event.pressed) ? &add_key : &del_key;
101 uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
102 if(layer_state == 0){
103 method(shifted ? KC_GRAVE : KC_ESCAPE);
105 method(shifted ? KC_ESCAPE : KC_GRAVE);
107 send_keyboard_report();
108 }else if(event->event.pressed){
110 case LFK_SET_DEFAULT_LAYER:
111 // set/save the current base layer to eeprom, falls through to LFK_CLEAR
112 eeconfig_update_default_layer(1UL << opt);
113 default_layer_set(1UL << opt);
115 // Go back to default layer
119 case LFK_CLICK_FREQ_LOWER:
120 sign = -1; // continue to next statement
121 case LFK_CLICK_FREQ_HIGHER:
122 click_hz += sign * 100;
123 click(click_hz, click_time);
125 case LFK_CLICK_TOGGLE:
136 case LFK_CLICK_TIME_SHORTER:
137 sign = -1; // continue to next statement
138 case LFK_CLICK_TIME_LONGER:
140 click(click_hz, click_time);
147 void reset_keyboard_kb(){
148 #ifdef WATCHDOG_ENABLE
156 void led_set_kb(uint8_t usb_led)
158 led_set_user(usb_led);
162 const uint8_t rgb_matrices[] = {0, 1};
163 const uint8_t rgb_sequence[] = {