qmk_firmware

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

cu75.c (1632B)


      1 #include "cu75.h"
      2 #include <avr/wdt.h>
      3 
      4 #ifdef AUDIO_ENABLE
      5 float test_sound[][2] = SONG(STARTUP_SOUND);
      6 #endif
      7 
      8 uint16_t click_hz = CLICK_HZ;
      9 uint16_t click_time = CLICK_MS;
     10 uint8_t click_toggle = CLICK_ENABLED;
     11 
     12 
     13 void matrix_init_kb(void)
     14 {
     15     // put your keyboard start-up code here
     16     // runs once when the firmware starts up
     17     matrix_init_user();
     18 
     19 #ifdef AUDIO_ENABLE
     20     audio_init();
     21     PLAY_SONG(test_sound);
     22     // Fix port B5
     23     gpio_set_pin_input(B5);
     24     gpio_write_pin_high(B5);
     25 #else
     26     // If we're not using the audio pin, drive it low
     27     gpio_set_pin_output(C6);
     28     gpio_write_pin_low(C6);
     29 #endif
     30 }
     31 
     32 void housekeeping_task_kb(void) {
     33 #ifdef WATCHDOG_ENABLE
     34     wdt_reset();
     35 #endif
     36 }
     37 
     38 void click(uint16_t freq, uint16_t duration){
     39 #ifdef AUDIO_ENABLE
     40     if(freq >= 100 && freq <= 20000 && duration < 100){
     41         play_note(freq, 10);
     42         for (uint16_t i = 0; i < duration; i++){
     43             _delay_ms(1);
     44         }
     45         stop_all_notes();
     46     }
     47 #endif
     48 }
     49 
     50 bool process_record_kb(uint16_t keycode, keyrecord_t* record)
     51 {
     52     // Test code that turns on the switch led for the key that is pressed
     53     // set_backlight_by_keymap(record->event.key.col, record->event.key.row);
     54     if (click_toggle && record->event.pressed){
     55         click(click_hz, click_time);
     56     }
     57     return process_record_user(keycode, record);
     58 }
     59 
     60 bool shutdown_kb(bool jump_to_bootloader) {
     61 #ifdef WATCHDOG_ENABLE
     62     // Unconditionally run so shutdown_user can't mess up watchdog
     63     MCUSR = 0;
     64     wdt_disable();
     65     wdt_reset();
     66 #endif
     67 
     68     if (!shutdown_user(jump_to_bootloader)) {
     69         return false;
     70     }
     71     return true;
     72 }