Просмотр исходного кода

ssd1351: Initial implementation

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Mihai Tudor Panu 8 лет назад
Родитель
Сommit
144937995c

Двоичные данные
docs/images/ssd1351.jpg Просмотреть файл


+ 9
- 8
examples/c++/CMakeLists.txt Просмотреть файл

@@ -10,7 +10,7 @@ macro(get_module_name example_name module_name)
10 10
   elseif ((${example_name} MATCHES "^mq" AND ${length} EQUAL 3) OR ${example_name} STREQUAL "tp401")
11 11
     set (${module_name} "gas")
12 12
   else()
13
-    set(${module_name} ${example_name}) 
13
+    set(${module_name} ${example_name})
14 14
   endif()
15 15
 endmacro()
16 16
 
@@ -25,25 +25,25 @@ macro(add_custom_example example_bin example_src example_module_list)
25 25
     if (MODULE_LIST)
26 26
       list(FIND MODULE_LIST ${module} index)
27 27
       if (${index} EQUAL -1)
28
-        set(found_all_modules FALSE)      	
28
+        set(found_all_modules FALSE)
29 29
       endif()
30 30
     endif()
31 31
   endforeach()
32 32
   if (found_all_modules)
33 33
     add_executable (${example_bin} ${example_src})
34
-    target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})  
34
+    target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
35 35
     foreach (module ${example_module_list})
36 36
       set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}")
37 37
       include_directories (${module_dir})
38 38
       if (${module} STREQUAL "lcd")
39
-      	set(module "i2clcd")
39
+        set(module "i2clcd")
40 40
       endif()
41
-      target_link_libraries (${example_bin} ${module})    
41
+      target_link_libraries (${example_bin} ${module})
42 42
     endforeach()
43 43
   else()
44 44
    MESSAGE(INFO " Ignored ${example_bin}")
45 45
    set (example_bin "")
46
-  endif()  	
46
+  endif()
47 47
 endmacro()
48 48
 
49 49
 
@@ -56,13 +56,13 @@ macro(add_example example_name)
56 56
   set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}")
57 57
   if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}"
58 58
      AND EXISTS ${module_dir}
59
-     AND IS_DIRECTORY ${module_dir})  
59
+     AND IS_DIRECTORY ${module_dir})
60 60
     add_custom_example(${example_bin} ${example_src} ${module_name})
61 61
     if ((NOT ${example_bin} STREQUAL "") AND (${module_name} STREQUAL "grove"))
62 62
       set(grove_module_path "${PROJECT_SOURCE_DIR}/src/${example_name}")
63 63
       if (EXISTS ${grove_module_path})
64 64
         include_directories(${grove_module_path})
65
-        target_link_libraries (${example_bin} ${example_name})  
65
+        target_link_libraries (${example_bin} ${example_name})
66 66
       endif()
67 67
     endif()
68 68
   else()
@@ -239,6 +239,7 @@ add_example (hdxxvxta)
239 239
 add_example (rhusb)
240 240
 add_example (apds9930)
241 241
 add_example (kxcjk1013)
242
+add_example (ssd1351)
242 243
 
243 244
 # These are special cases where you specify example binary, source file and module(s)
244 245
 include_directories (${PROJECT_SOURCE_DIR}/src)

+ 61
- 0
examples/c++/ssd1351.cxx Просмотреть файл

@@ -0,0 +1,61 @@
1
+#include "mraa.hpp"
2
+#include <iostream>
3
+#include <unistd.h>
4
+
5
+#include "ssd1351.h"
6
+
7
+#define BLACK       0x0000
8
+#define WHITE       0xFFFF
9
+#define INTEL_BLUE  0x0BF8
10
+
11
+int main(int argc, char **argv)
12
+{
13
+    // Define colors (16-bit RGB on 5/6/5 bits)
14
+    int colors[] = {0x0000, 0x000F, 0x03E0, 0x03EF,
15
+                    0x7800, 0x780F, 0x7BE0, 0xC618,
16
+                    0x7BEF, 0x001F, 0x07E0, 0x07FF,
17
+                    0xF800, 0xF81F, 0xFFE0, 0xFFFF};
18
+//! [Interesting]
19
+    // Initialize display with pins
20
+    // oc = 0, dc = 1, r  = 2, si = 11, cl = 13
21
+    upm::SSD1351* display = new upm::SSD1351(0, 1, 2);
22
+
23
+    // Test lines pixel by pixel
24
+    for(int i = 0; i < SSD1351HEIGHT; i++) {
25
+        for(int j = 0; j < SSD1351WIDTH; j++) {
26
+            display->drawPixel(i, j, colors[i/8]);
27
+        }
28
+    }
29
+    display->refresh();
30
+    sleep(5);
31
+
32
+    // Test rectangles
33
+    for(int i = 0; i < SSD1351HEIGHT/32; i++) {
34
+        for (int j = 0; j < SSD1351WIDTH/32; j++) {
35
+            display->fillRect(i * 32, j * 32, 32, 32, colors[i * 4 + j]);
36
+        }
37
+    }
38
+    display->refresh();
39
+    sleep(5);
40
+
41
+    // Test circles
42
+    display->fillScreen(0x2104);
43
+    for(int i = 0; i < SSD1351HEIGHT/32; i++) {
44
+        for (int j = 0; j < SSD1351WIDTH/32; j++) {
45
+            display->drawCircle(i * 32 + 15, j * 32 + 15, 15, colors[i * 4 + j]);
46
+        }
47
+    }
48
+    display->refresh();
49
+    sleep(5);
50
+
51
+    // Test Text
52
+    display->fillScreen(INTEL_BLUE);
53
+    display->setTextColor(WHITE, INTEL_BLUE);
54
+    display->setTextSize(4);
55
+    display->setCursor(7, 30);
56
+    display->print("Intel");
57
+    display->setCursor(5, 70);
58
+    display->print("IoTDK");
59
+    display->refresh();
60
+//! [Interesting]
61
+}

+ 5
- 0
src/ssd1351/CMakeLists.txt Просмотреть файл

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

+ 218
- 0
src/ssd1351/gfx.cxx Просмотреть файл

