Skip to content

Commit

Permalink
Move tft init to TFT class
Browse files Browse the repository at this point in the history
  • Loading branch information
cgreening committed Jan 10, 2024
1 parent 9e2a07f commit 9e31047
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
58 changes: 29 additions & 29 deletions player/src/Displays/TFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <TFT_eSPI.h>
#include "TFT.h"

TFT::TFT(TFT_eSPI &tft) : tft(tft) {
// power on the tft
TFT::TFT(): tft(new TFT_eSPI()) {
// power on the tft
#ifdef TFT_POWER
if (TFT_POWER != GPIO_NUM_NC) {
Serial.println("Powering on TFT");
Expand All @@ -13,20 +13,20 @@ TFT::TFT(TFT_eSPI &tft) : tft(tft) {
}
#endif

tft.init();
tft->init();
#ifdef M5CORE2
tft.setRotation(6);
tft->setRotation(6);
#else
tft.setRotation(1);
tft->setRotation(1);
#endif
tft.fillScreen(TFT_BLACK);
tft->fillScreen(TFT_BLACK);
#ifdef USE_DMA
tft.initDMA();
tft->initDMA();
#endif
tft.fillScreen(TFT_BLACK);
tft.setTextFont(2);
tft.setTextSize(2);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft->fillScreen(TFT_BLACK);
tft->setTextFont(2);
tft->setTextSize(2);
tft->setTextColor(TFT_GREEN, TFT_BLACK);
}

void TFT::drawPixels(int x, int y, int width, int height, uint16_t *pixels) {
Expand All @@ -37,53 +37,53 @@ void TFT::drawPixels(int x, int y, int width, int height, uint16_t *pixels) {
}
memcpy(dmaBuffer[dmaBufferIndex], pixels, numPixels * 2);
#ifdef USE_DMA
tft.dmaWait();
tft->dmaWait();
#endif
tft.setAddrWindow(x, y, width, height);
tft->setAddrWindow(x, y, width, height);
#ifdef USE_DMA
tft.pushPixelsDMA(dmaBuffer[dmaBufferIndex], numPixels);
tft->pushPixelsDMA(dmaBuffer[dmaBufferIndex], numPixels);
#else
tft.pushPixels(dmaBuffer[dmaBufferIndex], numPixels);
tft->pushPixels(dmaBuffer[dmaBufferIndex], numPixels);
#endif
dmaBufferIndex = (dmaBufferIndex + 1) % 2;
}

void TFT::startWrite() {
tft.startWrite();
tft->startWrite();
}

void TFT::endWrite() {
tft.endWrite();
tft->endWrite();
}

int TFT::width() {
return tft.width();
return tft->width();
}

int TFT::height() {
return tft.height();
return tft->height();
}

void TFT::fillScreen(uint16_t color) {
tft.fillScreen(color);
tft->fillScreen(color);
}

void TFT::drawChannel(int channelIndex) {
tft.setCursor(20, 20);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.printf("%d", channelIndex);
tft->setCursor(20, 20);
tft->setTextColor(TFT_GREEN, TFT_BLACK);
tft->printf("%d", channelIndex);
}

void TFT::drawTuningText() {
tft.setCursor(20, 20);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.println("TUNING...");
tft->setCursor(20, 20);
tft->setTextColor(TFT_GREEN, TFT_BLACK);
tft->println("TUNING...");
}

void TFT::drawFPS(int fps) {
// show the frame rate in the top right
tft.setCursor(width() - 50, 20);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.printf("%d", fps);
tft->setCursor(width() - 50, 20);
tft->setTextColor(TFT_GREEN, TFT_BLACK);
tft->printf("%d", fps);
}
#endif
4 changes: 2 additions & 2 deletions player/src/Displays/TFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class TFT_eSPI;

class TFT: public Display {
private:
TFT_eSPI &tft;
TFT_eSPI *tft;
uint16_t *dmaBuffer[2] = {NULL, NULL};
int dmaBufferIndex = 0;
public:
TFT(TFT_eSPI &tft);
TFT();
void drawPixels(int x, int y, int width, int height, uint16_t *pixels);
void startWrite();
void endWrite();
Expand Down
3 changes: 1 addition & 2 deletions player/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ ChannelData *channelData = NULL;
#ifdef LED_MATRIX
Matrix display;
#else
TFT_eSPI tft = TFT_eSPI();
TFT display(tft);
TFT display;
#endif

void setup()
Expand Down

0 comments on commit 9e31047

Please sign in to comment.