qmk_firmware

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

revb.c (2161B)


      1 /*
      2 Copyright 2020 LFKeyboards
      3 This program is free software: you can redistribute it and/or modify
      4 it under the terms of the GNU General Public License as published by
      5 the Free Software Foundation, either version 2 of the License, or
      6 (at your option) any later version.
      7 This program is distributed in the hope that it will be useful,
      8 but WITHOUT ANY WARRANTY; without even the implied warranty of
      9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     10 GNU General Public License for more details.
     11 You should have received a copy of the GNU General Public License
     12 along with this program.  If not, see <http://www.gnu.org/licenses/>.
     13 */
     14 
     15 #include "revb.h"
     16 #include <avr/wdt.h>
     17 
     18 uint16_t click_hz = CLICK_HZ;
     19 uint16_t click_time = CLICK_MS;
     20 uint8_t click_toggle = CLICK_ENABLED;
     21 
     22 
     23 void matrix_init_kb(void)
     24 {
     25     matrix_init_user();
     26 
     27 #ifdef AUDIO_ENABLE
     28     // audio_init() sets PB5 to output and drives it low, which breaks our matrix
     29     // so reset PB5 to input
     30     gpio_set_pin_input(B5);
     31     gpio_write_pin_high(B5);
     32 #else
     33     // If we're not using the audio pin, drive it low
     34     gpio_set_pin_output(C6);
     35     gpio_write_pin_low(C6);
     36 #endif
     37 }
     38 
     39 void housekeeping_task_kb(void) {
     40 #ifdef WATCHDOG_ENABLE
     41     wdt_reset();
     42 #endif
     43 }
     44 
     45 void click(uint16_t freq, uint16_t duration){
     46 #ifdef AUDIO_ENABLE
     47     if(freq >= 100 && freq <= 20000 && duration < 100){
     48         play_note(freq, 10);
     49         for (uint16_t i = 0; i < duration; i++){
     50             _delay_ms(1);
     51         }
     52         stop_all_notes();
     53     }
     54 #endif
     55 }
     56 
     57 bool process_record_kb(uint16_t keycode, keyrecord_t* record)
     58 {
     59     // Test code that turns on the switch led for the key that is pressed
     60     // set_backlight_by_keymap(record->event.key.col, record->event.key.row);
     61     if (click_toggle && record->event.pressed){
     62         click(click_hz, click_time);
     63     }
     64     return process_record_user(keycode, record);
     65 }
     66 
     67 bool shutdown_kb(bool jump_to_bootloader) {
     68 #ifdef WATCHDOG_ENABLE
     69     // Unconditionally run so shutdown_user can't mess up watchdog
     70     MCUSR = 0;
     71     wdt_disable();
     72     wdt_reset();
     73 #endif
     74 
     75     if (!shutdown_user(jump_to_bootloader)) {
     76         return false;
     77     }
     78     return true;
     79 }