1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
25
26
31
32
35
38
39
42
45
46
49
52
53
56
57
58
59
60
61
62
65
66
67
70
71
72
75
78
79
82
83
88
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
120
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
145
146
147
148
152
156
157
158
159
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
190
194
195
196
197
201
202
203
204
209
210
211
212
213
214
215
216
217
218
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
242
243
244
245
256
257
258
259
260
261
262
263
264
271
286
287
290
291
294
295
/* ... */
#include "fatfs_storage.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
uint8_t sector[512];
FATFS fs;
FILINFO fno;
DIR dir;
FIL F;
const uint8_t SlidesCheck[2] =
{
0x42, 0x4D
...};
uint32_t BytesRead = 0;
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
uint32_t Storage_Init(void)
{
BSP_SD_Init();
if(f_mount(&fs, (TCHAR const*)"",0))
{
return 1;
}if (f_mount(&fs, (TCHAR const*)"",0)) { ... }
return 0;
}{ ... }
/* ... */
uint32_t Storage_OpenReadFile(uint8_t *Address, const char* BmpName)
{
uint32_t index = 0, size = 0, i1 = 0;
uint32_t BmpAddress;
FIL F1;
if (f_open(&F1, BmpName, FA_READ) != FR_OK)
{
while(1)
{
}while (1) { ... }
}if (f_open(&F1, BmpName, FA_READ) != FR_OK) { ... }
if (f_read (&F1, sector, 30, (UINT *)&BytesRead) != FR_OK)
{
while(1)
{
}while (1) { ... }
}if (f_read (&F1, sector, 30, (UINT *)&BytesRead) != FR_OK) { ... }
BmpAddress = (uint32_t)sector;
size = *(uint16_t *) (BmpAddress + 2);
size |= (*(uint16_t *) (BmpAddress + 4)) << 16;
index = *(uint16_t *) (BmpAddress + 10);
index |= (*(uint16_t *) (BmpAddress + 12)) << 16;
f_close (&F1);
f_open (&F1, BmpName, FA_READ);
if (size > 240*240*2)
{
size = 240*240*2;
}if (size > 240*240*2) { ... }
do
{
if (size < 256*2)
{
i1 = size;
}if (size < 256*2) { ... }
else
{
i1 = 256*2;
}else { ... }
size -= i1;
f_read (&F1, sector, i1, (UINT *)&BytesRead);
for (index = 0; index < i1; index++)
{
*(__IO uint8_t*) (Address) = *(__IO uint8_t *)BmpAddress;
BmpAddress++;
Address++;
}for (index = 0; index < i1; index++) { ... }
BmpAddress = (uint32_t)sector;
...}
while (size > 0);
f_close (&F1);
return 1;
}{ ... }
/* ... */
uint32_t Storage_CheckBitmapFile(const char* BmpName, uint32_t *FileLen)
{
if(f_mount(&fs, (TCHAR const*)"",0))
{
return 1;
}if (f_mount(&fs, (TCHAR const*)"",0)) { ... }
if (f_open (&F, BmpName, FA_READ))
{
return 2;
}if (f_open (&F, BmpName, FA_READ)) { ... }
f_read (&F, sector, 6, (UINT *)&BytesRead);
if (Buffercmp((uint8_t *)SlidesCheck, (uint8_t *) sector, 2) != 0)
{
return 3;
}if (Buffercmp((uint8_t *)SlidesCheck, (uint8_t *) sector, 2) != 0) { ... }
return 0;
}{ ... }
/* ... */
uint32_t Storage_GetDirectoryBitmapFiles (const char* DirName, char* Files[])
{
FATFS fs;
FILINFO fno;
DIR dir;
uint32_t counter = 0, index = 0;
FRESULT res;
if(f_mount(&fs, (TCHAR const*)"",0) != FR_OK)
{
return 0;
}if (f_mount(&fs, (TCHAR const*)"",0) != FR_OK) { ... }
res = f_opendir(&dir, DirName);
if (res == FR_OK)
{
for (;;)
{
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0)
break;
if (fno.fname[0] == '.')
continue;
if (!(fno.fattrib & AM_DIR))
{
do
{
counter++;
...}
while (fno.fname[counter] != 0x2E);
if (index < MAX_BMP_FILES)
{
if ((fno.fname[counter + 1] == 'B') && (fno.fname[counter + 2] == 'M') && (fno.fname[counter + 3] == 'P'))
{
if(sizeof(fno.fname) <= (MAX_BMP_FILE_NAME + 2))
{
sprintf (Files[index], "%s", fno.fname);
index++;
}if (sizeof(fno.fname) <= (MAX_BMP_FILE_NAME + 2)) { ... }
}if ((fno.fname[counter + 1] == 'B') && (fno.fname[counter + 2] == 'M') && (fno.fname[counter + 3] == 'P')) { ... }
}if (index < MAX_BMP_FILES) { ... }
counter = 0;
}if (!(fno.fattrib & AM_DIR)) { ... }
}for (;;) { ... }
}if (res == FR_OK) { ... }
f_mount(NULL, (TCHAR const*)"",0);
return index;
}{ ... }
/* ... */
uint8_t Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
{
while (BufferLength--)
{
if (*pBuffer1 != *pBuffer2)
{
return 1;
}if (*pBuffer1 != *pBuffer2) { ... }
pBuffer1++;
pBuffer2++;
}while (BufferLength--) { ... }
return 0;
}{ ... }
/* ... */
/* ... */
/* ... */