lfk78.c (1395B)
1 #include "lfk78.h" 2 #include <avr/wdt.h> 3 4 uint16_t click_hz = CLICK_HZ; 5 uint16_t click_time = CLICK_MS; 6 uint8_t click_toggle = CLICK_ENABLED; 7 8 void matrix_init_kb(void) { 9 matrix_init_user(); 10 11 #ifndef AUDIO_ENABLE 12 // If we're not using the audio pin, drive it low 13 gpio_set_pin_output(C6); 14 gpio_write_pin_low(C6); 15 #endif 16 17 #ifdef WATCHDOG_ENABLE 18 // This is done after turning the layer LED red, if we're caught in a loop 19 // we should get a flashing red light 20 wdt_enable(WDTO_500MS); 21 #endif 22 } 23 24 void housekeeping_task_kb(void) { 25 #ifdef WATCHDOG_ENABLE 26 wdt_reset(); 27 #endif 28 } 29 30 void clicking_notes(uint16_t freq, uint16_t duration) { 31 #ifdef AUDIO_ENABLE 32 if (freq >= 100 && freq <= 20000 && duration < 100) { 33 play_note(freq, 10); 34 for (uint16_t i = 0; i < duration; i++) { 35 _delay_ms(1); 36 } 37 stop_all_notes(); 38 } 39 #endif 40 } 41 42 bool process_record_kb(uint16_t keycode, keyrecord_t* record) { 43 if (click_toggle && record->event.pressed) { 44 clicking_notes(click_hz, click_time); 45 } 46 return process_record_user(keycode, record); 47 } 48 49 bool shutdown_kb(bool jump_to_bootloader) { 50 #ifdef WATCHDOG_ENABLE 51 // Unconditionally run so shutdown_user can't mess up watchdog 52 MCUSR = 0; 53 wdt_disable(); 54 wdt_reset(); 55 #endif 56 57 if (!shutdown_user(jump_to_bootloader)) { 58 return false; 59 } 60 return true; 61 }