##// END OF EJS Templates
Removed error on fat32 library, seems now to be able navigate among sectors in...
jeandet -
r68:104125d87b89 dev_alexis
parent child
Show More
@@ -0,0 +1,19
1
2 #include <stdio.h>
3 #include <fat32.h>
4 #include <ucdirent.h>
5
6 void printRootClustersChain(FAT32fs* sdcard2FAT32part)
7 {
8 ucdirent root;
9 uint32_t sector_lba,res,tmp=sdcard2FAT32part->cluster_begin_lba;
10 sector_lba=tmp;
11 do
12 {
13 printf("Sector @0x%x\n",tmp);
14 //sector_lba=tmp+sdcard2FAT32part->BPB_SecPerClus-1;
15 sector_lba=tmp;
16 res=fat32nextsectorlba(sdcard2FAT32part,sector_lba,&tmp);
17 }while((res==DIRENT_noErr)&&(res!=DIRENT_LastSect));
18
19 }
@@ -60,7 +60,9 LCD_t lcd0={
60 60 terminal_t terminal0;
61 61
62 62 volatile int8_t* lcd0_CMD=(volatile int8_t*)0x60000000;
63 volatile int16_t* lcd0_CMD16=(volatile int16_t*)0x60000000;
63 64 volatile int8_t* lcd0_DATA=(volatile int8_t*)0x61FFFFF0;
65 volatile int16_t* lcd0_DATA16=(volatile int16_t*)0x61FFFFF0;
64 66
65 67 float VREF0 =(float)3.3;
66 68 volatile vs10XXDev audioCodec0;
@@ -156,8 +158,8 int bsp_FSMC_init()
156 158 #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA))
157 159 #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8)
158 160
159 gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\
160 ,PD4,PD5,PD7,PE4};
161 gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\
162 ,PD4,PD5,PD7,PE4};
161 163 for(int i=0;i<12;i++)
162 164 {
163 165 gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]);
@@ -167,7 +169,7 int bsp_FSMC_init()
167 169 }
168 170
169 171 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
170 FSMC_NORSRAMTimingInitTypeDef p,readtim;
172 FSMC_NORSRAMTimingInitTypeDef p;
171 173
172 174 /* Enable FSMC clock */
173 175 RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
@@ -302,7 +304,7 void bsp_SD_init()
302 304 {
303 305 printf("Can't open or read MBR\n");
304 306 }
305 delay_100us(1000);
307 delay_100us(10000);
306 308 if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr)
307 309 {
308 310 if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2))
@@ -312,7 +314,7 void bsp_SD_init()
312 314 {
313 315 printf("Can't open or read MBR\n");
314 316 }
315 delay_100us(1000);
317 delay_100us(10000);
316 318 if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr)
317 319 {
318 320 if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3))
@@ -322,7 +324,7 void bsp_SD_init()
322 324 {
323 325 printf("Can't open or read MBR\n");
324 326 }
325 delay_100us(1000);
327 delay_100us(10000);
326 328 if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr)
327 329 {
328 330 if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4))
@@ -338,7 +340,7 void bsp_SD_init()
338 340 printf("Can't initialize SDCARD\n");
339 341 }
340 342 }
341 delay_100us(2000);
343 delay_100us(20000);
342 344 }
343 345
344 346 void vs1052setXCS(char val)
@@ -401,7 +403,6 void bsp_lcd0_write_reg(uint32_t reg,uin
401 403 *lcd0_DATA=pt8[3];
402 404 *lcd0_DATA=pt8[2];
403 405 #else
404
405 406 *lcd0_CMD=pt8[1];
406 407 *lcd0_CMD=pt8[0];
407 408 pt8 = (uint8_t*)(void*)&data;
@@ -423,7 +424,6 uint32_t bsp_lcd0_read_reg(uint32_t reg)
423 424 pt8[3]=*lcd0_DATA;
424 425 pt8[2]=*lcd0_DATA;
425 426 #else
426
427 427 *lcd0_CMD=pt8[1];
428 428 *lcd0_CMD=pt8[0];
429 429 pt8 = (uint8_t*)(void*)&DATA;
@@ -448,7 +448,6 void bsp_lcd0_writeGRAM(void* buffer,uin
448 448 *lcd0_DATA=pt8[2*i];
449 449 }
450 450 #else
451
452 451 *lcd0_CMD=pt8[1];
453 452 *lcd0_CMD=pt8[0];
454 453 pt8 = (uint8_t*)(void*)buffer;
@@ -463,9 +462,9 void bsp_lcd0_writeGRAM(void* buffer,uin
463 462
464 463 void bsp_lcd0_readGRAM(void* buffer,uint32_t count)
465 464 {
466 //uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
467 volatile uint8_t* pt8 ;// = (uint8_t*)(void*)&reg;
468 /* #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
465 //uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
466 volatile uint8_t* pt8;// = (uint8_t*)(void*)&reg;
467 /* #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
469 468 *lcd0_CMD=pt8[3];
470 469 *lcd0_CMD=pt8[2];
471 470 pt8 = (uint8_t*)(void*)buffer;
@@ -485,7 +484,7 void bsp_lcd0_readGRAM(void* buffer,uint
485 484 /*
486 485 * x dummy reads Cf ili9328 datasheet p79!
487 486 */
488 /* pt8[0]=*lcd0_DATA;
487 /* pt8[0]=*lcd0_DATA;
489 488 pt8[1]=*lcd0_DATA;
490 489
491 490 for(int i=0;i<(int)count;i++)
@@ -497,15 +496,14 void bsp_lcd0_readGRAM(void* buffer,uint
497 496 }
498 497 #endif*/
499 498
500 *lcd0_CMD=(uint8_t)0;
501 *lcd0_CMD=(uint8_t)0x22;
499 *lcd0_CMD=(int8_t)0;
500 // *lcd0_CMD=(int8_t)0x22;
501 *lcd0_CMD=(int8_t)0x00;
502 502 pt8 = (uint8_t*)buffer;
503 503 pt8[1]=*lcd0_DATA;
504 504 pt8[0]=*lcd0_DATA;
505 505 for(int i=0;i<(int)count;i++)
506 506 {
507 //pt8[(2*i) +1]=0;
508 //pt8[2*i]=0;
509 507 pt8[(2*i)+1]= *lcd0_DATA;
510 508 pt8[2*i]= *lcd0_DATA;
511 509 }
@@ -516,7 +514,7 void bsp_GTerm_init()
516 514 if(__opnfiles__[1]==NULL)
517 515 {
518 516 streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
519 terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1);
517 terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1);
520 518 __opnfiles__[1] = fd1;
521 519 }
522 520 else
@@ -45,6 +45,7
45 45
46 46 #define LCD_RESET PD10
47 47 #define LCD_BACKL PE11
48 #define LCD_RS PE4
48 49
49 50 #define VS1053SPI spi1
50 51 #define VS1053xCS PA3
@@ -136,7 +136,55 void bsp_Audio_init()
136 136
137 137 void bsp_SD_init()
138 138 {
139
139 sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2, bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected);
140 if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT)
141 {
142 if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr)
143 {
144 if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1))
145 printf("Can't open fat32 partition 1\n");
146 }
147 else
148 {
149 printf("Can't open or read MBR\n");
150 }
151 delay_100us(1000);
152 if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr)
153 {
154 if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2))
155 printf("Can't open fat32 partition 2\n");
156 }
157 else
158 {
159 printf("Can't open or read MBR\n");
160 }
161 delay_100us(1000);
162 if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr)
163 {
164 if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3))
165 printf("Can't open fat32 partition 3\n");
166 }
167 else
168 {
169 printf("Can't open or read MBR\n");
170 }
171 delay_100us(1000);
172 if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr)
173 {
174 if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4))
175 printf("Can't open fat32 partition 4\n");
176 }
177 else
178 {
179 printf("Can't open or read MBR\n");
180 }
181 }
182 else
183 {
184 printf("Can't initialize SDCARD\n");
185 }
186
187 delay_100us(2000);
140 188 }
141 189
142 190 void vs1052setXCS(char val)
@@ -88,7 +88,7 void tryToplay2()
88 88 void playFile(ucdirent* file,FAT32fs* part)
89 89 {
90 90 extern volatile vs10XXDev audioCodec0;
91 char direntName[]=" \n";
91 char direntName[]=" \n";
92 92 uint32_t fileLba,nextLba;
93 93 int i=0;
94 94 fat32getdirentname(file,direntName);
@@ -139,7 +139,7 void playAllparts()
139 139 }
140 140 }
141 141
142 int main()
142 int main2()
143 143 {
144 144 delay_100us(30000);
145 145 int i=0;
@@ -206,7 +206,7 int main()
206 206 while(1);
207 207 }
208 208
209 int main2()
209 int main()
210 210 {
211 211 extern terminal_t terminal0;
212 212 extern volatile vs10XXDev audioCodec0;
@@ -9,5 +9,6 DEFINES += CPUFREQ=100000000
9 9
10 10 SOURCES += \
11 11 main.c \
12 test_lcd.c
12 test_lcd.c \
13 test_SDCARD.c
13 14
@@ -16,34 +16,48
16 16
17 17 extern streamdevice* __opnfiles__[];
18 18 extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color);
19 extern void test_address(LCD_t* LCD);
20 extern void printRootClustersChain(FAT32fs* sdcard2FAT32part);
19 21 char buffer[512];
20 22
21 23
22 void streamdevicePrint(streamdevice* dev, const char* format,...)
23 {
24 char** str_buffer;
25 int i;
26 va_list ap;
27 va_start(ap,format);
28 vasprintf(str_buffer,format,ap);
29 va_end(ap);
30 i=strlen(*str_buffer);
31 dev->ops->write(dev,(void*)*str_buffer,1,i);
32 free(*str_buffer);
33 }
34
35 //int printf(const char *format,...)
24 //void streamdevicePrint(streamdevice* dev, const char* format,...)
36 25 //{
37 // char** str_buffer;
26 // char str_buffer[512]="";
38 27 // int i;
39 28 // va_list ap;
40 29 // va_start(ap,format);
41 30 // vasprintf(str_buffer,format,ap);
42 31 // va_end(ap);
43 // i=strlen(*str_buffer);
44 // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)*str_buffer,1,i);
45 // free(*str_buffer);
32 // i=strlen(str_buffer);
33 // dev->ops->write(dev,(void*)str_buffer,1,i);
34 //}
35
36 int _write(int file, char *ptr, int len)
37 {
38 if(file<__MAX_OPENED_FILES__ && __opnfiles__[file]!=NULL)
39 {
40 if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len;
41 }
42 return len;
43 }
46 44
45 int _write_r (struct _reent *r, int file, char * ptr, int len)
46 {
47 return _write(file, ptr, len);
48 }
49
50 //int printf(const char *format,...)
51 //{
52 // char str_buffer[512]="";
53 // for(int i =0;i<512;i++)str_buffer[i]='\0';
54 // int i;
55 // va_list ap;
56 // va_start(ap,format);
57 // vasprintf(str_buffer,format,ap);
58 // va_end(ap);
59 // i=strlen(str_buffer);
60 // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)str_buffer,1,i);
47 61 //}
48 62
49 63 void lcd_print()
@@ -52,17 +66,70 void lcd_print()
52 66 // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5);
53 67 }
54 68
69
70 void playFile(ucdirent* file,FAT32fs* part)
71 {
72 extern volatile vs10XXDev audioCodec0;
73 char direntName[]=" \n";
74 uint32_t fileLba,nextLba;
75 int i=0;
76 fat32getdirentname(file,direntName);
77 //gpioset(LCD_BACKL);
78 printf("%s\n",direntName);
79 nextLba=fat32getdirentlba(file);
80 //printf("Streaming File\n");
81 //gpioclr(LCD_BACKL);
82 }
83
84 void listFiles()
85 {
86 extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4;
87 ucdirent root;
88 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root))
89 {
90 printf("Reading on SDCARD2 part1\n");
91 if(DIRENT_noErr==fat32getrootfirstent(&root))
92 {
93 do{
94 playFile(&root,&sdcard2FAT32part1);
95 }while (DIRENT_noErr==fat32nextdirent(&root));
96 }
97 }
98 gpioset(LED2);
99 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root))
100 {
101 printf("Reading on SDCARD2 part2\n");
102 if(DIRENT_noErr==fat32getrootfirstent(&root))
103 {
104 do{
105 playFile(&root,&sdcard2FAT32part2);
106 }while (DIRENT_noErr==fat32nextdirent(&root));
107 }
108 }
109 }
110
111
112 int libuc_main2()
113 {
114 printRootClustersChain(&sdcard2FAT32part1);
115
116 }
117
55 118 int libuc_main()
56 119 {
57 120 char in[255];
58 lcd_print();
121 //lcd_print();
59 122 printf("hello world\n");
60 streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96);
123 delay_100us(10000);
124 // streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96);
61 125 lcd0.paintText(&lcd0,"A",10,100,&ComicSansMS_18,0x0);
126 //while(1)test_address(&lcd0);
127 listFiles();
62 128 // while (scanf("%c",in))
63 129 // {
64 130 sleep(5);
65 131 // }
132
66 133 }
67 134
68 135
@@ -14,8 +14,30
14 14 #include <string.h>
15 15 #include <ili9328.h>
16 16
17 uint16_t buff[50*50];
17 18
18 19 void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color)
19 20 {
20 21 // LCD->paintFilRect(LCD,x,y,w,h,0,0,color);
21 22 }
23 int coef=1;
24
25 void test_address(LCD_t* LCD)
26 {
27 LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF);
28 uint16_t color[1];
29 for(int y=0;y<320;y++)
30 {
31 for(int x=0;x<240;x++)
32 {
33 color[0]=((x/10*y*x)/((y+x+1)))+coef;
34 coef = color[0];
35 LCD->paint(LCD,color,x,y,1,1);
36 //delay_100us(100);
37 }
38 }
39 LCD->getPix(LCD,buff,50,50,50,50);
40 // delay_100us(5000);
41 LCD->paint(LCD,buff,50,50,50,50);
42 delay_100us(500);
43 }
@@ -14,7 +14,7
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
@@ -25,34 +25,32
25 25 #include <stdint.h>
26 26 #include <hexviewer.h>
27 27
28 char fat32buff[512]__attribute__ ((aligned (4)));
28 char fat32buff[512];
29 29 uint32_t lastSecAddrs=-1;
30 30 FAT32fs* lastFATFS=0;
31 31
32 32 int fat32open(FAT32fs* fs,dikpartition* part)
33 33 {
34 fs->valide = 0;
35 if(part->valide==0)return FATBadpart;
36 char sector[512];
34 //char sector[512];
37 35 fs->part = part;
38 36 if(!isFat32(fs->part->TypeCode))return FATBadpart;
39 if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr;
40 fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(sector,BPB_BytsPerSecoff);
41 fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(sector,BPB_RsvdSecCntoff);
42 fs->BPB_FATSz32 = fat32Ui8_2_Ui32(sector,BPB_FATSz32off);
43 fs->BPB_RootClus = fat32Ui8_2_Ui32(sector,BPB_RootClusoff);
44 fs->BPB_SecPerClus = sector[BPB_SecPerClusoff];
45 fs->BPB_NumFATs = sector[BPB_NumFATsoff];
37 //if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr;
38 fat32sectorreadout(fs,fs->part->LBABegin);
39 fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(fat32buff,BPB_BytsPerSecoff);
40 fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(fat32buff,BPB_RsvdSecCntoff);
41 fs->BPB_FATSz32 = fat32Ui8_2_Ui32(fat32buff,BPB_FATSz32off);
42 fs->BPB_RootClus = fat32Ui8_2_Ui32(fat32buff,BPB_RootClusoff);
43 fs->BPB_SecPerClus = fat32buff[BPB_SecPerClusoff];
44 fs->BPB_NumFATs = fat32buff[BPB_NumFATsoff];
46 45 fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt;
47 46 fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 );
48 fs->valide=1;
49 47 return FATnoErr;
50 48 }
51 49
52 50
53 51 int fat32mkdirent(FAT32fs* fs,ucdirent* dirent)
54 52 {
55 if((fs==0) || (fs->valide==0)) return DIRENT_BabArg;
53 if(fs==0) return DIRENT_BabArg;
56 54 if(dirent==0) return DIRENT_BabArg;
57 55 dirent->fs = (UHANDLE)fs;
58 56 dirent->getrootfirstent = &fat32getrootfirstent;
@@ -62,7 +60,7 int fat32mkdirent(FAT32fs* fs,ucdirent*
62 60
63 61
64 62 int fat32getrootfirstent(ucdirent* entry)
65 {
63 {
66 64 if(entry==0) return DIRENT_BabArg;
67 65 entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba;
68 66 entry->Currententry = 0;
@@ -72,7 +70,7 int fat32getrootfirstent(ucdirent* entry
72 70
73 71 int fat32getVolName(FAT32fs* fs,char* Name)
74 72 {
75 if((fs==0) || (fs->valide==0)) return DIRENT_BabArg;
73 if(fs==0) return DIRENT_BabArg;
76 74 if(Name==0) return DIRENT_BabArg;
77 75 int i=0;
78 76 ucdirent entry;
@@ -109,31 +107,19 int fat32nextdirent(ucdirent* entry)
109 107 j=entry->CurrentSec;// /*Restart at last sector*/
110 108 do
111 109 {
112 //printf("reading new secotr\n",k);
113 110 fat32sectorreadout(((FAT32fs*)entry->fs),j);
114 //printf("done\n",k);
115 /*512 Bytes per sector and 32 bytes per entry*/
116 for(k=k;k<(512);k+=32)
111 for(k=k;k<(512);k+=32) /*512 Bytes per sector and 32 bytes per entry*/
117 112 {
118 113 if((fat32buff[DIR_Nameoff+k]!=(char)0xE5)) /*0xE5 = free entry*/
119 114 {
120 //printf("Fount dir entry = %d, 0x%X\n",0xff & ((int)fat32buff[DIR_Nameoff+k]),0xff & ((int)fat32buff[DIR_Attroff+k]));
121 115 if(fat32buff[DIR_Nameoff+k]==(char)0)
122 {
123 //printf("end of directory reached\n",k);
124 116 return DIRENT_EndOfDir; /*0x00 = end of dir*/
125 }
126 117 else
127 {
128 uint8_t attribute=fat32buff[DIR_Attroff + k];
129 if( (attribute==ATTR_DIRECTORY)
130 ||(attribute==ATTR_ARCHIVE)
131 ||(attribute==ATTR_READ_ONLY)
132 ||(attribute==ATTR_READ_ONLY))
118 if((fat32buff[DIR_Attroff + k]==(char)ATTR_DIRECTORY)||(fat32buff[DIR_Attroff + k]==(char)ATTR_ARCHIVE)||(fat32buff[DIR_Attroff + k]==(char)(ATTR_READ_ONLY)))
133 119 {
134 120 for(n=0;n<16;n++)entry->DIR_Name[n] = '\0';
135 121 for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k];
136 entry->DIR_Attr = attribute;
122 entry->DIR_Attr = (uint8_t)fat32buff[DIR_Attroff + k];
137 123 entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k];
138 124 entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k));
139 125 entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k));
@@ -143,16 +129,13 int fat32nextdirent(ucdirent* entry)
143 129 entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k));
144 130 entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k));
145 131 entry->CurrentSec = j;
146 entry->Currententry = (uint8_t)(0xFF&(k>>5));
132 entry->Currententry = (unsigned char)(k/32);
147 133 return DIRENT_noErr;
148 134 }
149 }
150 135 }
136
151 137 }
152 //printf("asking for next sector\n");
153 //printf("current = 0x%X\n",j);
154 138 j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k);
155 //printf("got it 0x%x\n",k);
156 139 if(j!=DIRENT_noErr)
157 140 {
158 141 if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/
@@ -201,7 +184,7 int fat32getdirentname(ucdirent* entry,c
201 184 if(k==0)
202 185 {
203 186 //get previous sector
204 if(fat32prevsectorlba2((FAT32fs*)entry->fs,entry, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr;
187 if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr;
205 188 fat32sectorreadout(((FAT32fs*)entry->fs),j);
206 189 k=512-32;
207 190 for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k];
@@ -264,10 +247,13 int fat32nextsectorlba(FAT32fs* fs,uint3
264 247 *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i);
265 248 if(*nextsector_lba==0xFFFFFFF7)
266 249 {
250
251 printf("DIRENT_BadSect\n");
267 252 return DIRENT_BadSect;
268 253 }
269 254 if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6)
270 255 {
256 printf("DIRENT_LastSect\n");
271 257 return DIRENT_LastSect;
272 258 }
273 259 *nextsector_lba = clusterlba(fs,*nextsector_lba);
@@ -278,28 +264,30 int fat32nextsectorlba(FAT32fs* fs,uint3
278 264 int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba)
279 265 {
280 266 uint32_t i=0,fatsec=0;
281 if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/
267 if(((lastsector_lba - fs->cluster_begin_lba) % (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/
282 268 {
283 269 *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/
284 270 return DIRENT_noErr;
285 271 }
286
287 uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
272 uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
288 273 fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
289 while(fatsec>=fs->fat_begin_lba)
274 do
290 275 {
276
291 277 fat32sectorreadout(fs,fatsec);
292 278 fatsec--;
293 for(i=508;i>2;i-=4)
279 for(i=511;i>3;i-=4)
294 280 {
295 *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i);
281 *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i-3);
296 282 if (*nextsector_lba ==clusternum)
297 283 {
298 284 *nextsector_lba = clusterlba(fs,*nextsector_lba);
299 285 return DIRENT_noErr;
300 286 }
287
301 288 }
302 }
289
290 }while(fatsec>=fs->fat_begin_lba);
303 291
304 292 clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
305 293 fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
@@ -318,48 +306,12 int fat32prevsectorlba(FAT32fs* fs,uint3
318 306 }
319 307
320 308 }
309
321 310 }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32));
322 311 return DIRENT_ReadErr;
323 312 }
324 313
325 314
326 int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba)
327 {
328 uint32_t i=0,fatsec=0;
329 if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/
330 {
331 *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/
332 return DIRENT_noErr;
333 }
334
335 uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
336 uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(fat32getdirentlba(entry)));
337 fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/
338 *nextsector_lba = fat32getdirentlba(entry);
339 while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32))
340 {
341 uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(*nextsector_lba));
342 fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/
343 fat32sectorreadout(fs,fatsec);
344 i= fat32clusterinfatoff(currentClusternum);
345 if(i==clusternum)
346 {
347 return DIRENT_noErr;
348 }
349 *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i);
350 if(*nextsector_lba==0xFFFFFFF7)
351 {
352 return DIRENT_BadSect;
353 }
354 if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6)
355 {
356 return DIRENT_LastSect;
357 }
358 }
359 return DIRENT_ReadErr;
360 }
361
362
363 315
364 316
365 317
@@ -381,3 +333,4 int fat32prevsectorlba2(FAT32fs* fs,ucdi
381 333
382 334
383 335
336
@@ -38,9 +38,9 int mbropen(blkdevice* phy,dikpartition*
38 38 }
39 39 if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA))
40 40 {
41 part->TypeCode = mbr[(512-82+TypeCodeoffset)+partNum*16];
42 part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+partNum*16] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+partNum*16]<<24);
43 part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+partNum*16] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+partNum*16]<<24);
41 part->TypeCode = mbr[(512-82+TypeCodeoffset)+(partNum*16)];
42 part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+(partNum*16)] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+(partNum*16)]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+(partNum*16)]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+(partNum*16)]<<24);
43 part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+(partNum*16)] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+(partNum*16)]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+(partNum*16)]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+(partNum*16)]<<24);
44 44 printf("MBR Ok\n");
45 45 part->valide = 1;
46 46 return MBRnoErr;
@@ -154,9 +154,9 int terminal_writenc(terminal_t* termina
154 154 if(terminal->column==0)terminal_clearCurentLine(terminal);
155 155 if(buffer[0]!='\r'){
156 156 // terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor);
157 // terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor);
158 #include <ili9328.h>
159 ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor);
157 terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor);
158 //#include <ili9328.h>
159 // ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor);
160 160 terminal_movecursor(terminal,1);
161 161 }
162 162 }
@@ -14,7 +14,7
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
@@ -99,7 +99,7 typedef struct FAT32fs
99 99 uint8_t BPB_SecPerClus;
100 100 uint8_t BPB_NumFATs;
101 101 char valide;
102 dikpartition* part;
102 dikpartition* part;
103 103 }FAT32fs;
104 104
105 105
@@ -193,4 +193,3 extern int fat32getdirentname(ucdirent*
193 193
194 194
195 195
196
@@ -2,7 +2,7
2 2 #include <sdcard.h>
3 3 #include <sdcard-spi.h>
4 4
5 FILE* sdcardimg;
5 FILE* sdcardimg=NULL;
6 6
7 7
8 8 void sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,unsigned int ),void (*xmit_mmc) (UHANDLE,const char *,unsigned int ),void (*setspeed) (UHANDLE phy,unsigned int speed),unsigned int (*getspeed) (UHANDLE phy))
@@ -67,6 +67,7 DSTATUS sdcarddisk_initialize (blkdevice
67 67
68 68 DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned long sector,char count)
69 69 {
70 if(sdcardimg==NULL)return RES_ERROR;
70 71 int res = fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET);
71 72 if(count*512== fread(buff,1,count*512,sdcardimg))
72 73 return RES_OK;
@@ -75,6 +76,7 DRESULT sdcarddisk_read (blkdevice* _thi
75 76
76 77 DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned long sector,char count)
77 78 {
79 if(sdcardimg==NULL)return RES_ERROR;
78 80 fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET);
79 81 fwrite(buff,1,count*512,sdcardimg);
80 82 return RES_OK;
@@ -86,7 +88,7 DRESULT sdcarddisk_ioctl (blkdevice* _th
86 88
87 89 void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected)
88 90 {
89 sdcardimg=fopen("sdcard.bin","rb");
91 sdcardimg=fopen("/dev/sdc","rb");
90 92 // sdcardimg=fopen("usbkey.bin","rb");
91 93 if(sdcardimg!=NULL)printf("ok sdcard openned\n");
92 94 else printf("Nok sdcard not openned\n");
@@ -100,7 +102,6 void sdcardspimakeblkdev(blkdevice* dev,
100 102 dev->ioctl = sdcarddisk_ioctl;
101 103 dev->initialize = sdcarddisk_initialize;
102 104 dev->status = sdcarddisk_status;
103 printf("sdcard opened\n");
104 105 }
105 106
106 107
@@ -38,6 +38,22 void* SDLCD_buffer;
38 38 int SDLCD_bpp;
39 39 void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
40 40
41 static Uint32 sdl_refresh_timer(Uint32 interval, void *opaque) {
42
43 if ( SDL_MUSTLOCK(screen) ) {
44 if ( SDL_LockSurface(screen) < 0 ) {
45 fprintf(stderr, "Can’t lock screen: %s\n", SDL_GetError());
46 return interval;
47 }
48 }
49 //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
50 SDL_Flip(screen);
51 if ( SDL_MUSTLOCK(screen) ) {
52 SDL_UnlockSurface(screen);
53 }
54 return interval; /* 0 means stop timer */
55 }
56
41 57 void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype)
42 58 {
43 59 int i=0;
@@ -45,7 +61,7 void SDLCD_mkscreen(int resx,int resy,in
45 61 fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
46 62 exit(1);
47 63 }
48 screen = SDL_SetVideoMode(resx, resy, bpp, 0);
64 screen = SDL_SetVideoMode(resx, resy, bpp, SDL_DOUBLEBUF);
49 65 if(!screen) {
50 66 fprintf(stderr, "SDL: could not set video mode - exiting\n");
51 67 exit(1);
@@ -56,16 +72,17 void SDLCD_mkscreen(int resx,int resy,in
56 72 return;
57 73 }
58 74 }
75 SDL_UpdateRect(screen, 0, 0, resx, resy);
59 76 if ( SDL_MUSTLOCK(screen) ) {
60 77 SDL_UnlockSurface(screen);
61 78 }
62 SDL_UpdateRect(screen, 0, 0, resx, resy);
63 79 SDLCD_buffer = malloc(resx*resy*bpp/8);
64 80 SDLCD_bpp = bpp;
65 81 for(i=0;i<(resx*resy);i++)
66 82 {
67 83 SDLCD_putpixel(screen, i%resx, (i/resx), 0xFFFF);
68 84 }
85 SDL_AddTimer(10, sdl_refresh_timer, NULL);
69 86 }
70 87
71 88
@@ -213,7 +230,7 void SDLCD_writeGRAM(void* buffer,uint32
213 230 SDL_UnlockSurface(screen);
214 231 }
215 232 // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt);
216 SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
233 //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
217 234 }
218 235
219 236 void SDLCD_writeGRAM_16bpp(void* buffer,uint32_t count)
@@ -244,7 +261,7 void SDLCD_writeGRAM_16bpp(void* buffer,
244 261 SDL_UnlockSurface(screen);
245 262 }
246 263 // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt);
247 SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
264 //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
248 265 }
249 266
250 267 void SDLCD_readGRAM_16bpp(void* buffer,uint32_t count)
General Comments 0
You need to be logged in to leave comments. Login now