mirror of
https://github.com/jscrane/r65emu.git
synced 2024-10-31 13:05:08 +00:00
sound uses timed
This commit is contained in:
parent
ffd169fc8d
commit
1f7bf6935e
@ -12,17 +12,15 @@ static dac_channel_t channel;
|
||||
|
||||
static volatile const uint8_t *_bytes;
|
||||
static volatile unsigned _size, _off;
|
||||
static hw_timer_t *timer;
|
||||
|
||||
void IRAM_ATTR timer_callback() {
|
||||
portENTER_CRITICAL_ISR(&mux);
|
||||
|
||||
if (_off < _size)
|
||||
dac_output_voltage(channel, _bytes[_off++]);
|
||||
else {
|
||||
else if (_bytes) {
|
||||
_bytes = 0;
|
||||
dac_output_disable(channel);
|
||||
timerAlarmDisable(timer);
|
||||
}
|
||||
|
||||
portEXIT_CRITICAL_ISR(&mux);
|
||||
@ -34,9 +32,7 @@ void Sound::begin(unsigned pin, unsigned freq) {
|
||||
else if (pin == 26)
|
||||
channel = DAC_CHANNEL_2;
|
||||
|
||||
timer = timerBegin(1, 80, true);
|
||||
timerAttachInterrupt(timer, &timer_callback, true);
|
||||
timerAlarmWrite(timer, 1000000 / freq, true);
|
||||
timer_create(freq, &timer_callback);
|
||||
}
|
||||
|
||||
const uint8_t *Sound::play(const uint8_t *bytes, unsigned size) {
|
||||
@ -48,7 +44,6 @@ const uint8_t *Sound::play(const uint8_t *bytes, unsigned size) {
|
||||
_size = size;
|
||||
_off = 0;
|
||||
dac_output_enable(channel);
|
||||
timerAlarmEnable(timer);
|
||||
play = bytes;
|
||||
}
|
||||
|
||||
|
19
timed.cpp
19
timed.cpp
@ -9,17 +9,16 @@
|
||||
|
||||
#include "timed.h"
|
||||
|
||||
static Timed *t;
|
||||
|
||||
// FIXME: disable timer when tick() returns false
|
||||
#if defined(__LM4F120H5QR__)
|
||||
static void (*client_handler)(void);
|
||||
|
||||
static void timer0isr(void) {
|
||||
ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
|
||||
t->tick();
|
||||
client_handler();
|
||||
}
|
||||
|
||||
void timer_create(unsigned freq, Timed *client) {
|
||||
t = client;
|
||||
void timer_create(unsigned freq, void (*handler)(void)) {
|
||||
client_handler = handler;
|
||||
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
|
||||
ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
|
||||
TimerIntRegister(TIMER0_BASE, TIMER_A, timer0isr);
|
||||
@ -30,13 +29,9 @@ void timer_create(unsigned freq, Timed *client) {
|
||||
}
|
||||
#elif defined(ESP_PLATFORM)
|
||||
|
||||
void IRAM_ATTR onTimer() {
|
||||
t->tick();
|
||||
}
|
||||
|
||||
void timer_create(unsigned freq, Timed *client) {
|
||||
void timer_create(unsigned freq, void (*handler)(void)) {
|
||||
hw_timer_t *timer = timerBegin(3, 80, true); // prescaler of 80
|
||||
timerAttachInterrupt(timer, &onTimer, true);
|
||||
timerAttachInterrupt(timer, handler, true);
|
||||
timerAlarmWrite(timer, 1000000 / freq, true);
|
||||
timerAlarmEnable(timer);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user