2020-08-17 20:47:05 +00:00
|
|
|
#include "configuration.h"
|
|
|
|
|
2020-08-17 21:06:31 +00:00
|
|
|
#ifdef ST7735_CS
|
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
|
|
|
|
2020-08-28 22:06:52 +00:00
|
|
|
TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl)
|
|
|
|
{
|
2020-10-15 07:12:27 +00:00
|
|
|
setGeometry(GEOMETRY_RAWMODE, 160, 80);
|
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);
|
|
|
|
|
2020-08-28 22:06:52 +00:00
|
|
|
// FIXME - only draw bits have changed (use backbuf similar to the other displays)
|
2020-08-28 22:33:33 +00:00
|
|
|
// tft.drawBitmap(0, 0, buffer, 128, 64, TFT_YELLOW, TFT_BLACK);
|
2020-10-15 07:12:27 +00:00
|
|
|
for (uint8_t y = 0; y < displayHeight; y++) {
|
|
|
|
for (uint8_t 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
|
2020-10-15 07:12:27 +00:00
|
|
|
auto b = buffer[x + (y / 8) * displayWidth];
|
2020-08-28 22:33:33 +00:00
|
|
|
auto isset = b & (1 << (y & 7));
|
|
|
|
tft.drawPixel(x, y, isset ? TFT_WHITE : TFT_BLACK);
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connect to the display
|
|
|
|
bool TFTDisplay::connect()
|
2020-08-17 20:47:05 +00:00
|
|
|
{
|
2020-08-28 21:24:22 +00:00
|
|
|
DEBUG_MSG("Doing TFT init\n");
|
|
|
|
|
|
|
|
#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();
|
2020-08-28 22:06:52 +00:00
|
|
|
tft.setRotation(3); // Orient horizontal and wide underneath the silkscreen name label
|
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
|