Initial version for Modtronix LCD2S I2C and SPI serial LCD displays. For details, see http://modtronix.com/products-serial-lcd-board/

Files at this revision

API Documentation at this revision

Comitter:
modtronix
Date:
Fri Aug 07 18:27:11 2015 +1000
Parent:
1:429b7d3f7b95
Commit message:
Improvements

Changed in this revision

lcd2s.cpp Show annotated file Show diff for this revision Revisions of this file
lcd2s.h Show annotated file Show diff for this revision Revisions of this file
lcd2s_i2c.cpp Show annotated file Show diff for this revision Revisions of this file
lcd2s_i2c.h Show annotated file Show diff for this revision Revisions of this file
--- a/lcd2s.cpp	Tue Aug 04 18:54:37 2015 +1000
+++ b/lcd2s.cpp	Fri Aug 07 18:27:11 2015 +1000
@@ -21,6 +21,7 @@
 #include "mbed.h"
 #include "lcd2s.h"
 
+
 // DEFINES ////////////////////////////////////////////////////////////////////
 
 
@@ -33,6 +34,30 @@
 // Function Prototypes ////////////////////////////////////////////////////////
 
 
+// DEBUG ////////////////////////////////////////////////////////////////////
+//IMPORTANT, when enabling debugging, it is very important to note the following:
+//- If (MX_DEBUG_IS_POINTER==1), ensure there is global Stream pointer defined somewhere in code to override "pMxDebug = NULL" below!
+//- If (MX_DEBUG_IS_POINTER==0), define a mxDebug() function somewhere in code to handel debug output
+#define DEBUG_ENABLE            1
+#if (DEBUG_ENABLE==1) && !defined(NDEBUG)
+//Alternative method in stead of using NULL below. This requires to create derived Stream class in each file we want to use debugging
+//    class modtronixDebugStream : public Stream {int _putc(int value) {return 0;}int _getc() {return 0;}};
+//    static modtronixDebugStream modtronixDebug;
+//    WEAK Stream* pMxDebug = &modtronixDebug;
+    #if (MX_DEBUG_IS_POINTER==1)        //More efficient, but only works if pMxDebug is defined in code. Disabled by default!
+        WEAK Stream* pMxDebug = NULL;
+        #define MX_DEBUG  pMxDebug->printf
+    #else
+        WEAK void mxDebug(const char *format, ...) {}
+        #define MX_DEBUG mxDebug
+    #endif
+#else
+    //GCC's CPP has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away.
+    #define MX_DEBUG(format, args...) ((void)0)
+#endif
+
+
+
 LCD2S::LCD2S(uint8_t rows/* = 4*/, uint8_t columns/* = 20*/) {
     contrast = 200;
     brightness = 200;
@@ -41,6 +66,8 @@
     bufSize = rows * columns;
     cursor_row = cursor_col = 0;
 
+    //MX_DEBUG("\r\nLCD2S()");
+
 #if (LCD2S_USE_MALLOC == 1)
     buf = new uint8_t[bufSize)];
     dirtyRows = new uint32_t(rows);
--- a/lcd2s.h	Tue Aug 04 18:54:37 2015 +1000
+++ b/lcd2s.h	Fri Aug 07 18:27:11 2015 +1000
@@ -24,6 +24,15 @@
 
 #include "mbed.h"
 
+#ifndef WEAK
+    #if defined (__ICCARM__)
+        #define WEAK     __weak
+    #else
+        #define WEAK     __attribute__((weak))
+    #endif
+#endif
+
+
 //LCD2S Commands
 /** Cursor moves backwards, no parameters */
 #define LCD2S_CMD_CURSOR_MOVES_BACKWARDS    0x01
@@ -205,8 +214,10 @@
     virtual void initDefault(uint8_t contrast) = 0;
 
     /** Causes the display to be updated with buffer content
+     *
+     * @return 0 if success, else error code
      */
-    virtual void display() = 0;
+    virtual uint8_t display() = 0;
 
     void clearDisplay();
 
--- a/lcd2s_i2c.cpp	Tue Aug 04 18:54:37 2015 +1000
+++ b/lcd2s_i2c.cpp	Fri Aug 07 18:27:11 2015 +1000
@@ -93,7 +93,8 @@
 
 /** Causes the display to be updated with buffer content
  */
-void LCD2S_I2C::display(void) {
+uint8_t LCD2S_I2C::display(void) {
+    uint8_t retVal = 0;
     uint8_t row, col;
     uint8_t colFirstDirty   = 0xff;
     uint8_t colLastDirty    = 0xff;
@@ -132,7 +133,9 @@
             cmd[0] = LCD2S_CMD_SET_CURSOR_POSITION;
             cmd[1] = row+1;
             cmd[2] = colFirstDirty+1;
-            pI2C->write(this->i2cAdr, cmd, 3);
+            if ((retVal = pI2C->write(this->i2cAdr, cmd, 3)) != 0) {
+                return retVal;  //Return error code
+            }
             wait_ms(5);
 
             //Write string - only dirty characters are written
@@ -140,9 +143,13 @@
             for(col=colFirstDirty; col<=colLastDirty; col++) {
                 cmd[col-colFirstDirty+1] = pBuf[(row*columns)+col];
             }
-            pI2C->write(this->i2cAdr, cmd, colLastDirty-colFirstDirty+2);
+            if ((retVal = pI2C->write(this->i2cAdr, cmd, colLastDirty-colFirstDirty+2)) != 0) {
+                return retVal;  //Return error code
+            }
         }
     }
+
+    return retVal;
 }
 
 int LCD2S_I2C::writeChar(uint8_t c) {
--- a/lcd2s_i2c.h	Tue Aug 04 18:54:37 2015 +1000
+++ b/lcd2s_i2c.h	Fri Aug 07 18:27:11 2015 +1000
@@ -51,8 +51,10 @@
 
 
     /** Causes the display to be updated with buffer content
+     *
+     * @return: 0 is successful, else non-0
      */
-    void display();
+    uint8_t display();
 
     int writeChar(uint8_t c);