lcd: changed the OOO generalisation.
authorKiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
Thu, 5 Jun 2014 15:20:40 +0000 (15:20 +0000)
committerKiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
Fri, 6 Jun 2014 12:36:40 +0000 (12:36 +0000)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
src/lcd/iiclcd.cxx
src/lcd/iiclcd.h
src/lcd/jhd1313m1.cxx
src/lcd/jhd1313m1.h
src/lcd/lcm1602.cxx
src/lcd/ssd1308.cxx
src/lcd/ssd1308.h

index aec56f1..a2d39e4 100644 (file)
@@ -51,3 +51,36 @@ maa_result_t
 IICLcd::close() {
     return maa_i2c_stop(m_i2c_lcd_control);
 }
+
+maa_result_t
+IICLcd::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
+    maa_result_t error = MAA_SUCCESS;
+
+    uint8_t data[2] = { addr, value };
+    error = maa_i2c_address (ctx, deviceAdress);
+    error = maa_i2c_write (ctx, data, 2);
+
+    return error;
+}
+
+maa_result_t
+IICLcd::i2Cmd (maa_i2c_context ctx, uint8_t value) {
+    maa_result_t error = MAA_SUCCESS;
+
+    uint8_t data[2] = { LCD_CMD, value };
+    error = maa_i2c_address (ctx, m_lcd_control_address);
+    error = maa_i2c_write (ctx, data, 2);
+
+    return error;
+}
+
+maa_result_t
+IICLcd::i2cData (maa_i2c_context ctx, uint8_t value) {
+    maa_result_t error = MAA_SUCCESS;
+
+    uint8_t data[2] = { LCD_DATA, value };
+    error = maa_i2c_address (ctx, m_lcd_control_address);
+    error = maa_i2c_write (ctx, data, 2);
+
+    return error;
+}
index c36a9e1..fa12fd5 100644 (file)
@@ -35,8 +35,8 @@ namespace upm {
 #define LCD_DISPLAYCONTROL 0x08
 #define LCD_CURSORSHIFT 0x10
 #define LCD_FUNCTIONSET 0x20
-#define LCD_SETCGRAMADDR 0x40
-#define LCD_SETDDRAMADDR 0x80
+#define LCD_DATA 0x40
+#define LCD_CMD 0x80
 
 #define LCD_BACKLIGHT 0x08
 #define LCD_NOBACKLIGHT 0x00
@@ -70,11 +70,16 @@ namespace upm {
 class IICLcd {
     public:
         IICLcd (int bus, int lcdAddress);
-        virtual maa_result_t write (std::string msg) = 0;
         maa_result_t write (int x, int y, std::string msg);
+        
+        virtual maa_result_t write (std::string msg) = 0;
         virtual maa_result_t setCursor (int row, int column) = 0;
         virtual maa_result_t clear () = 0;
         virtual maa_result_t home () = 0;
+        virtual maa_result_t i2Cmd (maa_i2c_context ctx, uint8_t value);
+        virtual maa_result_t i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
+        virtual maa_result_t i2cData (maa_i2c_context ctx, uint8_t value);
+        
         maa_result_t close();
         std::string name()
         {
index eb114e9..9eed420 100644 (file)
@@ -41,29 +41,29 @@ Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : IICLcd(bus, lcd
     }
 
     usleep(50000);
-    cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
+    i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
     usleep(4500);
-    cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
+    i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
     usleep(4500);
-    cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
+    i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
     usleep(4500);
-    cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
+    i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
 
-    cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
+    i2Cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
     clear ();
     usleep(4500);
     
-    cmd (m_i2c_lcd_control,     LCD_ENTRYMODESET |
-                            LCD_ENTRYLEFT |
-                            LCD_ENTRYSHIFTDECREMENT);
+    i2Cmd (m_i2c_lcd_control, LCD_ENTRYMODESET |
+                              LCD_ENTRYLEFT |
+                              LCD_ENTRYSHIFTDECREMENT);
 
-    setReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
-    setReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
-    setReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
+    i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
+    i2cReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
+    i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
 
-    setReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
-    setReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
-    setReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
+    i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
+    i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
+    i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
 }
 
 Jhd1313m1::~Jhd1313m1() {
@@ -80,9 +80,7 @@ Jhd1313m1::write (std::string msg) {
     maa_result_t error = MAA_SUCCESS;
     uint8_t data[2] = {0x40, 0};
     for (std::string::size_type i = 0; i < msg.size(); ++i) {
-        data[1] = msg[i];
-        error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
-        error = maa_i2c_write (m_i2c_lcd_control, data, 2);
+        error = i2cData (m_i2c_lcd_control, msg[i]);
     }
 
     return error;
@@ -91,50 +89,19 @@ Jhd1313m1::write (std::string msg) {
 maa_result_t
 Jhd1313m1::setCursor (int row, int column) {
     maa_result_t error = MAA_SUCCESS;
-
     int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
     uint8_t offset = ((column % 16) + row_addr[row]);
-
-    uint8_t data[2] = { 0x80, offset };
-    error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
-    error = maa_i2c_write (m_i2c_lcd_control, data, 2);
+    error =  i2Cmd (m_i2c_lcd_control, offset);
 
     return error;
 }
 
 maa_result_t
 Jhd1313m1::clear () {
-    return cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
+    return i2Cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
 }
 
 maa_result_t
 Jhd1313m1::home () {
-    return cmd (m_i2c_lcd_control, LCD_RETURNHOME);
-}
-
-/*
- * **************
- *  private area
- * **************
- */
-maa_result_t
-Jhd1313m1::setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
-    maa_result_t error = MAA_SUCCESS;
-
-    uint8_t data[2] = { addr, value };
-    error = maa_i2c_address (ctx, deviceAdress);
-    error = maa_i2c_write (ctx, data, 2);
-
-    return error;
-}
-
-maa_result_t
-Jhd1313m1::cmd (maa_i2c_context ctx, uint8_t value) {
-    maa_result_t error = MAA_SUCCESS;
-
-    uint8_t data[2] = { 0x80, value };
-    error = maa_i2c_address (ctx, m_lcd_control_address);
-    error = maa_i2c_write (ctx, data, 2);
-
-    return error;
+    return i2Cmd (m_i2c_lcd_control, LCD_RETURNHOME);
 }
index 436e5c9..9b60c8f 100644 (file)
@@ -38,9 +38,6 @@ class Jhd1313m1 : public IICLcd {
         maa_result_t home ();
 
     private:
-        maa_result_t cmd (maa_i2c_context ctx, uint8_t value);
-        maa_result_t setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
-
         int m_rgb_address;
         maa_i2c_context m_i2c_lcd_rgb;
 };
index 6ec488b..fe39668 100644 (file)
@@ -85,7 +85,7 @@ Lcm1602::setCursor (int row, int column) {
     int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
     uint8_t offset = ((column % 16) + row_addr[row]);
 
-    return send (LCD_SETDDRAMADDR | offset, 0);
+    return send (LCD_CMD | offset, 0);
 }
 
 maa_result_t
index 2456efb..6aef5ae 100644 (file)
@@ -117,39 +117,6 @@ SSD1308::home () {
  * **************
  */
 maa_result_t
-SSD1308::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
-    maa_result_t error = MAA_SUCCESS;
-
-    uint8_t data[2] = { addr, value };
-    error = maa_i2c_address (ctx, deviceAdress);
-    error = maa_i2c_write (ctx, data, 2);
-
-    return error;
-}
-
-maa_result_t
-SSD1308::i2Cmd (maa_i2c_context ctx, uint8_t value) {
-    maa_result_t error = MAA_SUCCESS;
-
-    uint8_t data[2] = { 0x80, value };
-    error = maa_i2c_address (ctx, m_lcd_control_address);
-    error = maa_i2c_write (ctx, data, 2);
-
-    return error;
-}
-
-maa_result_t
-SSD1308::i2cData (maa_i2c_context ctx, uint8_t value) {
-    maa_result_t error = MAA_SUCCESS;
-
-    uint8_t data[2] = { 0x40, value };
-    error = maa_i2c_address (ctx, m_lcd_control_address);
-    error = maa_i2c_write (ctx, data, 2);
-
-    return error;
-}
-
-maa_result_t
 SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) {
     if (value < 0x20 || value > 0x7F) {
         value = 0x20; // space
index a3f1881..280198e 100644 (file)
@@ -156,16 +156,13 @@ class SSD1308 : public IICLcd {
         ~SSD1308 ();
         maa_result_t draw(uint8_t *data, int bytes);
 
-        // virtual methods
+        // pure virtual methods
         maa_result_t write (std::string msg);
         maa_result_t setCursor (int row, int column);
         maa_result_t clear ();
         maa_result_t home ();
 
     private:
-        maa_result_t i2Cmd (maa_i2c_context ctx, uint8_t value);
-        maa_result_t i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
-        maa_result_t i2cData (maa_i2c_context ctx, uint8_t value);
         maa_result_t writeChar (maa_i2c_context ctx, uint8_t value);
         maa_result_t setNormalDisplay ();
         maa_result_t setAddressingMode (displayAddressingMode mode);