ok

Fork of TextLCD by Wim Huiskamp

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Fri May 30 15:05:13 2014 +0000
Parent:
25:6162b31128c9
Child:
27:22d5086f6ba6
Commit message:
Added support for MCP23008 I2C expander, added pinmapping for Adafruit I2C and SPI backplane.

Changed in this revision

TextLCD.cpp Show annotated file Show diff for this revision Revisions of this file
TextLCD.h Show annotated file Show diff for this revision Revisions of this file
--- a/TextLCD.cpp	Sat May 10 21:34:51 2014 +0000
+++ b/TextLCD.cpp	Fri May 30 15:05:13 2014 +0000
@@ -9,6 +9,7 @@
  *               2013, v07: WH, Added support for backlight and include portdefinitions for LCD2004 Module from DFROBOT 
  *               2014, v08: WH, Refactored in Base and Derived Classes to deal with mbed lib change regarding 'NC' defined pins 
  *               2014, v09: WH/EO, Added Class for Native SPI controllers such as ST7032 
+ *               2014, v10: WH, Added Class for Native I2C controllers such as ST7032i, Added support for MCP23008 I2C portexpander, Added support for Adafruit module  
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -78,9 +79,9 @@
   */
 void TextLCD_Base::_initCtrl() {
 
-    this->_setRS(false);      // command mode
+    this->_setRS(false); // command mode
     
-    wait_ms(20);        // Wait 20ms to ensure powered up
+    wait_ms(20);         // Wait 20ms to ensure powered up
 
     // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)    
     for (int i=0; i<3; i++) {
@@ -111,16 +112,34 @@
           wait_ms(50);      
           break;
           
-      case ST7032:
+      case ST7032_3V3:
+          // ST7032 controller: Initialise Voltage booster for VLCD. VDD=3V3
+     
           _writeByte( 0x1c );    //Internal OSC frequency adjustment 183HZ, bias will be 1/4 
           wait_us(30);
-          _writeByte( 0x73 );    //Contrast control  low byte
+          _writeByte( 0x73 );    //Contrast control low byte
           wait_us(30);  
-          _writeByte( 0x57 );    //booster circuit is turn on. /ICON display off. /Contrast control   high byte
+          _writeByte( 0x57 );    //booster circuit is turned on. /ICON display off. /Contrast control high byte
           wait_us(30);
           _writeByte( 0x6c );    //Follower control
           wait_us(50);   
-          _writeByte( 0x0c );    //DISPLAY ON
+          _writeByte( 0x0c );    //DISPLAY ON, not needed
+          wait_us(30);
+          break;
+
+//Check and fix booster disable
+      case ST7032_5V:
+          // ST7032 controller: Disable Voltage booster for VLCD. VDD=5V      
+          
+          _writeByte( 0x1c );    //Internal OSC frequency adjustment 183HZ, bias will be 1/4 
+          wait_us(30);
+          _writeByte( 0x73 );    //Contrast control low byte
+          wait_us(30);  
+          _writeByte( 0x57 );    //booster circuit is turned on. /ICON display off. /Contrast control high byte
+          wait_us(30);
+          _writeByte( 0x6c );    //Follower control
+          wait_us(50);   
+          _writeByte( 0x0c );    //DISPLAY ON  --> remove, done later?
           wait_us(30);
           break;
           
@@ -858,10 +877,10 @@
 
 //--------- Start TextLCD_I2C -----------
 
-/** Create a TextLCD interface using an I2C PC8574 or PCF8574A portexpander
+/** Create a TextLCD interface using an I2C PC8574 (or PCF8574A) or MCP23008 portexpander
   *
   * @param i2c             I2C Bus
-  * @param deviceAddress   I2C slave address (PCF8574 or PCF8574A, default = 0x40)
+  * @param deviceAddress   I2C slave address (PCF8574, PCF8574A or MCP23008, default = 0x40)
   * @param type            Sets the panel size/addressing mode (default = LCD16x2)
   * @param ctrl            LCD controller (default = HD44780)    
   */
@@ -871,11 +890,35 @@
                               
   _slaveAddress = deviceAddress & 0xFE;
   
+
+#if (MCP23008==1)
+  // MCP23008 portexpander Init
+   _write_register(IODIR,   0x00);  // All outputs
+   _write_register(IPOL,    0x00);  // No reverse polarity 
+   _write_register(GPINTEN, 0x00);  // No interrupt 
+   _write_register(DEFVAL,  0x00);  // Default value to compare against for interrupts
+   _write_register(INTCON,  0x00);  // No interrupt on changes 
+   _write_register(IOCON,   0x00);  // Interrupt polarity   
+   _write_register(GPPU,    0x00);  // No Pullup 
+   _write_register(INTF,    0x00);  //    
+   _write_register(INTCAP,  0x00);  //    
+   _write_register(GPIO,    0x00);  // Output/Input pins   
+   _write_register(OLAT,    0x00);  // Output Latch  
+    
   // Init the portexpander bus
   _lcd_bus = D_LCD_BUS_DEF;
   
   // write the new data to the portexpander
+  _write_register(GPIO, _lcd_bus);      
+#else
+  // PCF8574 of PCF8574A portexpander
+
+  // Init the portexpander bus
+  _lcd_bus = D_LCD_BUS_DEF;
+
+  // write the new data to the portexpander
   _i2c->write(_slaveAddress, &_lcd_bus, 1);    
+#endif
 
   _init();
     
@@ -886,34 +929,59 @@
 void TextLCD_I2C::_setEnable(bool value) {
 
   if(_ctrl_idx==_LCDCtrl_0) {
-    if (value)
+    if (value) {
       _lcd_bus |= D_LCD_E;     // Set E bit 
-    else                     
+    }  
+    else {                    
       _lcd_bus &= ~D_LCD_E;    // Reset E bit                     
+    }  
   }
   else {
-    if (value)
+    if (value) {
       _lcd_bus |= D_LCD_E2;    // Set E2 bit 
-    else                     
+    }  
+    else {
       _lcd_bus &= ~D_LCD_E2;   // Reset E2bit                     
-    }    
+    }  
+  }    
+
+
+#if (MCP23008==1)
+  // MCP23008 portexpander
+  
+  // write the new data to the portexpander
+  _write_register(GPIO, _lcd_bus);      
+#else
+  // PCF8574 of PCF8574A portexpander
 
   // write the new data to the I2C portexpander
   _i2c->write(_slaveAddress, &_lcd_bus, 1);    
-
+#endif
 }    
 
 // Set RS pin
 // Used for mbed pins, I2C bus expander or SPI shiftregister
 void TextLCD_I2C::_setRS(bool value) {
 
-  if (value)
+  if (value) {
     _lcd_bus |= D_LCD_RS;    // Set RS bit 
-  else                     
+  }  
+  else {                    
     _lcd_bus &= ~D_LCD_RS;   // Reset RS bit                     
+  }
+
+
+#if (MCP23008==1)
+  // MCP23008 portexpander
+  
+  // write the new data to the portexpander
+  _write_register(GPIO, _lcd_bus);      
+#else
+  // PCF8574 of PCF8574A portexpander
 
   // write the new data to the I2C portexpander
   _i2c->write(_slaveAddress, &_lcd_bus, 1);    
+#endif
                   
 }    
 
@@ -921,13 +989,24 @@
 // Used for mbed pins, I2C bus expander or SPI shiftregister
 void TextLCD_I2C::_setBL(bool value) {
 
-  if (value)
+  if (value) {
     _lcd_bus |= D_LCD_BL;    // Set BL bit 
-  else                     
+  }  
+  else {                    
     _lcd_bus &= ~D_LCD_BL;   // Reset BL bit                     
+  }
+  
+#if (MCP23008==1)
+  // MCP23008 portexpander
+  
+  // write the new data to the portexpander
+  _write_register(GPIO, _lcd_bus);      
+#else
+  // PCF8574 of PCF8574A portexpander
 
   // write the new data to the I2C portexpander
   _i2c->write(_slaveAddress, &_lcd_bus, 1);    
+#endif
                  
 }    
 
@@ -941,31 +1020,56 @@
   // Set bit by bit to support any mapping of expander portpins to LCD pins
   
   data = value & 0x0F;
-  if (data & 0x01)
+  if (data & 0x01){
     _lcd_bus |= D_LCD_D4;   // Set Databit 
-  else                     
-    _lcd_bus &= ~D_LCD_D4;  // Reset Databit                     
+  }  
+  else { 
+    _lcd_bus &= ~D_LCD_D4;  // Reset Databit
+  }  
 
-  if (data & 0x02)
+  if (data & 0x02){
     _lcd_bus |= D_LCD_D5;   // Set Databit 
-  else                     
-    _lcd_bus &= ~D_LCD_D5;  // Reset Databit                     
+  }  
+  else {
+    _lcd_bus &= ~D_LCD_D5;  // Reset Databit
+  }  
 
-  if (data & 0x04)
+  if (data & 0x04) {
     _lcd_bus |= D_LCD_D6;   // Set Databit 
-  else                     
-    _lcd_bus &= ~D_LCD_D6;  // Reset Databit                     
+  }  
+  else {                    
+    _lcd_bus &= ~D_LCD_D6;  // Reset Databit
+  }  
 
-  if (data & 0x08)
+  if (data & 0x08) {
     _lcd_bus |= D_LCD_D7;   // Set Databit 
-  else                     
-    _lcd_bus &= ~D_LCD_D7;  // Reset Databit                     
+  }  
+  else {
+    _lcd_bus &= ~D_LCD_D7;  // Reset Databit
+  }  
                     
+#if (MCP23008==1)
+  // MCP23008 portexpander
+  
+  // write the new data to the portexpander
+  _write_register(GPIO, _lcd_bus);      
+#else
+  // PCF8574 of PCF8574A portexpander
+
   // write the new data to the I2C portexpander
-  _i2c->write(_slaveAddress, &_lcd_bus, 1);  
+  _i2c->write(_slaveAddress, &_lcd_bus, 1);    
+#endif
                  
 }    
 
