upm  0.8.0
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ssd1351_gfx.hpp
1 /*
2  * Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Mihai Tudor Panu <mihai.tudor.panu@intel.com>
4  *
5  * Copyright (c) 2016 Intel Corporation.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <string>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <stdint.h>
32 
33 #define swap(a, b) { int16_t t = a; a = b; b = t; }
34 
35 namespace upm {
36 
37 const unsigned char font[] = {
38  0x00, 0x00, 0x00, 0x00, 0x00,
39  0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
40  0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
41  0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
42  0x18, 0x3C, 0x7E, 0x3C, 0x18,
43  0x1C, 0x57, 0x7D, 0x57, 0x1C,
44  0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
45  0x00, 0x18, 0x3C, 0x18, 0x00,
46  0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
47  0x00, 0x18, 0x24, 0x18, 0x00,
48  0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
49  0x30, 0x48, 0x3A, 0x06, 0x0E,
50  0x26, 0x29, 0x79, 0x29, 0x26,
51  0x40, 0x7F, 0x05, 0x05, 0x07,
52  0x40, 0x7F, 0x05, 0x25, 0x3F,
53  0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
54  0x7F, 0x3E, 0x1C, 0x1C, 0x08,
55  0x08, 0x1C, 0x1C, 0x3E, 0x7F,
56  0x14, 0x22, 0x7F, 0x22, 0x14,
57  0x5F, 0x5F, 0x00, 0x5F, 0x5F,
58  0x06, 0x09, 0x7F, 0x01, 0x7F,
59  0x00, 0x66, 0x89, 0x95, 0x6A,
60  0x60, 0x60, 0x60, 0x60, 0x60,
61  0x94, 0xA2, 0xFF, 0xA2, 0x94,
62  0x08, 0x04, 0x7E, 0x04, 0x08,
63  0x10, 0x20, 0x7E, 0x20, 0x10,
64  0x08, 0x08, 0x2A, 0x1C, 0x08,
65  0x08, 0x1C, 0x2A, 0x08, 0x08,
66  0x1E, 0x10, 0x10, 0x10, 0x10,
67  0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
68  0x30, 0x38, 0x3E, 0x38, 0x30,
69  0x06, 0x0E, 0x3E, 0x0E, 0x06,
70  0x00, 0x00, 0x00, 0x00, 0x00,
71  0x00, 0x00, 0x5F, 0x00, 0x00,
72  0x00, 0x07, 0x00, 0x07, 0x00,
73  0x14, 0x7F, 0x14, 0x7F, 0x14,
74  0x24, 0x2A, 0x7F, 0x2A, 0x12,
75  0x23, 0x13, 0x08, 0x64, 0x62,
76  0x36, 0x49, 0x56, 0x20, 0x50,
77  0x00, 0x08, 0x07, 0x03, 0x00,
78  0x00, 0x1C, 0x22, 0x41, 0x00,
79  0x00, 0x41, 0x22, 0x1C, 0x00,
80  0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
81  0x08, 0x08, 0x3E, 0x08, 0x08,
82  0x00, 0x80, 0x70, 0x30, 0x00,
83  0x08, 0x08, 0x08, 0x08, 0x08,
84  0x00, 0x00, 0x60, 0x60, 0x00,
85  0x20, 0x10, 0x08, 0x04, 0x02,
86  0x3E, 0x51, 0x49, 0x45, 0x3E,
87  0x00, 0x42, 0x7F, 0x40, 0x00,
88  0x72, 0x49, 0x49, 0x49, 0x46,
89  0x21, 0x41, 0x49, 0x4D, 0x33,
90  0x18, 0x14, 0x12, 0x7F, 0x10,
91  0x27, 0x45, 0x45, 0x45, 0x39,
92  0x3C, 0x4A, 0x49, 0x49, 0x31,
93  0x41, 0x21, 0x11, 0x09, 0x07,
94  0x36, 0x49, 0x49, 0x49, 0x36,
95  0x46, 0x49, 0x49, 0x29, 0x1E,
96  0x00, 0x00, 0x14, 0x00, 0x00,
97  0x00, 0x40, 0x34, 0x00, 0x00,
98  0x00, 0x08, 0x14, 0x22, 0x41,
99  0x14, 0x14, 0x14, 0x14, 0x14,
100  0x00, 0x41, 0x22, 0x14, 0x08,
101  0x02, 0x01, 0x59, 0x09, 0x06,
102  0x3E, 0x41, 0x5D, 0x59, 0x4E,
103  0x7C, 0x12, 0x11, 0x12, 0x7C,
104  0x7F, 0x49, 0x49, 0x49, 0x36,
105  0x3E, 0x41, 0x41, 0x41, 0x22,
106  0x7F, 0x41, 0x41, 0x41, 0x3E,
107  0x7F, 0x49, 0x49, 0x49, 0x41,
108  0x7F, 0x09, 0x09, 0x09, 0x01,
109  0x3E, 0x41, 0x41, 0x51, 0x73,
110  0x7F, 0x08, 0x08, 0x08, 0x7F,
111  0x00, 0x41, 0x7F, 0x41, 0x00,
112  0x20, 0x40, 0x41, 0x3F, 0x01,
113  0x7F, 0x08, 0x14, 0x22, 0x41,
114  0x7F, 0x40, 0x40, 0x40, 0x40,
115  0x7F, 0x02, 0x1C, 0x02, 0x7F,
116  0x7F, 0x04, 0x08, 0x10, 0x7F,
117  0x3E, 0x41, 0x41, 0x41, 0x3E,
118  0x7F, 0x09, 0x09, 0x09, 0x06,
119  0x3E, 0x41, 0x51, 0x21, 0x5E,
120  0x7F, 0x09, 0x19, 0x29, 0x46,
121  0x26, 0x49, 0x49, 0x49, 0x32,
122  0x03, 0x01, 0x7F, 0x01, 0x03,
123  0x3F, 0x40, 0x40, 0x40, 0x3F,
124  0x1F, 0x20, 0x40, 0x20, 0x1F,
125  0x3F, 0x40, 0x38, 0x40, 0x3F,
126  0x63, 0x14, 0x08, 0x14, 0x63,
127  0x03, 0x04, 0x78, 0x04, 0x03,
128  0x61, 0x59, 0x49, 0x4D, 0x43,
129  0x00, 0x7F, 0x41, 0x41, 0x41,
130  0x02, 0x04, 0x08, 0x10, 0x20,
131  0x00, 0x41, 0x41, 0x41, 0x7F,
132  0x04, 0x02, 0x01, 0x02, 0x04,
133  0x40, 0x40, 0x40, 0x40, 0x40,
134  0x00, 0x03, 0x07, 0x08, 0x00,
135  0x20, 0x54, 0x54, 0x78, 0x40,
136  0x7F, 0x28, 0x44, 0x44, 0x38,
137  0x38, 0x44, 0x44, 0x44, 0x28,
138  0x38, 0x44, 0x44, 0x28, 0x7F,
139  0x38, 0x54, 0x54, 0x54, 0x18,
140  0x00, 0x08, 0x7E, 0x09, 0x02,
141  0x18, 0xA4, 0xA4, 0x9C, 0x78,
142  0x7F, 0x08, 0x04, 0x04, 0x78,
143  0x00, 0x44, 0x7D, 0x40, 0x00,
144  0x20, 0x40, 0x40, 0x3D, 0x00,
145  0x7F, 0x10, 0x28, 0x44, 0x00,
146  0x00, 0x41, 0x7F, 0x40, 0x00,
147  0x7C, 0x04, 0x78, 0x04, 0x78,
148  0x7C, 0x08, 0x04, 0x04, 0x78,
149  0x38, 0x44, 0x44, 0x44, 0x38,
150  0xFC, 0x18, 0x24, 0x24, 0x18,
151  0x18, 0x24, 0x24, 0x18, 0xFC,
152  0x7C, 0x08, 0x04, 0x04, 0x08,
153  0x48, 0x54, 0x54, 0x54, 0x24,
154  0x04, 0x04, 0x3F, 0x44, 0x24,
155  0x3C, 0x40, 0x40, 0x20, 0x7C,
156  0x1C, 0x20, 0x40, 0x20, 0x1C,
157  0x3C, 0x40, 0x30, 0x40, 0x3C,
158  0x44, 0x28, 0x10, 0x28, 0x44,
159  0x4C, 0x90, 0x90, 0x90, 0x7C,
160  0x44, 0x64, 0x54, 0x4C, 0x44,
161  0x00, 0x08, 0x36, 0x41, 0x00,
162  0x00, 0x00, 0x77, 0x00, 0x00,
163  0x00, 0x41, 0x36, 0x08, 0x00,
164  0x02, 0x01, 0x02, 0x04, 0x02,
165  0x3C, 0x26, 0x23, 0x26, 0x3C,
166  0x1E, 0xA1, 0xA1, 0x61, 0x12,
167  0x3A, 0x40, 0x40, 0x20, 0x7A,
168  0x38, 0x54, 0x54, 0x55, 0x59,
169  0x21, 0x55, 0x55, 0x79, 0x41,
170  0x21, 0x54, 0x54, 0x78, 0x41,
171  0x21, 0x55, 0x54, 0x78, 0x40,
172  0x20, 0x54, 0x55, 0x79, 0x40,
173  0x0C, 0x1E, 0x52, 0x72, 0x12,
174  0x39, 0x55, 0x55, 0x55, 0x59,
175  0x39, 0x54, 0x54, 0x54, 0x59,
176  0x39, 0x55, 0x54, 0x54, 0x58,
177  0x00, 0x00, 0x45, 0x7C, 0x41,
178  0x00, 0x02, 0x45, 0x7D, 0x42,
179  0x00, 0x01, 0x45, 0x7C, 0x40,
180  0xF0, 0x29, 0x24, 0x29, 0xF0,
181  0xF0, 0x28, 0x25, 0x28, 0xF0,
182  0x7C, 0x54, 0x55, 0x45, 0x00,
183  0x20, 0x54, 0x54, 0x7C, 0x54,
184  0x7C, 0x0A, 0x09, 0x7F, 0x49,
185  0x32, 0x49, 0x49, 0x49, 0x32,
186  0x32, 0x48, 0x48, 0x48, 0x32,
187  0x32, 0x4A, 0x48, 0x48, 0x30,
188  0x3A, 0x41, 0x41, 0x21, 0x7A,
189  0x3A, 0x42, 0x40, 0x20, 0x78,
190  0x00, 0x9D, 0xA0, 0xA0, 0x7D,
191  0x39, 0x44, 0x44, 0x44, 0x39,
192  0x3D, 0x40, 0x40, 0x40, 0x3D,
193  0x3C, 0x24, 0xFF, 0x24, 0x24,
194  0x48, 0x7E, 0x49, 0x43, 0x66,
195  0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
196  0xFF, 0x09, 0x29, 0xF6, 0x20,
197  0xC0, 0x88, 0x7E, 0x09, 0x03,
198  0x20, 0x54, 0x54, 0x79, 0x41,
199  0x00, 0x00, 0x44, 0x7D, 0x41,
200  0x30, 0x48, 0x48, 0x4A, 0x32,
201  0x38, 0x40, 0x40, 0x22, 0x7A,
202  0x00, 0x7A, 0x0A, 0x0A, 0x72,
203  0x7D, 0x0D, 0x19, 0x31, 0x7D,
204  0x26, 0x29, 0x29, 0x2F, 0x28,
205  0x26, 0x29, 0x29, 0x29, 0x26,
206  0x30, 0x48, 0x4D, 0x40, 0x20,
207  0x38, 0x08, 0x08, 0x08, 0x08,
208  0x08, 0x08, 0x08, 0x08, 0x38,
209  0x2F, 0x10, 0xC8, 0xAC, 0xBA,
210  0x2F, 0x10, 0x28, 0x34, 0xFA,
211  0x00, 0x00, 0x7B, 0x00, 0x00,
212  0x08, 0x14, 0x2A, 0x14, 0x22,
213  0x22, 0x14, 0x2A, 0x14, 0x08,
214  0xAA, 0x00, 0x55, 0x00, 0xAA,
215  0xAA, 0x55, 0xAA, 0x55, 0xAA,
216  0x00, 0x00, 0x00, 0xFF, 0x00,
217  0x10, 0x10, 0x10, 0xFF, 0x00,
218  0x14, 0x14, 0x14, 0xFF, 0x00,
219  0x10, 0x10, 0xFF, 0x00, 0xFF,
220  0x10, 0x10, 0xF0, 0x10, 0xF0,
221  0x14, 0x14, 0x14, 0xFC, 0x00,
222  0x14, 0x14, 0xF7, 0x00, 0xFF,
223  0x00, 0x00, 0xFF, 0x00, 0xFF,
224  0x14, 0x14, 0xF4, 0x04, 0xFC,
225  0x14, 0x14, 0x17, 0x10, 0x1F,
226  0x10, 0x10, 0x1F, 0x10, 0x1F,
227  0x14, 0x14, 0x14, 0x1F, 0x00,
228  0x10, 0x10, 0x10, 0xF0, 0x00,
229  0x00, 0x00, 0x00, 0x1F, 0x10,
230  0x10, 0x10, 0x10, 0x1F, 0x10,
231  0x10, 0x10, 0x10, 0xF0, 0x10,
232  0x00, 0x00, 0x00, 0xFF, 0x10,
233  0x10, 0x10, 0x10, 0x10, 0x10,
234  0x10, 0x10, 0x10, 0xFF, 0x10,
235  0x00, 0x00, 0x00, 0xFF, 0x14,
236  0x00, 0x00, 0xFF, 0x00, 0xFF,
237  0x00, 0x00, 0x1F, 0x10, 0x17,
238  0x00, 0x00, 0xFC, 0x04, 0xF4,
239  0x14, 0x14, 0x17, 0x10, 0x17,
240  0x14, 0x14, 0xF4, 0x04, 0xF4,
241  0x00, 0x00, 0xFF, 0x00, 0xF7,
242  0x14, 0x14, 0x14, 0x14, 0x14,
243  0x14, 0x14, 0xF7, 0x00, 0xF7,
244  0x14, 0x14, 0x14, 0x17, 0x14,
245  0x10, 0x10, 0x1F, 0x10, 0x1F,
246  0x14, 0x14, 0x14, 0xF4, 0x14,
247  0x10, 0x10, 0xF0, 0x10, 0xF0,
248  0x00, 0x00, 0x1F, 0x10, 0x1F,
249  0x00, 0x00, 0x00, 0x1F, 0x14,
250  0x00, 0x00, 0x00, 0xFC, 0x14,
251  0x00, 0x00, 0xF0, 0x10, 0xF0,
252  0x10, 0x10, 0xFF, 0x10, 0xFF,
253  0x14, 0x14, 0x14, 0xFF, 0x14,
254  0x10, 0x10, 0x10, 0x1F, 0x00,
255  0x00, 0x00, 0x00, 0xF0, 0x10,
256  0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
257  0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
258  0xFF, 0xFF, 0xFF, 0x00, 0x00,
259  0x00, 0x00, 0x00, 0xFF, 0xFF,
260  0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
261  0x38, 0x44, 0x44, 0x38, 0x44,
262  0x7C, 0x2A, 0x2A, 0x3E, 0x14,
263  0x7E, 0x02, 0x02, 0x06, 0x06,
264  0x02, 0x7E, 0x02, 0x7E, 0x02,
265  0x63, 0x55, 0x49, 0x41, 0x63,
266  0x38, 0x44, 0x44, 0x3C, 0x04,
267  0x40, 0x7E, 0x20, 0x1E, 0x20,
268  0x06, 0x02, 0x7E, 0x02, 0x02,
269  0x99, 0xA5, 0xE7, 0xA5, 0x99,
270  0x1C, 0x2A, 0x49, 0x2A, 0x1C,
271  0x4C, 0x72, 0x01, 0x72, 0x4C,
272  0x30, 0x4A, 0x4D, 0x4D, 0x30,
273  0x30, 0x48, 0x78, 0x48, 0x30,
274  0xBC, 0x62, 0x5A, 0x46, 0x3D,
275  0x3E, 0x49, 0x49, 0x49, 0x00,
276  0x7E, 0x01, 0x01, 0x01, 0x7E,
277  0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
278  0x44, 0x44, 0x5F, 0x44, 0x44,
279  0x40, 0x51, 0x4A, 0x44, 0x40,
280  0x40, 0x44, 0x4A, 0x51, 0x40,
281  0x00, 0x00, 0xFF, 0x01, 0x03,
282  0xE0, 0x80, 0xFF, 0x00, 0x00,
283  0x08, 0x08, 0x6B, 0x6B, 0x08,
284  0x36, 0x12, 0x36, 0x24, 0x36,
285  0x06, 0x0F, 0x09, 0x0F, 0x06,
286  0x00, 0x00, 0x18, 0x18, 0x00,
287  0x00, 0x00, 0x10, 0x10, 0x00,
288  0x30, 0x40, 0xFF, 0x01, 0x01,
289  0x00, 0x1F, 0x01, 0x01, 0x1E,
290  0x00, 0x19, 0x1D, 0x17, 0x12,
291  0x00, 0x3C, 0x3C, 0x3C, 0x3C,
292  0x00, 0x00, 0x00, 0x00, 0x00
293 };
294 
300 class GFX {
301  public:
308  GFX (int width, int height);
309 
313  ~GFX ();
314 
323  virtual void drawPixel (int16_t x, int16_t y, uint16_t color) = 0;
324 
328  virtual void refresh () = 0;
329 
340  void drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size);
341 
347  void print (std::string msg);
348 
354  void fillScreen (uint16_t color);
355 
365  void fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
366 
375  void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
376 
386  void drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
387 
399  void drawTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
400 
409  void drawCircle (int16_t x, int16_t y, int16_t r, uint16_t color);
410 
417  void setCursor (int16_t x, int16_t y);
418 
425  void setTextColor (uint16_t textColor, uint16_t textBGColor);
426 
432  void setTextSize (uint8_t size);
433 
439  void setTextWrap (uint8_t wrap);
440 
441  protected:
442  int m_width;
443  int m_height;
447  int m_cursorX;
448  int m_cursorY;
449  int m_wrap;
451  const unsigned char * m_font;
452  };
453 }
virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Definition: ili9341_gfx.cxx:45
int m_textSize
Definition: ssd1351_gfx.hpp:444
void setTextSize(uint8_t s)
Definition: ili9341_gfx.cxx:426
int m_cursorY
Definition: ssd1351_gfx.hpp:448
int m_width
Definition: ssd1351_gfx.hpp:442
void setTextWrap(bool w)
Definition: ili9341_gfx.cxx:430
virtual void drawPixel(int16_t x, int16_t y, uint16_t color)=0
int16_t height(void) const
Definition: ili9341_gfx.cxx:488
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Definition: ili9341_gfx.cxx:242
virtual void fillScreen(uint16_t color)
Definition: ili9341_gfx.cxx:124
~GFX()
Definition: ssd1351_gfx.cxx:40
void setTextColor(uint16_t c)
Definition: ili9341_gfx.cxx:415
virtual void refresh()=0
GFX(int16_t w, int16_t h)
Definition: ili9341_gfx.cxx:31
int m_textBGColor
Definition: ssd1351_gfx.hpp:446
int m_cursorX
Definition: ssd1351_gfx.hpp:447
void setCursor(int16_t x, int16_t y)
Definition: ili9341_gfx.cxx:410
int m_wrap
Definition: ssd1351_gfx.hpp:449
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Definition: ili9341_gfx.cxx:89
int m_textColor
Definition: ssd1351_gfx.hpp:445
void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size)
Definition: ili9341_gfx.cxx:371
int m_height
Definition: ssd1351_gfx.hpp:443
void print(std::string msg)
Definition: ili9341_gfx.cxx:477
int16_t width(void) const
Definition: ili9341_gfx.cxx:484
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Definition: ili9341_gfx.cxx:132
virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Definition: ili9341_gfx.cxx:114