struct znFAT_Init_Args Init_Args; //初始化参数集合 struct FileInfo fileinfo; //文件信息集合
JDEC jd; //TJpgD的解码体 unsigned char work_buf[4096]; //TJpgD的工作缓冲
int main(void) { u32 res=0,len=0; delay_init(); uart_init(115200); //串口初始化为115200 printf("串口设置完毕\r\n"); TFT_Init(); TFT_Clear(0x8888); //TFT初始化与清屏 znFAT_Device_Init(); //存储设备初始化 printf("SD卡初始化完毕\r\n"); znFAT_Select_Device(0,&Init_Args); //选择设备 res=znFAT_Init(); //文件系统初始化 if(!res) //文件系统初始化成功 { printf("Suc. to init FS\r\n");
printf("BPB_Sector_No: %d\r\n",Init_Args.BPB_Sector_No); printf("Total_SizeKB: %d\r\n",Init_Args.Total_SizeKB); printf("BytesPerSector: %d\r\n",Init_Args.BytesPerSector); printf("FATsectors: %d\r\n",Init_Args.FATsectors); printf("SectorsPerClust: %d\r\n",Init_Args.SectorsPerClust); printf("FirstFATSector: %d\r\n",Init_Args.FirstFATSector); printf("FirstDirSector: %d\r\n",Init_Args.FirstDirSector); printf("FSsec: %d\r\n",Init_Args.FSINFO_Sec); printf("Next_Free_Cluster: %d\r\n",Init_Args.Next_Free_Cluster); printf("FreenCluster: %d\r\n",Init_Args.Free_nCluster); } else //文件系统初始化失败 { printf("Fail to init FS , Err Code: %d\r\n",res); }
res=znFAT_Open_File(&fileinfo,"/test.jpg",0,1); //打开文件 if(!res) //如果打开文件成功 { printf("Suc. to open file.\r\n"); printf("================================\r\n"); printf("File_Name(Short 8.3):%s\r\n",fileinfo.File_Name); printf("File_Size:%d\r\n",fileinfo.File_Size);
printf("File_CDate:%d-%d-%d %d:%d:%d\r\n",fileinfo.File_CDate.year, \ fileinfo.File_CDate.month,fileinfo.File_CDate.day,fileinfo.File_CTime.hour, \ fileinfo.File_CTime.min,fileinfo.File_CTime.sec);
printf("File_StartClust:%d\r\n",fileinfo.File_StartClust); printf("File_CurClust:%d\r\n",fileinfo.File_CurClust); printf("File_CurSec:%d\r\n",fileinfo.File_CurSec); printf("File_CurPos:%d\r\n",fileinfo.File_CurPos); printf("File_CurOffset:%d\r\n",fileinfo.File_CurOffset); printf("================================\r\n"); printf("Start to read data....\r\n"); //开始读取数据 jd_prepare(&jd, input_func, work_buf, 4096, &fileinfo); //TJpdD解码前的准备
printf("JPEG info:\r\n"); printf("width:%d height:%d\r\n",jd.width,jd.height);
jd_decomp(&jd, output_func, 0); //开始解码
znFAT_Close_File(&fileinfo); //关闭文件 } else //如果打开文件不成功 { printf("Fail to open file , Err Code:%d\n",res); }
znFAT_Flush_FS(); //刷新文件系统
while(1); } |