+// Write data to MCP23008 I2C portexpander
+void TextLCD_I2C::_write_register (int reg, int value) {
+  char data[] = {reg, value};
+    
+  _i2c->write(_slaveAddress, data, 2);
+ 
+}
+
 //---------- End TextLCD_I2C ------------
 
 
@@ -1008,16 +1112,20 @@
 void TextLCD_SPI::_setEnable(bool value) {
 
   if(_ctrl_idx==_LCDCtrl_0) {
-    if (value)
+    if (value) {
       _lcd_bus |= D_LCD_E;     // Set E bit 
-    else                     
+    }  
+    else {                    
       _lcd_bus &= ~D_LCD_E;    // Reset E bit                     
+    }  
   }
   else {
-    if (value)
+    if (value) {
       _lcd_bus |= D_LCD_E2;    // Set E2 bit 
-    else                     
+    }  
+    else {
       _lcd_bus &= ~D_LCD_E2;   // Reset E2 bit                     
+    }  
   }
                   
   // write the new data to the SPI portexpander
@@ -1073,25 +1181,33 @@
   // Set bit by bit to support any mapping of expander portpins to LCD pins
     
   data = value & 0x0F;
-  if (data & 0x01)
+  if (data & 0x01) {
     _lcd_bus |= D_LCD_D4;   // Set Databit 
-  else                     
+  }  
+  else {                    
     _lcd_bus &= ~D_LCD_D4;  // Reset Databit                     
-
-  if (data & 0x02)
+  }
+  
+  if (data & 0x02) {
     _lcd_bus |= D_LCD_D5;   // Set Databit 
-  else                     
+  }  
+  else {
     _lcd_bus &= ~D_LCD_D5;  // Reset Databit                     
-
-  if (data & 0x04)
+  }
+  
+  if (data & 0x04) {
     _lcd_bus |= D_LCD_D6;   // Set Databit 
-  else                     
+  }  
+  else {
     _lcd_bus &= ~D_LCD_D6;  // Reset Databit                     
-
-  if (data & 0x08)
+  }
+  
+  if (data & 0x08) {
     _lcd_bus |= D_LCD_D7;   // Set Databit 
-  else                     
-    _lcd_bus &= ~D_LCD_D7;  // Reset Databit                     
+  }  
+  else {
+    _lcd_bus &= ~D_LCD_D7;  // Reset Databit
+  }  
                     
   // write the new data to the SPI portexpander
   _setCS(false);  
@@ -1125,7 +1241,7 @@
    * @param rs              Instruction/data control line
    * @param type            Sets the panel size/addressing mode (default = LCD16x2)
    * @param bl              Backlight control line (optional, default = NC)  
-   * @param ctrl            LCD controller (default = ST7032) 
+   * @param ctrl            LCD controller (default = ST7032_3V3) 
    */       
 TextLCD_SPI_N::TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type, PinName bl, LCDCtrl ctrl) :
                              TextLCD_Base(type, ctrl), 
