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