@@ -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 | terminal_t terminal0; |
|
60 | terminal_t terminal0; | |
61 |
|
61 | |||
62 | volatile int8_t* lcd0_CMD=(volatile int8_t*)0x60000000; |
|
62 | volatile int8_t* lcd0_CMD=(volatile int8_t*)0x60000000; | |
|
63 | volatile int16_t* lcd0_CMD16=(volatile int16_t*)0x60000000; | |||
63 | volatile int8_t* lcd0_DATA=(volatile int8_t*)0x61FFFFF0; |
|
64 | volatile int8_t* lcd0_DATA=(volatile int8_t*)0x61FFFFF0; | |
|
65 | volatile int16_t* lcd0_DATA16=(volatile int16_t*)0x61FFFFF0; | |||
64 |
|
66 | |||
65 | float VREF0 =(float)3.3; |
|
67 | float VREF0 =(float)3.3; | |
66 | volatile vs10XXDev audioCodec0; |
|
68 | volatile vs10XXDev audioCodec0; | |
@@ -167,7 +169,7 int bsp_FSMC_init() | |||||
167 | } |
|
169 | } | |
168 |
|
170 | |||
169 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
|
171 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; | |
170 |
FSMC_NORSRAMTimingInitTypeDef p |
|
172 | FSMC_NORSRAMTimingInitTypeDef p; | |
171 |
|
173 | |||
172 | /* Enable FSMC clock */ |
|
174 | /* Enable FSMC clock */ | |
173 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); |
|
175 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); | |
@@ -302,7 +304,7 void bsp_SD_init() | |||||
302 | { |
|
304 | { | |
303 | printf("Can't open or read MBR\n"); |
|
305 | printf("Can't open or read MBR\n"); | |
304 | } |
|
306 | } | |
305 | delay_100us(1000); |
|
307 | delay_100us(10000); | |
306 | if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) |
|
308 | if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) | |
307 | { |
|
309 | { | |
308 | if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) |
|
310 | if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) | |
@@ -312,7 +314,7 void bsp_SD_init() | |||||
312 | { |
|
314 | { | |
313 | printf("Can't open or read MBR\n"); |
|
315 | printf("Can't open or read MBR\n"); | |
314 | } |
|
316 | } | |
315 | delay_100us(1000); |
|
317 | delay_100us(10000); | |
316 | if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) |
|
318 | if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) | |
317 | { |
|
319 | { | |
318 | if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) |
|
320 | if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) | |
@@ -322,7 +324,7 void bsp_SD_init() | |||||
322 | { |
|
324 | { | |
323 | printf("Can't open or read MBR\n"); |
|
325 | printf("Can't open or read MBR\n"); | |
324 | } |
|
326 | } | |
325 | delay_100us(1000); |
|
327 | delay_100us(10000); | |
326 | if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) |
|
328 | if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) | |
327 | { |
|
329 | { | |
328 | if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) |
|
330 | if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) | |
@@ -338,7 +340,7 void bsp_SD_init() | |||||
338 | printf("Can't initialize SDCARD\n"); |
|
340 | printf("Can't initialize SDCARD\n"); | |
339 | } |
|
341 | } | |
340 | } |
|
342 | } | |
341 | delay_100us(2000); |
|
343 | delay_100us(20000); | |
342 | } |
|
344 | } | |
343 |
|
345 | |||
344 | void vs1052setXCS(char val) |
|
346 | void vs1052setXCS(char val) | |
@@ -401,7 +403,6 void bsp_lcd0_write_reg(uint32_t reg,uin | |||||
401 | *lcd0_DATA=pt8[3]; |
|
403 | *lcd0_DATA=pt8[3]; | |
402 | *lcd0_DATA=pt8[2]; |
|
404 | *lcd0_DATA=pt8[2]; | |
403 | #else |
|
405 | #else | |
404 |
|
||||
405 | *lcd0_CMD=pt8[1]; |
|
406 | *lcd0_CMD=pt8[1]; | |
406 | *lcd0_CMD=pt8[0]; |
|
407 | *lcd0_CMD=pt8[0]; | |
407 | pt8 = (uint8_t*)(void*)&data; |
|
408 | pt8 = (uint8_t*)(void*)&data; | |
@@ -423,7 +424,6 uint32_t bsp_lcd0_read_reg(uint32_t reg) | |||||
423 | pt8[3]=*lcd0_DATA; |
|
424 | pt8[3]=*lcd0_DATA; | |
424 | pt8[2]=*lcd0_DATA; |
|
425 | pt8[2]=*lcd0_DATA; | |
425 | #else |
|
426 | #else | |
426 |
|
||||
427 | *lcd0_CMD=pt8[1]; |
|
427 | *lcd0_CMD=pt8[1]; | |
428 | *lcd0_CMD=pt8[0]; |
|
428 | *lcd0_CMD=pt8[0]; | |
429 | pt8 = (uint8_t*)(void*)&DATA; |
|
429 | pt8 = (uint8_t*)(void*)&DATA; | |
@@ -448,7 +448,6 void bsp_lcd0_writeGRAM(void* buffer,uin | |||||
448 | *lcd0_DATA=pt8[2*i]; |
|
448 | *lcd0_DATA=pt8[2*i]; | |
449 | } |
|
449 | } | |
450 | #else |
|
450 | #else | |
451 |
|
||||
452 | *lcd0_CMD=pt8[1]; |
|
451 | *lcd0_CMD=pt8[1]; | |
453 | *lcd0_CMD=pt8[0]; |
|
452 | *lcd0_CMD=pt8[0]; | |
454 | pt8 = (uint8_t*)(void*)buffer; |
|
453 | pt8 = (uint8_t*)(void*)buffer; | |
@@ -497,15 +496,14 void bsp_lcd0_readGRAM(void* buffer,uint | |||||
497 | } |
|
496 | } | |
498 | #endif*/ |
|
497 | #endif*/ | |
499 |
|
498 | |||
500 |
*lcd0_CMD=( |
|
499 | *lcd0_CMD=(int8_t)0; | |
501 |
*lcd0_CMD=( |
|
500 | // *lcd0_CMD=(int8_t)0x22; | |
|
501 | *lcd0_CMD=(int8_t)0x00; | |||
502 | pt8 = (uint8_t*)buffer; |
|
502 | pt8 = (uint8_t*)buffer; | |
503 | pt8[1]=*lcd0_DATA; |
|
503 | pt8[1]=*lcd0_DATA; | |
504 | pt8[0]=*lcd0_DATA; |
|
504 | pt8[0]=*lcd0_DATA; | |
505 | for(int i=0;i<(int)count;i++) |
|
505 | for(int i=0;i<(int)count;i++) | |
506 | { |
|
506 | { | |
507 | //pt8[(2*i) +1]=0; |
|
|||
508 | //pt8[2*i]=0; |
|
|||
509 | pt8[(2*i)+1]= *lcd0_DATA; |
|
507 | pt8[(2*i)+1]= *lcd0_DATA; | |
510 | pt8[2*i]= *lcd0_DATA; |
|
508 | pt8[2*i]= *lcd0_DATA; | |
511 | } |
|
509 | } | |
@@ -516,7 +514,7 void bsp_GTerm_init() | |||||
516 | if(__opnfiles__[1]==NULL) |
|
514 | if(__opnfiles__[1]==NULL) | |
517 | { |
|
515 | { | |
518 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
516 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
519 |
terminal_init(&terminal0 ,&lcd0,&ComicSansMS_ |
|
517 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); | |
520 | __opnfiles__[1] = fd1; |
|
518 | __opnfiles__[1] = fd1; | |
521 | } |
|
519 | } | |
522 | else |
|
520 | else |
@@ -45,6 +45,7 | |||||
45 |
|
45 | |||
46 | #define LCD_RESET PD10 |
|
46 | #define LCD_RESET PD10 | |
47 | #define LCD_BACKL PE11 |
|
47 | #define LCD_BACKL PE11 | |
|
48 | #define LCD_RS PE4 | |||
48 |
|
49 | |||
49 | #define VS1053SPI spi1 |
|
50 | #define VS1053SPI spi1 | |
50 | #define VS1053xCS PA3 |
|
51 | #define VS1053xCS PA3 |
@@ -136,7 +136,55 void bsp_Audio_init() | |||||
136 |
|
136 | |||
137 | void bsp_SD_init() |
|
137 | void bsp_SD_init() | |
138 | { |
|
138 | { | |
|
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 | } | |||
139 |
|
186 | |||
|
187 | delay_100us(2000); | |||
140 | } |
|
188 | } | |
141 |
|
189 | |||
142 | void vs1052setXCS(char val) |
|
190 | void vs1052setXCS(char val) |
@@ -139,7 +139,7 void playAllparts() | |||||
139 | } |
|
139 | } | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | int main() |
|
142 | int main2() | |
143 | { |
|
143 | { | |
144 | delay_100us(30000); |
|
144 | delay_100us(30000); | |
145 | int i=0; |
|
145 | int i=0; | |
@@ -206,7 +206,7 int main() | |||||
206 | while(1); |
|
206 | while(1); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 |
int main |
|
209 | int main() | |
210 | { |
|
210 | { | |
211 | extern terminal_t terminal0; |
|
211 | extern terminal_t terminal0; | |
212 | extern volatile vs10XXDev audioCodec0; |
|
212 | extern volatile vs10XXDev audioCodec0; |
@@ -9,5 +9,6 DEFINES += CPUFREQ=100000000 | |||||
9 |
|
9 | |||
10 | SOURCES += \ |
|
10 | SOURCES += \ | |
11 | main.c \ |
|
11 | main.c \ | |
12 | test_lcd.c |
|
12 | test_lcd.c \ | |
|
13 | test_SDCARD.c | |||
13 |
|
14 |
@@ -16,34 +16,48 | |||||
16 |
|
16 | |||
17 | extern streamdevice* __opnfiles__[]; |
|
17 | extern streamdevice* __opnfiles__[]; | |
18 | extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); |
|
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 | char buffer[512]; |
|
21 | char buffer[512]; | |
20 |
|
22 | |||
21 |
|
23 | |||
22 | void streamdevicePrint(streamdevice* dev, const char* format,...) |
|
24 | //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,...) |
|
|||
36 | //{ |
|
25 | //{ | |
37 |
// char |
|
26 | // char str_buffer[512]=""; | |
38 | // int i; |
|
27 | // int i; | |
39 | // va_list ap; |
|
28 | // va_list ap; | |
40 | // va_start(ap,format); |
|
29 | // va_start(ap,format); | |
41 | // vasprintf(str_buffer,format,ap); |
|
30 | // vasprintf(str_buffer,format,ap); | |
42 | // va_end(ap); |
|
31 | // va_end(ap); | |
43 |
// i=strlen( |
|
32 | // i=strlen(str_buffer); | |
44 |
// |
|
33 | // dev->ops->write(dev,(void*)str_buffer,1,i); | |
45 | // free(*str_buffer); |
|
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 | void lcd_print() |
|
63 | void lcd_print() | |
@@ -52,17 +66,70 void lcd_print() | |||||
52 | // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5); |
|
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 | int libuc_main() |
|
118 | int libuc_main() | |
56 | { |
|
119 | { | |
57 | char in[255]; |
|
120 | char in[255]; | |
58 | lcd_print(); |
|
121 | //lcd_print(); | |
59 | printf("hello world\n"); |
|
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 | lcd0.paintText(&lcd0,"A",10,100,&ComicSansMS_18,0x0); |
|
125 | lcd0.paintText(&lcd0,"A",10,100,&ComicSansMS_18,0x0); | |
|
126 | //while(1)test_address(&lcd0); | |||
|
127 | listFiles(); | |||
62 | // while (scanf("%c",in)) |
|
128 | // while (scanf("%c",in)) | |
63 | // { |
|
129 | // { | |
64 | sleep(5); |
|
130 | sleep(5); | |
65 | // } |
|
131 | // } | |
|
132 | ||||
66 | } |
|
133 | } | |
67 |
|
134 | |||
68 |
|
135 |
@@ -14,8 +14,30 | |||||
14 | #include <string.h> |
|
14 | #include <string.h> | |
15 | #include <ili9328.h> |
|
15 | #include <ili9328.h> | |
16 |
|
16 | |||
|
17 | uint16_t buff[50*50]; | |||
17 |
|
18 | |||
18 | void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) |
|
19 | void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) | |
19 | { |
|
20 | { | |
20 | // LCD->paintFilRect(LCD,x,y,w,h,0,0,color); |
|
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 | } |
@@ -25,34 +25,32 | |||||
25 | #include <stdint.h> |
|
25 | #include <stdint.h> | |
26 | #include <hexviewer.h> |
|
26 | #include <hexviewer.h> | |
27 |
|
27 | |||
28 | char fat32buff[512]__attribute__ ((aligned (4))); |
|
28 | char fat32buff[512]; | |
29 | uint32_t lastSecAddrs=-1; |
|
29 | uint32_t lastSecAddrs=-1; | |
30 | FAT32fs* lastFATFS=0; |
|
30 | FAT32fs* lastFATFS=0; | |
31 |
|
31 | |||
32 | int fat32open(FAT32fs* fs,dikpartition* part) |
|
32 | int fat32open(FAT32fs* fs,dikpartition* part) | |
33 | { |
|
33 | { | |
34 | fs->valide = 0; |
|
34 | //char sector[512]; | |
35 | if(part->valide==0)return FATBadpart; |
|
|||
36 | char sector[512]; |
|
|||
37 | fs->part = part; |
|
35 | fs->part = part; | |
38 | if(!isFat32(fs->part->TypeCode))return FATBadpart; |
|
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; |
|
37 | //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); |
|
38 | fat32sectorreadout(fs,fs->part->LBABegin); | |
41 |
fs->BPB_ |
|
39 | fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(fat32buff,BPB_BytsPerSecoff); | |
42 |
fs->BPB_ |
|
40 | fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(fat32buff,BPB_RsvdSecCntoff); | |
43 |
fs->BPB_ |
|
41 | fs->BPB_FATSz32 = fat32Ui8_2_Ui32(fat32buff,BPB_FATSz32off); | |
44 | fs->BPB_SecPerClus = sector[BPB_SecPerClusoff]; |
|
42 | fs->BPB_RootClus = fat32Ui8_2_Ui32(fat32buff,BPB_RootClusoff); | |
45 | fs->BPB_NumFATs = sector[BPB_NumFATsoff]; |
|
43 | fs->BPB_SecPerClus = fat32buff[BPB_SecPerClusoff]; | |
|
44 | fs->BPB_NumFATs = fat32buff[BPB_NumFATsoff]; | |||
46 | fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt; |
|
45 | fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt; | |
47 | fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 ); |
|
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 | return FATnoErr; |
|
47 | return FATnoErr; | |
50 | } |
|
48 | } | |
51 |
|
49 | |||
52 |
|
50 | |||
53 | int fat32mkdirent(FAT32fs* fs,ucdirent* dirent) |
|
51 | int fat32mkdirent(FAT32fs* fs,ucdirent* dirent) | |
54 | { |
|
52 | { | |
55 |
if |
|
53 | if(fs==0) return DIRENT_BabArg; | |
56 | if(dirent==0) return DIRENT_BabArg; |
|
54 | if(dirent==0) return DIRENT_BabArg; | |
57 | dirent->fs = (UHANDLE)fs; |
|
55 | dirent->fs = (UHANDLE)fs; | |
58 | dirent->getrootfirstent = &fat32getrootfirstent; |
|
56 | dirent->getrootfirstent = &fat32getrootfirstent; | |
@@ -72,7 +70,7 int fat32getrootfirstent(ucdirent* entry | |||||
72 |
|
70 | |||
73 | int fat32getVolName(FAT32fs* fs,char* Name) |
|
71 | int fat32getVolName(FAT32fs* fs,char* Name) | |
74 | { |
|
72 | { | |
75 |
if |
|
73 | if(fs==0) return DIRENT_BabArg; | |
76 | if(Name==0) return DIRENT_BabArg; |
|
74 | if(Name==0) return DIRENT_BabArg; | |
77 | int i=0; |
|
75 | int i=0; | |
78 | ucdirent entry; |
|
76 | ucdirent entry; | |
@@ -109,31 +107,19 int fat32nextdirent(ucdirent* entry) | |||||
109 | j=entry->CurrentSec;// /*Restart at last sector*/ |
|
107 | j=entry->CurrentSec;// /*Restart at last sector*/ | |
110 | do |
|
108 | do | |
111 | { |
|
109 | { | |
112 | //printf("reading new secotr\n",k); |
|
|||
113 | fat32sectorreadout(((FAT32fs*)entry->fs),j); |
|
110 | fat32sectorreadout(((FAT32fs*)entry->fs),j); | |
114 | //printf("done\n",k); |
|
111 | for(k=k;k<(512);k+=32) /*512 Bytes per sector and 32 bytes per entry*/ | |
115 | /*512 Bytes per sector and 32 bytes per entry*/ |
|
|||
116 | for(k=k;k<(512);k+=32) |
|
|||
117 | { |
|
112 | { | |
118 | if((fat32buff[DIR_Nameoff+k]!=(char)0xE5)) /*0xE5 = free entry*/ |
|
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 | if(fat32buff[DIR_Nameoff+k]==(char)0) |
|
115 | if(fat32buff[DIR_Nameoff+k]==(char)0) | |
122 | { |
|
|||
123 | //printf("end of directory reached\n",k); |
|
|||
124 | return DIRENT_EndOfDir; /*0x00 = end of dir*/ |
|
116 | return DIRENT_EndOfDir; /*0x00 = end of dir*/ | |
125 | } |
|
|||
126 | else |
|
117 | else | |
127 | { |
|
118 | if((fat32buff[DIR_Attroff + k]==(char)ATTR_DIRECTORY)||(fat32buff[DIR_Attroff + k]==(char)ATTR_ARCHIVE)||(fat32buff[DIR_Attroff + k]==(char)(ATTR_READ_ONLY))) | |
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)) |
|
|||
133 | { |
|
119 | { | |
134 | for(n=0;n<16;n++)entry->DIR_Name[n] = '\0'; |
|
120 | for(n=0;n<16;n++)entry->DIR_Name[n] = '\0'; | |
135 | for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k]; |
|
121 | for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k]; | |
136 |
entry->DIR_Attr = |
|
122 | entry->DIR_Attr = (uint8_t)fat32buff[DIR_Attroff + k]; | |
137 | entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k]; |
|
123 | entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k]; | |
138 | entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k)); |
|
124 | entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k)); | |
139 | entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k)); |
|
125 | entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k)); | |
@@ -143,16 +129,13 int fat32nextdirent(ucdirent* entry) | |||||
143 | entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k)); |
|
129 | entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k)); | |
144 | entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k)); |
|
130 | entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k)); | |
145 | entry->CurrentSec = j; |
|
131 | entry->CurrentSec = j; | |
146 |
entry->Currententry = (u |
|
132 | entry->Currententry = (unsigned char)(k/32); | |
147 | return DIRENT_noErr; |
|
133 | return DIRENT_noErr; | |
148 | } |
|
134 | } | |
149 |
|
|
135 | } | |
150 | } |
|
136 | ||
151 | } |
|
137 | } | |
152 | //printf("asking for next sector\n"); |
|
|||
153 | //printf("current = 0x%X\n",j); |
|
|||
154 | j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k); |
|
138 | j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k); | |
155 | //printf("got it 0x%x\n",k); |
|
|||
156 | if(j!=DIRENT_noErr) |
|
139 | if(j!=DIRENT_noErr) | |
157 | { |
|
140 | { | |
158 | if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/ |
|
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 | if(k==0) |
|
184 | if(k==0) | |
202 | { |
|
185 | { | |
203 | //get previous sector |
|
186 | //get previous sector | |
204 |
if(fat32prevsectorlba |
|
187 | if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr; | |
205 | fat32sectorreadout(((FAT32fs*)entry->fs),j); |
|
188 | fat32sectorreadout(((FAT32fs*)entry->fs),j); | |
206 | k=512-32; |
|
189 | k=512-32; | |
207 | for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k]; |
|
190 | for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k]; | |
@@ -264,10 +247,13 int fat32nextsectorlba(FAT32fs* fs,uint3 | |||||
264 | *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i); |
|
247 | *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i); | |
265 | if(*nextsector_lba==0xFFFFFFF7) |
|
248 | if(*nextsector_lba==0xFFFFFFF7) | |
266 | { |
|
249 | { | |
|
250 | ||||
|
251 | printf("DIRENT_BadSect\n"); | |||
267 | return DIRENT_BadSect; |
|
252 | return DIRENT_BadSect; | |
268 | } |
|
253 | } | |
269 | if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6) |
|
254 | if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6) | |
270 | { |
|
255 | { | |
|
256 | printf("DIRENT_LastSect\n"); | |||
271 | return DIRENT_LastSect; |
|
257 | return DIRENT_LastSect; | |
272 | } |
|
258 | } | |
273 | *nextsector_lba = clusterlba(fs,*nextsector_lba); |
|
259 | *nextsector_lba = clusterlba(fs,*nextsector_lba); | |
@@ -278,28 +264,30 int fat32nextsectorlba(FAT32fs* fs,uint3 | |||||
278 | int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba) |
|
264 | int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba) | |
279 | { |
|
265 | { | |
280 | uint32_t i=0,fatsec=0; |
|
266 | uint32_t i=0,fatsec=0; | |
281 |
if(((lastsector_lba - |
|
267 | if(((lastsector_lba - fs->cluster_begin_lba) % (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/ | |
282 | { |
|
268 | { | |
283 | *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/ |
|
269 | *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/ | |
284 | return DIRENT_noErr; |
|
270 | return DIRENT_noErr; | |
285 | } |
|
271 | } | |
286 |
|
||||
287 |
uint32_t clusternum |
|
272 | uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ | |
288 | fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ |
|
273 | fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ | |
289 | while(fatsec>=fs->fat_begin_lba) |
|
274 | do | |
290 | { |
|
275 | { | |
|
276 | ||||
291 | fat32sectorreadout(fs,fatsec); |
|
277 | fat32sectorreadout(fs,fatsec); | |
292 | fatsec--; |
|
278 | fatsec--; | |
293 |
for(i=5 |
|
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 | if (*nextsector_lba ==clusternum) |
|
282 | if (*nextsector_lba ==clusternum) | |
297 | { |
|
283 | { | |
298 | *nextsector_lba = clusterlba(fs,*nextsector_lba); |
|
284 | *nextsector_lba = clusterlba(fs,*nextsector_lba); | |
299 | return DIRENT_noErr; |
|
285 | return DIRENT_noErr; | |
300 | } |
|
286 | } | |
|
287 | ||||
301 | } |
|
288 | } | |
302 | } |
|
289 | ||
|
290 | }while(fatsec>=fs->fat_begin_lba); | |||
303 |
|
291 | |||
304 | clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ |
|
292 | clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ | |
305 | fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ |
|
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 | }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32)); |
|
310 | }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32)); | |
322 | return DIRENT_ReadErr; |
|
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 | if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA)) |
|
39 | if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA)) | |
40 | { |
|
40 | { | |
41 |
|
|
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); |
|
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); |
|
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 | printf("MBR Ok\n"); |
|
44 | printf("MBR Ok\n"); | |
45 | part->valide = 1; |
|
45 | part->valide = 1; | |
46 | return MBRnoErr; |
|
46 | return MBRnoErr; |
@@ -154,9 +154,9 int terminal_writenc(terminal_t* termina | |||||
154 | if(terminal->column==0)terminal_clearCurentLine(terminal); |
|
154 | if(terminal->column==0)terminal_clearCurentLine(terminal); | |
155 | if(buffer[0]!='\r'){ |
|
155 | if(buffer[0]!='\r'){ | |
156 | // terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); |
|
156 | // terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); | |
157 |
|
|
157 | terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); | |
158 | #include <ili9328.h> |
|
158 | //#include <ili9328.h> | |
159 | ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); |
|
159 | // ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); | |
160 | terminal_movecursor(terminal,1); |
|
160 | terminal_movecursor(terminal,1); | |
161 | } |
|
161 | } | |
162 | } |
|
162 | } |
@@ -2,7 +2,7 | |||||
2 | #include <sdcard.h> |
|
2 | #include <sdcard.h> | |
3 | #include <sdcard-spi.h> |
|
3 | #include <sdcard-spi.h> | |
4 |
|
4 | |||
5 | FILE* sdcardimg; |
|
5 | FILE* sdcardimg=NULL; | |
6 |
|
6 | |||
7 |
|
7 | |||
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)) |
|
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 | DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned long sector,char count) |
|
68 | DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned long sector,char count) | |
69 | { |
|
69 | { | |
|
70 | if(sdcardimg==NULL)return RES_ERROR; | |||
70 | int res = fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); |
|
71 | int res = fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); | |
71 | if(count*512== fread(buff,1,count*512,sdcardimg)) |
|
72 | if(count*512== fread(buff,1,count*512,sdcardimg)) | |
72 | return RES_OK; |
|
73 | return RES_OK; | |
@@ -75,6 +76,7 DRESULT sdcarddisk_read (blkdevice* _thi | |||||
75 |
|
76 | |||
76 | DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned long sector,char count) |
|
77 | DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned long sector,char count) | |
77 | { |
|
78 | { | |
|
79 | if(sdcardimg==NULL)return RES_ERROR; | |||
78 | fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); |
|
80 | fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); | |
79 | fwrite(buff,1,count*512,sdcardimg); |
|
81 | fwrite(buff,1,count*512,sdcardimg); | |
80 | return RES_OK; |
|
82 | return RES_OK; | |
@@ -86,7 +88,7 DRESULT sdcarddisk_ioctl (blkdevice* _th | |||||
86 |
|
88 | |||
87 | void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected) |
|
89 | void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected) | |
88 | { |
|
90 | { | |
89 |
sdcardimg=fopen("sdc |
|
91 | sdcardimg=fopen("/dev/sdc","rb"); | |
90 | // sdcardimg=fopen("usbkey.bin","rb"); |
|
92 | // sdcardimg=fopen("usbkey.bin","rb"); | |
91 | if(sdcardimg!=NULL)printf("ok sdcard openned\n"); |
|
93 | if(sdcardimg!=NULL)printf("ok sdcard openned\n"); | |
92 | else printf("Nok sdcard not openned\n"); |
|
94 | else printf("Nok sdcard not openned\n"); | |
@@ -100,7 +102,6 void sdcardspimakeblkdev(blkdevice* dev, | |||||
100 | dev->ioctl = sdcarddisk_ioctl; |
|
102 | dev->ioctl = sdcarddisk_ioctl; | |
101 | dev->initialize = sdcarddisk_initialize; |
|
103 | dev->initialize = sdcarddisk_initialize; | |
102 | dev->status = sdcarddisk_status; |
|
104 | dev->status = sdcarddisk_status; | |
103 | printf("sdcard opened\n"); |
|
|||
104 | } |
|
105 | } | |
105 |
|
106 | |||
106 |
|
107 |
@@ -38,6 +38,22 void* SDLCD_buffer; | |||||
38 | int SDLCD_bpp; |
|
38 | int SDLCD_bpp; | |
39 | void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); |
|
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 | void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype) |
|
57 | void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype) | |
42 | { |
|
58 | { | |
43 | int i=0; |
|
59 | int i=0; | |
@@ -45,7 +61,7 void SDLCD_mkscreen(int resx,int resy,in | |||||
45 | fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); |
|
61 | fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); | |
46 | exit(1); |
|
62 | exit(1); | |
47 | } |
|
63 | } | |
48 |
screen = SDL_SetVideoMode(resx, resy, bpp, |
|
64 | screen = SDL_SetVideoMode(resx, resy, bpp, SDL_DOUBLEBUF); | |
49 | if(!screen) { |
|
65 | if(!screen) { | |
50 | fprintf(stderr, "SDL: could not set video mode - exiting\n"); |
|
66 | fprintf(stderr, "SDL: could not set video mode - exiting\n"); | |
51 | exit(1); |
|
67 | exit(1); | |
@@ -56,16 +72,17 void SDLCD_mkscreen(int resx,int resy,in | |||||
56 | return; |
|
72 | return; | |
57 | } |
|
73 | } | |
58 | } |
|
74 | } | |
|
75 | SDL_UpdateRect(screen, 0, 0, resx, resy); | |||
59 | if ( SDL_MUSTLOCK(screen) ) { |
|
76 | if ( SDL_MUSTLOCK(screen) ) { | |
60 | SDL_UnlockSurface(screen); |
|
77 | SDL_UnlockSurface(screen); | |
61 | } |
|
78 | } | |
62 | SDL_UpdateRect(screen, 0, 0, resx, resy); |
|
|||
63 | SDLCD_buffer = malloc(resx*resy*bpp/8); |
|
79 | SDLCD_buffer = malloc(resx*resy*bpp/8); | |
64 | SDLCD_bpp = bpp; |
|
80 | SDLCD_bpp = bpp; | |
65 | for(i=0;i<(resx*resy);i++) |
|
81 | for(i=0;i<(resx*resy);i++) | |
66 | { |
|
82 | { | |
67 | SDLCD_putpixel(screen, i%resx, (i/resx), 0xFFFF); |
|
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 | SDL_UnlockSurface(screen); |
|
230 | SDL_UnlockSurface(screen); | |
214 | } |
|
231 | } | |
215 | // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); |
|
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 | void SDLCD_writeGRAM_16bpp(void* buffer,uint32_t count) |
|
236 | void SDLCD_writeGRAM_16bpp(void* buffer,uint32_t count) | |
@@ -244,7 +261,7 void SDLCD_writeGRAM_16bpp(void* buffer, | |||||
244 | SDL_UnlockSurface(screen); |
|
261 | SDL_UnlockSurface(screen); | |
245 | } |
|
262 | } | |
246 | // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); |
|
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 | void SDLCD_readGRAM_16bpp(void* buffer,uint32_t count) |
|
267 | void SDLCD_readGRAM_16bpp(void* buffer,uint32_t count) |
General Comments 0
You need to be logged in to leave comments.
Login now