1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-17 21:35:27 +03:00

[Horus] MP3 driver. The sound is completely distorded (why?), but the background noise is not there

This commit is contained in:
Bertrand Songis 2016-01-18 23:26:10 +01:00
parent a8172e3588
commit c46c1f887a

View file

@ -161,7 +161,7 @@ OPTIMIZE("O0") static void delay_us(uint32_t nCount)
}
OPTIMIZE("O0") u8 SPIx_ReadWriteByte(uint8_t value)
OPTIMIZE("O0") u8 SPIy_ReadWriteByte(uint8_t value)
{
u8 ret_val = 0;
@ -255,11 +255,11 @@ u16 VS_RD_Reg(u8 address)
SPIx_SetSpeed(SPI_SPEED_64);
XDCS_HIGH();
CS_LOW();
SPIx_ReadWriteByte(VS_READ_COMMAND);
SPIx_ReadWriteByte(address);
temp=SPIx_ReadWriteByte(0xff);
SPIy_ReadWriteByte(VS_READ_COMMAND);
SPIy_ReadWriteByte(address);
temp=SPIy_ReadWriteByte(0xff);
temp=temp<<8;
temp+=SPIx_ReadWriteByte(0xff);
temp+=SPIy_ReadWriteByte(0xff);
delay_us(10);//10us
CS_HIGH();
SPIx_SetSpeed(SPI_SPEED_8);
@ -267,6 +267,25 @@ u16 VS_RD_Reg(u8 address)
return temp;
}
u16 VS_RD_Cmd(u8 address)
{
u16 retry=0;
u16 x ;
while(READ_DREQ()==0&&(retry++)<0xfffe)retry++;
SPIx_SetSpeed(SPI_SPEED_64);
XDCS_HIGH();
CS_LOW();
SPIy_ReadWriteByte(VS_READ_COMMAND);
SPIy_ReadWriteByte(address); //
x = SPIy_ReadWriteByte(0); //
x <<= 8 ;
x |= SPIy_ReadWriteByte(0); //
delay_us(5);//5us
CS_HIGH();
SPIx_SetSpeed(SPI_SPEED_8); //
return x ;
}
void VS_WR_Cmd(u8 address,u16 data)
{
u16 retry=0;
@ -274,10 +293,10 @@ void VS_WR_Cmd(u8 address,u16 data)
SPIx_SetSpeed(SPI_SPEED_64);
XDCS_HIGH();
CS_LOW();
SPIx_ReadWriteByte(VS_WRITE_COMMAND);
SPIx_ReadWriteByte(address); //
SPIx_ReadWriteByte(data>>8); //
SPIx_ReadWriteByte(data); //
SPIy_ReadWriteByte(VS_WRITE_COMMAND);
SPIy_ReadWriteByte(address); //
SPIy_ReadWriteByte(data>>8); //
SPIy_ReadWriteByte(data); //
delay_us(5);//5us
CS_HIGH();
SPIx_SetSpeed(SPI_SPEED_8); //
@ -310,26 +329,21 @@ u8 VS_HD_Reset(void)
return 0;
}
uint16_t Mp3ReadValue ;
void VS_Soft_Reset(void)
{
volatile u8 retry;
SPIx_SetSpeed(SPI_SPEED_64);
while(READ_DREQ()== 0);
VS_WR_Cmd(SPI_MODE,0x0020); //SOFT RESET,new model
return;
SPIx_ReadWriteByte(0x00); //start the transfer
SPIy_ReadWriteByte(0x00); //start the transfer
retry=0;
VS10XX_ID=VS_RD_Reg(SPI_STATUS);//Read the status register
VS10XX_ID>>=4;//get vs10xx signal
if(VS10XX_ID==VS1053)
VS_WR_Cmd(SPI_MODE,0x0836); //SOFT RESET,new model
else
VS_WR_Cmd(SPI_MODE,0x0824);
if(VS10XX_ID==VS1053) VS_WR_Cmd(SPI_MODE,0x0816);//SOFT RESET,new model
else VS_WR_Cmd(SPI_MODE,0x0804);
while((READ_DREQ()== 0)&&(retry<200))//waiting DREQ HIGH
{
@ -346,10 +360,10 @@ void VS_Soft_Reset(void)
VS_Rst_DecodeTime(); //Reset the decoding time
SPIx_SetSpeed(SPI_SPEED_8); //
XDCS_LOW();
SPIx_ReadWriteByte(0X0);
SPIx_ReadWriteByte(0X0);
SPIx_ReadWriteByte(0X0);
SPIx_ReadWriteByte(0X0);
SPIy_ReadWriteByte(0X0);
SPIy_ReadWriteByte(0X0);
SPIy_ReadWriteByte(0X0);
SPIy_ReadWriteByte(0X0);
delay_us(10);//10us
XDCS_HIGH();
}
@ -421,11 +435,20 @@ void mp3_spi_init(void)
int SpiMp3_read(const void * buffer, int len);
const uint8_t header[] = {
0x52, 0x49, 0x46, 0x46, 0xff, 0xff, 0xff, 0xff, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20,
0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00,
0x02, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
void audioInit()
{
mp3_spi_init();
VS_HD_Reset();
VS_Soft_Reset();
SPIx_SetSpeed(SPI_SPEED_8);
// SPIx_SetSpeed(SPI_SPEED_8);
// delay_us(10000);//10ms
@ -435,137 +458,49 @@ void audioInit()
// delay_us(10000);//10ms
const uint8_t sine[] = { 0x53, 0xEF, 0x6E, 126, 0, 0, 0, 0 };
const uint8_t header[] = {
0x52, 0x49, 0x46, 0x46, 0xff, 0xff, 0xff, 0xff, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20,
0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00,
0x04, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const int16_t sineValues[] =
{
0, 196, 392, 588, 784, 980, 1175, 1370, 1564, 1758,
1951, 2143, 2335, 2525, 2715, 2904, 3091, 3278, 3463, 3647,
3829, 4011, 4190, 4369, 4545, 4720, 4894, 5065, 5235, 5403,
5569, 5733, 5895, 6055, 6213, 6369, 6522, 6673, 6822, 6969,
7113, 7255, 7395, 7532, 7667, 7799, 7929, 8056, 8180, 8302,
8422, 8539, 8653, 8765, 8874, 8980, 9084, 9185, 9283, 9379,
9472, 9562, 9650, 9735, 9818, 9898, 9975, 10050, 10123, 10192,
10260, 10324, 10387, 10447, 10504, 10559, 10612, 10663, 10711, 10757,
10801, 10843, 10882, 10920, 10955, 10989, 11020, 11050, 11078, 11104,
11128, 11151, 11172, 11191, 11209, 11225, 11240, 11254, 11266, 11277,
11287, 11296, 11303, 11310, 11316, 11320, 11324, 11327, 11330, 11331,
11332, 11333, 11333, 11333, 11332, 11331, 11329, 11328, 11326, 11324,
11323, 11321, 11319, 11318, 11316, 11315, 11314, 11313, 11313, 11313,
11314, 11315, 11317, 11319, 11323, 11326, 11331, 11336, 11342, 11349,
11356, 11365, 11375, 11385, 11397, 11409, 11423, 11437, 11453, 11470,
11488, 11507, 11527, 11548, 11571, 11595, 11620, 11646, 11673, 11702,
11732, 11763, 11795, 11828, 11863, 11899, 11936, 11974, 12013, 12054,
12095, 12138, 12182, 12227, 12273, 12320, 12368, 12417, 12467, 12518,
12570, 12623, 12676, 12731, 12786, 12842, 12898, 12956, 13014, 13072,
13131, 13191, 13251, 13311, 13372, 13433, 13495, 13556, 13618, 13680,
13743, 13805, 13867, 13929, 13991, 14053, 14115, 14177, 14238, 14299,
14359, 14419, 14479, 14538, 14597, 14655, 14712, 14768, 14824, 14879,
14933, 14986, 15039, 15090, 15140, 15189, 15237, 15284, 15330, 15375,
15418, 15460, 15500, 15539, 15577, 15614, 15648, 15682, 15714, 15744,
15772, 15799, 15825, 15849, 15871, 15891, 15910, 15927, 15942, 15955,
15967, 15977, 15985, 15991, 15996, 15999, 16000, 15999, 15996, 15991,
15985, 15977, 15967, 15955, 15942, 15927, 15910, 15891, 15871, 15849,
15825, 15799, 15772, 15744, 15714, 15682, 15648, 15614, 15577, 15539,
15500, 15460, 15418, 15375, 15330, 15284, 15237, 15189, 15140, 15090,
15039, 14986, 14933, 14879, 14824, 14768, 14712, 14655, 14597, 14538,
14479, 14419, 14359, 14299, 14238, 14177, 14115, 14053, 13991, 13929,
13867, 13805, 13743, 13680, 13618, 13556, 13495, 13433, 13372, 13311,
13251, 13191, 13131, 13072, 13014, 12956, 12898, 12842, 12786, 12731,
12676, 12623, 12570, 12518, 12467, 12417, 12368, 12320, 12273, 12227,
12182, 12138, 12095, 12054, 12013, 11974, 11936, 11899, 11863, 11828,
11795, 11763, 11732, 11702, 11673, 11646, 11620, 11595, 11571, 11548,
11527, 11507, 11488, 11470, 11453, 11437, 11423, 11409, 11397, 11385,
11375, 11365, 11356, 11349, 11342, 11336, 11331, 11326, 11323, 11319,
11317, 11315, 11314, 11313, 11313, 11313, 11314, 11315, 11316, 11318,
11319, 11321, 11323, 11324, 11326, 11328, 11329, 11331, 11332, 11333,
11333, 11333, 11332, 11331, 11330, 11327, 11324, 11320, 11316, 11310,
11303, 11296, 11287, 11277, 11266, 11254, 11240, 11225, 11209, 11191,
11172, 11151, 11128, 11104, 11078, 11050, 11020, 10989, 10955, 10920,
10882, 10843, 10801, 10757, 10711, 10663, 10612, 10559, 10504, 10447,
10387, 10324, 10260, 10192, 10123, 10050, 9975, 9898, 9818, 9735,
9650, 9562, 9472, 9379, 9283, 9185, 9084, 8980, 8874, 8765,
8653, 8539, 8422, 8302, 8180, 8056, 7929, 7799, 7667, 7532,
7395, 7255, 7113, 6969, 6822, 6673, 6522, 6369, 6213, 6055,
5895, 5733, 5569, 5403, 5235, 5065, 4894, 4720, 4545, 4369,
4190, 4011, 3829, 3647, 3463, 3278, 3091, 2904, 2715, 2525,
2335, 2143, 1951, 1758, 1564, 1370, 1175, 980, 784, 588,
392, 196, 0, -196, -392, -588, -784, -980, -1175, -1370,
-1564, -1758, -1951, -2143, -2335, -2525, -2715, -2904, -3091, -3278,
-3463, -3647, -3829, -4011, -4190, -4369, -4545, -4720, -4894, -5065,
-5235, -5403, -5569, -5733, -5895, -6055, -6213, -6369, -6522, -6673,
-6822, -6969, -7113, -7255, -7395, -7532, -7667, -7799, -7929, -8056,
-8180, -8302, -8422, -8539, -8653, -8765, -8874, -8980, -9084, -9185,
-9283, -9379, -9472, -9562, -9650, -9735, -9818, -9898, -9975, -10050,
-10123, -10192, -10260, -10324, -10387, -10447, -10504, -10559, -10612, -10663,
-10711, -10757, -10801, -10843, -10882, -10920, -10955, -10989, -11020, -11050,
-11078, -11104, -11128, -11151, -11172, -11191, -11209, -11225, -11240, -11254,
-11266, -11277, -11287, -11296, -11303, -11310, -11316, -11320, -11324, -11327,
-11330, -11331, -11332, -11333, -11333, -11333, -11332, -11331, -11329, -11328,
-11326, -11324, -11323, -11321, -11319, -11318, -11316, -11315, -11314, -11313,
-11313, -11313, -11314, -11315, -11317, -11319, -11323, -11326, -11331, -11336,
-11342, -11349, -11356, -11365, -11375, -11385, -11397, -11409, -11423, -11437,
-11453, -11470, -11488, -11507, -11527, -11548, -11571, -11595, -11620, -11646,
-11673, -11702, -11732, -11763, -11795, -11828, -11863, -11899, -11936, -11974,
-12013, -12054, -12095, -12138, -12182, -12227, -12273, -12320, -12368, -12417,
-12467, -12518, -12570, -12623, -12676, -12731, -12786, -12842, -12898, -12956,
-13014, -13072, -13131, -13191, -13251, -13311, -13372, -13433, -13495, -13556,
-13618, -13680, -13743, -13805, -13867, -13929, -13991, -14053, -14115, -14177,
-14238, -14299, -14359, -14419, -14479, -14538, -14597, -14655, -14712, -14768,
-14824, -14879, -14933, -14986, -15039, -15090, -15140, -15189, -15237, -15284,
-15330, -15375, -15418, -15460, -15500, -15539, -15577, -15614, -15648, -15682,
-15714, -15744, -15772, -15799, -15825, -15849, -15871, -15891, -15910, -15927,
-15942, -15955, -15967, -15977, -15985, -15991, -15996, -15999, -16000, -15999,
-15996, -15991, -15985, -15977, -15967, -15955, -15942, -15927, -15910, -15891,
-15871, -15849, -15825, -15799, -15772, -15744, -15714, -15682, -15648, -15614,
-15577, -15539, -15500, -15460, -15418, -15375, -15330, -15284, -15237, -15189,
-15140, -15090, -15039, -14986, -14933, -14879, -14824, -14768, -14712, -14655,
-14597, -14538, -14479, -14419, -14359, -14299, -14238, -14177, -14115, -14053,
-13991, -13929, -13867, -13805, -13743, -13680, -13618, -13556, -13495, -13433,
-13372, -13311, -13251, -13191, -13131, -13072, -13014, -12956, -12898, -12842,
-12786, -12731, -12676, -12623, -12570, -12518, -12467, -12417, -12368, -12320,
-12273, -12227, -12182, -12138, -12095, -12054, -12013, -11974, -11936, -11899,
-11863, -11828, -11795, -11763, -11732, -11702, -11673, -11646, -11620, -11595,
-11571, -11548, -11527, -11507, -11488, -11470, -11453, -11437, -11423, -11409,
-11397, -11385, -11375, -11365, -11356, -11349, -11342, -11336, -11331, -11326,
-11323, -11319, -11317, -11315, -11314, -11313, -11313, -11313, -11314, -11315,
-11316, -11318, -11319, -11321, -11323, -11324, -11326, -11328, -11329, -11331,
-11332, -11333, -11333, -11333, -11332, -11331, -11330, -11327, -11324, -11320,
-11316, -11310, -11303, -11296, -11287, -11277, -11266, -11254, -11240, -11225,
-11209, -11191, -11172, -11151, -11128, -11104, -11078, -11050, -11020, -10989,
-10955, -10920, -10882, -10843, -10801, -10757, -10711, -10663, -10612, -10559,
-10504, -10447, -10387, -10324, -10260, -10192, -10123, -10050, -9975, -9898,
-9818, -9735, -9650, -9562, -9472, -9379, -9283, -9185, -9084, -8980,
-8874, -8765, -8653, -8539, -8422, -8302, -8180, -8056, -7929, -7799,
-7667, -7532, -7395, -7255, -7113, -6969, -6822, -6673, -6522, -6369,
-6213, -6055, -5895, -5733, -5569, -5403, -5235, -5065, -4894, -4720,
-4545, -4369, -4190, -4011, -3829, -3647, -3463, -3278, -3091, -2904,
-2715, -2525, -2335, -2143, -1951, -1758, -1564, -1370, -1175, -980,
-784, -588, -392, -196,
};
delay_us(10000);//10ms
/*
XDCS_LOW();
SPIy_ReadWriteByte(0x53);
SPIy_ReadWriteByte(0xEF);
SPIy_ReadWriteByte(0x6E);
SPIy_ReadWriteByte(0x63);
SPIy_ReadWriteByte(0X0);
SPIy_ReadWriteByte(0X0);
SPIy_ReadWriteByte(0X0);
SPIy_ReadWriteByte(0X0);
delay_us(10);//10ms
XDCS_HIGH();
*/
while(SpiMp3_read(sine, sizeof(sine)) != 1) {
XDCS_LOW();
while (SpiMp3_read(header, sizeof(header)) != 1) {
// delay_us(10);//10ms
}
/*for (int h = 0; h < 10; h++) {
while (SpiMp3_read(sineValues, sizeof(sineValues)) != 1) {
delay_us(1000);//10ms
}
for (int i = 0; i < 100; i++)
delay_us(1000);//1ms
}*/
}
unsigned short curIndex = 0;
bool dacQueue(AudioBuffer * buffer)
{
SpiMp3_read(buffer->data, AUDIO_BUFFER_SIZE);
while (SpiMp3_read(buffer->data, buffer->size) != 1) {
// delay_us(10);//10ms
}
return true;
// SpiMp3_read(buffer->data, AUDIO_BUFFER_SIZE);
}
int SpiMp3_read(const void * buffer, int len)
@ -588,26 +523,28 @@ int SpiMp3_read(const void * buffer, int len)
}
else
{
XDCS_LOW();
// XDCS_LOW();
//send data
for( n = 0; n < 32; ++n)
{
if (curIndex >= len)
{
curIndex = 0;
return 1;
//none
//temp_c = 0x00;
// SPIx_ReadWriteByte(temp_c);
// SPIy_ReadWriteByte(temp_c);
}
else
{
temp_c = pTmp[curIndex];
SPIx_ReadWriteByte(temp_c);
SPIy_ReadWriteByte(temp_c);
++curIndex;
}
}
//delay for send over
delay_us(10);//10ms
XDCS_HIGH();
// delay_us(10);//10ms
//XDCS_HIGH();
//continue
ret_val = 2;