Skip to content

Commit

Permalink
vs1053 stated in midi mode
Browse files Browse the repository at this point in the history
  • Loading branch information
karawin committed Dec 30, 2020
1 parent 3404f0d commit ad5f73a
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 26 deletions.
Binary file modified binaries/KaRadio32.bin
Binary file not shown.
66 changes: 66 additions & 0 deletions boards/radiva52.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
key type encoding value
label_space namespace
L_LABEL data string radiva52.csv
L_COMMENT data string xcs:15 xdcs:2 rst:12 dreq:4 a/d:14 d_cs:13 d_rst:32 ir:36 lcd:194 led:22 bl:27 t_cs:21 miso:19 mosi:23 sck:18 disp:203
gpio_space namespace
K_SPI data u8 2
P_MISO data u8 19
P_MOSI data u8 23
P_CLK data u8 18
P_XCS data u8 15
P_RST data u8 12
P_XDCS data u8 2
P_DREQ data u8 4
P_ENC0_A data u8 255
P_ENC0_B data u8 255
P_ENC0_BTN data u8 255
P_ENC1_A data u8 255
P_ENC1_B data u8 255
P_ENC1_BTN data u8 255
P_BTN0_A data u8 255
P_BTN0_B data u8 255
P_BTN0_C data u8 255
P_BTN1_A data u8 255
P_BTN1_B data u8 255
P_BTN1_C data u8 255
P_I2C_SCL data u8 255
P_I2C_SDA data u8 255
P_I2C_RST data u8 255
P_LCD_CS data u8 13
P_LCD_A0 data u8 14
P_LCD_RST data u8 32
P_IR_SIGNAL data u8 36
P_I2S_LRCK data u8 255
P_I2S_BCLK data u8 255
P_I2S_DATA data u8 255
P_TOUCH_CS data u8 21
P_JOY_0 data u8 255
P_JOY_1 data u8 255
P_LED_GPIO data u8 22
P_ADC_KBD data u8 255
P_BACKLIGHT data u8 27
option_space namespace
O_BTN0 data u8 0
O_LCD_TYPE data u8 203
O_LCD_ROTA data u8 0
O_LCD_OUT data u32 0
O_DDMM_FLAG data u8 1
custom_ir_space namespace
K_UP data string
K_LEFT data string
K_OK data string
K_RIGHT data string
K_DOWN data string
K_0 data string
K_1 data string
K_2 data string
K_3 data string
K_4 data string
K_5 data string
K_6 data string
K_7 data string
K_8 data string
K_9 data string
K_STAR data string
K_DIESE data string
K_INFO data string
2 changes: 1 addition & 1 deletion main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ void start_network(){
IPADDR2_COPY(&g_device->mask1, &info.netmask);
IPADDR2_COPY(&g_device->gate1, &info.gw);
break;
case STA2: //ssid1 used
case STA2: //ssid2 used
IPADDR2_COPY(&g_device->ipAddr2, &info.ip);
IPADDR2_COPY(&g_device->mask2, &info.netmask);
IPADDR2_COPY(&g_device->gate2, &info.gw);
Expand Down
65 changes: 43 additions & 22 deletions main/vs1053.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ uint8_t VS1053_checkDREQ() {
return gpio_get_level(dreq);
}

void VS1053_spi_write_char(spi_device_handle_t ivsspi, uint8_t *cbyte, uint16_t len)
void VS1053_spi_write_char(uint8_t *cbyte, uint16_t len)
{
esp_err_t ret;
spi_transaction_t t;
Expand All @@ -184,8 +184,7 @@ void VS1053_spi_write_char(spi_device_handle_t ivsspi, uint8_t *cbyte, uint16_t
//t.rxlength=0;
while(VS1053_checkDREQ() == 0)taskYIELD ();
spi_take_semaphore(hsSPI);
// ESP_ERROR_CHECK(spi_device_transmit(ivsspi, &t)); //Transmit!
ret = spi_device_transmit(ivsspi, &t); //Transmit!
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);
Expand Down Expand Up @@ -272,9 +271,9 @@ void VS1053_ResetChip(){
ControlReset(SET);
vTaskDelay(30);
ControlReset(RESET);
vTaskDelay(30);
vTaskDelay(10);
if (VS1053_checkDREQ() == 1) return;
vTaskDelay(20);
vTaskDelay(30);
}


Expand Down Expand Up @@ -334,20 +333,45 @@ void VS1053_Start(){
ESP_LOGE(TAG,"NO VS1053 detected");
return;
}

// VS1053_ResetChip();
// these 4 lines makes board to run on mp3 mode, no soldering required anymore
VS1053_WriteRegister16(SPI_WRAMADDR, 0xc017); //address of GPIO_DDR is 0xC017
VS1053_WriteRegister16(SPI_WRAM, 0x0003); //GPIO_DDR=3
VS1053_WriteRegister16(SPI_WRAMADDR, 0xc019); //address of GPIO_ODATA is 0xC019
VS1053_WriteRegister16(SPI_WRAM, 0x0000); //GPIO_ODATA=0
vTaskDelay(150);


VS1053_ResetChip();

int MP3Status = VS1053_ReadRegister(SPI_STATUSVS);
vsVersion = (MP3Status >> 4) & 0x000F; //Mask out only the four version bits
//0 for VS1001, 1 for VS1011, 2 for VS1002, 3 for VS1003, 4 for VS1053 and VS8053,
//5 for VS1033, 7 for VS1103, and 6 for VS1063
ESP_LOGI(TAG,"VS1053/VS1003 detected. MP3Status: %x, Version: %x",MP3Status,vsVersion);


if (vsVersion == 4) // only 1053b
{
uint16_t aud;
VS1053_ResetChip();
// these 4 lines makes board to run on mp3 mode, no soldering required anymore
VS1053_WriteRegister16(SPI_WRAMADDR, 0xc017); //address of GPIO_DDR is 0xC017
VS1053_WriteRegister16(SPI_WRAM, 0x0003); //GPIO_DDR=3
VS1053_WriteRegister16(SPI_WRAMADDR, 0xc019); //address of GPIO_ODATA is 0xC019
VS1053_WriteRegister16(SPI_WRAM, 0x0000); //GPIO_ODATA=0
aud = VS1053_ReadRegister(SPI_AUDATA);
ESP_LOGI(TAG,"VS1053/SPI_AUDATE= %x",aud);
if (aud == 0xac45)
{
VS1053_ResetChip();
// these 4 lines makes board to run on mp3 mode, no soldering required anymore
VS1053_WriteRegister16(SPI_WRAMADDR, 0xc017); //address of GPIO_DDR is 0xC017
VS1053_WriteRegister16(SPI_WRAM, 0x0003); //GPIO_DDR=3
VS1053_WriteRegister16(SPI_WRAMADDR, 0xc019); //address of GPIO_ODATA is 0xC019
VS1053_WriteRegister16(SPI_WRAM, 0x0000); //GPIO_ODATA=0
aud = VS1053_ReadRegister(SPI_AUDATA);
ESP_LOGI(TAG,"VS1053/SPI_AUDATE= %x",aud);
}

}

vTaskDelay(10);
ESP_LOGI(TAG,"VS1053/VS1003 detection. MP3Status: %x, Version: %x",MP3Status,vsVersion);


if (vsVersion == 4) // only 1053b
// VS1053_WriteRegister(SPI_CLOCKF,0x78,0x00); // SC_MULT = x3, SC_ADD= x2
// VS1053_WriteRegister16(SPI_CLOCKF,0xB800); // SC_MULT = x1, SC_ADD= x1
Expand All @@ -357,8 +381,8 @@ void VS1053_Start(){
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
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 ();

VS1053_regtest();
Expand Down Expand Up @@ -396,7 +420,7 @@ int VS1053_SendMusicBytes(uint8_t* music, uint16_t quantity){
{
int t = quantity;
if(t > CHUNK) t = CHUNK;
VS1053_spi_write_char(hvsspi, &music[oo], t);
VS1053_spi_write_char(&music[oo], t);
oo += t;
quantity -= t;
} // else taskYIELD ();
Expand Down Expand Up @@ -619,11 +643,8 @@ void VS1053_flush_cancel(uint8_t mode) { // 0 only fillbyte 1 before play 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;
for ( y = 0; y < 5; y++) VS1053_SendMusicBytes( buf, 512); // 4*513 = 2052
} else
{
for ( y = 0; y < 5; y++) VS1053_SendMusicBytes( buf, 512); // 4*513 = 2052
}
}
for ( y = 0; y < 5; y++) VS1053_SendMusicBytes( buf, 512); // 4*513 = 2052
}


Expand Down
10 changes: 7 additions & 3 deletions main/vs1053b-patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// 117
/* not used in esp32*/
/*
const unsigned short admix[] = { // Compressed plugin
0x0007, 0x0001, 0x8f00, 0x0006, 0x0070, 0x2803, 0xc2c0, 0x0030, // 0
Expand All @@ -31,7 +32,7 @@ const unsigned short admix[] = { // Compressed plugin
0x0717, 0x2100, 0x0000, 0x3f05, 0xdbd7,
};
#define ADMIX_SIZE 117

*/

const unsigned short newpatch[] = { /* Compressed plugin */
0x0007,0x0001, /*copy 1*/
Expand Down Expand Up @@ -661,9 +662,10 @@ void LoadUserCode( const unsigned short* iplugin,uint16_t ssize) {
int i = 0;

ESP_LOGI(TAG,"plugin size %d, start: %x %x %x",ssize,*iplugin,*(iplugin+1),*(iplugin+2));


unsigned short addr, n, val;
addr = 0;val=0;
while (i<ssize) {
unsigned short addr, n, val;
addr = iplugin[i++];
n = iplugin[i++];
if (n & 0x8000U) { /* RLE run, replicate n samples */
Expand All @@ -679,6 +681,8 @@ void LoadUserCode( const unsigned short* iplugin,uint16_t ssize) {
}
}
}
//VS1053_WriteRegister((uint8_t)addr&0xff, (uint8_t)((val&0xFF00)>>8), (uint8_t)(val&0xFF));
ESP_LOGI(TAG,"plugin end Addr: %x, val:%x %x",(uint8_t)addr&0xff,(uint8_t)((val&0xFF00)>>8),(uint8_t)(val&0xFF) );
}
void LoadUserCodes(void)
{
Expand Down

0 comments on commit ad5f73a

Please sign in to comment.