qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

lfk87.c (1477B)


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