@@ -0,0 +1,218 @@
1
+/*
2
+ * Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ *          Mihai Tudor Panu <mihai.tudor.panu@intel.com>
4
+ *
5
+ * Copyright (c) 2016 Intel Corporation.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining
8
+ * a copy of this software and associated documentation files (the
9
+ * "Software"), to deal in the Software without restriction, including
10
+ * without limitation the rights to use, copy, modify, merge, publish,
11
+ * distribute, sublicense, and/or sell copies of the Software, and to
12
+ * permit persons to whom the Software is furnished to do so, subject to
13
+ * the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ */
26
+
27
+#include <iostream>
28
+#include <unistd.h>
29
+#include <stdlib.h>
30
+
31
+#include "gfx.h"
32
+
33
+using namespace upm;
34
+
35
+GFX::GFX (int width, int height) : m_width(width), m_height(height),
36
+        m_textSize(1), m_textColor(0xFFFF), m_textBGColor(0x0000),
37
+        m_cursorX(0), m_cursorY(0), m_font(font) {
38
+}
39
+
40
+GFX::~GFX () {
41
+}
42
+
43
+void
44
+GFX::fillScreen (uint16_t color) {
45
+    fillRect(0, 0, m_width, m_height, color);
46
+}
47
+
48
+void
49
+GFX::fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
50
+    for (int16_t i=x; i<x+w; i++) {
51
+        drawFastVLine(i, y, h, color);
52
+    }
53
+}
54
+
55
+void
56
+GFX::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
57
+    drawLine(x, y, x, y+h-1, color);
58
+}
59
+
60
+void
61
+GFX::drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
62
+    int16_t steep = abs(y1 - y0) > abs(x1 - x0);
63
+
64
+    if (steep) {
65
+        swap(x0, y0);
66
+        swap(x1, y1);
67
+    }
68
+
69
+    if (x0 > x1) {
70
+        swap(x0, x1);
71
+        swap(y0, y1);
72
+    }
73
+
74
+    int16_t dx, dy;
75
+    dx = x1 - x0;
76
+    dy = abs (y1 - y0);
77
+
78
+    int16_t err = dx / 2;
79
+    int16_t ystep;
80
+
81
+    if (y0 < y1) {
82
+        ystep = 1;
83
+    } else {
84
+        ystep = -1;
85
+    }
86
+
87
+    for (; x0 <= x1; x0++) {
88
+        if (steep) {
89
+            drawPixel(y0, x0, color);
90
+        } else {
91
+            drawPixel(x0, y0, color);
92
+        }
93
+        err -= dy;
94
+        if (err < 0) {
95
+            y0 += ystep;
96
+            err += dx;
97
+        }
98
+    }
99
+}
100
+
101
+void
102
+GFX::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) {
103
+    drawLine(x0, y0, x1, y1, color);
104
+    drawLine(x1, y1, x2, y2, color);
105
+    drawLine(x2, y2, x0, y0, color);
106
+}
107
+
108
+void
109
+GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
110
+    int16_t f = 1 - r;
111
+    int16_t ddF_x = 1;
112
+    int16_t ddF_y = -2 * r;
113
+    int16_t x = 0;
114
+    int16_t y = r;
115
+
116
+    drawPixel(x0  , y0+r, color);
117
+    drawPixel(x0  , y0-r, color);
118
+    drawPixel(x0+r, y0  , color);
119
+    drawPixel(x0-r, y0  , color);
120
+
121
+    while (x<y) {
122
+        if (f >= 0) {
123
+            y--;
124
+            ddF_y += 2;
125
+            f += ddF_y;
126
+        }
127
+        x++;
128
+
129
+        ddF_x += 2;
130
+        f += ddF_x;
131
+
132
+        drawPixel(x0 + x, y0 + y, color);
133
+        drawPixel(x0 - x, y0 + y, color);
134
+        drawPixel(x0 + x, y0 - y, color);
135
+        drawPixel(x0 - x, y0 - y, color);
136
+        drawPixel(x0 + y, y0 + x, color);
137
+        drawPixel(x0 - y, y0 + x, color);
138
+        drawPixel(x0 + y, y0 - x, color);
139
+        drawPixel(x0 - y, y0 - x, color);
140
+    }
141
+}
142
+
143
+void
144
+GFX::setCursor (int16_t x, int16_t y) {
145
+    m_cursorX = x;
146
+    m_cursorY = y;
147
+}
148
+
149
+void
150
+GFX::setTextColor (uint16_t textColor, uint16_t textBGColor) {
151
+    m_textColor   = textColor;
152
+    m_textBGColor = textBGColor;
153
+}
154
+
155
+void
156
+GFX::setTextSize (uint8_t size) {
157
+    m_textSize = (size > 0) ? size : 1;
158
+}
159
+
160
+void
161
+GFX::setTextWrap (uint8_t wrap) {
162
+    m_wrap = wrap;
163
+}
164
+
165
+void
166
+GFX::drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size) {
167
+    if( (x >= m_width)            || // Clip right
168
+        (y >= m_height)           || // Clip bottom
169
+        ((x + 6 * size - 1) < 0)  || // Clip left
170
+        ((y + 8 * size - 1) < 0))    // Clip top
171
+    return;
172
+
173
+    for (int8_t i=0; i<6; i++ ) {
174
+        uint8_t line;
175
+        if (i == 5) {
176
+            line = 0x0;
177
+        } else {
178
+            line = *(m_font+(data * 5)+i);
179
+            for (int8_t j = 0; j<8; j++) {
180
+                if (line & 0x1) {
181
+                    if (size == 1) // default size
182
+                        drawPixel (x+i, y+j, color);
183
+                    else {  // big size
184
+                        fillRect (x+(i*size), y+(j*size), size, size, color);
185
+                    }
186
+                } else if (bg != color) {
187
+                    if (size == 1) // default size
188
+                        drawPixel (x+i, y+j, bg);
189
+                    else {  // big size
190
+                        fillRect (x+i*size, y+j*size, size, size, bg);
191
+                    }
192
+                }
193
+                line >>= 1;
194
+            }
195
+        }
196
+    }
197
+}
198
+
199
+void
200
+GFX::print (std::string msg) {
201
+    int len = msg.length();
202
+
203
+    for (int idx = 0; idx < len; idx++) {
204
+        if (msg[idx] == '\n') {
205
+            m_cursorY += m_textSize * 8;
206
+            m_cursorX  = 0;
207
+        } else if (msg[idx] == '\r') {
208
+            // skip em
209
+        } else {
210
+            drawChar(m_cursorX, m_cursorY, msg[idx], m_textColor, m_textBGColor, m_textSize);
211
+            m_cursorX += m_textSize * 6;
212
+            if (m_wrap && ((m_cursorX + m_textSize * 6) >= m_width)) {
213
+                m_cursorY += m_textSize * 8;
214
+                m_cursorX = 0;
215
+            }
216
+        }
217
+    }
218
+}

+ 453
- 0
src/ssd1351/gfx.h Просмотреть файл

