1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-10-10 10:23:49 +00:00
r65emu/tftdisplay.cpp

105 lines
2.1 KiB
C++
Raw Normal View History

2018-11-03 13:30:49 +00:00
#include <stdint.h>
#include "hardware.h"
#include "memory.h"
#include "tftdisplay.h"
#if defined(USE_UTFT)
2020-07-08 13:33:31 +00:00
#pragma message "UTFT configured"
2018-11-03 13:30:49 +00:00
#include <UTFT.h>
#include "TinyFont.h"
2019-03-03 14:38:47 +00:00
#if !defined(TFT_SER)
#define TFT_SER 0
#endif
static UTFT utft(TFT_MODEL, TFT_RS, TFT_WR, TFT_CS, TFT_RST, TFT_SER);
2018-11-03 13:30:49 +00:00
#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;
2020-07-08 13:33:31 +00:00
#else
#pragma error "Display not configured!"
2018-11-03 13:30:49 +00:00
#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();
2020-07-08 13:33:31 +00:00
2018-11-03 13:30:49 +00:00
#elif defined(USE_ESPI)
espi.init();
espi.setRotation(orient);
_dx = espi.width();
_dy = espi.height();
_cy = espi.fontHeight();
2018-11-12 22:18:44 +00:00
_cx = 6; // FIXME
2018-11-03 13:30:49 +00:00
#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
}
2018-11-12 07:46:21 +00:00
void TFTDisplay::drawString(const char *s, unsigned x, unsigned y) {
#if defined(USE_UTFT)
utft.print(s, x, y);
#elif defined(USE_ESPI)
2018-11-12 22:18:44 +00:00
espi.setTextDatum(TL_DATUM);
unsigned w = espi.textWidth(s);
espi.fillRect(x, y, w, _cy, _bg);
2018-11-12 07:46:21 +00:00
espi.drawString(s, x, y);
#endif
}