@@ -1169,8 +1285,9 @@
 
 // Set BL pin
 void TextLCD_SPI_N::_setBL(bool value) {
-    if (_bl)
+    if (_bl) {
         _bl->write(value);   
+    }    
 }    
 
 // Write a byte using SPI
--- a/TextLCD.h	Sat May 10 21:34:51 2014 +0000
+++ b/TextLCD.h	Fri May 30 15:05:13 2014 +0000
@@ -9,6 +9,7 @@
  *               2013, v07: WH, Added support for backlight and include portdefinitions for LCD2004 Module from DFROBOT
  *               2014, v08: WH, Refactored in Base and Derived Classes to deal with mbed lib change regarding 'NC' defined DigitalOut pins
  *               2014, v09: WH/EO, Added Class for Native SPI controllers such as ST7032 
+ *               2014, v10: WH, Added Class for Native I2C controllers such as ST7032i, Added support for MCP23008 I2C portexpander, Added support for Adafruit module  
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -34,11 +35,10 @@
 
 #include "mbed.h"
 
-
 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
  *
  * Currently supports 8x1, 8x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
- * Interface options include direct mbed pins, I2C portexpander (PCF8474, PCF8574A) or SPI bus shiftregister (74595)
+ * Interface options include direct mbed pins, I2C portexpander (PCF8474, PCF8574A, MCP23008) or SPI bus shiftregister (74595)
  * Supports some controllers that provide internal DC/DC converters for VLCD or VLED. 
  *
  * @code
