Переглянути джерело

i2clcd: use the mraa C++ API instead of the C API

Rewrite the i2c module to be based around the MRAA C++ API,
since this makes resource management easier inside of the UPM
C++ classes.

i2clcd.{h,cxx}: remove the close() function. This now automatically gets
called when the object goes out of scope, inside the destructor.

examples/i2clcd: fix C++/Python/Javascript examples that explicitly called the close function.
The I2c context now gets called by the destructor of the sensor class. This
happens when the object goes out of scope or when it gets deleted, if the
object was created using the new keyword, as is the case here.

Signed-off-by: Wouter van Verre <wouter.van.verre@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Wouter van Verre 9 роки тому
джерело
коміт
31c4f470fe

+ 1
- 1
examples/c++/jhd1313m1-lcd.cxx Переглянути файл

@@ -34,6 +34,6 @@ main(int argc, char **argv)
34 34
     lcd->write("Hello World");
35 35
     lcd->setCursor(1,2);
36 36
     lcd->write("Hello World");
37
-    lcd->close();
37
+    delete lcd;
38 38
 //! [Interesting]
39 39
 }

+ 1
- 1
examples/c++/lcm1602-lcd.cxx Переглянути файл

@@ -38,5 +38,5 @@ main(int argc, char **argv)
38 38
     lcd->write("Hello World");
39 39
     lcd->setCursor(3,6);
40 40
     lcd->write("Hello World");
41
-    lcd->close();
41
+    delete lcd;
42 42
 }

+ 1
- 1
examples/c++/ssd1308-oled.cxx Переглянути файл

@@ -93,6 +93,6 @@ main(int argc, char **argv)
93 93
     lcd->clear();
94 94
     lcd->draw(intel_logo, 1024);
95 95
 
96
-    lcd->close();
96
+    delete lcd;
97 97
 //! [Interesting]
98 98
 }

+ 1
- 1
examples/c++/ssd1327-oled.cxx Переглянути файл

@@ -121,6 +121,6 @@ main(int argc, char **argv)
121 121
 		lcd->write("Hello World");
122 122
 	}
123 123
 
124
-	lcd->close();
124
+	delete lcd;
125 125
 //! [Interesting]
126 126
 }

+ 0
- 1
examples/javascript/oled_ssd1308.js Переглянути файл

@@ -93,7 +93,6 @@ for (var x = 0; x < logoArr.length; x++)
93 93
 myLcd.clear();
94 94
 myLcd.draw(intelLogo, 1024);
95 95
 
96
-myLcd.close();
97 96
 intelLogo = null;
98 97
 myLcd = null;
99 98
 LCD.cleanUp();

+ 0
- 1
examples/javascript/oled_ssd1327.js Переглянути файл

@@ -191,5 +191,4 @@ for (var i = 0; i < 12; i++)
191 191
 	myLcd.write('Hello World');
192 192
 }
193 193
 
194
-myLcd.close();
195 194
 

+ 0
- 1
examples/javascript/rgb-lcd.js Переглянути файл

@@ -39,4 +39,3 @@ myLcd.setColor(255, 0, 0);
39 39
 myLcd.write('Hello World');  
40 40
 myLcd.setCursor(1,2);
41 41
 myLcd.write('Hello World');
42
-myLcd.close();

+ 0
- 1
examples/python/oled_ssd1308.py Переглянути файл

@@ -89,7 +89,6 @@ for x in range(len(logoArr)):
89 89
 	intelLogo.__setitem__(x, logoArr[x])
90 90
 myLCD.clear()
91 91
 myLCD.draw(intelLogo, 1024)
92
-myLCD.close()
93 92
 
94 93
 del intelLogo
95 94
 del myLCD

+ 0
- 2
examples/python/oled_ssd1327.py Переглянути файл

@@ -186,6 +186,4 @@ for i in range(12):
186 186
 	myLCD.setGrayLevel(i)
187 187
 	myLCD.write('Hello World')
188 188
 
