1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
23
24
25
26
27
28
29
30
31
32
33
34
35
38
39
40
41
42
43
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
97
101
102
103
104
105
115
116
125
126
127
128
129
130
131
132
133
139
140
141
142
143
144
145
146
147
148
149
150
151
152
156
160
161
162
163
167
168
169
170
176
177
178
179
180
181
182
186
187
188
189
190
191
208
209
210
211
212
213
214
221
/* ... */
#include "main.h"
#include <string.h>
Includes
uint8_t aBuffer[512];
FATFS fs;
FILINFO MyFileInfo;
DIR MyDirectory;
FIL MyFile;
UINT BytesWritten, BytesRead;
const uint8_t SlidesCheck[2] =
{
0x42, 0x4D
...};
Private variables
/* ... */
uint32_t Storage_OpenReadFile(uint8_t Xpoz, uint16_t Ypoz, const char *BmpName)
{
uint32_t index = 0, size = 0, width = 0, height = 0, i1 = 0, x = 0, y = 159;
uint32_t bmpaddress, bit_pixel = 0;
FIL file1;
uint16_t color = 0;
f_open(&file1, BmpName, FA_READ);
f_read(&file1, aBuffer, 30, &BytesRead);
bmpaddress = (uint32_t)aBuffer;
size = *(uint16_t *) (bmpaddress + 2);
size |= (*(uint16_t *) (bmpaddress + 4)) << 16;
index = *(uint16_t *) (bmpaddress + 10);
index |= (*(uint16_t *) (bmpaddress + 12)) << 16;
width = *(uint16_t *) (bmpaddress + 18);
width |= (*(uint16_t *) (bmpaddress + 20)) << 16;
height = *(uint16_t *) (bmpaddress + 22);
height |= (*(uint16_t *) (bmpaddress + 24)) << 16;
bit_pixel = *(uint16_t *) (bmpaddress + 28);
bit_pixel = bit_pixel/8;
size = (size - index);
f_close (&file1);
f_open (&file1, (TCHAR const*)BmpName, FA_READ);
f_read(&file1, aBuffer, index, &BytesRead);
do
{
if(size < 512)
{
i1 = size;
}if (size < 512) { ... }
else
{
i1 = 512;
}else { ... }
size -= i1;
f_read(&file1, aBuffer, i1, (UINT *)&BytesRead);
for (index = 0; index < (i1/bit_pixel); index++)
{
if( index%bit_pixel == 0)
{
color = (aBuffer[ index + 1] << 8) | aBuffer[ index];
}if (index%bit_pixel == 0) { ... }
x = index/bit_pixel;
BSP_LCD_DrawPixel(x, y, color);
}for (index = 0; index < (i1/bit_pixel); index++) { ... }
y--;
for (index = (i1/bit_pixel); index < i1; index++)
{
if( index%bit_pixel == 0)
{
color = (aBuffer[ index + 1] << 8) | aBuffer[ index];
}if (index%bit_pixel == 0) { ... }
x = index/bit_pixel - width;
BSP_LCD_DrawPixel(x, y, color);
}for (index = (i1/bit_pixel); index < i1; index++) { ... }
y--;
...}
while (size > 0);
f_close(&file1);
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 (&MyFile, (TCHAR const*)BmpName, FA_READ))
{
return 2;
}if (f_open (&MyFile, (TCHAR const*)BmpName, FA_READ)) { ... }
f_read (&MyFile, aBuffer, 6, (UINT *)&BytesRead);
if (Buffercmp((uint8_t *)SlidesCheck, (uint8_t *) aBuffer, 2) != 0)
{
return 3;
}if (Buffercmp((uint8_t *)SlidesCheck, (uint8_t *) aBuffer, 2) != 0) { ... }
return 0;
}{ ... }
/* ... */
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)
{
while (BufferLength--)
{
if (*pBuffer1 != *pBuffer2)
{
return 1;
}if (*pBuffer1 != *pBuffer2) { ... }
pBuffer1++;
pBuffer2++;
}while (BufferLength--) { ... }
return 0;
}{ ... }