MeshCore/src/helpers/ui/ST7789Display.cpp

118 lines
2.3 KiB
C++
Raw Normal View History

#ifdef ST7789
#include "ST7789Display.h"
2025-04-30 11:09:43 +02:00
#ifndef X_OFFSET
#define X_OFFSET 16
#endif
bool ST7789Display::begin() {
if(!_isOn) {
pinMode(PIN_TFT_VDD_CTL, OUTPUT);
pinMode(PIN_TFT_LEDA_CTL, OUTPUT);
digitalWrite(PIN_TFT_VDD_CTL, LOW);
digitalWrite(PIN_TFT_LEDA_CTL, LOW);
digitalWrite(PIN_TFT_RST, HIGH);
2025-04-24 22:37:06 +02:00
display.init();
2025-04-30 11:09:43 +02:00
display.landscapeScreen();
2025-04-24 22:37:06 +02:00
display.displayOn();
2025-04-30 11:26:04 +02:00
setCursor(0,0);
_isOn = true;
}
return true;
}
void ST7789Display::turnOn() {
ST7789Display::begin();
}
void ST7789Display::turnOff() {
digitalWrite(PIN_TFT_VDD_CTL, HIGH);
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
digitalWrite(PIN_TFT_RST, LOW);
_isOn = false;
}
void ST7789Display::clear() {
2025-04-24 22:37:06 +02:00
display.clear();
}
void ST7789Display::startFrame(Color bkg) {
2025-04-24 22:37:06 +02:00
display.clear();
}
void ST7789Display::setTextSize(int sz) {
2025-04-24 22:37:06 +02:00
switch(sz) {
case 1 :
display.setFont(ArialMT_Plain_10);
break;
case 2 :
display.setFont(ArialMT_Plain_24);
break;
default:
display.setFont(ArialMT_Plain_10);
}
}
void ST7789Display::setColor(Color c) {
switch (c) {
case DisplayDriver::DARK :
_color = ST77XX_BLACK;
break;
case DisplayDriver::LIGHT :
_color = ST77XX_WHITE;
break;
case DisplayDriver::RED :
_color = ST77XX_RED;
break;
case DisplayDriver::GREEN :
_color = ST77XX_GREEN;
break;
case DisplayDriver::BLUE :
_color = ST77XX_BLUE;
break;
case DisplayDriver::YELLOW :
_color = ST77XX_YELLOW;
break;
case DisplayDriver::ORANGE :
_color = ST77XX_ORANGE;
break;
default:
_color = ST77XX_WHITE;
break;
}
2025-04-24 22:37:06 +02:00
display.setRGB(_color);
}
void ST7789Display::setCursor(int x, int y) {
2025-04-30 11:09:43 +02:00
_x = x + X_OFFSET;
2025-04-24 22:37:06 +02:00
_y = y;
}
void ST7789Display::print(const char* str) {
2025-04-24 22:37:06 +02:00
display.drawString(_x, _y, str);
}
void ST7789Display::fillRect(int x, int y, int w, int h) {
2025-04-30 11:09:43 +02:00
display.fillRect(x + X_OFFSET, y, w, h);
}
void ST7789Display::drawRect(int x, int y, int w, int h) {
2025-04-30 11:09:43 +02:00
display.drawRect(x + X_OFFSET, y, w, h);
}
void ST7789Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
2025-04-30 11:09:43 +02:00
display.drawBitmap(x+X_OFFSET, y, w, h, bits);
}
uint16_t ST7789Display::getTextWidth(const char* str) {
return display.getStringWidth(str);
}
void ST7789Display::endFrame() {
2025-04-24 22:37:06 +02:00
display.display();
}
#endif