@@ -199,15 +199,15 int bsp_FSMC_init() | |||
|
199 | 199 | |
|
200 | 200 | void bsp_spi_init() |
|
201 | 201 | { |
|
202 | gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO}; | |
|
203 | for(int i=0;i<3;i++) | |
|
204 | { | |
|
205 | gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]); | |
|
206 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
|
207 | gpiosetconfig(&SPI_DBx); | |
|
208 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1); | |
|
209 | } | |
|
210 | spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1); | |
|
202 | // gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO}; | |
|
203 | // for(int i=0;i<3;i++) | |
|
204 | // { | |
|
205 | // gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]); | |
|
206 | // SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
|
207 | // gpiosetconfig(&SPI_DBx); | |
|
208 | // GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1); | |
|
209 | // } | |
|
210 | // spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1); | |
|
211 | 211 | |
|
212 | 212 | gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO}; |
|
213 | 213 | for(int i=0;i<3;i++) |
@@ -235,13 +235,13 void bsp_Audio_init() | |||
|
235 | 235 | |
|
236 | 236 | void bsp_SD_init() |
|
237 | 237 | { |
|
238 | sdcardDev sdcard2; | |
|
239 | blkdevice sdcard2blkdev; | |
|
240 | dikpartition sdcard2Part1; | |
|
241 | sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed); | |
|
242 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); | |
|
243 | sdcard2blkdev.initialize(&sdcard2blkdev); | |
|
244 | mbropen(&sdcard2blkdev,&sdcard2Part1,1); | |
|
238 | // sdcardDev sdcard2; | |
|
239 | // blkdevice sdcard2blkdev; | |
|
240 | // dikpartition sdcard2Part1; | |
|
241 | // sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed); | |
|
242 | // sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); | |
|
243 | // sdcard2blkdev.initialize(&sdcard2blkdev); | |
|
244 | // mbropen(&sdcard2blkdev,&sdcard2Part1,1); | |
|
245 | 245 | } |
|
246 | 246 | |
|
247 | 247 | void vs1052setXCS(char val) |
@@ -7,6 +7,13 | |||
|
7 | 7 | #include <core.h> |
|
8 | 8 | #include <VS10XX.h> |
|
9 | 9 | #include <bsp.h> |
|
10 | #include <spi.h> | |
|
11 | #include <sdcard.h> | |
|
12 | #include <sdcard-spi.h> | |
|
13 | #include <fat32.h> | |
|
14 | #include <ucdirent.h> | |
|
15 | #include <string.h> | |
|
16 | ||
|
10 | 17 | |
|
11 | 18 | extern streamdevice* __opnfiles__[]; |
|
12 | 19 | |
@@ -30,6 +37,52 void randBoxesDemo() | |||
|
30 | 37 | |
|
31 | 38 | int main() |
|
32 | 39 | { |
|
40 | while(!bspsdcardpresent()); | |
|
41 | delay_100us(5000); | |
|
42 | printf("About to initialize SDCARD"); | |
|
43 | sdcardDev sdcard2; | |
|
44 | blkdevice sdcard2blkdev; | |
|
45 | dikpartition sdcard2Part1; | |
|
46 | FAT32fs partoche; | |
|
47 | sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed); | |
|
48 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); | |
|
49 | sdcard2blkdev.initialize(&sdcard2blkdev); | |
|
50 | mbropen(&sdcard2blkdev,&sdcard2Part1,1); | |
|
51 | if(FATnoErr==fat32open(&partoche,&sdcard2Part1)) | |
|
52 | { | |
|
53 | printf("FAT32 partition opened\n"); | |
|
54 | char test[]=" \n"; | |
|
55 | ucdirent root,folder; | |
|
56 | fat32mkdirent(&partoche,&root); | |
|
57 | fat32getrootfirstent(&root); | |
|
58 | fat32getVolName(&partoche,test); | |
|
59 | printf("Vol Name=%s\n",test); | |
|
60 | fat32getdirentname(&root,test); | |
|
61 | printf("%s\n",test); | |
|
62 | while (DIRENT_EndOfDir!=fat32nextdirent(&root)) | |
|
63 | { | |
|
64 | if(test[0]=='m') | |
|
65 | { | |
|
66 | printf("enter music folder\n"); | |
|
67 | fat32enterdirent(&root,&folder); | |
|
68 | while (DIRENT_EndOfDir!=fat32nextdirent(&folder)) | |
|
69 | { | |
|
70 | printf("%s\n",test); | |
|
71 | } | |
|
72 | } | |
|
73 | fat32getdirentname(&root,test); | |
|
74 | printf("%s\n",test); | |
|
75 | } | |
|
76 | if(test[0]=='m') | |
|
77 | { | |
|
78 | printf("enter music folder\n"); | |
|
79 | fat32enterdirent(&root,&folder); | |
|
80 | while (DIRENT_EndOfDir!=fat32nextdirent(&folder)) | |
|
81 | { | |
|
82 | printf("%s\n",test); | |
|
83 | } | |
|
84 | } | |
|
85 | } | |
|
33 | 86 | while(1) |
|
34 | 87 | { |
|
35 | 88 | // printf("Audio Codec reg0=0x%x\n",vs10XXcmdread(&audioCodec0,0)); |
@@ -37,6 +90,7 int main() | |||
|
37 | 90 | // bsp_lcd0_write_reg(1,0x1234); |
|
38 | 91 | // delay_100us(10000); |
|
39 | 92 | // randBoxesDemo(); |
|
93 | ||
|
40 | 94 | gpioset(LED1); |
|
41 | 95 | delay_100us(10000); |
|
42 | 96 | gpioclr(LED1); |
@@ -32,6 +32,7 int mbropen(blkdevice* phy,dikpartition* | |||
|
32 | 32 | if(phy->read(phy,mbr,0,1)!=RES_OK) |
|
33 | 33 | { |
|
34 | 34 | printf("can't read MBR!\n"); |
|
35 | printf("%x %x %x %x %x %x %x %x\n",mbr[0],mbr[1],mbr[2],mbr[3],mbr[4],mbr[5],mbr[6],mbr[7]); | |
|
35 | 36 | return MBRReadErr; |
|
36 | 37 | } |
|
37 | 38 | if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA)) |
@@ -64,7 +64,7 int sdcardwait_ready (sdcardDev* sdcard) | |||
|
64 | 64 | unsigned int tmr; |
|
65 | 65 | volatile unsigned int i=0; |
|
66 | 66 | |
|
67 |
for (tmr = |
|
|
67 | for (tmr = 500; tmr>0; tmr--) { /* Wait for ready in timeout of 500ms */ | |
|
68 | 68 | sdcard->rcvr_mmc(sdcard->phy,&d, 1); |
|
69 | 69 | if (d == 0xFF) break; |
|
70 | 70 | delay_100us(10); |
@@ -78,10 +78,10 int sdcardrcvr_datablock (sdcardDev* sdc | |||
|
78 | 78 | char d[2]; |
|
79 | 79 | unsigned int tmr; |
|
80 | 80 | volatile unsigned int i=0; |
|
81 |
|
|
|
81 | for (tmr = 100; tmr; tmr--) { /* Wait for data packet in timeout of 100ms */ | |
|
82 | 82 | sdcard->rcvr_mmc(sdcard->phy,d, 1); |
|
83 | 83 | if (d[0] != 0xFF) break; |
|
84 | for(i=0;i<64;i++); | |
|
84 | delay_100us(10); | |
|
85 | 85 | } |
|
86 | 86 | if (d[0] != 0xFE) return 0; /* If not valid data token, return with error */ |
|
87 | 87 | |
@@ -139,14 +139,17 char sdcardsend_cmd (blkdeviceptr _this, | |||
|
139 | 139 | buf[5] = n; |
|
140 | 140 | ((sdcardDev*)_this->phy)->xmit_mmc(((sdcardDev*)_this->phy)->phy,buf, 6); |
|
141 | 141 | /* Receive command response */ |
|
142 | if (cmd == CMD12) {((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,&d, 1);} /* Skip a stuff byte when stop reading */ | |
|
143 | n = 10; /* Wait for a valid response in timeout of 10 attempts */ | |
|
142 | if (cmd == CMD12) | |
|
143 | { | |
|
144 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,&d, 1); | |
|
145 | } /* Skip a stuff byte when stop reading */ | |
|
146 | n = 100; /* Wait for a valid response in timeout of 100 attempts */ | |
|
144 | 147 | do |
|
145 | 148 | { |
|
146 | 149 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,&d, 1); |
|
150 | delay_100us(10); | |
|
147 | 151 | //libucprintf("resp=%d\n\r",d); |
|
148 | } | |
|
149 | while ((d & 0x80) && --n); | |
|
152 | }while ((d & 0x80) && --n); | |
|
150 | 153 | |
|
151 | 154 | return d; /* Return with the response value */ |
|
152 | 155 | } |
@@ -206,13 +209,17 DSTATUS sdcarddisk_initialize (blkdevice | |||
|
206 | 209 | printf("SDCARD in Idle mode\n"); |
|
207 | 210 | Timer1 = 1000; /* Initialization timeout = 1 sec */ |
|
208 | 211 | if (sdcardsend_cmd(_this,CMD8, 0x1AA) == 1) { /* SDv2? */ |
|
212 | printf("SDCARD V2\n"); | |
|
209 | 213 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,ocr, 4); |
|
210 | 214 | //for (n = 0; n < 4; n++) ocr[n] = xchg_spi(0xFF); /* Get 32 bit return value of R7 resp */ |
|
211 | 215 | if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* Is the card supports vcc of 2.7-3.6V? */ |
|
216 | printf("The card supports vcc of 2.7-3.6V\n"); | |
|
212 | 217 | while (Timer1 && sdcardsend_cmd(_this,ACMD41, 1UL << 30)) ; /* Wait for end of initialization with ACMD41(HCS) */ |
|
213 | 218 | if (Timer1 && sdcardsend_cmd(_this,CMD58, 0) == 0) { /* Check CCS bit in the OCR */ |
|
214 | 219 | //for (n = 0; n < 4; n++) ocr[n] = xchg_spi(0xFF); |
|
220 | printf("Check CCS bit in the OCR:\n"); | |
|
215 | 221 |
|
|
222 | printf("OCR[0]=0x%X\n",ocr[0]); | |
|
216 | 223 | ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* Card id SDv2 */ |
|
217 | 224 | } |
|
218 | 225 | } |
@@ -228,6 +235,7 DSTATUS sdcarddisk_initialize (blkdevice | |||
|
228 | 235 | } |
|
229 | 236 | } |
|
230 | 237 | ((sdcardDev*)_this->phy)->CardType = ty; /* Card type */ |
|
238 | printf("CardType=0x%X\n",ty); | |
|
231 | 239 | |
|
232 | 240 | if (ty) { /* OK */ |
|
233 | 241 | ((sdcardDev*)_this->phy)->Stat &= ~STA_NOINIT; /* Clear STA_NOINIT flag */ |
@@ -247,7 +255,7 DSTATUS sdcarddisk_initialize (blkdevice | |||
|
247 | 255 | break; |
|
248 | 256 | } |
|
249 | 257 | } |
|
250 | if(speed>(50*1000*1000)) | |
|
258 | if((speed>(50*1000*1000)) || (speed >= getCpuFreq())) | |
|
251 | 259 | { |
|
252 | 260 | break; |
|
253 | 261 | } |
@@ -257,6 +265,7 DSTATUS sdcarddisk_initialize (blkdevice | |||
|
257 | 265 | speed-=1000000; |
|
258 | 266 | ((sdcardDev*)_this->phy)->setspeed(((sdcardDev*)_this->phy)->phy,speed); |
|
259 | 267 | } |
|
268 | printf("SDCARD speed = %dMHz\n",speed/1000000); | |
|
260 | 269 | |
|
261 | 270 | } else { /* Failed */ |
|
262 | 271 | //power_off(); |
@@ -46,8 +46,8 int terminal_init(terminal_t* terminal,L | |||
|
46 | 46 | terminal->font=font; |
|
47 | 47 | terminal->line = 0; |
|
48 | 48 | terminal->column = 0; |
|
49 |
terminal->horizontalSpace= |
|
|
50 |
terminal->verticalSpace= |
|
|
49 | terminal->horizontalSpace=0; | |
|
50 | terminal->verticalSpace=0; | |
|
51 | 51 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
52 | 52 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
53 | 53 | terminal->textColor=0xFFFF; |
General Comments 0
You need to be logged in to leave comments.
Login now