[STM32-64 Ardu] 보드에서 ST7789 TFT LCD 모듈은 SSM Type 모듈 커넥터에 연결해서 테스트 가능하다.
CS핀은 PB0, DC핀 PC4에 할당되어 있다.
먼저 [STM32-64 Ardu] 보드용으로 셋업 파일을 생성한다.
Arduino\libraries\TFT_eSPI_Setups\Setup_ST7789_stm32f7_ardu.h
#define TFT_CS PB0 // Define as not used
#define TFT_DC PC4 // Data Command control pin
#define TFT_RST -1 // TFT reset pin (could connect to NodeMCU RST, see next line)
TFT_eSP 기본 예제중 간단한것 하나 테스트 해 보았다.
기본 예제에서 좌표값이 좀 맞지 않아 수정했더니 문제 없이 잘동작하는것을 확인 할 수 있다.
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define DEG2RAD 0.0174532925
byte inc = 0;
unsigned int col = 0;
void setup(void)
{
tft.begin();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
}
void loop() {
// Draw 4 pie chart segments
fillSegment(120, 120, 0, 60, 100, TFT_RED);
fillSegment(120, 120, 60, 30, 100, TFT_GREEN);
fillSegment(120, 120, 60 + 30, 120, 100, TFT_BLUE);
fillSegment(120, 120, 60 + 30 + 120, 150, 100, TFT_YELLOW);
delay(4000);
// Erase old chart with 360 degree black plot
fillSegment(120, 120, 0, 360, 100, TFT_BLACK);
}
// #########################################################################
// Draw circle segments
// #########################################################################
// x,y == coords of centre of circle
// start_angle = 0 - 359
// sub_angle = 0 - 360 = subtended angle
// r = radius
// colour = 16 bit colour value
int fillSegment(int x, int y, int start_angle, int sub_angle, int r, unsigned int colour)
{
// Calculate first pair of coordinates for segment start
float sx = cos((start_angle - 90) * DEG2RAD);
float sy = sin((start_angle - 90) * DEG2RAD);
uint16_t x1 = sx * r + x;
uint16_t y1 = sy * r + y;
// Draw colour blocks every inc degrees
for (int i = start_angle; i < start_angle + sub_angle; i++) {
// Calculate pair of coordinates for segment end
int x2 = cos((i + 1 - 90) * DEG2RAD) * r + x;
int y2 = sin((i + 1 - 90) * DEG2RAD) * r + y;
tft.fillTriangle(x1, y1, x2, y2, x, y, colour);
// Copy segment end to sgement start for next segment
x1 = x2;
y1 = y2;
}
return 1;
}
// #########################################################################
// Return the 16 bit colour with brightness 0-100%
// #########################################################################
unsigned int brightness(unsigned int colour, int brightness)
{
byte red = colour >> 11;
byte green = (colour & 0x7E0) >> 5;
byte blue = colour & 0x1F;
blue = (blue * brightness)/100;
green = (green * brightness)/100;
red = (red * brightness)/100;
return (red << 11) + (green << 5) + blue;
}
반응형