firmware/src/graphics/TFT.cpp

66 lines
1.8 KiB
C++
Raw Normal View History

2020-08-17 20:47:05 +00:00
#include "configuration.h"
#ifdef ST7735_CS
#include "SPILock.h"
2020-08-28 22:06:52 +00:00
#include "TFT.h"
#include "graphics/configs.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
2020-08-28 22:06:52 +00:00
TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl)
{
setGeometry(GEOMETRY_128_64); // FIXME - currently we lie and claim 128x64 because I'm not yet sure other resolutions will
// work ie GEOMETRY_RAWMODE
2020-08-28 22:06:52 +00:00
}
// Write the buffer to the display memory
void TFTDisplay::display(void)
{
concurrency::LockGuard g(spiLock);
#if 1
2020-08-28 22:06:52 +00:00
// FIXME - only draw bits have changed (use backbuf similar to the other displays)
// tft.drawBitmap(0, 0, buffer, 128, 64, TFT_YELLOW, TFT_BLACK);
for (uint8_t y = 0; y < SCREEN_HEIGHT; y++) {
for (uint8_t x = 0; x < SCREEN_WIDTH; x++) {
// get src pixel in the page based ordering the OLED lib uses FIXME, super inefficent
auto b = buffer[x + (y / 8) * SCREEN_WIDTH];
auto isset = b & (1 << (y & 7));
tft.drawPixel(x, y, isset ? TFT_WHITE : TFT_BLACK);
}
}
#endif
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
{
DEBUG_MSG("Doing TFT init\n");
#ifdef ST7735_BACKLIGHT_EN
digitalWrite(ST7735_BACKLIGHT_EN, HIGH);
pinMode(ST7735_BACKLIGHT_EN, OUTPUT);
#endif
#if 1
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
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
#endif
2020-08-28 22:06:52 +00:00
return true;
2020-08-17 20:47:05 +00:00
}
#endif