189
-myLCD.close()
190
-
191 189
 print "Exiting"

+ 0
- 1
examples/python/rgb-lcd.py Переглянути файл

@@ -36,4 +36,3 @@ myLcd.setColor(255, 0, 0)
36 36
 myLcd.write('Hello World')
37 37
 myLcd.setCursor(1,2)
38 38
 myLcd.write('Hello World')
39
-myLcd.close()

+ 4
- 12
src/lcd/i2clcd.cxx Переглянути файл

@@ -30,14 +30,12 @@
30 30
 
31 31
 using namespace upm;
32 32
 
33
-I2CLcd::I2CLcd(int bus, int lcdAddress)
33
+I2CLcd::I2CLcd(int bus, int lcdAddress) : m_i2c_lcd_control(bus)
34 34
 {
35 35
     m_lcd_control_address = lcdAddress;
36 36
     m_bus = bus;
37 37
 
38
-    m_i2c_lcd_control = mraa_i2c_init(m_bus);
39
-
40
-    mraa_result_t ret = mraa_i2c_address(m_i2c_lcd_control, m_lcd_control_address);
38
+    mraa_result_t ret = m_i2c_lcd_control.address(m_lcd_control_address);
41 39
     if (ret != MRAA_SUCCESS) {
42 40
         fprintf(stderr, "Messed up i2c bus\n");
43 41
     }
@@ -55,22 +53,16 @@ I2CLcd::createChar(uint8_t charSlot, uint8_t charData[])
55 53
 {
56 54
     mraa_result_t error = MRAA_SUCCESS;
57 55
     charSlot &= 0x07; // only have 8 positions we can set
58
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, LCD_SETCGRAMADDR | (charSlot << 3), LCD_CMD);
56
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, LCD_SETCGRAMADDR | (charSlot << 3));
59 57
     if (error == MRAA_SUCCESS) {
60 58
         for (int i = 0; i < 8; i++) {
61
-            error = mraa_i2c_write_byte_data(m_i2c_lcd_control, charData[i], LCD_DATA);
59
+            error = m_i2c_lcd_control.writeReg(LCD_DATA, charData[i]);
62 60
         }
63 61
     }
64 62
 
65 63
     return error;
66 64
 }
67 65
 
68
-mraa_result_t
69
-I2CLcd::close()
70
-{
71
-    return mraa_i2c_stop(m_i2c_lcd_control);
72
-}
73
-
74 66
 std::string
75 67
 I2CLcd::name()
76 68
 {

+ 3
- 3
src/lcd/i2clcd.h Переглянути файл

@@ -24,7 +24,7 @@
24 24
 #pragma once
25 25
 
26 26
 #include <string>
27
-#include <mraa/i2c.h>
27
+#include <mraa/i2c.hpp>
28 28
 
29 29
 namespace upm
30 30
 {
@@ -92,13 +92,13 @@ class I2CLcd
92 92
     virtual mraa_result_t home() = 0;
93 93
     virtual mraa_result_t createChar(uint8_t charSlot, uint8_t charData[]);
94 94
 
95
-    mraa_result_t close();
96 95
     std::string name();
97 96
 
98 97
   protected:
99 98
     std::string m_name;
100 99
     int m_lcd_control_address;
101 100
     int m_bus;
102
-    mraa_i2c_context m_i2c_lcd_control;
101
+
102
+    mraa::I2c m_i2c_lcd_control;
103 103
 };
104 104
 }

+ 31
- 31
src/lcd/jhd1313m1.cxx Переглянути файл

@@ -31,22 +31,26 @@
31 31
 
32 32
 using namespace upm;
33 33
 
