2020-08-17 20:47:05 +00:00
|
|
|
#include "configuration.h"
|
|
|
|
|
2022-05-09 17:50:39 +00:00
|
|
|
#if defined(ST7735_CS) || defined(ILI9341_DRIVER)
|
2020-08-29 00:38:23 +00:00
|
|
|
#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
|
|
|
|
|
2020-08-29 00:38:23 +00:00
|
|
|
static TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
|
2020-08-17 20:47:05 +00:00
|
|
|
|
2022-11-12 16:12:40 +00:00
|
|
|
TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus)
|
2020-08-28 22:06:52 +00:00
|
|
|
{
|
2022-05-09 17:50:39 +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)
|
|
|
|
{
|
2020-08-29 00:38:23 +00:00
|
|
|
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++) {
|
2020-08-28 22:33:33 +00:00
|
|
|
// get src pixel in the page based ordering the OLED lib uses FIXME, super inefficent
|
2022-05-09 17:50:39 +00:00
|
|
|
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:33:33 +00:00
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
}
|
|
|
|
|
2022-05-09 17:50:39 +00:00
|
|
|
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
|
|
|
{
|
2022-05-09 17:50:39 +00:00
|
|
|
concurrency::LockGuard g(spiLock);
|
2020-08-28 21:24:22 +00:00
|
|
|
DEBUG_MSG("Doing TFT init\n");
|
|
|
|
|
2022-05-09 17:50:39 +00:00
|
|
|
#ifdef TFT_BL
|
|
|
|
digitalWrite(TFT_BL, HIGH);
|
|
|
|
pinMode(TFT_BL, OUTPUT);
|
|
|
|
#endif
|
|
|
|
|
2020-08-28 21:24:22 +00:00
|
|
|
#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();
|
2022-05-09 17:50:39 +00:00
|
|
|
#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
|
2022-05-09 17:50:39 +00:00
|
|
|
#endif
|
2020-08-29 00:38:23 +00:00
|
|
|
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
|