@@ -55,7 +55,7 @@
  * //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4);                    // SPI bus, CS pin, LCD Type  
  * TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4);                  // I2C bus, PCF8574 Slaveaddress, LCD Type
  * //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type
- * //TextLCD_SPI_N lcd(&spi_lcd, p8, p9);                                  // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032   
+ * //TextLCD_SPI_N lcd(&spi_lcd, p8, p9);                                // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032   
  * 
  * int main() {
  *   lcd.printf("Hello World!\n");
@@ -63,14 +63,23 @@
  * @endcode
  */
 
-//Pin Defines for I2C PCF8574 and SPI 74595 Bus interfaces
+
+//Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces
 //LCD and serial portexpanders should be wired accordingly 
 //
-#if (1)
+//Select Hardware module (one option only)
+#define DEFAULT        1
+#define ADAFRUIT       0
+#define DFROBOT        0
+
+
+#if (DEFAULT==1)
 //Definitions for hardware used by WH 
+//This hardware supports the I2C bus expander (PCF8574/PCF8574A or MCP23008) and SPI bus expander (74595) interfaces
+//
 //Note: LCD RW pin must be connected to GND
 //      E2 is used for LCD40x4 (second controller)
-//      BL may be used for future expansion to control backlight
+//      BL may be used to control backlight
 #define D_LCD_PIN_D4   0
 #define D_LCD_PIN_D5   1
 #define D_LCD_PIN_D6   2
@@ -82,12 +91,40 @@
 
 #define D_LCD_PIN_RW   D_LCD_PIN_E2
 
-#else
+//Select I2C Portexpander type (one option only)
+#define PCF8574        1
+#define MCP23008       0
+#endif
 
+#if (ADAFRUIT==1)
+//Definitions for i2cspilcdbackpack from Adafruit, See http://www.ladyada.net/products/i2cspilcdbackpack
+//This hardware supports both an I2C expander (MCP23008) and an SPI expander (74595) selectable by a jumper.
+//
+//Note: LCD RW pin must be kept LOW
+//      E2 is not available on this hardware and so it does not support LCD40x4 (second controller)
+//      BL is used to control backlight
+#define D_LCD_PIN_0    0
+#define D_LCD_PIN_RS   1
+#define D_LCD_PIN_E    2
+#define D_LCD_PIN_D4   3
+#define D_LCD_PIN_D5   4
+#define D_LCD_PIN_D6   5
+#define D_LCD_PIN_D7   6
+#define D_LCD_PIN_BL   7
+
+#define D_LCD_PIN_E2   D_LCD_PIN_0
+
+//Force I2C portexpander type
+#define PCF8574        0
+#define MCP23008       1
+#endif
+
+#if (DFROBOT==1)
 //Definitions for LCD2004 Module from DFROBOT, See http://arduino-info.wikispaces.com/LCD-Blue-I2C
-//This hardware is different from earlier/different Arduino I2C LCD displays
+//This hardware uses PCF8574 and is different from earlier/different Arduino I2C LCD displays
+//
 //Note: LCD RW pin must be kept LOW
-//      E2 is not available on default Arduino hardware and does not support LCD40x4 (second controller)
+//      E2 is not available on default Arduino hardware and so it does not support LCD40x4 (second controller)
 //      BL is used to control backlight
 #define D_LCD_PIN_RS   0
 #define D_LCD_PIN_RW   1
@@ -99,9 +136,13 @@
 #define D_LCD_PIN_D7   7
 
 #define D_LCD_PIN_E2   D_LCD_PIN_RW
+
+//Force I2C portexpander type
+#define PCF8574        1
+#define MCP23008       0
 #endif
 
-//Bitpattern Defines for I2C PCF8574 and SPI 74595 Bus
+//Bitpattern Defines for I2C PCF8574/PCF8574A, MCP23008 and SPI 74595 Bus expanders
 //
 #define D_LCD_D4       (1<<D_LCD_PIN_D4)
 #define D_LCD_D5       (1<<D_LCD_PIN_D5)
@@ -113,10 +154,56 @@
 #define D_LCD_BL       (1<<D_LCD_PIN_BL)
 //#define D_LCD_RW       (1<<D_LCD_PIN_RW)
 
-
 #define D_LCD_BUS_MSK  (D_LCD_D4 | D_LCD_D5 | D_LCD_D6 | D_LCD_D7)
 #define D_LCD_BUS_DEF  0x00
 
+/* PCF8574/PCF8574A I2C portexpander slave address */
+#define PCF8574_SA0   0x40
+#define PCF8574_SA1   0x42
+#define PCF8574_SA2   0x44
+#define PCF8574_SA3   0x46
+#define PCF8574_SA4   0x48
+#define PCF8574_SA5   0x4A
+#define PCF8574_SA6   0x4C
+#define PCF8574_SA7   0x4E
+
+#define PCF8574A_SA0  0x70
+#define PCF8574A_SA1  0x72
+#define PCF8574A_SA2  0x74
+#define PCF8574A_SA3  0x76
+#define PCF8574A_SA4  0x78
+#define PCF8574A_SA5  0x7A
+#define PCF8574A_SA6  0x7C
+#define PCF8574A_SA7  0x7E
+
+/* MCP23008 I2C portexpander slave address */
+#define MCP23008_SA0  0x40
+#define MCP23008_SA1  0x42
+#define MCP23008_SA2  0x44
+#define MCP23008_SA3  0x46
+#define MCP23008_SA4  0x48
+#define MCP23008_SA5  0x4A
+#define MCP23008_SA6  0x4C
+#define MCP23008_SA7  0x4E
+
+
+/* MCP23008 I2C portexpander internal registers */
+#define IODIR         0x00
+#define IPOL          0x01
+#define GPINTEN       0x02
+#define DEFVAL        0x03
+#define INTCON        0x04
+#define IOCON         0x05
+#define GPPU          0x06
+#define INTF          0x07
+#define INTCAP        0x08
+#define GPIO          0x09
+#define OLAT          0x0A
+
+
+/* ST7032I I2C slave address */
+#define ST7032_SA     0x7C
+
 
 /** Some sample User Defined Chars 5x7 dots */
 const char udc_ae[] = {0x00, 0x00, 0x1B, 0x05, 0x1F, 0x14, 0x1F, 0x00};  //æ
@@ -164,7 +251,7 @@
 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
  *
  * @brief Currently supports 8x1, 8x2, 12x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
- *        Interface options include direct mbed pins, I2C portexpander (PCF8474, PCF8574A) or SPI bus shiftregister (74595) 
+ *        Interface options include direct mbed pins, I2C portexpander (PCF8474, PCF8574A) or SPI bus shiftregister (74595) and some native I2C or SPI devices 
  *
  */
 class TextLCD_Base : public Stream {
@@ -191,10 +278,11 @@
 
     /** LCD Controller Device */
     enum LCDCtrl {
-        HD44780,    /**<  HD44780 (default)      */    
-        WS0010,     /**<  WS0010 OLED Controller */    
-        ST7036,      /**<  ST7036                 */   
-        ST7032      /**<  ST7032                 */   
+        HD44780,    /**<  HD44780 (default)       */    
+        WS0010,     /**<  WS0010 OLED Controller  */    
+        ST7036,     /**<  ST7036                  */   
+        ST7032_3V3, /**<  ST7032 3V3 with Booster */   
+        ST7032_5V   /**<  ST7032 5V  no Booster   */           
     };
 
 
@@ -424,26 +512,29 @@
 //--------- Start TextLCD_I2C -----------
 
 
-/** Create a TextLCD interface using an I2C PC8574 or PCF8574A portexpander
+/** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander
   *
   */
 class TextLCD_I2C : public TextLCD_Base {    
 public:
-    /** Create a TextLCD interface using an I2C PC8574 or PCF8574A portexpander
+   /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander
      *
      * @param i2c             I2C Bus
-     * @param deviceAddress   I2C slave address (PCF8574 or PCF8574A, default = 0x40)
+     * @param deviceAddress   I2C slave address (PCF8574 or PCF8574A, default = PCF8574_SA0 = 0x40)
      * @param type            Sets the panel size/addressing mode (default = LCD16x2)
      * @param ctrl            LCD controller (default = HD44780)                
      */
-    TextLCD_I2C(I2C *i2c, char deviceAddress = 0x40, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
+    TextLCD_I2C(I2C *i2c, char deviceAddress = PCF8574_SA0, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
 
 private:
 //Low level writes to LCD Bus (serial or parallel)
     virtual void _setEnable(bool value);
     virtual void _setRS(bool value);  
     virtual void _setBL(bool value);
-    virtual void _setData(int value);   
+    virtual void _setData(int value); 
+
+// Write data to MCP23008 I2C portexpander
+    void _write_register (int reg, int value);     
   
 //I2C bus
     I2C *_i2c;
@@ -500,8 +591,8 @@
 //---------- End TextLCD_SPI ------------
 
 
-//--------- Start TextLCD_NativeSPI -----------
 
+//--------- Start TextLCD_SPI_N -----------
 
 /** Create a TextLCD interface using a controller with native SPI interface
   *
@@ -515,9 +606,9 @@
      * @param rs              Instruction/data control line
      * @param type            Sets the panel size/addressing mode (default = LCD16x2)
      * @param bl              Backlight control line (optional, default = NC)  
-     * @param ctrl            LCD controller (default = ST7032)                     
+     * @param ctrl            LCD controller (default = ST7032_3V3)                     
      */
-    TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032);
+    TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3);
     virtual ~TextLCD_SPI_N(void);
 
 private:
@@ -537,4 +628,40 @@
 
 //---------- End TextLCD_SPI_N ------------
 
+
+//--------- Start TextLCD_I2C_N -----------
+
+/** Create a TextLCD interface using a controller with native I2C interface
+  *
+  */
+class TextLCD_I2C_N : public TextLCD_Base {    
+public:
+    /** Create a TextLCD interface using a controller with native I2C interface
+     *
+     * @param i2c             I2C Bus
+     * @param deviceAddress   I2C slave address (default = 0x)  
+     * @param type            Sets the panel size/addressing mode (default = LCD16x2)
+     * @param ctrl            LCD controller (default = ST7032_3V3)                     
+     */
+    TextLCD_I2C_N(I2C *i2c, char deviceAddress = 0x40, LCDType type = LCD16x2, LCDCtrl ctrl = ST7032_3V3);
+    virtual ~TextLCD_I2C_N(void);
+
+private:
+    virtual void _setEnable(bool value);
+    virtual void _setRS(bool value);  
+    virtual void _setBL(bool value);
+    virtual void _setData(int value);
+    virtual void _writeByte(int value);
+
+//I2C bus
+    I2C *_i2c;
+    char _slaveAddress;
+    
+// Internal bus mirror value for serial bus only
+    char _lcd_bus;   
+};
+
+//---------- End TextLCD_I2C_N ------------
+
+
 #endif