lfk78.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "lfk78.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. matrix_init_user();
  8. #ifndef AUDIO_ENABLE
  9. // If we're not using the audio pin, drive it low
  10. gpio_set_pin_output(C6);
  11. gpio_write_pin_low(C6);
  12. #endif
  13. #ifdef WATCHDOG_ENABLE
  14. // This is done after turning the layer LED red, if we're caught in a loop
  15. // we should get a flashing red light
  16. wdt_enable(WDTO_500MS);
  17. #endif
  18. }
  19. void matrix_scan_kb(void) {
  20. #ifdef WATCHDOG_ENABLE
  21. wdt_reset();
  22. #endif
  23. matrix_scan_user();
  24. }
  25. void clicking_notes(uint16_t freq, uint16_t duration) {
  26. #ifdef AUDIO_ENABLE
  27. if (freq >= 100 && freq <= 20000 && duration < 100) {
  28. play_note(freq, 10);
  29. for (uint16_t i = 0; i < duration; i++) {
  30. _delay_ms(1);
  31. }
  32. stop_all_notes();
  33. }
  34. #endif
  35. }
  36. bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
  37. if (click_toggle && record->event.pressed) {
  38. clicking_notes(click_hz, click_time);
  39. }
  40. if (keycode == QK_BOOT) {
  41. reset_keyboard_kb();
  42. }
  43. return process_record_user(keycode, record);
  44. }
  45. void reset_keyboard_kb(void) {
  46. #ifdef WATCHDOG_ENABLE
  47. MCUSR = 0;
  48. wdt_disable();
  49. wdt_reset();
  50. #endif
  51. reset_keyboard();
  52. }