Browse Source

ili9341: Initial implementation

This driver provides support for the ILI9341 LCD driver via SPI (e.g.
Adafruit 2.8" TFT LCD).

It was implemented and tested on the Edison.

Signed-off-by: Shawn Hymel
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Shawn Hymel 9 years ago
parent
commit
d7f4b76ed0

BIN
docs/images/ili9341.jpg View File


+ 1
- 0
examples/c++/CMakeLists.txt View File

@@ -226,6 +226,7 @@ add_example (mcp9808)
226 226
 add_example (groveultrasonic)
227 227
 add_example (sx1276-lora)
228 228
 add_example (sx1276-fsk)
229
+add_example (ili9341)
229 230
 if (OPENZWAVE_FOUND)
230 231
   include_directories(${OPENZWAVE_INCLUDE_DIRS})
231 232
   add_example (ozw)

+ 84
- 0
examples/c++/ili9341.cxx View File

@@ -0,0 +1,84 @@
1
+/**
2
+ * Author: Shawn Hymel
3
+ * Copyright (c) 2016 SparkFun Electronics
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+#include <unistd.h>
26
+
27
+#include "ili9341.h"
28
+
29
+int main(int argc, char **argv) {
30
+//! [Interesting]
31
+
32
+    // Pins (Edison)
33
+    // CS_LCD   GP44 (MRAA 31)
34
+    // CS_SD    GP43 (MRAA 38) unused
35
+    // DC       GP12 (MRAA 20)
36
+    // RESEST   GP13 (MRAA 14)
37
+    upm::ILI9341 * lcd = new upm::ILI9341(31, 38, 20, 14);
38
+
39
+    // Fill the screen with a solid color
40
+    lcd->fillScreen(lcd->color565(0, 40, 16));
41
+
42
+    // Draw some shapes
43
+    lcd->drawFastVLine(10, 10, 100, ILI9341_RED);
44
+    lcd->drawFastHLine(20, 10, 50, ILI9341_CYAN);
45
+    lcd->drawLine(160, 30, 200, 60, ILI9341_GREEN);
46
+    lcd->fillRect(20, 30, 75, 60, ILI9341_ORANGE);
47
+    lcd->drawCircle(70, 50, 20, ILI9341_PURPLE);
48
+    lcd->fillCircle(120, 50, 20, ILI9341_PURPLE);
49
+    lcd->drawTriangle(50, 100, 10, 140, 90, 140, ILI9341_YELLOW);
50
+    lcd->fillTriangle(150, 100, 110, 140, 190, 140, ILI9341_YELLOW);
51
+    lcd->drawRoundRect(20, 150, 50, 30, 10, ILI9341_RED);
52
+    lcd->drawRoundRect(130, 150, 50, 30, 10, ILI9341_RED);
53
+    lcd->fillRoundRect(75, 150, 50, 30, 10, ILI9341_RED);
54
+
55
+    // Write some text
56
+    lcd->setCursor(0, 200);
57
+    lcd->setTextColor(ILI9341_LIGHTGREY);
58
+    lcd->setTextWrap(true);
59
+    lcd->setTextSize(1);
60
+    lcd->print("Text 1\n");
61
+    lcd->setTextSize(2);
62
+    lcd->print("Text 2\n");
63
+    lcd->setTextSize(3);
64
+    lcd->print("Text 3\n");
65
+    lcd->setTextSize(4);
66
+    lcd->print("Text 4\n");
67
+ 
68
+    // Test screen rotation
69
+    for(int r = 0; r < 4; r++) {
70
+        lcd->setRotation(r);
71
+        lcd->fillRect(0, 0, 5, 5, ILI9341_WHITE);
72
+        sleep(1);
73
+    }
74
+
75
+    // Invert colors, wait, then revert back
76
+    lcd->invertDisplay(true);
77
+    sleep(2);
78
+    lcd->invertDisplay(false);
79
+
80
+    // Don't forget to free up that memory!
81
+    delete lcd;
82
+//! [Interesting]
83
+    return 0;
84
+}

+ 79
- 0
examples/javascript/ili9341.js View File

@@ -0,0 +1,79 @@
1
+/*jslint node:true, vars:true, bitwise:true, unparam:true */
2
+/*jshint unused:true */
3
+
4
+/**
5
+ * Author: Shawn Hymel
6
+ * Copyright (c) 2016 SparkFun Electronics
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
+
28
+var ili9341 = require('jsupm_ili9341');
29
+
30
+// Pins (Edison)
31
+// CS_LCD   GP44 (MRAA 31)
32
+// CS_SD    GP43 (MRAA 38) unused
33
+// DC       GP12 (MRAA 20)
34
+// RESEST   GP13 (MRAA 14)
35
+var lcd = new ili9341.ILI9341(31, 38, 20, 14);
36
+
37
+// Fill the screen with a solid color
38
+lcd.fillScreen(lcd.color565(0, 40, 16));
39
+
40
+// Draw some shapes
41
+lcd.drawFastVLine(10, 10, 100, ili9341.ILI9341_RED);
42
+lcd.drawFastHLine(20, 10, 50, ili9341.ILI9341_CYAN);
43
+lcd.drawLine(160, 30, 200, 60, ili9341.ILI9341_GREEN);
44
+lcd.fillRect(20, 30, 75, 60, ili9341.ILI9341_ORANGE);
45
+lcd.drawCircle(70, 50, 20, ili9341.ILI9341_PURPLE);
46
+lcd.fillCircle(120, 50, 20, ili9341.ILI9341_PURPLE);
47
+lcd.drawTriangle(50, 100, 10, 140, 90, 140, ili9341.ILI9341_YELLOW);
48
+lcd.fillTriangle(150, 100, 110, 140, 190, 140, ili9341.ILI9341_YELLOW);
49
+lcd.drawRoundRect(20, 150, 50, 30, 10, ili9341.ILI9341_RED);
50
+lcd.drawRoundRect(130, 150, 50, 30, 10, ili9341.ILI9341_RED);
51
+lcd.fillRoundRect(75, 150, 50, 30, 10, ili9341.ILI9341_RED);
52
+
53
+// Write some text
54
+lcd.setCursor(0, 200);
55
+lcd.setTextColor(ili9341.ILI9341_LIGHTGREY);
56
+lcd.setTextWrap(true);
57
+lcd.setTextSize(1);
58
+lcd.print("Text 1\n");
59
+lcd.setTextSize(2);
60
+lcd.print("Text 2\n");
61
+lcd.setTextSize(3);
62
+lcd.print("Text 3\n");
63
+lcd.setTextSize(4);
64
+lcd.print("Text 4\n");
65
+
66
+// Test screen rotation
67
+function rotateScreen(r) {
68
+    lcd.setRotation(r);
69
+    lcd.fillRect(0, 0, 5, 5, ili9341.ILI9341_WHITE);
70
+    if (r < 4) {
71
+        r++;
72
+        setTimeout(function() { rotateScreen(r); }, 1000);
73
+    }
74
+}
75
+rotateScreen(0);
76
+
77
+// Invert colors, wait, then revert back
78
+setTimeout(function() { lcd.invertDisplay(true); }, 4000);
79
+setTimeout(function() { lcd.invertDisplay(false); }, 6000);

+ 75
- 0
examples/python/ili9341.py View File

@@ -0,0 +1,75 @@
1
+#!/usr/bin/python
2
+# Author: Shawn Hymel
3
+# Copyright (c) 2016 SparkFun Electronics
4
+#
5
+# Permission is hereby granted, free of charge, to any person obtaining
6
+# a copy of this software and associated documentation files (the
7
+# "Software"), to deal in the Software without restriction, including
8
+# without limitation the rights to use, copy, modify, merge, publish,
9
+# distribute, sublicense, and/or sell copies of the Software, and to
10
+# permit persons to whom the Software is furnished to do so, subject to
11
+# the following conditions:
12
+#
13
+# The above copyright notice and this permission notice shall be
14
+# included in all copies or substantial portions of the Software.
15
+#
16
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+import time
25
+import pyupm_ili9341 as ili9341
26
+
27
+# Pins (Edison)
28
+# CS_LCD   GP44 (MRAA 31)
29
+# CS_SD    GP43 (MRAA 38) unused
30
+# DC       GP12 (MRAA 20)
31
+# RESEST   GP13 (MRAA 14)
32
+lcd = ili9341.ILI9341(31, 38, 20, 14)
33
+
34
+# Fill the screen with a solid color
35
+lcd.fillScreen(lcd.color565(0, 40, 16))
36
+
37
+# Draw some shapes
38
+lcd.drawFastVLine(10, 10, 100, ili9341.ILI9341_RED)
39
+lcd.drawFastHLine(20, 10, 50, ili9341.ILI9341_CYAN)
40
+lcd.drawLine(160, 30, 200, 60, ili9341.ILI9341_GREEN)
41
+lcd.fillRect(20, 30, 75, 60, ili9341.ILI9341_ORANGE)
42
+lcd.drawCircle(70, 50, 20, ili9341.ILI9341_PURPLE)
43
+lcd.fillCircle(120, 50, 20, ili9341.ILI9341_PURPLE)
44
+lcd.drawTriangle(50, 100, 10, 140, 90, 140, ili9341.ILI9341_YELLOW)
45
+lcd.fillTriangle(150, 100, 110, 140, 190, 140, ili9341.ILI9341_YELLOW)
46
+lcd.drawRoundRect(20, 150, 50, 30, 10, ili9341.ILI9341_RED)
47
+lcd.drawRoundRect(130, 150, 50, 30, 10, ili9341.ILI9341_RED)
48
+lcd.fillRoundRect(75, 150, 50, 30, 10, ili9341.ILI9341_RED)
49
+
50
+# Write some text
51
+lcd.setCursor(0, 200)
52
+lcd.setTextColor(ili9341.ILI9341_LIGHTGREY)
53
+lcd.setTextWrap(True)
54
+lcd.setTextSize(1)
55
+lcd._print("Text 1\n")
56
+lcd.setTextSize(2)
57
+lcd._print("Text 2\n")
58
+lcd.setTextSize(3)
59
+lcd._print("Text 3\n")
60
+lcd.setTextSize(4)
61
+lcd._print("Text 4\n")
62
+
63
+# Test screen rotation
64
+for r in range(0, 4):
65
+    lcd.setRotation(r)
66
+    lcd.fillRect(0, 0, 5, 5, ili9341.ILI9341_WHITE)
67
+    time.sleep(1)
68
+    
69
+# Invert colors, wait, then revert back
70
+lcd.invertDisplay(True)
71
+time.sleep(2)
72
+lcd.invertDisplay(False)
73
+
74
+# Don't forget to free up that memory!
75
+del lcd

+ 5
- 0
src/ili9341/CMakeLists.txt View File

@@ -0,0 +1,5 @@
1
+set (libname "ili9341")
2
+set (libdescription "libupm ILI9341 SPI LCD")
3
+set (module_src gfx.cxx ili9341.cxx)
4
+set (module_h gfx.h ili9341.h)
5
+upm_module_init()

+ 749
- 0
src/ili9341/gfx.cxx View File

@@ -0,0 +1,749 @@
1
+/**
2
+ * Author: Shawn Hymel
3
+ * Copyright (c) 2016 SparkFun Electronics
4
+ *
5
+ * Based on GFX interface by Yevgeniy Kiveisha and Adafruit Industries.
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
+
27
+#include "gfx.h"
28
+
29
+using namespace upm;
30
+
31
+GFX::GFX(int16_t w, int16_t h) : WIDTH(w), HEIGHT(h) {
32
+    _width = WIDTH;
33
+    _height = HEIGHT;
34
+    rotation = 0;
35
+    
36
+    cursor_x = 0;
37
+    cursor_y = 0;
38
+    textsize = 1;
39
+    textcolor = 0xFFFF;
40
+    textbgcolor = 0xFFFF;
41
+    wrap = true;
42
+    _cp437 = false;
43
+}
44
+
45
+void GFX::drawLine(int16_t x0, 
46
+                   int16_t y0, 
47
+                   int16_t x1, 
48
+                   int16_t y1, 
49
+                   uint16_t color) {
50
+                   
51
+    int16_t steep = abs(y1 - y0) > abs(x1 - x0);
52
+    if (steep) {
53
+        adagfxswap(x0, y0);
54
+        adagfxswap(x1, y1);
55
+    }
56
+
57
+    if (x0 > x1) {
58
+        adagfxswap(x0, x1);
59
+        adagfxswap(y0, y1);
60
+    }
61
+
62
+    int16_t dx, dy;
63
+    dx = x1 - x0;
64
+    dy = abs(y1 - y0);
65
+
66
+    int16_t err = dx / 2;
67
+    int16_t ystep;
68
+
69
+    if (y0 < y1) {
70
+        ystep = 1;
71
+    } else {
72
+        ystep = -1;
73
+    }
74
+
75
+    for (; x0<=x1; x0++) {
76
+        if (steep) {
77
+            drawPixel(y0, x0, color);
78
+        } else {
79
+            drawPixel(x0, y0, color);
80
+        }
81
+        err -= dy;
82
+        if (err < 0) {
83
+            y0 += ystep;
84
+          err += dx;
85
+        }
86
+    }
87
+}
88
+
89
+void GFX::drawFastVLine(int16_t x, 
90
+                        int16_t y, 
91
+                        int16_t h, 
92
+                        uint16_t color) {
93
+    drawLine(x, y, x, y+h-1, color);
94
+}
95
+
96
+void GFX::drawFastHLine(int16_t x, 
97
+                        int16_t y, 
98
+                        int16_t w, 
99
+                        uint16_t color) {
100
+    drawLine(x, y, x+w-1, y, color);
101
+}
102
+
103
+void GFX::drawRect(int16_t x, 
104
+                   int16_t y, 
105
+                   int16_t w, 
106
+                   int16_t h, 
107
+                   uint16_t color) {
108
+    drawFastHLine(x, y, w, color);
109
+    drawFastHLine(x, y+h-1, w, color);
110
+    drawFastVLine(x, y, h, color);
111
+    drawFastVLine(x+w-1, y, h, color);
112
+}
113
+
114
+void GFX::fillRect(int16_t x, 
115
+                   int16_t y, 
116
+                   int16_t w, 
117
+                   int16_t h, 
118
+                   uint16_t color) {
119
+    for (int16_t i=x; i<x+w; i++) {
120
+        drawFastVLine(i, y, h, color);
121
+    }
122
+}
123
+
124
+void GFX::fillScreen(uint16_t color) {
125
+    fillRect(0, 0, _width, _height, color);
126
+}
127
+
128
+void GFX::invertDisplay(bool i) {
129
+    // Do nothing, must be subclassed if supported by hardware
130
+}
131
+
132
+void GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
133
+    int16_t f = 1 - r;
134
+    int16_t ddF_x = 1;
135
+    int16_t ddF_y = -2 * r;
136
+    int16_t x = 0;
137
+    int16_t y = r;
138
+
139
+    drawPixel(x0  , y0+r, color);
140
+    drawPixel(x0  , y0-r, color);
141
+    drawPixel(x0+r, y0  , color);
142
+    drawPixel(x0-r, y0  , color);
143
+
144
+    while (x<y) {
145
+        if (f >= 0) {
146
+            y--;
147
+            ddF_y += 2;
148
+            f += ddF_y;
149
+        }
150
+        x++;
151
+        ddF_x += 2;
152
+        f += ddF_x;
153
+
154
+        drawPixel(x0 + x, y0 + y, color);
155
+        drawPixel(x0 - x, y0 + y, color);
156
+        drawPixel(x0 + x, y0 - y, color);
157
+        drawPixel(x0 - x, y0 - y, color);
158
+        drawPixel(x0 + y, y0 + x, color);
159
+        drawPixel(x0 - y, y0 + x, color);
160
+        drawPixel(x0 + y, y0 - x, color);
161
+        drawPixel(x0 - y, y0 - x, color);
162
+    }
163
+}
164
+
165
+void GFX::drawCircleHelper(int16_t x0, 
166
+                           int16_t y0, 
167
+                           int16_t r, 
168
+                           uint8_t cornername,
169
+                           uint16_t color) {
170
+    int16_t f     = 1 - r;
171
+    int16_t ddF_x = 1;
172
+    int16_t ddF_y = -2 * r;
173
+    int16_t x     = 0;
174
+    int16_t y     = r;
175
+
176
+    while (x<y) {
177
+        if (f >= 0) {
178
+            y--;
179
+            ddF_y += 2;
180
+            f     += ddF_y;
181
+        }
182
+        x++;
183
+        ddF_x += 2;
184
+        f     += ddF_x;
185
+        if (cornername & 0x4) {
186
+            drawPixel(x0 + x, y0 + y, color);
187
+            drawPixel(x0 + y, y0 + x, color);
188
+        }
189
+        if (cornername & 0x2) {
190
+            drawPixel(x0 + x, y0 - y, color);
191
+            drawPixel(x0 + y, y0 - x, color);
192
+        }
193
+        if (cornername & 0x8) {
194
+            drawPixel(x0 - y, y0 + x, color);
195
+            drawPixel(x0 - x, y0 + y, color);
196
+        }
197
+        if (cornername & 0x1) {
198
+            drawPixel(x0 - y, y0 - x, color);
199
+            drawPixel(x0 - x, y0 - y, color);
200
+        }
201
+    }
202
+}
203
+
204
+void GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
205
+    drawFastVLine(x0, y0-r, 2*r+1, color);
206
+    fillCircleHelper(x0, y0, r, 3, 0, color);
207
+}
208
+
209
+void GFX::fillCircleHelper(int16_t x0, 
210
+                           int16_t y0, 
211
+                           int16_t r, 
212
+                           uint8_t cornername,
213
+                           int16_t delta,
214
+                           uint16_t color) {
215
+    int16_t f     = 1 - r;
216
+    int16_t ddF_x = 1;
217
+    int16_t ddF_y = -2 * r;
218
+    int16_t x     = 0;
219
+    int16_t y     = r;
220
+
221
+    while (x<y) {
222
+        if (f >= 0) {
223
+            y--;
224
+            ddF_y += 2;
225
+            f     += ddF_y;
226
+        }
227
+        x++;
228
+        ddF_x += 2;
229
+        f     += ddF_x;
230
+
231
+        if (cornername & 0x1) {
232
+            drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
233
+            drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
234
+        }
235
+        if (cornername & 0x2) {
236
+            drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
237
+            drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
238
+        }
239
+    }
240
+}
241
+
242
+void GFX::drawTriangle(int16_t x0, 
243
+                       int16_t y0,
244
+                       int16_t x1, 
245
+                       int16_t y1, 
246
+                       int16_t x2, 
247
+                       int16_t y2, 
248
+                       uint16_t color) {
249
+  drawLine(x0, y0, x1, y1, color);
250
+  drawLine(x1, y1, x2, y2, color);
251
+  drawLine(x2, y2, x0, y0, color);
252
+}
253
+
254
+void GFX::fillTriangle(int16_t x0, 
255
+                       int16_t y0,
256
+                       int16_t x1, 
257
+                       int16_t y1,
258
+                       int16_t x2, 
259
+                       int16_t y2, 
260
+                       uint16_t color) {
261
+
262
+  int16_t a, b, y, last;
263
+
264
+  // Sort coordinates by Y order (y2 >= y1 >= y0)
265
+  if (y0 > y1) {
266
+    adagfxswap(y0, y1); adagfxswap(x0, x1);
267
+  }
268
+  if (y1 > y2) {
269
+    adagfxswap(y2, y1); adagfxswap(x2, x1);
270
+  }
271
+  if (y0 > y1) {
272
+    adagfxswap(y0, y1); adagfxswap(x0, x1);
273
+  }
274
+
275
+  if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing
276
+    a = b = x0;
277
+    if(x1 < a)      a = x1;
278
+    else if(x1 > b) b = x1;
279
+    if(x2 < a)      a = x2;
280
+    else if(x2 > b) b = x2;
281
+    drawFastHLine(a, y0, b-a+1, color);
282
+    return;
283
+  }
284
+
285
+  int16_t
286
+    dx01 = x1 - x0,
287
+    dy01 = y1 - y0,
288
+    dx02 = x2 - x0,
289
+    dy02 = y2 - y0,
290
+    dx12 = x2 - x1,
291
+    dy12 = y2 - y1;
292
+  int32_t
293
+    sa   = 0,
294
+    sb   = 0;
295
+
296
+  // For upper part of triangle, find scanline crossings for segments
297
+  // 0-1 and 0-2.  If y1=y2 (flat-bottomed triangle), the scanline y1
298
+  // is included here (and second loop will be skipped, avoiding a /0
299
+  // error there), otherwise scanline y1 is skipped here and handled
300
+  // in the second loop...which also avoids a /0 error here if y0=y1
301
+  // (flat-topped triangle).
302
+  if(y1 == y2) last = y1;   // Include y1 scanline
303
+  else         last = y1-1; // Skip it
304
+
305
+  for(y=y0; y<=last; y++) {
306
+    a   = x0 + sa / dy01;
307
+    b   = x0 + sb / dy02;
308
+    sa += dx01;
309
+    sb += dx02;
310
+    /* longhand:
311
+    a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
312
+    b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
313
+    */
314
+    if(a > b) adagfxswap(a,b);
315
+    drawFastHLine(a, y, b-a+1, color);
316
+  }
317
+
318
+  // For lower part of triangle, find scanline crossings for segments
319
+  // 0-2 and 1-2.  This loop is skipped if y1=y2.
320
+  sa = dx12 * (y - y1);
321
+  sb = dx02 * (y - y0);
322
+  for(; y<=y2; y++) {
323
+    a   = x1 + sa / dy12;
324
+    b   = x0 + sb / dy02;
325
+    sa += dx12;
326
+    sb += dx02;
327
+    /* longhand:
328
+    a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
329
+    b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
330
+    */
331
+    if(a > b) adagfxswap(a,b);
332
+    drawFastHLine(a, y, b-a+1, color);
333
+  }
334
+}
335
+
336
+// Draw a rounded rectangle
337
+void GFX::drawRoundRect(int16_t x, 
338
+                        int16_t y, 
339
+                        int16_t w,
340
+                        int16_t h, 
341
+                        int16_t r, 
342
+                        uint16_t color) {
343
+                        
344
+  // smarter version
345
+  drawFastHLine(x+r  , y    , w-2*r, color); // Top
346
+  drawFastHLine(x+r  , y+h-1, w-2*r, color); // Bottom
347
+  drawFastVLine(x    , y+r  , h-2*r, color); // Left
348
+  drawFastVLine(x+w-1, y+r  , h-2*r, color); // Right
349
+  // draw four corners
350
+  drawCircleHelper(x+r    , y+r    , r, 1, color);
351
+  drawCircleHelper(x+w-r-1, y+r    , r, 2, color);
352
+  drawCircleHelper(x+w-r-1, y+h-r-1, r, 4, color);
353
+  drawCircleHelper(x+r    , y+h-r-1, r, 8, color);
354
+}
355
+
356
+void GFX::fillRoundRect(int16_t x, 
357
+                        int16_t y, 
358
+                        int16_t w,
359
+                        int16_t h, 
360
+                        int16_t r, 
361
+                        uint16_t color) {
362
+                        
363
+  // smarter version
364
+  fillRect(x+r, y, w-2*r, h, color);
365
+
366
+  // draw four corners
367
+  fillCircleHelper(x+w-r-1, y+r, r, 1, h-2*r-1, color);
368
+  fillCircleHelper(x+r    , y+r, r, 2, h-2*r-1, color);
369
+}
370
+
371
+void GFX::drawChar(int16_t x, 
372
+                  int16_t y, 
373
+                  unsigned char c,
374
+                  uint16_t color, 
375
+                  uint16_t bg, 
376
+                  uint8_t size) {
377
+
378
+    if((x >= _width)            || // Clip right
379
+       (y >= _height)           || // Clip bottom
380
+       ((x + 6 * size - 1) < 0) || // Clip left
381
+       ((y + 8 * size - 1) < 0))   // Clip top
382
+        return;
383
+
384
+    if(!_cp437 && (c >= 176)) c++; // Handle 'classic' charset behavior
385
+
386
+    for(int8_t i=0; i<6; i++ ) {
387
+        uint8_t line;
388
+        if(i < 5) line = font[(c * 5) + i];
389
+        else      line = 0x0;
390
+        for(int8_t j=0; j<8; j++, line >>= 1) {
391
+            if(line & 0x1) {
392
+                if(size == 1) drawPixel(x+i, y+j, color);
393
+                else          fillRect(x+(i*size), y+(j*size), size, size, color);
394
+            } else if(bg != color) {
395
+                if(size == 1) drawPixel(x+i, y+j, bg);
396
+                else          fillRect(x+i*size, y+j*size, size, size, bg);
397
+            }
398
+        }
399
+    }
400
+}
401
+
402
+int16_t GFX::getCursorX(void) const {
403
+    return cursor_x;
404
+}
405
+
406
+int16_t GFX::getCursorY(void) const {
407
+    return cursor_y;
408
+}
409
+
410
+void GFX::setCursor(int16_t x, int16_t y) {
411
+    cursor_x = x;
412
+    cursor_y = y;
413
+}
414
+
415
+void GFX::setTextColor(uint16_t c) {
416
+    // For 'transparent' background, we'll set the bg
417
+    // to the same as fg instead of using a flag
418
+    textcolor = textbgcolor = c;
419
+}
420
+
421
+void GFX::setTextColor(uint16_t c, uint16_t bg) {
422
+    textcolor = c;
423
+    textbgcolor = bg;
424
+}
425
+
426
+void GFX::setTextSize(uint8_t s) {
427
+    textsize = (s > 0) ? s : 1;
428
+}
429
+
430
+void GFX::setTextWrap(bool w) {
431
+    wrap = w;
432
+}
433
+
434
+uint8_t GFX::getRotation(void) const {
435
+    return rotation;
436
+}
437
+
438
+void GFX::setRotation(uint8_t r) {
439
+    rotation = (r & 3);
440
+    switch(rotation) {
441
+        case 0:
442
+        case 2:
443
+            _width  = WIDTH;
444
+            _height = HEIGHT;
445
+            break;
446
+        case 1:
447
+        case 3:
448
+            _width  = HEIGHT;
449
+            _height = WIDTH;
450
+            break;
451
+    }
452
+}
453
+
454
+void GFX::cp437(bool x) {
455
+    _cp437 = x;
456
+}
457
+
458
+void GFX::write(uint8_t c) {
459
+    
460
+    if(c == '\n') {
461
+        cursor_y += textsize*8;
462
+        cursor_x  = 0;
463
+    } else if(c == '\r') {
464
+        // skip em
465
+    } else {
466
+    
467
+        // Heading off edge?
468
+        if(wrap && ((cursor_x + textsize * 6) >= _width)) {
469
+            cursor_x  = 0;            // Reset x to zero
470
+            cursor_y += textsize * 8; // Advance y one line
471
+        }
472
+        drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
473
+        cursor_x += textsize * 6;
474
+    }
475
+}
476
+
477
+void GFX::print(std::string msg) {
478
+    int len = msg.length();
479
+    for (int idx = 0; idx < len; idx++) {
480
+        write(msg[idx]);
481
+    }
482
+}
483
+
484
+int16_t GFX::width(void) const {
485
+    return _width;
486
+}
487
+
488
+int16_t GFX::height(void) const {
489
+    return _height;
490
+}
491
+
492
+const unsigned char GFX::font[] = {    
493
+    0x00, 0x00, 0x00, 0x00, 0x00,
494
+    0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
495
+    0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
496
+    0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
497
+    0x18, 0x3C, 0x7E, 0x3C, 0x18,
498
+    0x1C, 0x57, 0x7D, 0x57, 0x1C,
499
+    0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
500
+    0x00, 0x18, 0x3C, 0x18, 0x00,
501
+    0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
502
+    0x00, 0x18, 0x24, 0x18, 0x00,
503
+    0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
504
+    0x30, 0x48, 0x3A, 0x06, 0x0E,
505
+    0x26, 0x29, 0x79, 0x29, 0x26,
506
+    0x40, 0x7F, 0x05, 0x05, 0x07,
507
+    0x40, 0x7F, 0x05, 0x25, 0x3F,
508
+    0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
509
+    0x7F, 0x3E, 0x1C, 0x1C, 0x08,
510
+    0x08, 0x1C, 0x1C, 0x3E, 0x7F,
511
+    0x14, 0x22, 0x7F, 0x22, 0x14,
512
+    0x5F, 0x5F, 0x00, 0x5F, 0x5F,
513
+    0x06, 0x09, 0x7F, 0x01, 0x7F,
514
+    0x00, 0x66, 0x89, 0x95, 0x6A,
515
+    0x60, 0x60, 0x60, 0x60, 0x60,
516
+    0x94, 0xA2, 0xFF, 0xA2, 0x94,
517
+    0x08, 0x04, 0x7E, 0x04, 0x08,
518
+    0x10, 0x20, 0x7E, 0x20, 0x10,
519
+    0x08, 0x08, 0x2A, 0x1C, 0x08,
520
+    0x08, 0x1C, 0x2A, 0x08, 0x08,
521
+    0x1E, 0x10, 0x10, 0x10, 0x10,
522
+    0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
523
+    0x30, 0x38, 0x3E, 0x38, 0x30,
524
+    0x06, 0x0E, 0x3E, 0x0E, 0x06,
525
+    0x00, 0x00, 0x00, 0x00, 0x00,
526
+    0x00, 0x00, 0x5F, 0x00, 0x00,
527
+    0x00, 0x07, 0x00, 0x07, 0x00,
528
+    0x14, 0x7F, 0x14, 0x7F, 0x14,
529
+    0x24, 0x2A, 0x7F, 0x2A, 0x12,
530
+    0x23, 0x13, 0x08, 0x64, 0x62,
531
+    0x36, 0x49, 0x56, 0x20, 0x50,
532
+    0x00, 0x08, 0x07, 0x03, 0x00,
533
+    0x00, 0x1C, 0x22, 0x41, 0x00,
534
+    0x00, 0x41, 0x22, 0x1C, 0x00,
535
+    0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
536
+    0x08, 0x08, 0x3E, 0x08, 0x08,
537
+    0x00, 0x80, 0x70, 0x30, 0x00,
538
+    0x08, 0x08, 0x08, 0x08, 0x08,
539
+    0x00, 0x00, 0x60, 0x60, 0x00,
540
+    0x20, 0x10, 0x08, 0x04, 0x02,
541
+    0x3E, 0x51, 0x49, 0x45, 0x3E,
542
+    0x00, 0x42, 0x7F, 0x40, 0x00,
543
+    0x72, 0x49, 0x49, 0x49, 0x46,
544
+    0x21, 0x41, 0x49, 0x4D, 0x33,
545
+    0x18, 0x14, 0x12, 0x7F, 0x10,
546
+    0x27, 0x45, 0x45, 0x45, 0x39,
547
+    0x3C, 0x4A, 0x49, 0x49, 0x31,
548
+    0x41, 0x21, 0x11, 0x09, 0x07,
549
+    0x36, 0x49, 0x49, 0x49, 0x36,
550
+    0x46, 0x49, 0x49, 0x29, 0x1E,
551
+    0x00, 0x00, 0x14, 0x00, 0x00,
552
+    0x00, 0x40, 0x34, 0x00, 0x00,
553
+    0x00, 0x08, 0x14, 0x22, 0x41,
554
+    0x14, 0x14, 0x14, 0x14, 0x14,
555
+    0x00, 0x41, 0x22, 0x14, 0x08,
556
+    0x02, 0x01, 0x59, 0x09, 0x06,
557
+    0x3E, 0x41, 0x5D, 0x59, 0x4E,
558
+    0x7C, 0x12, 0x11, 0x12, 0x7C,
559
+    0x7F, 0x49, 0x49, 0x49, 0x36,
560
+    0x3E, 0x41, 0x41, 0x41, 0x22,
561
+    0x7F, 0x41, 0x41, 0x41, 0x3E,
562
+    0x7F, 0x49, 0x49, 0x49, 0x41,
563
+    0x7F, 0x09, 0x09, 0x09, 0x01,
564
+    0x3E, 0x41, 0x41, 0x51, 0x73,
565
+    0x7F, 0x08, 0x08, 0x08, 0x7F,
566
+    0x00, 0x41, 0x7F, 0x41, 0x00,
567
+    0x20, 0x40, 0x41, 0x3F, 0x01,
568
+    0x7F, 0x08, 0x14, 0x22, 0x41,
569
+    0x7F, 0x40, 0x40, 0x40, 0x40,
570
+    0x7F, 0x02, 0x1C, 0x02, 0x7F,
571
+    0x7F, 0x04, 0x08, 0x10, 0x7F,
572
+    0x3E, 0x41, 0x41, 0x41, 0x3E,
573
+    0x7F, 0x09, 0x09, 0x09, 0x06,
574
+    0x3E, 0x41, 0x51, 0x21, 0x5E,
575
+    0x7F, 0x09, 0x19, 0x29, 0x46,
576
+    0x26, 0x49, 0x49, 0x49, 0x32,
577
+    0x03, 0x01, 0x7F, 0x01, 0x03,
578
+    0x3F, 0x40, 0x40, 0x40, 0x3F,
579
+    0x1F, 0x20, 0x40, 0x20, 0x1F,
580
+    0x3F, 0x40, 0x38, 0x40, 0x3F,
581
+    0x63, 0x14, 0x08, 0x14, 0x63,
582
+    0x03, 0x04, 0x78, 0x04, 0x03,
583
+    0x61, 0x59, 0x49, 0x4D, 0x43,
584
+    0x00, 0x7F, 0x41, 0x41, 0x41,
585
+    0x02, 0x04, 0x08, 0x10, 0x20,
586
+    0x00, 0x41, 0x41, 0x41, 0x7F,
587
+    0x04, 0x02, 0x01, 0x02, 0x04,
588
+    0x40, 0x40, 0x40, 0x40, 0x40,
589
+    0x00, 0x03, 0x07, 0x08, 0x00,
590
+    0x20, 0x54, 0x54, 0x78, 0x40,
591
+    0x7F, 0x28, 0x44, 0x44, 0x38,
592
+    0x38, 0x44, 0x44, 0x44, 0x28,
593
+    0x38, 0x44, 0x44, 0x28, 0x7F,
594
+    0x38, 0x54, 0x54, 0x54, 0x18,
595
+    0x00, 0x08, 0x7E, 0x09, 0x02,
596
+    0x18, 0xA4, 0xA4, 0x9C, 0x78,
597
+    0x7F, 0x08, 0x04, 0x04, 0x78,
598
+    0x00, 0x44, 0x7D, 0x40, 0x00,
599
+    0x20, 0x40, 0x40, 0x3D, 0x00,
600
+    0x7F, 0x10, 0x28, 0x44, 0x00,
601
+    0x00, 0x41, 0x7F, 0x40, 0x00,
602
+    0x7C, 0x04, 0x78, 0x04, 0x78,
603
+    0x7C, 0x08, 0x04, 0x04, 0x78,
604
+    0x38, 0x44, 0x44, 0x44, 0x38,
605
+    0xFC, 0x18, 0x24, 0x24, 0x18,
606
+    0x18, 0x24, 0x24, 0x18, 0xFC,
607
+    0x7C, 0x08, 0x04, 0x04, 0x08,
608
+    0x48, 0x54, 0x54, 0x54, 0x24,
609
+    0x04, 0x04, 0x3F, 0x44, 0x24,
610
+    0x3C, 0x40, 0x40, 0x20, 0x7C,
611
+    0x1C, 0x20, 0x40, 0x20, 0x1C,
612
+    0x3C, 0x40, 0x30, 0x40, 0x3C,
613
+    0x44, 0x28, 0x10, 0x28, 0x44,
614
+    0x4C, 0x90, 0x90, 0x90, 0x7C,
615
+    0x44, 0x64, 0x54, 0x4C, 0x44,
616
+    0x00, 0x08, 0x36, 0x41, 0x00,
617
+    0x00, 0x00, 0x77, 0x00, 0x00,
618
+    0x00, 0x41, 0x36, 0x08, 0x00,
619
+    0x02, 0x01, 0x02, 0x04, 0x02,
620
+    0x3C, 0x26, 0x23, 0x26, 0x3C,
621
+    0x1E, 0xA1, 0xA1, 0x61, 0x12,
622
+    0x3A, 0x40, 0x40, 0x20, 0x7A,
623
+    0x38, 0x54, 0x54, 0x55, 0x59,
624
+    0x21, 0x55, 0x55, 0x79, 0x41,
625
+    0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
626
+    0x21, 0x55, 0x54, 0x78, 0x40,
627
+    0x20, 0x54, 0x55, 0x79, 0x40,
628
+    0x0C, 0x1E, 0x52, 0x72, 0x12,
629
+    0x39, 0x55, 0x55, 0x55, 0x59,
630
+    0x39, 0x54, 0x54, 0x54, 0x59,
631
+    0x39, 0x55, 0x54, 0x54, 0x58,
632
+    0x00, 0x00, 0x45, 0x7C, 0x41,
633
+    0x00, 0x02, 0x45, 0x7D, 0x42,
634
+    0x00, 0x01, 0x45, 0x7C, 0x40,
635
+    0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
636
+    0xF0, 0x28, 0x25, 0x28, 0xF0,
637
+    0x7C, 0x54, 0x55, 0x45, 0x00,
638
+    0x20, 0x54, 0x54, 0x7C, 0x54,
639
+    0x7C, 0x0A, 0x09, 0x7F, 0x49,
640
+    0x32, 0x49, 0x49, 0x49, 0x32,
641
+    0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
642
+    0x32, 0x4A, 0x48, 0x48, 0x30,
643
+    0x3A, 0x41, 0x41, 0x21, 0x7A,
644
+    0x3A, 0x42, 0x40, 0x20, 0x78,
645
+    0x00, 0x9D, 0xA0, 0xA0, 0x7D,
646
+    0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
647
+    0x3D, 0x40, 0x40, 0x40, 0x3D,
648
+    0x3C, 0x24, 0xFF, 0x24, 0x24,
649
+    0x48, 0x7E, 0x49, 0x43, 0x66,
650
+    0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
651
+    0xFF, 0x09, 0x29, 0xF6, 0x20,
652
+    0xC0, 0x88, 0x7E, 0x09, 0x03,
653
+    0x20, 0x54, 0x54, 0x79, 0x41,
654
+    0x00, 0x00, 0x44, 0x7D, 0x41,
655
+    0x30, 0x48, 0x48, 0x4A, 0x32,
656
+    0x38, 0x40, 0x40, 0x22, 0x7A,
657
+    0x00, 0x7A, 0x0A, 0x0A, 0x72,
658
+    0x7D, 0x0D, 0x19, 0x31, 0x7D,
659
+    0x26, 0x29, 0x29, 0x2F, 0x28,
660
+    0x26, 0x29, 0x29, 0x29, 0x26,
661
+    0x30, 0x48, 0x4D, 0x40, 0x20,
662
+    0x38, 0x08, 0x08, 0x08, 0x08,
663
+    0x08, 0x08, 0x08, 0x08, 0x38,
664
+    0x2F, 0x10, 0xC8, 0xAC, 0xBA,
665
+    0x2F, 0x10, 0x28, 0x34, 0xFA,
666
+    0x00, 0x00, 0x7B, 0x00, 0x00,
667
+    0x08, 0x14, 0x2A, 0x14, 0x22,
668
+    0x22, 0x14, 0x2A, 0x14, 0x08,
669
+    0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
670
+    0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
671
+    0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
672
+    0x00, 0x00, 0x00, 0xFF, 0x00,
673
+    0x10, 0x10, 0x10, 0xFF, 0x00,
674
+    0x14, 0x14, 0x14, 0xFF, 0x00,
675
+    0x10, 0x10, 0xFF, 0x00, 0xFF,
676
+    0x10, 0x10, 0xF0, 0x10, 0xF0,
677
+    0x14, 0x14, 0x14, 0xFC, 0x00,
678
+    0x14, 0x14, 0xF7, 0x00, 0xFF,
679
+    0x00, 0x00, 0xFF, 0x00, 0xFF,
680
+    0x14, 0x14, 0xF4, 0x04, 0xFC,
681
+    0x14, 0x14, 0x17, 0x10, 0x1F,
682
+    0x10, 0x10, 0x1F, 0x10, 0x1F,
683
+    0x14, 0x14, 0x14, 0x1F, 0x00,
684
+    0x10, 0x10, 0x10, 0xF0, 0x00,
685
+    0x00, 0x00, 0x00, 0x1F, 0x10,
686
+    0x10, 0x10, 0x10, 0x1F, 0x10,
687
+    0x10, 0x10, 0x10, 0xF0, 0x10,
688
+    0x00, 0x00, 0x00, 0xFF, 0x10,
689
+    0x10, 0x10, 0x10, 0x10, 0x10,
690
+    0x10, 0x10, 0x10, 0xFF, 0x10,
691
+    0x00, 0x00, 0x00, 0xFF, 0x14,
692
+    0x00, 0x00, 0xFF, 0x00, 0xFF,
693
+    0x00, 0x00, 0x1F, 0x10, 0x17,
694
+    0x00, 0x00, 0xFC, 0x04, 0xF4,
695
+    0x14, 0x14, 0x17, 0x10, 0x17,
696
+    0x14, 0x14, 0xF4, 0x04, 0xF4,
697
+    0x00, 0x00, 0xFF, 0x00, 0xF7,
698
+    0x14, 0x14, 0x14, 0x14, 0x14,
699
+    0x14, 0x14, 0xF7, 0x00, 0xF7,
700
+    0x14, 0x14, 0x14, 0x17, 0x14,
701
+    0x10, 0x10, 0x1F, 0x10, 0x1F,
702
+    0x14, 0x14, 0x14, 0xF4, 0x14,
703
+    0x10, 0x10, 0xF0, 0x10, 0xF0,
704
+    0x00, 0x00, 0x1F, 0x10, 0x1F,
705
+    0x00, 0x00, 0x00, 0x1F, 0x14,
706
+    0x00, 0x00, 0x00, 0xFC, 0x14,
707
+    0x00, 0x00, 0xF0, 0x10, 0xF0,
708
+    0x10, 0x10, 0xFF, 0x10, 0xFF,
709
+    0x14, 0x14, 0x14, 0xFF, 0x14,
710
+    0x10, 0x10, 0x10, 0x1F, 0x00,
711
+    0x00, 0x00, 0x00, 0xF0, 0x10,
712
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
713
+    0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
714
+    0xFF, 0xFF, 0xFF, 0x00, 0x00,
715
+    0x00, 0x00, 0x00, 0xFF, 0xFF,
716
+    0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
717
+    0x38, 0x44, 0x44, 0x38, 0x44,
718
+    0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
719
+    0x7E, 0x02, 0x02, 0x06, 0x06,
720
+    0x02, 0x7E, 0x02, 0x7E, 0x02,
721
+    0x63, 0x55, 0x49, 0x41, 0x63,
722
+    0x38, 0x44, 0x44, 0x3C, 0x04,
723
+    0x40, 0x7E, 0x20, 0x1E, 0x20,
724
+    0x06, 0x02, 0x7E, 0x02, 0x02,
725
+    0x99, 0xA5, 0xE7, 0xA5, 0x99,
726
+    0x1C, 0x2A, 0x49, 0x2A, 0x1C,
727
+    0x4C, 0x72, 0x01, 0x72, 0x4C,
728
+    0x30, 0x4A, 0x4D, 0x4D, 0x30,
729
+    0x30, 0x48, 0x78, 0x48, 0x30,
730
+    0xBC, 0x62, 0x5A, 0x46, 0x3D,
731
+    0x3E, 0x49, 0x49, 0x49, 0x00,
732
+    0x7E, 0x01, 0x01, 0x01, 0x7E,
733
+    0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
734
+    0x44, 0x44, 0x5F, 0x44, 0x44,
735
+    0x40, 0x51, 0x4A, 0x44, 0x40,
736
+    0x40, 0x44, 0x4A, 0x51, 0x40,
737
+    0x00, 0x00, 0xFF, 0x01, 0x03,
738
+    0xE0, 0x80, 0xFF, 0x00, 0x00,
739
+    0x08, 0x08, 0x6B, 0x6B, 0x08,
740
+    0x36, 0x12, 0x36, 0x24, 0x36,
741
+    0x06, 0x0F, 0x09, 0x0F, 0x06,
742
+    0x00, 0x00, 0x18, 0x18, 0x00,
743
+    0x00, 0x00, 0x10, 0x10, 0x00,
744
+    0x30, 0x40, 0xFF, 0x01, 0x01,
745
+    0x00, 0x1F, 0x01, 0x01, 0x1E,
746
+    0x00, 0x19, 0x1D, 0x17, 0x12,
747
+    0x00, 0x3C, 0x3C, 0x3C, 0x3C,
748
+    0x00, 0x00, 0x00, 0x00, 0x00  // #255 NBSP
749
+};

