firmware/src/graphics/TFTDisplay.cpp

85 lines
2.2 KiB
C++
Raw Normal View History

2020-08-17 20:47:05 +00:00
#include "configuration.h"
#if defined(ST7735_CS) || defined(ILI9341_DRIVER)
#include "SPILock.h"
2020-09-26 16:40:48 +00:00
#include "TFTDisplay.h"
2020-08-17 20:47:05 +00:00
#include <SPI.h>
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
static TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
2020-08-17 20:47:05 +00:00
TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl)
2020-08-28 22:06:52 +00:00
{
#ifdef SCREEN_ROTATE
setGeometry(GEOMETRY_RAWMODE, TFT_HEIGHT, TFT_WIDTH);
#else
setGeometry(GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT);
#endif
2020-08-28 22:06:52 +00:00
}
// Write the buffer to the display memory
void TFTDisplay::display(void)
{
concurrency::LockGuard g(spiLock);
2022-09-19 14:57:18 +00:00
uint16_t x,y;
for (y = 0; y < displayHeight; y++) {
for (x = 0; x < displayWidth; x++) {
// get src pixel in the page based ordering the OLED lib uses FIXME, super inefficent
auto isset = buffer[x + (y / 8) * displayWidth] & (1 << (y & 7));
2022-09-19 14:57:18 +00:00
auto dblbuf_isset = buffer_back[x + (y / 8) * displayWidth] & (1 << (y & 7));
if (isset != dblbuf_isset) {
tft.drawPixel(x, y, isset ? TFT_WHITE : TFT_BLACK);
}
}
}
// Copy the Buffer to the Back Buffer
for (y = 0; y < (displayHeight / 8); y++) {
for (x = 0; x < displayWidth; x++) {
uint16_t pos = x + y * displayWidth;
buffer_back[pos] = buffer[pos];
}
}
2020-08-28 22:06:52 +00:00
}
// Send a command to the display (low level function)
void TFTDisplay::sendCommand(uint8_t com)
{
(void)com;
// Drop all commands to device (we just update the buffer)
}
void TFTDisplay::setDetected(uint8_t detected)
{
(void)detected;
}
2020-08-28 22:06:52 +00:00
// Connect to the display
bool TFTDisplay::connect()
2020-08-17 20:47:05 +00:00
{
concurrency::LockGuard g(spiLock);
2022-12-30 02:41:37 +00:00
LOG_DEBUG("Doing TFT init\n");
#ifdef TFT_BL
digitalWrite(TFT_BL, HIGH);
pinMode(TFT_BL, OUTPUT);
#endif
#ifdef ST7735_BACKLIGHT_EN
digitalWrite(ST7735_BACKLIGHT_EN, HIGH);
pinMode(ST7735_BACKLIGHT_EN, OUTPUT);
#endif
2020-08-17 20:47:05 +00:00
tft.init();
#ifdef M5STACK
tft.setRotation(1); // M5Stack has the TFT in landscape
#else
2020-08-28 22:06:52 +00:00
tft.setRotation(3); // Orient horizontal and wide underneath the silkscreen name label
#endif
tft.fillScreen(TFT_BLACK);
2020-08-28 22:06:52 +00:00
// tft.drawRect(0, 0, 40, 10, TFT_PURPLE); // wide rectangle in upper left
return true;
2020-08-17 20:47:05 +00:00
}
#endif