pdf-icon

Arduino 上手教程

2. 设备开发 & 案例程序

M5GFX API

M5GFX Functions

按字母检索

a-d e-h i-r s-z
begin effect init scroll
beginTransaction endTransaction initDMA setAddrWindow
calibrateTouch endTransactionWait invertDisplay setAutoDisplay
clear endWrite isBusShared setBaseColor
clearClipRect fillAffine isEPD setBrightness
clearDisplay fillArc isReadable setClipRect
clearScrollRect fillCircle isSPIShared setColor
color8to16 fillEllipse loadFont setColorDepth
color16to24 fillEllipseArc paint setCursor
color16to8 fillRect panel setEpdMode
color24to16 fillRoundRect popState setFont
color332 fillScreen powerSave setPivot
color565 fillTriangle powerSaveOff setRawColor
color888 floodFill powerSaveOn setResolution
convertRawXY fontHeight print setRotation
copyRect fontWidth printf setScrollRect
createPng getAttribute println setSwapBytes
display getBaseColor progressBar setTextColor
displayBusy getBoard pushBlock setTextDatum
dmaBusy getBrightness pushImage setTextScroll
drawArc getClipRect pushImageAffine setTextSize
drawBezier getColorDepth pushImageAffineWithAA setTextStyle
drawBmp getCursorX pushPixels setTextWrap
drawBmpFile getCursorY pushPixelsDMA setTouchCalibrate
drawBmpUrl getEpdMode pushState setWindow
drawCenterString getPaletteCount qrcode showFont
drawChar getFont readData16 sleep
drawCircle getInstance readData32 startWrite
drawEllipse getInvert readData8 swap565
drawEllipseArc getPalette readPixel swap888
drawFastHLine getPanel readPixelRGB textLength
drawFastVLine getPivotX readRect textWidth
drawFloat getPivotY readRectRGB touch
drawGradientHLine getRawColor unloadFont
drawGradientLine getRotation waitDisplay
drawGradientVLine getScrollRect waitDMA
drawJpg getStartCount wakeup
drawJpgFile getSwapBytes width
drawJpgUrl getTextDatum writeColor
drawLine getTextPadding writeCommand16
drawNumber getTextSizeX writeData16
drawPng getTextSizeY writeData32
drawPngFile getTextStyle writeData
drawPngUrl getTouch writeFastHLine
drawQoi getTouchRaw writeFastVLine
drawQoiFile hasPalette writeFillRect
drawQoiUrl height writeIndexedPixels
drawString writePixel
drawTriangle writePixels
writePixelsDMA

a - e

begin

函数原型:

void begin(void)

功能说明:

  • 初始化函数

传入参数:

  • null

返回值:

  • null

beginTransaction

函数原型:

void beginTransaction(void)

功能说明

  • 初始化面板事务,虚函数可被重写。

传入参数:

  • null

返回值:

  • null

calibrateTouch

函数原型:

void calibrateTouch<T>(uint16_t* parameters, const T &color_fg, const T &color_bg, uint8_t size = 10)

功能说明

  • 校准触摸板,传递一个指针给第一个参数,以获得一个校准值,你可以将这个值记录在 flash 中等等,并在下次启动时使用setTouchCalibrate来省略手工校准。

传入参数:

  • parameters:校准值
  • color_fg:前景色
  • color_bg:背景色
  • size:触摸点大小

返回值:

  • null

clear

函数原型:

void clear(const T &color)

功能说明

  • 清空显示,如果指定了一个颜色,就用该颜色初始化屏幕,效果与 clearDisplayfillScreen 相同。

传入参数:

  • color:清屏颜色

*关于颜色编码

返回值:

  • null

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <Arduino.h>
#include <M5GFX.h>
M5GFX display;

void setup() {
  display.begin();
  display.clear(RED);
  //clearDisplay(RED);
  //fillScreen(RED);
}

void loop() {
}

clearClipRect

函数原型:

void clearClipRect(void)

功能说明:

传入参数:

  • null

返回值:

  • null

clearDisplay

函数原型:

void clearDisplay(uint32_t color = 0)

功能说明:

  • 清空显示,如果指定了一个颜色,就用该颜色初始化屏幕,否则使用默认颜色。效果与fillScreenclear相同。

传入参数:

  • color:清屏颜色

*关于颜色编码

返回值:

  • null

clearScrollRect

函数原型:

void clearScrollRect(void)

功能说明:

传入参数:

  • null

返回值:

  • null

color8to16

函数原型:

uint16_t color8to16(uint8_t rgb332)

功能说明:

  • 转变 RGB322 颜色编码(8 bit)为 RGB565 颜色编码(16 bit)

传入参数:

  • rgb332:RGB322 颜色编码

返回值:

  • uint16_t:RGB565 颜色编码

color16to24

函数原型:

uint32_t color16to24(uint16_t rgb565)

功能说明:

  • 转变 RGB565 颜色编码(16 bit)为 RGB888 颜色编码(24 bit)

传入参数:

  • rgb565:RGB565 颜色编码

返回值:

  • uint32_t:RGB888 颜色编码

color16to8

函数原型:

uint8_t color16to8(uint16_t rgb565)

功能说明:

  • 转变 RGB565 颜色编码(16 bit)为 RGB322 颜色编码(8 bit)

传入参数:

  • rgb565:RGB565 颜色编码

返回值:

  • uint8_t:RGB322 颜色编码

color24to16

函数原型:

uint16_t color24to16(uint32_t rgb888)

功能说明:

  • 转变 RGB888 颜色编码(24 bit)为 RGB565 颜色编码(16 bit)

传入参数:

  • rgb888:RGB888 颜色编码

返回值:

  • uint16_t:RGB565 颜色编码

color332

函数原型:

uint8_t color332(uint8_t r, uint8_t g, uint8_t b)

功能说明:

  • 根据 R,G,B 分量生成颜色编码

传入参数:

  • r: 红色分量,0-255
  • g: 绿色分量,0-255
  • b: 蓝色分量,0-255

返回值:

  • uint8_t:RGB322 颜色编码

color565

函数原型:

uint16_t color565(uint8_t r, uint8_t g, uint8_t b)

功能说明:

  • 根据 R,G,B 分量生成颜色编码

传入参数:

  • r: 红色分量,0-255
  • g: 绿色分量,0-255
  • b: 蓝色分量,0-255

返回值:

  • uint16_t:RGB565 颜色编码

color888

函数原型:

uint32_t color888(uint8_t r, uint8_t g, uint8_t b)

功能说明:

  • 根据 R,G,B 分量生成颜色编码

传入参数:

  • r: 红色分量,0-255
  • g: 绿色分量,0-255
  • b: 蓝色分量,0-255

convertRawXY

函数原型:

void convertRawXY(touch_point_t *tp, uint_fast8_t count = 1)

功能说明:

传入参数:

  • tp:触摸点结构体指针
  • count:触摸点个数,默认为1个

*关于touch_point_t

返回值:

  • null

copyRect

函数原型:

void copyRect(uint32_t dst_x, uint32_t dst_y, uint32_t w, uint32_t h, uint32_t src_x, uint32_t src_y)

功能说明:

  • 拷贝矩形范围

传入参数:

  • dst_x:拷贝目的地 x 坐标
  • dst_y:拷贝目的地 y 坐标
  • w:矩形宽度
  • h:矩形高度
  • src_x:拷贝目标 x 坐标
  • src_y:拷贝目标 y 坐标

返回值:

  • null

createPng

函数原型:

void* createPng( size_t* datalen, int32_t x = 0, int32_t y = 0, int32_t width = 0, int32_t height = 0)

功能说明:

  • 截屏功能,会将面板中显示的数据以PNG格式保存到设备内存中。
注意事项:
能够存储的图像大小取决于内存容量。例如,如果禁用了 PSRAM 功能,高分辨率高色深的图像将无法被保存。

传入参数:

  • datalen:图像数据长度
  • x:截图起始点 x 坐标
  • y:截图起始点 y 坐标
  • w:截图宽度
  • h:截图高度

返回值:

  • void*:
    • 截屏成功时:指向 PNG 图像数据的内存区域的指针
    • 截屏失败时:nullptr

display

函数原型:

void display(void)

功能说明:

  • 显示到面板(液晶、电子纸屏等)

传入参数:

  • null

返回值:

  • null

