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