Under construction
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed
Fork of vs1011e by
main.cpp
00001 #include "mbed.h" 00002 #include "SDFileSystem.h" 00003 #include "uLCD_4DGL.h" 00004 #include "VS1002.h" 00005 00006 uLCD_4DGL uLCD(p28, p27, p30); 00007 00008 DigitalIn Dreq(p26); 00009 DigitalOut XDCS(p25); 00010 DigitalOut reset(p23); 00011 DigitalOut XCS(p22); 00012 00013 SPI mp3Board(p11, p12, p13); // mosi, miso, sclk 00014 SDFileSystem sd(p5, p6, p7, p8, "sd"); // DI, DO, SCK, CS 00015 00016 int killLoop = 1; 00017 int mp3Chunk; 00018 int fileSize; 00019 00020 long getFileSize(FILE *fp) { 00021 fseek(fp, 0, SEEK_END); 00022 int size = ftell(fp); 00023 fseek(fp, 0, SEEK_SET); 00024 return size; 00025 } 00026 00027 void sdi_write(unsigned char datum) 00028 { 00029 XCS = 1; 00030 XDCS = 1; 00031 XCS = 0; 00032 while(!Dreq); 00033 mp3Board.write(datum); 00034 XCS = 1; 00035 } 00036 00037 /* 00038 void sdi_write(unsigned char datum) 00039 { 00040 _CS = 1; 00041 _DCS = 1; 00042 _CS = 0; 00043 while(!_DREQ); 00044 _spi.write(datum); 00045 _CS = 1; 00046 } 00047 //////////////////////////////////////////////////////////////////////////// 00048 VS1002::VS1002( 00049 PinName mmosi, PinName mmiso, PinName ssck, PinName ccs, const char *name, 00050 PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, 00051 PinName dreq, PinName dcs, PinName vol) 00052 : 00053 _sd(mmosi, mmiso, ssck, ccs, name), 00054 _spi(mosi, miso, sck), 00055 _CS(cs), 00056 _RST(rst), 00057 _DREQ(dreq), 00058 _DCS(dcs), 00059 _VOL(vol) { 00060 00061 } */ 00062 /////////////////////////////////////////////////////////////////////////// 00063 00064 int main() { 00065 reset = 1; 00066 //Sine test // So, the simplified procedure is: 00067 XDCS = 1; //1) Always keep XDCS at logical 1. 00068 XCS = 0; //2) Set XCS to 0, 00069 mp3Board.write(0x02); //0x02 is the write opcode 00070 mp3Board.write(0x00); //0x00 is the address of the sci mode register 00071 mp3Board.write(0x0A); //0x0A (11 in dec) is the SM_SDINEW bit //send SCI command to set SCI_MODE with SM_SHARED and SM_SDINEW set to 1, 00072 XCS = 1; //then set XCS back to 1. 00073 mp3Board.write(0x53); //3) While XCS is 1, send sine test activation bytes, e.g. 0x53 0xef 0x6e 0x7e 0x00 0x00 0x00 0x00. 00074 mp3Board.write(0xEF); 00075 mp3Board.write(0x6E); 00076 mp3Board.write(0x44); 00077 mp3Board.write(0x00); 00078 mp3Board.write(0x00); 00079 mp3Board.write(0x00); 00080 mp3Board.write(0x00); 00081 00082 00083 /* 00084 mp3Board.frequency(12000000); 00085 XCS=1; 00086 XCS=0; //pull xcs low to begin sci write. Sets mode to vs1002, 00087 mp3Board.write(0x02); //0x02 is the write opcode 00088 mp3Board.write(0x00); //0x00 is the address of the sci mode register 00089 mp3Board.write(0x0A); //0x0A (11 in dec) is the SM_SDINEW bit 00090 XCS=1; //pulled high to end write sequence 00091 00092 uLCD.locate(0,0); 00093 uLCD.printf("Initialized..."); 00094 00095 FILE *mp3_file; 00096 unsigned char mp3Chunk[512]; 00097 mp3_file = fopen("/sd/GGW.mp3","rb"); 00098 00099 if (mp3_file !=NULL) 00100 { 00101 uLCD.locate(0,1); 00102 uLCD.printf("File found"); 00103 XDCS = 1; 00104 XDCS = 0; 00105 fileSize=getFileSize(mp3_file); 00106 uLCD.locate(0,3); 00107 uLCD.printf("Filesize: "); 00108 uLCD.locate(0,4); 00109 uLCD.printf(" %i", fileSize); 00110 //fread(&mp3Chunk, 1, 1, mp3_file); 00111 uLCD.locate(0,5); 00112 uLCD.printf("mp3 file: "); 00113 uLCD.locate(0,6); 00114 uLCD.printf(" %i", mp3_file); 00115 uLCD.locate(0,7); 00116 //uLCD.printf("mp3 chunk: "); 00117 //uLCD.locate(0,8); 00118 //uLCD.printf(" %i", mp3Chunk); 00119 //would have funtion here passing the 8 bits to arm assembler code, hence the necessatity for 8 btis only! 00120 //mp3Board.write(mp3Chunk); 00121 uLCD.locate(0,10); 00122 uLCD.printf("File writing..."); 00123 ////////////////////////////////////////////////////////////////////////////// 00124 fread(&mp3Chunk, 1, 512, mp3_file); 00125 for(int i=0; i<512; i++) 00126 { 00127 #ifndef FS_ONLY 00128 //mp3Board.write(mp3Chunk[i]); 00129 sdi_write(mp3Chunk[i]); 00130 uLCD.locate(0,11); 00131 uLCD.printf("... %i", i); 00132 uLCD.locate(0,12); 00133 uLCD.printf(".. %i", mp3Chunk[i]); 00134 #endif 00135 } 00136 #ifndef FS_ONLY 00137 //Volume set to 0 dB 00138 XCS = 1; 00139 XDCS = 1; 00140 XCS = 0; //enables SCI/disables SDI 00141 while(!Dreq); //wait unitl data request is high 00142 mp3Board.write(0x02); //SCI write 00143 mp3Board.write(0x0B); //register address 00144 mp3Board.write((0 >> 8) & 0xFF); //write out first half of data word 00145 mp3Board.write(0 & 0xFF); //write out second half of data word 00146 XCS = 1; //enables SDI/disables SCI 00147 wait_us(5); 00148 #endif 00149 for(int n=0; n<2048; n++) 00150 { 00151 #ifndef FS_ONLY 00152 sdi_write(0x00); 00153 uLCD.locate(0,13); 00154 uLCD.printf("... %i", n); 00155 #endif 00156 } 00157 //////////////////////////////////////////////////////////////////////// 00158 fclose(mp3_file); 00159 XDCS=1; 00160 uLCD.locate(0,14); 00161 uLCD.printf("File closing."); 00162 } 00163 else 00164 { 00165 uLCD.locate(0,2); 00166 uLCD.printf("File not found"); 00167 } 00168 return 0;*/ 00169 }
Generated on Wed Jul 13 2022 07:44:22 by
1.7.2