+ 407
- 0
src/ili9341/gfx.h View File

@@ -0,0 +1,407 @@
1
+/**
2
+ * Author: Shawn Hymel
3
+ * Copyright (c) 2016 SparkFun Electronics
4
+ *
5
+ * Based on GFX interface by Yevgeniy Kiveisha and Adafruit Industries.
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
+
27
+#pragma once
28
+
29
+#include <mraa.hpp>
30
+
31
+#define adagfxswap(a, b) { int16_t t = a; a = b; b = t; }
32
+
33
+namespace upm 
34
+{
35
+
36
+    /**
37
+     * @brief GFX helper class
38
+     */
39
+    class GFX {
40
+        public:
41
+        
42
+            /**
43
+             * Creates a GFX object
44
+             *
45
+             * @param w Screen width
46
+             * @param h Screen height
47
+             */
48
+            GFX(int16_t w, int16_t h);
49
+             
50
+            /**
51
+             * Sends a pixel color (RGB) to the driver chip. This must be
52
+             * defined by the subclass (pure virtual function).
53
+             *
54
+             * @param x Axis on the horizontal scale
55
+             * @param y Axis on the vertical scale
56
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
57
+             */
58
+            virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
59
+            
60
+            /**
61
+             * Draw a line.
62
+             *
63
+             * @param x0 Start of line x coordinate
64
+             * @param y0 Start of line y coordinate
65
+             * @param x1 End of line x coordinate
66
+             * @param y1 End of line y coordinate
67
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
68
+             */            
69
+            virtual void drawLine(int16_t x0, 
70
+                                  int16_t y0, 
71
+                                  int16_t x1, 
72
+                                  int16_t y1, 
73
+                                  uint16_t color);
74
+            
75
+            /**
76
+             * Draws a vertical line using minimal SPI writes.
77
+             *
78
+             * @param x Axis on the horizontal scale to begin line
79
+             * @param y Axis on the vertical scale to begin line
80
+             * @param h Height of line in pixels
81
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
82
+             */
83
+            virtual void drawFastVLine(int16_t x, 
84
+                                       int16_t y, 
85
+                                       int16_t h, 
86
+                                       uint16_t color);
87
+            
88
+            /**
89
+             * Draws a horizontal line using  minimal SPI writes.
90
+             *
91
+             * @param x Axis on the horizontal scale to begin line
92
+             * @param y Axis on the vertical scale to begin line
93
+             * @param w Width of line in pixels
94
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
95
+             */
96
+            virtual void drawFastHLine(int16_t x, 
97
+                                       int16_t y, 
98
+                                       int16_t w, 
99
+                                       uint16_t color);
100
+    
101
+            /**
102
+             * Draws a rectangle (not filled).
103
+             *
104
+             * @param x Position of upper left corner on horizontal axis
105
+             * @param y Position of upper left corner on vertical axis
106
+             * @param w Width of rectangle
107
+             * @param h Height of rectangle
108
+             * @color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
109
+             */
110
+            virtual void drawRect(int16_t x, 
111
+                                  int16_t y, 
112
+                                  int16_t w, 
113
+                                  int16_t h, 
114
+                                  uint16_t color);
115
+                                 
116
+            /**
117
+             * Draw a filled rectangle.
118
+             *
119
+             * @param x Axis on the horizontal scale of upper-left corner
120
+             * @param y Axis on the vertical scale of upper-left corner
121
+             * @param w Width of rectangle in pixels
122
+             * @param h Height of rectangle in pixels
123
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
124
+             */ 
125
+            virtual void fillRect(int16_t x, 
126
+                                  int16_t y, 
127
+                                  int16_t w, 
128
+                                  int16_t h, 
129
+                                  uint16_t color);
130
+    
131
+            /**
132
+             * Fill the screen with a single color.
133
+             *
134
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
135
+             */
136
+            virtual void fillScreen(uint16_t color);
137
+    
138
+            /**
139
+             * Invert colors on the display.
140
+             *
141
+             * @param i True or false to invert colors
142
+             */
143
+            virtual void invertDisplay(bool i);
144
+            
145
+            /**
146
+             * Draw a circle outline.
147
+             *
148
+             * @param x0 Center point of circle on x-axis
149
+             * @param y0 Center point of circle on y-axis
150
+             * @param r Radius of circle
151
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
152
+             */
153
+            void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
154
+            
155
+            /**
156
+             * Used to draw rounded corners.
157
+             *
158
+             * @param x0 Center point of circle on x-axis
159
+             * @param y0 Center point of circle on y-axis
160
+             * @param r Radius of circle
161
+             * @param cornername Mask of corner number (1, 2, 4, 8)
162
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
163
+             */
164
+            void drawCircleHelper(int16_t x0, 
165
+                                  int16_t y0, 
166
+                                  int16_t r, 
167
+                                  uint8_t cornername,
168
+                                  uint16_t color);
169
+
170
+            /**
171
+             * Draws a filled circle.
172
+             *
173
+             * @param x0 Center point of circle on x-axis
174
+             * @param y0 Center point of circle on y-axis
175
+             * @param r Radius of circle
176
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
177
+             */    
178
+            void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
179
+    
180
+            /**
181
+             * Used to draw a filled circle and rounded rectangles.
182
+             *
183
+             * @param x0 Center point of circle on x-axis
184
+             * @param y0 Center point of circle on y-axis
185
+             * @param r Radius of circle
186
+             * @param cornername Mask of corner number (1, 2, 4, 8)
187
+             * @param delta Line offset
188
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
189
+             */
190
+            void fillCircleHelper(int16_t x0, 
191
+                                  int16_t y0, 
192
+                                  int16_t r, 
193
+                                  uint8_t cornername,
194
+                                  int16_t delta,
195
+                                  uint16_t color);
196
+                                  
197
+            /**
198
+             * Draw a triangle.
199
+             *
200
+             * @param x0 First point coordinate on x-axis
201
+             * @param y0 First point coordinate on y-axis
202
+             * @param x1 Second point coordinate on x-axis
203
+             * @param y1 Second point coordinate on y-axis
204
+             * @param x2 Third point coordinate on x-axis
205
+             * @param y2 Third point coordinate on y-axis
206
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
207
+             */
208
+            void drawTriangle(int16_t x0, 
209
+                              int16_t y0, 
210
+                              int16_t x1, 
211
+                              int16_t y1,
212
+                              int16_t x2, 
213
+                              int16_t y2, 
214
+                              uint16_t color);
215
+                              
216
+            /**
217
+             * Draw a filled triangle.
218
+             *
219
+             * @param x0 First point coordinate on x-axis
220
+             * @param y0 First point coordinate on y-axis
221
+             * @param x1 Second point coordinate on x-axis
222
+             * @param y1 Second point coordinate on y-axis
223
+             * @param x2 Third point coordinate on x-axis
224
+             * @param y2 Third point coordinate on y-axis
225
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
226
+             */
227
+            void fillTriangle(int16_t x0,
228
+                              int16_t y0,
229
+                              int16_t x1,
230
+                              int16_t y1,
231
+                              int16_t x2,
232
+                              int16_t y2,
233
+                              uint16_t color);
234
+
235
+            /**
236
+             * Draw a rectangle with rounded corners
237
+             *
238
+             * @param x0 X-axis coordinate of top-left corner
239
+             * @param y0 Y-axis coordinate of top-left corner
240
+             * @param w Width of rectangle
241
+             * @param h height of rectangle
242
+             * @param radius Radius of rounded corners
243
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
244
+             */
245
+            void drawRoundRect(int16_t x0, 
246
+                               int16_t y0, 
247
+                               int16_t w, 
248
+                               int16_t h,
249
+                               int16_t radius, 
250
+                               uint16_t color);
251
+                               
252
+            /**
253
+             * Draw a filled rectangle with rounded corners
254
+             *
255
+             * @param x0 X-axis coordinate of top-left corner
256
+             * @param y0 Y-axis coordinate of top-left corner
257
+             * @param w Width of rectangle
258
+             * @param h height of rectangle
259
+             * @param radius Radius of rounded corners
260
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
261
+             */
262
+            void fillRoundRect(int16_t x0, 
263
+                               int16_t y0, 
264
+                               int16_t w, 
265
+                               int16_t h,
266
+                               int16_t radius, 
267
+                               uint16_t color);
268
+                               
269
+            /**
270
+             * Draw a character at the specified point.
271
+             *
272
+             * @param x X-axis coordinate of the top-left corner
273
+             * @param y Y-axis coordinate of the top-left corner
274
+             * @param c Character to draw
275
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
276
+             * @param bg Background color (16-bit RGB)
277
+             * @param size Font size
278
+             */
279
+            void drawChar(int16_t x, 
280
+                          int16_t y, 
281
+                          unsigned char c, 
282
+                          uint16_t color,
283
+                          uint16_t bg, 
284
+                          uint8_t size);
285
+            
286
+            /**
287
+             * Get the x-axis coordinate of the upper-left corner of the cursor.
288
+             *
289
+             * @return X-axis coordinate of the cursor
290
+             */
291
+            int16_t getCursorX(void) const;
292
+            
293
+            /**
294
+             * Get the y-axis coordinate of the upper-left corner of the cursor.
295
+             *
296
+             * @return Y-axis coordinate of the cursor
297
+             */
298
+            int16_t getCursorY(void) const;
299
+             
300
+            /**
301
+             * Set the cursor for writing text.
302
+             *
303
+             * @param x X-axis coordinate of the top-left corner of the cursor
304
+             * @param y Y-axis coordinate of the top-left corner of the cursor
305
+             */
306
+            void setCursor(int16_t x, int16_t y);
307
+             
308
+            /**
309
+             * Set the color for text.
310
+             *
311
+             * @param c RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
312
+             */
313
+            void setTextColor(uint16_t c);
314
+            
315
+            /**
316
+             * Set the color for text and text background (highlight).
317
+             *
318
+             * @param c Text color (RGB, 16-bit)
319
+             * @param bg Background text color (RGB, 16-bit)
320
+             */
321
+            void setTextColor(uint16_t c, uint16_t bg);
322
+            
323
+            /**
324
+             * Set the size of the text.
325
+             *
326
+             * @param s Font size (multiples of 8 pixel text height)
327
+             */ 
328
+            void setTextSize(uint8_t s);
329
+            
330
+            /**
331
+             * Enable or disable text wrapping.
332
+             *
333
+             * @param w True to wrap text. False to truncate.
334
+             */
335
+            void setTextWrap(bool w);
336
+            
337
+            /**
338
+             * Get the current rotation configuration of the screen.
339
+             *
340
+             * @return current rotation 0-3
341
+             */
342
+            uint8_t getRotation(void) const;
343
+            
344
+            /**
345
+             * Sets the rotation of the screen. Can be overridden with another
346
+             * screen-specific definition.
347
+             *
348
+             * @param r Rotation 0-3
349
+             */
350
+            void setRotation(uint8_t r);
351
+                        
352
+            /**
353
+             * Enable (or disable) Code Page 437-compatible charset.
354
+             *
355
+             * @param x True to enable CP437 charset. False to disable.
356
+             */
357
+            void cp437(bool x);
358
+            
359
+            /**
360
+             * Write a character at the current cursor position. Definition
361
+             * can be overridden with board-specific code.
362
+             *
363
+             * @param c Character to draw
364
+             */
365
+            virtual void write(uint8_t c);
366
+            
367
+            /**
368
+             * Prints a string to the screen.
369
+             *
370
+             * @param s Message to print
371
+             */
372
+            void print(std::string msg);
373
+            
374
+            /**
375
+             * Get the current width of the screen.
376
+             *
377
+             * @return the width in pixels
378
+             */
379
+            int16_t width(void) const;
380
+            
381
+            /**
382
+             * Get the current height of the screen.
383
+             *
384
+             * @return the height in pixels
385
+             */
386
+            int16_t height(void) const;
387
+            
388
+        protected:
389
+        
390
+            const int16_t WIDTH;
391
+            const int16_t HEIGHT;
392
+            
393
+            int16_t _width;
394
+            int16_t _height;
395
+            
396
+            uint8_t rotation;
397
+            
398
+            uint16_t textcolor;
399
+            uint16_t textbgcolor;
400
+            int16_t cursor_x;
401
+            int16_t cursor_y;
402
+            uint8_t textsize;
403
+            bool wrap;
404
+            bool _cp437;
405
+            static const unsigned char font[];
406
+    };
407
+}     

