wt60_xt.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "wt60_xt.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. #endif
  27. // We want to enable audio clicky (i.e. compile it into firmware),
  28. // but not have it "turned on" by default.
  29. #ifdef AUDIO_CLICKY
  30. #include "process_clicky.h"
  31. extern audio_config_t audio_config;
  32. void eeconfig_init_kb(void) {
  33. // Reset Keyboard EEPROM value to blank, rather than to a set value
  34. eeconfig_update_kb(0);
  35. // Need to read here because this isn't done before calling eeconfig_init_kb()
  36. audio_config.raw = eeconfig_read_audio();
  37. // ...and this call needs audio_config initialized.
  38. clicky_off();
  39. eeconfig_init_user();
  40. }
  41. #endif // AUDIO_CLICKY
  42. void keyboard_pre_init_kb(void) {
  43. setPinOutput(F1);
  44. keyboard_pre_init_user();
  45. }
  46. bool led_update_kb(led_t led_state) {
  47. if (led_update_user(led_state)) {
  48. writePin(F1, led_state.caps_lock);
  49. }
  50. #ifdef AUDIO_ENABLE
  51. static led_t old_led_state = { .raw = 0 };
  52. wait_ms(10); // gets rid of tick
  53. if (led_state.caps_lock && !old_led_state.caps_lock)
  54. {
  55. PLAY_SONG(tone_caps_on);
  56. }
  57. else if (!led_state.caps_lock && old_led_state.caps_lock)
  58. {
  59. PLAY_SONG(tone_caps_off);
  60. }
  61. else if (led_state.num_lock && !old_led_state.num_lock)
  62. {
  63. PLAY_SONG(tone_numlk_on);
  64. }
  65. else if (!led_state.num_lock && old_led_state.num_lock)
  66. {
  67. PLAY_SONG(tone_numlk_off);
  68. }
  69. else if (led_state.scroll_lock && !old_led_state.scroll_lock)
  70. {
  71. PLAY_SONG(tone_scroll_on);
  72. }
  73. else if (!led_state.scroll_lock && old_led_state.scroll_lock)
  74. {
  75. PLAY_SONG(tone_scroll_off);
  76. }
  77. old_led_state = led_state;
  78. #endif // AUDIO_ENABLE
  79. return true;
  80. }