aboutsummaryrefslogtreecommitdiff
path: root/quantum/fauxclicky.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/fauxclicky.c')
-rw-r--r--quantum/fauxclicky.c59
1 files changed, 0 insertions, 59 deletions
diff --git a/quantum/fauxclicky.c b/quantum/fauxclicky.c
deleted file mode 100644
index 53499c9c1..000000000
--- a/quantum/fauxclicky.c
+++ /dev/null
@@ -1,59 +0,0 @@
1/*
2Copyright 2017 Priyadi Iman Nurcahyo
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12You should have received a copy of the GNU General Public License
13along with this program. If not, see <http://www.gnu.org/licenses/>.
14*/
15
16#include <avr/interrupt.h>
17#include <avr/io.h>
18#include "timer.h"
19#include "fauxclicky.h"
20#include <stdbool.h>
21#include "musical_notes.h"
22
23bool fauxclicky_enabled = true;
24uint16_t note_start = 0;
25bool note_playing = false;
26uint16_t note_period = 0;
27
28void fauxclicky_init() {
29 // Set port PC6 (OC3A and /OC4A) as output
30 DDRC |= _BV(PORTC6);
31
32 // TCCR3A / TCCR3B: Timer/Counter #3 Control Registers
33 TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
34 TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30);
35}
36
37void fauxclicky_stop() {
38 FAUXCLICKY_DISABLE_OUTPUT;
39 note_playing = false;
40}
41
42void fauxclicky_play(float note[]) {
43 if (!fauxclicky_enabled) return;
44 if (note_playing) fauxclicky_stop();
45 FAUXCLICKY_TIMER_PERIOD = (uint16_t)(((float)F_CPU) / (note[0] * (float)FAUXCLICKY_CPU_PRESCALER));
46 FAUXCLICKY_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (note[0] * (float)FAUXCLICKY_CPU_PRESCALER)) / (float)2);
47 note_playing = true;
48 note_period = (note[1] / (float)16) * ((float)60 / (float)FAUXCLICKY_TEMPO) * 1000;
49 note_start = timer_read();
50 FAUXCLICKY_ENABLE_OUTPUT;
51}
52
53void fauxclicky_check() {
54 if (!note_playing) return;
55
56 if (timer_elapsed(note_start) > note_period) {
57 fauxclicky_stop();
58 }
59}