2018-11-03 13:30:49 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include "hardware.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "tftdisplay.h"
|
|
|
|
|
|
|
|
#if defined(USE_UTFT)
|
|
|
|
#include <UTFT.h>
|
|
|
|
#include "TinyFont.h"
|
|
|
|
|
|
|
|
static UTFT utft(TFT_MODEL, TFT_RS, TFT_WR, TFT_CS, TFT_RST);
|
|
|
|
|
|
|
|
#elif defined(USE_ESPI)
|
2018-11-05 21:34:39 +00:00
|
|
|
#pragma message "Configure TFT_eSPI in Makefile or User_Setup.h"
|
2018-11-03 13:30:49 +00:00
|
|
|
#include <TFT_eSPI.h>
|
|
|
|
|
|
|
|
static TFT_eSPI espi;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void setColor(colour_t c) {
|
|
|
|
#if defined(USE_UTFT)
|
|
|
|
utft.setColor(c);
|
|
|
|
#elif defined(USE_ESPI)
|
|
|
|
espi.setTextColor(c);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFTDisplay::begin(unsigned bg, unsigned fg, orientation_t orient) {
|
|
|
|
_bg = bg;
|
|
|
|
_fg = fg;
|
|
|
|
|
|
|
|
#if defined(USE_UTFT)
|
|
|
|
utft.InitLCD(orient);
|
|
|
|
_dx = utft.getDisplayXSize();
|
|
|
|
_dy = utft.getDisplayYSize();
|
|
|
|
|
|
|
|
utft.setFont((uint8_t *)TinyFont);
|
|
|
|
_cx = utft.getFontXsize();
|
|
|
|
_cy = utft.getFontYsize();
|
|
|
|
#elif defined(USE_ESPI)
|
|
|
|
espi.init();
|
|
|
|
espi.setRotation(orient);
|
|
|
|
_dx = espi.width();
|
|
|
|
_dy = espi.height();
|
|
|
|
_cy = espi.fontHeight();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
setColor(fg);
|
|
|
|
_oxs = _dx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFTDisplay::clear() {
|
|
|
|
#if defined(USE_UTFT)
|
|
|
|
utft.fillScr(_bg);
|
|
|
|
#elif defined(USE_ESPI)
|
|
|
|
espi.fillScreen(_bg);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFTDisplay::status(const char *s) {
|
|
|
|
setColor(_fg);
|
|
|
|
|
|
|
|
#if defined(USE_UTFT)
|
|
|
|
unsigned y = _dy - _cy, n = strlen(s), xs = _dx - n*_cx;
|
|
|
|
for (unsigned x = _oxs; x < xs; x += _cx)
|
|
|
|
utft.print(" ", x, y);
|
|
|
|
utft.print(s, xs, y);
|
|
|
|
_oxs = xs;
|
|
|
|
#elif defined(USE_ESPI)
|
2018-11-10 13:34:36 +00:00
|
|
|
espi.fillRect(_dx - _oxs, _dy - _cy, _oxs, _cy, _bg);
|
2018-11-03 13:30:49 +00:00
|
|
|
_oxs = espi.textWidth(s);
|
2018-11-10 13:34:36 +00:00
|
|
|
espi.setTextDatum(BR_DATUM);
|
|
|
|
espi.drawString(s, _dx, _dy);
|
2018-11-03 13:30:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFTDisplay::drawPixel(unsigned x, unsigned y, colour_t col) {
|
|
|
|
#if defined(USE_UTFT)
|
|
|
|
utft.setColor(col);
|
|
|
|
utft.drawPixel(x, y);
|
|
|
|
#elif defined(USE_ESPI)
|
2018-11-10 13:34:36 +00:00
|
|
|
espi.drawPixel(x, y, col);
|
2018-11-03 13:30:49 +00:00
|
|
|
#endif
|
|
|
|
}
|