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.

97 lines
2.5 KiB

  1. /*
  2. Copyright 2017 Priyadi Iman Nurcahyo
  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. #ifdef AUDIO_ENABLE
  15. # error "AUDIO_ENABLE and FAUXCLICKY_ENABLE cannot be both enabled"
  16. #endif
  17. #include "musical_notes.h"
  18. #include "stdbool.h"
  19. __attribute__((weak)) float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_D4, 0.25);
  20. __attribute__((weak)) float fauxclicky_released_note[2] = MUSICAL_NOTE(_C4, 0.125);
  21. __attribute__((weak)) float fauxclicky_beep_note[2] = MUSICAL_NOTE(_C4, 0.25);
  22. bool fauxclicky_enabled;
  23. //
  24. // tempo in BPM
  25. //
  26. #ifndef FAUXCLICKY_TEMPO
  27. # define FAUXCLICKY_TEMPO TEMPO_DEFAULT
  28. #endif
  29. // beep on press
  30. #define FAUXCLICKY_ACTION_PRESS fauxclicky_play(fauxclicky_pressed_note)
  31. // beep on release
  32. #define FAUXCLICKY_ACTION_RELEASE fauxclicky_play(fauxclicky_released_note)
  33. // general purpose beep
  34. #define FAUXCLICKY_BEEP fauxclicky_play(fauxclicky_beep_note)
  35. // enable
  36. #define FAUXCLICKY_ON fauxclicky_enabled = true
  37. // disable
  38. #define FAUXCLICKY_OFF \
  39. do { \
  40. fauxclicky_enabled = false; \
  41. fauxclicky_stop(); \
  42. } while (0)
  43. // toggle
  44. #define FAUXCLICKY_TOGGLE \
  45. do { \
  46. if (fauxclicky_enabled) { \
  47. FAUXCLICKY_OFF; \
  48. } else { \
  49. FAUXCLICKY_ON; \
  50. } \
  51. } while (0)
  52. //
  53. // pin configuration
  54. //
  55. #ifndef FAUXCLICKY_CPU_PRESCALER
  56. # define FAUXCLICKY_CPU_PRESCALER 8
  57. #endif
  58. #ifndef FAUXCLICKY_ENABLE_OUTPUT
  59. # define FAUXCLICKY_ENABLE_OUTPUT TCCR3A |= _BV(COM3A1)
  60. #endif
  61. #ifndef FAUXCLICKY_DISABLE_OUTPUT
  62. # define FAUXCLICKY_DISABLE_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0))
  63. #endif
  64. #ifndef FAUXCLICKY_TIMER_PERIOD
  65. # define FAUXCLICKY_TIMER_PERIOD ICR3
  66. #endif
  67. #ifndef FAUXCLICKY_DUTY_CYCLE
  68. # define FAUXCLICKY_DUTY_CYCLE OCR3A
  69. #endif
  70. //
  71. // definitions
  72. //
  73. void fauxclicky_init(void);
  74. void fauxclicky_stop(void);
  75. void fauxclicky_play(float note[2]);
  76. void fauxclicky_check(void);