upm  0.1.8
Sensor/Actuator repository for libmraa (v0.4.5)
 All Data Structures Files Functions Variables Macros Pages
st7735.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Credits to Adafruit.
6  * Based on Adafruit ST7735 library, see original license in license.txt file.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #pragma once
28 
29 #include <string>
30 #include <mraa/aio.h>
31 #include <mraa/gpio.h>
32 #include <mraa/spi.h>
33 #include <gfx.h>
34 
35 #define INITR_GREENTAB 0x0
36 #define INITR_REDTAB 0x1
37 #define INITR_BLACKTAB 0x2
38 
39 #define ST7735_TFTWIDTH 128
40 #define ST7735_TFTHEIGHT 160
41 
42 #define ST7735_NOP 0x00
43 #define ST7735_SWRESET 0x01
44 #define ST7735_RDDID 0x04
45 #define ST7735_RDDST 0x09
46 
47 #define ST7735_SLPIN 0x10
48 #define ST7735_SLPOUT 0x11
49 #define ST7735_PTLON 0x12
50 #define ST7735_NORON 0x13
51 
52 #define ST7735_INVOFF 0x20
53 #define ST7735_INVON 0x21
54 #define ST7735_DISPOFF 0x28
55 #define ST7735_DISPON 0x29
56 #define ST7735_CASET 0x2A
57 #define ST7735_RASET 0x2B
58 #define ST7735_RAMWR 0x2C
59 #define ST7735_RAMRD 0x2E
60 
61 #define ST7735_PTLAR 0x30
62 #define ST7735_COLMOD 0x3A
63 #define ST7735_MADCTL 0x36
64 
65 #define ST7735_FRMCTR1 0xB1
66 #define ST7735_FRMCTR2 0xB2
67 #define ST7735_FRMCTR3 0xB3
68 #define ST7735_INVCTR 0xB4
69 #define ST7735_DISSET5 0xB6
70 
71 #define ST7735_PWCTR1 0xC0
72 #define ST7735_PWCTR2 0xC1
73 #define ST7735_PWCTR3 0xC2
74 #define ST7735_PWCTR4 0xC3
75 #define ST7735_PWCTR5 0xC4
76 #define ST7735_VMCTR1 0xC5
77 
78 #define ST7735_RDID1 0xDA
79 #define ST7735_RDID2 0xDB
80 #define ST7735_RDID3 0xDC
81 #define ST7735_RDID4 0xDD
82 
83 #define ST7735_PWCTR6 0xFC
84 
85 #define ST7735_GMCTRP1 0xE0
86 #define ST7735_GMCTRN1 0xE1
87 
88 // Color definitions
89 #define ST7735_BLACK 0x0000
90 #define ST7735_BLUE 0x001F
91 #define ST7735_RED 0xF800
92 #define ST7735_GREEN 0x07E0
93 #define ST7735_CYAN 0x07FF
94 #define ST7735_MAGENTA 0xF81F
95 #define ST7735_YELLOW 0xFFE0
96 #define ST7735_WHITE 0xFFFF
97 
98 #define HIGH 1
99 #define LOW 0
100 
101 #define DELAY 0x80
102 
103 namespace upm {
104 
105 static const uint8_t Bcmd[] = {
106  // Initialization commands for 7735B screens
107  18, // 18 commands in list:
108  ST7735_SWRESET, DELAY, // 1: Software reset, no args, w/delay
109  50, // 50 ms delay
110  ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, no args, w/delay
111  255, // 255 = 500 ms delay
112  ST7735_COLMOD , 1+DELAY, // 3: Set color mode, 1 arg + delay:
113  0x05, // 16-bit color
114  10, // 10 ms delay
115  ST7735_FRMCTR1, 3+DELAY, // 4: Frame rate control, 3 args + delay:
116  0x00, // fastest refresh
117  0x06, // 6 lines front porch
118  0x03, // 3 lines back porch
119  10, // 10 ms delay
120  ST7735_MADCTL , 1 , // 5: Memory access ctrl (directions), 1 arg:
121  0x08, // Row addr/col addr, bottom to top refresh
122  ST7735_DISSET5, 2 , // 6: Display settings #5, 2 args, no delay:
123  0x15, // 1 clk cycle nonoverlap, 2 cycle gate
124  // rise, 3 cycle osc equalize
125  0x02, // Fix on VTL
126  ST7735_INVCTR , 1 , // 7: Display inversion control, 1 arg:
127  0x0, // Line inversion
128  ST7735_PWCTR1 , 2+DELAY, // 8: Power control, 2 args + delay:
129  0x02, // GVDD = 4.7V
130  0x70, // 1.0uA
131  10, // 10 ms delay
132  ST7735_PWCTR2 , 1 , // 9: Power control, 1 arg, no delay:
133  0x05, // VGH = 14.7V, VGL = -7.35V
134  ST7735_PWCTR3 , 2 , // 10: Power control, 2 args, no delay:
135  0x01, // Opamp current small
136  0x02, // Boost frequency
137  ST7735_VMCTR1 , 2+DELAY, // 11: Power control, 2 args + delay:
138  0x3C, // VCOMH = 4V
139  0x38, // VCOML = -1.1V
140  10, // 10 ms delay
141  ST7735_PWCTR6 , 2 , // 12: Power control, 2 args, no delay:
142  0x11, 0x15,
143  ST7735_GMCTRP1,16 , // 13: Magical unicorn dust, 16 args, no delay:
144  0x09, 0x16, 0x09, 0x20, // (seriously though, not sure what
145  0x21, 0x1B, 0x13, 0x19, // these config values represent)
146  0x17, 0x15, 0x1E, 0x2B,
147  0x04, 0x05, 0x02, 0x0E,
148  ST7735_GMCTRN1,16+DELAY, // 14: Sparkles and rainbows, 16 args + delay:
149  0x0B, 0x14, 0x08, 0x1E, // (ditto)
150  0x22, 0x1D, 0x18, 0x1E,
151  0x1B, 0x1A, 0x24, 0x2B,
152  0x06, 0x06, 0x02, 0x0F,
153  10, // 10 ms delay
154  ST7735_CASET , 4 , // 15: Column addr set, 4 args, no delay:
155  0x00, 0x02, // XSTART = 2
156  0x00, 0x81, // XEND = 129
157  ST7735_RASET , 4 , // 16: Row addr set, 4 args, no delay:
158  0x00, 0x02, // XSTART = 1
159  0x00, 0x81, // XEND = 160
160  ST7735_NORON , DELAY, // 17: Normal display on, no args, w/delay
161  10, // 10 ms delay
162  ST7735_DISPON , DELAY, // 18: Main screen turn on, no args, w/delay
163  255 }, // 255 = 500 ms delay
164 
165  Rcmd1[] = { // Init for 7735R, part 1 (red or green tab)
166  15, // 15 commands in list:
167  ST7735_SWRESET, DELAY, // 1: Software reset, 0 args, w/delay
168  150, // 150 ms delay
169  ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, 0 args, w/delay
170  255, // 500 ms delay
171  ST7735_FRMCTR1, 3 , // 3: Frame rate ctrl - normal mode, 3 args:
172  0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
173  ST7735_FRMCTR2, 3 , // 4: Frame rate control - idle mode, 3 args:
174  0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
175  ST7735_FRMCTR3, 6 , // 5: Frame rate ctrl - partial mode, 6 args:
176  0x01, 0x2C, 0x2D, // Dot inversion mode
177  0x01, 0x2C, 0x2D, // Line inversion mode
178  ST7735_INVCTR , 1 , // 6: Display inversion ctrl, 1 arg, no delay:
179  0x07, // No inversion
180  ST7735_PWCTR1 , 3 , // 7: Power control, 3 args, no delay:
181  0xA2,
182  0x02, // -4.6V
183  0x84, // AUTO mode
184  ST7735_PWCTR2 , 1 , // 8: Power control, 1 arg, no delay:
185  0xC5, // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD
186  ST7735_PWCTR3 , 2 , // 9: Power control, 2 args, no delay:
187  0x0A, // Opamp current small
188  0x00, // Boost frequency
189  ST7735_PWCTR4 , 2 , // 10: Power control, 2 args, no delay:
190  0x8A, // BCLK/2, Opamp current small & Medium low
191  0x2A,
192  ST7735_PWCTR5 , 2 , // 11: Power control, 2 args, no delay:
193  0x8A, 0xEE,
194  ST7735_VMCTR1 , 1 , // 12: Power control, 1 arg, no delay:
195  0x0E,
196  ST7735_INVOFF , 0 , // 13: Don't invert display, no args, no delay
197  ST7735_MADCTL , 1 , // 14: Memory access control (directions), 1 arg:
198  0xC8, // row addr/col addr, bottom to top refresh
199  ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay:
200  0x05 }, // 16-bit color
201 
202  Rcmd2green[] = { // Init for 7735R, part 2 (green tab only)
203  2, // 2 commands in list:
204  ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay:
205  0x00, 0x02, // XSTART = 0
206  0x00, 0x7F+0x02, // XEND = 127
207  ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay:
208  0x00, 0x01, // XSTART = 0
209  0x00, 0x9F+0x01 }, // XEND = 159
210  Rcmd2red[] = { // Init for 7735R, part 2 (red tab only)
211  2, // 2 commands in list:
212  ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay:
213  0x00, 0x00, // XSTART = 0
214  0x00, 0x7F, // XEND = 127
215  ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay:
216  0x00, 0x00, // XSTART = 0
217  0x00, 0x9F }, // XEND = 159
218 
219  Rcmd3[] = { // Init for 7735R, part 3 (red or green tab)
220  4, // 4 commands in list:
221  ST7735_GMCTRP1, 16 , // 1: Magical unicorn dust, 16 args, no delay:
222  0x02, 0x1c, 0x07, 0x12,
223  0x37, 0x32, 0x29, 0x2d,
224  0x29, 0x25, 0x2B, 0x39,
225  0x00, 0x01, 0x03, 0x10,
226  ST7735_GMCTRN1, 16 , // 2: Sparkles and rainbows, 16 args, no delay:
227  0x03, 0x1d, 0x07, 0x06,
228  0x2E, 0x2C, 0x29, 0x2D,
229  0x2E, 0x2E, 0x37, 0x3F,
230  0x00, 0x00, 0x02, 0x10,
231  ST7735_NORON , DELAY, // 3: Normal display on, no args, w/delay
232  10, // 10 ms delay
233  ST7735_DISPON , DELAY, // 4: Main screen turn on, no args w/delay
234  100 }; // 100 ms delay
235 
236 #define swap(a, b) { int16_t t = a; a = b; b = t; }
237 
238 const unsigned char font[] = {
239  0x00, 0x00, 0x00, 0x00, 0x00,
240  0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
241  0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
242  0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
243  0x18, 0x3C, 0x7E, 0x3C, 0x18,
244  0x1C, 0x57, 0x7D, 0x57, 0x1C,
245  0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
246  0x00, 0x18, 0x3C, 0x18, 0x00,
247  0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
248  0x00, 0x18, 0x24, 0x18, 0x00,
249  0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
250  0x30, 0x48, 0x3A, 0x06, 0x0E,
251  0x26, 0x29, 0x79, 0x29, 0x26,
252  0x40, 0x7F, 0x05, 0x05, 0x07,
253  0x40, 0x7F, 0x05, 0x25, 0x3F,
254  0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
255  0x7F, 0x3E, 0x1C, 0x1C, 0x08,
256  0x08, 0x1C, 0x1C, 0x3E, 0x7F,
257  0x14, 0x22, 0x7F, 0x22, 0x14,
258  0x5F, 0x5F, 0x00, 0x5F, 0x5F,
259  0x06, 0x09, 0x7F, 0x01, 0x7F,
260  0x00, 0x66, 0x89, 0x95, 0x6A,
261  0x60, 0x60, 0x60, 0x60, 0x60,
262  0x94, 0xA2, 0xFF, 0xA2, 0x94,
263  0x08, 0x04, 0x7E, 0x04, 0x08,
264  0x10, 0x20, 0x7E, 0x20, 0x10,
265  0x08, 0x08, 0x2A, 0x1C, 0x08,
266  0x08, 0x1C, 0x2A, 0x08, 0x08,
267  0x1E, 0x10, 0x10, 0x10, 0x10,
268  0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
269  0x30, 0x38, 0x3E, 0x38, 0x30,
270  0x06, 0x0E, 0x3E, 0x0E, 0x06,
271  0x00, 0x00, 0x00, 0x00, 0x00,
272  0x00, 0x00, 0x5F, 0x00, 0x00,
273  0x00, 0x07, 0x00, 0x07, 0x00,
274  0x14, 0x7F, 0x14, 0x7F, 0x14,
275  0x24, 0x2A, 0x7F, 0x2A, 0x12,
276  0x23, 0x13, 0x08, 0x64, 0x62,
277  0x36, 0x49, 0x56, 0x20, 0x50,
278  0x00, 0x08, 0x07, 0x03, 0x00,
279  0x00, 0x1C, 0x22, 0x41, 0x00,
280  0x00, 0x41, 0x22, 0x1C, 0x00,
281  0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
282  0x08, 0x08, 0x3E, 0x08, 0x08,
283  0x00, 0x80, 0x70, 0x30, 0x00,
284  0x08, 0x08, 0x08, 0x08, 0x08,
285  0x00, 0x00, 0x60, 0x60, 0x00,
286  0x20, 0x10, 0x08, 0x04, 0x02,
287  0x3E, 0x51, 0x49, 0x45, 0x3E,
288  0x00, 0x42, 0x7F, 0x40, 0x00,
289  0x72, 0x49, 0x49, 0x49, 0x46,
290  0x21, 0x41, 0x49, 0x4D, 0x33,
291  0x18, 0x14, 0x12, 0x7F, 0x10,
292  0x27, 0x45, 0x45, 0x45, 0x39,
293  0x3C, 0x4A, 0x49, 0x49, 0x31,
294  0x41, 0x21, 0x11, 0x09, 0x07,
295  0x36, 0x49, 0x49, 0x49, 0x36,
296  0x46, 0x49, 0x49, 0x29, 0x1E,
297  0x00, 0x00, 0x14, 0x00, 0x00,
298  0x00, 0x40, 0x34, 0x00, 0x00,
299  0x00, 0x08, 0x14, 0x22, 0x41,
300  0x14, 0x14, 0x14, 0x14, 0x14,
301  0x00, 0x41, 0x22, 0x14, 0x08,
302  0x02, 0x01, 0x59, 0x09, 0x06,
303  0x3E, 0x41, 0x5D, 0x59, 0x4E,
304  0x7C, 0x12, 0x11, 0x12, 0x7C,
305  0x7F, 0x49, 0x49, 0x49, 0x36,
306  0x3E, 0x41, 0x41, 0x41, 0x22,
307  0x7F, 0x41, 0x41, 0x41, 0x3E,
308  0x7F, 0x49, 0x49, 0x49, 0x41,
309  0x7F, 0x09, 0x09, 0x09, 0x01,
310  0x3E, 0x41, 0x41, 0x51, 0x73,
311  0x7F, 0x08, 0x08, 0x08, 0x7F,
312  0x00, 0x41, 0x7F, 0x41, 0x00,
313  0x20, 0x40, 0x41, 0x3F, 0x01,
314  0x7F, 0x08, 0x14, 0x22, 0x41,
315  0x7F, 0x40, 0x40, 0x40, 0x40,
316  0x7F, 0x02, 0x1C, 0x02, 0x7F,
317  0x7F, 0x04, 0x08, 0x10, 0x7F,
318  0x3E, 0x41, 0x41, 0x41, 0x3E,
319  0x7F, 0x09, 0x09, 0x09, 0x06,
320  0x3E, 0x41, 0x51, 0x21, 0x5E,
321  0x7F, 0x09, 0x19, 0x29, 0x46,
322  0x26, 0x49, 0x49, 0x49, 0x32,
323  0x03, 0x01, 0x7F, 0x01, 0x03,
324  0x3F, 0x40, 0x40, 0x40, 0x3F,
325  0x1F, 0x20, 0x40, 0x20, 0x1F,
326  0x3F, 0x40, 0x38, 0x40, 0x3F,
327  0x63, 0x14, 0x08, 0x14, 0x63,
328  0x03, 0x04, 0x78, 0x04, 0x03,
329  0x61, 0x59, 0x49, 0x4D, 0x43,
330  0x00, 0x7F, 0x41, 0x41, 0x41,
331  0x02, 0x04, 0x08, 0x10, 0x20,
332  0x00, 0x41, 0x41, 0x41, 0x7F,
333  0x04, 0x02, 0x01, 0x02, 0x04,
334  0x40, 0x40, 0x40, 0x40, 0x40,
335  0x00, 0x03, 0x07, 0x08, 0x00,
336  0x20, 0x54, 0x54, 0x78, 0x40,
337  0x7F, 0x28, 0x44, 0x44, 0x38,
338  0x38, 0x44, 0x44, 0x44, 0x28,
339  0x38, 0x44, 0x44, 0x28, 0x7F,
340  0x38, 0x54, 0x54, 0x54, 0x18,
341  0x00, 0x08, 0x7E, 0x09, 0x02,
342  0x18, 0xA4, 0xA4, 0x9C, 0x78,
343  0x7F, 0x08, 0x04, 0x04, 0x78,
344  0x00, 0x44, 0x7D, 0x40, 0x00,
345  0x20, 0x40, 0x40, 0x3D, 0x00,
346  0x7F, 0x10, 0x28, 0x44, 0x00,
347  0x00, 0x41, 0x7F, 0x40, 0x00,
348  0x7C, 0x04, 0x78, 0x04, 0x78,
349  0x7C, 0x08, 0x04, 0x04, 0x78,
350  0x38, 0x44, 0x44, 0x44, 0x38,
351  0xFC, 0x18, 0x24, 0x24, 0x18,
352  0x18, 0x24, 0x24, 0x18, 0xFC,
353  0x7C, 0x08, 0x04, 0x04, 0x08,
354  0x48, 0x54, 0x54, 0x54, 0x24,
355  0x04, 0x04, 0x3F, 0x44, 0x24,
356  0x3C, 0x40, 0x40, 0x20, 0x7C,
357  0x1C, 0x20, 0x40, 0x20, 0x1C,
358  0x3C, 0x40, 0x30, 0x40, 0x3C,
359  0x44, 0x28, 0x10, 0x28, 0x44,
360  0x4C, 0x90, 0x90, 0x90, 0x7C,
361  0x44, 0x64, 0x54, 0x4C, 0x44,
362  0x00, 0x08, 0x36, 0x41, 0x00,
363  0x00, 0x00, 0x77, 0x00, 0x00,
364  0x00, 0x41, 0x36, 0x08, 0x00,
365  0x02, 0x01, 0x02, 0x04, 0x02,
366  0x3C, 0x26, 0x23, 0x26, 0x3C,
367  0x1E, 0xA1, 0xA1, 0x61, 0x12,
368  0x3A, 0x40, 0x40, 0x20, 0x7A,
369  0x38, 0x54, 0x54, 0x55, 0x59,
370  0x21, 0x55, 0x55, 0x79, 0x41,
371  0x21, 0x54, 0x54, 0x78, 0x41,
372  0x21, 0x55, 0x54, 0x78, 0x40,
373  0x20, 0x54, 0x55, 0x79, 0x40,
374  0x0C, 0x1E, 0x52, 0x72, 0x12,
375  0x39, 0x55, 0x55, 0x55, 0x59,
376  0x39, 0x54, 0x54, 0x54, 0x59,
377  0x39, 0x55, 0x54, 0x54, 0x58,
378  0x00, 0x00, 0x45, 0x7C, 0x41,
379  0x00, 0x02, 0x45, 0x7D, 0x42,
380  0x00, 0x01, 0x45, 0x7C, 0x40,
381  0xF0, 0x29, 0x24, 0x29, 0xF0,
382  0xF0, 0x28, 0x25, 0x28, 0xF0,
383  0x7C, 0x54, 0x55, 0x45, 0x00,
384  0x20, 0x54, 0x54, 0x7C, 0x54,
385  0x7C, 0x0A, 0x09, 0x7F, 0x49,
386  0x32, 0x49, 0x49, 0x49, 0x32,
387  0x32, 0x48, 0x48, 0x48, 0x32,
388  0x32, 0x4A, 0x48, 0x48, 0x30,
389  0x3A, 0x41, 0x41, 0x21, 0x7A,
390  0x3A, 0x42, 0x40, 0x20, 0x78,
391  0x00, 0x9D, 0xA0, 0xA0, 0x7D,
392  0x39, 0x44, 0x44, 0x44, 0x39,
393  0x3D, 0x40, 0x40, 0x40, 0x3D,
394  0x3C, 0x24, 0xFF, 0x24, 0x24,
395  0x48, 0x7E, 0x49, 0x43, 0x66,
396  0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
397  0xFF, 0x09, 0x29, 0xF6, 0x20,
398  0xC0, 0x88, 0x7E, 0x09, 0x03,
399  0x20, 0x54, 0x54, 0x79, 0x41,
400  0x00, 0x00, 0x44, 0x7D, 0x41,
401  0x30, 0x48, 0x48, 0x4A, 0x32,
402  0x38, 0x40, 0x40, 0x22, 0x7A,
403  0x00, 0x7A, 0x0A, 0x0A, 0x72,
404  0x7D, 0x0D, 0x19, 0x31, 0x7D,
405  0x26, 0x29, 0x29, 0x2F, 0x28,
406  0x26, 0x29, 0x29, 0x29, 0x26,
407  0x30, 0x48, 0x4D, 0x40, 0x20,
408  0x38, 0x08, 0x08, 0x08, 0x08,
409  0x08, 0x08, 0x08, 0x08, 0x38,
410  0x2F, 0x10, 0xC8, 0xAC, 0xBA,
411  0x2F, 0x10, 0x28, 0x34, 0xFA,
412  0x00, 0x00, 0x7B, 0x00, 0x00,
413  0x08, 0x14, 0x2A, 0x14, 0x22,
414  0x22, 0x14, 0x2A, 0x14, 0x08,
415  0xAA, 0x00, 0x55, 0x00, 0xAA,
416  0xAA, 0x55, 0xAA, 0x55, 0xAA,
417  0x00, 0x00, 0x00, 0xFF, 0x00,
418  0x10, 0x10, 0x10, 0xFF, 0x00,
419  0x14, 0x14, 0x14, 0xFF, 0x00,
420  0x10, 0x10, 0xFF, 0x00, 0xFF,
421  0x10, 0x10, 0xF0, 0x10, 0xF0,
422  0x14, 0x14, 0x14, 0xFC, 0x00,
423  0x14, 0x14, 0xF7, 0x00, 0xFF,
424  0x00, 0x00, 0xFF, 0x00, 0xFF,
425  0x14, 0x14, 0xF4, 0x04, 0xFC,
426  0x14, 0x14, 0x17, 0x10, 0x1F,
427  0x10, 0x10, 0x1F, 0x10, 0x1F,
428  0x14, 0x14, 0x14, 0x1F, 0x00,
429  0x10, 0x10, 0x10, 0xF0, 0x00,
430  0x00, 0x00, 0x00, 0x1F, 0x10,
431  0x10, 0x10, 0x10, 0x1F, 0x10,
432  0x10, 0x10, 0x10, 0xF0, 0x10,
433  0x00, 0x00, 0x00, 0xFF, 0x10,
434  0x10, 0x10, 0x10, 0x10, 0x10,
435  0x10, 0x10, 0x10, 0xFF, 0x10,
436  0x00, 0x00, 0x00, 0xFF, 0x14,
437  0x00, 0x00, 0xFF, 0x00, 0xFF,
438  0x00, 0x00, 0x1F, 0x10, 0x17,
439  0x00, 0x00, 0xFC, 0x04, 0xF4,
440  0x14, 0x14, 0x17, 0x10, 0x17,
441  0x14, 0x14, 0xF4, 0x04, 0xF4,
442  0x00, 0x00, 0xFF, 0x00, 0xF7,
443  0x14, 0x14, 0x14, 0x14, 0x14,
444  0x14, 0x14, 0xF7, 0x00, 0xF7,
445  0x14, 0x14, 0x14, 0x17, 0x14,
446  0x10, 0x10, 0x1F, 0x10, 0x1F,
447  0x14, 0x14, 0x14, 0xF4, 0x14,
448  0x10, 0x10, 0xF0, 0x10, 0xF0,
449  0x00, 0x00, 0x1F, 0x10, 0x1F,
450  0x00, 0x00, 0x00, 0x1F, 0x14,
451  0x00, 0x00, 0x00, 0xFC, 0x14,
452  0x00, 0x00, 0xF0, 0x10, 0xF0,
453  0x10, 0x10, 0xFF, 0x10, 0xFF,
454  0x14, 0x14, 0x14, 0xFF, 0x14,
455  0x10, 0x10, 0x10, 0x1F, 0x00,
456  0x00, 0x00, 0x00, 0xF0, 0x10,
457  0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
458  0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
459  0xFF, 0xFF, 0xFF, 0x00, 0x00,
460  0x00, 0x00, 0x00, 0xFF, 0xFF,
461  0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
462  0x38, 0x44, 0x44, 0x38, 0x44,
463  0x7C, 0x2A, 0x2A, 0x3E, 0x14,
464  0x7E, 0x02, 0x02, 0x06, 0x06,
465  0x02, 0x7E, 0x02, 0x7E, 0x02,
466  0x63, 0x55, 0x49, 0x41, 0x63,
467  0x38, 0x44, 0x44, 0x3C, 0x04,
468  0x40, 0x7E, 0x20, 0x1E, 0x20,
469  0x06, 0x02, 0x7E, 0x02, 0x02,
470  0x99, 0xA5, 0xE7, 0xA5, 0x99,
471  0x1C, 0x2A, 0x49, 0x2A, 0x1C,
472  0x4C, 0x72, 0x01, 0x72, 0x4C,
473  0x30, 0x4A, 0x4D, 0x4D, 0x30,
474  0x30, 0x48, 0x78, 0x48, 0x30,
475  0xBC, 0x62, 0x5A, 0x46, 0x3D,
476  0x3E, 0x49, 0x49, 0x49, 0x00,
477  0x7E, 0x01, 0x01, 0x01, 0x7E,
478  0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
479  0x44, 0x44, 0x5F, 0x44, 0x44,
480  0x40, 0x51, 0x4A, 0x44, 0x40,
481  0x40, 0x44, 0x4A, 0x51, 0x40,
482  0x00, 0x00, 0xFF, 0x01, 0x03,
483  0xE0, 0x80, 0xFF, 0x00, 0x00,
484  0x08, 0x08, 0x6B, 0x6B, 0x08,
485  0x36, 0x12, 0x36, 0x24, 0x36,
486  0x06, 0x0F, 0x09, 0x0F, 0x06,
487  0x00, 0x00, 0x18, 0x18, 0x00,
488  0x00, 0x00, 0x10, 0x10, 0x00,
489  0x30, 0x40, 0xFF, 0x01, 0x01,
490  0x00, 0x1F, 0x01, 0x01, 0x1E,
491  0x00, 0x19, 0x1D, 0x17, 0x12,
492  0x00, 0x3C, 0x3C, 0x3C, 0x3C,
493  0x00, 0x00, 0x00, 0x00, 0x00
494 };
495 
503 class ST7735 : public GFX {
504  public:
513  ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst);
514 
518  ~ST7735 ();
519 
523  std::string name()
524  {
525  return m_name;
526  }
527 
531  void initModule ();
532 
536  void configModule ();
537 
543  void write (uint8_t value);
544 
550  void data (uint8_t value);
551 
557  void executeCMDList (const uint8_t *addr);
558 
568  void setAddrWindow (uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
569 
577  void drawPixel (int16_t x, int16_t y, uint16_t color);
578 
582  void refresh ();
583 
587  mraa_result_t lcdCSOn ();
588 
592  mraa_result_t lcdCSOff ();
593 
597  mraa_result_t sdCSOn ();
598 
602  mraa_result_t sdCSOff ();
603 
607  mraa_result_t rsHIGH ();
608 
612  mraa_result_t rsLOW ();
613 
614  uint8_t m_map[160 * 128 * 2];
615  private:
616  mraa_spi_context m_spi;
617  uint8_t m_csLCD;
618  uint8_t m_cSD;
619  uint8_t m_rST;
620  uint8_t m_rS;
621 
622  mraa_gpio_context m_csLCDPinCtx;
623  mraa_gpio_context m_cSDPinCtx;
624  mraa_gpio_context m_rSTPinCtx;
625  mraa_gpio_context m_rSPinCtx;
626 
627  uint8_t m_spiBuffer[32];
628 
629  std::string m_name;
630 };
631 
632 }
void setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
Definition: st7735.cxx:169
mraa_result_t sdCSOff()
Definition: st7735.cxx:286
void configModule()
Definition: st7735.cxx:214
C++ API for ST7735 SPI LCD module.
Definition: st7735.h:503
void initModule()
Definition: st7735.cxx:72
GFX helper class.
Definition: gfx.h:41
std::string name()
Definition: st7735.h:523
void data(uint8_t value)
Definition: st7735.cxx:138
ST7735(uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst)
Definition: st7735.cxx:35
void executeCMDList(const uint8_t *addr)
Definition: st7735.cxx:144
void refresh()
Definition: st7735.cxx:204
mraa_result_t rsHIGH()
Definition: st7735.cxx:298
void write(uint8_t value)
Definition: st7735.cxx:132
uint8_t m_map[160 *128 *2]
Definition: st7735.h:614
mraa_result_t lcdCSOff()
Definition: st7735.cxx:257
~ST7735()
Definition: st7735.cxx:47
mraa_result_t sdCSOn()
Definition: st7735.cxx:269
mraa_result_t lcdCSOn()
Definition: st7735.cxx:240
void drawPixel(int16_t x, int16_t y, uint16_t color)
Definition: st7735.cxx:195
mraa_result_t rsLOW()
Definition: st7735.cxx:310