A TextLCD interface for driving 4-bit HD44780-based LCDs.

Fork of TextLCD by Wim Huiskamp

Revision:
42:14e1718fba52
Parent:
41:111ca62e8a59
Child:
43:db59a996a57a
--- a/TextLCD_Config.h	Fri Nov 06 18:59:27 2015 +0000
+++ b/TextLCD_Config.h	Fri Jan 06 14:51:48 2017 +0000
@@ -33,15 +33,15 @@
 #define MBED_TEXTLCDCONFIG_H
 
 //Select hardware interface options to reduce memory footprint (multiple options allowed)
-#define LCD_I2C        1           /* I2C Expander PCF8574/MCP23008 */
-#define LCD_SPI        1           /* SPI Expander SN74595          */
-#define LCD_I2C_N      1           /* Native I2C bus     */
-#define LCD_SPI_N      1           /* Native SPI bus     */
-#define LCD_SPI_N_3_8  1           /* Native SPI bus     */
-#define LCD_SPI_N_3_9  1           /* Native SPI bus     */
-#define LCD_SPI_N_3_10 1           /* Native SPI bus     */
-#define LCD_SPI_N_3_16 1           /* Native SPI bus     */
-#define LCD_SPI_N_3_24 1           /* Native SPI bus     */
+#define LCD_I2C        1           /* I2C Expander PCF8574/MCP23008/PCA9538 */
+#define LCD_SPI        0           /* SPI Expander SN74595          */
+#define LCD_I2C_N      0           /* Native I2C bus     */
+#define LCD_SPI_N      0           /* Native SPI bus     */
+#define LCD_SPI_N_3_8  0           /* Native SPI bus     */
+#define LCD_SPI_N_3_9  0           /* Native SPI bus     */
+#define LCD_SPI_N_3_10 0           /* Native SPI bus     */
+#define LCD_SPI_N_3_16 0           /* Native SPI bus     */
+#define LCD_SPI_N_3_24 0           /* Native SPI bus     */
 
 //Select options to reduce memory footprint (multiple options allowed)
 #define LCD_UDC        1           /* Enable predefined UDC example*/
@@ -53,7 +53,7 @@
 #define LCD_POWER      1           /* Enable Power control implementation -0.1K codesize*/
 #define LCD_BLINK      1           /* Enable UDC and Icon Blink control implementation -0.8K codesize*/
 #define LCD_CONTRAST   1           /* Enable Contrast control implementation -0.9K codesize*/
-#define LCD_TWO_CTRL   1           /* Enable LCD40x4 (two controller) implementation -0.1K codesize*/
+#define LCD_TWO_CTRL   0           /* Enable LCD40x4 (two controller) implementation -0.1K codesize*/
 #define LCD_FONTSEL    0           /* Enable runtime font select implementation using setFont -0.9K codesize*/
 
 //Select option to activate default fonttable or alternatively use conversion for specific controller versions (eg PCF2116C, PCF2119R, SSD1803, US2066)
@@ -63,7 +63,7 @@
 //#define LCD_UTF8_FONT  1           /* Enable UTF8 Support (eg Cyrillic tables) -0.4K codesize*/
 //#define LCD_UTF8_CYR_B 1           /*  Select specific UTF8 Cyrillic table (SSD1803 ROM_B)              */
 
-//Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces
+//Pin Defines for I2C PCF8574/PCF8574A or MCP23008 or PCA9538 and SPI 74595 bus expander interfaces
 //Different commercially available LCD portexpanders use different wiring conventions.
 //LCD and serial portexpanders should be wired according to the tables below.
 //
@@ -81,14 +81,14 @@
 
 #if (DEFAULT==1)
 //Definitions for default (WH) mapping between serial port expander pins and LCD controller
-//This hardware supports the I2C bus expander (PCF8574/PCF8574A or MCP23008) and SPI bus expander (74595) interfaces
+//This hardware supports the I2C bus expander (PCF8574/PCF8574A or MCP23008or PCA9538) and SPI bus expander (74595) interfaces
 //See https://mbed.org/cookbook/Text-LCD-Enhanced
 //
 //Note: LCD RW pin must be connected to GND
 //      E2 is used for LCD40x4 (second controller)
 //      BL may be used to control backlight
 
-//I2C bus expander (PCF8574/PCF8574A or MCP23008) interface
+//I2C bus expander (PCF8574/PCF8574A or MCP23008 or PCA9538) interface
 #define LCD_BUS_I2C_D4 (1 << 0)
 #define LCD_BUS_I2C_D5 (1 << 1)
 #define LCD_BUS_I2C_D6 (1 << 2)
@@ -113,8 +113,9 @@
 #define LCD_BUS_SPI_RW LCD_BUS_I2C_RW
 
 //Select I2C Portexpander type (one option only)
-#define PCF8574        1
+#define PCF8574        0
 #define MCP23008       0
+#define PCA9538        1
 
 //Inverted Backlight control
 #define BACKLIGHT_INV  0
@@ -160,6 +161,7 @@
 //Force I2C portexpander type
 #define PCF8574        0
 #define MCP23008       1
+#define PCA9538        0
 
 //Inverted Backlight control
 #define BACKLIGHT_INV  0
@@ -209,6 +211,7 @@
 //Force I2C portexpander type
 #define PCF8574        1
 #define MCP23008       0
+#define PCA9538        0
 
 //Inverted Backlight control
 #define BACKLIGHT_INV  0
@@ -251,6 +254,7 @@
 //Force I2C portexpander type
 #define PCF8574        1
 #define MCP23008       0
+#define PCA9538        0
 
 //Inverted Backlight control
 #define BACKLIGHT_INV  0
@@ -293,6 +297,7 @@
 //Force I2C portexpander type
 #define PCF8574        1
 #define MCP23008       0
+#define PCA9538        0
 
 //Force Inverted Backlight control
 #define BACKLIGHT_INV  1
@@ -335,6 +340,7 @@
 //Force I2C portexpander type
 #define PCF8574        1
 #define MCP23008       0
+#define PCA9538        0
 
 //Force Inverted Backlight control
 #define BACKLIGHT_INV  0
@@ -376,8 +382,9 @@
 #define LCD_BUS_SPI_E2 LCD_BUS_I2C_E2
 
 //Force I2C portexpander type
-#define PCF8574        0
-#define MCP23008       1
+#define PCF8574        1
+#define MCP23008       0
+#define PCA9538        0
 
 //Inverted Backlight control
 #define BACKLIGHT_INV  0
@@ -419,8 +426,9 @@
 #define LCD_BUS_SPI_RW LCD_BUS_I2C_RW
 
 //Force I2C portexpander type
-#define PCF8574        0
-#define MCP23008       1
+#define PCF8574        1
+#define MCP23008       0
+#define PCA9538        0
 
 //Inverted Backlight control
 #define BACKLIGHT_INV  0
@@ -486,6 +494,18 @@
 #define GPIO           0x09
 #define OLAT           0x0A
 
+/* PCA9538 I2C portexpander slave address */
+#define PCA9538_SA0   0xE0
+#define PCA9538_SA1   0xE2
+#define PCA9538_SA2   0xE4
+#define PCA9538_SA3   0xE6
+
+/* PCA9538 I2C portexpander internal registers */
+#define PCA_INPUT      0x00
+#define PCA_OUTPUT     0x01
+#define PCA_POLARITY   0x02
+#define PCA_CONFIG     0x03
+
 /* ST7032i I2C slave address */
 #define ST7032_SA      0x7C