void saveImage(void)
{
uint x,y,w,h;
uint count,count2;
FRESULT res;
UINT br, bw; /* File read/write count */
FRESULT fr; /* FatFs return code */
uint len;
uint last;
do
{
sprintf(LastFile, "image%d.dat\0",imageCount++);
fr = f_open(&fil, LastFile, FA_OPEN_EXISTING);
f_close(&fil);
if(fr == FR_NO_FILE) break;
} while(1);
fr = f_open(&fil, LastFile, FA_CREATE_ALWAYS | FA_WRITE);
//void LCD_ReadBuff(char *buff, uint len)
x = 0;
y = 480-myH;
w = myW;
h = myH;
WriteCommand(0x40,0x00); // Graphics mode
WriteCommand(0x45,0x00); // Graphics mode - READ LEFT TO RIGHT then TOP TO BOTTOM
SetGraphicsCursorRead(x, y);
LCD_CmdWrite(0x02);
len = ((w*h)*2)/IMAGEBUFF_LEN;
last = (((w*h)*2)%IMAGEBUFF_LEN);
if(last > 0) len++;
while(len--)
{
if(len==1)
count2 = last;
else
count2 = IMAGEBUFF_LEN;
CS_LOW(LCD);
SPI_Write(0x40); // Cmd: read data
for(count = 0; count < count2;count++)
{
FILE_IN_BUFF[count++] = SPI_Read();
FILE_IN_BUFF[count++] = SPI_Read();
FILE_IN_BUFF[count++] = SPI_Read();
FILE_IN_BUFF[count] = SPI_Read();
}
CS_HIGH();
fr = f_write(&fil, FILE_IN_BUFF, count2, &bw); /* Write it to the destination file */
if (fr) break; /* error or disk full */
}
f_close(&fil);
}
void OpenImage(void)
{
uint x,y,w,h;
uint count,count2;
FRESULT res;
UINT br, bw; /* File read/write count */
FRESULT fr; /* FatFs return code */
uint len;
uint last;
fr = f_open(&fil, LastFile, FA_OPEN_EXISTING | FA_READ);
x = 0;
y = 480-myH;
w = myW;
h = myH;
WriteCommand(0x40,0x00); // Graphics write mode
SetGraphicsCursorWrite(x, y);
LCD_CmdWrite(0x02);
len = ((w*h)*2)/IMAGEBUFF_LEN;
last = (((w*h)*2)%IMAGEBUFF_LEN);
if(last > 0) len++;
while(len--)
{
if(len==1)
count2 = last;
else
count2 = IMAGEBUFF_LEN;
fr = f_read(&fil, FILE_IN_BUFF, count2, &br); /* Read a chunk of source file */
if (fr != FR_OK) break;
Chk_Busy();
CS_LOW(LCD);
SPI_Write(0x00); // Cmd: write data
for(count = 0; count < count2;count++)
SPI_Write(FILE_IN_BUFF[count]);
CS_HIGH();
//if (br != count2) break; /* error or eof */
}
f_close(&fil);
}