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