+ 487
- 0
src/ili9341/ili9341.cxx View File

@@ -0,0 +1,487 @@
1
+/*
2
+ * Author: Shawn Hymel
3
+ * Copyright (c) 2015 SparkFun Electronics
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
+
28
+#include <iostream>
29
+#include <string>
30
+#include <stdexcept>
31
+#include <unistd.h>
32
+#include <stdlib.h>
33
+#include <stdio.h>
34
+#include <string.h>
35
+
36
+#include "ili9341.h"
37
+
38
+using namespace upm;
39
+
40
+ILI9341::ILI9341(uint8_t csLCD, uint8_t csSD, uint8_t dc, uint8_t rst) :
41
+    GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT), m_csLCDPinCtx(csLCD), 
42
+    m_csSDPinCtx(csSD), m_dcPinCtx(dc), m_rstPinCtx(rst), m_spi(0) {
43
+    
44
+    initModule();
45
+    configModule();
46
+}
47
+
48
+void ILI9341::initModule() {
49
+    mraa::Result error = mraa::SUCCESS;
50
+    
51
+    error = m_csLCDPinCtx.dir(mraa::DIR_OUT);
52
+    if (error != mraa::SUCCESS) {
53
+        mraa::printError(error);
54
+    }
55
+    
56
+    error = m_csSDPinCtx.dir(mraa::DIR_OUT);
57
+    if (error != mraa::SUCCESS) {
58
+        mraa::printError(error);
59
+    }
60
+    
61
+    error = m_dcPinCtx.dir(mraa::DIR_OUT);
62
+    if (error != mraa::SUCCESS) {
63
+        mraa::printError(error);
64
+    }
65
+    
66
+    error = m_rstPinCtx.dir(mraa::DIR_OUT);
67
+    if (error != mraa::SUCCESS) {
68
+        mraa::printError(error);
69
+    }
70
+    
71
+    error = m_spi.frequency(SPI_FREQ);
72
+    if (error != mraa::SUCCESS) {
73
+        mraa::printError (error);
74
+    }
75
+    
76
+    lcdCSOff();
77
+}
78
+
79
+void ILI9341::setRotation(uint8_t r) {
80
+
81
+    writecommand(ILI9341_MADCTL);
82
+    r = r % 4; // can't be higher than 3
83
+    switch(r) {
84
+    case 0:
85
+        writedata(MADCTL_MX | MADCTL_BGR);
86
+        _width  = ILI9341_TFTWIDTH;
87
+        _height = ILI9341_TFTHEIGHT;
88
+        break;
89
+    case 1:
90
+        writedata(MADCTL_MV | MADCTL_BGR);
91
+        _width  = ILI9341_TFTHEIGHT;
92
+        _height = ILI9341_TFTWIDTH;
93
+        break;
94
+    case 2:
95
+        writedata(MADCTL_MY | MADCTL_BGR);
96
+        _width  = ILI9341_TFTWIDTH;
97
+        _height = ILI9341_TFTHEIGHT;
98
+        break;
99
+    case 3:
100
+        writedata(MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR);
101
+        _width  = ILI9341_TFTHEIGHT;
102
+        _height = ILI9341_TFTWIDTH;
103
+        break;
104
+    }
105
+}
106
+
107
+void ILI9341::configModule() {
108
+    
109
+    // Toggle RST low to reset
110
+    rstHigh();
111
+    usleep(5000);
112
+    rstLow();
113
+    usleep(20000);
114
+    rstHigh();
115
+    usleep(150000);
116
+
117
+    // Send initialization commands
118
+    writecommand(0xEF);
119
+    writedata(0x03);
120
+    writedata(0x80);
121
+    writedata(0x02);
122
+
123
+    writecommand(0xCF);  
124
+    writedata(0x00); 
125
+    writedata(0XC1); 
126
+    writedata(0X30); 
127
+
128
+    writecommand(0xED);  
129
+    writedata(0x64); 
130
+    writedata(0x03); 
131
+    writedata(0X12); 
132
+    writedata(0X81); 
133
+
134
+    writecommand(0xE8);  
135
+    writedata(0x85); 
136
+    writedata(0x00); 
137
+    writedata(0x78); 
138
+
139
+    writecommand(0xCB);  
140
+    writedata(0x39); 
141
+    writedata(0x2C); 
142
+    writedata(0x00); 
143
+    writedata(0x34); 
144
+    writedata(0x02); 
145
+
146
+    writecommand(0xF7);  
147
+    writedata(0x20); 
148
+
149
+    writecommand(0xEA);  
150
+    writedata(0x00); 
151
+    writedata(0x00); 
152
+
153
+    writecommand(ILI9341_PWCTR1);    //Power control 
154
+    writedata(0x23);   //VRH[5:0] 
155
+
156
+    writecommand(ILI9341_PWCTR2);    //Power control 
157
+    writedata(0x10);   //SAP[2:0];BT[3:0] 
158
+
159
+    writecommand(ILI9341_VMCTR1);    //VCM control 
160
+    writedata(0x3e);
161
+    writedata(0x28); 
162
+
163
+    writecommand(ILI9341_VMCTR2);    //VCM control2 
164
+    writedata(0x86);  //--
165
+
166
+    writecommand(ILI9341_MADCTL);    // Memory Access Control 
167
+    writedata(0x48);
168
+
169
+    writecommand(ILI9341_PIXFMT);    
170
+    writedata(0x55); 
171
+
172
+    writecommand(ILI9341_FRMCTR1);    
173
+    writedata(0x00);  
174
+    writedata(0x18); 
175
+
176
+    writecommand(ILI9341_DFUNCTR);    // Display Function Control 
177
+    writedata(0x08); 
178
+    writedata(0x82);
179
+    writedata(0x27);  
180
+
181
+    writecommand(0xF2);    // 3Gamma Function Disable 
182
+    writedata(0x00); 
183
+
184
+    writecommand(ILI9341_GAMMASET);    //Gamma curve selected 
185
+    writedata(0x01); 
186
+
187
+    writecommand(ILI9341_GMCTRP1);    //Set Gamma 
188
+    writedata(0x0F); 
189
+    writedata(0x31); 
190
+    writedata(0x2B); 
191
+    writedata(0x0C); 
192
+    writedata(0x0E); 
193
+    writedata(0x08); 
194
+    writedata(0x4E); 
195
+    writedata(0xF1); 
196
+    writedata(0x37); 
197
+    writedata(0x07); 
198
+    writedata(0x10); 
199
+    writedata(0x03); 
200
+    writedata(0x0E); 
201
+    writedata(0x09); 
202
+    writedata(0x00); 
203
+
204
+    writecommand(ILI9341_GMCTRN1);    //Set Gamma 
205
+    writedata(0x00); 
206
+    writedata(0x0E); 
207
+    writedata(0x14); 
208
+    writedata(0x03); 
209
+    writedata(0x11); 
210
+    writedata(0x07); 
211
+    writedata(0x31); 
212
+    writedata(0xC1); 
213
+    writedata(0x48); 
214
+    writedata(0x08); 
215
+    writedata(0x0F); 
216
+    writedata(0x0C); 
217
+    writedata(0x31); 
218
+    writedata(0x36); 
219
+    writedata(0x0F);
220
+    
221
+    writecommand(ILI9341_SLPOUT);
222
+    usleep(120000);
223
+    writecommand(ILI9341_DISPON);
224
+}
225
+
226
+void ILI9341::setAddrWindow(uint16_t x0, 
227
+                            uint16_t y0, 
228
+                            uint16_t x1, 
229
+                            uint16_t y1) {
230
+    
231
+    writecommand(ILI9341_CASET); // Column addr set
232
+    writedata(x0 >> 8);
233
+    writedata(x0 & 0xFF);     // XSTART 
234
+    writedata(x1 >> 8);
235
+    writedata(x1 & 0xFF);     // XEND
236
+    
237
+    writecommand(ILI9341_PASET); // Row addr set
238
+    writedata(y0>>8);
239
+    writedata(y0);     // YSTART
240
+    writedata(y1>>8);
241
+    writedata(y1);     // YEND
242
+
243
+    writecommand(ILI9341_RAMWR); // write to RAM
244
+}
245
+
246
+void ILI9341::drawPixel(int16_t x, int16_t y, uint16_t color) {
247
+    
248
+    if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) {
249
+        return;
250
+    }
251
+    
252
+    setAddrWindow(x, y, x + 1, y + 1);
253
+    
254
+    writedata(color >> 8);
255
+    writedata(color);
256
+}
257
+
258
+void ILI9341::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
259
+
260
+    // Rudimentary clipping
261
+    if((x >= _width) || (y >= _height)) {
262
+        return;
263
+    }
264
+    
265
+    if((y+h-1) >= _height) {
266
+        h = _height-y;
267
+    }
268
+
269
+    setAddrWindow(x, y, x, y+h-1);
270
+
271
+    uint8_t hi = color >> 8;
272
+    uint8_t lo = color;
273
+    
274
+    lcdCSOn();
275
+    dcHigh();
276
+
277
+    while (h--) {
278
+        m_spi.writeByte(hi);
279
+        m_spi.writeByte(lo);
280
+    }
281
+
282
+    lcdCSOff();
283
+}
284
+
285
+void ILI9341::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) {
286
+
287
+    // Rudimentary clipping
288
+    if((x >= _width) || (y >= _height)) {
289
+        return;
290
+    }
291
+
292
+    if((x+w-1) >= _width) {
293
+        w = _width - x;
294
+    }
295
+
296
+    setAddrWindow(x, y, x+w-1, y);
297
+
298
+    uint8_t hi = color >> 8;
299
+    uint8_t lo = color;
300
+
301
+    lcdCSOn();
302
+    dcHigh();
303
+
304
+    while (w--) {
305
+        m_spi.writeByte(hi);
306
+        m_spi.writeByte(lo);
307
+    }
308
+
309
+    lcdCSOff();
310
+}
311
+
312
+void ILI9341::fillRect(int16_t x, 
313
+                       int16_t y, 
314
+                       int16_t w, 
315
+                       int16_t h,
316
+                       uint16_t color) {
317
+                       
318
+    // rudimentary clipping (drawChar w/big text requires this)
319
+    if((x >= _width) || (y >= _height)) return;
320
+    if((x + w - 1) >= _width)  w = _width  - x;
321
+    if((y + h - 1) >= _height) h = _height - y;
322
+
323
+    setAddrWindow(x, y, x+w-1, y+h-1);
324
+
325
+    uint8_t hi = color >> 8;
326
+    uint8_t lo = color;
327
+  
328
+    lcdCSOn();
329
+    dcHigh();
330
+
331
+    for(y = h; y > 0; y--) {
332
+        for(x = w; x > 0; x--) {
333
+            m_spi.writeByte(hi);
334
+            m_spi.writeByte(lo);
335
+        }
336
+    }
337
+
338
+    lcdCSOff();
339
+}
340
+
341
+void ILI9341::fillScreen(uint16_t color) {
342
+    fillRect(0, 0,  _width, _height, color);
343
+}
344
+
345
+void ILI9341::invertDisplay(bool i) {
346
+    writecommand(i ? ILI9341_INVON : ILI9341_INVOFF);
347
+}
348
+
349
+uint16_t ILI9341::color565(uint8_t r, uint8_t g, uint8_t b) {
350
+    return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
351
+}
352
+
353
+void ILI9341::executeCMDList(const uint8_t *addr) {
354
+    uint8_t numCommands, numArgs;
355
+    uint16_t ms;
356
+        
357
+    numCommands = *(addr++);        // Number of commands to follow
358
+    while (numCommands--) {         // For each command...
359
+        writecommand(*(addr++));    // Read, issue command
360
+        numArgs = *(addr++);        // Number of args to follow
361
+        ms = numArgs & DELAY;       // If hibit set, delay follows args
362
+        numArgs &= ~DELAY;          // Mask out delay bit
363
+        while (numArgs--) {         // For each argument...
364
+            writedata(*(addr++));   // Read, issue argument
365
+        }
366
+        
367
+        if (ms) {
368
+            ms = *(addr++);         // Read post-command delay time (ms)
369
+            if (ms == 255) {
370
+                ms = 500;           // If 255, delay for 500 ms
371
+            }
372
+            usleep(ms * 1000);
373
+        }
374
+    }
375
+}
376
+
377
+void ILI9341::writecommand(uint8_t c) {
378
+    lcdCSOn();
379
+    dcLow();
380
+    m_spi.writeByte(c);
381
+    lcdCSOff();
382
+}
383
+
384
+void ILI9341::writedata(uint8_t d) {
385
+    lcdCSOn();
386
+    dcHigh();
387
+    m_spi.writeByte(d);
388
+    lcdCSOff();
389
+}
390
+
391
+mraa::Result ILI9341::lcdCSOn() {
392
+    mraa::Result error = mraa::SUCCESS;
393
+
394
+    error = m_csLCDPinCtx.write(LOW);
395
+    if (error != mraa::SUCCESS) {
396
+        mraa::printError (error);
397
+    }
398
+
399
+    error = m_csSDPinCtx.write(HIGH);
400
+    if (error != mraa::SUCCESS) {
401
+        mraa::printError (error);
402
+    }
403
+
404
+    return error;
405
+}
406
+
407
+mraa::Result ILI9341::lcdCSOff() {
408
+    mraa::Result error = mraa::SUCCESS;
409
+
410
+    error = m_csLCDPinCtx.write(HIGH);
411
+    if (error != mraa::SUCCESS) {
412
+        mraa::printError (error);
413
+    }
414
+
415
+    return error;
416
+}
417
+
418
+mraa::Result ILI9341::sdCSOn() {
419
+    mraa::Result error = mraa::SUCCESS;
420
+
421
+    error = m_csSDPinCtx.write(LOW);
422
+    if (error != mraa::SUCCESS) {
423
+        mraa::printError (error);
424
+    }
425
+
426
+    error = m_csLCDPinCtx.write(HIGH);
427
+    if (error != mraa::SUCCESS) {
428
+        mraa::printError (error);
429
+    }
430
+
431
+    return error;
432
+}
433
+
434
+mraa::Result ILI9341::sdCSOff() {
435
+    mraa::Result error = mraa::SUCCESS;
436
+
437
+    error = m_csSDPinCtx.write(HIGH);
438
+    if (error != mraa::SUCCESS) {
439
+        mraa::printError (error);
440
+    }
441
+
442
+    return error;
443
+}
444
+
445
+mraa::Result ILI9341::dcHigh() {
446
+    mraa::Result error = mraa::SUCCESS;
447
+
448
+    error = m_dcPinCtx.write(HIGH);
449
+    if (error != mraa::SUCCESS) {
450
+        mraa::printError(error);
451
+    }
452
+
453
+    return error;
454
+}
455
+
456
+mraa::Result ILI9341::dcLow() {
457
+    mraa::Result error = mraa::SUCCESS;
458
+
459
+    error = m_dcPinCtx.write(LOW);
460
+    if (error != mraa::SUCCESS) {
461
+        mraa::printError(error);
462
+    }
463
+
464
+    return error;
465
+}
466
+
467
+mraa::Result ILI9341::rstHigh() {
468
+    mraa::Result error = mraa::SUCCESS;
469
+    
470
+    error = m_rstPinCtx.write(HIGH);
471
+    if (error != mraa::SUCCESS) {
472
+        mraa::printError(error);
473
+    }
474
+    
475
+    return error;
476
+}
477
+
478
+mraa::Result ILI9341::rstLow() {
479
+    mraa::Result error = mraa::SUCCESS;
480
+
481
+    error = m_rstPinCtx.write(LOW);
482
+    if (error != mraa::SUCCESS) {
483
+        mraa::printError(error);
484
+    }
485
+
486
+    return error;
487
+}

+ 345
- 0
src/ili9341/ili9341.h View File

@@ -0,0 +1,345 @@
1
+/*
2
+ * Author: Shawn Hymel
3
+ * Copyright (c) 2015 SparkFun Electronics
4
+ *
5
+ * Credits to Adafruit.
6
+ * Based on Adafruit ILI9341 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
+
28
+#pragma once
29
+
30
+// Includes
31
+#include <string>
32
+#include <mraa/common.hpp>
33
+#include <mraa/gpio.hpp>
34
+#include <mraa/spi.hpp>
35
+#include <gfx.h>
36
+
37
+// Defines
38
+#define ILI9341_TFTWIDTH    240
39
+#define ILI9341_TFTHEIGHT   320
40
+
41
+#define SPI_FREQ            15000000
42
+
43
+#define ILI9341_NOP         0x00
44
+#define ILI9341_SWRESET     0x01
45
+#define ILI9341_RDDID       0x04
46
+#define ILI9341_RDDST       0x09
47
+
48
+#define ILI9341_SLPIN       0x10
49
+#define ILI9341_SLPOUT      0x11
50
+#define ILI9341_PTLON       0x12
51
+#define ILI9341_NORON       0x13
52
+
53
+#define ILI9341_RDMODE      0x0A
54
+#define ILI9341_RDMADCTL    0x0B
55
+#define ILI9341_RDPIXFMT    0x0C
56
+#define ILI9341_RDIMGFMT    0x0D
57
+#define ILI9341_RDSELFDIAG  0x0F
58
+
59
+#define ILI9341_INVOFF      0x20
60
+#define ILI9341_INVON       0x21
61
+#define ILI9341_GAMMASET    0x26
62
+#define ILI9341_DISPOFF     0x28
63
+#define ILI9341_DISPON      0x29
64
+
65
+#define ILI9341_CASET       0x2A
66
+#define ILI9341_PASET       0x2B
67
+#define ILI9341_RAMWR       0x2C
68
+#define ILI9341_RAMRD       0x2E
69
+
70
+#define ILI9341_PTLAR       0x30
71
+#define ILI9341_MADCTL      0x36
72
+#define ILI9341_PIXFMT      0x3A
73
+
74
+#define ILI9341_FRMCTR1     0xB1
75
+#define ILI9341_FRMCTR2     0xB2
76
+#define ILI9341_FRMCTR3     0xB3
77
+#define ILI9341_INVCTR      0xB4
78
+#define ILI9341_DFUNCTR     0xB6
79
+
80
+#define ILI9341_PWCTR1      0xC0
81
+#define ILI9341_PWCTR2      0xC1
82
+#define ILI9341_PWCTR3      0xC2
83
+#define ILI9341_PWCTR4      0xC3
84
+#define ILI9341_PWCTR5      0xC4
85
+#define ILI9341_VMCTR1      0xC5
86
+#define ILI9341_VMCTR2      0xC7
87
+
88
+#define ILI9341_RDID1       0xDA
89
+#define ILI9341_RDID2       0xDB
90
+#define ILI9341_RDID3       0xDC
91
+#define ILI9341_RDID4       0xDD
92
+
93
+#define ILI9341_GMCTRP1     0xE0
94
+#define ILI9341_GMCTRN1     0xE1
95
+
96
+#define MADCTL_MY  0x80
97
+#define MADCTL_MX  0x40
98
+#define MADCTL_MV  0x20
99
+#define MADCTL_ML  0x10
100
+#define MADCTL_RGB 0x00
101
+#define MADCTL_BGR 0x08
102
+#define MADCTL_MH  0x04
103
+
104
+#define HIGH                1
105
+#define LOW                 0
106
+
107
+#define DELAY               0x80
108
+
109
+// Color definitions
110
+#define ILI9341_BLACK       0x0000      /*   0,   0,   0 */
111
+#define ILI9341_NAVY        0x000F      /*   0,   0, 128 */
112
+#define ILI9341_DARKGREEN   0x03E0      /*   0, 128,   0 */
113
+#define ILI9341_DARKCYAN    0x03EF      /*   0, 128, 128 */
114
+#define ILI9341_MAROON      0x7800      /* 128,   0,   0 */
115
+#define ILI9341_PURPLE      0x780F      /* 128,   0, 128 */
116
+#define ILI9341_OLIVE       0x7BE0      /* 128, 128,   0 */
117
+#define ILI9341_LIGHTGREY   0xC618      /* 192, 192, 192 */
118
+#define ILI9341_DARKGREY    0x7BEF      /* 128, 128, 128 */
119
+#define ILI9341_BLUE        0x001F      /*   0,   0, 255 */
120
+#define ILI9341_GREEN       0x07E0      /*   0, 255,   0 */
121
+#define ILI9341_CYAN        0x07FF      /*   0, 255, 255 */
122
+#define ILI9341_RED         0xF800      /* 255,   0,   0 */
123
+#define ILI9341_MAGENTA     0xF81F      /* 255,   0, 255 */
124
+#define ILI9341_YELLOW      0xFFE0      /* 255, 255,   0 */
125
+#define ILI9341_WHITE       0xFFFF      /* 255, 255, 255 */
126
+#define ILI9341_ORANGE      0xFD20      /* 255, 165,   0 */
127
+#define ILI9341_GREENYELLOW 0xAFE5      /* 173, 255,  47 */
128
+#define ILI9341_PINK        0xF81F
129
+
130
+namespace upm {
131
+
132
+    /**
133
+     * @brief ILI9341 LCD library
134
+     * @defgroup ili9341 libupm-ili9341
135
+     * @ingroup adafruit spi display
136
+     */
137
+    /**
138
+     * @library ili9341
139
+     * @sensor ili9341
140
+     * @comname ILI9341 LCD
141
+     * @type display
142
+     * @man adafruit
143
+     * @web http://www.adafruit.com/product/2090
144
+     * @con spi
145
+     *
146
+     * @brief API for the ILI9342 LCd
147
+     *
148
+     * This module defines the interface for the ILI9341 display library
149
+     *
150
+     * @image html ili9341.jpg
151
+     * @snippet ili9341.cxx Interesting
152
+     */
153
+    class ILI9341 : public GFX {
154
+        public:
155
+            /**
156
+             * Instantiates an ILI9341 object
157
+             *
158
+             * @param csLCD LCD chip select pin
159
+             * @param csSD SD card select pin
160
+             * @param dc Data/command pin
161
+             * @param rst Reset pin
162
+             */
163
+            ILI9341(uint8_t csLCD, uint8_t csSD, uint8_t dc, uint8_t rst);
164
+            
165
+            /**
166
+             * Returns the name of the component
167
+             */
168
+            std::string name() {
169
+                return m_name;
170
+            }
171
+            
172
+            /**
173
+             * Initializes GPIOs used to talk to the LCD
174
+             */
175
+            void initModule();
176
+            
177
+            /**
178
+             * Configures the LCD driver chip via SPI
179
+             */
180
+            void configModule();
181
+            
182
+            /**
183
+             * Sets the window size inside the screen where pixel data is 
184
+             * written. Concrete implementation from GFX interface.
185
+             *
186
+             * @param x0 First coordinate
187
+             * @param y0 First coordinate
188
+             * @param x1 Second coordinate
189
+             * @param y1 Second coordinate
190
+             */
191
+            void setAddrWindow(uint16_t x0, 
192
+                               uint16_t y0, 
193
+                               uint16_t x1, 
194
+                               uint16_t y1);
195
+            
196
+            /**
197
+             * Sends a pixel color (RGB) to the driver chip. Concrete
198
+             * implementation from GFX interface.
199
+             *
200
+             * @param x Axis on the horizontal scale
201
+             * @param y Axis on the vertical scale
202
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
203
+             */
204
+            void drawPixel(int16_t x, int16_t y, uint16_t color);
205
+
206
+            /**
207
+             * Draws a vertical line using minimal SPI writes.
208
+             *
209
+             * @param x Axis on the horizontal scale to begin line
210
+             * @param y Axis on the vertical scale to begin line
211
+             * @param h Height of line in pixels
212
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
213
+             */
214
+            void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
215
+            
216
+            /**
217
+             * Draws a horizontal line using  minimal SPI writes.
218
+             *
219
+             * @param x Axis on the horizontal scale to begin line
220
+             * @param y Axis on the vertical scale to begin line
221
+             * @param w Width of line in pixels
222
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
223
+             */
224
+            void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
225
+            
226
+            /**
227
+             * Draw a filled rectangle.
228
+             *
229
+             * @param x Axis on the horizontal scale of upper-left corner
230
+             * @param y Axis on the vertical scale of upper-left corner
231
+             * @param w Width of rectangle in pixels
232
+             * @param h Height of rectangle in pixels
233
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
234
+             */
235
+            void fillRect(int16_t x, 
236
+                          int16_t y, 
237
+                          int16_t w, 
238
+                          int16_t h,
239
+                          uint16_t color);
240
+                          
241
+            /**
242
+             * Fill the screen with a single color.
243
+             *
244
+             * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
245
+             */
246
+            void fillScreen(uint16_t color);
247
+            
248
+            /**
249
+             * Sets the screen to one of four 90 deg rotations.
250
+             *
251
+             * @param r Rotation setting: 0, 1, 2, 3
252
+             */
253
+            void setRotation(uint8_t r);
254
+            
255
+            /**
256
+             * Invert colors on the display.
257
+             *
258
+             * @param i True or false to invert colors
259
+             */
260
+            void invertDisplay(bool i);
261
+            
262
+            /**
263
+             * Pass 8-bit R, G, B values and get back 16-bit packed color.
264
+             *
265
+             * @param r Red color 0-31
266
+             * @param g Green color 0-63
267
+             * @param b blue color 0-31
268
+             * @return 16-bit packed color (RGB) value
269
+             */
270
+            uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
271
+                        
272
+            /**
273
+             * Executes a set of commands and data.
274
+             *
275
+             * @param addr Pointer to the start of the commands/data section
276
+             */
277
+            void executeCMDList(const uint8_t *addr);
278
+            
279
+            /**
280
+             * Sends a command to the display driver via SPI.
281
+             *
282
+             * @param c Command to be written
283
+             */
284
+            void writecommand(uint8_t c);
285
+            
286
+            /**
287
+             * Sends data to the display driver via SPI
288
+             *
289
+             * @param d Data to be written
290
+             */
291
+            void writedata(uint8_t d);
292
+            
293
+            /**
294
+             * Set LCD chip select to LOW
295
+             */
296
+            mraa::Result lcdCSOn();
297
+            
298
+            /**
299
+             * Set LCD chip select to HIGH
300
+             */
301
+            mraa::Result lcdCSOff();
302
+            
303
+            /**
304
+             * Set SD card chip select to LOW
305
+             */
306
+            mraa::Result sdCSOn();
307
+            
308
+            /**
309
+             * Set SD card chip select to HIGH
310
+             */
311
+            mraa::Result sdCSOff();
312
+            
313
+            /**
314
+             * Set data/command line to HIGH
315
+             */
316
+            mraa::Result dcHigh();
317
+            
318
+            /**
319
+             * Set data/command line to LOW
320
+             */
321
+            mraa::Result dcLow();
322
+            
323
+            /**
324
+             * Set reset line to HIGH
325
+             */
326
+            mraa::Result rstHigh();
327
+            
328
+            /**
329
+             * Set reset line to LOW
330
+             */
331
+            mraa::Result rstLow();
332
+            
333
+        private:
334
+            mraa::Spi   m_spi;
335
+            uint8_t     m_spiBuffer[32];
336
+            
337
+            mraa::Gpio  m_csLCDPinCtx;
338
+            mraa::Gpio  m_csSDPinCtx;
339
+            mraa::Gpio  m_dcPinCtx;
340
+            mraa::Gpio  m_rstPinCtx;
341
+            
342
+            std::string m_name;
343
+    };
344
+}
345
+

+ 12
- 0
src/ili9341/jsupm_ili9341.i View File

@@ -0,0 +1,12 @@
1
+%module jsupm_ili9341
2
+%include "../upm.i"
3
+
4
+%include "gfx.h"
5
+%{
6
+    #include "gfx.h"
7
+%}
8
+
9
+%include "ili9341.h"
10
+%{
11
+    #include "ili9341.h"
12
+%}

+ 16
- 0
src/ili9341/pyupm_ili9341.i View File

@@ -0,0 +1,16 @@
1
+// Include doxygen-generated documentation
2
+%include "pyupm_doxy2swig.i"
3
+%module pyupm_ili9341
4
+%include "../upm.i"
5
+
6
+%feature("autodoc", "3");
7
+
8
+%include "gfx.h"
9
+%{
10
+    #include "gfx.h"
11
+%}
12
+
13
+%include "ili9341.h"
14
+%{
15
+    #include "ili9341.h"
16
+%}