1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
22
23
28
36
37
38
39
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
115
116
117
118
119
120
121
122
123
124
125
126
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
155
162
163
164
165
166
172
173
174
175
176
177
178
182
183
184
185
186
187
204
205
206
207
208
209
210
217
218
219
220
221
231
232
233
/* ... */
#include "main.h"
#include <string.h>
Includes
#define BITMAP_BUFFER_SIZE 1*512
#define BITMAP_HEADER_SIZE sizeof(BmpHeader)
#define MIN(a,b) (((a)<(b))?(a):(b))
Private define
uint8_t aBuffer[BITMAP_HEADER_SIZE + BITMAP_BUFFER_SIZE];
FILINFO MyFileInfo;
DIR MyDirectory;
FIL MyFile;
FATFS fs;
UINT BytesWritten, BytesRead;
Private variables
/* ... */
uint32_t Storage_OpenReadFile(uint8_t Xpoz, uint16_t Ypoz, const char *BmpName)
{
uint32_t size = 0;
FIL bmpfile;
uint32_t nbline;
BmpHeader* pbmpheader = (BmpHeader*)aBuffer;
f_open(&bmpfile, BmpName, FA_READ);
f_read(&bmpfile, &aBuffer, BITMAP_HEADER_SIZE, &BytesRead);
size = pbmpheader->fsize - pbmpheader->offset;
f_lseek(&bmpfile, 0);
f_read(&bmpfile, &aBuffer, pbmpheader->offset, &BytesRead);
nbline = (BITMAP_BUFFER_SIZE - pbmpheader->offset + BITMAP_HEADER_SIZE)/(pbmpheader->w * 2);
do
{
uint32_t nbbytetoread;
nbbytetoread = MIN(size,nbline*pbmpheader->w*2);
pbmpheader->fsize = pbmpheader->offset + nbbytetoread;
pbmpheader->h = nbbytetoread/(pbmpheader->w*2);
f_lseek(&bmpfile, pbmpheader->offset + size - nbbytetoread);
f_read(&bmpfile, aBuffer + pbmpheader->offset, nbbytetoread, &BytesRead);
BSP_LCD_DrawBitmap(Xpoz, Ypoz, aBuffer);
size -= nbbytetoread;
Ypoz += nbline;
...}while (size > 0);
f_close(&bmpfile);
return 0;
}{ ... }
/* ... */
uint32_t Storage_CopyFile(const char* BmpName1, const char* BmpName2)
{
uint32_t index = 0;
FIL file1, file2;
f_open(&file1, BmpName1, FA_READ);
f_open(&file2, BmpName2, FA_CREATE_ALWAYS | FA_WRITE);
do
{
f_read(&file1, aBuffer, _MAX_SS, &BytesRead);
f_write(&file2, aBuffer, _MAX_SS, &BytesWritten);
index+= _MAX_SS;
...} while(index < f_size(&file1));
f_close(&file1);
f_close(&file2);
return 1;
}{ ... }
/* ... */
uint32_t Storage_CheckBitmapFile(const char* BmpName, uint32_t *FileLen)
{
uint32_t err = 0;
if(f_open(&MyFile, BmpName, FA_READ) != FR_OK)
{
err = 1;
}if (f_open(&MyFile, BmpName, FA_READ) != FR_OK) { ... }
else
{
if(f_close(&MyFile) != FR_OK)
{
err = 1;
}if (f_close(&MyFile) != FR_OK) { ... }
}else { ... }
return err;
}{ ... }
/* ... */
uint32_t Storage_GetDirectoryBitmapFiles(const char* DirName, char* Files[])
{
FRESULT res;
uint32_t index = 0;
if(f_mount(&fs, (TCHAR const*)"",0) != FR_OK)
{
return 0;
}if (f_mount(&fs, (TCHAR const*)"",0) != FR_OK) { ... }
res = f_findfirst(&MyDirectory, &MyFileInfo, DirName, "*.bmp");
while (MyFileInfo.fname[0])
{
if(res == FR_OK)
{
if(index < MAX_BMP_FILES)
{
sprintf (Files[index++], "%s", MyFileInfo.fname);
}if (index < MAX_BMP_FILES) { ... }
res = f_findnext(&MyDirectory, &MyFileInfo);
}if (res == FR_OK) { ... }
else
{
index = 0;
break;
}else { ... }
}while (MyFileInfo.fname[0]) { ... }
f_closedir(&MyDirectory);
return index;
}{ ... }
/* ... */
uint8_t Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
{
uint8_t ret = 1;
while (BufferLength--)
{
if(*pBuffer1 != *pBuffer2)
{
ret = 0;
}if (*pBuffer1 != *pBuffer2) { ... }
pBuffer1++;
pBuffer2++;
}while (BufferLength--) { ... }
return ret;
}{ ... }