34
-Jhd1313m1::Jhd1313m1(int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcdAddress)
34
+Jhd1313m1::Jhd1313m1(int bus, int lcdAddress, int rgbAddress)
35
+        : I2CLcd(bus, lcdAddress), m_i2c_lcd_rgb(bus)
35 36
 {
36 37
     m_rgb_address = rgbAddress;
37
-    m_i2c_lcd_rgb = mraa_i2c_init(m_bus);
38 38
 
39
-    mraa_result_t ret = mraa_i2c_address(m_i2c_lcd_rgb, m_rgb_address);
39
+    mraa_result_t ret = m_i2c_lcd_rgb.address(m_rgb_address);
40 40
     if (ret != MRAA_SUCCESS) {
41 41
         fprintf(stderr, "Messed up i2c bus\n");
42 42
     }
43 43
 
44 44
     usleep(50000);
45
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE, LCD_CMD);
46
-    UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
45
+    ret = m_i2c_lcd_control.writeReg(LCD_CMD, LCD_FUNCTIONSET | LCD_2LINE);
46
+
47
+    if (!ret) {
48
+        ret = m_i2c_lcd_control.writeReg(LCD_CMD, LCD_FUNCTIONSET | LCD_2LINE);
49
+        UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
50
+    }
47 51
 
48 52
     usleep(100);
49
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON, LCD_CMD);
53
+    ret = m_i2c_lcd_control.writeReg(LCD_CMD, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
50 54
     UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
51 55
 
52 56
     usleep(100);
@@ -54,23 +58,22 @@ Jhd1313m1::Jhd1313m1(int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcdA
54 58
     UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
55 59
 
56 60
     usleep(2000);
57
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_control,
58
-                                   LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT,
59
-                                   LCD_CMD);
61
+    ret =
62
+    m_i2c_lcd_control.writeReg(LCD_CMD, LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT);
60 63
     UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
61 64
 
62
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, 0, 0);
65
+    ret = m_i2c_lcd_rgb.writeReg(0, 0);
63 66
     UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
64
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, 0, 1);
67
+    ret = m_i2c_lcd_rgb.writeReg(1, 0);
65 68
     UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
66
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, 0xAA, 0x08);
69
+    ret = m_i2c_lcd_rgb.writeReg(0x08, 0xAA);
67 70
     UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
68 71
 
69
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, 0xFF, 0x04);
72
+    ret = m_i2c_lcd_rgb.writeReg(0x04, 0xFF);
70 73
     UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
71
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, 0xFF, 0x03);
74
+    ret = m_i2c_lcd_rgb.writeReg(0x03, 0xFF);
72 75
     UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
73
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, 0xFF, 0x02);
76
+    ret = m_i2c_lcd_rgb.writeReg(0x02, 0xFF);
74 77
     UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
75 78
 }
76 79
 
@@ -83,18 +86,18 @@ Jhd1313m1::setColor(uint8_t r, uint8_t g, uint8_t b)
83 86
 {
84 87
     mraa_result_t ret;
85 88
 
86
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, 0, 0);
89
+    ret = m_i2c_lcd_rgb.writeReg(0, 0);
87 90
     UPM_GOTO_ON_MRAA_FAIL(ret, beach);
88
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, 0, 1);
91
+    ret = m_i2c_lcd_rgb.writeReg(1, 0);
89 92
     UPM_GOTO_ON_MRAA_FAIL(ret, beach);
90
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, 0xAA, 0x08);
93
+    ret = m_i2c_lcd_rgb.writeReg(0x08, 0xAA);
91 94
     UPM_GOTO_ON_MRAA_FAIL(ret, beach);
92 95
 
93
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, r, 0x04);
96
+    ret = m_i2c_lcd_rgb.writeReg(0x04, r);
94 97
     UPM_GOTO_ON_MRAA_FAIL(ret, beach);
95
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, g, 0x03);
98
+    ret = m_i2c_lcd_rgb.writeReg(0x03, g);
96 99
     UPM_GOTO_ON_MRAA_FAIL(ret, beach);
97
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_rgb, b, 0x02);
100
+    ret = m_i2c_lcd_rgb.writeReg(0x02, b);
98 101
 
99 102
 beach:
100 103
     return ret;
@@ -104,13 +107,10 @@ mraa_result_t
104 107
 Jhd1313m1::scroll(bool direction)
