[sky9x] Background music
This commit is contained in:
+2
-1
@@ -197,8 +197,9 @@ extern "C" {
|
||||
/ ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj
|
||||
/ function must be added to the project. */
|
||||
|
||||
// TODO needed?
|
||||
#if defined(PCBSKY9X)
|
||||
#define _FS_SHARE 3 /* 0:Disable or >=1:Enable */
|
||||
#define _FS_SHARE 4 /* 0:Disable or >=1:Enable */
|
||||
#else
|
||||
#define _FS_SHARE 2 /* 0:Disable or >=1:Enable */
|
||||
#endif
|
||||
|
||||
+2
-4
@@ -609,7 +609,7 @@ void init_pwm()
|
||||
pwmptr->PWM_CH_NUM[2].PWM_CDTYUPD = 40 ; // Duty
|
||||
pwmptr->PWM_OOV &= ~0x00040000 ; // Force low
|
||||
pwmptr->PWM_OSS = 0x00040000 ; // Force low
|
||||
// pwmptr->PWM_ENA = PWM_ENA_CHID2 ; // Enable channel 2 // TODO on REVA?
|
||||
// pwmptr->PWM_ENA = PWM_ENA_CHID2 ; // Enable channel 2 // TODO on REVA?
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1035,9 +1035,7 @@ void read_9_adc()
|
||||
#endif
|
||||
|
||||
temperature = (((int32_t)temperature * 7) + ((((int32_t)ADC->ADC_CDR15 - 838) * 621) >> 11)) >> 3; // Filter it
|
||||
if (get_tmr10ms()<100)
|
||||
return;
|
||||
if (temperature < 200 && temperature > maxTemperature) {
|
||||
if (get_tmr10ms() >= 100 && temperature > maxTemperature) {
|
||||
maxTemperature = temperature;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -798,7 +798,6 @@ void ee32_process()
|
||||
p = Eeprom32_source_address;
|
||||
q = (uint8_t *) &Eeprom_buffer.data;
|
||||
if (p != q) {
|
||||
// TODO why not memcpy
|
||||
for (x = 0; x < Eeprom32_data_size; x += 1) {
|
||||
*q++ = *p++; // Copy the data to temp buffer
|
||||
}
|
||||
|
||||
+1
-1
@@ -114,7 +114,7 @@ class EFile
|
||||
static bool exists(uint8_t i_fileId);
|
||||
|
||||
///return size of compressed file without block overhead
|
||||
uint16_t size(); // TODO static ?
|
||||
uint16_t size();
|
||||
|
||||
///open file for reading, no close necessary
|
||||
void openRd(uint8_t i_fileId);
|
||||
|
||||
+1
-1
@@ -2632,7 +2632,7 @@ void menuProcFunctionSwitches(uint8_t event)
|
||||
}
|
||||
#endif
|
||||
#if defined(PCBSKY9X) && defined(SDCARD)
|
||||
else if (sd->func == FUNC_PLAY_TRACK) {
|
||||
else if (sd->func == FUNC_PLAY_TRACK || sd->func == FUNC_BACKGND_MUSIC) {
|
||||
if (sd->param[0] && sd->param[1])
|
||||
lcd_putsnAtt(15*FW, y, sd->param, sizeof(sd->param), attr);
|
||||
else
|
||||
|
||||
@@ -358,6 +358,9 @@ enum Functions {
|
||||
FUNC_VOLUME,
|
||||
#endif
|
||||
FUNC_BACKLIGHT,
|
||||
#if defined(PCBSKY9X)
|
||||
FUNC_BACKGND_MUSIC,
|
||||
#endif
|
||||
#if defined(DEBUG)
|
||||
FUNC_TEST, // should remain the last before MAX as not added in companion9x
|
||||
#endif
|
||||
|
||||
+7
-2
@@ -1950,7 +1950,7 @@ void evalFunctions()
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X) && defined(SDCARD)
|
||||
else if (sd->func == FUNC_PLAY_TRACK) {
|
||||
else if (sd->func == FUNC_PLAY_TRACK || sd->func == FUNC_BACKGND_MUSIC) {
|
||||
if (IS_PLAYING(i+1)) {
|
||||
switch_mask = 0;
|
||||
}
|
||||
@@ -1959,7 +1959,7 @@ void evalFunctions()
|
||||
strncpy(lfn+sizeof(SOUNDS_PATH), sd->param, sizeof(sd->param));
|
||||
lfn[sizeof(SOUNDS_PATH)+sizeof(sd->param)] = '\0';
|
||||
strcat(lfn+sizeof(SOUNDS_PATH), SOUNDS_EXT);
|
||||
PLAY_FILE(lfn, i+1);
|
||||
PLAY_FILE(lfn, sd->func==FUNC_BACKGND_MUSIC ? PLAY_BACKGROUND : 0, i+1);
|
||||
}
|
||||
}
|
||||
else if (sd->func == FUNC_PLAY_VALUE) {
|
||||
@@ -2016,6 +2016,11 @@ void evalFunctions()
|
||||
activeFunctionSwitches |= switch_mask;
|
||||
}
|
||||
else {
|
||||
#if defined(PCBSKY9X) && defined(SDCARD)
|
||||
if (sd->func == FUNC_BACKGND_MUSIC) {
|
||||
STOP_PLAY(i+1);
|
||||
}
|
||||
#endif
|
||||
activeFunctionSwitches &= (~switch_mask);
|
||||
if (momentary)
|
||||
newActiveFunctions |= (activeFunctions & function_mask);
|
||||
|
||||
+1
-1
@@ -983,7 +983,7 @@ extern uint16_t jeti_keys;
|
||||
|
||||
// REPEAT uses 0x01 to 0x0f
|
||||
#define PLAY_NOW 0x10
|
||||
#define PLAY_SOUND_VARIO 0x20
|
||||
#define PLAY_BACKGROUND 0x20
|
||||
|
||||
/* make sure the defines below always go in numeric order */
|
||||
enum AUDIO_SOUNDS {
|
||||
|
||||
@@ -115,7 +115,6 @@ void *eeprom_write_function(void *)
|
||||
if (eeprom_read_operation) {
|
||||
assert(eeprom_buffer_size);
|
||||
eeprom_read_block(eeprom_buffer_data, (const void *)(int64_t)eeprom_pointer, eeprom_buffer_size);
|
||||
// TODO sleep()
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
|
||||
+2
-195
@@ -226,51 +226,6 @@ unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Configure SDcard pins
|
||||
// ConfigurePIO(mciID);
|
||||
|
||||
#if defined(MCI2_INTERFACE)
|
||||
// DMAD_Initialize(BOARD_MCI_DMA_CHANNEL, DMAD_NO_DEFAULT_IT);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// Initialize the MCI driver
|
||||
if ( mciID == 0 )
|
||||
{
|
||||
IRQ_ConfigureIT(BOARD_SD_MCI_ID, 1, MCI0_IrqHandler);
|
||||
MCI_Init(mciDrv, BOARD_SD_MCI_BASE, BOARD_SD_MCI_ID, BOARD_SD_SLOT, BOARD_MCK );
|
||||
IRQ_EnableIT(BOARD_SD_MCI_ID);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef BOARD_SD_MCI1_ID
|
||||
IRQ_ConfigureIT(BOARD_SD_MCI1_ID, 1, MCI0_IrqHandler);
|
||||
MCI_Init(mciDrv, BOARD_SD_MCI1_BASE, BOARD_SD_MCI1_ID, BOARD_SD_MCI1_SLOT, BOARD_MCK );
|
||||
IRQ_EnableIT(BOARD_SD_MCI1_ID);
|
||||
#else
|
||||
TRACE_ERROR("SD/MMC card initialization failed (MCI1 not supported)\n\r");
|
||||
#endif
|
||||
}
|
||||
#if MCI_BUSY_CHECK_FIX && defined(BOARD_SD_DAT0)
|
||||
MCI_SetBusyFix(mciDrv, &pinSdDAT0);
|
||||
#endif
|
||||
|
||||
// Initialize the SD card driver
|
||||
if (SD_Init(sdDrv, (SdDriver *)mciDrv))
|
||||
{
|
||||
TRACE_ERROR("SD/MMC card initialization failed\n\r");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//SD_DisplayRegisterCSD(&sdDrv);
|
||||
TRACE_INFO("SD/MMC card initialization successful\n\r");
|
||||
TRACE_INFO("Card size: %d MB\n\r", (int)(MMC_GetTotalSizeKB(sdDrv)/1024));
|
||||
}
|
||||
MCI_SetSpeed(mciDrv, sdDrv->transSpeed, sdDrv->transSpeed, BOARD_MCK);
|
||||
#endif
|
||||
|
||||
|
||||
media->write = MEDSdcard_Write;
|
||||
media->read = MEDSdcard_Read;
|
||||
media->lock = 0;
|
||||
@@ -281,14 +236,11 @@ unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID)
|
||||
media->blockSize = SD_BLOCK_SIZE;
|
||||
media->baseAddress = 0;
|
||||
|
||||
if (Cmd_A41_resp & OCR_SD_CCS)
|
||||
media->size = SD_CSD_BLOCKNR_HC(Card_CSD);
|
||||
else
|
||||
media->size = SD_CSD_BLOCKNR(Card_CSD);
|
||||
media->size = SD_GET_BLOCKNR();
|
||||
|
||||
media->mappedRD = 0;
|
||||
media->mappedWR = 0;
|
||||
media->protected = 0; // TODO BSS CardIsProtected(mciID);
|
||||
media->protected = 0;
|
||||
media->removable = 1;
|
||||
|
||||
media->state = MED_STATE_READY;
|
||||
@@ -302,148 +254,3 @@ unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes a Media instance and the associated physical interface
|
||||
/// \param media Pointer to the Media instance to initialize
|
||||
/// \return 1 if success.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char MEDSdusb_Initialize(Media *media, unsigned char mciID)
|
||||
{
|
||||
TRACE_INFO("MEDSdusb init\n\r");
|
||||
|
||||
// Initialize SDcard
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
if (!CardIsConnected()) return 0;
|
||||
#if 0
|
||||
// Configure SDcard pins
|
||||
ConfigurePIO(mciID);
|
||||
|
||||
#if defined(MCI2_INTERFACE)
|
||||
DMAD_Initialize(BOARD_MCI_DMA_CHANNEL, DMAD_NO_DEFAULT_IT);
|
||||
#endif
|
||||
// Initialize the MCI driver
|
||||
if ( mciID == 0 )
|
||||
{
|
||||
IRQ_ConfigureIT(BOARD_SD_MCI_ID, 1, MCI0_IrqHandler);
|
||||
MCI_Init(mciDrv, BOARD_SD_MCI_BASE, BOARD_SD_MCI_ID, BOARD_SD_SLOT, BOARD_MCK );
|
||||
IRQ_EnableIT(BOARD_SD_MCI_ID);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef BOARD_SD_MCI1_ID
|
||||
IRQ_ConfigureIT(BOARD_SD_MCI1_ID, 1, MCI0_IrqHandler);
|
||||
MCI_Init(mciDrv, BOARD_SD_MCI1_BASE, BOARD_SD_MCI1_ID, BOARD_SD_SLOT, BOARD_MCK );
|
||||
IRQ_EnableIT(BOARD_SD_MCI1_ID);
|
||||
#else
|
||||
TRACE_ERROR("SD/MMC card initialization failed (MCI1 not supported)\n\r");
|
||||
#endif
|
||||
}
|
||||
#if MCI_BUSY_CHECK_FIX && defined(BOARD_SD_DAT0)
|
||||
MCI_SetBusyFix(mciDrv, &pinSdDAT0);
|
||||
#endif
|
||||
|
||||
// Initialize the SD card driver
|
||||
if (SD_Init(sdDrv, (SdDriver *)mciDrv))
|
||||
{
|
||||
TRACE_ERROR("SD/MMC card initialization failed\n\r");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE_INFO("SD/MMC card initialization successful\n\r");
|
||||
TRACE_INFO("Card size: %d MB\n\r", (int)(MMC_GetTotalSizeKB(sdDrv)/1024));
|
||||
}
|
||||
MCI_SetSpeed(mciDrv, sdDrv->transSpeed, sdDrv->transSpeed, BOARD_MCK);
|
||||
#endif
|
||||
// Initialize media fields
|
||||
//--------------------------------------------------------------------------
|
||||
//media->interface = sdDrv;
|
||||
media->write = MEDSdusb_Write;
|
||||
media->read = MEDSdusb_Read;
|
||||
media->lock = 0;
|
||||
media->unlock = 0;
|
||||
media->handler = 0;
|
||||
media->flush = 0;
|
||||
|
||||
media->blockSize = SD_BLOCK_SIZE;
|
||||
media->baseAddress = 0;
|
||||
media->size = 1024*1024; // TODO BSS SD_TOTAL_BLOCK(sdDrv);
|
||||
|
||||
media->mappedRD = 0;
|
||||
media->mappedWR = 0;
|
||||
media->protectedd = false; // TODO BSS CardIsProtected(mciID);
|
||||
media->removable = 1;
|
||||
|
||||
media->state = MED_STATE_READY;
|
||||
|
||||
media->transfer.data = 0;
|
||||
media->transfer.address = 0;
|
||||
media->transfer.length = 0;
|
||||
media->transfer.callback = 0;
|
||||
media->transfer.argument = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
//------------------------------------------------------------------------------
|
||||
/// erase all the Sdcard
|
||||
/// \param media Pointer to the Media instance to initialize
|
||||
//------------------------------------------------------------------------------
|
||||
void MEDSdcard_EraseAll(Media *media)
|
||||
{
|
||||
unsigned char buffer[SD_BLOCK_SIZE];
|
||||
unsigned int block;
|
||||
unsigned int multiBlock = 1; // change buffer size for multiblocks
|
||||
unsigned char error;
|
||||
|
||||
TRACE_INFO("MEDSdcard Erase All ...\n\r");
|
||||
|
||||
// Clear the block buffer
|
||||
memset(buffer, 0, media->blockSize * multiBlock);
|
||||
|
||||
for (block=0;
|
||||
block < (SD_TOTAL_BLOCK((SdCard*)media->interface)-multiBlock);
|
||||
block += multiBlock)
|
||||
{
|
||||
// TODO BSS error = SD_WriteBlock((SdCard*)media->interface, block, multiBlock, buffer);
|
||||
assert( !error ); /* "\n\r-F- Failed to write block (%d) #%u\n\r", error, block */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// erase block
|
||||
/// \param media Pointer to the Media instance to initialize
|
||||
/// \param block to erase
|
||||
//------------------------------------------------------------------------------
|
||||
#if 0
|
||||
void MEDSdcard_EraseBlock(Media *media, unsigned int block)
|
||||
{
|
||||
unsigned char buffer[SD_BLOCK_SIZE];
|
||||
unsigned char error;
|
||||
|
||||
// Clear the block buffer
|
||||
memset(buffer, 0, media->blockSize);
|
||||
|
||||
// TODO BSS error = SD_WriteBlock((SdCard*)media->interface, block, 1, buffer);
|
||||
assert( !error ) ; /* "\n\r-F- Failed to write block (%d) #%u\n\r", error, block */
|
||||
}
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
/// Get driver pointer
|
||||
//------------------------------------------------------------------------------
|
||||
#if 0
|
||||
SdCard* MEDSdcard_GetDriver( unsigned int slot )
|
||||
{
|
||||
if (slot >= NUM_SD_SLOTS)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return &sdDrv[slot];
|
||||
}
|
||||
#endif
|
||||
|
||||
+151
-13
@@ -163,6 +163,8 @@ extern uint16_t Sine_values[];
|
||||
#define CODEC_ID_PCM_ALAW 6
|
||||
uint8_t pcmCodec;
|
||||
uint32_t pcmFreq = 8000;
|
||||
uint8_t backgroundCodec;
|
||||
uint32_t backgroundFreq = 8000;
|
||||
|
||||
#ifndef SIMU
|
||||
void audioTask(void* pdata)
|
||||
@@ -187,13 +189,17 @@ uint16_t wavSamplesArray[3*WAV_BUFFER_SIZE];
|
||||
uint16_t * wavSamplesBuffer = &wavSamplesArray[0];
|
||||
uint16_t * nextAudioData = NULL;
|
||||
uint16_t nextAudioSize = 0;
|
||||
bool playingBackground = false;
|
||||
|
||||
void AudioQueue::wakeup()
|
||||
{
|
||||
#if defined(SDCARD) && !defined(SIMU)
|
||||
static FIL wavFile;
|
||||
static FIL backgroundFile;
|
||||
#endif
|
||||
|
||||
bool lv_playingBackground = false;
|
||||
|
||||
if (prioIdx >= 0) {
|
||||
memset(¤t, 0, sizeof(current));
|
||||
background.duration = 0;
|
||||
@@ -271,13 +277,13 @@ void AudioQueue::wakeup()
|
||||
if (dacptr->DACC_ISR & DACC_ISR_TXBUFE) {
|
||||
dacptr->DACC_TPR = CONVERT_PTR(wavSamplesBuffer);
|
||||
dacptr->DACC_TCR = read;
|
||||
nextAudioData = NULL; // TODO possible?
|
||||
nextAudioData = NULL;
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
else if (dacptr->DACC_TNCR == 0) {
|
||||
dacptr->DACC_TNPR = CONVERT_PTR(wavSamplesBuffer);
|
||||
dacptr->DACC_TNCR = read;
|
||||
nextAudioData = NULL; // TODO possible?
|
||||
nextAudioData = NULL;
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
else {
|
||||
@@ -354,6 +360,113 @@ void AudioQueue::wakeup()
|
||||
CoClearFlag(audioFlag);
|
||||
CoStartTmr(audioTimer);
|
||||
}
|
||||
#if defined(SDCARD) && !defined(SIMU)
|
||||
else if (ridx == widx && prioIdx < 0 && background.file[0]) {
|
||||
if (!nextAudioData || DACC->DACC_ISR & DACC_ISR_TXBUFE) {
|
||||
FRESULT result = FR_OK;
|
||||
UINT read = 0;
|
||||
if (background.file[1]) {
|
||||
f_close(&backgroundFile);
|
||||
result = f_open(&backgroundFile, background.file, FA_OPEN_EXISTING | FA_READ);
|
||||
background.file[1] = 0;
|
||||
if (result == FR_OK) {
|
||||
result = f_read(&backgroundFile, (uint8_t *)wavSamplesBuffer, WAV_HEADER_SIZE, &read);
|
||||
if (result == FR_OK && read == WAV_HEADER_SIZE && !memcmp(wavSamplesBuffer, "RIFF", 4)) {
|
||||
backgroundCodec = wavSamplesBuffer[10];
|
||||
backgroundFreq = wavSamplesBuffer[12];
|
||||
if (backgroundCodec != CODEC_ID_PCM_S16LE) {
|
||||
result = f_read(&backgroundFile, (uint8_t *)wavSamplesBuffer, 12, &read);
|
||||
}
|
||||
setFrequency(backgroundFreq);
|
||||
}
|
||||
else {
|
||||
result = FR_DENIED;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!playingBackground) {
|
||||
setFrequency(backgroundFreq);
|
||||
}
|
||||
|
||||
lv_playingBackground = true;
|
||||
|
||||
read = 0;
|
||||
uint16_t bufsize = (backgroundCodec == CODEC_ID_PCM_S16LE ? WAV_BUFFER_SIZE * sizeof(uint16_t) : WAV_BUFFER_SIZE);
|
||||
if (result == FR_OK) {
|
||||
result = f_read(&backgroundFile, (uint8_t *)wavSamplesBuffer, bufsize, &read);
|
||||
}
|
||||
|
||||
if (result != FR_OK) {
|
||||
toneStop();
|
||||
background.file[0] = 0;
|
||||
f_close(&backgroundFile);
|
||||
CoSetTmrCnt(audioTimer, (WAV_BUFFER_SIZE * 1000) / backgroundFreq, 0);
|
||||
CoClearFlag(audioFlag);
|
||||
CoStartTmr(audioTimer);
|
||||
state = AUDIO_RESUMING;
|
||||
}
|
||||
else {
|
||||
if (read != bufsize) {
|
||||
background.file[0] = 0;
|
||||
f_close(&backgroundFile);
|
||||
}
|
||||
|
||||
if (backgroundCodec == CODEC_ID_PCM_S16LE) {
|
||||
read /= 2;
|
||||
uint32_t i = 0;
|
||||
for (; i < read; i++)
|
||||
wavSamplesBuffer[i] = ((uint16_t) 0x8000 + ((int16_t) (wavSamplesBuffer[i]))) >> 4;
|
||||
for (; i < WAV_BUFFER_SIZE; i++)
|
||||
wavSamplesBuffer[i] = 0x8000;
|
||||
}
|
||||
else if (backgroundCodec == CODEC_ID_PCM_ALAW) {
|
||||
int32_t i;
|
||||
for (i = read - 1; i >= 0; i--)
|
||||
wavSamplesBuffer[i] = alawTable[((uint8_t *) wavSamplesBuffer)[i]];
|
||||
for (i = read; i < WAV_BUFFER_SIZE; i++)
|
||||
wavSamplesBuffer[i] = 0x8000;
|
||||
}
|
||||
|
||||
read /= 2;
|
||||
register Dacc *dacptr = DACC;
|
||||
|
||||
if (read) {
|
||||
state = AUDIO_PLAYING_WAV;
|
||||
if (dacptr->DACC_ISR & DACC_ISR_TXBUFE) {
|
||||
dacptr->DACC_TPR = CONVERT_PTR(wavSamplesBuffer);
|
||||
dacptr->DACC_TCR = read;
|
||||
nextAudioData = NULL;
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
else if (dacptr->DACC_TNCR == 0) {
|
||||
dacptr->DACC_TNPR = CONVERT_PTR(wavSamplesBuffer);
|
||||
dacptr->DACC_TNCR = read;
|
||||
nextAudioData = NULL;
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
else {
|
||||
nextAudioSize = read;
|
||||
nextAudioData = wavSamplesBuffer;
|
||||
toneStart();
|
||||
CoSetTmrCnt(audioTimer, (WAV_BUFFER_SIZE * 500) / pcmFreq, 0);
|
||||
CoStartTmr(audioTimer);
|
||||
}
|
||||
|
||||
wavSamplesBuffer += WAV_BUFFER_SIZE;
|
||||
if (wavSamplesBuffer >= wavSamplesArray + 3 * WAV_BUFFER_SIZE)
|
||||
wavSamplesBuffer = wavSamplesArray;
|
||||
}
|
||||
else {
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
CoSetTmrCnt(audioTimer, 5/*10ms*/, 0);
|
||||
CoStartTmr(audioTimer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
CoEnterMutexSection(audioMutex);
|
||||
|
||||
@@ -395,6 +508,8 @@ void AudioQueue::wakeup()
|
||||
|
||||
CoLeaveMutexSection(audioMutex);
|
||||
}
|
||||
|
||||
playingBackground = lv_playingBackground;
|
||||
}
|
||||
|
||||
inline uint8_t getToneLength(uint8_t tLen)
|
||||
@@ -423,6 +538,10 @@ bool AudioQueue::isPlaying(uint8_t id)
|
||||
return true;
|
||||
i = (i + 1) % AUDIO_QUEUE_LENGTH;
|
||||
}
|
||||
|
||||
if (background.id == id)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -434,7 +553,7 @@ void AudioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlag
|
||||
{
|
||||
CoEnterMutexSection(audioMutex);
|
||||
|
||||
if (tFlags & PLAY_SOUND_VARIO) {
|
||||
if (tFlags & PLAY_BACKGROUND) {
|
||||
background.freq = tFreq * 2;
|
||||
background.duration = tLen;
|
||||
background.pause = tPause;
|
||||
@@ -482,26 +601,45 @@ void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id)
|
||||
|
||||
CoEnterMutexSection(audioMutex);
|
||||
|
||||
uint8_t next_widx = (widx + 1) % AUDIO_QUEUE_LENGTH;
|
||||
if (next_widx != ridx) {
|
||||
AudioFragment & fragment = fragments[widx];
|
||||
memset(&fragment, 0, sizeof(fragment));
|
||||
strcpy(fragment.file, filename);
|
||||
fragment.repeat = flags & 0x0f;
|
||||
fragment.id = id;
|
||||
if (flags & PLAY_NOW)
|
||||
prioIdx = widx;
|
||||
widx = next_widx;
|
||||
if (flags & PLAY_BACKGROUND) {
|
||||
memset(&background, 0, sizeof(background));
|
||||
strcpy(background.file, filename); // TODO strncpy
|
||||
background.id = id;
|
||||
if (!busy()) {
|
||||
state = AUDIO_RESUMING;
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
}
|
||||
else {
|
||||
uint8_t next_widx = (widx + 1) % AUDIO_QUEUE_LENGTH;
|
||||
if (next_widx != ridx) {
|
||||
AudioFragment & fragment = fragments[widx];
|
||||
memset(&fragment, 0, sizeof(fragment));
|
||||
strcpy(fragment.file, filename); // TODO strncpy
|
||||
fragment.repeat = flags & 0x0f;
|
||||
fragment.id = id;
|
||||
if (flags & PLAY_NOW)
|
||||
prioIdx = widx;
|
||||
widx = next_widx;
|
||||
if (!busy()) {
|
||||
state = AUDIO_RESUMING;
|
||||
CoSetFlag(audioFlag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CoLeaveMutexSection(audioMutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
void AudioQueue::stopPlay(uint8_t id)
|
||||
{
|
||||
// For the moment it's only needed to stop the background music
|
||||
if (background.id == id) {
|
||||
memset(&background, 0, sizeof(background));
|
||||
}
|
||||
}
|
||||
|
||||
void AudioQueue::stopSD()
|
||||
{
|
||||
sdAvailableAudioFiles = 0;
|
||||
|
||||
+9
-4
@@ -62,6 +62,8 @@ extern "C" void DAC_IRQHandler();
|
||||
#define AUDIO_PLAYING_TONE 2
|
||||
#define AUDIO_PLAYING_WAV 3
|
||||
|
||||
extern bool playingBackground;
|
||||
|
||||
class AudioQueue {
|
||||
|
||||
friend void audioTask(void* pdata);
|
||||
@@ -75,6 +77,8 @@ class AudioQueue {
|
||||
|
||||
void playFile(const char *filename, uint8_t flags=0, uint8_t id=0);
|
||||
|
||||
void stopPlay(uint8_t id);
|
||||
|
||||
void pause(uint8_t tLen);
|
||||
|
||||
void stopSD();
|
||||
@@ -86,7 +90,7 @@ class AudioQueue {
|
||||
#ifdef SIMU
|
||||
return false;
|
||||
#else
|
||||
return (state != AUDIO_SLEEPING);
|
||||
return (state != AUDIO_SLEEPING && !playingBackground);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -99,7 +103,7 @@ class AudioQueue {
|
||||
uint8_t widx;
|
||||
int8_t prioIdx;
|
||||
AudioFragment fragments[AUDIO_QUEUE_LENGTH];
|
||||
ToneFragment background; // for vario
|
||||
AudioFragment background; // for background music / vario
|
||||
|
||||
AudioFragment current;
|
||||
|
||||
@@ -141,7 +145,7 @@ void audioEvent(uint8_t e, uint8_t f=BEEP_DEFAULT_FREQ);
|
||||
#define AUDIO_TRIM_END(f) audioEvent(AU_TRIM_END, f)
|
||||
#define AUDIO_TRIM(event, f) audioEvent(AU_TRIM_MOVE, f)
|
||||
#define AUDIO_PLAY(p) audioEvent(p)
|
||||
#define AUDIO_VARIO(f, t) audioQueue.play(f, t, 0, PLAY_SOUND_VARIO)
|
||||
#define AUDIO_VARIO(f, t) audioQueue.play(f, t, 0, PLAY_BACKGROUND)
|
||||
|
||||
#define AUDIO_HEARTBEAT()
|
||||
|
||||
@@ -153,6 +157,7 @@ extern void pushPrompt(uint16_t prompt, uint8_t id=0);
|
||||
#define PLAY_DURATION(d) playDuration((d), id)
|
||||
#define IS_PLAYING(id) audioQueue.isPlaying((id))
|
||||
#define PLAY_VALUE(v, id) playValue((v), (id))
|
||||
#define PLAY_FILE(f, id) audioQueue.playFile((f), 0, (id))
|
||||
#define PLAY_FILE(f, flags, id) audioQueue.playFile((f), (flags), (id))
|
||||
#define STOP_PLAY(id) audioQueue.stopPlay((id))
|
||||
|
||||
#endif
|
||||
|
||||
@@ -173,7 +173,7 @@ void initDac()
|
||||
|
||||
extern "C" void DAC_IRQHandler()
|
||||
{
|
||||
// Data for PDC must NOT be in flash, PDC needs a RAM source.
|
||||
// Data for PDC must NOT be in flash, PDC needs a RAM source.
|
||||
if (audioQueue.state == AUDIO_PLAYING_WAV) {
|
||||
if (nextAudioData) {
|
||||
DACC->DACC_TNPR = CONVERT_PTR(nextAudioData);
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ void audioQueue::pause(uint8_t tLen)
|
||||
void audioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
|
||||
uint8_t tFlags, int8_t tFreqIncr)
|
||||
{
|
||||
if (tFlags & PLAY_SOUND_VARIO) {
|
||||
if (tFlags & PLAY_BACKGROUND) {
|
||||
tone2Freq = tFreq;
|
||||
tone2TimeLeft = tLen;
|
||||
tone2Pause = tPause;
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ void audioDefevent(uint8_t e);
|
||||
#define AUDIO_TRIM_END(f) AUDIO_TRIM_MIDDLE(f)
|
||||
#define AUDIO_TRIM(event, f) audio.event(AU_TRIM_MOVE, f)
|
||||
#define AUDIO_PLAY(p) audio.event(p)
|
||||
#define AUDIO_VARIO(f, t) audio.play(f, t, 0, PLAY_SOUND_VARIO)
|
||||
#define AUDIO_VARIO(f, t) audio.play(f, t, 0, PLAY_BACKGROUND)
|
||||
|
||||
#define AUDIO_DRIVER() audio.driver()
|
||||
#define AUDIO_HEARTBEAT() audio.heartbeat()
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
#define TR_SDCLOGS "[Logov\200n\204 SD]"
|
||||
#endif
|
||||
#define TR_FSW_VOLUME "Hlasitost\0 "
|
||||
#define TR_FSW_BG_MUSIC "Bg Music\0 "
|
||||
#elif defined(PCBGRUVIN9X)
|
||||
#if defined(SDCARD)
|
||||
#define TR_SDCLOGS "Logování SD "
|
||||
@@ -119,16 +120,18 @@
|
||||
#define TR_SDCLOGS "[Logování SD]"
|
||||
#endif
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#else
|
||||
#define TR_SDCLOGS
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
#define TR_TEST "Test\0 "
|
||||
#else
|
||||
#define TR_TEST
|
||||
#endif
|
||||
#define TR_VFSWFUNC "Bezpe\201\0 ""Tren\202r\0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Podsv\203tlen\204\0 " TR_TEST
|
||||
#define TR_VFSWFUNC "Bezpe\201\0 ""Tren\202r\0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Podsv\203tlen\204\0 " TR_FSW_BG_MUSIC TR_TEST
|
||||
|
||||
#define LEN_VFSWRESET "\006"
|
||||
#define TR_VFSWRESET "Timer1""Timer2""V\207e ""Telem."
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
#define TR_SDCLOGS "[SDCARD Logs]"
|
||||
#endif
|
||||
#define TR_FSW_VOLUME "Volume\0 "
|
||||
#define TR_FSW_BG_MUSIC "Bg Music\0 "
|
||||
#elif defined(PCBGRUVIN9X)
|
||||
#if defined(SDCARD)
|
||||
#define TR_SDCLOGS "SDcard Logs "
|
||||
@@ -119,16 +120,18 @@
|
||||
#define TR_SDCLOGS "[SDcard Logs]"
|
||||
#endif
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#else
|
||||
#define TR_SDCLOGS
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
#define TR_TEST "Test\0 "
|
||||
#else
|
||||
#define TR_TEST
|
||||
#endif
|
||||
#define TR_VFSWFUNC "Safety\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_TEST
|
||||
#define TR_VFSWFUNC "Safety\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_FSW_BG_MUSIC TR_TEST
|
||||
|
||||
#define LEN_VFSWRESET "\006"
|
||||
#define TR_VFSWRESET "Timer1""Timer2""Alle ""Telem."
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
#define TR_SDCLOGS "[SDCARD Logs]"
|
||||
#endif
|
||||
#define TR_FSW_VOLUME "Volume\0 "
|
||||
#define TR_FSW_BG_MUSIC "Bg Music\0 "
|
||||
#elif defined(PCBGRUVIN9X)
|
||||
#if defined(SDCARD)
|
||||
#define TR_SDCLOGS "SDCARD Logs "
|
||||
@@ -119,17 +120,18 @@
|
||||
#define TR_SDCLOGS "[SDCARD Logs]"
|
||||
#endif
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#else
|
||||
#define TR_SDCLOGS
|
||||
#define TR_FSW_VOLUME
|
||||
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
#define TR_TEST "Test\0"
|
||||
#else
|
||||
#define TR_TEST
|
||||
#endif
|
||||
#define TR_VFSWFUNC "Safety\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_TEST
|
||||
#define TR_VFSWFUNC "Safety\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_FSW_BG_MUSIC TR_TEST
|
||||
|
||||
#define LEN_VFSWRESET "\006"
|
||||
#define TR_VFSWRESET "Timer1""Timer2""All ""Telem."
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
#define TR_SDCLOGS "[Logs SD]\0 "
|
||||
#endif
|
||||
#define TR_FSW_VOLUME "Volume\0 "
|
||||
#define TR_FSW_BG_MUSIC "Bg Music\0 "
|
||||
#elif defined(PCBGRUVIN9X)
|
||||
#if defined(SDCARD)
|
||||
#define TR_SDCLOGS "Logs carte SD"
|
||||
@@ -114,16 +115,18 @@
|
||||
#define TR_SDCLOGS "[Logs SD]\0 "
|
||||
#endif
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#else
|
||||
#define TR_SDCLOGS
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
#define TR_TEST "Test\0 "
|
||||
#else
|
||||
#define TR_TEST
|
||||
#endif
|
||||
#define TR_VFSWFUNC "S\200cur.\0 ""Ecolage \0 ""Trim instant." TR_SOUND TR_HAPTIC "Remise \202 0\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "R\200tro\200cl.\0 " TR_TEST
|
||||
#define TR_VFSWFUNC "S\200cur.\0 ""Ecolage \0 ""Trim instant." TR_SOUND TR_HAPTIC "Remise \202 0\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "R\200tro\200cl.\0 " TR_FSW_BG_MUSIC TR_TEST
|
||||
|
||||
#define LEN_VFSWRESET "\006"
|
||||
#define TR_VFSWRESET "Timer1""Timer2""Timers""T\200l\200m."
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
#define TR_SDCLOGS "[SDCARD Logs]"
|
||||
#endif
|
||||
#define TR_FSW_VOLUME "Volume\0 "
|
||||
#define TR_FSW_BG_MUSIC "Bg Music\0 "
|
||||
#elif defined(PCBGRUVIN9X)
|
||||
#if defined(SDCARD)
|
||||
#define TR_SDCLOGS "SDCARD Logs"
|
||||
@@ -119,16 +120,18 @@
|
||||
#define TR_SDCLOGS "[SDCARD Logs]"
|
||||
#endif
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#else
|
||||
#define TR_SDCLOGS
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
#define TR_TEST "Test\0 "
|
||||
#else
|
||||
#define TR_TEST
|
||||
#endif
|
||||
#define TR_VFSWFUNC "Blocco\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_TEST
|
||||
#define TR_VFSWFUNC "Blocco\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_FSW_BG_MUSIC TR_TEST
|
||||
|
||||
#define LEN_VFSWRESET "\006"
|
||||
#define TR_VFSWRESET "Timer1""Timer2""Tutto ""Telem."
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
#define TR_SDCLOGS "[SDCARD Logg]"
|
||||
#endif
|
||||
#define TR_FSW_VOLUME "Volym\0 "
|
||||
#define TR_FSW_BG_MUSIC "Bg Music\0 "
|
||||
#elif defined(PCBGRUVIN9X)
|
||||
#if defined(SDCARD)
|
||||
#define TR_SDCLOGS "SDCARD Loggar"
|
||||
@@ -114,16 +115,18 @@
|
||||
#define TR_SDCLOGS "[SDCARD Logg]"
|
||||
#endif
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#else
|
||||
#define TR_SDCLOGS
|
||||
#define TR_FSW_VOLUME
|
||||
#define TR_FSW_BG_MUSIC
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
#define TR_TEST "Test\0 "
|
||||
#else
|
||||
#define TR_TEST
|
||||
#endif
|
||||
#define TR_VFSWFUNC "S\201kra\0 ""Trainer\0 ""S\201tt Trim " TR_SOUND TR_HAPTIC "Nollst\201ll " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Bakgrundsljus" TR_TEST
|
||||
#define TR_VFSWFUNC "S\201kra\0 ""Trainer\0 ""S\201tt Trim " TR_SOUND TR_HAPTIC "Nollst\201ll " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Bakgrundsljus" TR_FSW_BG_MUSIC TR_TEST
|
||||
|
||||
#define LEN_VFSWRESET "\006"
|
||||
#define TR_VFSWRESET "Timer1""Timer2""Allt ""Telem."
|
||||
|
||||
Reference in New Issue
Block a user