opensteno_qmk/quantum/fauxclicky.h

98 lines
2.5 KiB
C
Raw Normal View History

2017-02-13 01:03:07 +00:00
/*
Copyright 2017 Priyadi Iman Nurcahyo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef AUDIO_ENABLE
2019-08-30 18:19:03 +00:00
# error "AUDIO_ENABLE and FAUXCLICKY_ENABLE cannot be both enabled"
2017-02-13 01:03:07 +00:00
#endif
#include "musical_notes.h"
#include <stdbool.h>
2017-02-13 01:03:07 +00:00
2019-08-30 18:19:03 +00:00
__attribute__((weak)) float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_D4, 0.25);
__attribute__((weak)) float fauxclicky_released_note[2] = MUSICAL_NOTE(_C4, 0.125);
__attribute__((weak)) float fauxclicky_beep_note[2] = MUSICAL_NOTE(_C4, 0.25);
2017-02-13 01:03:07 +00:00
extern bool fauxclicky_enabled;
2017-02-13 01:03:07 +00:00
//
// tempo in BPM
//
#ifndef FAUXCLICKY_TEMPO
2019-08-30 18:19:03 +00:00
# define FAUXCLICKY_TEMPO TEMPO_DEFAULT
2017-02-13 01:03:07 +00:00
#endif
// beep on press
#define FAUXCLICKY_ACTION_PRESS fauxclicky_play(fauxclicky_pressed_note)
// beep on release
#define FAUXCLICKY_ACTION_RELEASE fauxclicky_play(fauxclicky_released_note)
// general purpose beep
#define FAUXCLICKY_BEEP fauxclicky_play(fauxclicky_beep_note)
// enable
#define FAUXCLICKY_ON fauxclicky_enabled = true
// disable
2019-08-30 18:19:03 +00:00
#define FAUXCLICKY_OFF \
do { \
fauxclicky_enabled = false; \
fauxclicky_stop(); \
} while (0)
2017-02-13 01:03:07 +00:00
// toggle
2019-08-30 18:19:03 +00:00
#define FAUXCLICKY_TOGGLE \
do { \
if (fauxclicky_enabled) { \
FAUXCLICKY_OFF; \
} else { \
FAUXCLICKY_ON; \
} \
} while (0)
2017-02-13 01:03:07 +00:00
//
// pin configuration
//
#ifndef FAUXCLICKY_CPU_PRESCALER
2019-08-30 18:19:03 +00:00
# define FAUXCLICKY_CPU_PRESCALER 8
2017-02-13 01:03:07 +00:00
#endif
#ifndef FAUXCLICKY_ENABLE_OUTPUT
2019-08-30 18:19:03 +00:00
# define FAUXCLICKY_ENABLE_OUTPUT TCCR3A |= _BV(COM3A1)
2017-02-13 01:03:07 +00:00
#endif
#ifndef FAUXCLICKY_DISABLE_OUTPUT
2019-08-30 18:19:03 +00:00
# define FAUXCLICKY_DISABLE_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0))
2017-02-13 01:03:07 +00:00
#endif
#ifndef FAUXCLICKY_TIMER_PERIOD
2019-08-30 18:19:03 +00:00
# define FAUXCLICKY_TIMER_PERIOD ICR3
2017-02-13 01:03:07 +00:00
#endif
#ifndef FAUXCLICKY_DUTY_CYCLE
2019-08-30 18:19:03 +00:00
# define FAUXCLICKY_DUTY_CYCLE OCR3A
2017-02-13 01:03:07 +00:00
#endif
//
// definitions
//
void fauxclicky_init(void);
void fauxclicky_stop(void);
void fauxclicky_play(float note[2]);
void fauxclicky_check(void);