displayBusy

函数原型:

bool displayBusy(void)

功能说明:

  • 检测面板是否繁忙

传入参数:

  • null

返回值:

  • bool:
    • true:面板繁忙
    • false:面板不繁忙

dmaBusy

函数原型:

bool dmaBusy(void)

功能说明:

  • 检测DMA控制器是否繁忙

传入参数:

  • null

返回值:

  • bool
    • true:DMA控制器繁忙
    • false:DMA控制器空闲

drawArc

函数原型1:

void drawArc(int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1)

函数原型2:

void drawArc(int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1, const T &color)

功能说明:

  • 绘制圆弧,r0、r1不同将绘制粗圆弧。

传入参数:

  • x:圆弧中心点 x 坐标
  • y:圆弧中心点 y 坐标
  • r0:内圆半径
  • r1:外圆半径
  • angle0:圆弧起始角度
  • angle1:圆弧终点角度
  • color:圆弧颜色

返回值:

  • null

*关于颜色编码

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <Arduino.h>
#include <M5GFX.h>
M5GFX display;

void setup() {
  display.begin();
  uint16_t x = display.width() / 2;
  uint16_t y = display.height() / 2;
  display.drawArc(x, y, 10, 20, 20, 240, TFT_WHITE);
}

void loop() {
}

drawBezier

函数原型1:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color)

函数原型2:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2)

函数原型3:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, const T& color)

函数原型4:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, const T& color)

功能说明:

  • 绘制贝塞尔曲线,有两种类型可供选择:3 点型和 4 点型。

传入参数:

  • xN: 绘制点 x 坐标
  • yN:绘制点 y 坐标
  • color:曲线颜色

返回值:

  • null

*关于颜色编码

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <Arduino.h>
#include <M5GFX.h>
M5GFX display;

void setup() {
  display.begin();
  uint16_t x = display.width() / 2;
  uint16_t y = display.height() / 2;
  display.drawBezier(0, 0, x, 0, x, y, TFT_WHITE);
  display.drawBezier(0, 0, x, 0, x, y, 0, y, TFT_WHITE);
}

void loop() {
}

drawBmp

函数原型1:

void drawBmp(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

函数原型2:

void drawBmp(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

功能说明:

  • 绘制/显示 BMP 图像

传入参数:

  • data
    • const uint8_t:原始常量数据指针
    • DataWrapper:包装数据对象指针
  • len:数据长度
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

*关于datum_t

返回值:

  • null

drawBmpFile

函数原型1:

void drawBmpFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

函数原型3:

void drawBmpFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

函数原型2:

void drawBmpFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

功能说明:

  • 从 BMP 文件绘制/显示 BMP 图像

传入参数:

  • fs:文件系统对象
    • SPIFFS
    • SD
      etc
  • path:BMP 文件路径
  • file:DataWrapper 结构体指针
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

*关于DataWrapper
*关于datum_t

返回值:

  • null

drawBmpUrl

函数原型:

bool drawBmpUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 
bool drawBmpUrl(String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

功能说明:

  • 从链接绘制/显示 BMP 图像
注意事项:
要使用此功能,需在包含 <M5GFX.h> 之前写入 #include <HTTPClient.h>

传入参数:

  • url:图像链接
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

返回值:

  • bool
    • true:绘制/显示成功
    • false:绘制/显示失败

drawCenterString or drawCentreString

函数原型1:

void drawCenterString(const char *string, int32_t x, int32_t y, const IFont* font)

函数原型2:

void drawCenterString(const char *string, int32_t x, int32_t y)

功能说明:

  • 在中心位置书写文本

传入参数:

  • string:文本字符串
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • font:字体格式

*关于Font

返回值:

  • null

drawChar

函数原型1:

size_t drawChar(int32_t x, int32_t y, uint16_t uniCode, T color, T bg, float size_x, float size_y)

函数原型2:

size_t drawChar(int32_t x, int32_t y, uint16_t uniCode, T color, T bg, float size)

函数原型3:

size_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font)

函数原型4:

size_t drawChar(uint16_t uniCode, int32_t x, int32_t y)

功能说明:

  • 绘制单个字符

传入参数:

  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • uniCode:字符 UniCode 编码
  • color:字符颜色
  • bg:字符背景颜色
  • size(_N):文本缩放比例
  • font:文本字体格式

返回值:

  • size_t:
    • 字符在 x 方向占用的总像素宽度

drawCircle

函数原型1:

void drawCircle( int32_t x, int32_t y, int32_t r)

函数原型2:

void drawCircle( int32_t x, int32_t y, int32_t r, const T& color)

功能说明:

  • 绘制圆

传入参数:

  • x:圆心 x 坐标
  • y:圆心 y 坐标
  • r:圆半径
  • color:圆颜色

返回值:

  • null

*关于颜色编码

drawEllipse

函数原型1:

void drawEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry)

函数原型2:

void drawEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry, const T& color)

功能说明:

  • 绘制椭圆

传入参数:

drawGradientVLine

  • x:绘制圆心 x 坐标
  • y:绘制圆心 y 坐标
  • rx:椭圆长半轴
  • ry:椭圆短半轴
  • color:椭圆颜色

返回值:

  • null

drawEllipseArc

函数原型1:

void drawEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1)

函数原型2:

void drawEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1, const T& color)

功能说明:

  • 绘制椭圆弧,r0、r1不同将绘制粗椭圆弧。

传入参数:

  • x:椭圆弧中心 x 坐标
  • y:椭圆弧中心 y 坐标
  • r0x:内椭圆 x 半径
  • r1x:内椭圆 y 半径
  • r0y:外椭圆 x 半径
  • r1y:外椭圆 y 半径
  • angle0:起始角度
  • angle1:结束角度
  • color:椭圆弧颜色

返回值:

  • null

drawFastHLine

函数原型1:

void drawFastHLine( int32_t x, int32_t y, int32_t w)

函数原型2:

void drawFastHLine( int32_t x, int32_t y, int32_t w, const T& color)

功能说明:

  • 绘制水平线

传入参数:

  • x:起点 x 坐标
  • y:起点 y 坐标
  • w:线长度
  • color:线颜色

返回值:

  • null

drawFastVLine

函数原型1:

void drawFastVLine( int32_t x, int32_t y, int32_t w)

函数原型2:

void drawFastVLine( int32_t x, int32_t y, int32_t w, const T& color)

功能说明:

  • 绘制垂直线

传入参数:

  • x:起点 x 坐标
  • y:起点 y 坐标
  • w:线长度
  • color:线颜色

返回值:

  • null

drawFloat

函数原型1:

size_t drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY)

函数原型2:

size_t drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY, uint8_t font)

功能说明:

  • 绘制浮点数

传入参数:

  • floatNumber:浮点数
  • dp:小数点后位数
  • poX:起点 x 坐标
  • poY:起点 y 坐标
  • font:文本字体格式

返回值:

  • size_t:字符串绘制的总水平像素宽度

drawGradientHLine

函数原型:

void drawGradientHLine( int32_t x, int32_t y, int32_t w, const T& colorstart, const T& colorend) 

功能说明:

  • 绘制水平渐变线

传入参数:

  • x:起点 x 坐标
  • y:起点 y 坐标
  • w:线宽度
  • colorstart:起始颜色
  • colorend:结束颜色

返回值:

  • null

drawGradientLine

函数原型:

void drawGradientLine ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, const T& colorstart, const T& colorend )

功能说明:

  • 绘制由两点确定的渐变线

传入参数:

  • x0:起点 x 坐标
  • y0:起点 y 坐标
  • x1:终点 x 坐标
  • y1:终点 y 坐标
  • colorstart:起始颜色
  • colorend:结束颜色

返回值:

  • null

drawGradientVLine

函数原型:

void drawGradientVLine( int32_t x, int32_t y, int32_t h, const T& colorstart, const T& colorend) 

功能说明:

  • 绘制垂直渐变线

传入参数:

  • x:起点 x 坐标
  • y:起点 y 坐标
  • h:线高度
  • colorstart:起始颜色
  • colorend:结束颜色

返回值:

  • null

drawJpg

函数原型1:

void drawJpg(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

函数原型2:

void drawJpg(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

功能说明:

  • 绘制/显示 JPG 图像

传入参数:

  • data
    • const uint8_t:原始常量数据指针
    • DataWrapper:包装数据对象指针
  • len:数据长度
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

*关于datum_t

返回值:

  • null

drawJpgFile

函数原型1:

void drawJpgFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

函数原型3:

void drawJpgFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

函数原型2:

void drawJpgFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

功能说明:

  • 从 JPG 文件绘制/显示 JPG 图像

传入参数:

  • fs:文件系统对象
    • SPIFFS
    • SD
      etc
  • path:JPG 文件路径
  • file:DataWrapper 结构体指针
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

*关于DataWrapper *关于datum_t

返回值:

  • null

drawJpgUrl

函数原型:

bool drawJpgUrl(const char*/String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

功能说明:

  • 从链接绘制/显示 JPG 图像
注意事项:
要使用此功能,需在包含 <M5GFX.h> 之前写入 #include <HTTPClient.h>

传入参数:

  • url:图像链接
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

返回值:

  • bool
    • true:绘制/显示成功
    • false:绘制/显示失败

drawLine

函数原型1:

void drawLine( int32_t x0, int32_t y0, int32_t x1, int32_t y1)

函数原型2:

void drawLine( int32_t x0, int32_t y0, int32_t x1, int32_t y1, const T& color)

功能说明:

  • 绘制一条直线

传入参数:

  • x0:起点 x 坐标
  • y0:起点 y 坐标
  • x1:终点 x 坐标
  • y1:终点 y 坐标
  • color:线颜色

返回值:

  • null

drawNumber

函数原型1:

size_t drawNumber(long long_num, int32_t poX, int32_t poY)

函数原型2:

size_t drawNumber(long long_num, int32_t poX, int32_t poY, uint8_t font)

功能说明:

  • 绘制一个长整型数字

传入参数:

  • long_num:长整型数字
  • poX:x 坐标
  • poY:y 坐标
  • font:文本字体格式

返回值:

  • size_t:字符串绘制的总水平像素宽度

drawPixel

函数原型1:

void drawPixel( int32_t x, int32_t y)

函数原型2:

void drawPixel( int32_t x, int32_t y, const T& color)

功能说明:

  • 绘制一个像素点

传入参数:

  • x:x 坐标
  • y:y 坐标
  • color:像素颜色

返回值:

  • null

drawPng

函数原型1:

void drawPng(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

函数原型2:

void drawPng(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

功能说明:

  • 绘制/显示 PNG 图像

传入参数:

  • data
    • const uint8_t:原始常量数据指针
    • DataWrapper:包装数据对象指针
  • len:数据长度
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

*关于datum_t

drawPngFile

函数原型1:

void drawPngFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

函数原型3:

void drawPngFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

函数原型2:

void drawPngFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

功能说明:

  • 从 PNG 文件绘制/显示 PNG 图像

传入参数:

  • fs:文件系统对象
    • SPIFFS
    • SD
      etc
  • path:PNG 文件路径
  • file:DataWrapper 结构体指针
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

*关于DataWrapper *关于datum_t

返回值:

  • null

drawPngUrl

函数原型:

bool drawPngUrl(const char*/String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

功能说明:

  • 从链接绘制/显示 PNG 图像
注意事项:
要使用此功能,需在包含 <M5GFX.h> 之前写入 #include <HTTPClient.h>

传入参数:

  • url:图像链接
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

返回值:

  • bool
    • true:绘制/显示成功
    • false:绘制/显示失败

drawQoi

函数原型1:

void drawQoi(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

函数原型2:

void drawQoi(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

功能说明:

  • 绘制/显示 Qoi 图像

传入参数:

  • data
    • const uint8_t:原始常量数据指针
    • DataWrapper:包装数据对象指针
  • len:数据长度
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

*关于datum_t

返回值:

  • null

drawQoiFile

函数原型1:

void drawQoiFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

函数原型3:

void drawQoiFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

函数原型2:

void drawQoiFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

功能说明:

  • 从 Qoi 文件绘制/显示 Qoi 图像

传入参数:

  • fs:文件系统对象
    • SPIFFS
    • SD
      etc
  • path:Qoi 文件路径
  • file:DataWrapper 结构体指针
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

*关于DataWrapper *关于datum_t

返回值:

  • null

drawQoiUrl

函数原型:

bool drawQoiUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 
bool drawQoiUrl(String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

功能说明:

  • 从链接绘制/显示 Qoi 图像
注意事项:
要使用此功能,需在包含 <M5GFX.h> 之前写入 #include <HTTPClient.h>

传入参数:

  • url:图像链接
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • maxWidth:图像最大宽度
  • maxHeight:图像最大高度
  • offX:x 轴偏移量
  • offY:y 轴偏移量
  • scale_x:x 方向缩放比例
  • scale_y:y 方向缩放比例
  • datum:图像对齐方式,默认为左上对齐

返回值:

  • bool
    • true:绘制/显示成功
    • false:绘制/显示失败

drawRect

函数原型1:

void drawRect( int32_t x, int32_t y, int32_t w, int32_t h)

函数原型2:

void drawRect( int32_t x, int32_t y, int32_t w, int32_t h, const T& color)

功能说明:

  • 绘制矩形

传入参数:

  • x:矩形起点 x 坐标
  • y:矩形起点 y 坐标
  • w:矩形宽度
  • h:矩形高度
  • color:矩形颜色

返回值:

  • null

drawRightString

函数原型1:

size_t drawRightString( const char *string, int32_t x, int32_t y)

函数原型2:

size_t drawRightString( const char *string, int32_t x, int32_t y, const IFont* font)

功能说明:

  • 绘制右对齐字符串

传入参数:

  • string:要绘制的字符串
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • font:文本字体格式

返回值:

  • size_t:字符串绘制的总水平像素宽度

drawRoundRect

函数原型1:

void drawRoundRect( int32_t x, int32_t y, int32_t w, int32_t h, int32_t r)

函数原型2:

void drawRoundRect( int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, const T& color)

功能说明:

  • 绘制圆角矩形

传入参数:

  • x:矩形起点 x 坐标
  • y:矩形起点 y 坐标
  • w:矩形宽度
  • h:矩形高度
  • r:圆角半径
  • color:矩形颜色

返回值:

  • null

drawString

函数原型1:

size_t drawString( const char *string, int32_t x, int32_t y)

函数原型2:

size_t drawString( const char *string, int32_t x, int32_t y, const IFont* font)

功能说明:

  • 绘制字符串

传入参数:

  • string:要绘制的字符串
  • x:绘制起点 x 坐标
  • y:绘制起点 y 坐标
  • font:文本字体格式

返回值:

  • size_t:字符串绘制的总水平像素宽度

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <Arduino.h>
#include <M5GFX.h>
M5GFX display;

void setup() {
  display.begin();
  display.setTextDatum(middle_center);
  uint16_t x = display.width() / 2;
  uint16_t y = display.height() / 2;
  display.drawString("Text", x, y);
}

void loop() {
}

drawTriangle

函数原型1:

void drawTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2)

函数原型2:

void drawTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color)

功能说明:

  • 绘制三角形

传入参数:

  • xN:三角形顶点 x 坐标
  • yN:三角形顶点 y 坐标
  • color:三角形颜色

返回值:

  • null

effect

函数原型:

void effect(int32_t x, int32_t y, int32_t w, int32_t h, TFunc&& effector)

功能说明:

  • 使用自定义的变换函数对指定的矩形范围进行效果处理

传入参数:

  • x:矩形起点 x 坐标
  • y:矩形起点 y 坐标
  • w:矩形宽度
  • h:矩形高度
  • effector:变换函数

返回值:

  • null

endTransaction

函数原型:

void endTransaction(void)

功能说明

  • 结束面板事务,虚函数可被重写,与 startTransaction 配套使用。

传入参数:

  • null

返回值:

  • null

endWrite

函数原型:

void endWrite(void)

功能说明

  • 在 SPI 总线上关闭 CS(片选信号),与 startWrite 配套使用。

传入参数:

  • null

返回值:

  • null

f - h

fillAffine

函数原型1:

void fillAffine(const float matrix[6], int32_t w, int32_t h)

函数原型2:

void fillAffine(const float matrix[6], int32_t w, int32_t h, const T& color)

功能说明:

  • 填充仿射变换区域

传入参数:

  • matrix:仿射变换矩阵
  • w:图像宽度
  • h:图像高度
  • color:填充颜色

返回值:

  • null

fillArc

函数原型1:

void fillArc( int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1)

函数原型2:

void fillArc( int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1, const T& color)

功能说明:

  • 填充弧形区域

传入参数:

  • x:弧形区域中心 x 坐标
  • y:弧形区域中心 y 坐标
  • r0:内半径
  • r1:外半径
  • angle0:起始角度
  • angle1:结束角度
  • color:填充颜色

返回值:

  • null

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <Arduino.h>
#include <M5GFX.h>
M5GFX display;

void setup() {
  display.begin();
  uint16_t x = display.width() / 2;
  uint16_t y = display.height() / 2;
  display.fillArc(x, y, 10, 20, 20, 240, TFT_WHITE);
}

void loop() {
}

fillCircle

函数原型1:

void fillCircle( int32_t x, int32_t y, int32_t r)

函数原型2:

void fillCircle( int32_t x, int32_t y, int32_t r, const T& color)

功能说明:

  • 绘制填充颜色的圆

传入参数:

  • x:圆心 x 坐标
  • y:圆心 y 坐标
  • r:圆半径
  • color:圆颜色

返回值:

  • null

fillEllipse

函数原型1:

void fillEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry)

函数原型2:

void fillEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry, const T& color)

功能说明:

  • 绘制填充颜色的椭圆

传入参数:

  • x:绘制圆心 x 坐标
  • y:绘制圆心 y 坐标
  • rx:椭圆长半轴
  • ry:椭圆短半轴
  • color:椭圆颜色

返回值:

  • null

fillEllipseArc

函数原型1:

void fillEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1)

函数原型2:

void fillEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1, const T& color)

功能说明:

  • 绘制填充颜色的椭圆弧,r0、r1不同将绘制粗椭圆弧。

传入参数:

  • x:椭圆弧中心 x 坐标
  • y:椭圆弧中心 y 坐标
  • r0x:内椭圆 x 半径
  • r1x:内椭圆 y 半径
  • r0y:外椭圆 x 半径
  • r1y:外椭圆 y 半径
  • angle0:起始角度
  • angle1:结束角度
  • color:椭圆弧颜色

返回值:

  • null

fillRect

函数原型1:

void fillRect( int32_t x, int32_t y, int32_t w, int32_t h)

函数原型2:

void fillRect( int32_t x, int32_t y, int32_t w, int32_t h, const T& color)

功能说明:

  • 绘制填充颜色的矩形

传入参数:

  • x:矩形起点 x 坐标
  • y:矩形起点 y 坐标
  • w:矩形宽度
  • h:矩形高度
  • color:矩形颜色

返回值:

  • null

fillRectAlpha

函数原型:

void fillRectAlpha(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t alpha, const T& color)

功能说明:

  • 绘制带透明度的填充矩形

传入参数:

  • x:矩形起点 x 坐标
  • y:矩形起点 y 坐标
  • w:矩形宽度
  • h:矩形高度
  • alpha:透明度(0-255)
  • color:矩形颜色

返回值:

  • null

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <Arduino.h>
#include <M5GFX.h>
M5GFX display;

void setup()
{
  display.begin();
  display.fillScreen(TFT_BLACK);
  uint16_t x = display.width() / 2;
  uint16_t y = display.height() / 2;
  display.fillRect(x - 10, y - 10, 50, 50, TFT_WHITE);
  display.fillRectAlpha(x, y, 30, 30, 100, TFT_BLACK);
}

void loop(){
}

fillRoundRect

函数原型1:

void fillRoundRect( int32_t x, int32_t y, int32_t w, int32_t h, int32_t r)

函数原型2:

void fillRoundRect( int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, const T& color)

功能说明:

  • 绘制圆角填充矩形

传入参数:

  • x:矩形起点 x 坐标
  • y:矩形起点 y 坐标
  • w:矩形宽度
  • h:矩形高度
  • r:圆角半径
  • color:矩形颜色

返回值:

  • null

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <Arduino.h>
#include <M5GFX.h>
M5GFX display;

void setup()
{
  display.begin();
  display.fillScreen(TFT_BLACK);
  uint16_t x = display.width() / 2;
  uint16_t y = display.height() / 2;
  display.fillRoundRect(x, y, 30, 30, 5, TFT_WHITE);
}

void loop(){
}

fillScreen

函数原型:

void fillScreen(const T &color)

功能说明:

  • 清空显示,如果指定了一个颜色,就用该颜色初始化屏幕,效果与 clearclearDisplay 相同。

传入参数:

  • color:填充颜色

返回值:

  • null

fillTriangle

函数原型1:

void fillTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2)

函数原型2:

void fillTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color)

功能说明:

  • 绘制填充三角形

传入参数:

  • xN:三角形顶点 x 坐标
  • yN:三角形顶点 y 坐标
  • color:三角形颜色

返回值:

  • null

floodFill

函数原型1:

void floodFill( int32_t x, int32_t y)

函数原型2:

void floodFill( int32_t x, int32_t y, const T& color)

功能说明:

  • 填充指定坐标所对应的大致色域范围

传入参数:

  • x:指定点 x 坐标
  • y:指定点 y 坐标
  • color:填充颜色

返回值:

  • null

fontHeight

函数原型:

int32_t fontHeight(const IFont* font)

功能说明:

  • 获取指定字体的高度

传入参数:

  • font:文本字体格式

返回值:

  • int32_t:字体高度

fontWidth

函数原型:

int32_t fontWidth(const IFont* font)

功能说明:

  • 获取指定字体的宽度

传入参数:

  • font:文本字体格式

返回值:

  • int32_t:字体宽度

getAttribute

函数原型:

uint8_t getAttribute(attribute_t attr_id)

功能说明:

  • 获取指定属性的值

传入参数:

  • attr_id:属性 ID,

*关于attribute_t

返回值:

  • uint8_t:属性值

getBaseColor

函数原型:

uint32_t getBaseColor(void)

功能说明:

传入参数:

  • null

返回值:

  • uint32_t:基色值

getBoard

函数原型:

board_t getBoard(void)

功能说明:

  • 获取当前面板类型

传入参数:

  • null

返回值:

  • board_t:当前面板类型

*关于board_t

getBrightness

函数原型:

uint8_t getBrightness(void)

功能说明:

传入参数:

  • null

返回值:

  • uint8_t:亮度值

getClipRect

函数原型:

void getClipRect(int32_t *x, int32_t *y, int32_t *w, int32_t *h)

功能说明:

传入参数:

  • x:指向 x 坐标的指针
  • y:指向 y 坐标的指针
  • w:指向宽度的指针
  • h:指向高度的指针

返回值:

  • null

getColorDepth

函数原型:

color_depth_t getColorDepth(void)

功能说明:

传入参数:

  • null

返回值:

  • color_depth_t:颜色深度值

getCursorX

函数原型:

int32_t getCursorX(void)

功能说明:

  • 获取当前光标的 x 坐标位置

传入参数:

  • null

返回值:

  • int32_t:当前光标的 x 坐标位置

getCursorY

函数原型:

int32_t getCursorY(void)

功能说明:

  • 获取当前光标的 y 坐标位置

传入参数:

  • null

返回值:

  • int32_t:当前光标的 y 坐标位置

getEpdMode

函数原型:

epd_mode_t getEpdMode(void)

功能说明:

  • 获取由 setEpdMode 设置的 EPD 模式。(仅限电子纸屏产品)

传入参数:

  • null

返回值:

  • epd_mode_t:EPD 模式值

*关于epd_mode_t

getFont

函数原型:

const IFont* getFont (void)

功能说明:

  • 获取由 setFont 设置的当前使用的字体

传入参数:

  • null

返回值:

  • const IFont*:当前使用的字体对象指针

*关于Font

getInstance

函数原型:

static M5GFX* getInstance(void)

功能说明:

  • 获取 M5GFX 的实例

传入参数:

  • null

返回值:

  • M5GFX*:M5GFX 的实例指针

getInvert

函数原型:

bool getInvert(void)

功能说明:

传入参数:

  • null

返回值:

  • bool:当前面板的反转状态
    • true:反转
    • false:不反转

getPalette

函数原型:

RGBColor* getPalette(void)

功能说明:

  • 获取当前调色板信息

传入参数:

  • null

返回值:

  • RGBColor*:指向 bgr888_t 结构体的指针,指向当前调色板中的第一个颜色

getPaletteCount

函数原型:

uint32_t getPaletteCount(void)

功能说明:

  • 获取调色板颜色数量

传入参数:

  • null

返回值:

  • uint32_t:调色板颜色数量

getPanel

函数原型:

Panel_Device* getPanel(void)

功能说明:

  • 获取当前面板设备的指针

传入参数:

  • null

返回值:

  • Panel_Device*:指向当前面板设备的指针

getPivotX

函数原型:

float getPivotX(void)

功能说明:

  • 获取 x 轴的中心点坐标

传入参数:

  • null

返回值:

  • float:x 轴的中心点坐标

getPivotY

函数原型:

float getPivotY(void)

功能说明:

  • 获取 y 轴的中心点坐标

传入参数:

  • null

返回值:

  • float:y 轴的中心点坐标

getRawColor

函数原型:

uint32_t getRawColor(void)

功能说明:

传入参数:

  • null

返回值:

  • uint32_t:原始颜色值

getRotation

函数原型:

uint8_t getRotation(void)

功能说明:

传入参数:

  • null

返回值:

  • uint8_t:当前旋转值
    • 0:0 度
    • 1:90 度
    • 2:180 度
    • 3:270 度

getScrollRect

函数原型:

void getScrollRect(int32_t *x, int32_t *y, int32_t *w, int32_t *h)

功能说明:

传入参数:

  • x:指向 x 坐标的指针
  • y:指向 y 坐标的指针
  • w:指向宽度的指针
  • h:指向高度的指针

返回值:

  • null

getStartCount

函数原型:

uint32_t getStartCount(void)

功能说明:

传入参数:

  • null

返回值:

  • uint32_t:调用次数

getSwapBytes

函数原型:

bool getSwapBytes(void)

功能说明:

传入参数:

  • null

返回值:

  • bool:字节交换状态
    • true:已交换
    • false:未交换

getTextDatum

函数原型:

textdatum_t getTextDatum(void)

功能说明:

传入参数:

  • null

返回值:

  • textdatum_t:文本对齐方式

getTextPadding

函数原型:

uint32_t getTextPadding(void)

功能说明:

传入参数:

  • null

返回值:

  • uint32_t:文本填充值

getTextSizeX

函数原型:

float getTextSizeX(void)

功能说明:

传入参数:

  • null

返回值:

  • float:文本宽度

getTextSizeY

函数原型:

float getTextSizeY(void)

功能说明:

传入参数:

  • null

返回值:

  • float:文本高度

getTextStyle

函数原型:

TextStyle& getTextStyle(void)

功能说明:

传入参数:

  • null

返回值:

  • TextStyle&:文本样式信息的引用

getTouch

函数原型:

uint_fast8_t getTouch(touch_point_t *tp, uint_fast8_t count = 1)

功能说明:

  • 获取触摸面板的触摸信息

传入参数:

  • tp:指向触摸点的指针
  • count:触摸点数量,默认为 1

返回值:

  • uint_fast8_t:触摸点数量

getTouchRaw

函数原型:

uint_fast8_t getTouchRaw(touch_point_t *tp, uint_fast8_t count = 1)

功能说明:

  • 获取触摸面板的原始触摸信息

传入参数:

  • tp:指向触摸点的指针
  • count:触摸点数量,默认为 1

返回值:

  • uint_fast8_t:触摸点数量

hasPalette

函数原型:

bool hasPalette(void)

功能说明:

  • 检查是否存在调色板

传入参数:

  • null

返回值:

  • bool:调色板存在状态
    • true:存在
    • false:不存在

height

函数原型:

int32_t height(void)

功能说明:

  • 获取当前面板高度

传入参数:

  • null

返回值:

  • int32_t:当前面板像素高度

i - q

init

函数原型:

bool init(void)

功能说明:

  • 初始化面板设备,可被重写。

传入参数:

  • null

返回值:

  • bool:初始化是否成功
    • true:成功
    • false:失败

initDMA

函数原型:

void initDMA(void)

功能说明:

  • 初始化 DMA 功能,可被重写。

传入参数:

  • null

返回值:

  • null

invertDisplay

函数原型:

void invertDisplay(bool i)

功能说明:

  • 设置屏幕的亮度和色调是否反转输出(负-正反转)。

传入参数:

  • i:反转标志
    • true 表示反转
    • false 表示不反转

返回值:

  • null

isBusShared

函数原型:

bool isBusShared(void)

功能说明:

  • 检查总线是否被共享,可被重写。

传入参数:

  • null

返回值:

  • bool:总线共享状态
    • true:被共享
    • false:未被共享

isEPD

函数原型:

bool isEPD(void)

功能说明:

  • 检查面板是否为 EPD

返回值:

  • bool:EPD 状态
    • true:是 EPD
    • false:不是 EPD

isReadable

函数原型:

bool isReadable(void)

功能说明:

  • 检查面板是否可读

返回值:

  • bool:可读状态
    • true:可读
    • false:不可读

isSPIShared

函数原型:

bool isSPIShared(void)

功能说明:

  • 检查 SPI 总线是否被共享

返回值:

  • bool:SPI 总线共享状态
    • true:被共享
    • false:未被共享

loadFont

函数原型1:

bool loadFont(const uint8_t* array)

函数原型2:

bool loadFont(T &fs, const char *path)

函数原型3:

bool loadFont(const char *path)

函数原型4:

bool loadFont(DataWrapper* data)

功能说明:

  • 加载字体数据

传入参数:

  • array:指向字体数据的指针
  • fs:字体数据对象
    • SPIFFS
    • SD etc
  • path:字体文件路径
  • data:指向字体数据对象的指针

返回值:

  • bool:加载是否成功
    • true:成功
    • false:失败

paint

函数原型1:

void paint( int32_t x, int32_t y)

函数原型2:

void paint( int32_t x, int32_t y, const T& color)

功能说明:

  • 绘制指定位置的颜色,与 floodFill() 功能相同。

传入参数:

  • x:指定位置的 x 坐标
  • y:指定位置的 y 坐标
  • color:指定位置的颜色

返回值:

  • null

panel

函数原型1:

void panel(Panel_Device* panel)

函数原型2:

Panel_Device* panel(void)

功能说明:

  • 获取面板设备信息

传入参数:

  • panel:指向面板设备的指针 or
  • null

返回值:

  • null or
  • Panel_Device*:指向当前面板设备的指针

popState

函数原型:

void popState(void)

功能说明:

  • 暂时保存文本信息,恢复操作通过 pushState来完成。

传入参数:

  • null

返回值:

  • null

powerSave

函数原型:

void powerSave(bool flg)

功能说明:

  • 设置电源保存状态

传入参数:

  • flg:电源保存标志
    • true:开启电源保存
    • false:关闭电源保存

返回值:

  • null

powerSaveOff

函数原型:

void powerSaveOff(void)

功能说明:

  • 设置电源保存状态为关闭

传入参数:

  • null

返回值:

  • null

powerSaveOn

函数原型:

void powerSaveOn(void)

功能说明:

  • 设置电源保存状态为开启

传入参数:

  • null

返回值:

  • null

print

函数原型1:

size_t print(char c)
size_t print(const char str[])

函数原型2:

size_t print(int  n, int base = 10)
size_t print(long n, int base = 10)
size_t print(unsigned char n, int base = 10)
size_t print(unsigned int  n, int base = 10)
size_t print(unsigned long n, int base = 10)
size_t print(double        n, int digits= 2)

功能说明:

  • 输出文本到光标位置,兼容 Arduino 头文件 Print.h

传入参数:

  • c:字符
  • str:字符串
  • n:整数或浮点数
  • base:进制(默认为 10)
  • digits:小数点后保留的位数(默认为 2)

返回值:

  • size_t:输出的字符数

printf

函数原型:

size_t printf(const char* format, ...)

功能说明:

  • 输出文本到光标位置,兼容 Arduino 头文件 LibPrint.h

传入参数:

  • format:格式化字符串
  • ...:可变参数

返回值:

  • size_t: 输出的字符数

println

函数原型:

size_t println(void)
size_t println(char c)
size_t println(const char c[])

函数原型:

size_t println(int  n, int base = 10) 
size_t println(long n, int base = 10)
size_t println(unsigned char n, int base = 10)
size_t println(unsigned int  n, int base = 10)
size_t println(unsigned long n, int base = 10)
size_t println(double        n, int digits= 2)

功能说明:

  • 输出文本到光标位置,兼容 Arduino 头文件 Print.h

传入参数:

  • c:字符/字符串
  • n:整数或浮点数
  • base:进制(默认为 10)
  • digits:小数点后保留的位数(默认为 2)

返回值:

  • size_t:输出的字符数

progressBar

函数原型:

void progressBar(int x, int y, int w, int h, uint8_t val)

功能说明:

  • 显示蓝色进度条

传入参数:

  • x:进度条的起始 x 坐标
  • y:进度条的起始 y 坐标
  • w:进度条的宽度
  • h:进度条的高度
  • val:进度值(0 - 100)

返回值:

  • null

pushBlock

注意事项:
请在 M5GFX 库相关数据定义查看 draw/push 和 write 函数之间的不同

函数原型:

void pushBlock( const T& color, uint32_t length)

功能说明:

传入参数:

  • color:线条颜色
  • length:线条长度

返回值:

  • null

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <Arduino.h>
#include <M5GFX.h>

M5GFX display;
int32_t x;
int32_t y;

void setup()
{
  display.begin();
  display.fillScreen(TFT_BLACK);

  x = display.width() / 2;
  y = display.height() / 2;

  display.startWrite();
  display.setWindow(0, 0, x - 1 , y);
  for (int i=0; i<y; i++) {
    display.pushBlock(TFT_RED, x / 4);
    display.pushBlock(TFT_BLUE, x / 4);
    display.pushBlock(TFT_GREEN, x / 4);
    display.pushBlock(TFT_YELLOW, x / 4);
  }
  display.endWrite();
}


void loop(){
}

pushImage

函数原型1:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, pixelcopy_t *param, bool use_dma = false)