105 108
 {
106 109
     if (direction) {
107
-        return mraa_i2c_write_byte_data(m_i2c_lcd_control,
108
-                                        LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT,
109
-                                        LCD_CMD);
110
+        return m_i2c_lcd_control.writeReg(LCD_CMD, LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
110 111
     } else {
111
-        return mraa_i2c_write_byte_data(m_i2c_lcd_control,
112
-                                        LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT,
113
-                                        LCD_CMD);
112
+        return m_i2c_lcd_control.writeReg(LCD_CMD,
113
+                                          LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
114 114
     }
115 115
 }
116 116
 
@@ -128,7 +128,7 @@ Jhd1313m1::write(std::string msg)
128 128
     usleep(1000);
129 129
 
130 130
     for (std::string::size_type i = 0; i < msg.size(); ++i) {
131
-        ret = mraa_i2c_write_byte_data(m_i2c_lcd_control, msg[i], LCD_DATA);
131
+        ret = m_i2c_lcd_control.writeReg(LCD_DATA, msg[i]);
132 132
         UPM_GOTO_ON_MRAA_FAIL(ret, beach);
133 133
     }
134 134
 
@@ -144,7 +144,7 @@ Jhd1313m1::setCursor(int row, int column)
144 144
     int row_addr[] = { 0x80, 0xc0, 0x14, 0x54 };
145 145
     uint8_t offset = ((column % 16) + row_addr[row]);
146 146
 
147
-    ret = mraa_i2c_write_byte_data(m_i2c_lcd_control, offset, LCD_CMD);
147
+    ret = m_i2c_lcd_control.writeReg(LCD_CMD, offset);
148 148
 
149 149
     return ret;
150 150
 }
@@ -152,11 +152,11 @@ Jhd1313m1::setCursor(int row, int column)
152 152
 mraa_result_t
153 153
 Jhd1313m1::clear()
154 154
 {
155
-    return mraa_i2c_write_byte_data(m_i2c_lcd_control, LCD_CLEARDISPLAY, LCD_CMD);
155
+    return m_i2c_lcd_control.writeReg(LCD_CMD, LCD_CLEARDISPLAY);
156 156
 }
157 157
 
158 158
 mraa_result_t
159 159
 Jhd1313m1::home()
160 160
 {
161
-    return mraa_i2c_write_byte_data(m_i2c_lcd_control, LCD_RETURNHOME, LCD_CMD);
161
+    return m_i2c_lcd_control.writeReg(LCD_CMD, LCD_RETURNHOME);
162 162
 }

+ 1
- 1
src/lcd/jhd1313m1.h Переглянути файл

@@ -112,6 +112,6 @@ class Jhd1313m1 : public I2CLcd
112 112
 
113 113
   private:
114 114
     int m_rgb_address;
115
-    mraa_i2c_context m_i2c_lcd_rgb;
115
+    mraa::I2c m_i2c_lcd_rgb;
116 116
 };
117 117
 }

+ 1
- 1
src/lcd/lcm1602.cxx Переглянути файл

@@ -132,7 +132,7 @@ mraa_result_t
132 132
 Lcm1602::expandWrite(uint8_t value)
133 133
 {
134 134
     uint8_t buffer = value | LCD_BACKLIGHT;
135
-    return mraa_i2c_write_byte(m_i2c_lcd_control, buffer);
135
+    return m_i2c_lcd_control.writeByte(buffer);
136 136
 }
137 137
 
138 138
 mraa_result_t

+ 18
- 22
src/lcd/ssd1308.cxx Переглянути файл

@@ -31,9 +31,9 @@ using namespace upm;
31 31
 
32 32
 SSD1308::SSD1308(int bus_in, int addr_in) : I2CLcd(bus_in, addr_in)
33 33
 {
34
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, DISPLAY_CMD_OFF, LCD_CMD); // display off
34
+    m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_OFF); // display off
35 35
     usleep(4500);
36
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, DISPLAY_CMD_ON, LCD_CMD); // display on
36
+    m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_ON); // display on
37 37
     usleep(4500);
