-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtftdisplay.cpp
More file actions
69 lines (52 loc) · 1.38 KB
/
tftdisplay.cpp
File metadata and controls
69 lines (52 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdint.h>
#include "hardware.h"
#include "memory.h"
#include "tftdisplay.h"
#include <TFT_eSPI.h>
static TFT_eSPI tft;
static TFT_eSprite espi = TFT_eSprite(&tft); // used as a framebuffer
static inline void setColor(colour_t c) {
espi.setTextColor(c);
}
void TFTDisplay::begin(unsigned bg, unsigned fg, orientation_t orient, unsigned w, unsigned h) {
_bg = bg;
_fg = fg;
tft.init();
tft.setRotation(orient);
tft.fillScreen(bg);
_dx = tft.width();
_dy = tft.height();
_cy = tft.fontHeight();
_cx = 6; // FIXME
_xoff = (_dx - w) / 2;
_yoff = (_dy - h) / 2;
setColor(fg);
_oxs = _dx;
espi.setColorDepth(8);
espi.createSprite(w,h); // framebuffer
}
void TFTDisplay::clear() {
espi.fillScreen(_bg);
}
void TFTDisplay::status(const char *s) {
setColor(_fg);
espi.fillRect(_dx - _oxs, _dy - _cy, _oxs, _cy, _bg);
_oxs = espi.textWidth(s);
espi.setTextDatum(BR_DATUM);
espi.drawString(s, _dx, _dy);
}
void TFTDisplay::drawPixel(unsigned x, unsigned y, colour_t col) {
espi.drawPixel(x, y, col);
}
void TFTDisplay::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t* data) {
espi.pushImage(x,y,w,h,data);
}
void TFTDisplay::drawString(const char *s, unsigned x, unsigned y) {
espi.setTextDatum(TL_DATUM);
unsigned w = espi.textWidth(s);
espi.fillRect(x, y, w, _cy, _bg);
espi.drawString(s, x, y);
}
void TFTDisplay::flush() {
espi.pushSprite(_xoff,_yoff);
}