[SKY9X] Audio fix - Tested on 9XR-PRO (#4088)

* [SKY9X] Audio fix - Tested on 9XR-PRO

* [X7D] Bootloader fixes
This commit is contained in:
Bertrand Songis
2016-12-02 18:50:23 +01:00
committed by GitHub
parent 705823a9a6
commit 9b3cd8eeff
4 changed files with 97 additions and 39 deletions
+49 -5
View File
@@ -86,12 +86,14 @@ template <unsigned int NUM_BITS> class BitField {
#define BEEP_KEY_UP_FREQ (BEEP_DEFAULT_FREQ+150) #define BEEP_KEY_UP_FREQ (BEEP_DEFAULT_FREQ+150)
#define BEEP_KEY_DOWN_FREQ (BEEP_DEFAULT_FREQ-150) #define BEEP_KEY_DOWN_FREQ (BEEP_DEFAULT_FREQ-150)
#if defined(PCBSKY9X)
enum AudioBufferState enum AudioBufferState
{ {
AUDIO_BUFFER_FREE, AUDIO_BUFFER_FREE,
AUDIO_BUFFER_FILLED, AUDIO_BUFFER_FILLED,
AUDIO_BUFFER_PLAYING AUDIO_BUFFER_PLAYING
}; };
#endif
#if defined(SIMU) #if defined(SIMU)
typedef uint16_t audio_data_t; typedef uint16_t audio_data_t;
@@ -116,6 +118,7 @@ enum AudioBufferState
struct AudioBuffer { struct AudioBuffer {
audio_data_t data[AUDIO_BUFFER_SIZE]; audio_data_t data[AUDIO_BUFFER_SIZE];
uint16_t size; uint16_t size;
uint8_t state;
}; };
extern AudioBuffer audioBuffers[AUDIO_BUFFER_COUNT]; extern AudioBuffer audioBuffers[AUDIO_BUFFER_COUNT];
@@ -314,38 +317,79 @@ class AudioBufferFifo {
// returns an empty buffer to be filled wit data and put back into FIFO with audioPushBuffer() // returns an empty buffer to be filled wit data and put back into FIFO with audioPushBuffer()
AudioBuffer * getEmptyBuffer() const AudioBuffer * getEmptyBuffer() const
{ {
return full() ? 0 : &audioBuffers[writeIdx]; #if defined(PCBSKY9X)
AudioBuffer * buffer = &audioBuffers[writeIdx];
return buffer->state == AUDIO_BUFFER_FREE ? buffer : NULL;
#else
return full() ? NULL : &audioBuffers[writeIdx];
#endif
} }
// puts filled buffer into FIFO // puts filled buffer into FIFO
void audioPushBuffer() void audioPushBuffer()
{ {
// AudioBuffer * buffer = &audioBuffers[writeIdx];
audioDisableIrq(); audioDisableIrq();
#if defined(PCBSKY9X)
AudioBuffer * buffer = &audioBuffers[writeIdx];
buffer->state = AUDIO_BUFFER_FILLED;
#endif
writeIdx = nextBufferIdx(writeIdx); writeIdx = nextBufferIdx(writeIdx);
bufferFull = (writeIdx == readIdx); bufferFull = (writeIdx == readIdx);
audioEnableIrq(); audioEnableIrq();
// buffer->state = AUDIO_BUFFER_FILLED;
} }
// returns a pointer to the audio buffer to be played // returns a pointer to the audio buffer to be played
const AudioBuffer * getNextFilledBuffer() const const AudioBuffer * getNextFilledBuffer()
{ {
return empty() ? 0 : &audioBuffers[readIdx]; #if defined(PCBSKY9X)
uint8_t idx = readIdx;
do {
AudioBuffer * buffer = &audioBuffers[idx];
if (buffer->state == AUDIO_BUFFER_FILLED) {
buffer->state = AUDIO_BUFFER_PLAYING;
readIdx = idx;
return buffer;
}
idx = nextBufferIdx(idx);
} while (idx != writeIdx); // this fixes a bug if all buffers are filled
return NULL;
#else
return empty() ? NULL : &audioBuffers[readIdx];
#endif
} }
// frees the last played buffer // frees the last played buffer
void freeNextFilledBuffer() void freeNextFilledBuffer()
{ {
audioDisableIrq(); audioDisableIrq();
#if defined(PCBSKY9X)
if (audioBuffers[readIdx].state == AUDIO_BUFFER_PLAYING) {
audioBuffers[readIdx].state = AUDIO_BUFFER_FREE;
readIdx = nextBufferIdx(readIdx);
bufferFull = false;
}
#else
readIdx = nextBufferIdx(readIdx); readIdx = nextBufferIdx(readIdx);
bufferFull = false; bufferFull = false;
#endif
audioEnableIrq(); audioEnableIrq();
} }
bool filledAtleast(int noBuffers) const bool filledAtleast(int noBuffers) const
{ {
#if defined(PCBSKY9X)
int count = 0;
for(int n= 0; n<AUDIO_BUFFER_COUNT; ++n) {
if (audioBuffers[n].state == AUDIO_BUFFER_FILLED) {
if (++count >= noBuffers) {
return true;
}
}
}
return false;
#else
return used() >= noBuffers; return used() >= noBuffers;
#endif
} }
}; };
+20 -10
View File
@@ -19,7 +19,8 @@
*/ */
#include "opentx.h" #include "opentx.h"
const AudioBuffer * nextBuffer = 0;
volatile uint8_t dacStarted = false;
const int8_t volumeScale[VOLUME_LEVEL_MAX+1] = const int8_t volumeScale[VOLUME_LEVEL_MAX+1] =
{ {
@@ -94,13 +95,23 @@ void dacInit()
NVIC_EnableIRQ(DACC_IRQn) ; NVIC_EnableIRQ(DACC_IRQn) ;
} }
inline void dacStart()
{
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
DACC->DACC_IER = DACC_IER_ENDTX ;
dacStarted = true;
}
inline void dacStop()
{
DACC->DACC_IDR = DACC_IDR_ENDTX ; // Disable interrupt
dacStarted = false;
}
void audioConsumeCurrentBuffer() void audioConsumeCurrentBuffer()
{ {
if (nextBuffer == 0) { if (!dacStarted) {
nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer(); dacStart();
if (nextBuffer) {
dacStart();
}
} }
} }
@@ -109,9 +120,8 @@ extern "C" void DAC_IRQHandler()
{ {
uint32_t sr = DACC->DACC_ISR; uint32_t sr = DACC->DACC_ISR;
if (sr & DACC_ISR_ENDTX) { if (sr & DACC_ISR_ENDTX) {
if (nextBuffer) audioQueue.buffersFifo.freeNextFilledBuffer(); audioQueue.buffersFifo.freeNextFilledBuffer();
const AudioBuffer * nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
if (nextBuffer) { if (nextBuffer) {
// Try the first PDC buffer // Try the first PDC buffer
if ((DACC->DACC_TCR == 0) && (DACC->DACC_TNCR == 0)) { if ((DACC->DACC_TCR == 0) && (DACC->DACC_TNCR == 0)) {
@@ -137,7 +147,7 @@ extern "C" void DAC_IRQHandler()
// Sound routines // Sound routines
void audioInit() void audioInit()
{ {
Pio *pioptr ; Pio * pioptr ;
dacInit() ; dacInit() ;
-11
View File
@@ -29,17 +29,6 @@ void audioConsumeCurrentBuffer();
void setSampleRate( uint32_t frequency ) ; void setSampleRate( uint32_t frequency ) ;
inline void dacStart()
{
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
DACC->DACC_IER = DACC_IER_ENDTX ;
}
inline void dacStop()
{
DACC->DACC_IDR = DACC_IDR_ENDTX ; // Disable interrupt
}
#define VOLUME_LEVEL_MAX 23 #define VOLUME_LEVEL_MAX 23
#define VOLUME_LEVEL_DEF 12 #define VOLUME_LEVEL_DEF 12
+28 -13
View File
@@ -21,19 +21,34 @@
#include "opentx.h" #include "opentx.h"
#include "stamp.h" #include "stamp.h"
#define BOOTLOADER_TITLE " Taranis BootLoader - " VERSION #if defined(PCBX7D)
#if defined(PCBX9E) || defined(PCBX7D) #define BOOTLOADER_TITLE " X7 Bootloader - " VERSION
#define BOOT_KEY_UP KEY_MINUS #elif defined(PCBTARANIS)
#define BOOT_KEY_DOWN KEY_PLUS #define BOOTLOADER_TITLE " Taranis Bootloader - " VERSION
#else #else
#define BOOT_KEY_UP KEY_PLUS #error "Not implemented"
#define BOOT_KEY_DOWN KEY_MINUS #endif
#if defined(PCBX9E) || defined(PCBX7D)
#define BOOT_KEY_UP KEY_MINUS
#define BOOT_KEY_DOWN KEY_PLUS
#else
#define BOOT_KEY_UP KEY_PLUS
#define BOOT_KEY_DOWN KEY_MINUS
#endif
#define BOOT_KEY_LEFT KEY_MENU
#define BOOT_KEY_RIGHT KEY_PAGE
#define BOOT_KEY_MENU KEY_ENTER
#define BOOT_KEY_EXIT KEY_EXIT
#define DISPLAY_CHAR_WIDTH 35
#if LCD_W >= 212
#define STR_OR_PLUGIN_USB_CABLE INDENT "Or plug in a USB cable for mass storage"
#define STR_USB_CONNECTED "\026USB Connected"
#else
#define STR_OR_PLUGIN_USB_CABLE INDENT "Or plug in a USB cable"
#define STR_USB_CONNECTED "\012USB Connected "
#endif #endif
#define BOOT_KEY_LEFT KEY_MENU
#define BOOT_KEY_RIGHT KEY_PAGE
#define BOOT_KEY_MENU KEY_ENTER
#define BOOT_KEY_EXIT KEY_EXIT
#define DISPLAY_CHAR_WIDTH 35
const uint8_t bootloaderVersion[] __attribute__ ((section(".version"), used)) = const uint8_t bootloaderVersion[] __attribute__ ((section(".version"), used)) =
{ {
@@ -377,7 +392,7 @@ int main()
lcdDrawTextAlignedLeft(3*FH, "\010Restore EEPROM"); lcdDrawTextAlignedLeft(3*FH, "\010Restore EEPROM");
lcdDrawTextAlignedLeft(4*FH, "\010Exit"); lcdDrawTextAlignedLeft(4*FH, "\010Exit");
lcdInvertLine(2+vpos); lcdInvertLine(2+vpos);
lcdDrawTextAlignedLeft(7*FH, INDENT "Or plug in a USB cable for mass storage"); lcdDrawTextAlignedLeft(7*FH, STR_OR_PLUGIN_USB_CABLE);
if (event == EVT_KEY_FIRST(BOOT_KEY_DOWN)) { if (event == EVT_KEY_FIRST(BOOT_KEY_DOWN)) {
vpos == 2 ? vpos = 0 : vpos = vpos+1; vpos == 2 ? vpos = 0 : vpos = vpos+1;
} }
@@ -399,7 +414,7 @@ int main()
} }
if (state == ST_USB) { if (state == ST_USB) {
lcdDrawTextAlignedLeft(4*FH, "\026USB Connected"); lcdDrawTextAlignedLeft(4*FH, STR_USB_CONNECTED);
if (usbPlugged() == 0) { if (usbPlugged() == 0) {
vpos = 0; vpos = 0;
if (unlocked) { if (unlocked) {