Browse Source

ssd1308: Added new oled display

Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
Kiveisha Yevgeniy 10 years ago
parent
commit
039b138194
7 changed files with 479 additions and 1 deletions
  1. 2
    0
      examples/CMakeLists.txt
  2. 116
    0
      examples/oled-1308.cxx
  3. 1
    1
      src/lcd/CMakeLists.txt
  4. 7
    0
      src/lcd/jsupm_ssd1308.i
  5. 8
    0
      src/lcd/pyupm_ssd1308.i
  6. 172
    0
      src/lcd/ssd1308.cxx
  7. 173
    0
      src/lcd/ssd1308.h

+ 2
- 0
examples/CMakeLists.txt View File

@@ -10,6 +10,7 @@ add_executable (nrf_transmitter nrf_transmitter.cxx)
10 10
 add_executable (nrf_receiver nrf_receiver.cxx)
11 11
 add_executable (es08a es08a.cxx)
12 12
 add_executable (son-hcsr04 hcsr04.cxx)
13
+add_executable (oled-1308 oled-1308.cxx)
13 14
 
14 15
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
15 16
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@@ -33,3 +34,4 @@ target_link_libraries (nrf_transmitter nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
33 34
 target_link_libraries (nrf_receiver nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
34 35
 target_link_libraries (es08a servo ${CMAKE_THREAD_LIBS_INIT})
35 36
 target_link_libraries (son-hcsr04 hcsr04 ${CMAKE_THREAD_LIBS_INIT})
37
+target_link_libraries (oled-1308 i2clcd ${CMAKE_THREAD_LIBS_INIT})

+ 116
- 0
examples/oled-1308.cxx View File

@@ -0,0 +1,116 @@
1
+/*
2
+ * Author: Yevgeniy Kiveish <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
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 "ssd1308.h"
26
+
27
+#define DEVICE_ADDRESS    0x3C
28
+#define BUS_NUMBER        0x0
29
+
30
+static uint8_t SeeedLogo[] ={
31
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
32
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39
+0x60, 0xf0, 0xc0, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
40
+0xff, 0xfc, 0x00, 0x00, 0x00, 0x80, 0xf0, 0x20, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0x60, 0xe0, 0xc0,
41
+0xc0, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x60, 0xe0, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x80, 0xc0,
42
+0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x60, 0xe0, 0xc0, 0xc0,
43
+0x80, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00,
44
+0x00, 0xc0, 0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00, 0xc0, 0xf0, 0xf0, 0xf0, 0xc0, 0x00, 0xc0,
45
+0xc0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0,
46
+0xf8, 0xf8, 0x00, 0xd8, 0xd8, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00,
47
+0x00, 0x03, 0x0f, 0x1e, 0x3c, 0x70, 0xe3, 0xcf, 0x9f, 0x30, 0x00, 0x00, 0x00, 0x00, 0x70, 0xbf,
48
+0xcf, 0xe3, 0x70, 0x78, 0x3e, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x33, 0x77, 0x66, 0x66, 0x66, 0x6c,
49
+0x7d, 0x18, 0x00, 0x1f, 0x3f, 0x76, 0x66, 0x66, 0x66, 0x76, 0x37, 0x07, 0x00, 0x0f, 0x3f, 0x7f,
50
+0x66, 0x66, 0x66, 0x66, 0x77, 0x27, 0x07, 0x00, 0x1f, 0x3f, 0x76, 0x66, 0x66, 0x66, 0x76, 0x37,
51
+0x07, 0x00, 0x0f, 0x3f, 0x71, 0x60, 0x60, 0x60, 0x60, 0x31, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00,
52
+0x11, 0x37, 0x67, 0x66, 0x66, 0x6c, 0x7d, 0x38, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00, 0x00, 0x1f,
53
+0x3f, 0x70, 0x60, 0x60, 0x70, 0x7f, 0x7f, 0x00, 0x0f, 0x3f, 0x71, 0x60, 0x60, 0x60, 0x60, 0x31,
54
+0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x06, 0x1f, 0x3b, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3f, 0x1f,
55
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
56
+0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0xb0, 0x00, 0xc0, 0x20,
64
+0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00,
65
+0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0xf8, 0x08,
66
+0x08, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xf8, 0x00, 0xc0, 0xa0, 0xa0, 0xa0, 0xc0, 0x00, 0x20, 0xa0,
67
+0xa0, 0xa0, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0x08, 0x00, 0x20, 0x40, 0x80, 0x40,
69
+0x20, 0x00, 0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0xc0, 0xa0, 0xa0, 0xa0, 0xc0, 0x00, 0xe0, 0x00,
70
+0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x02, 0x01, 0x00, 0x01, 0x02,
72
+0x02, 0x02, 0x01, 0x00, 0x01, 0x02, 0x02, 0x02, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00,
73
+0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x03, 0x02,
74
+0x02, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x00, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x01, 0x02,
75
+0x02, 0x02, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x08, 0x06, 0x00, 0x00, 0x00,
76
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x82, 0x02, 0x00, 0x02, 0x01, 0x01, 0x01,
77
+0x02, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x03, 0x00,
78
+0x00, 0x00, 0x03, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81
+0x00, 0x00, 0x00, 0x82, 0x8c, 0x60, 0x1c, 0x02, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x1e,
82
+0x20, 0x20, 0x00, 0x3e, 0x00, 0x00, 0x3e, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83
+0x00, 0x00, 0x3e, 0x04, 0x02, 0x02, 0x00, 0x1c, 0x2a, 0x2a, 0x2a, 0x0c, 0x00, 0x12, 0x2a, 0x2a,
84
+0x2a, 0x1c, 0x20, 0x1c, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3f, 0x00, 0x02, 0x02, 0x3c, 0x00, 0x00,
85
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
95
+};
96
+
97
+
98
+int
99
+main(int argc, char **argv)
100
+{
101
+    upm::SSD1308 *lcd = new upm::SSD1308 (BUS_NUMBER, DEVICE_ADDRESS);
102
+
103
+    /*
104
+     * Simple print hello world
105
+     */
106
+    // lcd->setCursor (0, 0);
107
+    // lcd->write ("Hello World");
108
+
109
+   /*
110
+     * Simple print hello world
111
+     */
112
+    lcd->clear ();
113
+    lcd->draw (SeeedLogo, 1024);
114
+
115
+    lcd->close ();
116
+}

+ 1
- 1
src/lcd/CMakeLists.txt View File

@@ -1,4 +1,4 @@
1 1
 set (libname "i2clcd")
2
-add_library (i2clcd SHARED iiclcd.cxx lcm1602.cxx jhd1313m1.cxx)
2
+add_library (i2clcd SHARED iiclcd.cxx lcm1602.cxx jhd1313m1.cxx ssd1308.cxx)
3 3
 include_directories (${MAA_INCLUDE_DIR})
4 4
 target_link_libraries (i2clcd ${MAA_LIBRARIES})

+ 7
- 0
src/lcd/jsupm_ssd1308.i View File

@@ -0,0 +1,7 @@
1
+%module jsupm_ssd1308
2
+
3
+%{
4
+    #include "ssd1308.h"
5
+%}
6
+
7
+%include "ssd1308.h"

+ 8
- 0
src/lcd/pyupm_ssd1308.i View File

@@ -0,0 +1,8 @@
1
+%module pyupm_ssd1308
2
+
3
+%feature("autodoc", "3");
4
+
5
+%include "ssd1308.h"
6
+%{
7
+    #include "ssd1308.h"
8
+%}

+ 172
- 0
src/lcd/ssd1308.cxx View File

@@ -0,0 +1,172 @@
1
+/*
2
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
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 <string>
26
+#include <unistd.h>
27
+
28
+#include "ssd1308.h"
29
+
30
+using namespace upm;
31
+
32
+SSD1308::SSD1308 (int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
33
+    i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF);  // display off
34
+    printf ("NO_GDB :: DISPLAY_CMD_OFF \n");
35
+    usleep (4500);
36
+    i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON);   // display on
37
+    usleep (4500);
38
+    setNormalDisplay ();                         // set to normal display '1' is ON
39
+
40
+    clear ();
41
+    setAddressingMode (PAGE);
42
+}
43
+
44
+SSD1308::~SSD1308 () {
45
+
46
+}
47
+
48
+maa_result_t
49
+SSD1308::draw (uint8_t *data, int bytes) {
50
+    maa_result_t error = MAA_SUCCESS;
51
+
52
+    setAddressingMode (HORIZONTAL);
53
+    for (int idx = 0; idx < bytes; idx++) {
54
+        i2cData (m_i2c_lcd_control, data[idx]);
55
+    }
56
+
57
+    return error;
58
+}
59
+
60
+/*
61
+ * **************
62
+ *  virtual area
63
+ * **************
64
+ */
65
+maa_result_t
66
+SSD1308::write (std::string msg) {
67
+    maa_result_t error = MAA_SUCCESS;
68
+    uint8_t data[2] = {0x40, 0};
69
+
70
+    setAddressingMode (PAGE);
71
+    for (std::string::size_type i = 0; i < msg.size(); ++i) {
72
+        writeChar (m_i2c_lcd_control, msg[i]);
73
+    }
74
+
75
+    return error;
76
+}
77
+
78
+maa_result_t
79
+SSD1308::setCursor (int row, int column) {
80
+    maa_result_t error = MAA_SUCCESS;
81
+
82
+    error = i2Cmd (m_i2c_lcd_control, BASE_PAGE_START_ADDR + row);                           // set page address
83
+    error = i2Cmd (m_i2c_lcd_control, BASE_LOW_COLUMN_ADDR + (8 * column & 0x0F));           // set column lower address
84
+    error = i2Cmd (m_i2c_lcd_control, BASE_HIGH_COLUMN_ADDR + ((8 * column >> 4) & 0x0F));   // set column higher address
85
+
86
+    return error;
87
+}
88
+
89
+maa_result_t
90
+SSD1308::clear () {
91
+    maa_result_t error = MAA_SUCCESS;
92
+    uint8_t columnIdx, rowIdx;
93
+
94
+    i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF);  // display off
95
+    for(rowIdx = 0; rowIdx < 8; rowIdx++) {
96
+        setCursor (rowIdx, 0);
97
+
98
+        // clear all columns
99
+        for(columnIdx = 0; columnIdx < 16; columnIdx++) {
100
+            writeChar (m_i2c_lcd_control, ' ');
101
+        }
102
+    }
103
+    i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON);   // display on
104
+    home ();
105
+
106
+    return MAA_SUCCESS;
107
+}
108
+
109
+maa_result_t
110
+SSD1308::home () {
111
+    return setCursor (0, 0);
112
+}
113
+
114
+/*
115
+ * **************
116
+ *  private area
117
+ * **************
118
+ */
119
+maa_result_t
120
+SSD1308::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
121
+    maa_result_t error = MAA_SUCCESS;
122
+
123
+    uint8_t data[2] = { addr, value };
124
+    error = maa_i2c_address (ctx, deviceAdress);
125
+    error = maa_i2c_write (ctx, data, 2);
126
+
127
+    return error;
128
+}
129
+
130
+maa_result_t
131
+SSD1308::i2Cmd (maa_i2c_context ctx, uint8_t value) {
132
+    maa_result_t error = MAA_SUCCESS;
133
+
134
+    uint8_t data[2] = { 0x80, value };
135
+    error = maa_i2c_address (ctx, m_lcd_control_address);
136
+    error = maa_i2c_write (ctx, data, 2);
137
+
138
+    return error;
139
+}
140
+
141
+maa_result_t
142
+SSD1308::i2cData (maa_i2c_context ctx, uint8_t value) {
143
+    maa_result_t error = MAA_SUCCESS;
144
+
145
+    uint8_t data[2] = { 0x40, value };
146
+    error = maa_i2c_address (ctx, m_lcd_control_address);
147
+    error = maa_i2c_write (ctx, data, 2);
148
+
149
+    return error;
150
+}
151
+
152
+maa_result_t
153
+SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) {
154
+    if (value < 0x20 || value > 0x7F) {
155
+        value = 0x20; // space
156
+    }
157
+
158
+    for (uint8_t idx = 0; idx < 8; idx++) {
159
+        i2cData (m_i2c_lcd_control, BasicFont[value - 32][idx]);
160
+    }
161
+}
162
+
163
+maa_result_t
164
+SSD1308::setNormalDisplay () {
165
+    return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL);    // set to normal display '1' is ON
166
+}
167
+
168
+maa_result_t
169
+SSD1308::setAddressingMode (displayAddressingMode mode) {
170
+    i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_MEM_ADDR_MODE); //set addressing mode
171
+    i2Cmd (m_i2c_lcd_control, mode); //set page addressing mode
172
+}

