diff --git a/bsp/src/OPLAYER/bsp.c b/bsp/src/OPLAYER/bsp.c --- a/bsp/src/OPLAYER/bsp.c +++ b/bsp/src/OPLAYER/bsp.c @@ -60,7 +60,9 @@ LCD_t lcd0={ terminal_t terminal0; volatile int8_t* lcd0_CMD=(volatile int8_t*)0x60000000; +volatile int16_t* lcd0_CMD16=(volatile int16_t*)0x60000000; volatile int8_t* lcd0_DATA=(volatile int8_t*)0x61FFFFF0; +volatile int16_t* lcd0_DATA16=(volatile int16_t*)0x61FFFFF0; float VREF0 =(float)3.3; volatile vs10XXDev audioCodec0; @@ -156,8 +158,8 @@ int bsp_FSMC_init() #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) - gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\ - ,PD4,PD5,PD7,PE4}; + gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\ + ,PD4,PD5,PD7,PE4}; for(int i=0;i<12;i++) { gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); @@ -167,7 +169,7 @@ int bsp_FSMC_init() } FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; - FSMC_NORSRAMTimingInitTypeDef p,readtim; + FSMC_NORSRAMTimingInitTypeDef p; /* Enable FSMC clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); @@ -302,7 +304,7 @@ void bsp_SD_init() { printf("Can't open or read MBR\n"); } - delay_100us(1000); + delay_100us(10000); if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) { if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) @@ -312,7 +314,7 @@ void bsp_SD_init() { printf("Can't open or read MBR\n"); } - delay_100us(1000); + delay_100us(10000); if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) { if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) @@ -322,7 +324,7 @@ void bsp_SD_init() { printf("Can't open or read MBR\n"); } - delay_100us(1000); + delay_100us(10000); if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) { if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) @@ -338,7 +340,7 @@ void bsp_SD_init() printf("Can't initialize SDCARD\n"); } } - delay_100us(2000); + delay_100us(20000); } void vs1052setXCS(char val) @@ -401,7 +403,6 @@ void bsp_lcd0_write_reg(uint32_t reg,uin *lcd0_DATA=pt8[3]; *lcd0_DATA=pt8[2]; #else - *lcd0_CMD=pt8[1]; *lcd0_CMD=pt8[0]; pt8 = (uint8_t*)(void*)&data; @@ -423,7 +424,6 @@ uint32_t bsp_lcd0_read_reg(uint32_t reg) pt8[3]=*lcd0_DATA; pt8[2]=*lcd0_DATA; #else - *lcd0_CMD=pt8[1]; *lcd0_CMD=pt8[0]; pt8 = (uint8_t*)(void*)&DATA; @@ -448,7 +448,6 @@ void bsp_lcd0_writeGRAM(void* buffer,uin *lcd0_DATA=pt8[2*i]; } #else - *lcd0_CMD=pt8[1]; *lcd0_CMD=pt8[0]; pt8 = (uint8_t*)(void*)buffer; @@ -463,9 +462,9 @@ void bsp_lcd0_writeGRAM(void* buffer,uin void bsp_lcd0_readGRAM(void* buffer,uint32_t count) { - //uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; - volatile uint8_t* pt8 ;// = (uint8_t*)(void*)® -/* #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ + //uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; + volatile uint8_t* pt8;// = (uint8_t*)(void*)® + /* #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ *lcd0_CMD=pt8[3]; *lcd0_CMD=pt8[2]; pt8 = (uint8_t*)(void*)buffer; @@ -485,7 +484,7 @@ void bsp_lcd0_readGRAM(void* buffer,uint /* * x dummy reads Cf ili9328 datasheet p79! */ - /* pt8[0]=*lcd0_DATA; + /* pt8[0]=*lcd0_DATA; pt8[1]=*lcd0_DATA; for(int i=0;i<(int)count;i++) @@ -497,15 +496,14 @@ void bsp_lcd0_readGRAM(void* buffer,uint } #endif*/ - *lcd0_CMD=(uint8_t)0; - *lcd0_CMD=(uint8_t)0x22; + *lcd0_CMD=(int8_t)0; +// *lcd0_CMD=(int8_t)0x22; + *lcd0_CMD=(int8_t)0x00; pt8 = (uint8_t*)buffer; pt8[1]=*lcd0_DATA; pt8[0]=*lcd0_DATA; for(int i=0;i<(int)count;i++) { - //pt8[(2*i) +1]=0; - //pt8[2*i]=0; pt8[(2*i)+1]= *lcd0_DATA; pt8[2*i]= *lcd0_DATA; } @@ -516,7 +514,7 @@ void bsp_GTerm_init() if(__opnfiles__[1]==NULL) { streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); - terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1); + terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); __opnfiles__[1] = fd1; } else diff --git a/bsp/src/OPLAYER/bsp.h b/bsp/src/OPLAYER/bsp.h --- a/bsp/src/OPLAYER/bsp.h +++ b/bsp/src/OPLAYER/bsp.h @@ -45,6 +45,7 @@ #define LCD_RESET PD10 #define LCD_BACKL PE11 +#define LCD_RS PE4 #define VS1053SPI spi1 #define VS1053xCS PA3 diff --git a/bsp/src/SIMULATOR/bsp.c b/bsp/src/SIMULATOR/bsp.c --- a/bsp/src/SIMULATOR/bsp.c +++ b/bsp/src/SIMULATOR/bsp.c @@ -136,7 +136,55 @@ void bsp_Audio_init() void bsp_SD_init() { - + sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2, bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); + if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT) + { + if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr) + { + if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1)) + printf("Can't open fat32 partition 1\n"); + } + else + { + printf("Can't open or read MBR\n"); + } + delay_100us(1000); + if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) + { + if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) + printf("Can't open fat32 partition 2\n"); + } + else + { + printf("Can't open or read MBR\n"); + } + delay_100us(1000); + if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) + { + if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) + printf("Can't open fat32 partition 3\n"); + } + else + { + printf("Can't open or read MBR\n"); + } + delay_100us(1000); + if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) + { + if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) + printf("Can't open fat32 partition 4\n"); + } + else + { + printf("Can't open or read MBR\n"); + } + } + else + { + printf("Can't initialize SDCARD\n"); + } + + delay_100us(2000); } void vs1052setXCS(char val) diff --git a/examples/SOLAR_PSU_HELLO/main.c b/examples/SOLAR_PSU_HELLO/main.c --- a/examples/SOLAR_PSU_HELLO/main.c +++ b/examples/SOLAR_PSU_HELLO/main.c @@ -88,7 +88,7 @@ void tryToplay2() void playFile(ucdirent* file,FAT32fs* part) { extern volatile vs10XXDev audioCodec0; - char direntName[]=" \n"; + char direntName[]=" \n"; uint32_t fileLba,nextLba; int i=0; fat32getdirentname(file,direntName); @@ -139,7 +139,7 @@ void playAllparts() } } -int main() +int main2() { delay_100us(30000); int i=0; @@ -206,7 +206,7 @@ int main() while(1); } -int main2() +int main() { extern terminal_t terminal0; extern volatile vs10XXDev audioCodec0; diff --git a/examples/TEST_SIMULATOR/TEST_SIMULATOR.pro b/examples/TEST_SIMULATOR/TEST_SIMULATOR.pro --- a/examples/TEST_SIMULATOR/TEST_SIMULATOR.pro +++ b/examples/TEST_SIMULATOR/TEST_SIMULATOR.pro @@ -9,5 +9,6 @@ DEFINES += CPUFREQ=100000000 SOURCES += \ main.c \ - test_lcd.c + test_lcd.c \ + test_SDCARD.c diff --git a/examples/TEST_SIMULATOR/main.c b/examples/TEST_SIMULATOR/main.c --- a/examples/TEST_SIMULATOR/main.c +++ b/examples/TEST_SIMULATOR/main.c @@ -16,34 +16,48 @@ extern streamdevice* __opnfiles__[]; extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); +extern void test_address(LCD_t* LCD); +extern void printRootClustersChain(FAT32fs* sdcard2FAT32part); char buffer[512]; -void streamdevicePrint(streamdevice* dev, const char* format,...) -{ - char** str_buffer; - int i; - va_list ap; - va_start(ap,format); - vasprintf(str_buffer,format,ap); - va_end(ap); - i=strlen(*str_buffer); - dev->ops->write(dev,(void*)*str_buffer,1,i); - free(*str_buffer); -} - -//int printf(const char *format,...) +//void streamdevicePrint(streamdevice* dev, const char* format,...) //{ -// char** str_buffer; +// char str_buffer[512]=""; // int i; // va_list ap; // va_start(ap,format); // vasprintf(str_buffer,format,ap); // va_end(ap); -// i=strlen(*str_buffer); -// __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)*str_buffer,1,i); -// free(*str_buffer); +// i=strlen(str_buffer); +// dev->ops->write(dev,(void*)str_buffer,1,i); +//} + +int _write(int file, char *ptr, int len) +{ + if(file<__MAX_OPENED_FILES__ && __opnfiles__[file]!=NULL) + { + if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len; + } + return len; +} +int _write_r (struct _reent *r, int file, char * ptr, int len) +{ + return _write(file, ptr, len); +} + +//int printf(const char *format,...) +//{ +// char str_buffer[512]=""; +// for(int i =0;i<512;i++)str_buffer[i]='\0'; +// int i; +// va_list ap; +// va_start(ap,format); +// vasprintf(str_buffer,format,ap); +// va_end(ap); +// i=strlen(str_buffer); +// __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)str_buffer,1,i); //} void lcd_print() @@ -52,17 +66,70 @@ void lcd_print() // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5); } + +void playFile(ucdirent* file,FAT32fs* part) +{ + extern volatile vs10XXDev audioCodec0; + char direntName[]=" \n"; + uint32_t fileLba,nextLba; + int i=0; + fat32getdirentname(file,direntName); + //gpioset(LCD_BACKL); + printf("%s\n",direntName); + nextLba=fat32getdirentlba(file); + //printf("Streaming File\n"); + //gpioclr(LCD_BACKL); +} + +void listFiles() +{ + extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4; + ucdirent root; + if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) + { + printf("Reading on SDCARD2 part1\n"); + if(DIRENT_noErr==fat32getrootfirstent(&root)) + { + do{ + playFile(&root,&sdcard2FAT32part1); + }while (DIRENT_noErr==fat32nextdirent(&root)); + } + } + gpioset(LED2); + if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) + { + printf("Reading on SDCARD2 part2\n"); + if(DIRENT_noErr==fat32getrootfirstent(&root)) + { + do{ + playFile(&root,&sdcard2FAT32part2); + }while (DIRENT_noErr==fat32nextdirent(&root)); + } + } +} + + +int libuc_main2() +{ + printRootClustersChain(&sdcard2FAT32part1); + +} + int libuc_main() { char in[255]; - lcd_print(); + //lcd_print(); printf("hello world\n"); - streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96); + delay_100us(10000); + // streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96); lcd0.paintText(&lcd0,"A",10,100,&ComicSansMS_18,0x0); + //while(1)test_address(&lcd0); + listFiles(); // while (scanf("%c",in)) // { sleep(5); // } + } diff --git a/examples/TEST_SIMULATOR/test_SDCARD.c b/examples/TEST_SIMULATOR/test_SDCARD.c new file mode 100644 --- /dev/null +++ b/examples/TEST_SIMULATOR/test_SDCARD.c @@ -0,0 +1,19 @@ + +#include +#include +#include + +void printRootClustersChain(FAT32fs* sdcard2FAT32part) +{ + ucdirent root; + uint32_t sector_lba,res,tmp=sdcard2FAT32part->cluster_begin_lba; + sector_lba=tmp; + do + { + printf("Sector @0x%x\n",tmp); + //sector_lba=tmp+sdcard2FAT32part->BPB_SecPerClus-1; + sector_lba=tmp; + res=fat32nextsectorlba(sdcard2FAT32part,sector_lba,&tmp); + }while((res==DIRENT_noErr)&&(res!=DIRENT_LastSect)); + +} diff --git a/examples/TEST_SIMULATOR/test_lcd.c b/examples/TEST_SIMULATOR/test_lcd.c --- a/examples/TEST_SIMULATOR/test_lcd.c +++ b/examples/TEST_SIMULATOR/test_lcd.c @@ -14,8 +14,30 @@ #include #include +uint16_t buff[50*50]; void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) { // LCD->paintFilRect(LCD,x,y,w,h,0,0,color); } +int coef=1; + +void test_address(LCD_t* LCD) +{ + LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); + uint16_t color[1]; + for(int y=0;y<320;y++) + { + for(int x=0;x<240;x++) + { + color[0]=((x/10*y*x)/((y+x+1)))+coef; + coef = color[0]; + LCD->paint(LCD,color,x,y,1,1); + //delay_100us(100); + } + } + LCD->getPix(LCD,buff,50,50,50,50); + // delay_100us(5000); + LCD->paint(LCD,buff,50,50,50,50); + delay_100us(500); +} diff --git a/lib/src/common/FILE_SYSTEM/FAT32/fat32.c b/lib/src/common/FILE_SYSTEM/FAT32/fat32.c --- a/lib/src/common/FILE_SYSTEM/FAT32/fat32.c +++ b/lib/src/common/FILE_SYSTEM/FAT32/fat32.c @@ -14,7 +14,7 @@ -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------------- -- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org @@ -25,34 +25,32 @@ #include #include -char fat32buff[512]__attribute__ ((aligned (4))); +char fat32buff[512]; uint32_t lastSecAddrs=-1; FAT32fs* lastFATFS=0; int fat32open(FAT32fs* fs,dikpartition* part) { - fs->valide = 0; - if(part->valide==0)return FATBadpart; - char sector[512]; + //char sector[512]; fs->part = part; if(!isFat32(fs->part->TypeCode))return FATBadpart; - if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr; - fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(sector,BPB_BytsPerSecoff); - fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(sector,BPB_RsvdSecCntoff); - fs->BPB_FATSz32 = fat32Ui8_2_Ui32(sector,BPB_FATSz32off); - fs->BPB_RootClus = fat32Ui8_2_Ui32(sector,BPB_RootClusoff); - fs->BPB_SecPerClus = sector[BPB_SecPerClusoff]; - fs->BPB_NumFATs = sector[BPB_NumFATsoff]; + //if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr; + fat32sectorreadout(fs,fs->part->LBABegin); + fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(fat32buff,BPB_BytsPerSecoff); + fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(fat32buff,BPB_RsvdSecCntoff); + fs->BPB_FATSz32 = fat32Ui8_2_Ui32(fat32buff,BPB_FATSz32off); + fs->BPB_RootClus = fat32Ui8_2_Ui32(fat32buff,BPB_RootClusoff); + fs->BPB_SecPerClus = fat32buff[BPB_SecPerClusoff]; + fs->BPB_NumFATs = fat32buff[BPB_NumFATsoff]; fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt; fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 ); - fs->valide=1; return FATnoErr; } int fat32mkdirent(FAT32fs* fs,ucdirent* dirent) { - if((fs==0) || (fs->valide==0)) return DIRENT_BabArg; + if(fs==0) return DIRENT_BabArg; if(dirent==0) return DIRENT_BabArg; dirent->fs = (UHANDLE)fs; dirent->getrootfirstent = &fat32getrootfirstent; @@ -62,7 +60,7 @@ int fat32mkdirent(FAT32fs* fs,ucdirent* int fat32getrootfirstent(ucdirent* entry) -{ +{ if(entry==0) return DIRENT_BabArg; entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba; entry->Currententry = 0; @@ -72,7 +70,7 @@ int fat32getrootfirstent(ucdirent* entry int fat32getVolName(FAT32fs* fs,char* Name) { - if((fs==0) || (fs->valide==0)) return DIRENT_BabArg; + if(fs==0) return DIRENT_BabArg; if(Name==0) return DIRENT_BabArg; int i=0; ucdirent entry; @@ -109,31 +107,19 @@ int fat32nextdirent(ucdirent* entry) j=entry->CurrentSec;// /*Restart at last sector*/ do { - //printf("reading new secotr\n",k); fat32sectorreadout(((FAT32fs*)entry->fs),j); - //printf("done\n",k); - /*512 Bytes per sector and 32 bytes per entry*/ - for(k=k;k<(512);k+=32) + for(k=k;k<(512);k+=32) /*512 Bytes per sector and 32 bytes per entry*/ { if((fat32buff[DIR_Nameoff+k]!=(char)0xE5)) /*0xE5 = free entry*/ { - //printf("Fount dir entry = %d, 0x%X\n",0xff & ((int)fat32buff[DIR_Nameoff+k]),0xff & ((int)fat32buff[DIR_Attroff+k])); if(fat32buff[DIR_Nameoff+k]==(char)0) - { - //printf("end of directory reached\n",k); return DIRENT_EndOfDir; /*0x00 = end of dir*/ - } else - { - uint8_t attribute=fat32buff[DIR_Attroff + k]; - if( (attribute==ATTR_DIRECTORY) - ||(attribute==ATTR_ARCHIVE) - ||(attribute==ATTR_READ_ONLY) - ||(attribute==ATTR_READ_ONLY)) + if((fat32buff[DIR_Attroff + k]==(char)ATTR_DIRECTORY)||(fat32buff[DIR_Attroff + k]==(char)ATTR_ARCHIVE)||(fat32buff[DIR_Attroff + k]==(char)(ATTR_READ_ONLY))) { for(n=0;n<16;n++)entry->DIR_Name[n] = '\0'; for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k]; - entry->DIR_Attr = attribute; + entry->DIR_Attr = (uint8_t)fat32buff[DIR_Attroff + k]; entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k]; entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k)); entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k)); @@ -143,16 +129,13 @@ int fat32nextdirent(ucdirent* entry) entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k)); entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k)); entry->CurrentSec = j; - entry->Currententry = (uint8_t)(0xFF&(k>>5)); + entry->Currententry = (unsigned char)(k/32); return DIRENT_noErr; } - } } + } - //printf("asking for next sector\n"); - //printf("current = 0x%X\n",j); j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k); - //printf("got it 0x%x\n",k); if(j!=DIRENT_noErr) { if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/ @@ -201,7 +184,7 @@ int fat32getdirentname(ucdirent* entry,c if(k==0) { //get previous sector - if(fat32prevsectorlba2((FAT32fs*)entry->fs,entry, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr; + if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr; fat32sectorreadout(((FAT32fs*)entry->fs),j); k=512-32; for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k]; @@ -264,10 +247,13 @@ int fat32nextsectorlba(FAT32fs* fs,uint3 *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i); if(*nextsector_lba==0xFFFFFFF7) { + + printf("DIRENT_BadSect\n"); return DIRENT_BadSect; } if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6) { + printf("DIRENT_LastSect\n"); return DIRENT_LastSect; } *nextsector_lba = clusterlba(fs,*nextsector_lba); @@ -278,28 +264,30 @@ int fat32nextsectorlba(FAT32fs* fs,uint3 int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba) { uint32_t i=0,fatsec=0; - if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/ + if(((lastsector_lba - fs->cluster_begin_lba) % (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/ { *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/ return DIRENT_noErr; } - - uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ + uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ - while(fatsec>=fs->fat_begin_lba) + do { + fat32sectorreadout(fs,fatsec); fatsec--; - for(i=508;i>2;i-=4) + for(i=511;i>3;i-=4) { - *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i); + *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i-3); if (*nextsector_lba ==clusternum) { *nextsector_lba = clusterlba(fs,*nextsector_lba); return DIRENT_noErr; } + } - } + + }while(fatsec>=fs->fat_begin_lba); clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ @@ -318,48 +306,12 @@ int fat32prevsectorlba(FAT32fs* fs,uint3 } } + }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32)); return DIRENT_ReadErr; } -int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba) -{ - uint32_t i=0,fatsec=0; - if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/ - { - *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/ - return DIRENT_noErr; - } - - uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ - uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(fat32getdirentlba(entry))); - fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/ - *nextsector_lba = fat32getdirentlba(entry); - while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32)) - { - uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(*nextsector_lba)); - fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/ - fat32sectorreadout(fs,fatsec); - i= fat32clusterinfatoff(currentClusternum); - if(i==clusternum) - { - return DIRENT_noErr; - } - *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i); - if(*nextsector_lba==0xFFFFFFF7) - { - return DIRENT_BadSect; - } - if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6) - { - return DIRENT_LastSect; - } - } - return DIRENT_ReadErr; -} - - @@ -381,3 +333,4 @@ int fat32prevsectorlba2(FAT32fs* fs,ucdi + diff --git a/lib/src/common/FILE_SYSTEM/MBR/mbr.c b/lib/src/common/FILE_SYSTEM/MBR/mbr.c --- a/lib/src/common/FILE_SYSTEM/MBR/mbr.c +++ b/lib/src/common/FILE_SYSTEM/MBR/mbr.c @@ -38,9 +38,9 @@ int mbropen(blkdevice* phy,dikpartition* } if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA)) { - part->TypeCode = mbr[(512-82+TypeCodeoffset)+partNum*16]; - 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); - 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); + part->TypeCode = mbr[(512-82+TypeCodeoffset)+(partNum*16)]; + 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); + 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); printf("MBR Ok\n"); part->valide = 1; return MBRnoErr; diff --git a/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.c b/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.c --- a/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.c +++ b/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.c @@ -154,9 +154,9 @@ int terminal_writenc(terminal_t* termina if(terminal->column==0)terminal_clearCurentLine(terminal); if(buffer[0]!='\r'){ // terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); - // terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); -#include - ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); + terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); +//#include +// ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); terminal_movecursor(terminal,1); } } diff --git a/lib/src/includes/fat32.h b/lib/src/includes/fat32.h --- a/lib/src/includes/fat32.h +++ b/lib/src/includes/fat32.h @@ -14,7 +14,7 @@ -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------------- -- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org @@ -99,7 +99,7 @@ typedef struct FAT32fs uint8_t BPB_SecPerClus; uint8_t BPB_NumFATs; char valide; - dikpartition* part; + dikpartition* part; }FAT32fs; @@ -193,4 +193,3 @@ extern int fat32getdirentname(ucdirent* - diff --git a/lib/src/simulator/SDCARD/fakesdcard.c b/lib/src/simulator/SDCARD/fakesdcard.c --- a/lib/src/simulator/SDCARD/fakesdcard.c +++ b/lib/src/simulator/SDCARD/fakesdcard.c @@ -2,7 +2,7 @@ #include #include -FILE* sdcardimg; +FILE* sdcardimg=NULL; 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 DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned long sector,char count) { + if(sdcardimg==NULL)return RES_ERROR; int res = fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); if(count*512== fread(buff,1,count*512,sdcardimg)) return RES_OK; @@ -75,6 +76,7 @@ DRESULT sdcarddisk_read (blkdevice* _thi DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned long sector,char count) { + if(sdcardimg==NULL)return RES_ERROR; fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); fwrite(buff,1,count*512,sdcardimg); return RES_OK; @@ -86,7 +88,7 @@ DRESULT sdcarddisk_ioctl (blkdevice* _th void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected) { - sdcardimg=fopen("sdcard.bin","rb"); + sdcardimg=fopen("/dev/sdc","rb"); // sdcardimg=fopen("usbkey.bin","rb"); if(sdcardimg!=NULL)printf("ok sdcard openned\n"); else printf("Nok sdcard not openned\n"); @@ -100,7 +102,6 @@ void sdcardspimakeblkdev(blkdevice* dev, dev->ioctl = sdcarddisk_ioctl; dev->initialize = sdcarddisk_initialize; dev->status = sdcarddisk_status; - printf("sdcard opened\n"); } diff --git a/lib/src/simulator/SDLCD/SDLCD.c b/lib/src/simulator/SDLCD/SDLCD.c --- a/lib/src/simulator/SDLCD/SDLCD.c +++ b/lib/src/simulator/SDLCD/SDLCD.c @@ -38,6 +38,22 @@ void* SDLCD_buffer; int SDLCD_bpp; void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); +static Uint32 sdl_refresh_timer(Uint32 interval, void *opaque) { + + if ( SDL_MUSTLOCK(screen) ) { + if ( SDL_LockSurface(screen) < 0 ) { + fprintf(stderr, "Can’t lock screen: %s\n", SDL_GetError()); + return interval; + } + } + //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); + SDL_Flip(screen); + if ( SDL_MUSTLOCK(screen) ) { + SDL_UnlockSurface(screen); + } + return interval; /* 0 means stop timer */ +} + void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype) { int i=0; @@ -45,7 +61,7 @@ void SDLCD_mkscreen(int resx,int resy,in fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); exit(1); } - screen = SDL_SetVideoMode(resx, resy, bpp, 0); + screen = SDL_SetVideoMode(resx, resy, bpp, SDL_DOUBLEBUF); if(!screen) { fprintf(stderr, "SDL: could not set video mode - exiting\n"); exit(1); @@ -56,16 +72,17 @@ void SDLCD_mkscreen(int resx,int resy,in return; } } + SDL_UpdateRect(screen, 0, 0, resx, resy); if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } - SDL_UpdateRect(screen, 0, 0, resx, resy); SDLCD_buffer = malloc(resx*resy*bpp/8); SDLCD_bpp = bpp; for(i=0;i<(resx*resy);i++) { SDLCD_putpixel(screen, i%resx, (i/resx), 0xFFFF); } + SDL_AddTimer(10, sdl_refresh_timer, NULL); } @@ -213,7 +230,7 @@ void SDLCD_writeGRAM(void* buffer,uint32 SDL_UnlockSurface(screen); } // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); - SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); + //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); } void SDLCD_writeGRAM_16bpp(void* buffer,uint32_t count) @@ -244,7 +261,7 @@ void SDLCD_writeGRAM_16bpp(void* buffer, SDL_UnlockSurface(screen); } // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); - SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); + //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); } void SDLCD_readGRAM_16bpp(void* buffer,uint32_t count)