You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.5 KiB

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