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.

79 lines
2.0 KiB

  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. #include "revb.h"
  15. #include <avr/wdt.h>
  16. uint16_t click_hz = CLICK_HZ;
  17. uint16_t click_time = CLICK_MS;
  18. uint8_t click_toggle = CLICK_ENABLED;
  19. void matrix_init_kb(void)
  20. {
  21. matrix_init_user();
  22. #ifdef AUDIO_ENABLE
  23. // audio_init() sets PB5 to output and drives it low, which breaks our matrix
  24. // so reset PB5 to input
  25. gpio_set_pin_input(B5);
  26. gpio_write_pin_high(B5);
  27. #else
  28. // If we're not using the audio pin, drive it low
  29. gpio_set_pin_output(C6);
  30. gpio_write_pin_low(C6);
  31. #endif
  32. }
  33. void matrix_scan_kb(void)
  34. {
  35. #ifdef WATCHDOG_ENABLE
  36. wdt_reset();
  37. #endif
  38. matrix_scan_user();
  39. }
  40. void click(uint16_t freq, uint16_t duration){
  41. #ifdef AUDIO_ENABLE
  42. if(freq >= 100 && freq <= 20000 && duration < 100){
  43. play_note(freq, 10);
  44. for (uint16_t i = 0; i < duration; i++){
  45. _delay_ms(1);
  46. }
  47. stop_all_notes();
  48. }
  49. #endif
  50. }
  51. bool process_record_kb(uint16_t keycode, keyrecord_t* record)
  52. {
  53. // Test code that turns on the switch led for the key that is pressed
  54. // set_backlight_by_keymap(record->event.key.col, record->event.key.row);
  55. if (click_toggle && record->event.pressed){
  56. click(click_hz, click_time);
  57. }
  58. if (keycode == QK_BOOT) {
  59. reset_keyboard_kb();
  60. }
  61. return process_record_user(keycode, record);
  62. }
  63. void reset_keyboard_kb(void){
  64. #ifdef WATCHDOG_ENABLE
  65. MCUSR = 0;
  66. wdt_disable();
  67. wdt_reset();
  68. #endif
  69. reset_keyboard();
  70. }