forked from moononournation/Arduino_GFX
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArduino_SEPS525.cpp
213 lines (189 loc) · 5.3 KB
/
Arduino_SEPS525.cpp
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* start rewrite from:
* https://github.com/adafruit/Adafruit-GFX-Library.git
*/
#include "Arduino_SEPS525.h"
#include "SPI.h"
Arduino_SEPS525::Arduino_SEPS525(
Arduino_DataBus *bus, int8_t rst, uint8_t r, int16_t w, int16_t h,
uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2)
: Arduino_TFT(bus, rst, r, false, w, h, col_offset1, row_offset1, col_offset2, row_offset2)
{
}
void Arduino_SEPS525::begin(int speed)
{
#if defined(ESP8266) || defined(ESP32)
if (speed == 0)
{
speed = 40000000;
}
#endif
Arduino_TFT::begin(speed);
}
// Companion code to the above tables. Reads and issues
// a series of LCD commands stored in PROGMEM byte array.
void Arduino_SEPS525::tftInit()
{
if (_rst < 0)
{
_bus->sendCommand(SEPS525_SOFT_RST);
_bus->sendData(0x01);
delay(SEPS525_RST_DELAY);
}
_bus->sendCommand(SEPS525_REDUCE_CURRENT);
_bus->sendData(0x01);
delay(1);
// normal mode
_bus->sendCommand(SEPS525_REDUCE_CURRENT);
_bus->sendData(0x00);
delay(1);
// display off
_bus->sendCommand(SEPS525_DISP_ON_OFF);
_bus->sendData(0x00);
// turn on internal oscillator using external resistor
_bus->sendCommand(SEPS525_OSC_CTL);
_bus->sendData(0x01);
// 90 hz frame rate, divider 0
_bus->sendCommand(SEPS525_CLOCK_DIV);
_bus->sendData(0x30);
// duty cycle 127
_bus->sendCommand(0x28);
_bus->sendData(0x7f);
// start on line 0
_bus->sendCommand(0x29);
_bus->sendData(0x00);
// rgb_if
_bus->sendCommand(SEPS525_RGB_IF);
_bus->sendData(0x31);
// driving current r g b (uA)
_bus->sendCommand(SEPS525_DRIVING_CURRENT_R);
_bus->sendData(0x45);
_bus->sendCommand(SEPS525_DRIVING_CURRENT_G);
_bus->sendData(0x34);
_bus->sendCommand(SEPS525_DRIVING_CURRENT_B);
_bus->sendData(0x33);
// precharge time r g b
_bus->sendCommand(SEPS525_PRECHARGE_TIME_R);
_bus->sendData(0x04);
_bus->sendCommand(SEPS525_PRECHARGE_TIME_G);
_bus->sendData(0x05);
_bus->sendCommand(SEPS525_PRECHARGE_TIME_B);
_bus->sendData(0x05);
// precharge current r g b (uA)
_bus->sendCommand(SEPS525_PRECHARGE_CURRENT_R);
_bus->sendData(0x9d);
_bus->sendCommand(SEPS525_PRECHARGE_CURRENT_G);
_bus->sendData(0x8c);
_bus->sendCommand(SEPS525_PRECHARGE_CURRENT_B);
_bus->sendData(0x57);
_bus->sendCommand(SEPS525_IREF);
_bus->sendData(0x00);
// display on
_bus->sendCommand(SEPS525_DISP_ON_OFF);
_bus->sendData(0x01);
}
void Arduino_SEPS525::writeAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
uint8_t cmd1, cmd2, cmd3;
if ((x != _currentX) || (w != _currentW))
{
uint16_t x_start = x + _xStart, x_end = x + w - 1 + _xStart;
if (_rotation & 0x01) // Portrait
{
cmd1 = SEPS525_MY1_ADDR;
cmd2 = SEPS525_M_AP_Y;
cmd3 = SEPS525_MY2_ADDR;
}
else
{
cmd1 = SEPS525_MX1_ADDR;
cmd2 = SEPS525_M_AP_X;
cmd3 = SEPS525_MX2_ADDR;
}
_bus->writeCommand(cmd1);
_bus->write16(x_start);
_bus->writeCommand(cmd2);
_bus->write16(x_start);
_bus->writeCommand(cmd3);
_bus->write16(x_end);
_currentX = x;
_currentW = w;
}
if ((y != _currentY) || (h != _currentH))
{
uint16_t y_start = y + _yStart, y_end = y + h - 1 + _yStart;
if (_rotation & 0x01) // Portrait
{
cmd1 = SEPS525_MX1_ADDR;
cmd2 = SEPS525_M_AP_X;
cmd3 = SEPS525_MX2_ADDR;
}
else
{
cmd1 = SEPS525_MY1_ADDR;
cmd2 = SEPS525_M_AP_Y;
cmd3 = SEPS525_MY2_ADDR;
}
_bus->writeCommand(cmd1);
_bus->write16(y_start);
_bus->writeCommand(cmd2);
_bus->write16(y_start);
_bus->writeCommand(cmd3);
_bus->write16(y_end);
_currentY = y;
_currentH = h;
}
_bus->writeCommand(SEPS525_RAMWR); // write to RAM
}
/**************************************************************************/
/*!
@brief Set origin of (0,0) and orientation of TFT display
@param m The index for rotation, from 0-3 inclusive
*/
/**************************************************************************/
void Arduino_SEPS525::setRotation(uint8_t r)
{
Arduino_TFT::setRotation(r);
uint8_t startline = (_rotation < 2) ? HEIGHT : 0;
switch (_rotation)
{
case 0:
_bus->sendCommand(SEPS525_DISPLAY_MODE_SET);
_bus->sendData(0x00);
_bus->sendCommand(SEPS525_MEMORY_WRITE_MODE);
_bus->sendData(0x66);
break;
case 1:
_bus->sendCommand(SEPS525_DISPLAY_MODE_SET);
_bus->sendData(0x10);
_bus->sendCommand(SEPS525_MEMORY_WRITE_MODE);
_bus->sendData(0x67);
break;
case 2:
_bus->sendCommand(SEPS525_DISPLAY_MODE_SET);
_bus->sendData(0x30);
_bus->sendCommand(SEPS525_MEMORY_WRITE_MODE);
_bus->sendData(0x66);
break;
case 3:
_bus->sendCommand(SEPS525_DISPLAY_MODE_SET);
_bus->sendData(0x20);
_bus->sendCommand(SEPS525_MEMORY_WRITE_MODE);
_bus->sendData(0x67);
break;
}
}
void Arduino_SEPS525::invertDisplay(bool i)
{
// Not Implemented
}
void Arduino_SEPS525::displayOn(void)
{
_bus->sendCommand(SEPS525_DISP_ON_OFF);
_bus->sendData(0x01);
}
void Arduino_SEPS525::displayOff(void)
{
_bus->sendCommand(SEPS525_DISP_ON_OFF);
_bus->sendData(0x00);
}