38 38
     setNormalDisplay(); // set to normal display '1' is ON
39 39
 
@@ -52,7 +52,7 @@ SSD1308::draw(uint8_t* data, int bytes)
52 52
 
53 53
     setAddressingMode(HORIZONTAL);
54 54
     for (int idx = 0; idx < bytes; idx++) {
55
-        mraa_i2c_write_byte_data(m_i2c_lcd_control, data[idx], LCD_DATA);
55
+        m_i2c_lcd_control.writeReg(LCD_DATA, data[idx]);
56 56
     }
57 57
 
58 58
     return error;
@@ -82,15 +82,13 @@ SSD1308::setCursor(int row, int column)
82 82
 {
83 83
     mraa_result_t error = MRAA_SUCCESS;
84 84
 
85
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control,
86
-                                     BASE_PAGE_START_ADDR + row,
87
-                                     LCD_CMD); // set page address
88
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control,
89
-                                     BASE_LOW_COLUMN_ADDR + (8 * column & 0x0F),
90
-                                     LCD_CMD); // set column lower address
91
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control,
92
-                                     BASE_HIGH_COLUMN_ADDR + ((8 * column >> 4) & 0x0F),
93
-                                     LCD_CMD); // set column higher address
85
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, BASE_PAGE_START_ADDR + row); // set page address
86
+    error = m_i2c_lcd_control.writeReg(LCD_CMD,
87
+                                       BASE_LOW_COLUMN_ADDR + (8 * column & 0x0F)); // set column
88
+                                                                                    // lower address
89
+    error = m_i2c_lcd_control.writeReg(LCD_CMD,
90
+                                       BASE_HIGH_COLUMN_ADDR +
91
+                                       ((8 * column >> 4) & 0x0F)); // set column higher address
94 92
 
95 93
     return error;
96 94
 }
@@ -101,7 +99,7 @@ SSD1308::clear()
101 99
     mraa_result_t error = MRAA_SUCCESS;
102 100
     uint8_t columnIdx, rowIdx;
103 101
 
104
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, DISPLAY_CMD_OFF, LCD_CMD); // display off
102
+    m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_OFF); // display off
105 103
     for (rowIdx = 0; rowIdx < 8; rowIdx++) {
106 104
         setCursor(rowIdx, 0);
107 105
 
@@ -110,7 +108,7 @@ SSD1308::clear()
110 108
             writeChar(' ');
111 109
         }
112 110
     }
113
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, DISPLAY_CMD_ON, LCD_CMD); // display on
111
+    m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_ON); // display on
114 112
     home();
115 113
 
116 114
     return MRAA_SUCCESS;
@@ -135,23 +133,21 @@ SSD1308::writeChar(uint8_t value)
135 133
     }
136 134
 
137 135
     for (uint8_t idx = 0; idx < 8; idx++) {
138
-        mraa_i2c_write_byte_data(m_i2c_lcd_control, BasicFont[value - 32][idx], LCD_DATA);
136
+        m_i2c_lcd_control.writeReg(LCD_DATA, BasicFont[value - 32][idx]);
139 137
     }
140 138
 }
141 139
 
142 140
 mraa_result_t
143 141
 SSD1308::setNormalDisplay()
144 142
 {
145
-    return mraa_i2c_write_byte_data(m_i2c_lcd_control,
146
-                                    DISPLAY_CMD_SET_NORMAL_1308,
147
-                                    LCD_CMD); // set to normal display '1' is ON
143
+    return m_i2c_lcd_control.writeReg(LCD_CMD,
144
+                                      DISPLAY_CMD_SET_NORMAL_1308); // set to normal display '1' is
145
+                                                                    // ON
148 146
 }
149 147
 
150 148
 mraa_result_t
151 149
 SSD1308::setAddressingMode(displayAddressingMode mode)
