lfk87.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "lfk87.h"
  2. #include <avr/wdt.h>
  3. uint16_t click_hz = CLICK_HZ;
  4. uint16_t click_time = CLICK_MS;
  5. uint8_t click_toggle = CLICK_ENABLED;
  6. void matrix_init_kb(void)
  7. {
  8. // put your keyboard start-up code here
  9. // runs once when the firmware starts up
  10. matrix_init_user();
  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. #ifdef WATCHDOG_ENABLE
  17. // This is done after turning the layer LED red, if we're caught in a loop
  18. // we should get a flashing red light
  19. wdt_enable(WDTO_500MS);
  20. #endif
  21. }
  22. void matrix_scan_kb(void)
  23. {
  24. #ifdef WATCHDOG_ENABLE
  25. wdt_reset();
  26. #endif
  27. matrix_scan_user();
  28. }
  29. void clicking_notes(uint16_t freq, uint16_t duration){
  30. #ifdef AUDIO_ENABLE
  31. if(freq >= 100 && freq <= 20000 && duration < 100){
  32. play_note(freq, 10);
  33. for (uint16_t i = 0; i < duration; i++){
  34. _delay_ms(1);
  35. }
  36. stop_all_notes();
  37. }
  38. #endif
  39. }
  40. bool process_record_kb(uint16_t keycode, keyrecord_t* record)
  41. {
  42. if (click_toggle && record->event.pressed){
  43. clicking_notes(click_hz, click_time);
  44. }
  45. if (keycode == QK_BOOT) {
  46. reset_keyboard_kb();
  47. }
  48. return process_record_user(keycode, record);
  49. }
  50. void reset_keyboard_kb(void){
  51. #ifdef WATCHDOG_ENABLE
  52. MCUSR = 0;
  53. wdt_disable();
  54. wdt_reset();
  55. #endif
  56. reset_keyboard();
  57. }