想试试看官方用的xbf字体外置在sd卡内,结果发现移植官方的教程后程序不断的重启
#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);
}
这个是我的xbf代码就是最后GUI_DispStringAt("Hello world!", 160, 80);就重启程序了,有人知道是为什么么? |