152 150
 {
153
-    mraa_i2c_write_byte_data(m_i2c_lcd_control,
154
-                             DISPLAY_CMD_MEM_ADDR_MODE,
155
-                             LCD_CMD);                          // set addressing mode
156
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, mode, LCD_CMD); // set page addressing mode
151
+    m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_MEM_ADDR_MODE); // set addressing mode
152
+    m_i2c_lcd_control.writeReg(LCD_CMD, mode);                      // set page addressing mode
157 153
 }

+ 68
- 73
src/lcd/ssd1327.cxx Переглянути файл

@@ -36,96 +36,92 @@ SSD1327::SSD1327(int bus_in, int addr_in) : I2CLcd(bus_in, addr_in)
36 36
 {
37 37
     mraa_result_t error = MRAA_SUCCESS;
38 38
     usleep(INIT_SLEEP);
39
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xFD, LCD_CMD); // Unlock OLED driver IC MCU
40
-                                                                // interface from entering command.
41
-                                                                // i.e: Accept commands
39
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0xFD); // Unlock OLED driver IC MCU
40
+                                               // interface from entering command.
41
+                                               // i.e: Accept commands
42 42
     usleep(INIT_SLEEP);
43
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x12, LCD_CMD);
43
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x12);
44 44
     usleep(INIT_SLEEP);
45
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xAE, LCD_CMD); // Set display off
45
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xAE); // Set display off
46 46
     usleep(INIT_SLEEP);
47
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xA8, LCD_CMD); // set multiplex ratio
47
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0xA8); // set multiplex ratio
48 48
     usleep(INIT_SLEEP);
49
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x5F, LCD_CMD); // 96
49
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x5F); // 96
50 50
     usleep(INIT_SLEEP);
51
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xA1, LCD_CMD); // set display start line
51
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xA1); // set display start line
52 52
     usleep(INIT_SLEEP);
53
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x00, LCD_CMD); //
53
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x00); //
54 54
     usleep(INIT_SLEEP);
55
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xA2, LCD_CMD); // set display offset
55
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xA2); // set display offset
56 56
     usleep(INIT_SLEEP);
57
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x60, LCD_CMD);
57
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x60);
58 58
     usleep(INIT_SLEEP);
59
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xA0, LCD_CMD); // set remap
59
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xA0); // set remap
60 60
     usleep(INIT_SLEEP);
61
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x46, LCD_CMD);
61
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x46);
62 62
     usleep(INIT_SLEEP);
63
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xAB, LCD_CMD); // set vdd internal
63
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xAB); // set vdd internal
64 64
     usleep(INIT_SLEEP);
65
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x01, LCD_CMD); //
65
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x01); //
66 66
     usleep(INIT_SLEEP);
67
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x81, LCD_CMD); // set contrasr
67
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x81); // set contrasr
68 68
     usleep(INIT_SLEEP);
69
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x53, LCD_CMD); // 100 nit
69
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x53); // 100 nit
70 70
     usleep(INIT_SLEEP);
71
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xB1, LCD_CMD); // Set Phase Length
71
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xB1); // Set Phase Length
72 72
     usleep(INIT_SLEEP);
73
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0X51, LCD_CMD); //
73
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0X51); //
74 74
     usleep(INIT_SLEEP);
75
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control,
76
-                                     0xB3,
77
-                                     LCD_CMD); // Set Display Clock Divide Ratio/Oscillator
78
-                                               // Frequency
75
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xB3); // Set Display Clock Divide Ratio/Oscillator
76
+                                                       // Frequency
79 77
     usleep(INIT_SLEEP);
80
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x01, LCD_CMD); //
78
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x01); //
81 79
     usleep(INIT_SLEEP);
82
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xB9, LCD_CMD); //
80
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xB9); //
83 81
     usleep(INIT_SLEEP);
84
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xBC, LCD_CMD); // set pre_charge
85
-                                                                        // voltage/VCOMH
82
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xBC); // set pre_charge
83
+                                                       // voltage/VCOMH
86 84
     usleep(INIT_SLEEP);
87
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x08, LCD_CMD); // (0x08);
85
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x08); // (0x08);
88 86
     usleep(INIT_SLEEP);
