for

Dependents:   LV_FGSE_Controller_Interface

Committer:
wim
Date:
Fri Aug 22 19:50:49 2014 +0000
Revision:
32:59c4b8f648d4
Parent:
31:ef31cd8a00d1
Child:
33:900a94bc7585
Added support for controllers PCF2119 (native I2C) and SSD1803A, ST7036 (native I2C/SPI), added setContrast method (by JH1PJL) and setPower method for supported devices (eg ST7032i). Cleaned up Init method.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 1:ac48b187213c 1 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780
simon 6:e4cb7ddee0d3 2 * Copyright (c) 2007-2010, sford, http://mbed.org
wim 13:24506ba22480 3 * 2013, v01: WH, Added LCD types, fixed LCD address issues, added Cursor and UDCs
wim 15:b70ebfffb258 4 * 2013, v02: WH, Added I2C and SPI bus interfaces
wim 15:b70ebfffb258 5 * 2013, v03: WH, Added support for LCD40x4 which uses 2 controllers
wim 17:652ab113bc2e 6 * 2013, v04: WH, Added support for Display On/Off, improved 4bit bootprocess
wim 18:bd65dc10f27f 7 * 2013, v05: WH, Added support for 8x2B, added some UDCs
wim 19:c747b9e2e7b8 8 * 2013, v06: WH, Added support for devices that use internal DC/DC converters
wim 20:e0da005a777f 9 * 2013, v07: WH, Added support for backlight and include portdefinitions for LCD2004 Module from DFROBOT
wim 21:9eb628d9e164 10 * 2014, v08: WH, Refactored in Base and Derived Classes to deal with mbed lib change regarding 'NC' defined DigitalOut pins
wim 25:6162b31128c9 11 * 2014, v09: WH/EO, Added Class for Native SPI controllers such as ST7032
wim 26:bd897a001012 12 * 2014, v10: WH, Added Class for Native I2C controllers such as ST7032i, Added support for MCP23008 I2C portexpander, Added support for Adafruit module
wim 30:033048611c01 13 * 2014, v11: WH, Added support for native I2C controllers such as PCF21XX, Improved the _initCtrl() method to deal with differences between all supported controllers
wim 32:59c4b8f648d4 14 * 2014, v12: WH, Added support for native I2C controller PCF2119 and native I2C/SPI controllers SSD1803, ST7036, added setContrast method (by JH1PJL) for supported devices (eg ST7032i)
simon 1:ac48b187213c 15 *
simon 1:ac48b187213c 16 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 1:ac48b187213c 17 * of this software and associated documentation files (the "Software"), to deal
simon 1:ac48b187213c 18 * in the Software without restriction, including without limitation the rights
simon 1:ac48b187213c 19 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 1:ac48b187213c 20 * copies of the Software, and to permit persons to whom the Software is
simon 1:ac48b187213c 21 * furnished to do so, subject to the following conditions:
simon 2:227356c7d12c 22 *
simon 1:ac48b187213c 23 * The above copyright notice and this permission notice shall be included in
simon 1:ac48b187213c 24 * all copies or substantial portions of the Software.
simon 2:227356c7d12c 25 *
simon 1:ac48b187213c 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 1:ac48b187213c 27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 1:ac48b187213c 28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 1:ac48b187213c 29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 1:ac48b187213c 30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 1:ac48b187213c 31 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 1:ac48b187213c 32 * THE SOFTWARE.
simon 1:ac48b187213c 33 */
simon 1:ac48b187213c 34
simon 1:ac48b187213c 35 #ifndef MBED_TEXTLCD_H
simon 1:ac48b187213c 36 #define MBED_TEXTLCD_H
simon 1:ac48b187213c 37
simon 1:ac48b187213c 38 #include "mbed.h"
simon 2:227356c7d12c 39
simon 5:a53b3e2d6f1e 40 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
simon 2:227356c7d12c 41 *
wim 32:59c4b8f648d4 42 * Currently supports 8x1, 8x2, 12x3, 12x4, 16x1, 16x2, 16x3, 16x4, 20x2, 20x4, 24x1, 24x2, 24x4, 40x2 and 40x4 panels
wim 27:22d5086f6ba6 43 * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595).
wim 27:22d5086f6ba6 44 * Supports some controllers with native I2C or SP interface. Supports some controllers that provide internal DC/DC converters for VLCD or VLED.
simon 2:227356c7d12c 45 *
simon 2:227356c7d12c 46 * @code
simon 2:227356c7d12c 47 * #include "mbed.h"
simon 2:227356c7d12c 48 * #include "TextLCD.h"
simon 5:a53b3e2d6f1e 49 *
wim 16:c276b75e6585 50 * // I2C Communication
wim 16:c276b75e6585 51 * I2C i2c_lcd(p28,p27); // SDA, SCL
wim 16:c276b75e6585 52 *
wim 16:c276b75e6585 53 * // SPI Communication
wim 16:c276b75e6585 54 * SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK
wim 16:c276b75e6585 55 *
wim 22:35742ec80c24 56 * //TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=HD44780
wim 28:30fa94f7341c 57 * //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, 74595 expander, CS pin, LCD Type
wim 22:35742ec80c24 58 * TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type
wim 21:9eb628d9e164 59 * //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type
wim 27:22d5086f6ba6 60 * //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3
wim 28:30fa94f7341c 61 * //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=ST7032_3V3
simon 5:a53b3e2d6f1e 62 *
simon 2:227356c7d12c 63 * int main() {
wim 16:c276b75e6585 64 * lcd.printf("Hello World!\n");
simon 2:227356c7d12c 65 * }
simon 2:227356c7d12c 66 * @endcode
simon 2:227356c7d12c 67 */
wim 8:03116f75b66e 68
wim 26:bd897a001012 69
wim 26:bd897a001012 70 //Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces
wim 13:24506ba22480 71 //LCD and serial portexpanders should be wired accordingly
wim 20:e0da005a777f 72 //
wim 26:bd897a001012 73 //Select Hardware module (one option only)
wim 31:ef31cd8a00d1 74 #define DEFAULT 1
wim 31:ef31cd8a00d1 75 #define ADAFRUIT 0
wim 26:bd897a001012 76 #define DFROBOT 0
wim 26:bd897a001012 77
wim 26:bd897a001012 78 #if (DEFAULT==1)
wim 29:a3663151aa65 79 //Definitions for default (WH) mapping between serial port expander pins and LCD controller
wim 26:bd897a001012 80 //This hardware supports the I2C bus expander (PCF8574/PCF8574A or MCP23008) and SPI bus expander (74595) interfaces
wim 29:a3663151aa65 81 //See https://mbed.org/cookbook/Text-LCD-Enhanced
wim 26:bd897a001012 82 //
wim 13:24506ba22480 83 //Note: LCD RW pin must be connected to GND
wim 15:b70ebfffb258 84 // E2 is used for LCD40x4 (second controller)
wim 26:bd897a001012 85 // BL may be used to control backlight
wim 15:b70ebfffb258 86 #define D_LCD_PIN_D4 0
wim 15:b70ebfffb258 87 #define D_LCD_PIN_D5 1
wim 15:b70ebfffb258 88 #define D_LCD_PIN_D6 2
wim 15:b70ebfffb258 89 #define D_LCD_PIN_D7 3
wim 15:b70ebfffb258 90 #define D_LCD_PIN_RS 4
wim 15:b70ebfffb258 91 #define D_LCD_PIN_E 5
wim 15:b70ebfffb258 92 #define D_LCD_PIN_E2 6
wim 15:b70ebfffb258 93 #define D_LCD_PIN_BL 7
wim 13:24506ba22480 94
wim 20:e0da005a777f 95 #define D_LCD_PIN_RW D_LCD_PIN_E2
wim 20:e0da005a777f 96
wim 26:bd897a001012 97 //Select I2C Portexpander type (one option only)
wim 26:bd897a001012 98 #define PCF8574 1
wim 26:bd897a001012 99 #define MCP23008 0
wim 26:bd897a001012 100 #endif
wim 20:e0da005a777f 101
wim 26:bd897a001012 102 #if (ADAFRUIT==1)
wim 29:a3663151aa65 103 //Definitions for Adafruit i2cspilcdbackpack mapping between serial port expander pins and LCD controller
wim 26:bd897a001012 104 //This hardware supports both an I2C expander (MCP23008) and an SPI expander (74595) selectable by a jumper.
wim 29:a3663151aa65 105 //See http://www.ladyada.net/products/i2cspilcdbackpack
wim 26:bd897a001012 106 //
wim 26:bd897a001012 107 //Note: LCD RW pin must be kept LOW
wim 26:bd897a001012 108 // E2 is not available on this hardware and so it does not support LCD40x4 (second controller)
wim 26:bd897a001012 109 // BL is used to control backlight
wim 26:bd897a001012 110 #define D_LCD_PIN_0 0
wim 26:bd897a001012 111 #define D_LCD_PIN_RS 1
wim 26:bd897a001012 112 #define D_LCD_PIN_E 2
wim 26:bd897a001012 113 #define D_LCD_PIN_D4 3
wim 26:bd897a001012 114 #define D_LCD_PIN_D5 4
wim 26:bd897a001012 115 #define D_LCD_PIN_D6 5
wim 26:bd897a001012 116 #define D_LCD_PIN_D7 6
wim 26:bd897a001012 117 #define D_LCD_PIN_BL 7
wim 26:bd897a001012 118
wim 26:bd897a001012 119 #define D_LCD_PIN_E2 D_LCD_PIN_0
wim 26:bd897a001012 120
wim 26:bd897a001012 121 //Force I2C portexpander type
wim 26:bd897a001012 122 #define PCF8574 0
wim 26:bd897a001012 123 #define MCP23008 1
wim 26:bd897a001012 124 #endif
wim 26:bd897a001012 125
wim 26:bd897a001012 126 #if (DFROBOT==1)
wim 29:a3663151aa65 127 //Definitions for DFROBOT LCD2004 Module mapping between serial port expander pins and LCD controller
wim 26:bd897a001012 128 //This hardware uses PCF8574 and is different from earlier/different Arduino I2C LCD displays
wim 29:a3663151aa65 129 //See http://arduino-info.wikispaces.com/LCD-Blue-I2C
wim 26:bd897a001012 130 //
wim 20:e0da005a777f 131 //Note: LCD RW pin must be kept LOW
wim 26:bd897a001012 132 // E2 is not available on default Arduino hardware and so it does not support LCD40x4 (second controller)
wim 20:e0da005a777f 133 // BL is used to control backlight
wim 20:e0da005a777f 134 #define D_LCD_PIN_RS 0
wim 20:e0da005a777f 135 #define D_LCD_PIN_RW 1
wim 20:e0da005a777f 136 #define D_LCD_PIN_E 2
wim 20:e0da005a777f 137 #define D_LCD_PIN_BL 3
wim 20:e0da005a777f 138 #define D_LCD_PIN_D4 4
wim 20:e0da005a777f 139 #define D_LCD_PIN_D5 5
wim 20:e0da005a777f 140 #define D_LCD_PIN_D6 6
wim 20:e0da005a777f 141 #define D_LCD_PIN_D7 7
wim 20:e0da005a777f 142
wim 20:e0da005a777f 143 #define D_LCD_PIN_E2 D_LCD_PIN_RW
wim 26:bd897a001012 144
wim 26:bd897a001012 145 //Force I2C portexpander type
wim 26:bd897a001012 146 #define PCF8574 1
wim 26:bd897a001012 147 #define MCP23008 0
wim 20:e0da005a777f 148 #endif
wim 13:24506ba22480 149
wim 26:bd897a001012 150 //Bitpattern Defines for I2C PCF8574/PCF8574A, MCP23008 and SPI 74595 Bus expanders
wim 13:24506ba22480 151 //
wim 13:24506ba22480 152 #define D_LCD_D4 (1<<D_LCD_PIN_D4)
wim 13:24506ba22480 153 #define D_LCD_D5 (1<<D_LCD_PIN_D5)
wim 13:24506ba22480 154 #define D_LCD_D6 (1<<D_LCD_PIN_D6)
wim 13:24506ba22480 155 #define D_LCD_D7 (1<<D_LCD_PIN_D7)
wim 13:24506ba22480 156 #define D_LCD_RS (1<<D_LCD_PIN_RS)
wim 13:24506ba22480 157 #define D_LCD_E (1<<D_LCD_PIN_E)
wim 13:24506ba22480 158 #define D_LCD_E2 (1<<D_LCD_PIN_E2)
wim 13:24506ba22480 159 #define D_LCD_BL (1<<D_LCD_PIN_BL)
wim 20:e0da005a777f 160 //#define D_LCD_RW (1<<D_LCD_PIN_RW)
wim 20:e0da005a777f 161
wim 20:e0da005a777f 162 #define D_LCD_BUS_MSK (D_LCD_D4 | D_LCD_D5 | D_LCD_D6 | D_LCD_D7)
wim 20:e0da005a777f 163 #define D_LCD_BUS_DEF 0x00
wim 13:24506ba22480 164
wim 26:bd897a001012 165 /* PCF8574/PCF8574A I2C portexpander slave address */
wim 30:033048611c01 166 #define PCF8574_SA0 0x40
wim 30:033048611c01 167 #define PCF8574_SA1 0x42
wim 30:033048611c01 168 #define PCF8574_SA2 0x44
wim 30:033048611c01 169 #define PCF8574_SA3 0x46
wim 30:033048611c01 170 #define PCF8574_SA4 0x48
wim 30:033048611c01 171 #define PCF8574_SA5 0x4A
wim 30:033048611c01 172 #define PCF8574_SA6 0x4C
wim 30:033048611c01 173 #define PCF8574_SA7 0x4E
wim 26:bd897a001012 174
wim 30:033048611c01 175 #define PCF8574A_SA0 0x70
wim 30:033048611c01 176 #define PCF8574A_SA1 0x72
wim 30:033048611c01 177 #define PCF8574A_SA2 0x74
wim 30:033048611c01 178 #define PCF8574A_SA3 0x76
wim 30:033048611c01 179 #define PCF8574A_SA4 0x78
wim 30:033048611c01 180 #define PCF8574A_SA5 0x7A
wim 30:033048611c01 181 #define PCF8574A_SA6 0x7C
wim 30:033048611c01 182 #define PCF8574A_SA7 0x7E
wim 26:bd897a001012 183
wim 26:bd897a001012 184 /* MCP23008 I2C portexpander slave address */
wim 30:033048611c01 185 #define MCP23008_SA0 0x40
wim 30:033048611c01 186 #define MCP23008_SA1 0x42
wim 30:033048611c01 187 #define MCP23008_SA2 0x44
wim 30:033048611c01 188 #define MCP23008_SA3 0x46
wim 30:033048611c01 189 #define MCP23008_SA4 0x48
wim 30:033048611c01 190 #define MCP23008_SA5 0x4A
wim 30:033048611c01 191 #define MCP23008_SA6 0x4C
wim 30:033048611c01 192 #define MCP23008_SA7 0x4E
wim 26:bd897a001012 193
wim 26:bd897a001012 194 /* MCP23008 I2C portexpander internal registers */
wim 30:033048611c01 195 #define IODIR 0x00
wim 30:033048611c01 196 #define IPOL 0x01
wim 30:033048611c01 197 #define GPINTEN 0x02
wim 30:033048611c01 198 #define DEFVAL 0x03
wim 30:033048611c01 199 #define INTCON 0x04
wim 30:033048611c01 200 #define IOCON 0x05
wim 30:033048611c01 201 #define GPPU 0x06
wim 30:033048611c01 202 #define INTF 0x07
wim 30:033048611c01 203 #define INTCAP 0x08
wim 30:033048611c01 204 #define GPIO 0x09
wim 30:033048611c01 205 #define OLAT 0x0A
wim 26:bd897a001012 206
wim 26:bd897a001012 207
wim 32:59c4b8f648d4 208 /* ST7032i I2C slave address */
wim 30:033048611c01 209 #define ST7032_SA 0x7C
wim 26:bd897a001012 210
wim 32:59c4b8f648d4 211 /* ST7036i I2C slave address */
wim 32:59c4b8f648d4 212 #define ST7036_SA0 0x78
wim 32:59c4b8f648d4 213 #define ST7036_SA1 0x7A
wim 32:59c4b8f648d4 214 #define ST7036_SA2 0x7C
wim 32:59c4b8f648d4 215 #define ST7036_SA3 0x7E
wim 32:59c4b8f648d4 216
wim 29:a3663151aa65 217 /* PCF21XX I2C slave address */
wim 30:033048611c01 218 #define PCF21XX_SA0 0x74
wim 30:033048611c01 219 #define PCF21XX_SA1 0x76
wim 30:033048611c01 220
wim 30:033048611c01 221 /* AIP31068 I2C slave address */
wim 30:033048611c01 222 #define AIP31068_SA 0x7C
wim 30:033048611c01 223
wim 32:59c4b8f648d4 224 /* SSD1803 I2C slave address */
wim 32:59c4b8f648d4 225 #define SSD1803_SA0 0x78
wim 32:59c4b8f648d4 226 #define SSD1803_SA1 0x7A
wim 32:59c4b8f648d4 227
wim 32:59c4b8f648d4 228 /* US2066 I2C slave address */
wim 32:59c4b8f648d4 229 #define US2066_SA0 0x78
wim 32:59c4b8f648d4 230 #define US2066_SA1 0x7A
wim 32:59c4b8f648d4 231
wim 32:59c4b8f648d4 232
wim 32:59c4b8f648d4 233 //Some native I2C controllers dont support ACK. Set define to '0' to allow code to proceed even without ACK
wim 32:59c4b8f648d4 234 //#define LCD_I2C_ACK 0
wim 32:59c4b8f648d4 235 #define LCD_I2C_ACK 1
wim 32:59c4b8f648d4 236
wim 30:033048611c01 237 /* LCD Type information on Rows, Columns and Variant. This information is encoded in
wim 30:033048611c01 238 * an int and used for the LCDType enumerators in order to simplify code maintenance */
wim 30:033048611c01 239 // Columns encoded in b7..b0
wim 30:033048611c01 240 #define LCD_T_COL_MSK 0x000000FF
wim 32:59c4b8f648d4 241 #define LCD_T_C6 0x00000006
wim 30:033048611c01 242 #define LCD_T_C8 0x00000008
wim 30:033048611c01 243 #define LCD_T_C10 0x0000000A
wim 30:033048611c01 244 #define LCD_T_C12 0x0000000C
wim 30:033048611c01 245 #define LCD_T_C16 0x00000010
wim 30:033048611c01 246 #define LCD_T_C20 0x00000014
wim 30:033048611c01 247 #define LCD_T_C24 0x00000018
wim 30:033048611c01 248 #define LCD_T_C32 0x00000020
wim 30:033048611c01 249 #define LCD_T_C40 0x00000028
wim 30:033048611c01 250
wim 30:033048611c01 251 // Rows encoded in b15..b8
wim 30:033048611c01 252 #define LCD_T_ROW_MSK 0x0000FF00
wim 30:033048611c01 253 #define LCD_T_R1 0x00000100
wim 30:033048611c01 254 #define LCD_T_R2 0x00000200
wim 30:033048611c01 255 #define LCD_T_R3 0x00000300
wim 30:033048611c01 256 #define LCD_T_R4 0x00000400
wim 30:033048611c01 257
wim 30:033048611c01 258 // Addressing mode encoded in b19..b16
wim 30:033048611c01 259 #define LCD_T_ADR_MSK 0x000F0000
wim 32:59c4b8f648d4 260 #define LCD_T_A 0x00000000 /*Mode A Default 1, 2 or 4 line display */
wim 32:59c4b8f648d4 261 #define LCD_T_B 0x00010000 /*Mode B, Alternate 8x2 (actually 16x1 display) */
wim 32:59c4b8f648d4 262 #define LCD_T_C 0x00020000 /*Mode C, Alternate 16x1 (actually 8x2 display) */
wim 32:59c4b8f648d4 263 #define LCD_T_D 0x00030000 /*Mode D, Alternate 3 or 4 line display (12x4, 20x4, 24x4) */
wim 32:59c4b8f648d4 264 #define LCD_T_D1 0x00040000 /*Mode D1, Alternate 3 out of 4 line display (12x3, 20x3, 24x3) */
wim 32:59c4b8f648d4 265 #define LCD_T_E 0x00050000 /*Mode E, 40x4 display (actually two 40x2) */
wim 32:59c4b8f648d4 266 #define LCD_T_F 0x00060000 /*Mode F, 16x3 display (actually 24x2) */
wim 32:59c4b8f648d4 267 #define LCD_T_G 0x00070000 /*Mode G, 16x3 display */
wim 30:033048611c01 268
wim 30:033048611c01 269 /* LCD Ctrl information on interface support and features. This information is encoded in
wim 30:033048611c01 270 * an int and used for the LCDCtrl enumerators in order to simplify code maintenance */
wim 30:033048611c01 271 // Interface encoded in b31..b24
wim 30:033048611c01 272 #define LCD_C_BUS_MSK 0xFF000000
wim 32:59c4b8f648d4 273 #define LCD_C_PAR 0x01000000 /*Parallel 4 or 8 bit data, E pin, RS pin, RW=GND */
wim 30:033048611c01 274 #define LCD_C_SPI3_9 0x02000000 /*SPI 3 line (MOSI, SCL, CS pins), 9 bits (RS + 8 Data) */
wim 30:033048611c01 275 #define LCD_C_SPI3_10 0x04000000 /*SPI 3 line (MOSI, SCL, CS pins), 10 bits (RS, RW + 8 Data) */
wim 32:59c4b8f648d4 276 #define LCD_C_SPI3_16 0x08000000 /*SPI 3 line (MOSI, SCL, CS pins), 16 bits (RS, RW + 8 Data) */
wim 32:59c4b8f648d4 277 #define LCD_C_SPI3_24 0x10000000 /*SPI 3 line (MOSI, SCL, CS pins), 24 bits (RS, RW + 8 Data) */
wim 32:59c4b8f648d4 278 #define LCD_C_SPI4 0x20000000 /*SPI 4 line (MOSI, SCL, CS, RS pin), RS pin + 8 Data */
wim 32:59c4b8f648d4 279 #define LCD_C_I2C 0x40000000 /*I2C (SDA, SCL pin), 8 control bits (Co, RS, RW) + 8 Data */
wim 30:033048611c01 280 // Features encoded in b23..b16
wim 30:033048611c01 281 #define LCD_C_FTR_MSK 0x00FF0000
wim 30:033048611c01 282 #define LCD_C_BST 0x00010000 /*Booster */
wim 32:59c4b8f648d4 283 #define LCD_C_CTR 0x00020000 /*Contrast Control */
wim 32:59c4b8f648d4 284 #define LCD_C_ICN 0x00040000 /*Icons */
wim 32:59c4b8f648d4 285 #define LCD_C_PDN 0x00080000 /*Power Down */
wim 32:59c4b8f648d4 286
wim 32:59c4b8f648d4 287
wim 32:59c4b8f648d4 288 // Contrast setting, 5 significant bits (only supported for controllers with extended features)
wim 32:59c4b8f648d4 289 // Voltage Multiplier setting, 2 or 3 significant bits (only supported for controllers with extended features)
wim 32:59c4b8f648d4 290 #define LCD_DEF_CONTRAST 0x20
wim 32:59c4b8f648d4 291
wim 32:59c4b8f648d4 292 //ST7032 EastRising display
wim 32:59c4b8f648d4 293 //ST7036 EA DOGM163 display
wim 32:59c4b8f648d4 294 //Contrast setting 5 significant bits
wim 32:59c4b8f648d4 295 //Voltage Multiplier setting 3 significant bits
wim 32:59c4b8f648d4 296 #define LCD_ST7032_CONTRAST 0x18
wim 32:59c4b8f648d4 297 #define LCD_ST7032_RAB 0x04
wim 32:59c4b8f648d4 298
wim 32:59c4b8f648d4 299 #define LCD_ST7036_CONTRAST 0x28
wim 32:59c4b8f648d4 300 #define LCD_ST7036_RAB 0x04
wim 32:59c4b8f648d4 301
wim 32:59c4b8f648d4 302
wim 32:59c4b8f648d4 303 //SSD1803 EA DOGM204 display
wim 32:59c4b8f648d4 304 //Contrast setting 5 significant bits
wim 32:59c4b8f648d4 305 //Voltage Multiplier setting 3 significant bits
wim 32:59c4b8f648d4 306 #define LCD_SSD1_CONTRAST 0x28
wim 32:59c4b8f648d4 307 #define LCD_SSD1_RAB 0x06
wim 32:59c4b8f648d4 308
wim 32:59c4b8f648d4 309
wim 32:59c4b8f648d4 310 //PCF2113, PCF2119 display
wim 32:59c4b8f648d4 311 //Contrast setting 5 significant bits
wim 32:59c4b8f648d4 312 //Voltage Multiplier setting 2 significant bits
wim 32:59c4b8f648d4 313 #define LCD_PCF2_CONTRAST 0x20
wim 32:59c4b8f648d4 314 #define LCD_PCF2_S12 0x02
wim 32:59c4b8f648d4 315
wim 32:59c4b8f648d4 316 //PT6314 VFD display
wim 32:59c4b8f648d4 317 //Contrast setting 2 significant bits
wim 32:59c4b8f648d4 318 #define LCD_PT63_CONTRAST 0x00
wim 13:24506ba22480 319
wim 13:24506ba22480 320 /** Some sample User Defined Chars 5x7 dots */
wim 32:59c4b8f648d4 321 //extern const char udc_ae[]; //æ
wim 32:59c4b8f648d4 322 //extern const char udc_0e[]; //ø
wim 32:59c4b8f648d4 323 //extern const char udc_ao[]; //å
wim 32:59c4b8f648d4 324 //extern const char udc_AE[]; //Æ
wim 32:59c4b8f648d4 325 //extern const char udc_0E[]; //Ø
wim 32:59c4b8f648d4 326 //extern const char udc_Ao[]; //Å
wim 32:59c4b8f648d4 327 //extern const char udc_PO[]; //Padlock Open
wim 32:59c4b8f648d4 328 //extern const char udc_PC[]; //Padlock Closed
wim 32:59c4b8f648d4 329
wim 32:59c4b8f648d4 330 //extern const char udc_alpha[]; //alpha
wim 32:59c4b8f648d4 331 //extern const char udc_ohm[]; //ohm
wim 32:59c4b8f648d4 332 //extern const char udc_sigma[]; //sigma
wim 32:59c4b8f648d4 333 //extern const char udc_pi[]; //pi
wim 32:59c4b8f648d4 334 //extern const char udc_root[]; //root
wim 32:59c4b8f648d4 335
wim 11:9ec02df863a1 336
wim 30:033048611c01 337 extern const char udc_0[]; // |>
wim 30:033048611c01 338 extern const char udc_1[]; // <|
wim 30:033048611c01 339 extern const char udc_2[]; // |
wim 30:033048611c01 340 extern const char udc_3[]; // ||
wim 30:033048611c01 341 extern const char udc_4[]; // |||
wim 30:033048611c01 342 extern const char udc_5[]; // =
wim 30:033048611c01 343 extern const char udc_6[]; // checkerboard
wim 30:033048611c01 344 extern const char udc_7[]; // \
wim 11:9ec02df863a1 345
wim 30:033048611c01 346 extern const char udc_degr[]; // Degree symbol
wim 13:24506ba22480 347
wim 30:033048611c01 348 extern const char udc_TM_T[]; // Trademark T
wim 30:033048611c01 349 extern const char udc_TM_M[]; // Trademark M
wim 13:24506ba22480 350
wim 30:033048611c01 351 //extern const char udc_Bat_Hi[]; // Battery Full
wim 30:033048611c01 352 //extern const char udc_Bat_Ha[]; // Battery Half
wim 30:033048611c01 353 //extern const char udc_Bat_Lo[]; // Battery Low
wim 30:033048611c01 354 extern const char udc_Bat_Hi[]; // Battery Full
wim 30:033048611c01 355 extern const char udc_Bat_Ha[]; // Battery Half
wim 30:033048611c01 356 extern const char udc_Bat_Lo[]; // Battery Low
wim 30:033048611c01 357 extern const char udc_AC[]; // AC Power
wim 13:24506ba22480 358
wim 30:033048611c01 359 //extern const char udc_smiley[]; // Smiley
wim 30:033048611c01 360 //extern const char udc_droopy[]; // Droopey
wim 30:033048611c01 361 //extern const char udc_note[]; // Note
wim 18:bd65dc10f27f 362
wim 30:033048611c01 363 //extern const char udc_bar_1[]; // Bar 1
wim 30:033048611c01 364 //extern const char udc_bar_2[]; // Bar 11
wim 30:033048611c01 365 //extern const char udc_bar_3[]; // Bar 111
wim 30:033048611c01 366 //extern const char udc_bar_4[]; // Bar 1111
wim 30:033048611c01 367 //extern const char udc_bar_5[]; // Bar 11111
wim 13:24506ba22480 368
wim 30:033048611c01 369 //extern const char udc_ch_1[]; // Hor bars 4
wim 30:033048611c01 370 //extern const char udc_ch_2[]; // Hor bars 4 (inverted)
wim 30:033048611c01 371 //extern const char udc_ch_3[]; // Ver bars 3
wim 30:033048611c01 372 //extern const char udc_ch_4[]; // Ver bars 3 (inverted)
wim 30:033048611c01 373 //extern const char udc_ch_yr[]; // Year (kana)
wim 30:033048611c01 374 //extern const char udc_ch_mo[]; // Month (kana)
wim 30:033048611c01 375 //extern const char udc_ch_dy[]; // Day (kana)
wim 30:033048611c01 376 //extern const char udc_ch_mi[]; // minute (kana)
wim 32:59c4b8f648d4 377 extern const char udc_None[];
wim 32:59c4b8f648d4 378 extern const char udc_All[];
wim 11:9ec02df863a1 379
wim 11:9ec02df863a1 380 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
wim 11:9ec02df863a1 381 *
wim 22:35742ec80c24 382 * @brief Currently supports 8x1, 8x2, 12x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
wim 27:22d5086f6ba6 383 * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595) and some native I2C or SPI devices
wim 11:9ec02df863a1 384 *
wim 11:9ec02df863a1 385 */
wim 21:9eb628d9e164 386 class TextLCD_Base : public Stream {
simon 1:ac48b187213c 387 public:
simon 1:ac48b187213c 388
simon 2:227356c7d12c 389 /** LCD panel format */
simon 1:ac48b187213c 390 enum LCDType {
wim 32:59c4b8f648d4 391 // LCD6x1 = (LCD_T_A | LCD_T_C6 | LCD_T_R1), /**< 6x1 LCD panel */
wim 32:59c4b8f648d4 392 // LCD6x2 = (LCD_T_A | LCD_T_C6 | LCD_T_R2), /**< 6x2 LCD panel */
wim 30:033048611c01 393 LCD8x1 = (LCD_T_A | LCD_T_C8 | LCD_T_R1), /**< 8x1 LCD panel */
wim 30:033048611c01 394 LCD8x2 = (LCD_T_A | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel */
wim 30:033048611c01 395 LCD8x2B = (LCD_T_D | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel (actually 16x1) */
wim 30:033048611c01 396 // LCD12x1 = (LCD_T_A | LCD_T_C12 | LCD_T_R1), /**< 12x1 LCD panel */
wim 30:033048611c01 397 LCD12x2 = (LCD_T_A | LCD_T_C12 | LCD_T_R2), /**< 12x2 LCD panel */
wim 30:033048611c01 398 LCD12x3D = (LCD_T_D | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX */
wim 30:033048611c01 399 LCD12x3D1 = (LCD_T_D1 | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX */
wim 32:59c4b8f648d4 400 // LCD12x3G = (LCD_T_G | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode ST7036 */
wim 30:033048611c01 401 LCD12x4 = (LCD_T_A | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel */
wim 30:033048611c01 402 LCD12x4D = (LCD_T_B | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel, special mode PCF21XX */
wim 30:033048611c01 403 LCD16x1 = (LCD_T_A | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel */
wim 30:033048611c01 404 LCD16x1C = (LCD_T_C | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel (actually 8x2) */
wim 30:033048611c01 405 LCD16x2 = (LCD_T_A | LCD_T_C16 | LCD_T_R2), /**< 16x2 LCD panel (default) */
wim 30:033048611c01 406 // LCD16x2B = (LCD_T_B | LCD_T_C16 | LCD_T_R2), /**< 16x2 LCD panel, alternate addressing, wrong.. */
wim 32:59c4b8f648d4 407 LCD16x3D = (LCD_T_D | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */
wim 32:59c4b8f648d4 408 // LCD16x3D1 = (LCD_T_D1 | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */
wim 32:59c4b8f648d4 409 LCD16x3F = (LCD_T_F | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel (actually 24x2) */
wim 32:59c4b8f648d4 410 LCD16x3G = (LCD_T_G | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode ST7036 */
wim 30:033048611c01 411 LCD16x4 = (LCD_T_A | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel */
wim 32:59c4b8f648d4 412 // LCD16x4D = (LCD_T_D | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel, special mode SSD1803 */
wim 30:033048611c01 413 // LCD20x1 = (LCD_T_A | LCD_T_C20 | LCD_T_R1), /**< 20x1 LCD panel */
wim 30:033048611c01 414 LCD20x2 = (LCD_T_A | LCD_T_C20 | LCD_T_R2), /**< 20x2 LCD panel */
wim 32:59c4b8f648d4 415 // LCD20x3 = (LCD_T_A | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel */
wim 32:59c4b8f648d4 416 // LCD20x3D = (LCD_T_D | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803 */
wim 32:59c4b8f648d4 417 // LCD20x3D1 = (LCD_T_D1 | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803 */
wim 30:033048611c01 418 LCD20x4 = (LCD_T_A | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel */
wim 32:59c4b8f648d4 419 LCD20x4D = (LCD_T_D | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel, special mode SSD1803 */
wim 30:033048611c01 420 LCD24x1 = (LCD_T_A | LCD_T_C24 | LCD_T_R1), /**< 24x1 LCD panel */
wim 30:033048611c01 421 LCD24x2 = (LCD_T_A | LCD_T_C24 | LCD_T_R2), /**< 24x2 LCD panel */
wim 32:59c4b8f648d4 422 // LCD24x3D = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */
wim 32:59c4b8f648d4 423 // LCD24x3D1 = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */
wim 30:033048611c01 424 LCD24x4D = (LCD_T_D | LCD_T_C24 | LCD_T_R4), /**< 24x4 LCD panel, special mode KS0078 */
wim 32:59c4b8f648d4 425 // LCD32x1 = (LCD_T_A | LCD_T_C32 | LCD_T_R1), /**< 32x1 LCD panel */
wim 32:59c4b8f648d4 426 // LCD32x2 = (LCD_T_A | LCD_T_C32 | LCD_T_R2), /**< 32x2 LCD panel */
wim 32:59c4b8f648d4 427 // LCD32x4 = (LCD_T_A | LCD_T_C32 | LCD_T_R4), /**< 32x4 LCD panel */
wim 30:033048611c01 428 // LCD40x1 = (LCD_T_A | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel */
wim 30:033048611c01 429 LCD40x2 = (LCD_T_A | LCD_T_C40 | LCD_T_R2), /**< 40x2 LCD panel */
wim 30:033048611c01 430 LCD40x4 = (LCD_T_E | LCD_T_C40 | LCD_T_R4) /**< 40x4 LCD panel, Two controller version */
wim 30:033048611c01 431 };
wim 30:033048611c01 432
wim 30:033048611c01 433
wim 30:033048611c01 434 /** LCD Controller Device */
wim 30:033048611c01 435 enum LCDCtrl {
wim 32:59c4b8f648d4 436 HD44780 = 0 | LCD_C_PAR, /**< HD44780 or full equivalent (default) */
wim 32:59c4b8f648d4 437 WS0010 = 1 | (LCD_C_PAR | LCD_C_SPI3_10 | LCD_C_BST), /**< WS0010 OLED Controller, 4/8 bit, SPI3 */
wim 32:59c4b8f648d4 438 ST7036_3V3 = 2 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7036 3V3 with Booster, 4/8 bit, SPI4, I2C */
wim 32:59c4b8f648d4 439 ST7036_5V = 3 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7036 5V no Booster, 4/8 bit, SPI4, I2C */
wim 32:59c4b8f648d4 440 ST7032_3V3 = 4 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7032 3V3 with Booster, 4/8 bit, SPI4, I2C */
wim 32:59c4b8f648d4 441 ST7032_5V = 5 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_CTR), /**< ST7032 5V no Booster, 4/8 bit, SPI4, I2C */
wim 32:59c4b8f648d4 442 KS0078 = 6 | (LCD_C_PAR | LCD_C_SPI3_24), /**< KS0078 24x4 support, 4/8 bit, SPI3 */
wim 32:59c4b8f648d4 443 PCF2113_3V3 = 7 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2113 3V3 with Booster, 4/8 bit, I2C */
wim 32:59c4b8f648d4 444 PCF2116_3V3 = 8 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST), /**< PCF2116 3V3 with Booster, 4/8 bit, I2C */
wim 32:59c4b8f648d4 445 PCF2116_5V = 9 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2116 5V no Booster, 4/8 bit, I2C */
wim 32:59c4b8f648d4 446 PCF2119_3V3 = 10 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2119 3V3 with Booster, 4/8 bit, I2C */
wim 32:59c4b8f648d4 447 // PCF2119_5V = 11 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2119 5V no Booster, 4/8 bit, I2C */
wim 32:59c4b8f648d4 448 AIP31068 = 12 | (LCD_C_SPI3_9 | LCD_C_I2C | LCD_C_BST), /**< AIP31068 I2C, SPI3 */
wim 32:59c4b8f648d4 449 SSD1803_3V3 = 13 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_PDN) /**< SSD1803 3V3 with Booster, 4/8 bit, I2C, SPI3 */
wim 32:59c4b8f648d4 450 // SSD1803_5V = 14 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_PDN) /**< SSD1803 3V3 with Booster, 4/8 bit, I2C, SPI3 */
wim 32:59c4b8f648d4 451 // US2066_3V3 = 15 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_PDN) /**< US2066 3V3 with Booster, 4/8 bit, I2C, SPI3 */
wim 32:59c4b8f648d4 452 // PT6314 = 16 | (LCD_C_PAR | LCD_C_SPI3_16 | LCD_C_CTR | LCD_C_PDN) /**< PT6314 VFD, 4/8 bit, SPI3 */
wim 30:033048611c01 453 };
wim 30:033048611c01 454
wim 30:033048611c01 455
wim 10:dd9b3a696acd 456 /** LCD Cursor control */
wim 10:dd9b3a696acd 457 enum LCDCursor {
wim 17:652ab113bc2e 458 CurOff_BlkOff = 0x00, /**< Cursor Off, Blinking Char Off */
wim 17:652ab113bc2e 459 CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */
wim 17:652ab113bc2e 460 CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */
wim 17:652ab113bc2e 461 CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */
wim 17:652ab113bc2e 462 };
wim 17:652ab113bc2e 463
wim 17:652ab113bc2e 464 /** LCD Display control */
wim 17:652ab113bc2e 465 enum LCDMode {
wim 17:652ab113bc2e 466 DispOff = 0x00, /**< Display Off */
wim 17:652ab113bc2e 467 DispOn = 0x04 /**< Display On */
wim 10:dd9b3a696acd 468 };
wim 10:dd9b3a696acd 469
wim 20:e0da005a777f 470 /** LCD Backlight control */
wim 20:e0da005a777f 471 enum LCDBacklight {
wim 20:e0da005a777f 472 LightOff, /**< Backlight Off */
wim 20:e0da005a777f 473 LightOn /**< Backlight On */
wim 20:e0da005a777f 474 };
wim 10:dd9b3a696acd 475
simon 2:227356c7d12c 476 #if DOXYGEN_ONLY
simon 2:227356c7d12c 477 /** Write a character to the LCD
simon 2:227356c7d12c 478 *
simon 2:227356c7d12c 479 * @param c The character to write to the display
simon 2:227356c7d12c 480 */
simon 2:227356c7d12c 481 int putc(int c);
simon 2:227356c7d12c 482
simon 2:227356c7d12c 483 /** Write a formated string to the LCD
simon 2:227356c7d12c 484 *
simon 2:227356c7d12c 485 * @param format A printf-style format string, followed by the
simon 2:227356c7d12c 486 * variables to use in formating the string.
simon 2:227356c7d12c 487 */
simon 2:227356c7d12c 488 int printf(const char* format, ...);
simon 2:227356c7d12c 489 #endif
simon 2:227356c7d12c 490
wim 29:a3663151aa65 491 /** Locate cursor to a screen column and row
simon 2:227356c7d12c 492 *
simon 2:227356c7d12c 493 * @param column The horizontal position from the left, indexed from 0
simon 2:227356c7d12c 494 * @param row The vertical position from the top, indexed from 0
simon 2:227356c7d12c 495 */
simon 1:ac48b187213c 496 void locate(int column, int row);
simon 2:227356c7d12c 497
wim 10:dd9b3a696acd 498 /** Return the memoryaddress of screen column and row location
wim 10:dd9b3a696acd 499 *
wim 10:dd9b3a696acd 500 * @param column The horizontal position from the left, indexed from 0
wim 10:dd9b3a696acd 501 * @param row The vertical position from the top, indexed from 0
wim 10:dd9b3a696acd 502 * @param return The memoryaddress of screen column and row location
wim 10:dd9b3a696acd 503 */
wim 30:033048611c01 504 int getAddress(int column, int row);
wim 10:dd9b3a696acd 505
wim 10:dd9b3a696acd 506 /** Set the memoryaddress of screen column and row location
wim 10:dd9b3a696acd 507 *
wim 10:dd9b3a696acd 508 * @param column The horizontal position from the left, indexed from 0
wim 10:dd9b3a696acd 509 * @param row The vertical position from the top, indexed from 0
wim 10:dd9b3a696acd 510 */
wim 9:0893d986e717 511 void setAddress(int column, int row);
wim 9:0893d986e717 512
wim 22:35742ec80c24 513 /** Clear the screen and locate to 0,0
wim 22:35742ec80c24 514 */
simon 1:ac48b187213c 515 void cls();
simon 2:227356c7d12c 516
wim 10:dd9b3a696acd 517 /** Return the number of rows
wim 10:dd9b3a696acd 518 *
wim 10:dd9b3a696acd 519 * @param return The number of rows
wim 10:dd9b3a696acd 520 */
simon 1:ac48b187213c 521 int rows();
wim 10:dd9b3a696acd 522
wim 10:dd9b3a696acd 523 /** Return the number of columns
wim 10:dd9b3a696acd 524 *
wim 10:dd9b3a696acd 525 * @param return The number of columns
wim 10:dd9b3a696acd 526 */
wim 10:dd9b3a696acd 527 int columns();
simon 2:227356c7d12c 528
wim 11:9ec02df863a1 529 /** Set the Cursormode
wim 11:9ec02df863a1 530 *
wim 17:652ab113bc2e 531 * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn)
wim 11:9ec02df863a1 532 */
wim 17:652ab113bc2e 533 void setCursor(LCDCursor cursorMode);
wim 17:652ab113bc2e 534
wim 17:652ab113bc2e 535 /** Set the Displaymode
wim 17:652ab113bc2e 536 *
wim 17:652ab113bc2e 537 * @param displayMode The Display mode (DispOff, DispOn)
wim 17:652ab113bc2e 538 */
wim 21:9eb628d9e164 539 void setMode(LCDMode displayMode);
wim 11:9ec02df863a1 540
wim 20:e0da005a777f 541 /** Set the Backlight mode
wim 20:e0da005a777f 542 *
wim 21:9eb628d9e164 543 * @param backlightMode The Backlight mode (LightOff, LightOn)
wim 20:e0da005a777f 544 */
wim 21:9eb628d9e164 545 void setBacklight(LCDBacklight backlightMode);
wim 20:e0da005a777f 546
wim 11:9ec02df863a1 547 /** Set User Defined Characters
wim 11:9ec02df863a1 548 *
wim 11:9ec02df863a1 549 * @param unsigned char c The Index of the UDC (0..7)
wim 12:6bf9d9957d31 550 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits)
wim 11:9ec02df863a1 551 */
wim 11:9ec02df863a1 552 void setUDC(unsigned char c, char *udc_data);
wim 11:9ec02df863a1 553
wim 32:59c4b8f648d4 554 /** Set Contrast
wim 32:59c4b8f648d4 555 * setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation
wim 32:59c4b8f648d4 556 * Code imported from fork by JH1PJL
wim 32:59c4b8f648d4 557 *
wim 32:59c4b8f648d4 558 * @param unsigned char c contrast data (6 significant bits, valid range 0..63, Value 0 will disable the Vgen)
wim 32:59c4b8f648d4 559 * @return none
wim 32:59c4b8f648d4 560 */
wim 32:59c4b8f648d4 561 void setContrast(unsigned char c = LCD_DEF_CONTRAST);
wim 32:59c4b8f648d4 562
wim 32:59c4b8f648d4 563
wim 32:59c4b8f648d4 564 /** Set Power
wim 32:59c4b8f648d4 565 * setPower method is supported by some compatible devices (eg SSD1803) that have power down modes
wim 32:59c4b8f648d4 566 *
wim 32:59c4b8f648d4 567 * @param bool powerOn Power on/off
wim 32:59c4b8f648d4 568 * @return none
wim 32:59c4b8f648d4 569 */
wim 32:59c4b8f648d4 570 void setPower(bool powerOn = true);
wim 32:59c4b8f648d4 571
wim 32:59c4b8f648d4 572
wim 29:a3663151aa65 573 //test
wim 30:033048611c01 574 // void _initCtrl();
wim 29:a3663151aa65 575
simon 1:ac48b187213c 576 protected:
wim 13:24506ba22480 577
wim 21:9eb628d9e164 578 /** LCD controller select, mainly used for LCD40x4
wim 21:9eb628d9e164 579 */
wim 19:c747b9e2e7b8 580 enum _LCDCtrl_Idx {
wim 15:b70ebfffb258 581 _LCDCtrl_0, /*< Primary */
wim 15:b70ebfffb258 582 _LCDCtrl_1, /*< Secondary */
wim 15:b70ebfffb258 583 };
wim 21:9eb628d9e164 584
wim 21:9eb628d9e164 585 /** Create a TextLCD_Base interface
wim 21:9eb628d9e164 586 * @brief Base class, can not be instantiated
wim 21:9eb628d9e164 587 *
wim 21:9eb628d9e164 588 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 589 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 590 */
wim 21:9eb628d9e164 591 TextLCD_Base(LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 15:b70ebfffb258 592
simon 1:ac48b187213c 593 // Stream implementation functions
simon 1:ac48b187213c 594 virtual int _putc(int value);
simon 1:ac48b187213c 595 virtual int _getc();
simon 1:ac48b187213c 596
wim 29:a3663151aa65 597 /** Low level method for LCD controller
wim 21:9eb628d9e164 598 */
wim 13:24506ba22480 599 void _init();
wim 29:a3663151aa65 600
wim 29:a3663151aa65 601 /** Low level initialisation method for LCD controller
wim 29:a3663151aa65 602 */
wim 30:033048611c01 603 void _initCtrl();
wim 29:a3663151aa65 604
wim 29:a3663151aa65 605 /** Low level character address set method
wim 29:a3663151aa65 606 */
wim 13:24506ba22480 607 int _address(int column, int row);
wim 29:a3663151aa65 608
wim 29:a3663151aa65 609 /** Low level cursor enable or disable method
wim 29:a3663151aa65 610 */
wim 21:9eb628d9e164 611 void _setCursor(LCDCursor show);
wim 29:a3663151aa65 612
wim 29:a3663151aa65 613 /** Low level method to store user defined characters for current controller
wim 29:a3663151aa65 614 */
wim 17:652ab113bc2e 615 void _setUDC(unsigned char c, char *udc_data);
wim 29:a3663151aa65 616
wim 29:a3663151aa65 617 /** Low level method to restore the cursortype and display mode for current controller
wim 29:a3663151aa65 618 */
wim 21:9eb628d9e164 619 void _setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType);
wim 13:24506ba22480 620
wim 29:a3663151aa65 621 /** Low level nibble write operation to LCD controller (serial or parallel)
wim 21:9eb628d9e164 622 */
wim 17:652ab113bc2e 623 void _writeNibble(int value);
wim 29:a3663151aa65 624
wim 29:a3663151aa65 625 /** Low level command byte write operation to LCD controller.
wim 29:a3663151aa65 626 * Methods resets the RS bit and provides the required timing for the command.
wim 29:a3663151aa65 627 */
wim 15:b70ebfffb258 628 void _writeCommand(int command);
wim 29:a3663151aa65 629
wim 29:a3663151aa65 630 /** Low level data byte write operation to LCD controller (serial or parallel).
wim 29:a3663151aa65 631 * Methods sets the RS bit and provides the required timing for the data.
wim 29:a3663151aa65 632 */
wim 15:b70ebfffb258 633 void _writeData(int data);
wim 15:b70ebfffb258 634
wim 29:a3663151aa65 635 /** Pure Virtual Low level writes to LCD Bus (serial or parallel)
wim 29:a3663151aa65 636 * Set the Enable pin.
wim 29:a3663151aa65 637 */
wim 29:a3663151aa65 638 virtual void _setEnable(bool value) = 0;
wim 29:a3663151aa65 639
wim 21:9eb628d9e164 640 /** Pure Virtual Low level writes to LCD Bus (serial or parallel)
wim 29:a3663151aa65 641 * Set the RS pin ( 0 = Command, 1 = Data).
wim 29:a3663151aa65 642 */
wim 21:9eb628d9e164 643 virtual void _setRS(bool value) = 0;
wim 29:a3663151aa65 644
wim 29:a3663151aa65 645 /** Pure Virtual Low level writes to LCD Bus (serial or parallel)
wim 29:a3663151aa65 646 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 647 */
wim 21:9eb628d9e164 648 virtual void _setBL(bool value) = 0;
wim 29:a3663151aa65 649
wim 29:a3663151aa65 650 /** Pure Virtual Low level writes to LCD Bus (serial or parallel)
wim 29:a3663151aa65 651 * Set the databus value (4 bit).
wim 29:a3663151aa65 652 */
wim 21:9eb628d9e164 653 virtual void _setData(int value) = 0;
wim 13:24506ba22480 654
wim 29:a3663151aa65 655 /** Low level byte write operation to LCD controller (serial or parallel)
wim 29:a3663151aa65 656 * Depending on the RS pin this byte will be interpreted as data or command
wim 29:a3663151aa65 657 */
wim 29:a3663151aa65 658 virtual void _writeByte(int value);
wim 13:24506ba22480 659
wim 13:24506ba22480 660 //Display type
simon 1:ac48b187213c 661 LCDType _type;
wim 30:033048611c01 662 int _nr_cols;
wim 30:033048611c01 663 int _nr_rows;
wim 30:033048611c01 664 int _addr_mode;
wim 30:033048611c01 665
wim 21:9eb628d9e164 666 //Display mode
wim 17:652ab113bc2e 667 LCDMode _currentMode;
wim 17:652ab113bc2e 668
wim 19:c747b9e2e7b8 669 //Controller type
wim 19:c747b9e2e7b8 670 LCDCtrl _ctrl;
wim 19:c747b9e2e7b8 671
wim 15:b70ebfffb258 672 //Controller select, mainly used for LCD40x4
wim 19:c747b9e2e7b8 673 _LCDCtrl_Idx _ctrl_idx;
wim 15:b70ebfffb258 674
wim 13:24506ba22480 675 // Cursor
simon 1:ac48b187213c 676 int _column;
simon 1:ac48b187213c 677 int _row;
wim 32:59c4b8f648d4 678 LCDCursor _currentCursor;
wim 32:59c4b8f648d4 679
wim 32:59c4b8f648d4 680 // Function mode saved to allow switch between Instruction sets after initialisation time
wim 32:59c4b8f648d4 681 // Icon, Booster mode and contrast saved to allow contrast change at later time
wim 32:59c4b8f648d4 682 // Only available for controllers with added features
wim 32:59c4b8f648d4 683 int _function, _function_1, _function_x;
wim 32:59c4b8f648d4 684 int _icon_power;
wim 32:59c4b8f648d4 685 int _contrast;
wim 32:59c4b8f648d4 686
simon 1:ac48b187213c 687 };
simon 1:ac48b187213c 688
wim 23:d47f226efb24 689 //--------- End TextLCD_Base -----------
wim 22:35742ec80c24 690
wim 22:35742ec80c24 691
wim 22:35742ec80c24 692
wim 23:d47f226efb24 693 //--------- Start TextLCD Bus -----------
wim 21:9eb628d9e164 694
wim 21:9eb628d9e164 695 /** Create a TextLCD interface for using regular mbed pins
wim 21:9eb628d9e164 696 *
wim 21:9eb628d9e164 697 */
wim 21:9eb628d9e164 698 class TextLCD : public TextLCD_Base {
wim 21:9eb628d9e164 699 public:
wim 21:9eb628d9e164 700 /** Create a TextLCD interface for using regular mbed pins
wim 21:9eb628d9e164 701 *
wim 21:9eb628d9e164 702 * @param rs Instruction/data control line
wim 21:9eb628d9e164 703 * @param e Enable line (clock)
wim 21:9eb628d9e164 704 * @param d4-d7 Data lines for using as a 4-bit interface
wim 21:9eb628d9e164 705 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 706 * @param bl Backlight control line (optional, default = NC)
wim 21:9eb628d9e164 707 * @param e2 Enable2 line (clock for second controller, LCD40x4 only)
wim 21:9eb628d9e164 708 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 709 */
wim 21:9eb628d9e164 710 TextLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2, PinName bl = NC, PinName e2 = NC, LCDCtrl ctrl = HD44780);
wim 21:9eb628d9e164 711
wim 22:35742ec80c24 712 /** Destruct a TextLCD interface for using regular mbed pins
wim 22:35742ec80c24 713 *
wim 22:35742ec80c24 714 * @param none
wim 22:35742ec80c24 715 * @return none
wim 22:35742ec80c24 716 */
wim 22:35742ec80c24 717 virtual ~TextLCD();
wim 22:35742ec80c24 718
wim 21:9eb628d9e164 719 private:
wim 29:a3663151aa65 720
wim 29:a3663151aa65 721 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel)
wim 29:a3663151aa65 722 * Set the Enable pin.
wim 29:a3663151aa65 723 */
wim 21:9eb628d9e164 724 virtual void _setEnable(bool value);
wim 29:a3663151aa65 725
wim 29:a3663151aa65 726 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel)
wim 32:59c4b8f648d4 727 * Set the RS pin (0 = Command, 1 = Data).
wim 29:a3663151aa65 728 */
wim 21:9eb628d9e164 729 virtual void _setRS(bool value);
wim 29:a3663151aa65 730
wim 29:a3663151aa65 731 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel)
wim 29:a3663151aa65 732 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 733 */
wim 21:9eb628d9e164 734 virtual void _setBL(bool value);
wim 29:a3663151aa65 735
wim 29:a3663151aa65 736 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel)
wim 29:a3663151aa65 737 * Set the databus value (4 bit).
wim 29:a3663151aa65 738 */
wim 21:9eb628d9e164 739 virtual void _setData(int value);
wim 21:9eb628d9e164 740
wim 29:a3663151aa65 741
wim 22:35742ec80c24 742 /** Regular mbed pins bus
wim 22:35742ec80c24 743 */
wim 22:35742ec80c24 744 DigitalOut _rs, _e;
wim 22:35742ec80c24 745 BusOut _d;
wim 22:35742ec80c24 746
wim 22:35742ec80c24 747 /** Optional Hardware pins for the Backlight and LCD40x4 device
wim 22:35742ec80c24 748 * Default PinName value is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins
wim 22:35742ec80c24 749 */
wim 22:35742ec80c24 750 DigitalOut *_bl, *_e2;
wim 21:9eb628d9e164 751 };
wim 21:9eb628d9e164 752
wim 22:35742ec80c24 753
wim 23:d47f226efb24 754 //----------- End TextLCD ---------------
wim 21:9eb628d9e164 755
wim 21:9eb628d9e164 756
wim 23:d47f226efb24 757 //--------- Start TextLCD_I2C -----------
wim 22:35742ec80c24 758
wim 22:35742ec80c24 759
wim 26:bd897a001012 760 /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander
wim 21:9eb628d9e164 761 *
wim 21:9eb628d9e164 762 */
wim 21:9eb628d9e164 763 class TextLCD_I2C : public TextLCD_Base {
wim 21:9eb628d9e164 764 public:
wim 26:bd897a001012 765 /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander
wim 21:9eb628d9e164 766 *
wim 21:9eb628d9e164 767 * @param i2c I2C Bus
wim 26:bd897a001012 768 * @param deviceAddress I2C slave address (PCF8574 or PCF8574A, default = PCF8574_SA0 = 0x40)
wim 21:9eb628d9e164 769 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 770 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 771 */
wim 26:bd897a001012 772 TextLCD_I2C(I2C *i2c, char deviceAddress = PCF8574_SA0, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 21:9eb628d9e164 773
wim 21:9eb628d9e164 774 private:
wim 29:a3663151aa65 775
wim 29:a3663151aa65 776 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 777 * Set the Enable pin.
wim 29:a3663151aa65 778 */
wim 21:9eb628d9e164 779 virtual void _setEnable(bool value);
wim 29:a3663151aa65 780
wim 29:a3663151aa65 781 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 32:59c4b8f648d4 782 * Set the RS pin (0 = Command, 1 = Data).
wim 29:a3663151aa65 783 */
wim 21:9eb628d9e164 784 virtual void _setRS(bool value);
wim 29:a3663151aa65 785
wim 29:a3663151aa65 786 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 787 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 788 */
wim 21:9eb628d9e164 789 virtual void _setBL(bool value);
wim 29:a3663151aa65 790
wim 29:a3663151aa65 791 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 792 * Set the databus value (4 bit).
wim 29:a3663151aa65 793 */
wim 29:a3663151aa65 794 virtual void _setData(int value);
wim 30:033048611c01 795
wim 29:a3663151aa65 796 /** Write data to MCP23008 I2C portexpander
wim 29:a3663151aa65 797 * @param reg register to write
wim 29:a3663151aa65 798 * @param value data to write
wim 29:a3663151aa65 799 * @return none
wim 29:a3663151aa65 800 *
wim 29:a3663151aa65 801 */
wim 26:bd897a001012 802 void _write_register (int reg, int value);
wim 21:9eb628d9e164 803
wim 21:9eb628d9e164 804 //I2C bus
wim 21:9eb628d9e164 805 I2C *_i2c;
wim 21:9eb628d9e164 806 char _slaveAddress;
wim 21:9eb628d9e164 807
wim 21:9eb628d9e164 808 // Internal bus mirror value for serial bus only
wim 30:033048611c01 809 char _lcd_bus;
wim 21:9eb628d9e164 810 };
wim 21:9eb628d9e164 811
wim 23:d47f226efb24 812 //---------- End TextLCD_I2C ------------
wim 22:35742ec80c24 813
wim 22:35742ec80c24 814
wim 23:d47f226efb24 815 //--------- Start TextLCD_SPI -----------
wim 22:35742ec80c24 816
wim 21:9eb628d9e164 817 /** Create a TextLCD interface using an SPI 74595 portexpander
wim 21:9eb628d9e164 818 *
wim 21:9eb628d9e164 819 */
wim 21:9eb628d9e164 820 class TextLCD_SPI : public TextLCD_Base {
wim 21:9eb628d9e164 821 public:
wim 21:9eb628d9e164 822 /** Create a TextLCD interface using an SPI 74595 portexpander
wim 21:9eb628d9e164 823 *
wim 21:9eb628d9e164 824 * @param spi SPI Bus
wim 21:9eb628d9e164 825 * @param cs chip select pin (active low)
wim 21:9eb628d9e164 826 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 827 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 828 */
wim 21:9eb628d9e164 829 TextLCD_SPI(SPI *spi, PinName cs, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 21:9eb628d9e164 830
wim 21:9eb628d9e164 831 private:
wim 29:a3663151aa65 832
wim 29:a3663151aa65 833 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 834 * Set the Enable pin.
wim 29:a3663151aa65 835 */
wim 21:9eb628d9e164 836 virtual void _setEnable(bool value);
wim 29:a3663151aa65 837
wim 29:a3663151aa65 838 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 32:59c4b8f648d4 839 * Set the RS pin (0 = Command, 1 = Data).
wim 29:a3663151aa65 840 */
wim 21:9eb628d9e164 841 virtual void _setRS(bool value);
wim 29:a3663151aa65 842
wim 29:a3663151aa65 843 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 844 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 845 */
wim 21:9eb628d9e164 846 virtual void _setBL(bool value);
wim 29:a3663151aa65 847
wim 29:a3663151aa65 848 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 849 * Set the databus value (4 bit).
wim 29:a3663151aa65 850 */
wim 21:9eb628d9e164 851 virtual void _setData(int value);
wim 29:a3663151aa65 852
wim 29:a3663151aa65 853 /** Implementation of Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 854 * Set the CS pin (0 = select, 1 = deselect).
wim 29:a3663151aa65 855 */
wim 21:9eb628d9e164 856 virtual void _setCS(bool value);
wim 21:9eb628d9e164 857
wim 29:a3663151aa65 858 ///** Low level writes to LCD serial bus only (serial expander)
wim 29:a3663151aa65 859 // */
wim 29:a3663151aa65 860 // void _writeBus();
wim 21:9eb628d9e164 861
wim 21:9eb628d9e164 862 // SPI bus
wim 21:9eb628d9e164 863 SPI *_spi;
wim 21:9eb628d9e164 864 DigitalOut _cs;
wim 21:9eb628d9e164 865
wim 21:9eb628d9e164 866 // Internal bus mirror value for serial bus only
wim 21:9eb628d9e164 867 char _lcd_bus;
wim 21:9eb628d9e164 868 };
wim 21:9eb628d9e164 869
wim 23:d47f226efb24 870 //---------- End TextLCD_SPI ------------
wim 21:9eb628d9e164 871
Sissors 24:fb3399713710 872
wim 26:bd897a001012 873 //--------- Start TextLCD_SPI_N -----------
Sissors 24:fb3399713710 874
wim 30:033048611c01 875 /** Create a TextLCD interface using a controller with native SPI4 interface
Sissors 24:fb3399713710 876 *
Sissors 24:fb3399713710 877 */
wim 25:6162b31128c9 878 class TextLCD_SPI_N : public TextLCD_Base {
Sissors 24:fb3399713710 879 public:
wim 30:033048611c01 880 /** Create a TextLCD interface using a controller with native SPI4 interface
Sissors 24:fb3399713710 881 *
Sissors 24:fb3399713710 882 * @param spi SPI Bus
Sissors 24:fb3399713710 883 * @param cs chip select pin (active low)
Sissors 24:fb3399713710 884 * @param rs Instruction/data control line
Sissors 24:fb3399713710 885 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Sissors 24:fb3399713710 886 * @param bl Backlight control line (optional, default = NC)
wim 26:bd897a001012 887 * @param ctrl LCD controller (default = ST7032_3V3)
Sissors 24:fb3399713710 888 */
wim 26:bd897a001012 889 TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3);
wim 25:6162b31128c9 890 virtual ~TextLCD_SPI_N(void);
Sissors 24:fb3399713710 891
Sissors 24:fb3399713710 892 private:
wim 29:a3663151aa65 893
wim 29:a3663151aa65 894 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 895 * Set the Enable pin.
wim 29:a3663151aa65 896 */
Sissors 24:fb3399713710 897 virtual void _setEnable(bool value);
wim 29:a3663151aa65 898
wim 29:a3663151aa65 899 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 900 * Set the RS pin (0 = Command, 1 = Data).
wim 29:a3663151aa65 901 */
Sissors 24:fb3399713710 902 virtual void _setRS(bool value);
wim 29:a3663151aa65 903
wim 29:a3663151aa65 904 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 905 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 906 */
Sissors 24:fb3399713710 907 virtual void _setBL(bool value);
wim 29:a3663151aa65 908
wim 29:a3663151aa65 909 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 910 * Set the databus value (4 bit).
wim 29:a3663151aa65 911 */
Sissors 24:fb3399713710 912 virtual void _setData(int value);
wim 29:a3663151aa65 913
wim 29:a3663151aa65 914 /** Low level writes to LCD serial bus only (serial native)
wim 29:a3663151aa65 915 */
Sissors 24:fb3399713710 916 virtual void _writeByte(int value);
Sissors 24:fb3399713710 917
Sissors 24:fb3399713710 918 // SPI bus
Sissors 24:fb3399713710 919 SPI *_spi;
Sissors 24:fb3399713710 920 DigitalOut _cs;
Sissors 24:fb3399713710 921 DigitalOut _rs;
wim 30:033048611c01 922
wim 30:033048611c01 923 //Backlight
Sissors 24:fb3399713710 924 DigitalOut *_bl;
Sissors 24:fb3399713710 925 };
Sissors 24:fb3399713710 926
wim 25:6162b31128c9 927 //---------- End TextLCD_SPI_N ------------
Sissors 24:fb3399713710 928
wim 26:bd897a001012 929
wim 32:59c4b8f648d4 930 #if(1)
wim 30:033048611c01 931 //Code checked out on logic analyser. Not yet tested on hardware..
wim 30:033048611c01 932
wim 30:033048611c01 933 //------- Start TextLCD_SPI_N_3_9 ---------
wim 30:033048611c01 934
wim 30:033048611c01 935 /** Create a TextLCD interface using a controller with native SPI3 9 bits interface
wim 30:033048611c01 936 * Note: current mbed libs only support SPI 9 bit mode for NXP platforms
wim 30:033048611c01 937 *
wim 30:033048611c01 938 */
wim 30:033048611c01 939 class TextLCD_SPI_N_3_9 : public TextLCD_Base {
wim 30:033048611c01 940 public:
wim 30:033048611c01 941 /** Create a TextLCD interface using a controller with native SPI3 9 bits interface
wim 30:033048611c01 942 * Note: current mbed libs only support SPI 9 bit mode for NXP platforms
wim 30:033048611c01 943 *
wim 30:033048611c01 944 * @param spi SPI Bus
wim 30:033048611c01 945 * @param cs chip select pin (active low)
wim 30:033048611c01 946 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 30:033048611c01 947 * @param bl Backlight control line (optional, default = NC)
wim 30:033048611c01 948 * @param ctrl LCD controller (default = AIP31068)
wim 30:033048611c01 949 */
wim 30:033048611c01 950 TextLCD_SPI_N_3_9(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = AIP31068);
wim 30:033048611c01 951 virtual ~TextLCD_SPI_N_3_9(void);
wim 30:033048611c01 952
wim 30:033048611c01 953 private:
wim 30:033048611c01 954
wim 30:033048611c01 955 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 956 * Set the Enable pin.
wim 30:033048611c01 957 */
wim 30:033048611c01 958 virtual void _setEnable(bool value);
wim 30:033048611c01 959
wim 30:033048611c01 960 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 961 * Set the RS pin (0 = Command, 1 = Data).
wim 32:59c4b8f648d4 962 */
wim 32:59c4b8f648d4 963 virtual void _setRS(bool value);
wim 32:59c4b8f648d4 964
wim 32:59c4b8f648d4 965 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 966 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 32:59c4b8f648d4 967 */
wim 32:59c4b8f648d4 968 virtual void _setBL(bool value);
wim 32:59c4b8f648d4 969
wim 32:59c4b8f648d4 970 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 971 * Set the databus value (4 bit).
wim 32:59c4b8f648d4 972 */
wim 32:59c4b8f648d4 973 virtual void _setData(int value);
wim 32:59c4b8f648d4 974
wim 32:59c4b8f648d4 975 /** Low level writes to LCD serial bus only (serial native)
wim 32:59c4b8f648d4 976 */
wim 32:59c4b8f648d4 977 virtual void _writeByte(int value);
wim 32:59c4b8f648d4 978
wim 32:59c4b8f648d4 979 // SPI bus
wim 32:59c4b8f648d4 980 SPI *_spi;
wim 32:59c4b8f648d4 981 DigitalOut _cs;
wim 32:59c4b8f648d4 982
wim 32:59c4b8f648d4 983 //Test
wim 32:59c4b8f648d4 984 DigitalOut _ps;
wim 32:59c4b8f648d4 985
wim 32:59c4b8f648d4 986
wim 32:59c4b8f648d4 987 // controlbyte to select between data and command. Internal value for serial bus only
wim 32:59c4b8f648d4 988 char _controlbyte;
wim 32:59c4b8f648d4 989
wim 32:59c4b8f648d4 990 //Backlight
wim 32:59c4b8f648d4 991 DigitalOut *_bl;
wim 32:59c4b8f648d4 992 };
wim 32:59c4b8f648d4 993
wim 32:59c4b8f648d4 994 //-------- End TextLCD_SPI_N_3_9 ----------
wim 32:59c4b8f648d4 995 #endif
wim 32:59c4b8f648d4 996
wim 32:59c4b8f648d4 997
wim 32:59c4b8f648d4 998 #if(1)
wim 32:59c4b8f648d4 999 //------- Start TextLCD_SPI_N_3_10 ---------
wim 32:59c4b8f648d4 1000
wim 32:59c4b8f648d4 1001 /** Create a TextLCD interface using a controller with native SPI3 10 bits interface
wim 32:59c4b8f648d4 1002 * Note: current mbed libs only support SPI 10 bit mode for NXP platforms
wim 32:59c4b8f648d4 1003 *
wim 32:59c4b8f648d4 1004 */
wim 32:59c4b8f648d4 1005 class TextLCD_SPI_N_3_10 : public TextLCD_Base {
wim 32:59c4b8f648d4 1006 public:
wim 32:59c4b8f648d4 1007 /** Create a TextLCD interface using a controller with native SPI3 10 bits interface
wim 32:59c4b8f648d4 1008 * Note: current mbed libs only support SPI 10 bit mode for NXP platforms
wim 32:59c4b8f648d4 1009 *
wim 32:59c4b8f648d4 1010 * @param spi SPI Bus
wim 32:59c4b8f648d4 1011 * @param cs chip select pin (active low)
wim 32:59c4b8f648d4 1012 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 32:59c4b8f648d4 1013 * @param bl Backlight control line (optional, default = NC)
wim 32:59c4b8f648d4 1014 * @param ctrl LCD controller (default = AIP31068)
wim 32:59c4b8f648d4 1015 */
wim 32:59c4b8f648d4 1016 TextLCD_SPI_N_3_10(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = AIP31068);
wim 32:59c4b8f648d4 1017 virtual ~TextLCD_SPI_N_3_10(void);
wim 32:59c4b8f648d4 1018
wim 32:59c4b8f648d4 1019 private:
wim 32:59c4b8f648d4 1020
wim 32:59c4b8f648d4 1021 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 1022 * Set the Enable pin.
wim 32:59c4b8f648d4 1023 */
wim 32:59c4b8f648d4 1024 virtual void _setEnable(bool value);
wim 32:59c4b8f648d4 1025
wim 32:59c4b8f648d4 1026 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 1027 * Set the RS pin (0 = Command, 1 = Data).
wim 32:59c4b8f648d4 1028 */
wim 32:59c4b8f648d4 1029 virtual void _setRS(bool value);
wim 32:59c4b8f648d4 1030
wim 32:59c4b8f648d4 1031 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 1032 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 32:59c4b8f648d4 1033 */
wim 32:59c4b8f648d4 1034 virtual void _setBL(bool value);
wim 32:59c4b8f648d4 1035
wim 32:59c4b8f648d4 1036 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 1037 * Set the databus value (4 bit).
wim 32:59c4b8f648d4 1038 */
wim 32:59c4b8f648d4 1039 virtual void _setData(int value);
wim 32:59c4b8f648d4 1040
wim 32:59c4b8f648d4 1041 /** Low level writes to LCD serial bus only (serial native)
wim 32:59c4b8f648d4 1042 */
wim 32:59c4b8f648d4 1043 virtual void _writeByte(int value);
wim 32:59c4b8f648d4 1044
wim 32:59c4b8f648d4 1045 // SPI bus
wim 32:59c4b8f648d4 1046 SPI *_spi;
wim 32:59c4b8f648d4 1047 DigitalOut _cs;
wim 32:59c4b8f648d4 1048
wim 32:59c4b8f648d4 1049
wim 32:59c4b8f648d4 1050 // controlbyte to select between data and command. Internal value for serial bus only
wim 32:59c4b8f648d4 1051 char _controlbyte;
wim 32:59c4b8f648d4 1052
wim 32:59c4b8f648d4 1053 //Backlight
wim 32:59c4b8f648d4 1054 DigitalOut *_bl;
wim 32:59c4b8f648d4 1055 };
wim 32:59c4b8f648d4 1056
wim 32:59c4b8f648d4 1057 //-------- End TextLCD_SPI_N_3_10 ----------
wim 32:59c4b8f648d4 1058 #endif
wim 32:59c4b8f648d4 1059
wim 32:59c4b8f648d4 1060 #if(0)
wim 32:59c4b8f648d4 1061 //Code not yet checked out on logic analyser. Not yet tested on hardware..
wim 32:59c4b8f648d4 1062
wim 32:59c4b8f648d4 1063 //------- Start TextLCD_SPI_N_3_16 ---------
wim 32:59c4b8f648d4 1064
wim 32:59c4b8f648d4 1065 /** Create a TextLCD interface using a controller with native SPI3 16 bits interface
wim 32:59c4b8f648d4 1066 *
wim 32:59c4b8f648d4 1067 */
wim 32:59c4b8f648d4 1068 class TextLCD_SPI_N_3_16 : public TextLCD_Base {
wim 32:59c4b8f648d4 1069 public:
wim 32:59c4b8f648d4 1070 /** Create a TextLCD interface using a controller with native SPI3 16 bits interface
wim 32:59c4b8f648d4 1071 *
wim 32:59c4b8f648d4 1072 * @param spi SPI Bus
wim 32:59c4b8f648d4 1073 * @param cs chip select pin (active low)
wim 32:59c4b8f648d4 1074 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 32:59c4b8f648d4 1075 * @param bl Backlight control line (optional, default = NC)
wim 32:59c4b8f648d4 1076 * @param ctrl LCD controller (default = PT6314)
wim 32:59c4b8f648d4 1077 */
wim 32:59c4b8f648d4 1078 TextLCD_SPI_N_3_16(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = PT6314);
wim 32:59c4b8f648d4 1079 virtual ~TextLCD_SPI_N_3_16(void);
wim 32:59c4b8f648d4 1080
wim 32:59c4b8f648d4 1081 private:
wim 32:59c4b8f648d4 1082
wim 32:59c4b8f648d4 1083 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 1084 * Set the Enable pin.
wim 32:59c4b8f648d4 1085 */
wim 32:59c4b8f648d4 1086 virtual void _setEnable(bool value);
wim 32:59c4b8f648d4 1087
wim 32:59c4b8f648d4 1088 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 1089 * Set the RS pin (0 = Command, 1 = Data).
wim 30:033048611c01 1090 */
wim 30:033048611c01 1091 virtual void _setRS(bool value);
wim 30:033048611c01 1092
wim 30:033048611c01 1093 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 1094 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 30:033048611c01 1095 */
wim 30:033048611c01 1096 virtual void _setBL(bool value);
wim 30:033048611c01 1097
wim 30:033048611c01 1098 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 1099 * Set the databus value (4 bit).
wim 30:033048611c01 1100 */
wim 30:033048611c01 1101 virtual void _setData(int value);
wim 30:033048611c01 1102
wim 30:033048611c01 1103 /** Low level writes to LCD serial bus only (serial native)
wim 30:033048611c01 1104 */
wim 30:033048611c01 1105 virtual void _writeByte(int value);
wim 30:033048611c01 1106
wim 30:033048611c01 1107 // SPI bus
wim 30:033048611c01 1108 SPI *_spi;
wim 30:033048611c01 1109 DigitalOut _cs;
wim 30:033048611c01 1110
wim 30:033048611c01 1111 // controlbyte to select between data and command. Internal value for serial bus only
wim 30:033048611c01 1112 char _controlbyte;
wim 30:033048611c01 1113
wim 30:033048611c01 1114 //Backlight
wim 30:033048611c01 1115 DigitalOut *_bl;
wim 30:033048611c01 1116 };
wim 30:033048611c01 1117
wim 32:59c4b8f648d4 1118 //-------- End TextLCD_SPI_N_3_16 ----------
wim 30:033048611c01 1119 #endif
wim 30:033048611c01 1120
wim 32:59c4b8f648d4 1121 #if(1)
wim 32:59c4b8f648d4 1122 //Code to be checked out on logic analyser. Not yet tested on hardware..
wim 30:033048611c01 1123
wim 32:59c4b8f648d4 1124 //------- Start TextLCD_SPI_N_3_24 ---------
wim 30:033048611c01 1125
wim 32:59c4b8f648d4 1126 /** Create a TextLCD interface using a controller with native SPI3 24 bits interface
wim 32:59c4b8f648d4 1127 * Note: lib uses SPI 8 bit mode
wim 30:033048611c01 1128 *
wim 30:033048611c01 1129 */
wim 32:59c4b8f648d4 1130 class TextLCD_SPI_N_3_24 : public TextLCD_Base {
wim 30:033048611c01 1131 public:
wim 32:59c4b8f648d4 1132 /** Create a TextLCD interface using a controller with native SPI3 24 bits interface
wim 32:59c4b8f648d4 1133 * Note: lib uses SPI 8 bit mode
wim 30:033048611c01 1134 *
wim 30:033048611c01 1135 * @param spi SPI Bus
wim 30:033048611c01 1136 * @param cs chip select pin (active low)
wim 30:033048611c01 1137 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 30:033048611c01 1138 * @param bl Backlight control line (optional, default = NC)
wim 32:59c4b8f648d4 1139 * @param ctrl LCD controller (default = SSD1803)
wim 30:033048611c01 1140 */
wim 32:59c4b8f648d4 1141 TextLCD_SPI_N_3_24(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = SSD1803_3V3);
wim 32:59c4b8f648d4 1142 virtual ~TextLCD_SPI_N_3_24(void);
wim 30:033048611c01 1143
wim 30:033048611c01 1144 private:
wim 30:033048611c01 1145
wim 30:033048611c01 1146 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 1147 * Set the Enable pin.
wim 30:033048611c01 1148 */
wim 30:033048611c01 1149 virtual void _setEnable(bool value);
wim 30:033048611c01 1150
wim 30:033048611c01 1151 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 1152 * Set the RS pin (0 = Command, 1 = Data).
wim 30:033048611c01 1153 */
wim 30:033048611c01 1154 virtual void _setRS(bool value);
wim 30:033048611c01 1155
wim 30:033048611c01 1156 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 1157 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 30:033048611c01 1158 */
wim 30:033048611c01 1159 virtual void _setBL(bool value);
wim 30:033048611c01 1160
wim 30:033048611c01 1161 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 1162 * Set the databus value (4 bit).
wim 30:033048611c01 1163 */
wim 30:033048611c01 1164 virtual void _setData(int value);
wim 30:033048611c01 1165
wim 30:033048611c01 1166 /** Low level writes to LCD serial bus only (serial native)
wim 30:033048611c01 1167 */
wim 30:033048611c01 1168 virtual void _writeByte(int value);
wim 30:033048611c01 1169
wim 30:033048611c01 1170 // SPI bus
wim 30:033048611c01 1171 SPI *_spi;
wim 30:033048611c01 1172 DigitalOut _cs;
wim 30:033048611c01 1173
wim 30:033048611c01 1174 // controlbyte to select between data and command. Internal value for serial bus only
wim 30:033048611c01 1175 char _controlbyte;
wim 30:033048611c01 1176
wim 30:033048611c01 1177 //Backlight
wim 30:033048611c01 1178 DigitalOut *_bl;
wim 30:033048611c01 1179 };
wim 30:033048611c01 1180
wim 32:59c4b8f648d4 1181 //-------- End TextLCD_SPI_N_3_24 ----------
wim 30:033048611c01 1182 #endif
wim 30:033048611c01 1183
wim 30:033048611c01 1184
wim 26:bd897a001012 1185 //--------- Start TextLCD_I2C_N -----------
wim 26:bd897a001012 1186
wim 26:bd897a001012 1187 /** Create a TextLCD interface using a controller with native I2C interface
wim 26:bd897a001012 1188 *
wim 26:bd897a001012 1189 */
wim 26:bd897a001012 1190 class TextLCD_I2C_N : public TextLCD_Base {
wim 26:bd897a001012 1191 public:
wim 26:bd897a001012 1192 /** Create a TextLCD interface using a controller with native I2C interface
wim 26:bd897a001012 1193 *
wim 26:bd897a001012 1194 * @param i2c I2C Bus
wim 28:30fa94f7341c 1195 * @param deviceAddress I2C slave address (default = ST7032_SA = 0x7C)
wim 26:bd897a001012 1196 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 28:30fa94f7341c 1197 * @param bl Backlight control line (optional, default = NC)
wim 26:bd897a001012 1198 * @param ctrl LCD controller (default = ST7032_3V3)
wim 26:bd897a001012 1199 */
wim 28:30fa94f7341c 1200 TextLCD_I2C_N(I2C *i2c, char deviceAddress = ST7032_SA, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3);
wim 26:bd897a001012 1201 virtual ~TextLCD_I2C_N(void);
wim 26:bd897a001012 1202
wim 26:bd897a001012 1203 private:
wim 29:a3663151aa65 1204
wim 29:a3663151aa65 1205 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 1206 * Set the Enable pin.
wim 29:a3663151aa65 1207 */
wim 26:bd897a001012 1208 virtual void _setEnable(bool value);
wim 29:a3663151aa65 1209
wim 29:a3663151aa65 1210 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 1211 * Set the RS pin ( 0 = Command, 1 = Data).
wim 29:a3663151aa65 1212 */
wim 26:bd897a001012 1213 virtual void _setRS(bool value);
wim 29:a3663151aa65 1214
wim 29:a3663151aa65 1215 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 1216 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 1217 */
wim 26:bd897a001012 1218 virtual void _setBL(bool value);
wim 29:a3663151aa65 1219
wim 29:a3663151aa65 1220 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 1221 * Set the databus value (4 bit).
wim 29:a3663151aa65 1222 */
wim 26:bd897a001012 1223 virtual void _setData(int value);
wim 29:a3663151aa65 1224
wim 29:a3663151aa65 1225 /** Low level writes to LCD serial bus only (serial native)
wim 29:a3663151aa65 1226 */
wim 26:bd897a001012 1227 virtual void _writeByte(int value);
wim 26:bd897a001012 1228
wim 26:bd897a001012 1229 //I2C bus
wim 26:bd897a001012 1230 I2C *_i2c;
wim 26:bd897a001012 1231 char _slaveAddress;
wim 26:bd897a001012 1232
wim 28:30fa94f7341c 1233 // controlbyte to select between data and command. Internal value for serial bus only
wim 28:30fa94f7341c 1234 char _controlbyte;
wim 28:30fa94f7341c 1235
wim 30:033048611c01 1236 //Backlight
wim 28:30fa94f7341c 1237 DigitalOut *_bl;
wim 32:59c4b8f648d4 1238
wim 32:59c4b8f648d4 1239
wim 32:59c4b8f648d4 1240 //Test
wim 32:59c4b8f648d4 1241 DigitalOut _ps;
wim 32:59c4b8f648d4 1242
wim 26:bd897a001012 1243 };
wim 26:bd897a001012 1244
wim 26:bd897a001012 1245 //---------- End TextLCD_I2C_N ------------
wim 26:bd897a001012 1246
wim 26:bd897a001012 1247
simon 1:ac48b187213c 1248 #endif