logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

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. #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 housekeeping_task_kb(void) {
  34. #ifdef WATCHDOG_ENABLE
  35. wdt_reset();
  36. #endif
  37. }
  38. void click(uint16_t freq, uint16_t duration){
  39. #ifdef AUDIO_ENABLE
  40. if(freq >= 100 && freq <= 20000 && duration < 100){
  41. play_note(freq, 10);
  42. for (uint16_t i = 0; i < duration; i++){
  43. _delay_ms(1);
  44. }
  45. stop_all_notes();
  46. }
  47. #endif
  48. }
  49. bool process_record_kb(uint16_t keycode, keyrecord_t* record)
  50. {
  51. // Test code that turns on the switch led for the key that is pressed
  52. // set_backlight_by_keymap(record->event.key.col, record->event.key.row);
  53. if (click_toggle && record->event.pressed){
  54. click(click_hz, click_time);
  55. }
  56. return process_record_user(keycode, record);
  57. }
  58. bool shutdown_kb(bool jump_to_bootloader) {
  59. #ifdef WATCHDOG_ENABLE
  60. // Unconditionally run so shutdown_user can't mess up watchdog
  61. MCUSR = 0;
  62. wdt_disable();
  63. wdt_reset();
  64. #endif
  65. if (!shutdown_user(jump_to_bootloader)) {
  66. return false;
  67. }
  68. return true;
  69. }