Fork for Seoul Hackathon

Dependents:   TextLCD_FC113 Kviz

Committer:
wim
Date:
Sun Jun 29 14:55:50 2014 +0000
Revision:
31:ef31cd8a00d1
Parent:
30:033048611c01
Child:
32:59c4b8f648d4
Added Support for native I2C controllers (PCF21XX, AIP31068), added LCDTypes for 3 and 4 line displays. Encoded features in LCDTypes and LCDCtrl enumerators to ease code maintenance and improve sanity checks.

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