aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/fauxclicky.c59
-rw-r--r--quantum/fauxclicky.h97
-rw-r--r--quantum/quantum.c15
-rw-r--r--quantum/quantum_keycodes.h10
4 files changed, 3 insertions, 178 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}
diff --git a/quantum/fauxclicky.h b/quantum/fauxclicky.h
deleted file mode 100644
index ed54d0edc..000000000
--- a/quantum/fauxclicky.h
+++ /dev/null
@@ -1,97 +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#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)) float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_D4, 0.25);
24__attribute__((weak)) float fauxclicky_released_note[2] = MUSICAL_NOTE(_C4, 0.125);
25__attribute__((weak)) float fauxclicky_beep_note[2] = MUSICAL_NOTE(_C4, 0.25);
26
27extern bool fauxclicky_enabled;
28
29//
30// tempo in BPM
31//
32
33#ifndef FAUXCLICKY_TEMPO
34# define FAUXCLICKY_TEMPO TEMPO_DEFAULT
35#endif
36
37// beep on press
38#define FAUXCLICKY_ACTION_PRESS fauxclicky_play(fauxclicky_pressed_note)
39
40// beep on release
41#define FAUXCLICKY_ACTION_RELEASE fauxclicky_play(fauxclicky_released_note)
42
43// general purpose beep
44#define FAUXCLICKY_BEEP fauxclicky_play(fauxclicky_beep_note)
45
46// enable
47#define FAUXCLICKY_ON fauxclicky_enabled = true
48
49// disable
50#define FAUXCLICKY_OFF \
51 do { \
52 fauxclicky_enabled = false; \
53 fauxclicky_stop(); \
54 } while (0)
55
56// toggle
57#define FAUXCLICKY_TOGGLE \
58 do { \
59 if (fauxclicky_enabled) { \
60 FAUXCLICKY_OFF; \
61 } else { \
62 FAUXCLICKY_ON; \
63 } \
64 } while (0)
65
66//
67// pin configuration
68//
69
70#ifndef FAUXCLICKY_CPU_PRESCALER
71# define FAUXCLICKY_CPU_PRESCALER 8
72#endif
73
74#ifndef FAUXCLICKY_ENABLE_OUTPUT
75# define FAUXCLICKY_ENABLE_OUTPUT TCCR3A |= _BV(COM3A1)
76#endif
77
78#ifndef FAUXCLICKY_DISABLE_OUTPUT
79# define FAUXCLICKY_DISABLE_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0))
80#endif
81
82#ifndef FAUXCLICKY_TIMER_PERIOD
83# define FAUXCLICKY_TIMER_PERIOD ICR3
84#endif
85
86#ifndef FAUXCLICKY_DUTY_CYCLE
87# define FAUXCLICKY_DUTY_CYCLE OCR3A
88#endif
89
90//
91// definitions
92//
93
94void fauxclicky_init(void);
95void fauxclicky_stop(void);
96void fauxclicky_play(float note[2]);
97void fauxclicky_check(void);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 8ae487bec..6d202c515 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -25,10 +25,6 @@
25# include "backlight.h" 25# include "backlight.h"
26#endif 26#endif
27 27
28#ifdef FAUXCLICKY_ENABLE
29# include "fauxclicky.h"
30#endif
31
32#ifdef API_ENABLE 28#ifdef API_ENABLE
33# include "api.h" 29# include "api.h"
34#endif 30#endif
@@ -310,17 +306,6 @@ bool process_record_quantum(keyrecord_t *record) {
310 case EEPROM_RESET: 306 case EEPROM_RESET:
311 eeconfig_init(); 307 eeconfig_init();
312 return false; 308 return false;
313#ifdef FAUXCLICKY_ENABLE
314 case FC_TOG:
315 FAUXCLICKY_TOGGLE;
316 return false;
317 case FC_ON:
318 FAUXCLICKY_ON;
319 return false;
320 case FC_OFF:
321 FAUXCLICKY_OFF;
322 return false;
323#endif
324#ifdef VELOCIKEY_ENABLE 309#ifdef VELOCIKEY_ENABLE
325 case VLK_TOG: 310 case VLK_TOG:
326 velocikey_toggle(); 311 velocikey_toggle();
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 0160c5586..e0f5dbc61 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -150,13 +150,6 @@ enum quantum_keycodes {
150 CLICKY_DOWN, 150 CLICKY_DOWN,
151 CLICKY_RESET, 151 CLICKY_RESET,
152 152
153#ifdef FAUXCLICKY_ENABLE
154 // Faux clicky
155 FC_ON,
156 FC_OFF,
157 FC_TOG,
158#endif
159
160 // Music mode on/off/toggle 153 // Music mode on/off/toggle
161 MU_ON, 154 MU_ON,
162 MU_OFF, 155 MU_OFF,
@@ -717,6 +710,9 @@ enum quantum_keycodes {
717#define CK_DOWN CLICKY_DOWN 710#define CK_DOWN CLICKY_DOWN
718#define CK_ON CLICKY_ENABLE 711#define CK_ON CLICKY_ENABLE
719#define CK_OFF CLICKY_DISABLE 712#define CK_OFF CLICKY_DISABLE
713#define FC_ON CLICKY_ENABLE
714#define FC_OFF CLICKY_DISABLE
715#define FC_TOGG CLICKY_TOGGLE
720 716
721#define RGB_MOD RGB_MODE_FORWARD 717#define RGB_MOD RGB_MODE_FORWARD
722#define RGB_RMOD RGB_MODE_REVERSE 718#define RGB_RMOD RGB_MODE_REVERSE