@@ -0,0 +1,453 @@
1
+/*
2
+ * Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ *          Mihai Tudor Panu <mihai.tudor.panu@intel.com>
4
+ *
5
+ * Copyright (c) 2016 Intel Corporation.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining
8
+ * a copy of this software and associated documentation files (the
9
+ * "Software"), to deal in the Software without restriction, including
10
+ * without limitation the rights to use, copy, modify, merge, publish,
11
+ * distribute, sublicense, and/or sell copies of the Software, and to
12
+ * permit persons to whom the Software is furnished to do so, subject to
13
+ * the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ */
26
+#pragma once
27
+
28
+#include <string>
29
+#include <stdio.h>
30
+#include <unistd.h>
31
+#include <stdint.h>
32
+
33
+#define swap(a, b) { int16_t t = a; a = b; b = t; }
34
+
35
+namespace upm {
36
+
37
+const unsigned char font[] = {
38
+    0x00, 0x00, 0x00, 0x00, 0x00,
39
+    0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
40
+    0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
41
+    0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
42
+    0x18, 0x3C, 0x7E, 0x3C, 0x18,
43
+    0x1C, 0x57, 0x7D, 0x57, 0x1C,
44
+    0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
45
+    0x00, 0x18, 0x3C, 0x18, 0x00,
46
+    0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
47
+    0x00, 0x18, 0x24, 0x18, 0x00,
48
+    0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
49
+    0x30, 0x48, 0x3A, 0x06, 0x0E,
50
+    0x26, 0x29, 0x79, 0x29, 0x26,
51
+    0x40, 0x7F, 0x05, 0x05, 0x07,
52
+    0x40, 0x7F, 0x05, 0x25, 0x3F,
53
+    0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
54
+    0x7F, 0x3E, 0x1C, 0x1C, 0x08,
55
+    0x08, 0x1C, 0x1C, 0x3E, 0x7F,
56
+    0x14, 0x22, 0x7F, 0x22, 0x14,
57
+    0x5F, 0x5F, 0x00, 0x5F, 0x5F,
58
+    0x06, 0x09, 0x7F, 0x01, 0x7F,
59
+    0x00, 0x66, 0x89, 0x95, 0x6A,
60
+    0x60, 0x60, 0x60, 0x60, 0x60,
61
+    0x94, 0xA2, 0xFF, 0xA2, 0x94,
62
+    0x08, 0x04, 0x7E, 0x04, 0x08,
63
+    0x10, 0x20, 0x7E, 0x20, 0x10,
64
+    0x08, 0x08, 0x2A, 0x1C, 0x08,
65
+    0x08, 0x1C, 0x2A, 0x08, 0x08,
66
+    0x1E, 0x10, 0x10, 0x10, 0x10,
67
+    0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
68
+    0x30, 0x38, 0x3E, 0x38, 0x30,
69
+    0x06, 0x0E, 0x3E, 0x0E, 0x06,
70
+    0x00, 0x00, 0x00, 0x00, 0x00,
71
+    0x00, 0x00, 0x5F, 0x00, 0x00,
72
+    0x00, 0x07, 0x00, 0x07, 0x00,
73
+    0x14, 0x7F, 0x14, 0x7F, 0x14,
74
+    0x24, 0x2A, 0x7F, 0x2A, 0x12,
75
+    0x23, 0x13, 0x08, 0x64, 0x62,
76
+    0x36, 0x49, 0x56, 0x20, 0x50,
77
+    0x00, 0x08, 0x07, 0x03, 0x00,
78
+    0x00, 0x1C, 0x22, 0x41, 0x00,
79
+    0x00, 0x41, 0x22, 0x1C, 0x00,
80
+    0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
81
+    0x08, 0x08, 0x3E, 0x08, 0x08,
82
+    0x00, 0x80, 0x70, 0x30, 0x00,
83
+    0x08, 0x08, 0x08, 0x08, 0x08,
84
+    0x00, 0x00, 0x60, 0x60, 0x00,
85
+    0x20, 0x10, 0x08, 0x04, 0x02,
86
+    0x3E, 0x51, 0x49, 0x45, 0x3E,
87
+    0x00, 0x42, 0x7F, 0x40, 0x00,
88
+    0x72, 0x49, 0x49, 0x49, 0x46,
89
+    0x21, 0x41, 0x49, 0x4D, 0x33,
90
+    0x18, 0x14, 0x12, 0x7F, 0x10,
91
+    0x27, 0x45, 0x45, 0x45, 0x39,
92
+    0x3C, 0x4A, 0x49, 0x49, 0x31,
93
+    0x41, 0x21, 0x11, 0x09, 0x07,
94
+    0x36, 0x49, 0x49, 0x49, 0x36,
95
+    0x46, 0x49, 0x49, 0x29, 0x1E,
96
+    0x00, 0x00, 0x14, 0x00, 0x00,
97
+    0x00, 0x40, 0x34, 0x00, 0x00,
98
+    0x00, 0x08, 0x14, 0x22, 0x41,
99
+    0x14, 0x14, 0x14, 0x14, 0x14,
100
+    0x00, 0x41, 0x22, 0x14, 0x08,
101
+    0x02, 0x01, 0x59, 0x09, 0x06,
102
+    0x3E, 0x41, 0x5D, 0x59, 0x4E,
103
+    0x7C, 0x12, 0x11, 0x12, 0x7C,
104
+    0x7F, 0x49, 0x49, 0x49, 0x36,
105
+    0x3E, 0x41, 0x41, 0x41, 0x22,
106
+    0x7F, 0x41, 0x41, 0x41, 0x3E,
107
+    0x7F, 0x49, 0x49, 0x49, 0x41,
108
+    0x7F, 0x09, 0x09, 0x09, 0x01,
109
+    0x3E, 0x41, 0x41, 0x51, 0x73,
110
+    0x7F, 0x08, 0x08, 0x08, 0x7F,
111
+    0x00, 0x41, 0x7F, 0x41, 0x00,
112
+    0x20, 0x40, 0x41, 0x3F, 0x01,
113
+    0x7F, 0x08, 0x14, 0x22, 0x41,
114
+    0x7F, 0x40, 0x40, 0x40, 0x40,
115
+    0x7F, 0x02, 0x1C, 0x02, 0x7F,
116
+    0x7F, 0x04, 0x08, 0x10, 0x7F,
117
+    0x3E, 0x41, 0x41, 0x41, 0x3E,
118
+    0x7F, 0x09, 0x09, 0x09, 0x06,
119
+    0x3E, 0x41, 0x51, 0x21, 0x5E,
120
+    0x7F, 0x09, 0x19, 0x29, 0x46,
121
+    0x26, 0x49, 0x49, 0x49, 0x32,
122
+    0x03, 0x01, 0x7F, 0x01, 0x03,
123
+    0x3F, 0x40, 0x40, 0x40, 0x3F,
124
+    0x1F, 0x20, 0x40, 0x20, 0x1F,
125
+    0x3F, 0x40, 0x38, 0x40, 0x3F,
126
+    0x63, 0x14, 0x08, 0x14, 0x63,
127
+    0x03, 0x04, 0x78, 0x04, 0x03,
128
+    0x61, 0x59, 0x49, 0x4D, 0x43,
129
+    0x00, 0x7F, 0x41, 0x41, 0x41,
130
+    0x02, 0x04, 0x08, 0x10, 0x20,
131
+    0x00, 0x41, 0x41, 0x41, 0x7F,
132
+    0x04, 0x02, 0x01, 0x02, 0x04,
133
+    0x40, 0x40, 0x40, 0x40, 0x40,
134
+    0x00, 0x03, 0x07, 0x08, 0x00,
135
+    0x20, 0x54, 0x54, 0x78, 0x40,
136
+    0x7F, 0x28, 0x44, 0x44, 0x38,
137
+    0x38, 0x44, 0x44, 0x44, 0x28,
138
+    0x38, 0x44, 0x44, 0x28, 0x7F,
139
+    0x38, 0x54, 0x54, 0x54, 0x18,
140
+    0x00, 0x08, 0x7E, 0x09, 0x02,
141
+    0x18, 0xA4, 0xA4, 0x9C, 0x78,
142
+    0x7F, 0x08, 0x04, 0x04, 0x78,
143
+    0x00, 0x44, 0x7D, 0x40, 0x00,
144
+    0x20, 0x40, 0x40, 0x3D, 0x00,
145
+    0x7F, 0x10, 0x28, 0x44, 0x00,
146
+    0x00, 0x41, 0x7F, 0x40, 0x00,
147
+    0x7C, 0x04, 0x78, 0x04, 0x78,
148
+    0x7C, 0x08, 0x04, 0x04, 0x78,
149
+    0x38, 0x44, 0x44, 0x44, 0x38,
150
+    0xFC, 0x18, 0x24, 0x24, 0x18,
151
+    0x18, 0x24, 0x24, 0x18, 0xFC,
152
+    0x7C, 0x08, 0x04, 0x04, 0x08,
153
+    0x48, 0x54, 0x54, 0x54, 0x24,
154
+    0x04, 0x04, 0x3F, 0x44, 0x24,
155
+    0x3C, 0x40, 0x40, 0x20, 0x7C,
156
+    0x1C, 0x20, 0x40, 0x20, 0x1C,
157
+    0x3C, 0x40, 0x30, 0x40, 0x3C,
158
+    0x44, 0x28, 0x10, 0x28, 0x44,
159
+    0x4C, 0x90, 0x90, 0x90, 0x7C,
160
+    0x44, 0x64, 0x54, 0x4C, 0x44,
161
+    0x00, 0x08, 0x36, 0x41, 0x00,
162
+    0x00, 0x00, 0x77, 0x00, 0x00,
163
+    0x00, 0x41, 0x36, 0x08, 0x00,
164
+    0x02, 0x01, 0x02, 0x04, 0x02,
165
+    0x3C, 0x26, 0x23, 0x26, 0x3C,
166
+    0x1E, 0xA1, 0xA1, 0x61, 0x12,
167
+    0x3A, 0x40, 0x40, 0x20, 0x7A,
168
+    0x38, 0x54, 0x54, 0x55, 0x59,
169
+    0x21, 0x55, 0x55, 0x79, 0x41,
170
+    0x21, 0x54, 0x54, 0x78, 0x41,
171
+    0x21, 0x55, 0x54, 0x78, 0x40,
172
+    0x20, 0x54, 0x55, 0x79, 0x40,
173
+    0x0C, 0x1E, 0x52, 0x72, 0x12,
174
+    0x39, 0x55, 0x55, 0x55, 0x59,
175
+    0x39, 0x54, 0x54, 0x54, 0x59,
176
+    0x39, 0x55, 0x54, 0x54, 0x58,
177
+    0x00, 0x00, 0x45, 0x7C, 0x41,
178
+    0x00, 0x02, 0x45, 0x7D, 0x42,
179
+    0x00, 0x01, 0x45, 0x7C, 0x40,
180
+    0xF0, 0x29, 0x24, 0x29, 0xF0,
181
+    0xF0, 0x28, 0x25, 0x28, 0xF0,
182
+    0x7C, 0x54, 0x55, 0x45, 0x00,
183
+    0x20, 0x54, 0x54, 0x7C, 0x54,
184
+    0x7C, 0x0A, 0x09, 0x7F, 0x49,
185
+    0x32, 0x49, 0x49, 0x49, 0x32,
186
+    0x32, 0x48, 0x48, 0x48, 0x32,
187
+    0x32, 0x4A, 0x48, 0x48, 0x30,
188
+    0x3A, 0x41, 0x41, 0x21, 0x7A,
189
+    0x3A, 0x42, 0x40, 0x20, 0x78,
190
+    0x00, 0x9D, 0xA0, 0xA0, 0x7D,
191
+    0x39, 0x44, 0x44, 0x44, 0x39,
192
+    0x3D, 0x40, 0x40, 0x40, 0x3D,
193
+    0x3C, 0x24, 0xFF, 0x24, 0x24,
194
+    0x48, 0x7E, 0x49, 0x43, 0x66,
195
+    0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
196
+    0xFF, 0x09, 0x29, 0xF6, 0x20,
197
+    0xC0, 0x88, 0x7E, 0x09, 0x03,
198
+    0x20, 0x54, 0x54, 0x79, 0x41,
199
+    0x00, 0x00, 0x44, 0x7D, 0x41,
200
+    0x30, 0x48, 0x48, 0x4A, 0x32,
201
+    0x38, 0x40, 0x40, 0x22, 0x7A,
202
+    0x00, 0x7A, 0x0A, 0x0A, 0x72,
203
+    0x7D, 0x0D, 0x19, 0x31, 0x7D,
204
+    0x26, 0x29, 0x29, 0x2F, 0x28,
205
+    0x26, 0x29, 0x29, 0x29, 0x26,
206
+    0x30, 0x48, 0x4D, 0x40, 0x20,
207
+    0x38, 0x08, 0x08, 0x08, 0x08,
208
+    0x08, 0x08, 0x08, 0x08, 0x38,
209
+    0x2F, 0x10, 0xC8, 0xAC, 0xBA,
210
+    0x2F, 0x10, 0x28, 0x34, 0xFA,
211
+    0x00, 0x00, 0x7B, 0x00, 0x00,
212
+    0x08, 0x14, 0x2A, 0x14, 0x22,
213
+    0x22, 0x14, 0x2A, 0x14, 0x08,
214
+    0xAA, 0x00, 0x55, 0x00, 0xAA,
215
+    0xAA, 0x55, 0xAA, 0x55, 0xAA,
216
+    0x00, 0x00, 0x00, 0xFF, 0x00,
217
+    0x10, 0x10, 0x10, 0xFF, 0x00,
218
+    0x14, 0x14, 0x14, 0xFF, 0x00,
219
+    0x10, 0x10, 0xFF, 0x00, 0xFF,
220
+    0x10, 0x10, 0xF0, 0x10, 0xF0,
221
+    0x14, 0x14, 0x14, 0xFC, 0x00,
222
+    0x14, 0x14, 0xF7, 0x00, 0xFF,
223
+    0x00, 0x00, 0xFF, 0x00, 0xFF,
224
+    0x14, 0x14, 0xF4, 0x04, 0xFC,
225
+    0x14, 0x14, 0x17, 0x10, 0x1F,
226
+    0x10, 0x10, 0x1F, 0x10, 0x1F,
227
+    0x14, 0x14, 0x14, 0x1F, 0x00,
228
+    0x10, 0x10, 0x10, 0xF0, 0x00,
229
+    0x00, 0x00, 0x00, 0x1F, 0x10,
230
+    0x10, 0x10, 0x10, 0x1F, 0x10,
231
+    0x10, 0x10, 0x10, 0xF0, 0x10,
232
+    0x00, 0x00, 0x00, 0xFF, 0x10,
233
+    0x10, 0x10, 0x10, 0x10, 0x10,
234
+    0x10, 0x10, 0x10, 0xFF, 0x10,
235
+    0x00, 0x00, 0x00, 0xFF, 0x14,
236
+    0x00, 0x00, 0xFF, 0x00, 0xFF,
237
+    0x00, 0x00, 0x1F, 0x10, 0x17,
238
+    0x00, 0x00, 0xFC, 0x04, 0xF4,
239
+    0x14, 0x14, 0x17, 0x10, 0x17,
240
+    0x14, 0x14, 0xF4, 0x04, 0xF4,
241
+    0x00, 0x00, 0xFF, 0x00, 0xF7,
242
+    0x14, 0x14, 0x14, 0x14, 0x14,
243
+    0x14, 0x14, 0xF7, 0x00, 0xF7,
244
+    0x14, 0x14, 0x14, 0x17, 0x14,
245
+    0x10, 0x10, 0x1F, 0x10, 0x1F,
246
+    0x14, 0x14, 0x14, 0xF4, 0x14,
247
+    0x10, 0x10, 0xF0, 0x10, 0xF0,
248
+    0x00, 0x00, 0x1F, 0x10, 0x1F,
249
+    0x00, 0x00, 0x00, 0x1F, 0x14,
250
+    0x00, 0x00, 0x00, 0xFC, 0x14,
251
+    0x00, 0x00, 0xF0, 0x10, 0xF0,
252
+    0x10, 0x10, 0xFF, 0x10, 0xFF,
253
+    0x14, 0x14, 0x14, 0xFF, 0x14,
254
+    0x10, 0x10, 0x10, 0x1F, 0x00,
255
+    0x00, 0x00, 0x00, 0xF0, 0x10,
256
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
257
+    0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
258
+    0xFF, 0xFF, 0xFF, 0x00, 0x00,
259
+    0x00, 0x00, 0x00, 0xFF, 0xFF,
260
+    0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
261
+    0x38, 0x44, 0x44, 0x38, 0x44,
262
+    0x7C, 0x2A, 0x2A, 0x3E, 0x14,
263
+    0x7E, 0x02, 0x02, 0x06, 0x06,
264
+    0x02, 0x7E, 0x02, 0x7E, 0x02,
265
+    0x63, 0x55, 0x49, 0x41, 0x63,
266
+    0x38, 0x44, 0x44, 0x3C, 0x04,
267
+    0x40, 0x7E, 0x20, 0x1E, 0x20,
268
+    0x06, 0x02, 0x7E, 0x02, 0x02,
269
+    0x99, 0xA5, 0xE7, 0xA5, 0x99,
270
+    0x1C, 0x2A, 0x49, 0x2A, 0x1C,
271
+    0x4C, 0x72, 0x01, 0x72, 0x4C,
272
+    0x30, 0x4A, 0x4D, 0x4D, 0x30,
273
+    0x30, 0x48, 0x78, 0x48, 0x30,
274
+    0xBC, 0x62, 0x5A, 0x46, 0x3D,
275
+    0x3E, 0x49, 0x49, 0x49, 0x00,
276
+    0x7E, 0x01, 0x01, 0x01, 0x7E,
277
+    0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
278
+    0x44, 0x44, 0x5F, 0x44, 0x44,
279
+    0x40, 0x51, 0x4A, 0x44, 0x40,
280
+    0x40, 0x44, 0x4A, 0x51, 0x40,
281
+    0x00, 0x00, 0xFF, 0x01, 0x03,
282
+    0xE0, 0x80, 0xFF, 0x00, 0x00,
283
+    0x08, 0x08, 0x6B, 0x6B, 0x08,
284
+    0x36, 0x12, 0x36, 0x24, 0x36,
285
+    0x06, 0x0F, 0x09, 0x0F, 0x06,
286
+    0x00, 0x00, 0x18, 0x18, 0x00,
287
+    0x00, 0x00, 0x10, 0x10, 0x00,
288
+    0x30, 0x40, 0xFF, 0x01, 0x01,
289
+    0x00, 0x1F, 0x01, 0x01, 0x1E,
290
+    0x00, 0x19, 0x1D, 0x17, 0x12,
291
+    0x00, 0x3C, 0x3C, 0x3C, 0x3C,
292
+    0x00, 0x00, 0x00, 0x00, 0x00
293
+};
294
+
295
+/**
296
+ * @brief GFX helper class
297
+ *
298
+ * This file is used by the screen.
299
+ */
300
+class GFX {
301
+    public:
302
+        /**
303
+         * Instantiates a GFX object
304
+         *
305
+         * @param width Screen width
306
+         * @param height Screen height
307
+         */
308
+        GFX (int width, int height);
309
+
310
+        /**
311
+         * GFX object destructor
312
+         */
313
+        ~GFX ();
314
+
315
+        /**
316
+         * Sends a pixel color (RGB) to the chip. Must be implemented by the
317
+         * inherited class.
318
+         *
319
+         * @param x Axis on the horizontal scale
320
+         * @param y Axis on the vertical scale
321
+         * @param color RGB value
322
+         */
323
+        virtual void drawPixel (int16_t x, int16_t y, uint16_t color) = 0;
324
+
325
+        /**
326
+         * Copies the buffer to the chip via the SPI.
327
+         */
328
+        virtual void refresh () = 0;
329
+
330
+        /**
331
+         *
332
+         *
333
+         * @param x Axis on the horizontal scale
334
+         * @param y Axis on the vertical scale
335
+         * @param data Character to write
336
+         * @param color Character color
337
+         * @param bg Character background color
338
+         * @param size Size of the font
339
+         */
340
+        void drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size);
341
+
342
+        /**
343
+         * Prints a message on the screen
344
+         *
345
+         * @param msg Message to print
346
+         */
347
+        void print (std::string msg);
348
+
349
+        /**
350
+         * Fills the screen with a selected color
351
+         *
352
+         * @param color Selected color
353
+         */
354
+        void fillScreen (uint16_t color);
355
+
356
+        /**
357
+         * Fills a rectangle with a selected color
358
+         *
359
+         * @param x Axis on the horizontal scale (top-left corner)
360
+         * @param y Axis on the vertical scale (top-left corner)
361
+         * @param w Distanse from x
362
+         * @param h Distanse from y
363
+         * @param color Selected color
364
+         */
365
+        void fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
366
+
367
+        /**
368
+         * Draws a line on the vertical scale
369
+         *
370
+         * @param x Axis on the horizontal scale
371
+         * @param y Axis on the vertical scale
372
+         * @param h Distanse from y
373
+         * @param color Selected color
374
+         */
375
+        void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
376
+
377
+        /**
378
+         * Draws a line from coordinate C0 to coordinate C1
379
+         *
380
+         * @param x0 First coordinate
381
+         * @param y0 First coordinate
382
+         * @param x1 Second coordinate
383
+         * @param y1 Second coordinate
384
+         * @param color selected color
385
+         */
386
+        void drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
387
+
388
+        /**
389
+         * Draws a triangle
390
+         *
391
+         * @param x0 First coordinate
392
+         * @param y0 First coordinate
393
+         * @param x1 Second coordinate
394
+         * @param y1 Second coordinate
395
+         * @param x2 Third coordinate
396
+         * @param y2 Third coordinate
397
+         * @param color Selected color
398
+         */
399
+        void drawTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
400
+
401
+        /**
402
+         * Draws a circle
403
+         *
404
+         * @param x Center of the circle on the horizontal scale
405
+         * @param y Center of the circle on the vertical scale
406
+         * @param r Radius of the circle
407
+         * @param color Color of the circle
408
+         */
409
+        void drawCircle (int16_t x, int16_t y, int16_t r, uint16_t color);
410
+
411
+        /**
412
+         * Sets the cursor for a text message
413
+         *
414
+         * @param x Axis on the horizontal scale
415
+         * @param y Axis on the vertical scale
416
+         */
417
+        void setCursor (int16_t x, int16_t y);
418
+
419
+        /**
420
+         * Sets a text color for a message
421
+         *
422
+         * @param textColor Font color
423
+         * @param textBGColor Background color
424
+         */
425
+        void setTextColor (uint16_t textColor, uint16_t textBGColor);
426
+
427
+        /**
428
+         * Sets the size of the font
429
+         *
430
+         * @param size Font size
431
+         */
432
+        void setTextSize (uint8_t size);
433
+
434
+        /**
435
+         * Wraps a printed message
436
+         *
437
+         * @param wrap True (0x1) or false (0x0)
438
+         */
439
+        void setTextWrap (uint8_t wrap);
440
+
441
+    protected:
442
+        int m_width; /**< Screen width */
443
+        int m_height; /**< Screen height */
444
+        int m_textSize; /**< Printed text size */
445
+        int m_textColor; /**< Printed text color */
446
+        int m_textBGColor; /**< Printed text background color */
447
+        int m_cursorX; /**< Cursor X coordinate */
448
+        int m_cursorY; /**< Cursor Y coordinate */
449
+        int m_wrap; /**< Wrapper flag (true or false) */
450
+
451
+        const unsigned char * m_font;
452
+    };
453
+}

