Skip to content

Commit

Permalink
Release 1.9R9
Browse files Browse the repository at this point in the history
VS1053b detection improved.
Now ogg stream are played with the vs1053b
No more glitch with the vs1053b
  • Loading branch information
karawin committed Dec 30, 2020
1 parent ad5f73a commit 4c88d3c
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 89 deletions.
Binary file modified binaries/KaRadio32.bin
Binary file not shown.
2 changes: 0 additions & 2 deletions components/audio_player/audio_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ static int start_decoder_task(player_t *player)
player->decoder_status = RUNNING;
}

spiRamFifoReset();
ESP_LOGD(TAG, "decoder task created: %s", task_name);

return 0;
Expand Down Expand Up @@ -193,7 +192,6 @@ void audio_player_stop()
if (get_audio_output_mode() != VS1053)renderer_stop();
player_instance->command = CMD_NONE;
player_status = STOPPED;

}

component_status_t get_player_status()
Expand Down
35 changes: 17 additions & 18 deletions main/addon.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ static void ClearBuffer()

static int16_t DrawString(int16_t x, int16_t y, const char *str)
{
// if (lcd_type == LCD_NONE) return -1;
if (isColor)
return ucg_DrawString(&ucg,x,y,0,str);
else
Expand All @@ -162,7 +161,6 @@ static int16_t DrawString(int16_t x, int16_t y, const char *str)

static void DrawColor(uint8_t color, uint8_t r, uint8_t g, uint8_t b)
{
// if (lcd_type == LCD_NONE) return;
if (isColor)
ucg_SetColor(&ucg, 0,r,g,b);
else
Expand All @@ -171,7 +169,6 @@ static void DrawColor(uint8_t color, uint8_t r, uint8_t g, uint8_t b)

static void DrawBox(ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h)
{
// if (lcd_type == LCD_NONE) return;
if (isColor)
ucg_DrawBox(&ucg, x,y,w,h);
else
Expand All @@ -180,15 +177,13 @@ static void DrawBox(ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h)

uint16_t GetWidth()
{
// if (lcd_type == LCD_NONE) return 0;
if (isColor)
return ucg_GetWidth(&ucg);

return u8g2.width;
}
uint16_t GetHeight()
{
// if (lcd_type == LCD_NONE) return 0;
if (isColor)
return ucg_GetHeight(&ucg);

Expand Down Expand Up @@ -522,16 +517,15 @@ static void evtClearScreen()
event_lcd_t evt;
evt.lcmd = eclrs;
evt.lline = NULL;
// xQueueSendToFront(event_lcd,&evt, 0);
xQueueSend(event_lcd,&evt, 0);
if (lcd_type != LCD_NONE) xQueueSend(event_lcd,&evt, 0);
}

static void evtScreen(typelcmd value)
{
event_lcd_t evt;
evt.lcmd = escreen;
evt.lline = (char*)((uint32_t)value);
xQueueSend(event_lcd,&evt, 0);
if (lcd_type != LCD_NONE) xQueueSend(event_lcd,&evt, 0);

}

Expand All @@ -540,7 +534,7 @@ static void evtStation(int16_t value)
event_lcd_t evt;
evt.lcmd = estation;
evt.lline = (char*)((uint32_t)value);
xQueueSend(event_lcd,&evt, 0);
if (lcd_type != LCD_NONE) xQueueSend(event_lcd,&evt, 0);
}

// toggle main / time
Expand All @@ -549,7 +543,7 @@ static void toggletime()
event_lcd_t evt;
evt.lcmd = etoggle;
evt.lline = NULL;
xQueueSend(event_lcd,&evt, 0);
if (lcd_type != LCD_NONE) xQueueSend(event_lcd,&evt, 0);
}

//----------------------------
Expand Down Expand Up @@ -1267,15 +1261,20 @@ void task_addon(void *pvParams)
// queue for events of the IR nec rx
event_ir = xQueueCreate(5, sizeof(event_ir_t));
ESP_LOGD(TAG,"event_ir: %x",(int)event_ir);
// queue for events of the lcd
event_lcd = xQueueCreate(20, sizeof(event_lcd_t));
ESP_LOGD(TAG,"event_lcd: %x",(int)event_lcd);


xTaskCreatePinnedToCore(rmt_nec_rx_task, "rmt_nec_rx_task", 2148, NULL, PRIO_RMT, &pxCreatedTask,CPU_RMT);
ESP_LOGI(TAG, "%s task: %x","rmt_nec_rx_task",(unsigned int)pxCreatedTask); ;
xTaskCreatePinnedToCore (task_lcd, "task_lcd", 2200, NULL, PRIO_LCD, &pxTaskLcd,CPU_LCD);
ESP_LOGI(TAG, "%s task: %x","task_lcd",(unsigned int)pxTaskLcd);
getTaskLcd(&pxTaskLcd); // give the handle to xpt

if (g_device->lcd_type!=LCD_NONE)
{
// queue for events of the lcd
event_lcd = xQueueCreate(20, sizeof(event_lcd_t));
ESP_LOGD(TAG,"event_lcd: %x",(int)event_lcd);

xTaskCreatePinnedToCore (task_lcd, "task_lcd", 2200, NULL, PRIO_LCD, &pxTaskLcd,CPU_LCD);
ESP_LOGI(TAG, "%s task: %x","task_lcd",(unsigned int)pxTaskLcd);
getTaskLcd(&pxTaskLcd); // give the handle to xpt
}

while (1)
{
Expand Down Expand Up @@ -1423,7 +1422,7 @@ void addonParse(const char *fmt, ...)
evt.lcmd = lovol;
evt.lline = NULL;
}
if (evt.lcmd != -1) xQueueSend(event_lcd,&evt, 0);
if (evt.lcmd != -1 && lcd_type !=LCD_NONE) xQueueSend(event_lcd,&evt, 0);
free (line);
}