89
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xBE, LCD_CMD); // set VCOMH
87
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xBE); // set VCOMH
90 88
     usleep(INIT_SLEEP);
91
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0X07, LCD_CMD); // (0x07);
89
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0X07); // (0x07);
92 90
     usleep(INIT_SLEEP);
93
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xB6, LCD_CMD); // Set second pre-charge
94
-                                                                        // period
91
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xB6); // Set second pre-charge
92
+                                                       // period
95 93
     usleep(INIT_SLEEP);
96
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x01, LCD_CMD); //
94
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x01); //
97 95
     usleep(INIT_SLEEP);
98
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control,
99
-                                     0xD5,
100
-                                     LCD_CMD); // enable second precharge and enternal vsl
96
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xD5); // enable second precharge and enternal vsl
101 97
     usleep(INIT_SLEEP);
102
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0X62, LCD_CMD); // (0x62);
98
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0X62); // (0x62);
103 99
     usleep(INIT_SLEEP);
104
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xA4, LCD_CMD); // Set Normal Display Mode
100
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xA4); // Set Normal Display Mode
105 101
     usleep(INIT_SLEEP);
106
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x2E, LCD_CMD); // Deactivate Scroll
102
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x2E); // Deactivate Scroll
107 103
     usleep(INIT_SLEEP);
108
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xAF, LCD_CMD); // Switch on display
104
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0xAF); // Switch on display
109 105
     usleep(INIT_SLEEP);
110 106
 
111 107
     // Row Address
112
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x75, LCD_CMD); // Set Row Address
108
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x75); // Set Row Address
113 109
     usleep(INIT_SLEEP);
114
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x00, LCD_CMD); // Start 0
110
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x00); // Start 0
115 111
     usleep(INIT_SLEEP);
116
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x5f, LCD_CMD); // End 95
112
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x5f); // End 95
117 113
     usleep(INIT_SLEEP);
118 114
 
119 115
     // Column Address
120
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x15, LCD_CMD); // Set Column Address
116
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x15); // Set Column Address
121 117
     usleep(INIT_SLEEP);
122
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x08, LCD_CMD); // Start from 8th Column of
123
-                                                                        // driver IC. This is 0th
124
-                                                                        // Column for OLED
118
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x08); // Start from 8th Column of
119
+                                                       // driver IC. This is 0th
120
+                                                       // Column for OLED
125 121
     usleep(INIT_SLEEP);
126
-    error = mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x37, LCD_CMD); // End at  (8 + 47)th
127
-                                                                        // column. Each Column has 2
128
-                                                                        // pixels(segments)
122
+    error = m_i2c_lcd_control.writeReg(LCD_CMD, 0x37); // End at  (8 + 47)th
123
+                                                       // column. Each Column has 2
124
+                                                       // pixels(segments)
129 125
     usleep(INIT_SLEEP);
130 126
 
131 127
     clear();
@@ -153,7 +149,7 @@ SSD1327::draw(uint8_t* data, int bytes)
153 149
             value |= (bitOne) ? grayHigh : 0x00;
154 150
             value |= (bitTwo) ? grayLow : 0x00;
155 151
 
156
-            mraa_i2c_write_byte_data(m_i2c_lcd_control, value, LCD_DATA);
152
+            m_i2c_lcd_control.writeReg(LCD_DATA, value);
157 153
             usleep(CMD_SLEEP - 2000);
158 154
         }
159 155
     }
@@ -185,19 +181,19 @@ SSD1327::setCursor(int row, int column)
185 181
     mraa_result_t error = MRAA_SUCCESS;
186 182
 
187 183
     // Column Address
188
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x15, LCD_CMD); /* Set Column Address */
184
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x15); /* Set Column Address */
189 185
     usleep(CMD_SLEEP);
190
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x08 + (column * 4), LCD_CMD); /* Start Column:
186
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x08 + (column * 4)); /* Start Column:
191 187
                                                                                   Start from 8 */