+ 28
- 0
src/ssd1351/javaupm_ssd1351.i Просмотреть файл

@@ -0,0 +1,28 @@
1
+%module javaupm_ssd1351
2
+%include "../upm.i"
3
+%include "typemaps.i"
4
+%include "stdint.i"
5
+
6
+%ignore m_map;
7
+%ignore font;
8
+
9
+%include "gfx.h"
10
+%{
11
+    #include "gfx.h"
12
+%}
13
+
14
+%include "ssd1351.h"
15
+%{
16
+    #include "ssd1351.h"
17
+%}
18
+
19
+%pragma(java) jniclasscode=%{
20
+    static {
21
+        try {
22
+            System.loadLibrary("javaupm_ssd1351");
23
+        } catch (UnsatisfiedLinkError e) {
24
+            System.err.println("Native code library failed to load. \n" + e);
25
+            System.exit(1);
26
+        }
27
+    }
28
+%}

+ 12
- 0
src/ssd1351/jsupm_ssd1351.i Просмотреть файл

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

+ 17
- 0
src/ssd1351/pyupm_ssd1351.i Просмотреть файл

@@ -0,0 +1,17 @@
1
+// Include doxygen-generated documentation
2
+%include "pyupm_doxy2swig.i"
3
+%module pyupm_ssd1351
4
+%include "../upm.i"
5
+
6
+%feature("autodoc", "3");
7
+%rename("printString") print(std::string msg);
8
+
9
+%include "gfx.h"
10
+%{
11
+    #include "gfx.h"
12
+%}
13
+
14
+%include "ssd1351.h"
15
+%{
16
+    #include "ssd1351.h"
17
+%}

