Current consumption may depend on 3 different sources
Flash saving in FrSky code SD card wav player (still read as raw 12000Hz 16bit samples)
This commit is contained in:
+123
-73
@@ -33,7 +33,30 @@
|
||||
|
||||
#include "../open9x.h"
|
||||
|
||||
audioQueue::audioQueue()
|
||||
uint8_t audioState = 0;
|
||||
|
||||
uint8_t t_queueRidx;
|
||||
uint8_t t_queueWidx;
|
||||
|
||||
uint8_t toneFreq;
|
||||
//int8_t toneFreqIncr;
|
||||
uint8_t toneTimeLeft;
|
||||
uint8_t tonePause;
|
||||
|
||||
uint8_t tone2Freq;
|
||||
uint8_t tone2TimeLeft;
|
||||
uint8_t tone2Pause;
|
||||
|
||||
char toneWavFile[32+1] = "";
|
||||
|
||||
// queue arrays
|
||||
uint8_t queueToneFreq[AUDIO_QUEUE_LENGTH];
|
||||
// int8_t queueToneFreqIncr[AUDIO_QUEUE_LENGTH];
|
||||
uint8_t queueToneLength[AUDIO_QUEUE_LENGTH];
|
||||
uint8_t queueTonePause[AUDIO_QUEUE_LENGTH];
|
||||
uint8_t queueToneRepeat[AUDIO_QUEUE_LENGTH];
|
||||
|
||||
void audioInit()
|
||||
{
|
||||
toneTimeLeft = 0;
|
||||
tonePause = 0;
|
||||
@@ -42,80 +65,105 @@ audioQueue::audioQueue()
|
||||
t_queueWidx = 0;
|
||||
}
|
||||
|
||||
// heartbeat is responsibile for issueing the audio tones and general square waves
|
||||
// it is essentially the life of the class.
|
||||
// it is called every 10ms
|
||||
void audioQueue::heartbeat()
|
||||
void audioTimerHandle(void)
|
||||
{
|
||||
#if defined(SIMU)
|
||||
return;
|
||||
#endif
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
|
||||
if (toneTimeLeft > 0) {
|
||||
if (toneChanged) {
|
||||
toneChanged = 0;
|
||||
set_frequency(toneFreq * 61 / 2);
|
||||
if(toneRateLimit == 0){ //only start if within rate limit
|
||||
if(toneFreq == 0){
|
||||
tone_stop();
|
||||
} else {
|
||||
tone_start(0);
|
||||
}
|
||||
}
|
||||
toneRateLimit++; //count up the rate limit
|
||||
if(toneRateLimit == TONE1_RATE_LIMIT){ //reset the rate limit
|
||||
toneRateLimit = 0;
|
||||
}
|
||||
// TODO Should be here!
|
||||
extern uint16_t Sine_values[];
|
||||
|
||||
|
||||
void audioTask(void* pdata)
|
||||
{
|
||||
static FIL wavFile;
|
||||
|
||||
while (1) {
|
||||
CoWaitForSingleFlag(audioFlag, 0);
|
||||
|
||||
audioState = 1; // TODO #define
|
||||
|
||||
if (toneWavFile[0]) {
|
||||
FRESULT result = FR_OK;
|
||||
uint16_t bufsize = 2*WAV_BUFFER_SIZE;
|
||||
uint16_t * bufdata = wavSamplesBuffer;
|
||||
if (toneWavFile[1]) {
|
||||
result = f_open(&wavFile, toneWavFile, FA_OPEN_EXISTING | FA_READ);
|
||||
toneWavFile[1] = '\0';
|
||||
bufdata = wavSamplesArray;
|
||||
bufsize = 4*WAV_BUFFER_SIZE;
|
||||
register Dacc *dacptr = DACC;
|
||||
dacptr->DACC_TPR = (uint32_t)wavSamplesArray;
|
||||
wavSamplesBuffer = wavSamplesArray + WAV_BUFFER_SIZE;
|
||||
dacptr->DACC_TNPR = (uint32_t)wavSamplesBuffer;
|
||||
dacptr->DACC_TCR = WAV_BUFFER_SIZE/2;
|
||||
dacptr->DACC_TNCR = WAV_BUFFER_SIZE/2;
|
||||
setFrequency(12000);
|
||||
toneStart();
|
||||
}
|
||||
UINT read;
|
||||
if (result != FR_OK || f_read(&wavFile, (uint8_t *)bufdata, bufsize, &read) != FR_OK || read != bufsize) {
|
||||
f_close(&wavFile);
|
||||
toneWavFile[0] = '\0';
|
||||
toneStop();
|
||||
}
|
||||
#if 1
|
||||
else {
|
||||
read /= 2;
|
||||
for (uint32_t i=0; i<read; i++) {
|
||||
bufdata[i] = ((uint16_t)0x8000 + ((int16_t)(bufdata[i]))) >> 4;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (toneFreqIncr && (toneTimeLeft&1) == 0) {
|
||||
toneFreq += toneFreqIncr;
|
||||
set_frequency(toneFreq * 61 / 2);
|
||||
else if (toneTimeLeft > 0) {
|
||||
CoSetTmrCnt(audioTimer, toneTimeLeft, 0);
|
||||
toneTimeLeft = 0;
|
||||
// TODO function for that ...
|
||||
DACC->DACC_TPR = (uint32_t) Sine_values ;
|
||||
DACC->DACC_TCR = 50 ; // words, 100 16 bit values
|
||||
DACC->DACC_TNPR = (uint32_t) Sine_values ;
|
||||
DACC->DACC_TNCR = 50 ; // words, 100 16 bit values
|
||||
setFrequency(toneFreq * 6100 / 2);
|
||||
toneStart();
|
||||
CoStartTmr(audioTimer);
|
||||
}
|
||||
toneTimeLeft--; //time gets counted down
|
||||
}
|
||||
else {
|
||||
if (tonePause > 0) {
|
||||
tone_stop();
|
||||
toneRateLimit = 0; //reset rate limit
|
||||
tonePause--; //time gets counted down
|
||||
else if (tonePause > 0) {
|
||||
CoSetTmrCnt(audioTimer, tonePause, 0);
|
||||
tonePause = 0;
|
||||
toneStop();
|
||||
CoStartTmr(audioTimer);
|
||||
}
|
||||
else if (t_queueRidx != t_queueWidx) {
|
||||
toneChanged = 1;
|
||||
toneFreq = queueToneFreq[t_queueRidx];
|
||||
toneTimeLeft = queueToneLength[t_queueRidx];
|
||||
toneFreqIncr = queueToneFreqIncr[t_queueRidx];
|
||||
// TODO ? toneFreqIncr = queueToneFreqIncr[t_queueRidx];
|
||||
tonePause = queueTonePause[t_queueRidx];
|
||||
if (!queueToneRepeat[t_queueRidx]--) {
|
||||
t_queueRidx = (t_queueRidx + 1) % AUDIO_QUEUE_LENGTH;
|
||||
}
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
else if (tone2TimeLeft > 0) {
|
||||
CoSetTmrCnt(audioTimer, tone2TimeLeft, 0);
|
||||
tone2TimeLeft = 0;
|
||||
// TODO function for that ...
|
||||
DACC->DACC_TPR = (uint32_t) Sine_values ;
|
||||
DACC->DACC_TCR = 50 ; // words, 100 16 bit values
|
||||
DACC->DACC_TNPR = (uint32_t) Sine_values ;
|
||||
DACC->DACC_TNCR = 50 ; // words, 100 16 bit values
|
||||
setFrequency(tone2Freq * 6100 / 2);
|
||||
toneStart();
|
||||
CoStartTmr(audioTimer);
|
||||
}
|
||||
else {
|
||||
if (tone2TimeLeft > 0) {
|
||||
if (tone2Changed) {
|
||||
tone2Changed = 0;
|
||||
set_frequency(tone2Freq * 61 / 2);
|
||||
if(tone2RateLimit == 0){ //only start if within rate limit
|
||||
tone_start(0);
|
||||
}
|
||||
}
|
||||
tone2TimeLeft--; //time gets counted down
|
||||
tone2RateLimit++; //count up the rate limit
|
||||
if(tone2RateLimit == TONE2_RATE_LIMIT){ //reset the rate limit
|
||||
tone2RateLimit = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
tone_stop();
|
||||
tone2RateLimit = 0; //reset rate limit
|
||||
if (tone2Pause > 0) {
|
||||
tone2Pause--; //time gets counted down
|
||||
}
|
||||
}
|
||||
audioState = 0;
|
||||
toneStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline uint8_t audioQueue::getToneLength(uint8_t tLen)
|
||||
inline uint8_t getToneLength(uint8_t tLen)
|
||||
{
|
||||
uint8_t result = tLen; // default
|
||||
if (g_eeGeneral.beeperLength < 0) {
|
||||
@@ -127,32 +175,33 @@ inline uint8_t audioQueue::getToneLength(uint8_t tLen)
|
||||
return result;
|
||||
}
|
||||
|
||||
void audioQueue::pause(uint8_t tLen)
|
||||
void pause(uint8_t tLen)
|
||||
{
|
||||
play(0, tLen, 5); // a pause
|
||||
play(0, 0, tLen); // a pause
|
||||
}
|
||||
|
||||
void audioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
|
||||
void play(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
|
||||
uint8_t tFlags, int8_t tFreqIncr)
|
||||
{
|
||||
if (tFlags & PLAY_SOUND_VARIO) {
|
||||
tone2Changed = 1;
|
||||
tone2Freq = tFreq;
|
||||
tone2TimeLeft = tLen;
|
||||
tone2Pause = tPause;
|
||||
if (audioState == 0) CoSetFlag(audioFlag);
|
||||
}
|
||||
else {
|
||||
if (tFreq > 0) { //we dont add pitch if zero as this is a pause only event
|
||||
tFreq += g_eeGeneral.speakerPitch + BEEP_OFFSET; // add pitch compensator
|
||||
}
|
||||
tLen = getToneLength(tLen);
|
||||
if (tFlags & PLAY_NOW || (!busy() && empty())) {
|
||||
toneChanged = 1;
|
||||
if ((tFlags & PLAY_NOW) || audioState == 0) {
|
||||
toneWavFile[0] = '\0';
|
||||
toneFreq = tFreq;
|
||||
toneTimeLeft = tLen;
|
||||
tonePause = tPause;
|
||||
toneFreqIncr = tFreqIncr;
|
||||
// toneFreqIncr = tFreqIncr;
|
||||
t_queueWidx = t_queueRidx;
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
else {
|
||||
tFlags++;
|
||||
@@ -166,14 +215,20 @@ void audioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
|
||||
queueToneLength[t_queueWidx] = tLen;
|
||||
queueTonePause[t_queueWidx] = tPause;
|
||||
queueToneRepeat[t_queueWidx] = tFlags - 1;
|
||||
queueToneFreqIncr[t_queueWidx] = tFreqIncr;
|
||||
// queueToneFreqIncr[t_queueWidx] = tFreqIncr;
|
||||
t_queueWidx = next_queueWidx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void audioQueue::event(uint8_t e, uint8_t f)
|
||||
void playFile(const char *filename)
|
||||
{
|
||||
strcpy(toneWavFile, filename);
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
|
||||
void audioEvent(uint8_t e, uint8_t f)
|
||||
{
|
||||
#ifdef HAPTIC
|
||||
haptic.event(e); //do this before audio to help sync timings
|
||||
@@ -185,7 +240,7 @@ void audioQueue::event(uint8_t e, uint8_t f)
|
||||
}
|
||||
|
||||
if (g_eeGeneral.beeperMode>0 || (g_eeGeneral.beeperMode==0 && e>=AU_TRIM_MOVE) || (g_eeGeneral.beeperMode>=-1 && e<=AU_ERROR)) {
|
||||
if (e < AU_FRSKY_FIRST || empty()) {
|
||||
if (e < AU_FRSKY_FIRST || audioEmpty()) {
|
||||
switch (e) {
|
||||
// inactivity timer alert
|
||||
case AU_INACTIVITY:
|
||||
@@ -193,7 +248,7 @@ void audioQueue::event(uint8_t e, uint8_t f)
|
||||
break;
|
||||
// low battery in tx
|
||||
case AU_TX_BATTERY_LOW:
|
||||
if (empty()) {
|
||||
if (audioEmpty()) {
|
||||
play(60, 40, 6, 2, 1);
|
||||
play(80, 40, 6, 2, -1);
|
||||
}
|
||||
@@ -343,8 +398,3 @@ void audioQueue::event(uint8_t e, uint8_t f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void audioDefevent(uint8_t e)
|
||||
{
|
||||
audio.event(e, BEEP_DEFAULT_FREQ);
|
||||
}
|
||||
|
||||
+60
-79
@@ -43,91 +43,72 @@
|
||||
#define TONE1_RATE_LIMIT (10)
|
||||
#define TONE2_RATE_LIMIT (10)
|
||||
|
||||
class audioQueue
|
||||
extern uint8_t t_queueRidx;
|
||||
extern uint8_t t_queueWidx;
|
||||
|
||||
extern uint8_t toneFreq;
|
||||
//int8_t toneFreqIncr;
|
||||
extern uint8_t toneTimeLeft;
|
||||
extern uint8_t tonePause;
|
||||
|
||||
extern char toneWavFile[32+1];
|
||||
|
||||
// vario
|
||||
extern uint8_t tone2Freq;
|
||||
extern uint8_t tone2TimeLeft;
|
||||
extern uint8_t tone2Pause;
|
||||
|
||||
// queue arrays
|
||||
extern uint8_t queueToneFreq[AUDIO_QUEUE_LENGTH];
|
||||
// int8_t queueToneFreqIncr[AUDIO_QUEUE_LENGTH];
|
||||
extern uint8_t queueToneLength[AUDIO_QUEUE_LENGTH];
|
||||
extern uint8_t queueTonePause[AUDIO_QUEUE_LENGTH];
|
||||
extern uint8_t queueToneRepeat[AUDIO_QUEUE_LENGTH];
|
||||
|
||||
void initAudio();
|
||||
|
||||
void play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlags=0, int8_t tFreqIncr=0);
|
||||
void playFile(const char *filename);
|
||||
void pause(uint8_t tLen);
|
||||
|
||||
inline bool audioBusy()
|
||||
{
|
||||
public:
|
||||
return (toneTimeLeft > 0);
|
||||
}
|
||||
|
||||
audioQueue();
|
||||
void audioEvent(uint8_t e, uint8_t f=BEEP_DEFAULT_FREQ);
|
||||
|
||||
inline bool audioEmpty()
|
||||
{
|
||||
return (t_queueRidx == t_queueWidx);
|
||||
}
|
||||
|
||||
void play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlags=0, int8_t tFreqIncr=0);
|
||||
void pause(uint8_t tLen);
|
||||
#define AUDIO_KEYPAD_UP() audioEvent(AU_KEYPAD_UP)
|
||||
#define AUDIO_KEYPAD_DOWN() audioEvent(AU_KEYPAD_DOWN)
|
||||
#define AUDIO_MENUS() audioEvent(AU_MENUS)
|
||||
#define AUDIO_WARNING1() audioEvent(AU_WARNING1)
|
||||
#define AUDIO_WARNING2() audioEvent(AU_WARNING2)
|
||||
#define AUDIO_ERROR() audioEvent(AU_ERROR)
|
||||
|
||||
inline bool busy() {
|
||||
return (toneTimeLeft > 0);
|
||||
}
|
||||
#define IS_AUDIO_BUSY() audioBusy()
|
||||
|
||||
void event(uint8_t e, uint8_t f=BEEP_DEFAULT_FREQ);
|
||||
#define AUDIO_TIMER_30() audioEvent(AU_TIMER_30)
|
||||
#define AUDIO_TIMER_20() audioEvent(AU_TIMER_20)
|
||||
#define AUDIO_TIMER_10() audioEvent(AU_TIMER_10)
|
||||
#define AUDIO_TIMER_LT3() audioEvent(AU_TIMER_LT3)
|
||||
#define AUDIO_MINUTE_BEEP() audioEvent(AU_WARNING1)
|
||||
#define AUDIO_INACTIVITY() audioEvent(AU_INACTIVITY)
|
||||
#define AUDIO_MIX_WARNING_1() audioEvent(AU_MIX_WARNING_1)
|
||||
#define AUDIO_MIX_WARNING_2() audioEvent(AU_MIX_WARNING_2)
|
||||
#define AUDIO_MIX_WARNING_3() audioEvent(AU_MIX_WARNING_3)
|
||||
#define AUDIO_POT_STICK_MIDDLE() audioEvent(AU_POT_STICK_MIDDLE)
|
||||
#define AUDIO_VARIO_UP() audioEvent(AU_KEYPAD_UP)
|
||||
#define AUDIO_VARIO_DOWN() audioEvent(AU_KEYPAD_DOWN)
|
||||
#define AUDIO_TRIM_MIDDLE(f) audioEvent(AU_TRIM_MIDDLE, f)
|
||||
#define AUDIO_TRIM(event, f) audioEvent(AU_TRIM_MOVE, f)
|
||||
#define AUDIO_PLAY(p) audioEvent(p)
|
||||
#define AUDIO_VARIO(f, t) play(f, t, 0, PLAY_SOUND_VARIO)
|
||||
|
||||
// heartbeat is responsibile for issueing the audio tones and general square waves
|
||||
// it is essentially the life of the class.
|
||||
void heartbeat();
|
||||
|
||||
// bool freeslots(uint8_t slots);
|
||||
|
||||
inline bool empty() {
|
||||
return (t_queueRidx == t_queueWidx);
|
||||
}
|
||||
|
||||
protected:
|
||||
inline uint8_t getToneLength(uint8_t tLen);
|
||||
|
||||
private:
|
||||
uint8_t t_queueRidx;
|
||||
uint8_t t_queueWidx;
|
||||
|
||||
uint8_t toneChanged;
|
||||
uint8_t toneFreq;
|
||||
int8_t toneFreqIncr;
|
||||
uint8_t toneTimeLeft;
|
||||
uint8_t tonePause;
|
||||
uint8_t toneRateLimit;
|
||||
|
||||
// vario
|
||||
uint8_t tone2Changed;
|
||||
uint8_t tone2Freq;
|
||||
uint8_t tone2TimeLeft;
|
||||
uint8_t tone2Pause;
|
||||
uint8_t tone2RateLimit;
|
||||
|
||||
// queue arrays
|
||||
uint8_t queueToneFreq[AUDIO_QUEUE_LENGTH];
|
||||
int8_t queueToneFreqIncr[AUDIO_QUEUE_LENGTH];
|
||||
uint8_t queueToneLength[AUDIO_QUEUE_LENGTH];
|
||||
uint8_t queueTonePause[AUDIO_QUEUE_LENGTH];
|
||||
uint8_t queueToneRepeat[AUDIO_QUEUE_LENGTH];
|
||||
|
||||
};
|
||||
|
||||
//wrapper function - dirty but results in a space saving!!!
|
||||
extern audioQueue audio;
|
||||
|
||||
void audioDefevent(uint8_t e);
|
||||
|
||||
#define AUDIO_KEYPAD_UP() audioDefevent(AU_KEYPAD_UP)
|
||||
#define AUDIO_KEYPAD_DOWN() audioDefevent(AU_KEYPAD_DOWN)
|
||||
#define AUDIO_MENUS() audioDefevent(AU_MENUS)
|
||||
#define AUDIO_WARNING1() audioDefevent(AU_WARNING1)
|
||||
#define AUDIO_WARNING2() audioDefevent(AU_WARNING2)
|
||||
#define AUDIO_ERROR() audioDefevent(AU_ERROR)
|
||||
|
||||
|
||||
#define IS_AUDIO_BUSY() audio.busy()
|
||||
|
||||
#define AUDIO_TIMER_30() audioDefevent(AU_TIMER_30)
|
||||
#define AUDIO_TIMER_20() audioDefevent(AU_TIMER_20)
|
||||
#define AUDIO_TIMER_10() audioDefevent(AU_TIMER_10)
|
||||
#define AUDIO_TIMER_LT3() audioDefevent(AU_TIMER_LT3)
|
||||
#define AUDIO_MINUTE_BEEP() audioDefevent(AU_WARNING1)
|
||||
#define AUDIO_INACTIVITY() audioDefevent(AU_INACTIVITY)
|
||||
#define AUDIO_MIX_WARNING_1() audioDefevent(AU_MIX_WARNING_1)
|
||||
#define AUDIO_MIX_WARNING_2() audioDefevent(AU_MIX_WARNING_2)
|
||||
#define AUDIO_MIX_WARNING_3() audioDefevent(AU_MIX_WARNING_3)
|
||||
#define AUDIO_POT_STICK_MIDDLE() audioDefevent(AU_POT_STICK_MIDDLE)
|
||||
#define AUDIO_VARIO_UP() audioDefevent(AU_KEYPAD_UP)
|
||||
#define AUDIO_VARIO_DOWN() audioDefevent(AU_KEYPAD_DOWN)
|
||||
#define AUDIO_TRIM_MIDDLE(f) audio.event(AU_TRIM_MIDDLE, f)
|
||||
|
||||
#define AUDIO_HEARTBEAT() audio.heartbeat()
|
||||
#define AUDIO_HEARTBEAT()
|
||||
|
||||
#endif
|
||||
|
||||
+669
-370
File diff suppressed because it is too large
Load Diff
@@ -51,28 +51,14 @@ uint16_t Sine_values[] =
|
||||
872, 976,1084,1196,1311,1429,1550,1673,1797,1922
|
||||
} ;
|
||||
|
||||
const uint16_t PianoTones[] =
|
||||
{
|
||||
28, 29, 31, 33, 35, 37, 39, 41, 44, 46,
|
||||
49, 52, 55, 58, 62, 65, 69, 73, 78, 82,
|
||||
87, 92, 98, 104, 110, 117, 123, 131, 139, 147,
|
||||
156, 165, 175, 185, 196, 208, 220, 233, 247, 262, // d#, E, F, f#, G, g#, A, a#, B, C(middle)
|
||||
277, 294, 311, 330, 349, 370, 392, 415, 440, 466, // c#, D, d#, E, F, f#, G, g#, A, a#
|
||||
494, 523, 554, 587, 622, 659, 698, 740, 784, 831, // B, C, c#, D, d#, E, F, f#, G, g#
|
||||
880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1480,
|
||||
1568, 1661, 1760, 1865, 1976, 2093, 2217, 2349, 2489, 2637,
|
||||
2794, 2960, 3136, 3322, 3520 ,3729, 3951, 4186
|
||||
} ;
|
||||
|
||||
|
||||
// Sound routines
|
||||
|
||||
void start_sound()
|
||||
void startSound()
|
||||
{
|
||||
register Pio *pioptr ;
|
||||
|
||||
start_timer1() ;
|
||||
init_dac() ;
|
||||
initDac() ;
|
||||
init_twi() ;
|
||||
|
||||
pioptr = PIOA ;
|
||||
@@ -115,20 +101,17 @@ void buzzer_sound( uint8_t time )
|
||||
Buzzer_count = time ;
|
||||
}
|
||||
|
||||
void set_frequency( uint32_t frequency )
|
||||
void setFrequency( uint32_t frequency )
|
||||
{
|
||||
register Tc *ptc ;
|
||||
register uint32_t timer ;
|
||||
|
||||
timer = Master_frequency / (800 * frequency) ; // MCK/8 and 100 000 Hz
|
||||
if ( timer > 65535 )
|
||||
{
|
||||
timer = 65535 ;
|
||||
}
|
||||
if ( timer < 2 )
|
||||
{
|
||||
timer = 2 ;
|
||||
}
|
||||
timer = Master_frequency / (8 * frequency) ; // MCK/8 and 100 000 Hz
|
||||
if (timer > 65535)
|
||||
timer = 65535 ;
|
||||
if (timer < 2)
|
||||
timer = 2 ;
|
||||
|
||||
ptc = TC0 ; // Tc block 0 (TC0-2)
|
||||
ptc->TC_CHANNEL[1].TC_CCR = TC_CCR0_CLKDIS ; // Stop clock
|
||||
ptc->TC_CHANNEL[1].TC_RC = timer ; // 100 000 Hz
|
||||
@@ -136,7 +119,6 @@ void set_frequency( uint32_t frequency )
|
||||
ptc->TC_CHANNEL[1].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
}
|
||||
|
||||
|
||||
// Start TIMER1 at 100000Hz, used for DACC trigger
|
||||
void start_timer1()
|
||||
{
|
||||
@@ -163,7 +145,7 @@ void start_timer1()
|
||||
// Configure DAC1 (or DAC0 for REVB)
|
||||
// Not sure why PB14 has not be allocated to the DAC, although it is an EXTRA function
|
||||
// So maybe it is automatically done
|
||||
void init_dac()
|
||||
void initDac()
|
||||
{
|
||||
register Dacc *dacptr ;
|
||||
|
||||
@@ -181,23 +163,32 @@ void init_dac()
|
||||
#endif
|
||||
dacptr->DACC_CDR = 2048 ; // Half amplitude
|
||||
// Data for PDC must NOT be in flash, PDC needs a RAM source.
|
||||
#ifndef SIMU
|
||||
dacptr->DACC_TPR = (uint32_t) Sine_values ;
|
||||
dacptr->DACC_TNPR = (uint32_t) Sine_values ;
|
||||
#endif
|
||||
dacptr->DACC_TCR = 50 ; // words, 100 16 bit values
|
||||
dacptr->DACC_TCR = 50 ; // words, 100 16 bit values
|
||||
dacptr->DACC_TNCR = 50 ; // words, 100 16 bit values
|
||||
dacptr->DACC_PTCR = DACC_PTCR_TXTEN ;
|
||||
NVIC_EnableIRQ(DACC_IRQn) ;
|
||||
}
|
||||
|
||||
uint16_t wavSamplesArray[2*WAV_BUFFER_SIZE]; /* 2 buffers of 100ms at 12kHz */
|
||||
uint16_t *wavSamplesBuffer;
|
||||
|
||||
extern "C" void DAC_IRQHandler()
|
||||
{
|
||||
// Data for PDC must NOT be in flash, PDC needs a RAM source.
|
||||
#ifndef SIMU
|
||||
DACC->DACC_TNPR = (uint32_t) Sine_values ;
|
||||
#endif
|
||||
DACC->DACC_TNCR = 50 ; // words, 100 16 bit values
|
||||
if (toneWavFile[0]) {
|
||||
CoEnterISR(); // Enter the interrupt
|
||||
CoSetFlag(audioFlag);
|
||||
CoExitISR(); // Exit the interrupt
|
||||
wavSamplesBuffer = (wavSamplesBuffer == wavSamplesArray) ? wavSamplesArray+WAV_BUFFER_SIZE : wavSamplesArray;
|
||||
DACC->DACC_TNPR = (uint32_t)wavSamplesBuffer;
|
||||
DACC->DACC_TNCR = WAV_BUFFER_SIZE/2;
|
||||
}
|
||||
else {
|
||||
DACC->DACC_TNPR = (uint32_t) Sine_values ;
|
||||
DACC->DACC_TNCR = 50 ; // words, 100 16 bit values
|
||||
}
|
||||
}
|
||||
|
||||
void end_sound()
|
||||
|
||||
@@ -37,23 +37,26 @@
|
||||
|
||||
#define NUM_VOL_LEVELS 24
|
||||
|
||||
extern void start_sound( void ) ;
|
||||
extern void startSound( void ) ;
|
||||
extern void buzzer_on( void ) ;
|
||||
extern void buzzer_off( void ) ;
|
||||
extern void buzzer_sound( uint8_t time ) ;
|
||||
extern void set_frequency( uint32_t frequency ) ;
|
||||
extern void setFrequency( uint32_t frequency ) ;
|
||||
extern void start_timer1( void ) ;
|
||||
extern void init_dac( void ) ;
|
||||
extern "C" void DAC_IRQHandler( void ) ;
|
||||
extern void initDac( void ) ;
|
||||
extern void end_sound( void ) ;
|
||||
|
||||
inline void tone_start( register uint32_t time )
|
||||
#define WAV_BUFFER_SIZE 1200
|
||||
extern uint16_t wavSamplesArray[2*WAV_BUFFER_SIZE]; /* 2 buffers of 100ms at 12kHz */
|
||||
extern uint16_t *wavSamplesBuffer;
|
||||
|
||||
inline void toneStart()
|
||||
{
|
||||
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
|
||||
DACC->DACC_IER = DACC_IER_ENDTX ;
|
||||
}
|
||||
|
||||
inline void tone_stop( void )
|
||||
inline void toneStop()
|
||||
{
|
||||
DACC->DACC_IDR = DACC_IDR_ENDTX ; // Disable interrupt
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user