1 #include <avr/sfr_defs.h>
2 #include <avr/timer_avr.h>
10 #include <audio/audio.h>
12 uint16_t click_hz = CLICK_HZ;
13 uint16_t click_time = CLICK_MS;
14 uint8_t click_toggle = CLICK_ENABLED;
17 const Layer_Info layer_info[] = {
18 // Layer Mask Red Green Blue
19 {0x00000000, 0xFFFFFFFF, {0x0000, 0x0FFF, 0x0000}}, // base layer - green
20 {0x00000002, 0xFFFFFFFE, {0x0000, 0x0000, 0x0FFF}}, // function layer - blue
21 {0x00000004, 0xFFFFFFFC, {0x0FFF, 0x0000, 0x0FFF}}, // settings layer - magenta
22 {0xFFFFFFFF, 0xFFFFFFFF, {0x0FFF, 0x0FFF, 0x0FFF}}, // unknown layer - REQUIRED - white
25 void matrix_init_kb(void)
29 // Configure the Layer LED
30 // Set up 16 bit PWM: Fast PWM, mode 15, inverted
34 // PWM values - 0xFFFF = off, 0x0000 = max
35 OCR1C = 0x0000; // B7 - Blue
36 OCR1B = 0x0000; // B6 - Green
37 OCR1A = 0x0FFF; // B5 - Red
42 // If we're not using the audio pin, drive it low
50 #ifdef WATCHDOG_ENABLE
51 // This is done after turning the layer LED red, if we're caught in a loop
52 // we should get a flashing red light
53 wdt_enable(WDTO_500MS);
58 void matrix_scan_kb(void)
60 #ifdef WATCHDOG_ENABLE
64 // switch/underglow lighting update
65 static uint32_t issi_device = 0;
66 static uint32_t twi_last_ready = 0;
67 if(twi_last_ready > 1000){
68 // Its been way too long since the last ISSI update, reset the I2C bus and start again
69 dprintf("TWI failed to recover, TWI re-init\n");
76 // If the i2c bus is available, kick off the issi update, alternate between devices
77 update_issi(issi_device, issi_device);
87 // Update layer indicator LED
89 // Not sure how else to reliably do this... TMK has the 'hook_layer_change'
90 // but can't find QMK equiv
91 static uint32_t layer_indicator = -1;
92 if(layer_indicator != layer_state){
93 for(uint32_t i=0;; i++){
94 // the layer_info list should end with layer 0xFFFFFFFF
95 // it will break this out of the loop and define the unknown layer color
96 if((layer_info[i].layer == (layer_state & layer_info[i].mask)) || (layer_info[i].layer == 0xFFFFFFFF)){
97 OCR1A = layer_info[i].color.red;
98 OCR1B = layer_info[i].color.green;
99 OCR1C = layer_info[i].color.blue;
100 layer_indicator = layer_state;
108 void click(uint16_t freq, uint16_t duration){
110 if(freq >= 100 && freq <= 20000 && duration < 100){
112 for (uint16_t i = 0; i < duration; i++){
120 bool process_record_kb(uint16_t keycode, keyrecord_t* record)
122 if (click_toggle && record->event.pressed){
123 click(click_hz, click_time);
125 if (keycode == RESET) {
129 return process_record_user(keycode, record);
132 void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
137 if(id == LFK_ESC_TILDE){
138 // Send ~ on shift-esc
139 void (*method)(uint8_t) = (event->event.pressed) ? &add_key : &del_key;
140 uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
141 if(layer_state == 0){
142 method(shifted ? KC_GRAVE : KC_ESCAPE);
144 method(shifted ? KC_ESCAPE : KC_GRAVE);
146 send_keyboard_report();
147 }else if(event->event.pressed){
149 case LFK_SET_DEFAULT_LAYER:
150 // set/save the current base layer to eeprom, falls through to LFK_CLEAR
151 eeconfig_update_default_layer(1UL << opt);
152 default_layer_set(1UL << opt);
154 // Go back to default layer
163 case LFK_CLICK_FREQ_LOWER:
164 sign = -1; // continue to next statement
165 case LFK_CLICK_FREQ_HIGHER:
166 click_hz += sign * 100;
167 click(click_hz, click_time);
169 case LFK_CLICK_TOGGLE:
180 case LFK_CLICK_TIME_SHORTER:
181 sign = -1; // continue to next statement
182 case LFK_CLICK_TIME_LONGER:
184 click(click_hz, click_time);
187 case LFK_DEBUG_SETTINGS:
189 dprintf(" toggle: %d\n", click_toggle);
190 dprintf(" freq(hz): %d\n", click_hz);
191 dprintf(" duration(ms): %d\n", click_time);
197 void reset_keyboard_kb(){
198 #ifdef WATCHDOG_ENABLE
203 OCR1A = 0x0000; // B5 - Red
204 OCR1B = 0x0FFF; // B6 - Green
205 OCR1C = 0x0FFF; // B7 - Blue
209 void led_set_kb(uint8_t usb_led)
211 // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
214 if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
215 activateLED(0, 3, 7, 255);
217 activateLED(0, 3, 7, 0);
219 #endif // CAPSLOCK_LED
221 led_set_user(usb_led);
225 const uint8_t switch_matrices[] = {0, 1};
226 const uint8_t rgb_matrices[] = {6, 7};
227 const uint8_t rgb_sequence[] = {
228 12, 11, 10, 9, 16, 32, 31, 30, 28, 25, 24, 22, 21,
229 20, 19, 18, 17, 1, 2, 3, 4, 5, 6, 7, 8, 14, 13
231 // Maps switch LEDs from Row/Col to ISSI matrix.
233 // Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
234 // / \ ISSI Col | ISSI Row |
236 const uint8_t switch_leds[MATRIX_ROWS][MATRIX_COLS] =
238 0x19, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x99, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91,
239 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0xA9, 0xA8, 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1,
240 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0xB9, 0xB8, 0xB7, 0xB6, 0xB5, 0xB3,
241 0x49, 0x48, 0x47, 0x45, 0x44, 0x43, 0x42, 0x41, 0xC9, 0xC8, 0xC7, 0xC6, 0xC5, 0xC4, 0xC2,
242 0x59, 0x58, 0x57, 0x56, 0x55, 0x51, 0xD6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1);