192 188
     usleep(CMD_SLEEP);
193
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x37, LCD_CMD); /* End Column */
189
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x37); /* End Column */
194 190
     usleep(CMD_SLEEP);
195 191
     // Row Address
196
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x75, LCD_CMD); /* Set Row Address */
192
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x75); /* Set Row Address */
197 193
     usleep(CMD_SLEEP);
198
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x00 + (row * 8), LCD_CMD); /* Start Row*/
194
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x00 + (row * 8)); /* Start Row*/
199 195
     usleep(CMD_SLEEP);
200
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x07 + (row * 8), LCD_CMD); /* End Row*/
196
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x07 + (row * 8)); /* End Row*/
201 197
     usleep(CMD_SLEEP);
202 198
 
203 199
     return error;
@@ -254,7 +250,7 @@ SSD1327::writeChar(uint8_t value)
254 250
             data |= (bitOne) ? grayHigh : 0x00;
255 251
             data |= (bitTwo) ? grayLow : 0x00;
256 252
 
257
-            mraa_i2c_write_byte_data(m_i2c_lcd_control, data, LCD_DATA);
253
+            m_i2c_lcd_control.writeReg(LCD_DATA, data);
258 254
             usleep(CMD_SLEEP - 2000);
259 255
         }
260 256
     }
@@ -263,43 +259,42 @@ SSD1327::writeChar(uint8_t value)
263 259
 mraa_result_t
264 260
 SSD1327::setNormalDisplay()
265 261
 {
266
-    return mraa_i2c_write_byte_data(m_i2c_lcd_control,
267
-                                    DISPLAY_CMD_SET_NORMAL,
268
-                                    LCD_CMD); // set to normal display '1' is ON
262
+    return m_i2c_lcd_control.writeReg(LCD_CMD,
263
+                                      DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
269 264
 }
270 265
 
271 266
 mraa_result_t
272 267
 SSD1327::setHorizontalMode()
273 268
 {
274
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xA0, LCD_CMD); // remap to
269
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0xA0); // remap to
275 270
     usleep(CMD_SLEEP);
276
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x42, LCD_CMD); // horizontal mode
271
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x42); // horizontal mode
277 272
     usleep(CMD_SLEEP);
278 273
 
279 274
     // Row Address
280
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x75, LCD_CMD); // Set Row Address
275
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x75); // Set Row Address
281 276
     usleep(CMD_SLEEP);
282
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x00, LCD_CMD); // Start 0
277
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x00); // Start 0
283 278
     usleep(CMD_SLEEP);
284
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x5f, LCD_CMD); // End 95
279
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x5f); // End 95
285 280
     usleep(CMD_SLEEP);
286 281
 
287 282
     // Column Address
288
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x15, LCD_CMD); // Set Column Address
283
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x15); // Set Column Address
289 284
     usleep(CMD_SLEEP);
290
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x08, LCD_CMD); // Start from 8th Column of driver
291
-                                                                // IC. This is 0th Column for OLED
285
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x08); // Start from 8th Column of driver
286
+                                               // IC. This is 0th Column for OLED
292 287
     usleep(CMD_SLEEP);
293
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x37, LCD_CMD); // End at  (8 + 47)th column. Each
294
-                                                                // Column has 2 pixels(or segments)
288
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x37); // End at  (8 + 47)th column. Each
289
+                                               // Column has 2 pixels(or segments)
295 290
     usleep(CMD_SLEEP);
296 291
 }
297 292
 
298 293
 mraa_result_t
299 294
 SSD1327::setVerticalMode()
300 295
 {
301
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0xA0, LCD_CMD); // remap to
296
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0xA0); // remap to
302 297
     usleep(CMD_SLEEP);
303
-    mraa_i2c_write_byte_data(m_i2c_lcd_control, 0x46, LCD_CMD); // Vertical mode
298
+    m_i2c_lcd_control.writeReg(LCD_CMD, 0x46); // Vertical mode
304 299
     usleep(CMD_SLEEP);
305 300
 }