函数原型2:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)

函数原型3:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const T1* data, const T2& transparent)

函数原型4:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

函数原型5:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

功能说明:

  • 推送图像数据

传入参数:

  • x:起始 x 坐标
  • y:起始 y 坐标
  • w:图像宽度
  • h:图像高度
  • data:图像数据
  • transparent:透明色
  • depth:颜色深度
  • palette:调色板

返回值:

  • null

pushImageAffine

函数原型1:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const T* data)

函数原型2:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const T1* data, const T2& transparent)

函数原型3:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

函数原型4:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

功能说明:

  • 使用仿射变换绘制图像

传入参数:

  • matrix:仿射变换矩阵
  • w:图像宽度
  • h:图像高度
  • data:图像数据
  • transparent:透明色
  • depth:颜色深度
  • palette:调色板

返回值:

  • null

pushImageAffineWithAA

函数原型1:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const T* data)

函数原型2:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const T1* data, const T2& transparent)

函数原型3:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

函数原型4:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

功能说明:

  • 使用仿射变换和抗锯齿绘制图像

传入参数:

  • matrix:仿射变换矩阵
  • w:图像宽度
  • h:图像高度
  • data:图像数据
  • transparent:透明色
  • depth:颜色深度
  • palette:调色板

返回值:

  • null

