#include "gui.h"
#ifdef USE_FONT_UPDATE
#include "ff.h"
#include "diskio.h"
#endif
#ifdef USE_FLASH_CHAR
#include "flash.h"
#else
#include "asciicode.h"
#endif
#ifdef USE_FONT_UPDATE
#include "malloc.h"
#endif
/****************************************************************************
* Function Name : GUI_Dot
* Description : ÔÚ²ÊÆÁÉÏÃæ»Ò»µã
* Input : x£ºµãµÄX×ø±ê
* * y£ºµãµÄY×ø±ê
* * color£ºµãµÄÑÕÉ«
* Output : None
* Return : None
****************************************************************************/
void GUI_Dot(uint16_t x, uint16_t y, uint16_t color)
{
TFT_SetWindow(x, y, x, y); //ÉèÖõãµÄλÖÃ
TFT_WriteData(color); //»µã
}
/****************************************************************************
* Function Name : GUI_Box
* Description : ¸øÒ»¸öÇøÓòÍ¿ÉÏÑÕÉ«
* Input : sx£ºÆðʼX×ø±ê, sy£ºÆäʵY×ø±ê,
* * ex£ºÖÕÖ¹X×ø±ê, ey£ºÖÕÖ¹Y×ø±ê,
* * color£º·½¿òµÄÑÕÉ«
* Output : None
* Return : None
****************************************************************************/
void GUI_Box(uint16_t xState, uint16_t yState, uint16_t xEnd, uint16_t yEnd, uint16_t color)
{
uint16_t temp;
if((xState > xEnd) || (yState > yEnd))
{
return;
}
TFT_SetWindow(xState, yState, xEnd, yEnd);
xState = xEnd - xState + 1;
yState = yEnd - yState + 1;
while(xState--)
{
temp = yState;
while (temp--)
{
TFT_WriteData(color);
}
}
}
/****************************************************************************
* Function Name : GUI_DrowSign
* Description : »Ò»¸öÊ®×ֵıê¼Ç
* Input : x£º±ê¼ÇµÄX×ø±ê£»
* * y£º±ê¼ÇµÄY×ø±ê
* * color£º±ê¼ÇµÄÑÕÉ«
* Output : None
* Return : None
****************************************************************************/
void GUI_DrowSign(uint16_t x, uint16_t y, uint16_t color)
{
uint8_t i;
/* »µã */
TFT_SetWindow(x-1, y-1, x+1, y+1);
for(i=0; i<9; i++)
{
TFT_WriteData(color);
}
/* »Êú */
TFT_SetWindow(x-4, y, x+4, y);
for(i=0; i<9; i++)
{
TFT_WriteData(color);
}
/* »ºá */
TFT_SetWindow(x, y-4, x, y+4);
for(i=0; i<9; i++)
{
TFT_WriteData(color);
}
}
#ifndef USE_FLASH_CHAR
/****************************************************************************
* Function Name : GUI_Show12ASCII
* Description : д12ºÅASCIIÂë
* Input : x£ºÆðʼX×ø±ê
* * y£ºÆðʼY×ø±ê
* * p£º×Ö·û´®Ê×µØÖ·
* * wordColor£º×ÖÌåÑÕÉ«
* * backColor£º±³¾°ÑÕÉ«
* Output : None
* Return : None
****************************************************************************/
void GUI_Show12ASCII(uint16_t x, uint16_t y, uint8_t *p,
uint16_t wordColor, uint16_t backColor)
{
uint8_t i, wordByte, wordNum;
uint16_t color;
while(*p != '\0') //¼ì²âÊÇ·ñÊÇ×îºÃÒ»¸ö×Ö
{
/* ÔÚ×Ö¿âÖеÄASCIIÂëÊÇ´Ó¿Õ¸ñ¿ªÊ¼µÄÒ²¾ÍÊÇ32¿ªÊ¼µÄ£¬ËùÒÔ¼õÈ¥32 */
wordNum = *p - 32;
TFT_SetWindow(x, y, x+7, y+15); //×Ö¿í*¸ßΪ£º8*16
for (wordByte=0; wordByte<16; wordByte++) //ÿ¸ö×ÖÄ£Ò»¹²ÓÐ16¸ö×Ö½Ú
{
color = ASCII8x16[wordNum][wordByte];
for (i=0; i<8; i++)
{
if ((color&0x80) == 0x80)
{
TFT_WriteData(wordColor);
}
else
{
TFT_WriteData(backColor);
}
color <<= 1;
}
}
p++; //Ö¸ÕëÖ¸ÏòÏÂÒ»¸ö×Ö
/* ÆÁÄ»×ø±ê´¦Àí */
x += 8;
if(x > 233) //TFT_XMAX -8
{
x = 0;
y += 16;
}
}
}
#else
/****************************************************************************
* Function Name : GUI_Show12Char
* Description : ͨ¹ýFLASH×Ö¿âÏÔʾ12ºÅ×ÖĸºÍºº×Ö£¨Ê¹ÓÃGBK£©
* Input : x£ºÆðʼX×ø±ê
* * y£ºÆðʼY×ø±ê
* * ch£º×Ö·û´®Ê×µØÖ·
* * wordColor£º×ÖÌåÑÕÉ«
* * backColor£º±³¾°ÑÕÉ«
* Output : None
* Return : None
****************************************************************************/
void GUI_Show12Char(uint16_t x, uint16_t y, uint8_t *ch,
uint16_t wordColor, uint16_t backColor)
{
uint8_t i, j, color, buf[32];
uint16_t asc;
uint32_t wordAddr = 0;
while(*ch != '\0')
{
/*ÏÔʾ×Öĸ£¬ASCII±àÂë */
if(*ch < 0x80) //ASCIIÂë´Ó0~127
{
/* ÔÚ×Ö¿âÖеÄASCIIÂëÊÇ´Ó¿Õ¸ñ¿ªÊ¼µÄÒ²¾ÍÊÇ32¿ªÊ¼µÄ£¬ËùÒÔ¼õÈ¥32 */
wordAddr = *ch - 32;
wordAddr *= 16;
wordAddr += GUI_FLASH_ASCII_ADDR;
/* ¶ÁÈ¡FLASHÖиÃ×ÖµÄ×ÖÄ£ */
FLASH_ReadData(buf, wordAddr, 16);
/* ÏÔʾ¸ÃÎÄ×Ö */
TFT_SetWindow(x, y, x+7, y+15); //×Ö¿í*¸ßΪ£º8*16
for (j=0; j<16; j++) //ÿ¸ö×ÖÄ£Ò»¹²ÓÐ16¸ö×Ö½Ú
{
color = buf[j];
for (i=0; i<8; i++)
{
if ((color&0x80) == 0x80)
{
TFT_WriteData(wordColor);
}
else
{
TFT_WriteData(backColor);
}
color <<= 1;
}
}
ch++; //Ö¸ÕëÖ¸ÏòÏÂÒ»¸ö×Ö
/* ÆÁÄ»×ø±ê´¦Àí */
x += 8;
if(x > 233) //TFT_XMAX -8
{
x = 0;
y += 16;
}
}
/* ÏÔʾºº×Ö£¬GBK±àÂë */
else
{
/* ½«ºº×Ö±àÂëת»»³ÉÔÚFLASHÖеĵØÖ· */
asc = *ch - 0x81; //¸ß×Ö½ÚÊDZíʾ·ÖÇø£¬·ÖÇøÊÇ´Ó0x81µ½0xFE,ËùÒÔת»»³ÉµØÖ·-0x80
wordAddr = asc * 190; //ÿ¸ö·ÖÇøÒ»¹²ÓÐ190¸ö×Ö
asc = *(ch + 1); //µÍ×Ö½Ú´ú±íÿ¸ö×ÖÔÚÿ¸ö·ÖÇøµÄλÖã¬ËüÊÇ´Ó0x40µ½0xFF
if(asc < 0x7F) //ÔÚ0x7FλÖÃÓиö¿Õ룬µ«ÊÇÎÒÃÇÈ¡Ä£²»Áô¿Õ£¬ËùÒÔ´óÓÚ0x7FÖ®ºó¶à¼õÒ»
{
asc -= 0x40;
}
else
{
asc -= 0x41;
}
wordAddr += asc; //Çó³öÔÚGBKÖÐÊǵڼ¸¸ö×Ö
wordAddr *= 32; //½«×ÖλÖÃת»»Î»FLASHµØÖ·
wordAddr += GUI_FLASH_12CHAR_ADDR; //¼ÓÉÏÊ×µØÖ·
/* ¶ÁÈ¡FLASHÖиÃ×ÖµÄ×ÖÄ£ */
FLASH_ReadData(buf, wordAddr, 32);
/* ÔÚ²ÊÆÁÉÏÃæÏÔʾ */
TFT_SetWindow(x, y, x+15, y+15);
for(i=0; i<32; i++)
{
color = buf[i];
for(j=0; j<8; j++)
{
if((color & 0x80) == 0x80)
{
TFT_WriteData(wordColor);
}
else
{
TFT_WriteData(backColor);
}
color <<= 1;
}//for(j=0;j<8;j++)½áÊø
}
/* ÆÁÄ»×ø±ê´¦Àí */
x += 16;
if(x > 225) //TFT_XMAX -15
{
x = 0;
y += 16;
}
/* дÏÂÒ»¸ö×Ö£¬Ã¿¸öºº×ÖÕ¼Á½¸ö×Ö½ÚËùÒÔ+2 */
ch += 2;
}
}
}
/****************************************************************************
* Function Name : GUI_Show12Chinese
* Description : ͨ¹ýFLASH×Ö¿âÏÔʾ12ºÅºº×Ö£¨Ê¹ÓÃGBK£©
* Input : x£ºÆðʼX×ø±ê
* * y£ºÆðʼY×ø±ê
* * cn£º×Ö·û´®Ê×µØÖ·
* * wordColor£º×ÖÌåÑÕÉ«
* * backColor£º±³¾°ÑÕÉ«
* Output : None
* Return : None
****************************************************************************/
void GUI_Show16Chinese(uint16_t x, uint16_t y, uint8_t *cn,
uint16_t wordColor, uint16_t backColor)
{
uint8_t i, j, color, buf[63];
uint16_t asc;
uint32_t wordAddr = 0;
while(*cn != '\0')
{
/* ½«ºº×Ö±àÂëת»»³ÉÔÚFLASHÖеĵØÖ· */
asc = *cn - 0x81; //¸ß×Ö½ÚÊDZíʾ·ÖÇø£¬·ÖÇøÊÇ´Ó0x81µ½0xFE,ËùÒÔת»»³ÉµØÖ·-0x80
wordAddr = asc * 190; //ÿ¸ö·ÖÇøÒ»¹²ÓÐ190¸ö×Ö
asc = *(cn + 1); //µÍ×Ö½Ú´ú±íÿ¸ö×ÖÔÚÿ¸ö·ÖÇøµÄλÖã¬ËüÊÇ´Ó0x40µ½0xFF
if(asc < 0x7F) //ÔÚ0x7FλÖÃÓиö¿Õ룬µ«ÊÇÎÒÃÇÈ¡Ä£²»Áô¿Õ£¬ËùÒÔ´óÓÚ0x7FÖ®ºó¶à¼õÒ»
{
asc -= 0x40;
}
else
{
asc -= 0x41;
}
wordAddr += asc; //Çó³öÔÚGBKÖÐÊǵڼ¸¸ö×Ö
wordAddr *= 63; //½«×ÖλÖÃת»»Î»FLASHµØÖ·
wordAddr += GUI_FLASH_16CHAR_ADDR; //¼ÓÉÏÊ×µØÖ·
/* ¶ÁÈ¡FLASHÖиÃ×ÖµÄ×ÖÄ£ */
FLASH_ReadData(buf, wordAddr, 63);
/* ÔÚ²ÊÆÁÉÏÃæÏÔʾ */
TFT_SetWindow(x, y, x+23, y+20);
for(i=0; i<63; i++)
{
color = buf[i];
for(j=0; j<8; j++)
{
if((color & 0x80) == 0x80)
{
TFT_WriteData(wordColor);
}
else
{
TFT_WriteData(backColor);
}
color <<= 1;
}//for(j=0;j<8;j++)½áÊø
}
/* ÆÁÄ»×ø±ê´¦Àí */
x += 21;
if(x > 218) //TFT_XMAX -21
{
x = 0;
y += 21;
}
/* дÏÂÒ»¸ö×Ö£¬Ã¿¸öºº×ÖÕ¼Á½¸ö×Ö½ÚËùÒÔ+2 */
cn += 2;
}
}
#endif
#ifdef USE_FONT_UPDATE
/****************************************************************************
* Function Name : GUI_FontUpdate
* Description : ¸üÐÂ×Ö¿â
* Input : updateState£ºÑ¡Ôñ¸üеÄ×Ö¿â
* Output : None
* Return : None
****************************************************************************/
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
这里用到的#ifdef USE_FONT_UPDATE
#include "ff.h"
#include "diskio.h"
#endif
#ifdef USE_FLASH_CHAR
#include "flash.h"
#else
#include "asciicode.h"
#endif
#ifdef USE_FONT_UPDATE
#include "malloc.h"
#endif
有什么作用
|
|