本文只是作為暫時的筆記!
想了解 GC9A01 有哪些繪圖指令,可以參考 Adafruit_GC9A01A 的 graphicstest.ino 。
#include "SPI.h"
void setup() {
tft.begin();
}
螢幕屬性
tft.width(); //取得螢幕寬度
tft.height(); //取得螢幕高度
tft.setRotation(uint8_t r); //旋轉螢幕 r=0~3
tft.invertDisplay(bool i); // 螢幕反色 | |
tft.setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h); |
調色
tft.color565(i, i, i);
顏色定義
// Color definitions | |
#define GC9A01A_BLACK 0x0000 ///< 0, 0, 0 | |
#define GC9A01A_NAVY 0x000F ///< 0, 0, 123 | |
#define GC9A01A_DARKGREEN 0x03E0 ///< 0, 125, 0 | |
#define GC9A01A_DARKCYAN 0x03EF ///< 0, 125, 123 | |
#define GC9A01A_MAROON 0x7800 ///< 123, 0, 0 | |
#define GC9A01A_PURPLE 0x780F ///< 123, 0, 123 | |
#define GC9A01A_OLIVE 0x7BE0 ///< 123, 125, 0 | |
#define GC9A01A_LIGHTGREY 0xC618 ///< 198, 195, 198 | |
#define GC9A01A_DARKGREY 0x7BEF ///< 123, 125, 123 | |
#define GC9A01A_BLUE 0x001F ///< 0, 0, 255 | |
#define GC9A01A_GREEN 0x07E0 ///< 0, 255, 0 | |
#define GC9A01A_CYAN 0x07FF ///< 0, 255, 255 | |
#define GC9A01A_RED 0xF800 ///< 255, 0, 0 | |
#define GC9A01A_MAGENTA 0xF81F ///< 255, 0, 255 | |
#define GC9A01A_YELLOW 0xFFE0 ///< 255, 255, 0 | |
#define GC9A01A_WHITE 0xFFFF ///< 255, 255, 255 | |
#define GC9A01A_ORANGE 0xFD20 ///< 255, 165, 0 | |
#define GC9A01A_GREENYELLOW 0xAFE5 ///< 173, 255, 41 | |
#define GC9A01A_PINK 0xFC18 ///< 255, 130, 198 |
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //棕色
#define BRRED 0XFC07 //棕紅色
#define GRAY 0X8430 //灰色
#define DARKBLUE 0X01CF //深藍色
#define LIGHTBLUE 0X7D7C //淺藍色
#define GRAYBLUE 0X5458 //灰藍色
#define LIGHTGREEN 0X841F //淺綠色
#define LGRAY 0XC618 //淺灰色(PANNEL),窗體背景色
#define LGRAYBLUE 0XA651 //淺灰藍色(中間層顏色)
#define LBBLUE 0X2B12 //淺棕藍色(選擇條目的反色)
螢幕填色
uint16_t color
tft.fillScreen(GC9A01A_BLACK); yield();
tft.fillScreen(GC9A01A_WHITE); yield();
tft.fillScreen(GC9A01A_RED); yield();
tft.fillScreen(GC9A01A_ORANGE); yield();
tft.fillScreen(GC9A01A_YELLOW); yield();
tft.fillScreen(GC9A01A_GREEN); yield();
tft.fillScreen(GC9A01A_BLUE); yield();
畫矩形
tft.drawRect(x, y, i, i, color);
畫矩形色塊
tft.fillRect(x, y, i, i, color);
畫圓
tft.drawCircle(x, y, radius, color);
畫圓形色塊
tft.fillCircle(x, y, radius, color);
畫三角形
tft.drawTriangle( | |
cx , cy - i, // peak | |
cx - i, cy + i, // bottom left | |
cx + i, cy + i, // bottom right | |
tft.color565(i, i, i)); |
畫三角形色塊
tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, | |
tft.color565(0, i*10, i*10)); | |
t += micros() - start; | |
tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, | |
tft.color565(i*10, i*10, 0)); |
畫圓角矩形
tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
畫圓角矩形色塊
tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); | |
yield(); |
#include <SPI.h>
#include "LCD_Driver.h"
#include "GUI_Paint.h"
#include "image.h"
void setup()
{
Config_Init();
LCD_Init();
LCD_SetBacklight(1000);
Paint_NewImage(LCD_WIDTH, LCD_HEIGHT, 0, BLACK);
Paint_Clear(BLACK);
Paint_DrawCircle(120,120, 120, BLUE ,DOT_PIXEL_2X2,DRAW_FILL_EMPTY);
Paint_DrawLine (120, 0, 120, 12,GREEN ,DOT_PIXEL_4X4,LINE_STYLE_SOLID);
Paint_DrawLine (120, 228, 120, 240,GREEN ,DOT_PIXEL_4X4,LINE_STYLE_SOLID);
Paint_DrawLine (0, 120, 12, 120,GREEN ,DOT_PIXEL_4X4,LINE_STYLE_SOLID);
Paint_DrawLine (228, 120, 240, 120,GREEN ,DOT_PIXEL_4X4,LINE_STYLE_SOLID);
Paint_DrawImage(gImage_70X70, 85, 25, 70, 70);
Paint_DrawString_CN(56,140, "微雪电子", &Font24CN,BLACK, WHITE);
Paint_DrawString_EN(123, 123, "WAVESHARE",&Font16, BLACK, GREEN);
Paint_DrawLine (120, 120, 70, 70,YELLOW ,DOT_PIXEL_3X3,LINE_STYLE_SOLID);
Paint_DrawLine (120, 120, 176, 64,BLUE ,DOT_PIXEL_3X3,LINE_STYLE_SOLID);
Paint_DrawLine (120, 120, 120, 210,RED ,DOT_PIXEL_2X2,LINE_STYLE_SOLID);
}
void loop()
{
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
Overlay parameters
The overlay support some optional parameters that allow changes in the default behavior and affects only the LCD display. They are key=value pairs, comma separated in no predefined order, as follow:
dtoverlay=gc9a01,speed=40000000,rotate=0,width=240,height=240,fps=50,debug=0
speed
: max spi frequency to be usedrotate
: image rotation (in degrees: 0, 90, 180, 270)width
: width of the displayheight
: height of the displayfps
: max fps to be useddebug
: debug level to be logged on boot process
Additional image orientation and resolution
Since fbcp
is making a plain copy from HDMI to LCD, screen resolution may affect the final result. Additional settings can be added on the config.txt
in order to adjust the resulting image to your needs. The full set of options can be checked at /boot/overlays/README.
Note that the following settings will be applied both to the HDMI and the LCD.
dtoverlay=gc9a01
hdmi_force_hotplug=1
hdmi_cvt=240 240 60 1 0 0 0
hdmi_group=2
hdmi_mode=87
hdmi_drive=2
display_rotate=2
hdmi_force_hotplug
: force HDMI output rather than DVIhdmi_cvt
: adjusts de resolution, framerate and more. Format: <width> <height> <framerate> <aspect> <margins> <interlace>hdmi_group
: set DMT group (Display Monitor Timings: the standard typically used by monitors)hdmi_mode
: set DMT modehdmi_drive
: force a HDMI mode rather than DVIdisplay_rotate
: rotate screen 180 degrees
The display_rotate
setting allows to rotate or flip the screen orientation to fit your needs. The default value is 0
, possible values are:
0
no rotation1
rotate 90 degrees clockwise2
rotate 180 degrees clockwise3
rotate 270 degrees clockwise0x10000
horizontal flip0x20000
vertical flip
This setting is a bitmask. So you can both flip and rotate the display at the same time. Example:
0x10001
both do a horizontal flip and rotate 90 degrees clockwise (0x10000
+1
).0x20003
both do a vertical flip and rotate 270 degrees clockwise (0x20000
+3
).