pushPixels

函数原型1:

void pushPixels(T* data, int32_t len )

函数原型2:

void pushPixels(const uint16_t* data, int32_t len, bool swap)
void pushPixels(const void*     data, int32_t len, bool swap)

功能说明:

传入参数:

  • data:像素数据
  • len:数据长度
  • swap:是否交换字节(可选)

返回值:

  • null

pushPixelsDMA

函数原型1:

void pushPixelsDMA(T* data, int32_t len )

函数原型2:

void pushPixelsDMA(const uint16_t* data, int32_t len, bool swap)
void pushPixelsDMA(const void*     data, int32_t len, bool swap)

功能说明:

传入参数:

  • data:像素数据
  • len:数据长度
  • swap:是否交换字节(可选)

返回值:

  • null

pushState

函数原型:

void pushState(void)

功能说明:

  • 恢复先前通过 popState 暂时退回的文本信息

传入参数:

  • null

返回值:

  • null

qrcode

Generate qrcode from a string.

函数原型:

void qrcode(const char *string, uint16_t x = 50, uint16_t y = 10, uint8_t width = 220, uint8_t version = 6)
void qrcode(const String &string, uint16_t x = 50, uint16_t y = 10, uint8_t width = 220, uint8_t version = 6)

功能说明:

  • 根据指定字符串信息生成二维码

