fauxclicky.h 2.1 KB

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