+ 225
- 0
src/ssd1351/ssd1351.cxx Просмотреть файл

@@ -0,0 +1,225 @@
1
+/*
2
+ * Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
3
+ * Copyright (c) 2016 Intel Corporation.
4
+ *
5
+ * Based on Adafruit SSD1351 library.
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 <iostream>
28
+#include <string>
29
+#include <stdexcept>
30
+#include <unistd.h>
31
+#include <stdlib.h>
32
+
33
+#include "ssd1351.h"
34
+
35
+using namespace upm;
36
+using namespace std;
37
+
38
+SSD1351::SSD1351 (uint8_t oc, uint8_t dc, uint8_t rst) :
39
+        GFX(SSD1351WIDTH, SSD1351HEIGHT),
40
+        m_spi(0), m_oc(oc), m_dc(dc), m_rst(rst) {
41
+
42
+    m_name = "SSD1351";
43
+    m_usemap = true;
44
+
45
+    // Setup SPI bus
46
+    m_spi.frequency(8 * 1000000);
47
+    m_spi.mode(mraa::SPI_MODE3);
48
+    m_spi.writeByte(0x00); // Need to bring clk high before init
49
+
50
+    // Init pins
51
+    if (m_oc.dir(mraa::DIR_OUT) != mraa::SUCCESS) {
52
+        throw std::runtime_error(string(__FUNCTION__) +
53
+                               ": Could not initialize CS pin");
54
+        return;
55
+    }
56
+    m_oc.useMmap(true);
57
+    if (m_dc.dir(mraa::DIR_OUT) != mraa::SUCCESS) {
58
+        throw std::runtime_error(string(__FUNCTION__) +
59
+                               ": Could not initialize data/cmd pin");
60
+        return;
61
+    }
62
+    m_dc.useMmap(true);
63
+    if (m_rst.dir(mraa::DIR_OUT) != mraa::SUCCESS) {
64
+        throw std::runtime_error(string(__FUNCTION__) +
65
+                               ": Could not initialize reset pin");
66
+        return;
67
+    }
68
+
69
+    // Toggle reset pin
70
+    ocLow();
71
+    m_rst.write(1);
72
+    usleep(500000);
73
+    m_rst.write(0);
74
+    usleep(500000);
75
+    m_rst.write(1);
76
+    usleep(500000);
77
+
78
+    // Configure and init display
79
+    writeCommand(SSD1351_CMD_COMMANDLOCK);
80
+    writeData(0x12);
81
+
82
+    writeCommand(SSD1351_CMD_COMMANDLOCK);
83
+    writeData(0xB1);
84
+
85
+    writeCommand(SSD1351_CMD_DISPLAYOFF);
86
+
87
+    writeCommand(SSD1351_CMD_CLOCKDIV);
88
+    writeCommand(0xF1);
89
+
90
+    writeCommand(SSD1351_CMD_MUXRATIO);
91
+    writeData(127);
92
+
93
+    writeCommand(SSD1351_CMD_SETREMAP);
94
+    writeData(0x74);
95
+
96
+    writeCommand(SSD1351_CMD_SETCOLUMN);
97
+    writeData(0x00);
98
+    writeData(0x7F);
99
+
100
+    writeCommand(SSD1351_CMD_SETROW);
101
+    writeData(0x00);
102
+    writeData(0x7F);
103
+
104
+    writeCommand(SSD1351_CMD_STARTLINE);
105
+    if (SSD1351HEIGHT == 96) {
106
+        writeData(96);
107
+    } else {
108
+        writeData(0);
109
+    }
110
+
111
+    writeCommand(SSD1351_CMD_DISPLAYOFFSET);
112
+    writeData(0x0);
113
+
114
+    writeCommand(SSD1351_CMD_SETGPIO);
115
+    writeData(0x00);
116
+
117
+    writeCommand(SSD1351_CMD_FUNCTIONSELECT);
118
+    writeData(0x01);
119
+
120
+    writeCommand(SSD1351_CMD_PRECHARGE);
121
+    writeCommand(0x32);
122
+
123
+    writeCommand(SSD1351_CMD_VCOMH);
124
+    writeCommand(0x05);
125
+
126
+    writeCommand(SSD1351_CMD_NORMALDISPLAY);
127
+
128
+    writeCommand(SSD1351_CMD_CONTRASTABC);
129
+    writeData(0xC8);
130
+    writeData(0x80);
131
+    writeData(0xC8);
132
+
133
+    writeCommand(SSD1351_CMD_CONTRASTMASTER);
134
+    writeData(0x0F);
135
+
136
+    writeCommand(SSD1351_CMD_SETVSL );
137
+    writeData(0xA0);
138
+    writeData(0xB5);
139
+    writeData(0x55);
140
+
141
+    writeCommand(SSD1351_CMD_PRECHARGE2);
142
+    writeData(0x01);
143
+
144
+    writeCommand(SSD1351_CMD_DISPLAYON);
145
+}
146
+
147
+SSD1351::~SSD1351() {
148
+}
149
+
150
+void
151
+SSD1351::writeCommand (uint8_t value) {
152
+    dcLow();
153
+    m_spi.writeByte(value);
154
+}
155
+
156
+void
157
+SSD1351::writeData (uint8_t value) {
158
+    dcHigh ();
159
+    m_spi.writeByte(value);
160
+}
161
+
162
+void
163
+SSD1351::drawPixel(int16_t x, int16_t y, uint16_t color) {
164
+      if ((x < 0) || (y < 0) || (x >= SSD1351WIDTH) || (y >= SSD1351HEIGHT))
165
+          return;
166
+
167
+      if(m_usemap) {
168
+          int index = (y * SSD1351WIDTH + x) * 2;
169
+          m_map[index] = color >> 8;
170
+          m_map[index + 1] = color;
171
+      } else {
172
+          writeCommand(SSD1351_CMD_SETCOLUMN);
173
+          writeData(x);
174
+          writeData(SSD1351WIDTH-1);
175
+
176
+          writeCommand(SSD1351_CMD_SETROW);
177
+          writeData(y);
178
+          writeData(SSD1351HEIGHT-1);
179
+
180
+          writeCommand(SSD1351_CMD_WRITERAM);
181
+          writeData(color >> 8);
182
+          writeData(color);
183
+      }
184
+}
185
+void
186
+SSD1351::refresh () {
187
+    writeCommand(SSD1351_CMD_WRITERAM);
188
+    int blockSize = SSD1351HEIGHT * SSD1351WIDTH * 2 / BLOCKS;
189
+    dcHigh();
190
+    for (int block = 0; block < BLOCKS; block++) {
191
+        m_spi.write(&m_map[block * blockSize], blockSize);
192
+    }
193
+}
194
+void
195
+SSD1351::ocLow() {
196
+    if (m_oc.write(LOW) != mraa::SUCCESS) {
197
+        throw std::runtime_error(string(__FUNCTION__) +
198
+                               ": Failed to write CS pin");
199
+    }
200
+}
201
+void
202
+SSD1351::ocHigh() {
203
+    if (m_oc.write(HIGH) != mraa::SUCCESS) {
204
+        throw std::runtime_error(string(__FUNCTION__) +
205
+                               ": Failed to write CS pin");
206
+    }
207
+}
208
+void
209
+SSD1351::dcLow() {
210
+    if (m_dc.write(LOW) != mraa::SUCCESS) {
211
+        throw std::runtime_error(string(__FUNCTION__) +
212
+                               ": Failed to write data/cmd pin");
213
+    }
214
+}
215
+void
216
+SSD1351::dcHigh() {
217
+    if (m_dc.write(HIGH) != mraa::SUCCESS) {
218
+        throw std::runtime_error(string(__FUNCTION__) +
219
+                               ": Failed to write data/cmd pin");
220
+    }
221
+}
222
+void
223
+upm::SSD1351::useMemoryMap(bool var) {
224
+    m_usemap = var;
225
+}

+ 188
- 0
src/ssd1351/ssd1351.h Просмотреть файл

@@ -0,0 +1,188 @@
1
+/*
2
+ * Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
3
+ * Copyright (c) 2016 Intel Corporation.
4
+ *
5
+ * Based on Adafruit SSD1351 library.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining
8
+ * a copy of this software and associated documentation files (the
9
+ * "Software"), to deal in the Software without restriction, including
10
+ * without limitation the rights to use, copy, modify, merge, publish,
11
+ * distribute, sublicense, and/or sell copies of the Software, and to
12
+ * permit persons to whom the Software is furnished to do so, subject to
13
+ * the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ */
26
+#pragma once
27
+
28
+#include <string>
29
+
30
+#include <mraa/common.hpp>
31
+#include <mraa/gpio.hpp>
32
+#include <mraa/spi.hpp>
33
+#include "gfx.h"
34
+
35
+// Display Size
36
+#define SSD1351WIDTH 128
37
+#define SSD1351HEIGHT 128  // Set this to 96 for 1.27"
38
+
39
+// SSD1351 Commands
40
+#define SSD1351_CMD_SETCOLUMN       0x15
41
+#define SSD1351_CMD_SETROW          0x75
42
+#define SSD1351_CMD_WRITERAM        0x5C
43
+#define SSD1351_CMD_READRAM         0x5D
44
+#define SSD1351_CMD_SETREMAP        0xA0
45
+#define SSD1351_CMD_STARTLINE       0xA1
46
+#define SSD1351_CMD_DISPLAYOFFSET   0xA2
47
+#define SSD1351_CMD_DISPLAYALLOFF   0xA4
48
+#define SSD1351_CMD_DISPLAYALLON    0xA5
49
+#define SSD1351_CMD_NORMALDISPLAY   0xA6
50
+#define SSD1351_CMD_INVERTDISPLAY   0xA7
51
+#define SSD1351_CMD_FUNCTIONSELECT  0xAB
52
+#define SSD1351_CMD_DISPLAYOFF      0xAE
53
+#define SSD1351_CMD_DISPLAYON       0xAF
54
+#define SSD1351_CMD_PRECHARGE       0xB1
55
+#define SSD1351_CMD_DISPLAYENHANCE  0xB2
56
+#define SSD1351_CMD_CLOCKDIV        0xB3
57
+#define SSD1351_CMD_SETVSL          0xB4
58
+#define SSD1351_CMD_SETGPIO         0xB5
59
+#define SSD1351_CMD_PRECHARGE2      0xB6
60
+#define SSD1351_CMD_SETGRAY         0xB8
61
+#define SSD1351_CMD_USELUT          0xB9
62
+#define SSD1351_CMD_PRECHARGELEVEL  0xBB
63
+#define SSD1351_CMD_VCOMH           0xBE
64
+#define SSD1351_CMD_CONTRASTABC     0xC1
65
+#define SSD1351_CMD_CONTRASTMASTER  0xC7
66
+#define SSD1351_CMD_MUXRATIO        0xCA
67
+#define SSD1351_CMD_COMMANDLOCK     0xFD
68
+#define SSD1351_CMD_HORIZSCROLL     0x96
69
+#define SSD1351_CMD_STOPSCROLL      0x9E
70
+#define SSD1351_CMD_STARTSCROLL     0x9F
71
+
72
+#define HIGH                1
73
+#define LOW                 0
74
+
75
+// Number of blocks for SPI transfer of buffer
76
+#define BLOCKS              8
77
+
78
+namespace upm {
79
+/**
80
+ * @brief SSD1351 OLED library
81
+ * @defgroup ssd1351 libupm-ssd1351
82
+ * @ingroup adafruit spi display
83
+ */
84
+/**
85
+ * @library ssd1351
86
+ * @sensor ssd1351
87
+ * @comname SSD1351 OLED
88
+ * @type display
89
+ * @man adafruit
90
+ * @web http://www.adafruit.com/products/1431
91
+ * @con spi
92
+ *
93
+ * @brief API for SSD1351 OLED displays
94
+ *
95
+ * This module defines the interface for the SSD1351 display library
96
+ *
97
+ * @image html ssd1351.jpg
98
+ * @snippet ssd1351.cxx Interesting
99
+ */
100
+class SSD1351 : public GFX{
101
+    public:
102
+        /**
103
+         * Instantiates an SSD1351 object
104
+         *
105
+         * @param oc LCD chip select pin
106
+         * @param dc Data/command pin
107
+         * @param rst Reset pin
108
+         */
109
+        SSD1351 (uint8_t oc, uint8_t dc, uint8_t rst);
110
+
111
+        /**
112
+         * SSD1351 object destructor
113
+         */
114
+        ~SSD1351();
115
+
116
+        /**
117
+         * Returns the name of the component
118
+         */
119
+        std::string name()
120
+        {
121
+            return m_name;
122
+        }
123
+
124
+        /**
125
+         * Sends a command to an SPI bus
126
+         *
127
+         * @param value Command
128
+         */
129
+        void writeCommand (uint8_t value);
130
+
131
+        /**
132
+         * Sends data to an SPI bus
133
+         *
134
+         * @param value Data
135
+         */
136
+        void writeData (uint8_t value);
137
+        /**
138
+         * Sends a pixel color (RGB) to the display buffer or chip
139
+         *
140
+         * @param x Axis on the horizontal scale
141
+         * @param y Axis on the vertical scale
142
+         * @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15])
143
+         */
144
+        void drawPixel (int16_t x, int16_t y, uint16_t color);
145
+
146
+        /**
147
+         * Copies the buffer to the chip via the SPI bus
148
+         */
149
+        void refresh ();
150
+
151
+        /**
152
+         * Set OLED chip select LOW
153
+         */
154
+        void ocLow ();
155
+
156
+        /**
157
+         * Set OLED chip select HIGH
158
+         */
159
+        void ocHigh ();
160
+
161
+        /**
162
+         * Data select LOW
163
+         */
164
+        void dcLow ();
165
+
166
+        /**
167
+         * Data select HIGH
168
+         */
169
+        void dcHigh ();
170
+
171
+        /**
172
+         * Use memory mapped (buffered) writes to the display
173
+         *
174
+         * @param var true for yes (default), false for no
175
+         */
176
+        void useMemoryMap (bool var);
177
+    private:
178
+        mraa::Spi       m_spi;
179
+        uint8_t         m_map[SSD1351HEIGHT * SSD1351WIDTH * 2]; /**< Screen buffer */
180
+        bool            m_usemap;
181
+
182
+        mraa::Gpio      m_oc;
183
+        mraa::Gpio      m_dc;
184
+        mraa::Gpio      m_rst;
185
+
186
+        std::string     m_name;
187
+};
188
+}