传入参数:

  • string:要生成二维码的字符串
  • x:二维码的起始 x 坐标
  • y:二维码的起始 y 坐标
  • width:二维码的宽度
  • version:二维码的版本(默认为 6)

返回值:

  • null

r - s

readData16

函数原型:

uint16_t readData16(uint8_t index=0)

功能说明:

  • 读取面板上的 16 位数据

传入参数:

  • index:数据索引(默认为 0)

返回值:

  • uint16_t:读取到的 16 位数据

readData32

函数原型:

uint32_t readData32(uint8_t index=0)

功能说明:

  • 读取面板上的 32 位数据

传入参数:

  • index:数据索引(默认为 0)

返回值:

  • uint32_t:读取到的 32 位数据

readData8

函数原型:

uint8_t readData8(uint8_t index=0)

功能说明:

  • 读取面板上的 8 位数据

传入参数:

  • index:数据索引(默认为 0)

返回值:

  • uint8_t:读取到的 8 位数据

readPixel

函数原型:

uint16_t readPixel(int32_t x, int32_t y)

功能说明:

  • 读取指定坐标的颜色编码,颜色编码格式为 RGB565

传入参数:

  • x:指定的 x 坐标
  • y:指定的 y 坐标

返回值:

  • uint16_t:读取到的颜色编码

readPixelRGB

函数原型:

RGBColor readPixelRGB(int32_t x, int32_t y)

功能说明:

  • 读取指定坐标的颜色编码,颜色编码格式为 RGB888

传入参数:

  • x:指定的 x 坐标
  • y:指定的 y 坐标

返回值:

  • RGBColor:读取到的颜色编码

readRect

函数原型:

void readRect( int32_t x, int32_t y, int32_t w, int32_t h, T* data)

功能说明:

  • 读取指定矩形区域的颜色数据

传入参数:

  • x:指定的 x 坐标
  • y:指定的 y 坐标
  • w:指定的宽度
  • h:指定的高度
  • data:存储读取到的颜色数据的缓冲区

返回值:

  • null

readRectRGB

函数原型:

void readRectRGB( int32_t x, int32_t y, int32_t w, int32_t h, RGBColor* data)

功能说明:

  • 读取指定矩形区域的颜色数据,颜色编码格式为 RGB888

传入参数:

  • x:指定的 x 坐标
  • y:指定的 y 坐标
  • w:指定的宽度
  • h:指定的高度
  • data:存储读取到的颜色数据的缓冲区

返回值:

  • null

scroll

函数原型:

void scroll(int_fast16_t dx, int_fast16_t dy)

功能说明:

  • 滚动显示的屏幕

传入参数:

  • dx:X 轴滚动的距离
  • dy:Y 轴滚动的距离

返回值:

  • null

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <Arduino.h>
#include <M5GFX.h>

M5GFX display;
uint16_t x;
uint16_t y;
void setup()
{
  display.begin();
  display.fillScreen(TFT_BLACK);
  x = display.width() / 2;
  y = display.height() / 2;
  display.drawCenterString("scroll", x, y, &fonts::lgfxJapanGothic_24);
}

void loop()
{
  for (int i=-10; i<=10; i+=1) {
    display.scroll(0, i);
  }
}

setAddrWindow

函数原型:

void setAddrWindow(int32_t x, int32_t y, int32_t w, int32_t h)

功能说明:

注意事项:
setWindow 功能相同,但参数不同。 setAddrWindow 会检查屏幕外的溢出,而 setWindow 不检查。

传入参数:

  • x:指定的 x 坐标
  • y:指定的 y 坐标
  • w:指定的宽度
  • h:指定的高度

返回值:

  • null

setAutoDisplay

函数原型:

void setAutoDisplay(bool flg)

功能说明:

  • 设置一个标志,在绘制时自动在面板上显示,而无需执行 display。(仅适用于 M5Paper、CoreInk、UnitOLED)

