跟着大家的教程移植完emwin以后,对官方的xbf字库又有点兴趣,感觉官方的功能很全很方便,但是根据例程改编的时候碰到了麻烦
#include "GUI.h"
#include "ff.h"
GUI_FONT XBFFont;
GUI_XBF_DATA XBF_Data;
static int _cbGetData(U32 Off, U16 NumBytes, void * pVoid, void * pBuffer) {
DWORD NumBytesRead;
FIL hFile;
FIL fsrc; // ?¨????????×÷?à
FRESULT res; // ?¨????×÷?á??±???
UINT br;
char string[30];
hFile = *(FIL *)pVoid;
/* Set file pointer to the requested position */
res = f_open(&fsrc, "0:/sys/Font18.xbf", FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) {
return 1; /* Error */
}
res = f_lseek(&fsrc,Off); //?????×???·
if (res != FR_OK) {
return 1; /* Error */
}
res=f_read(&fsrc,string,NumBytes,&br);
// pBuffer=string;
// res=f_read(&fsrc,pBuffer,NumBytes,&br);
// pBuffer=&string;
if (res != FR_OK) {
return 1; /* Error */
}
res = f_lseek(&fsrc,Off); //?????×???·
if (res != FR_OK) {
return 1; /* Error */
}
res=f_read(&fsrc,pBuffer,NumBytes,&br);
// pBuffer=string;
// res=f_read(&fsrc,pBuffer,NumBytes,&br);
// pBuffer=&string;
if (res != FR_OK) {
return 1; /* Error */
}
// /* Read font data */
// if (!ReadFile(hFile, pBuffer, NumBytes, &NumBytesRead, 0)) {
// return 1; /* Error */
// }
if (br != NumBytes) {
return 1; /* Error */
}
return 0; /* Ok */
}
void readFontfromXBFSD(void){
FIL fsrc; // ?¨????????×÷?à
FRESULT res; // ?¨????×÷?á??±???
res = f_open(&fsrc, "0:/sys/Font18.xbf", FA_OPEN_EXISTING | FA_READ);
GUI_XBF_CreateFont(&XBFFont, /* Pointer to GUI_FONT structure in RAM */
&XBF_Data, /* Pointer to GUI_XBF_DATA structure in RAM */
GUI_XBF_TYPE_PROP, /* Font type to be created */
_cbGetData, /* Pointer to callback function */
&fsrc); /* Pointer to be passed to GetData function */
// res = f_close(&fsrc); //??±?×???
// GUI_SetFont(&XBFFont);
GUI_DispStringAt("Hello world!", 160, 80);
}
这是我的代码,程序跑到GUI_DispStringAT的时候,跑了2遍_cbGetData然后竟然开始从头跑程序,然后又开始跑到readFontfromXBFSD函数,继续循环 不是很明白为什么会开始重新跑程序,希望有人能帮一下
|