logo

qmk_firmware

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

cu75.c (1632B)


  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. gpio_set_pin_input(B5);
  19. gpio_write_pin_high(B5);
  20. #else
  21. // If we're not using the audio pin, drive it low
  22. gpio_set_pin_output(C6);
  23. gpio_write_pin_low(C6);
  24. #endif
  25. }
  26. void housekeeping_task_kb(void) {
  27. #ifdef WATCHDOG_ENABLE
  28. wdt_reset();
  29. #endif
  30. }
  31. void click(uint16_t freq, uint16_t duration){
  32. #ifdef AUDIO_ENABLE
  33. if(freq >= 100 && freq <= 20000 && duration < 100){
  34. play_note(freq, 10);
  35. for (uint16_t i = 0; i < duration; i++){
  36. _delay_ms(1);
  37. }
  38. stop_all_notes();
  39. }
  40. #endif
  41. }
  42. bool process_record_kb(uint16_t keycode, keyrecord_t* record)
  43. {
  44. // Test code that turns on the switch led for the key that is pressed
  45. // set_backlight_by_keymap(record->event.key.col, record->event.key.row);
  46. if (click_toggle && record->event.pressed){
  47. click(click_hz, click_time);
  48. }
  49. return process_record_user(keycode, record);
  50. }
  51. bool shutdown_kb(bool jump_to_bootloader) {
  52. #ifdef WATCHDOG_ENABLE
  53. // Unconditionally run so shutdown_user can't mess up watchdog
  54. MCUSR = 0;
  55. wdt_disable();
  56. wdt_reset();
  57. #endif
  58. if (!shutdown_user(jump_to_bootloader)) {
  59. return false;
  60. }
  61. return true;
  62. }