+ 173
- 0
src/lcd/ssd1308.h View File

@@ -0,0 +1,173 @@
1
+/*
2
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
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
+#pragma once
26
+
27
+#include <string>
28
+#include "iiclcd.h"
29
+
30
+namespace upm {
31
+
32
+#define DISPLAY_CMD_OFF                0xAE
33
+#define DISPLAY_CMD_ON              0xAF
34
+
35
+#define BASE_LOW_COLUMN_ADDR        0x00
36
+#define BASE_HIGH_COLUMN_ADDR       0x10
37
+#define BASE_PAGE_START_ADDR        0xB0
38
+#define DISPLAY_CMD_MEM_ADDR_MODE   0x20
39
+
40
+#define DISPLAY_CMD_SET_NORMAL      0xA6
41
+
42
+const uint8_t BasicFont[][8] =
43
+{
44
+  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
45
+  {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
46
+  {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
47
+  {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
48
+  {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
49
+  {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
50
+  {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
51
+  {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
52
+  {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
53
+  {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
54
+  {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
55
+  {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
56
+  {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
57
+  {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
58
+  {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
59
+  {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
60
+  {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
61
+  {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
62
+  {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
63
+  {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
64
+  {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
65
+  {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
66
+  {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
67
+  {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
68
+  {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
69
+  {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
70
+  {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
71
+  {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
72
+  {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
73
+  {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
74
+  {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
75
+  {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
76
+  {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
77
+  {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
78
+  {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
79
+  {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
80
+  {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
81
+  {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
82
+  {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
83
+  {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
84
+  {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
85
+  {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
86
+  {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
87
+  {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
88
+  {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
89
+  {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
90
+  {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
91
+  {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
92
+  {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
93
+  {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
94
+  {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
95
+  {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
96
+  {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
97
+  {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
98
+  {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
99
+  {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
100
+  {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
101
+  {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
102
+  {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
103
+  {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
104
+  {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
105
+  {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
106
+  {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
107
+  {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
108
+  {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
109
+  {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
110
+  {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
111
+  {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
112
+  {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
113
+  {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
114
+  {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
115
+  {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
116
+  {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
117
+  {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
118
+  {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
119
+  {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
120
+  {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
121
+  {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
122
+  {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
123
+  {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
124
+  {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
125
+  {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
126
+  {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
127
+  {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
128
+  {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
129
+  {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
130
+  {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
131
+  {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
132
+  {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
133
+  {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
134
+  {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
135
+  {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
136
+  {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
137
+  {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
138
+  {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
139
+  {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
140
+};
141
+
142
+typedef enum {
143
+    HORIZONTAL    =  0,
144
+    VERTICAL      =  1,
145
+    PAGE          =  2
146
+} displayAddressingMode;
147
+
148
+class SSD1308 : public IICLcd {
149
+    public:
150
+        /** SSD1308 Constructor.
151
+         * Calls MAA initialisation functions.
152
+         * @param bus i2c bus to use
153
+         * @param address the slave address the lcd is registered on.
154
+         */
155
+        SSD1308 (int bus, int address);
156
+        ~SSD1308 ();
157
+        maa_result_t draw(uint8_t *data, int bytes);
158
+
159
+        // virtual methods
160
+        maa_result_t write (std::string msg);
161
+        maa_result_t setCursor (int row, int column);
162
+        maa_result_t clear ();
163
+        maa_result_t home ();
164
+
165
+    private:
166
+        maa_result_t i2Cmd (maa_i2c_context ctx, uint8_t value);
167
+        maa_result_t i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
168
+        maa_result_t i2cData (maa_i2c_context ctx, uint8_t value);
169
+        maa_result_t writeChar (maa_i2c_context ctx, uint8_t value);
170
+        maa_result_t setNormalDisplay ();
171
+        maa_result_t setAddressingMode (displayAddressingMode mode);
172
+    };
173
+}