forked from zxfr/Pixels
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPixels_SSD1289.h
More file actions
191 lines (163 loc) · 5.38 KB
/
Pixels_SSD1289.h
File metadata and controls
191 lines (163 loc) · 5.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
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
/*
* Pixels. Graphics library for TFT displays.
*
* Copyright (C) 2012-2013 Igor Repinetski
*
* The code is written in C/C++ for Arduino and can be easily ported to any microcontroller by rewritting the low level pin access functions.
*
* Text output methods of the library rely on Pixelmeister's font data format. See: http://pd4ml.com/pixelmeister
*
* This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* This library includes some code portions and algoritmic ideas derived from works of
* - Andreas Schiffler -- aschiffler at ferzkopp dot net (SDL_gfx Project)
* - K. Townsend http://microBuilder.eu (lpc1343codebase Project)
*/
/*
* Pixels port to SSD1289 controller, PPI16 mode (TFT_320QVT)
*/
#include "Pixels.h"
#ifndef PIXELS_SSD1289_H
#define PIXELS_SSD1289_H
#define PIXELS_MAIN
#if defined(PIXELS_ANTIALIASING_H)
#define PixelsBase PixelsAntialiased
#endif
class Pixels : public PixelsBase
#if defined(PIXELS_SPISW_H)
, public SPIsw
#elif defined(PIXELS_SPIHW_H)
, public SPIhw
#elif defined(PIXELS_PPI8_H)
, public PPI8
#elif defined(PIXELS_PPI16_H)
, public PPI16
#endif
{
protected:
void deviceWriteData(uint8_t high, uint8_t low) {
writeData(high, low);
}
int32_t setRegion(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
void quickFill(int b, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
void setFillDirection(uint8_t direction);
void scrollCmd();
public:
Pixels() : PixelsBase(240, 320) { // ElecFreaks TFT2.2SP shield as default
scrollSupported = true;
setSpiPins(4, 3, 7, 5, 6); // dummy code in PPI case
setPpiPins(38, 39, 40, 41, 0); // dummy code in SPI case
}
Pixels(uint16_t width, uint16_t height) : PixelsBase(width, height) {
scrollSupported = true;
setSpiPins(4, 3, 7, 5, 6); // dummy code in PPI case
setPpiPins(38, 39, 40, 41, 0); // dummy code in SPI case
}
void init();
};
#if defined(PIXELS_ANTIALIASING_H)
#undef PixelsBase
#endif
void Pixels::init() {
initInterface();
chipSelect();
writeCmdData(0x00,0x0001);
writeCmdData(0x03,0xA8A4);
writeCmdData(0x0C,0x0000);
writeCmdData(0x0D,0x080C);
writeCmdData(0x0E,0x2B00);
writeCmdData(0x1E,0x00B7);
writeCmdData(0x01,0x2B3F);
writeCmdData(0x02,0x0600);
writeCmdData(0x10,0x0000);
writeCmdData(0x11,0x6070);
writeCmdData(0x05,0x0000);
writeCmdData(0x06,0x0000);
writeCmdData(0x16,0xEF1C);
writeCmdData(0x17,0x0003);
writeCmdData(0x07,0x0233);
writeCmdData(0x0B,0x0000);
writeCmdData(0x0F,0x0000);
writeCmdData(0x41,0x0000);
writeCmdData(0x42,0x0000);
writeCmdData(0x48,0x0000);
writeCmdData(0x49,0x013F);
writeCmdData(0x4A,0x0000);
writeCmdData(0x4B,0x0000);
writeCmdData(0x44,0xEF00);
writeCmdData(0x45,0x0000);
writeCmdData(0x46,0x013F);
writeCmdData(0x30,0x0707);
writeCmdData(0x31,0x0204);
writeCmdData(0x32,0x0204);
writeCmdData(0x33,0x0502);
writeCmdData(0x34,0x0507);
writeCmdData(0x35,0x0204);
writeCmdData(0x36,0x0204);
writeCmdData(0x37,0x0502);
writeCmdData(0x3A,0x0302);
writeCmdData(0x3B,0x0302);
writeCmdData(0x23,0x0000);
writeCmdData(0x24,0x0000);
writeCmdData(0x25,0x8000);
writeCmdData(0x4f,0x0000);
writeCmdData(0x4e,0x0000);
writeCmd(0x22);
chipDeselect();
}
void Pixels::scrollCmd() {
int16_t s = (orientation > 1 ? deviceHeight - currentScroll : currentScroll) % deviceHeight;
writeCmd(0x41);
deviceWriteData(highByte(s), lowByte(s));
}
void Pixels::setFillDirection(uint8_t direction) {
fillDirection = direction;
}
void Pixels::quickFill (int color, int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
int32_t counter = setRegion(x1, y1, x2, y2);
if( counter == 0 ) {
return;
}
uint8_t lo = lowByte(color);
uint8_t hi = highByte(color);
registerSelect();
for (int16_t i = 0; i < counter / 20; i++) {
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
writeData(hi, lo);
}
for (int32_t i = 0; i < counter % 20; i++) {
writeData(hi, lo);
}
}
int32_t Pixels::setRegion(int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
Bounds bb(x1, y1, x2, y2);
if( !checkBounds(bb) ) {
return 0;
}
writeCmdData(0x44,(bb.x2<<8)+bb.x1);
writeCmdData(0x45,bb.y1);
writeCmdData(0x46,bb.y2);
writeCmdData(0x4e,bb.x1);
writeCmdData(0x4f,bb.y1);
writeCmd(0x22);
return (int32_t)(bb.x2 - bb.x1 + 1) * (bb.y2 - bb.y1 + 1);
}
#endif