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.

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