-
Notifications
You must be signed in to change notification settings - Fork 4
/
TFT_HX8357GLUE.h
164 lines (145 loc) · 4.39 KB
/
TFT_HX8357GLUE.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// NOT FOR PUBLIC USE
#define HX8357_BLACK 0x0000
#define HX8357_BLUE 0x001F
#define HX8357_RED 0xF800
#define HX8357_GREEN 0x07E0
#define HX8357_CYAN 0x07FF
#define HX8357_MAGENTA 0xF81F
#define HX8357_YELLOW 0xFFE0
#define HX8357_WHITE 0xFFFF
//#include <Adafruit_GFX.h> // Core graphics library
#include <MCUFRIEND_kbv.h> // Hardware-specific library
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSans18pt7b.h>
#include <Fonts/FreeSerifItalic12pt7b.h>
#include <Fonts/FreeMonoBold24pt7b.h>
const GFXfont *Fonts[] = {
NULL,
NULL,
&FreeSans9pt7b,
NULL,
&FreeSans12pt7b,
NULL,
&FreeSans18pt7b,
&FreeSerifItalic12pt7b,
&FreeMonoBold24pt7b,
};
#define TFT_BLACK 0x0000
#define TFT_NAVY 0x000F
#define TFT_DARKGREEN 0x03E0
#define TFT_DARKCYAN 0x03EF
#define TFT_MAROON 0x7800
#define TFT_PURPLE 0x780F
#define TFT_OLIVE 0x7BE0
#define TFT_LIGHTGREY 0xC618
#define TFT_DARKGREY 0x7BEF
#define TFT_BLUE 0x001F
#define TFT_GREEN 0x07E0
#define TFT_CYAN 0x07FF
#define TFT_RED 0xF800
#define TFT_MAGENTA 0xF81F
#define TFT_YELLOW 0xFFE0
#define TFT_WHITE 0xFFFF
#define TFT_ORANGE 0xFD20
#define TFT_GREENYELLOW 0xAFE5
#define TFT_PINK 0xF81F
#define MC_DATUM 4
class TFT_HX8357GLUE : public MCUFRIEND_kbv
{
public:
TFT_HX8357GLUE() {}
void begin(void) {
init();
}
void init(void)
{
MCUFRIEND_kbv::reset();
_ID = MCUFRIEND_kbv::readID();
if (_ID == 0x00D3 || _ID == 0xD3D3)
_ID = 0x9486;
MCUFRIEND_kbv::begin(_ID);
MCUFRIEND_kbv::setRotation(1);
_first = true;
}
void setWindow(int16_t x0, int16_t y0, int16_t x1, int16_t y1)
{
MCUFRIEND_kbv::setAddrWindow(x0, y0, x1, y1);
_first = true;
}
void pushColors(uint8_t *data, uint16_t len)
{
MCUFRIEND_kbv::pushColors((uint8_t*)data, len, _first);
_first = false;
}
void pushColors(uint16_t *data, uint8_t len)
{
MCUFRIEND_kbv::pushColors((uint16_t*)data, len, _first);
_first = false;
}
void pushColor(uint16_t color)
{
uint16_t c = color;
MCUFRIEND_kbv::pushColors(&c, 1, _first);
_first = false;
}
void setCursor(int16_t x, int16_t y)
{
setCursor(x, y, _font);
}
void setCursor(int16_t x, int16_t y, uint8_t idx)
{
const GFXfont *f = Fonts[idx];
MCUFRIEND_kbv::setFont(f);
// MCUFRIEND_kbv::setCursor(x, y + f->glyph->height);
MCUFRIEND_kbv::setCursor(x, y);
}
void setTextFont(uint8_t font)
{
_font = font;
MCUFRIEND_kbv::setFont(Fonts[_font]);
}
int16_t drawNumber(long long_num, int16_t poX, int16_t poY, int16_t idx)
{
char buf[12];
ltoa(long_num, buf, 10);
return drawString(buf, poX, poY, idx);
}
int16_t drawChar(char c, int16_t poX, int16_t poY, int16_t idx)
{
char buf[2];
buf[0] = c;
buf[1] = 0;
return drawString(buf, poX, poY, idx);
}
int16_t drawString(char *string, int16_t poX, int16_t poY, int16_t idx)
{
int16_t x1, y1;
uint16_t w, h;
setFont(Fonts[_font = idx]);
getTextBounds(string, poX, poY, &x1, &y1, &w, &h);
fillRect(x1, y1 + h, w, h, 0x0000);
MCUFRIEND_kbv::setCursor(poX, poY + h);
print(string);
return w;
}
int16_t drawCentreString(char *string, int16_t poX, int16_t poY, int16_t idx)
{
int16_t x1, y1;
uint16_t w, h;
setFont(Fonts[_font = idx]);
getTextBounds(string, poX, poY, &x1, &y1, &w, &h);
poX -= w/2;
x1 -= w/2;
fillRect(x1, y1 + h, w, h, 0x0000);
MCUFRIEND_kbv::setCursor(poX, poY + h);
print(string);
return w;
// return drawString(string, dX, poY, idx);
}
void setTextDatum(uint8_t datum) { ; }
void setTextPadding(uint16_t x_width) { ; }
private:
uint16_t _ID;
uint8_t _font, _first;
};