1 change: 1 addition & 0 deletions main/custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void backlight_percentage_set(int value)
{
if (lcdb != GPIO_NONE)
{
if (value > 100) value = 100;
int duty = DUTY_MAX * (value * 0.01f);
// printf("backlight_percentage_set %d\n",value);
ledc_set_fade_with_time(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, duty, 20);
Expand Down
2 changes: 1 addition & 1 deletion main/include/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


#define RELEASE "1.9"
#define REVISION "8"
#define REVISION "9"

uint32_t checkUart(uint32_t speed);
extern unsigned short adcdiv;
Expand Down
2 changes: 1 addition & 1 deletion main/include/vs1053.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int VS1053_SendMusicBytes(uint8_t* music,uint16_t quantity);
uint16_t VS1053_GetBitrate();
uint16_t VS1053_GetSampleRate();
uint16_t VS1053_GetDecodeTime();
void VS1053_flush_cancel(uint8_t mode);// 0 only fillbyte 1 before play 2 close play
void VS1053_flush_cancel();
void VS1053_spi_init();
// admix plugin control
void VS1053_SetVolumeLine(int16_t vol);
Expand Down
93 changes: 42 additions & 51 deletions main/vs1053.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ bool VS1053_HW_init()
gpio_conf.intr_type = GPIO_INTR_DISABLE;
gpio_conf.pin_bit_mask = ((uint64_t)(((uint64_t)1)<<rst));
ESP_ERROR_CHECK(gpio_config(&gpio_conf));

// ControlReset(RESET);
//gpio_set_direction(rst, GPIO_MODE_OUTPUT);


gpio_conf.mode = GPIO_MODE_INPUT;
gpio_conf.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
Expand All @@ -169,9 +166,18 @@ void ControlReset(uint8_t State){
gpio_set_level(rst, State);
}

uint8_t VS1053_checkDREQ() {
uint8_t CheckDREQ() {
return gpio_get_level(dreq);
}
#define TMAX 4096
void WaitDREQ() {
uint16_t time_out = 0;
while(gpio_get_level(dreq) == 0 && time_out++ < TMAX)
{
taskYIELD();
}
// if (time_out >0) ESP_LOGI(TAG,"timeout: %d",time_out);
}

void VS1053_spi_write_char(uint8_t *cbyte, uint16_t len)
{
Expand All @@ -182,14 +188,12 @@ void VS1053_spi_write_char(uint8_t *cbyte, uint16_t len)
t.tx_buffer = cbyte;
t.length= len*8;
//t.rxlength=0;
while(VS1053_checkDREQ() == 0)taskYIELD ();
while(gpio_get_level(dreq) == 0 )taskYIELD();
spi_take_semaphore(hsSPI);
ret = spi_device_transmit(hvsspi, &t); //Transmit!
if (ret != ESP_OK) ESP_LOGE(TAG,"err: %d, VS1053_spi_write_char(len: %d)",ret,len);
spi_give_semaphore(hsSPI);
while(VS1053_checkDREQ() == 0);
//printf("VS1053_spi_write val: %x rxlen: %x \n",*cbyte,t.rxlength);
// return ret;
// while(gpio_get_level(dreq) == 0 );
}

void VS1053_WriteRegister(uint8_t addressbyte, uint8_t highbyte, uint8_t lowbyte)
Expand All @@ -206,13 +210,13 @@ void VS1053_WriteRegister(uint8_t addressbyte, uint8_t highbyte, uint8_t lowbyte
t.tx_data[0] = highbyte;
t.tx_data[1] = lowbyte;
t.length= 16;
while(VS1053_checkDREQ() == 0)taskYIELD ();
WaitDREQ();
spi_take_semaphore(vsSPI);
// ESP_ERROR_CHECK(spi_device_transmit(vsspi, &t)); //Transmit!
ret = spi_device_transmit(vsspi, &t); //Transmit!
if (ret != ESP_OK) ESP_LOGE(TAG,"err: %d, VS1053_WriteRegister(%d,%d,%d)",ret,addressbyte,highbyte,lowbyte);
spi_give_semaphore(vsSPI);
while(VS1053_checkDREQ() == 0);
WaitDREQ();
}

void VS1053_WriteRegister16(uint8_t addressbyte, uint16_t value)
Expand All @@ -229,13 +233,13 @@ void VS1053_WriteRegister16(uint8_t addressbyte, uint16_t value)
t.tx_data[0] = (value>>8)&0xff;
t.tx_data[1] = value&0xff;
t.length= 16;
while(VS1053_checkDREQ() == 0)taskYIELD ();
WaitDREQ();
spi_take_semaphore(vsSPI);
// ESP_ERROR_CHECK(spi_device_transmit(vsspi, &t)); //Transmit!
ret = spi_device_transmit(vsspi, &t); //Transmit!
if (ret != ESP_OK) ESP_LOGE(TAG,"err: %d, VS1053_WriteRegister16(%d,%d)",ret,addressbyte,value);
spi_give_semaphore(vsSPI);
while(VS1053_checkDREQ() == 0);
WaitDREQ();

}

Expand All @@ -249,14 +253,14 @@ uint16_t VS1053_ReadRegister(uint8_t addressbyte){
t.flags |= SPI_TRANS_USE_RXDATA ;
t.cmd = VS_READ_COMMAND;
t.addr = addressbyte;
while(VS1053_checkDREQ() == 0) taskYIELD ();
WaitDREQ();
spi_take_semaphore(vsSPI);
ret = spi_device_transmit(vsspi, &t); //Transmit!
if (ret != ESP_OK) ESP_LOGE(TAG,"err: %d, VS1053_ReadRegister(%d), read: %d",ret,addressbyte,(uint32_t)*t.rx_data);
result = (((t.rx_data[0]&0xFF)<<8) | ((t.rx_data[1])&0xFF)) ;
// ESP_LOGI(TAG,"VS1053_ReadRegister data: %d %d %d %d",t.rx_data[0],t.rx_data[1],t.rx_data[2],t.rx_data[3]);
spi_give_semaphore(vsSPI);
while(VS1053_checkDREQ() == 0);
WaitDREQ();
return result;
}

Expand All @@ -272,7 +276,7 @@ void VS1053_ResetChip(){
vTaskDelay(30);
ControlReset(RESET);
vTaskDelay(10);
if (VS1053_checkDREQ() == 1) return;
if (CheckDREQ() == 1) return;
vTaskDelay(30);
}

Expand Down Expand Up @@ -327,7 +331,7 @@ void VS1053_Start(){
ControlReset(RESET);
vTaskDelay(200);
//Check DREQ
if (VS1053_checkDREQ() == 0)
if (CheckDREQ() == 0)
{
vsVersion = 0;
ESP_LOGE(TAG,"NO VS1053 detected");
Expand Down Expand Up @@ -376,22 +380,21 @@ void VS1053_Start(){
// VS1053_WriteRegister(SPI_CLOCKF,0x78,0x00); // SC_MULT = x3, SC_ADD= x2
// VS1053_WriteRegister16(SPI_CLOCKF,0xB800); // SC_MULT = x1, SC_ADD= x1
VS1053_WriteRegister16(SPI_CLOCKF,0x8800); // SC_MULT = x3.5, SC_ADD= x1
// VS1053_WriteRegister(SPI_CLOCKF,0x90,0x00); // SC_MULT = x3.5, SC_ADD= x1.5
else
VS1053_WriteRegister16(SPI_CLOCKF,0xB000);

//VS1053_SoftwareReset
VS1053_WriteRegister(SPI_MODE, (SM_SDINEW|SM_LINE1)>>8,SM_RESET);
VS1053_WriteRegister(SPI_MODE, (SM_SDINEW|SM_LINE1)>>8, SM_LAYER12); //mode
while(VS1053_checkDREQ() == 0)taskYIELD ();
WaitDREQ();

VS1053_regtest();

// enable I2C dac output of the vs1053
if (vsVersion == 4) // only 1053
{
VS1053_WriteRegister16(SPI_WRAMADDR, 0xc017); //
VS1053_WriteRegister16(SPI_WRAM, 0x00F0); //
VS1053_WriteRegister16(SPI_WRAMADDR, 0xc017);
VS1053_WriteRegister16(SPI_WRAM, 0x00F0);
VS1053_I2SRate(g_device->i2sspeed);

// plugin patch
Expand All @@ -413,17 +416,14 @@ void VS1053_Start(){
int VS1053_SendMusicBytes(uint8_t* music, uint16_t quantity){
if(quantity ==0) return 0;
int oo = 0;
// while(VS1053_checkDREQ() == 0);taskYIELD ();

while(quantity)
{
// if(VS1053_checkDREQ())
{
int t = quantity;
if(t > CHUNK) t = CHUNK;
VS1053_spi_write_char(&music[oo], t);
oo += t;
quantity -= t;
} // else taskYIELD ();
int t = quantity;
if(t > CHUNK) t = CHUNK;
VS1053_spi_write_char(&music[oo], t);
oo += t;
quantity -= t;
}
return oo;
}
Expand Down Expand Up @@ -610,41 +610,32 @@ uint16_t VS1053_GetSampleRate(){
}

/* to start and stop a new stream */
void VS1053_flush_cancel(uint8_t mode) { // 0 only fillbyte 1 before play 2 cancel play
// int8_t endFillByte = (int8_t) (Mp3ReadWRAM(para_endFillByte) & 0xFF);
void VS1053_flush_cancel() {
int8_t endFillByte ;
int16_t y;
uint8_t buf[513];
if (mode != 2)
{
VS1053_WriteRegister(SPI_WRAMADDR,MaskAndShiftRight(para_endFillByte,0xFF00,8), (para_endFillByte & 0x00FF) );
endFillByte = (int8_t) VS1053_ReadRegister(SPI_WRAM) & 0xFF;
for (y = 0; y < 513; y++) buf[y] = endFillByte;
}

if (mode != 0) //set CANCEL
{
uint8_t buf[514];
// set spimode with SM_CANCEL
uint16_t spimode = VS1053_ReadRegister(SPI_MODE)| SM_CANCEL;
// set CANCEL
VS1053_WriteRegister(SPI_MODE,MaskAndShiftRight(spimode,0xFF00,8), (spimode & 0x00FF) );
// wait CANCEL
endFillByte = (int8_t) VS1053_ReadRegister(SPI_WRAM) & 0xFF;
for (y = 0; y < 33; y++) buf[y] = endFillByte;
y = 0;
while (VS1053_ReadRegister(SPI_MODE)& SM_CANCEL)
{
if (mode == 1) VS1053_SendMusicBytes( buf, CHUNK); //1
else vTaskDelay(1); //2
// printf ("Wait CANCEL clear\n");
if (y++ > 200)
VS1053_SendMusicBytes( buf, 32);
if (y++ > 64)
{
if (mode == 1) VS1053_Start();
ESP_LOGE(TAG,"VS1053 Reset");
// VS1053_Start();
break;
}
}
VS1053_WriteRegister(SPI_WRAMADDR,MaskAndShiftRight(para_endFillByte,0xFF00,8), (para_endFillByte & 0x00FF) );

endFillByte = (int8_t) VS1053_ReadRegister(SPI_WRAM) & 0xFF;
for (y = 0; y < 513; y++) buf[y] = endFillByte;
}
for ( y = 0; y < 5; y++) VS1053_SendMusicBytes( buf, 512); // 4*513 = 2052
for (y = 0; y < 513; y++) buf[y] = endFillByte;
for ( y = 0; y < 5; y++) VS1053_SendMusicBytes( buf, 513); // 4*513 = 2052
}


Expand Down
9 changes: 3 additions & 6 deletions main/webclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,17 +1262,14 @@ void clientTask(void *pvParams) {
setVolumei(0);
if (get_player_status() != STOPPED)
audio_player_stop();
//if (get_audio_output_mode() == VS1053) spiRamFifoReset();
player_config->media_stream->eof = true;
// bufferReset();
if (get_audio_output_mode() == VS1053)VS1053_flush_cancel(2);
if (get_audio_output_mode() == VS1053) VS1053_flush_cancel();
playing = 0;
vTaskDelay(40); // stop without click
vTaskDelay(20); // stop without click
//VS1053_LowPower();
setVolumei(getVolume());
}

// bufferReset();
spiRamFifoReset();
shutdown(sockfd,SHUT_RDWR); // stop the socket
vTaskDelay(1);
close(sockfd);
Expand Down
Loading

0 comments on commit 4c88d3c

Please sign in to comment.