更新字库
void GUI_FontUpdate(uint8_t updateState)
{
FRESULT res;
FIL fsrc;
UINT br;
uint32_t wordAddr, i, j;
#ifdef __MALLOC_H
uint8_t *p;
p = malloc(4096); //开辟一个内存块
if(p == 0)
{
return;
}
#else
uint8_t buffer[512];
#endif
/* 更新ASCII字库 */
if((updateState & GUI_UPDATE_ASCII) == GUI_UPDATE_ASCII)
{
/* 设置写入起始地址 */
wordAddr = GUI_FLASH_ASCII_ADDR;
j = 0;
/* 打开读取文件 */
res = f_open(&fsrc, GUI_ASCII_FILE, FA_READ);
if(res == FR_OK) //打开成功
{
for (;;) //开始读取数据
{
#ifdef __MALLOC_H
res = f_read(&fsrc, p, 4096, &br);
/* 将读取到的数据写入FLASH */
FLASH_WriteData(p, wordAddr, br);
wordAddr += br; //写入地址增加
#else
res = f_read(&fsrc, buffer, sizeof(buffer), &br);
/* 将读取到的数据写入FLASH */
FLASH_WriteData(buffer, wordAddr, br);
wordAddr += br; //写入地址增加
#endif
j += br;
i = j * 100 / 1456;
GUI_Box(0, 80, i, 90, RED);
if (res || br == 0)
{
break; // error or eof
}
}
}
f_close(&fsrc); //不论是打开,还是新建文件,一定记得关闭
}
/* 更新12号汉字库 */
if((updateState & GUI_UPDATE_12CHAR) == GUI_UPDATE_12CHAR)
{
wordAddr = GUI_FLASH_12CHAR_ADDR;
j = 0;
res = f_open(&fsrc, GUI_12CHAR_FILE, FA_READ);
if(res == FR_OK)
{
for (;;)
{
#ifdef __MALLOC_H
res = f_read(&fsrc, p, 4096, &br);
/* 将读取到的数据写入FLASH */
FLASH_WriteData(p, wordAddr, br);
wordAddr += br; //写入地址增加
#else
res = f_read(&fsrc, buffer, sizeof(buffer), &br);
FLASH_WriteData(buffer, wordAddr, br);
wordAddr += br;
#endif
j += br;
i = j * 100 / 766080;
GUI_Box(0, 95, i, 105, RED);
if (res || br == 0)
{
break; // error or eof
}
}
}
f_close(&fsrc); //不论是打开,还是新建文件,一定记得关闭
}
/* 更新16号汉字库 */
if((updateState & GUI_UPDATE_16CHAR) == GUI_UPDATE_16CHAR)
{
wordAddr = GUI_FLASH_16CHAR_ADDR;
j = 0;
res = f_open(&fsrc, GUI_16CHAR_FILE, FA_READ);
if(res == FR_OK)
{
for (;;)
{
#ifdef __MALLOC_H
res = f_read(&fsrc, p, 4096, &br);
/* 将读取到的数据写入FLASH */
FLASH_WriteData(p, wordAddr, br);
wordAddr += br; //写入地址增加
#else
res = f_read(&fsrc, buffer, sizeof(buffer), &br);
FLASH_WriteData(buffer, wordAddr, br);
wordAddr += br;
#endif
j += br;
i = j * 100 / 1508220;
GUI_Box(0, 110, i, 120, RED);
if (res || br == 0)
{
break; // error or eof
}
}
}
f_close(&fsrc); //不论是打开,还是新建文件,一定记得关闭
}
#ifdef __MALLOC_H
free(p);
#endif
}
#endif |