forked from moononournation/Arduino_GFX
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArduino_SSD1283A.cpp
More file actions
184 lines (172 loc) · 4.94 KB
/
Arduino_SSD1283A.cpp
File metadata and controls
184 lines (172 loc) · 4.94 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
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
/*
* start rewrite from:
* https://github.com/adafruit/Adafruit-GFX-Library.git
* https://github.com/gitcnd/LCDWIKI_SPI.git
*/
#include "Arduino_SSD1283A.h"
#include "SPI.h"
Arduino_SSD1283A::Arduino_SSD1283A(
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_SSD1283A::begin(int32_t speed)
{
#if defined(ESP8266) || defined(ESP32)
if (speed == 0)
{
speed = 27000000;
}
#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_SSD1283A::tftInit()
{
// Initialization Sequence
_bus->beginWrite();
_bus->writeCommand16(SSD1283A_POWER_CONTROL_1);
_bus->write16(0x2F8E);
_bus->writeCommand16(SSD1283A_POWER_CONTROL_2);
_bus->write16(0x000C);
_bus->writeCommand16(SSD1283A_DISPLAY_CONTROL);
_bus->write16(0x0021);
_bus->writeCommand16(SSD1283A_VCOM_OTP_1);
_bus->write16(0x0006);
_bus->writeCommand16(SSD1283A_VCOM_OTP_1);
_bus->write16(0x0005);
_bus->writeCommand16(SSD1283A_FURTHER_BIAS_CURRENT_SETTING);
_bus->write16(0x057F);
_bus->writeCommand16(SSD1283A_VCOM_OTP_2);
_bus->write16(0x89A1);
_bus->writeCommand16(SSD1283A_OSCILLATOR);
_bus->write16(0x0001);
_bus->endWrite();
delay(100);
_bus->beginWrite();
_bus->writeCommand16(SSD1283A_VCOM_OTP_2);
_bus->write16(0x80B0);
_bus->endWrite();
delay(30);
_bus->beginWrite();
_bus->writeCommand16(SSD1283A_VCOM_OTP_2);
_bus->write16(0xFFFE);
_bus->writeCommand16(SSD1283A_DISPLAY_CONTROL);
_bus->write16(0x0223);
_bus->endWrite();
delay(30);
_bus->beginWrite();
_bus->writeCommand16(SSD1283A_DISPLAY_CONTROL);
_bus->write16(0x0233);
_bus->writeCommand16(SSD1283A_DRIVER_OUTPUT_CONTROL);
_bus->write16(0x2183);
_bus->writeCommand16(SSD1283A_ENTRY_MODE);
_bus->write16(0x6830);
_bus->writeCommand16(0x2F);
_bus->write16(0xFFFF);
_bus->writeCommand16(SSD1283A_OSCILLATOR_FREQUENCY);
_bus->write16(0x8000);
_bus->writeCommand16(SSD1283A_FURTHER_BIAS_CURRENT_SETTING);
_bus->write16(0x0570);
_bus->writeCommand16(SSD1283A_LCD_DRIVING_WAVEFORM_CONTROL);
_bus->write16(0x0300);
_bus->writeCommand16(SSD1283A_FRAME_CYCLE_CONTROL);
_bus->write16(0x580C);
_bus->writeCommand16(SSD1283A_POWER_CONTROL_3);
_bus->write16(0x0609);
_bus->writeCommand16(SSD1283A_POWER_CONTROL_4);
_bus->write16(0x3100);
_bus->endWrite();
}
void Arduino_SSD1283A::writeAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
uint8_t v1, v2, v3, h1, h2, h3;
// TODO: it works, but should have better way
switch (_rotation)
{
case 0:
v1 = y + h - 1 + _yStart;
v2 = y + _yStart;
v3 = v2;
h1 = x + w - 1 + _xStart;
h2 = x + _xStart;
h3 = h2;
break;
case 1:
v1 = x + w - 1 + _xStart;
v2 = x + _xStart;
v3 = v2;
h1 = SSD1283A_TFTWIDTH - y - 1 + _yStart;
h2 = SSD1283A_TFTWIDTH - y - h + _yStart;
h3 = h1;
break;
case 2:
v1 = SSD1283A_TFTWIDTH - y - 1 + _yStart;
v2 = SSD1283A_TFTWIDTH - y - h + _yStart;
v3 = v1;
h1 = SSD1283A_TFTHEIGHT - x - 1 + _xStart;
h2 = SSD1283A_TFTHEIGHT - x - w + _xStart;
h3 = h1;
break;
case 3:
v1 = SSD1283A_TFTHEIGHT - x - 1 + _xStart;
v2 = SSD1283A_TFTHEIGHT - x - w + _xStart;
v3 = v1;
h1 = y + h - 1 + _yStart;
h2 = y + _yStart;
h3 = h2;
break;
}
_bus->writeCommand(SSD1283A_HORIZONTAL_RAM_ADDRESS_POSITION);
_bus->write(h1);
_bus->write(h2);
_bus->writeCommand(SSD1283A_VERTICAL_RAM_ADDRESS_POSITION);
_bus->write(v1);
_bus->write(v2);
_bus->writeCommand(SSD1283A_RAM_ADDRESS_SET);
_bus->write(v3);
_bus->write(h3);
_bus->writeCommand(SSD1283A_WRITE_DATA_TO_GRAM);
}
/**************************************************************************/
/*!
@brief Set origin of (0,0) and orientation of TFT display
@param m The index for rotation, from 0-3 inclusive
*/
/**************************************************************************/
void Arduino_SSD1283A::setRotation(uint8_t r)
{
Arduino_TFT::setRotation(r);
_bus->beginWrite();
switch (_rotation)
{
case 0:
_bus->writeCommand16(SSD1283A_ENTRY_MODE);
_bus->write16(0x6830);
break;
case 1:
_bus->writeCommand16(SSD1283A_ENTRY_MODE);
_bus->write16(0x6828);
break;
case 2:
_bus->writeCommand(SSD1283A_ENTRY_MODE);
_bus->write16(0x6800);
break;
case 3:
_bus->writeCommand(SSD1283A_ENTRY_MODE);
_bus->write16(0x6818);
break;
}
_bus->endWrite();
}
void Arduino_SSD1283A::invertDisplay(bool i)
{
}
void Arduino_SSD1283A::displayOn(void)
{
}
void Arduino_SSD1283A::displayOff(void)
{
}