diff options
Diffstat (limited to 'quantum/fauxclicky.h')
| -rw-r--r-- | quantum/fauxclicky.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/quantum/fauxclicky.h b/quantum/fauxclicky.h new file mode 100644 index 000000000..109bd0d83 --- /dev/null +++ b/quantum/fauxclicky.h | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2017 Priyadi Iman Nurcahyo | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 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 | You should have received a copy of the GNU General Public License | ||
| 13 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 14 | */ | ||
| 15 | |||
| 16 | #ifdef AUDIO_ENABLE | ||
| 17 | #error "AUDIO_ENABLE and FAUXCLICKY_ENABLE cannot be both enabled" | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #include "musical_notes.h" | ||
| 21 | #include "stdbool.h" | ||
| 22 | |||
| 23 | __attribute__ ((weak)) | ||
| 24 | float fauxclicky_pressed_note[2]; | ||
| 25 | __attribute__ ((weak)) | ||
| 26 | float fauxclicky_released_note[2]; | ||
| 27 | __attribute__ ((weak)) | ||
| 28 | float fauxclicky_beep_note[2]; | ||
| 29 | |||
| 30 | bool fauxclicky_enabled; | ||
| 31 | |||
| 32 | // | ||
| 33 | // tempo in BPM | ||
| 34 | // | ||
| 35 | |||
| 36 | #ifndef FAUXCLICKY_TEMPO | ||
| 37 | #define FAUXCLICKY_TEMPO TEMPO_DEFAULT | ||
| 38 | #endif | ||
| 39 | |||
| 40 | // beep on press | ||
| 41 | #define FAUXCLICKY_ACTION_PRESS fauxclicky_play(fauxclicky_pressed_note) | ||
| 42 | |||
| 43 | // beep on release | ||
| 44 | #define FAUXCLICKY_ACTION_RELEASE fauxclicky_play(fauxclicky_released_note) | ||
| 45 | |||
| 46 | // general purpose beep | ||
| 47 | #define FAUXCLICKY_BEEP fauxclicky_play(fauxclicky_beep_note) | ||
| 48 | |||
| 49 | // enable | ||
| 50 | #define FAUXCLICKY_ON fauxclicky_enabled = true | ||
| 51 | |||
| 52 | // disable | ||
| 53 | #define FAUXCLICKY_OFF do { \ | ||
| 54 | fauxclicky_enabled = false; \ | ||
| 55 | fauxclicky_stop(); \ | ||
| 56 | } while (0) | ||
| 57 | |||
| 58 | // toggle | ||
| 59 | #define FAUXCLICKY_TOGGLE do { \ | ||
| 60 | if (fauxclicky_enabled) { \ | ||
| 61 | FAUXCLICKY_OFF; \ | ||
| 62 | } else { \ | ||
| 63 | FAUXCLICKY_ON; \ | ||
| 64 | } \ | ||
| 65 | } while (0) | ||
| 66 | |||
| 67 | // | ||
| 68 | // pin configuration | ||
| 69 | // | ||
| 70 | |||
| 71 | #ifndef FAUXCLICKY_CPU_PRESCALER | ||
| 72 | #define FAUXCLICKY_CPU_PRESCALER 8 | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #ifndef FAUXCLICKY_ENABLE_OUTPUT | ||
| 76 | #define FAUXCLICKY_ENABLE_OUTPUT TCCR3A |= _BV(COM3A1); | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #ifndef FAUXCLICKY_DISABLE_OUTPUT | ||
| 80 | #define FAUXCLICKY_DISABLE_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0)); | ||
| 81 | #endif | ||
| 82 | |||
| 83 | #ifndef FAUXCLICKY_TIMER_PERIOD | ||
| 84 | #define FAUXCLICKY_TIMER_PERIOD ICR3 | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #ifndef FAUXCLICKY_DUTY_CYCLE | ||
| 88 | #define FAUXCLICKY_DUTY_CYCLE OCR3A | ||
| 89 | #endif | ||
| 90 | |||
| 91 | // | ||
| 92 | // definitions | ||
| 93 | // | ||
| 94 | |||
| 95 | void fauxclicky_init(void); | ||
| 96 | void fauxclicky_stop(void); | ||
| 97 | void fauxclicky_play(float note[2]); | ||
| 98 | void fauxclicky_check(void); | ||
| 99 | |||
