|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2022-1-15 23:42:09
|
显示全部楼层
晚上趁散步时间想了一下,以及搜索了一下,决定放弃TFT-eSPI库.改为使用GFX库,GFX已经包含HX8347的驱动.库地址:[url]https://github.com/adafruit/Adafruit-GFX-Library[/url]
但是仍不能直接用.如果直接用,在目前的TFT上显示为左右镜像.因此仍需修改GFX库中HX8347的相关函数.
经查看HX8347规格数,0X36寄存器用于设定Source和Gate的扫描方向,改Source driver的扫描方向后,左右镜像问题已解决.因此GFX库的HX8347的setRotation函数需重新写.
查看GFX的说明,使用canvas可以避免刷新局部显示内容时的闪烁问题,但是会需要更多的RAM空间,类似TFT-eSPI的"Sprites"
以下是测试用的代码:
#include <Arduino_GFX_Library.h>
#include <font/FreeSans24pt7b.h>
#define font_w 44
#define font_h 44
/* More dev device declaration: https://github.com/moononournati ... -Device-Declaration */
#if defined(DISPLAY_DEV_KIT)
Arduino_GFX *gfx = create_default_Arduino_GFX();
#else /* !defined(DISPLAY_DEV_KIT) */
/* More data bus class: https://github.com/moononournati ... wiki/Data-Bus-Class */
Arduino_DataBus *bus = create_default_Arduino_DataBus();
/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_HX8347D(bus, TFT_RST, 0 /* rotation */, false /* IPS */);
Arduino_GFX *canvas = new Arduino_Canvas(150,font_h*5,gfx);
#endif /* !defined(DISPLAY_DEV_KIT) */
/*******************************************************************************
End of Arduino_GFX setting
******************************************************************************/
void display_ini() {
gfx->begin();
canvas->begin();
gfx->setRotation(3); //设置显示发现
gfx->fillScreen(BLACK); //清屏
#ifdef TFT_BL
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
#endif
//以下测试显示是否正常
gfx->fillScreen(BLACK); //清屏
gfx->setFont(&FreeSans24pt7b);
//gfx->setTextSize(1);
gfx->setTextColor(GREEN);
gfx->setCursor(0, font_h * 1);
gfx->print("GFX Test...");
//gfx->setTextSize(2);
gfx->setTextColor(RED);
gfx->setCursor(0, font_h * 2);
gfx->print("GFX Test...");
//gfx->setTextSize(3);
gfx->setTextColor(WHITE);
gfx->setCursor(0, font_h * 3);
gfx->print("GFX Test...");
//gfx->setTextSize(4);
gfx->setTextColor(YELLOW);
gfx->setCursor(0, font_h * 4);
gfx->print("GFX Test...");
gfx->setTextColor(ORANGE);
gfx->setCursor(0, font_h * 5);
gfx->print("GFX Test...");
delay(500);
gfx->fillScreen(BLACK); //清屏
//以下绘制显示的单位
gfx->setFont(&FreeSans24pt7b);
gfx->setCursor(150,font_h);
gfx->setTextColor(GREEN);
gfx->print("V");
gfx->setTextColor(RED);
gfx->setCursor(150,font_h*2);
gfx->print("A");
gfx->setTextColor(WHITE);
gfx->setCursor(150,font_h*3);
gfx->print("W");
gfx->setTextColor(ORANGE);
gfx->setCursor(150,font_h*4);
gfx->print("Ah");
}
void display_INA219() {
//以下用canvas的方式绘制数值,避免闪烁
canvas->fillRect(0,0,150,font_h*5,BLACK);
canvas->setFont(&FreeSans24pt7b);
canvas->setTextColor(GREEN);
canvas->setCursor(0,font_h*1);
canvas->print(batvoltage,3);
canvas->setTextColor(RED);
canvas->setCursor(0,font_h*2);
canvas->print(current_A,3);
canvas->setTextColor(WHITE);
canvas->setCursor(0,font_h*3);
canvas->print(power,3);
canvas->setTextColor(ORANGE);
canvas->setCursor(0,font_h*4);
canvas->print(Ah,3);
canvas->flush();
}
以下是显示效果,电流电压数值的刷新TFT毫无闪烁.
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|