wt60_xt.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright 2020 Jason Williams (Wilba)
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "quantum.h"
  17. #ifdef AUDIO_ENABLE
  18. #include "audio.h"
  19. #include "song_list.h"
  20. float tone_caps_on[][2] = SONG(CAPS_LOCK_ON_SOUND);
  21. float tone_caps_off[][2] = SONG(CAPS_LOCK_OFF_SOUND);
  22. float tone_numlk_on[][2] = SONG(NUM_LOCK_ON_SOUND);
  23. float tone_numlk_off[][2] = SONG(NUM_LOCK_OFF_SOUND);
  24. float tone_scroll_on[][2] = SONG(SCROLL_LOCK_ON_SOUND);
  25. float tone_scroll_off[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
  26. float tone_device_indication[][2] = SONG(FANTASIE_IMPROMPTU);
  27. #endif
  28. // We want to enable audio clicky (i.e. compile it into firmware),
  29. // but not have it "turned on" by default.
  30. #ifdef AUDIO_CLICKY
  31. #include "process_clicky.h"
  32. extern audio_config_t audio_config;
  33. void eeconfig_init_kb(void) {
  34. // Reset Keyboard EEPROM value to blank, rather than to a set value
  35. eeconfig_update_kb(0);
  36. // Need to read here because this isn't done before calling eeconfig_init_kb()
  37. audio_config.raw = eeconfig_read_audio();
  38. // ...and this call needs audio_config initialized.
  39. clicky_off();
  40. eeconfig_init_user();
  41. }
  42. #endif // AUDIO_CLICKY
  43. void keyboard_pre_init_kb(void) {
  44. gpio_set_pin_output(F1);
  45. keyboard_pre_init_user();
  46. }
  47. bool led_update_kb(led_t led_state) {
  48. if (led_update_user(led_state)) {
  49. gpio_write_pin(F1, led_state.caps_lock);
  50. }
  51. #ifdef AUDIO_ENABLE
  52. static led_t old_led_state = { .raw = 0 };
  53. wait_ms(10); // gets rid of tick
  54. if (led_state.caps_lock && !old_led_state.caps_lock)
  55. {
  56. PLAY_SONG(tone_caps_on);
  57. }
  58. else if (!led_state.caps_lock && old_led_state.caps_lock)
  59. {
  60. PLAY_SONG(tone_caps_off);
  61. }
  62. else if (led_state.num_lock && !old_led_state.num_lock)
  63. {
  64. PLAY_SONG(tone_numlk_on);
  65. }
  66. else if (!led_state.num_lock && old_led_state.num_lock)
  67. {
  68. PLAY_SONG(tone_numlk_off);
  69. }
  70. else if (led_state.scroll_lock && !old_led_state.scroll_lock)
  71. {
  72. PLAY_SONG(tone_scroll_on);
  73. }
  74. else if (!led_state.scroll_lock && old_led_state.scroll_lock)
  75. {
  76. PLAY_SONG(tone_scroll_off);
  77. }
  78. old_led_state = led_state;
  79. #endif // AUDIO_ENABLE
  80. return true;
  81. }
  82. void via_set_device_indication(uint8_t value) {
  83. if ( value == 0 ) {
  84. PLAY_SONG(tone_device_indication);
  85. }
  86. }