传入参数:

  • flg:是否启用自动显示标志
    • true:启用自动显示
    • false:禁用自动显示

返回值:

  • null

setBaseColor

函数原型:

void setBaseColor(T c)

功能说明:

  • 设置基色,使用滚动功能时可以指定绘图区域外的颜色。

传入参数:

  • c:指定的基色

返回值:

  • null

setBrightness

函数原型:

void setBrightness(uint8_t brightness)

功能说明:

  • 设置显示面板的亮度

传入参数:

  • brightness:指定的亮度值(0-255)

返回值:

  • null

setClipRect

函数原型:

void setClipRect(int32_t x, int32_t y, int32_t w, int32_t h)

功能说明:

  • 指定绘图区域的剪裁矩形

传入参数:

  • x:指定的 x 坐标
  • y:指定的 y 坐标
  • w:指定的宽度
  • h:指定的高度

返回值:

  • null

setColor

函数原型1:

void setColor(uint8_t r, uint8_t g, uint8_t b)

函数原型2:

void setColor(T color)

功能说明:

  • 设置绘图颜色

传入参数:

  • r:红色分量(0-255)
  • g:绿色分量(0-255)
  • b:蓝色分量(0-255)
  • color:颜色编码

返回值:

  • null

函数原型1:

void setColorDepth(uint8_t bpp)

函数原型2:

void* setColorDepth(color_depth_t depth)

功能说明:

  • 设置颜色深度

传入参数:

  • bpp: 每个像素的位数
    • 1: 1 位
    • 2: 2 位
    • 4: 4 位
    • 8: 8 位
    • 16: 16 位
    • 24: 24 位
    • 32: 32 位
  • depth: 颜色深度

*关于color_depth_t

setCursor

函数原型1:

void setCursor(int16_t x, int16_t y)

函数原型2:

void setCursor(int16_t x, int16_t y, uint8_t font)
void setCursor( int32_t x, int32_t y, const IFont* font)

功能说明:

  • 设置光标位置

传入参数:

  • x:光标 x 坐标
  • y:光标 y 坐标
  • font:文本字体格式

返回值:

  • null

setEpdMode

函数原型:

void setEpdMode(epd_mode_t epd_mode)

功能说明:

  • 设置 EPD 模式

传入参数:

  • epd_mode:指定的 EPD 模式

返回值:

  • null

setFont

函数原型:

void setFont(const IFont* font)

功能说明:

  • 设置文本字体

传入参数:

  • font:文本字体格式

返回值:

  • null

setPivot

函数原型:

void setFont(const IFont* font)

功能说明:

  • 设置文本字体

传入参数:

  • font:文本字体格式

返回值:

  • null

setRawColor

函数原型:

void setRawColor(uint32_t c)

功能说明:

  • 设置原始颜色

传入参数:

  • c:颜色编码

返回值:

  • null

setResolution

函数原型1:

bool setResolution(uint16_t logical_width = 0, uint16_t logical_height = 0, float refresh_rate = 0.0f, uint16_t output_width = 0, uint16_t output_height = 0, uint_fast8_t scale_w = 0, uint_fast8_t scale_h = 0, uint32_t pixel_clock = 74250000)

函数原型2:

bool setResolution( const config_resolution_t& cfg_resolution )

功能说明:

  • 设置分辨率

传入参数:

  • logical_width:逻辑宽度
  • logical_height:逻辑高度
  • refresh_rate:刷新率
  • output_width:输出宽度
  • output_height:输出高度
  • scale_w:缩放因子宽度
  • scale_h:缩放因子高度
  • pixel_clock:像素时钟频率
  • cfg_resolution:分辨率配置结构体
说明:
cfg_resolution 包含了如上所示的所有参数。

返回值:

  • bool
    • true:设置分辨率成功
    • false:设置分辨率失败

For only M5AtomDisplay. Set Resolution.

setRotation

函数原型:

void setRotation(uint_fast8_t r)

功能说明:

  • 设置显示旋转角度

传入参数:

  • r:旋转角度(0-7)

返回值:

  • null
特别提醒:
1.旋转角度是 90° 的倍数。
2.0 到 3 表示顺时针旋转,4 到 7 表示逆时针旋转(默认值为 1)。
3.需要在显示之前设置旋转角度。

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <Arduino.h>
#include <M5GFX.h>
M5GFX display;

void setup() {
  display.begin();
  display.setRotation(2);  //Rotate the screen 180 degrees clockwise (2 x 90)
  display.fillEllipse(160, 100, 60, 100, YELLOW);    //Create a yellow ellipse at (160, 100) with the long axis and the short axis to 60 and 100 respectively.
  delay(1000);
  display.setRotation(1);  //Restore the screen to the default display state
  display.fillEllipse(160, 100, 60, 100, GREEN);
}

void loop() {}

setScrollRect

注意事项:
设置文本滚动范围必须使用 setTextScroll(true)

函数原型:

void setScrollRect(int32_t x, int32_t y, int32_t w, int32_t h, const T& color)

功能说明:

  • 设置文本滚动范围

传入参数:

  • x:滚动范围起点 x 坐标
  • y:滚动范围起点 y 坐标
  • w:滚轴宽度
  • h:滚轴高度
  • color:滚轴颜色

返回值:

  • null

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <Arduino.h>
#include <M5GFX.h>

M5GFX display;
uint32_t count = 0;

void setup() {
    display.begin();
    display.setRotation(3);

    display.clear(TFT_WHITE);
    display.setTextFont(&fonts::FreeMonoBoldOblique18pt7b);
    display.setTextColor(TFT_BLACK);
    display.setTextScroll(true);
    display.setScrollRect(0, 0, display.width(), display.height());
}

void loop() {
  display.printf("Scroll: %d\n", count);
  count++;
  delay(500);
}

setSwapBytes

函数原型:

void setSwapBytes(bool swap)

功能说明:

  • 设置字节交换状态

传入参数:

  • swap:字节交换状态
    • true:字节交换
    • false:字节不交换

返回值:

  • null

setTextColor

函数原型1:

void setTextColor(T color)

函数原型2:

void setTextColor(T1 fgcolor, T2 bgcolor)

功能说明:

  • 设置文本颜色

传入参数:

  • color:文本颜色
  • fgcolor:文本前景色
  • bgcolor:文本背景色

返回值:

  • null

setTextDatum

函数原型:

void setTextDatum(textdatum_t datum)

功能说明:

  • 设置的文本基准信息

传入参数:

  • datum:文本对齐方式

返回值:

  • null

setTextScroll

函数原型:

void setTextScroll(bool scroll)

功能说明:

  • 设置文本滚动

传入参数:

  • scroll:文本滚动标志

返回值:

  • null

setTextSize

函数原型1:

void setTextSize(float size)

函数原型2:

void setTextSize(float sx, float sy)

功能说明:

  • 设置文本大小

传入参数:

  • size:文本缩放比例
  • sx:文本 x 轴向缩放比例
  • sy:文本 y 轴向缩放比例

返回值:

  • null

setTextStyle

函数原型:

void setTextStyle(const TextStyle& text_style)

功能说明:

  • 设置文本样式

传入参数:

  • text_style:文本样式对象

*关于 TextStyle

返回值:

  • null

setTextWrap

函数原型:

void setTextWrap( bool wrapX, bool wrapY = false)

功能说明:

  • 设置文本换行

传入参数:

  • wrapX:文本 x 轴向换行标志
  • wrapY:文本 y 轴向换行标志(默认为不换行)

返回值:

  • null

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <Arduino.h>
#include <M5GFX.h>

M5GFX display;

void setup()
{
  display.begin();
  display.fillScreen(TFT_BLACK);
  display.setTextWrap(true, true); // <- Change Value

}

uint32_t count = 0;

void loop()
{
  display.printf("wrap--------------------------------------------:%d\n", count);
  count++;
  delay(100);
}

setTouchCalibrate

函数原型:

void setTouchCalibrate(uint16_t *parameters)

功能说明:

传入参数:

  • parameters:指向包含校准值的 uint16_t 数组的指针,数组长度为 6。

返回值:

  • null

setWindow

注意事项:
setAddrWindow 功能相同,但参数不同。 setAddrWindow 会检查屏幕外的溢出,而 setWindow 不检查。

函数原型:

void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye)

功能说明:

传入参数:

  • xs:起始点 x 坐标
  • ys:起始点 y 坐标
  • xe:结束点 x 坐标
  • ye:结束点 y 坐标

返回值:

  • null

showFont

函数原型:

void showFont(uint32_t td = 2000)

功能说明:

  • 按照指定时间显示文本

传入参数:

  • td:显示时间,单位为毫秒

返回值:

  • null

sleep

函数原型:

void sleep(void)

功能说明:

  • 休眠面板,使用 wakeup 唤醒面板

传入参数:

  • null

返回值:

  • null

startWrite

函数原型:

void startWrite(bool transaction = true)

功能说明:

  • 在 SPI 总线上声明 CS(片选信号)。它与 endWrite() 配合使用。声明 startWrite() 可使 M5GFX 有效地利用 DMA 缓冲区。
注意事项:
不能与 SD 卡访问功能同时使用。当存在多个绘图任务时,需进行单独控制。

传入参数:

  • transaction:是否开启事务标志,默认为 true(开启)。

返回值:

  • null

swap565

函数原型:

uint16_t swap565( uint8_t r, uint8_t g, uint8_t b)

功能说明:

  • 根据 R,G,B 分量生成颜色编码

传入参数:

  • r: 红色分量,0-255
  • g: 绿色分量,0-255
  • b: 蓝色分量,0-255

返回值:

  • uint16_t:RGB565 颜色编码

swap888

函数原型:

uint16_t swap888( uint8_t r, uint8_t g, uint8_t b)

功能说明:

  • 根据 R,G,B 分量生成颜色编码

传入参数:

  • r: 红色分量,0-255
  • g: 绿色分量,0-255
  • b: 蓝色分量,0-255

返回值:

  • uint32_t:RGB888 颜色编码

t - z

textLength

函数原型:

int32_t textLength(const char *string, int32_t width)

功能说明:

  • 获取在指定范围内能显示的字符个数

传入参数:

  • string:需要显示的字符串指针
  • width:指定范围的像素宽度

返回值:

  • int32_t:能显示的字节个数
特别提醒:
返回值为字节个数而非字符个数,如中文字符为多字节字符,返回的字节个数大于字符个数

textWidth

函数原型:

int32_t textWidth(const char *string, const IFont* font)

功能说明:

  • 返回屏幕上显示的字符串的宽度。若未指定字体,则会使用默认字体或通过 setFont 方法设置的字体来计算。

传入参数:

  • string:屏幕上显示的字符串指针
  • font:文本字体格式

返回值:

  • int32_t:显示的字符串像素宽度

touch

函数原型:

ITouch* touch(void)

功能说明:

  • 如果存在触摸设备,则返回触摸设备 ITouch 指针。

传入参数:

  • null

返回值:

  • ITouch:触摸设备结构体指针

unloadFont

Restore font set by setFont() to the default font(&fonts::Font0).

函数原型:

void unloadFont(void)

功能说明:

  • 将由 setFont 设置的字体恢复为默认字体 &fonts::Font0

传入参数:

  • null

返回值:

  • null

waitDisplay

函数原型:

void waitDisplay(void)

功能说明:

  • 等待显示屏被释放,可被重写。

传入参数:

  • null

返回值:

  • null

waitDMA

函数原型:

void waitDMA(void)

功能说明:

  • 等待 DMA 被释放,可被重写。

传入参数:

  • null

返回值:

  • null

wakeup

函数原型:

void wakeup(void)

功能说明:

  • 唤醒面板,使用 sleep 休眠面板

传入参数:

  • null

返回值:

  • null

width

函数原型:

int32_t width (void)

功能说明:

  • 获取当前面板宽度

传入参数:

  • null

返回值:

  • int32_t:当前面板像素宽度

writeColor

函数原型:

void writeColor( const T& color, uint32_t length)

功能说明:

注意事项:
此函数需要与 startWriteendWrite 配合使用。

传入参数:

  • color:绘制的颜色
  • length:绘制的像素长度

返回值:

  • null

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <Arduino.h>
#include <M5GFX.h>

M5GFX display;
int32_t x;
int32_t y;

void setup()
{
  display.begin();
  display.fillScreen(TFT_BLACK);

  x = display.width() / 2;
  y = display.height() / 2;

  display.startWrite();
  display.setWindow(0, 0, x - 1 , y);
  for (int i=0; i<y; i++) {
    display.writeColor(TFT_RED, x / 4);
    display.writeColor(TFT_BLUE, x / 4);
    display.writeColor(TFT_GREEN, x / 4);
    display.writeColor(TFT_YELLOW, x / 4);
  }
  display.endWrite();
}

void loop(){
}

writeCommand16

函数原型:

void writeCommand16(uint16_t cmd)

功能说明:

  • 向控制面板写入 16 位命令

传入参数:

  • cmd:要写入的命令

返回值:

  • null

writeData16

函数原型:

void writeData16(uint16_t data)

功能说明:

  • 向控制面板写入 16 位数据

传入参数:

  • data:要写入的数据

返回值:

  • null

writeData32

函数原型:

void writeData32(uint32_t data)

功能说明:

  • 向控制面板写入 32 位数据

传入参数:

  • data:要写入的数据

返回值:

  • null

writeData

函数原型:

void writeData(uint8_t data)

功能说明:

  • 向控制面板写入 8 位数据

传入参数:

  • data:要写入的数据

返回值:

  • null

writeFastHLine

函数原型1:

void writeFastHLine( int32_t x, int32_t y, int32_t w)

函数原型2:

void writeFastHLine( int32_t x, int32_t y, int32_t w, const T& color)

功能说明:

  • 绘制水平线

传入参数:

  • x:起点 x 坐标
  • y:起点 y 坐标
  • w:线宽度
  • color:线颜色

返回值:

  • null

writeFastVLine

函数原型1:

void writeFastVLine( int32_t x, int32_t y, int32_t w)

函数原型2:

void writeFastVLine( int32_t x, int32_t y, int32_t w, const T& color)

功能说明:

  • 绘制垂直线

传入参数:

  • x:起点 x 坐标
  • y:起点 y 坐标
  • w:线宽度
  • color:线颜色

返回值:

  • null

writeFillRect

函数原型1:

void writeFillRect( int32_t x, int32_t y, int32_t w, int32_t h)

函数原型2:

void writeFillRect( int32_t x, int32_t y, int32_t w, int32_t h, const T& color)

功能说明:

  • 绘制填充颜色的矩形

传入参数:

  • x:矩形起点 x 坐标
  • y:矩形起点 y 坐标
  • w:矩形宽度
  • h:矩形高度
  • color:矩形颜色

返回值:

  • null

writeIndexedPixels

函数原型:

void writeIndexedPixels(const uint8_t* data, T* palette, int32_t len, uint8_t depth = 8)

功能说明:

  • 使用调色板颜色绘制图像数据

传入参数:

  • data:图像数据
  • paltte:调色板指针
  • len:图像数据长度
  • depth:颜色深度

返回值:

  • null

writePixel

函数原型1:

void writePixel(int32_t x, int32_t y)

函数原型2:

void writePixel(int32_t x, int32_t y, const T& color)

功能说明:

  • 在裁剪区域内绘制一个像素点

传入参数:

  • x:像素点 x 坐标
  • y:像素点 y 坐标
  • color:像素点颜色

返回值:

  • null

writePixels

函数原型1:

void writePixels(const T* data, int32_t len)

函数原型2:

void writePixels(const uint16_t* data, int32_t len, bool swap)
void writePixels(const void*     data, int32_t len, bool swap)

功能说明:

  • 在裁剪区域内绘制像素点,数据会逐行绘制,从左上角开始。

传入参数:

  • data:图像数据
  • len:图像数据长度
  • color:像素点颜色
  • swap:字节交换标志

返回值:

  • null

writePixelsDMA

函数原型1:

void writePixels(const T* data, int32_t len)

函数原型2:

void writePixels(const uint16_t* data, int32_t len, bool swap)
void writePixels(const void*     data, int32_t len, bool swap)

功能说明:

  • 在裁剪区域内使用 DMA 绘制像素点,数据会逐行绘制,从左上角开始。

传入参数:

  • data:图像数据
  • len:图像数据长度
  • color:像素点颜色
  • swap:字节交换标志

返回值:

  • null
On This Page