for
Dependents: LV_FGSE_Controller_Interface
TextLCD.h@30:033048611c01, 2014-06-28 (annotated)
- Committer:
- wim
- Date:
- Sat Jun 28 14:27:32 2014 +0000
- Revision:
- 30:033048611c01
- Parent:
- 29:a3663151aa65
- Child:
- 31:ef31cd8a00d1
Tested AIP31068 for I2C, tested SPI3_9 and SPI3_10
Who changed what in which revision?
User | Revision | Line number | New 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 | 29:a3663151aa65 | 73 | #define DEFAULT 0 |
wim | 29:a3663151aa65 | 74 | #define ADAFRUIT 1 |
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 | #if(0) |
wim | 30:033048611c01 | 351 | /** LCD panel format */ |
wim | 30:033048611c01 | 352 | enum LCDType { |
wim | 8:03116f75b66e | 353 | LCD8x1, /**< 8x1 LCD panel */ |
wim | 13:24506ba22480 | 354 | LCD8x2, /**< 8x2 LCD panel */ |
wim | 18:bd65dc10f27f | 355 | LCD8x2B, /**< 8x2 LCD panel (actually 16x1) */ |
wim | 29:a3663151aa65 | 356 | // LCD12x1, /**< 12x1 LCD panel */ |
wim | 29:a3663151aa65 | 357 | // LCD12x1B, /**< 12x1 LCD panel, special mode PCF21XX */ |
wim | 15:b70ebfffb258 | 358 | LCD12x2, /**< 12x2 LCD panel */ |
wim | 29:a3663151aa65 | 359 | LCD12x3B, /**< 12x3 LCD panel, special mode PCF21XX */ |
wim | 30:033048611c01 | 360 | // LCD12x3C, /**< 12x3 LCD panel, special mode PCF21XX */ |
wim | 15:b70ebfffb258 | 361 | LCD12x4, /**< 12x4 LCD panel */ |
wim | 29:a3663151aa65 | 362 | LCD12x4B, /**< 12x4 LCD panel, special mode PCF21XX */ |
wim | 13:24506ba22480 | 363 | LCD16x1, /**< 16x1 LCD panel (actually 8x2) */ |
wim | 30:033048611c01 | 364 | // LCD16x1B, /**< 16x1 LCD panel */ |
wim | 8:03116f75b66e | 365 | LCD16x2, /**< 16x2 LCD panel (default) */ |
wim | 8:03116f75b66e | 366 | LCD16x2B, /**< 16x2 LCD panel alternate addressing */ |
wim | 29:a3663151aa65 | 367 | // LCD16x3B, /**< 16x3 LCD panel, special mode ST7036 */ |
wim | 8:03116f75b66e | 368 | LCD16x4, /**< 16x4 LCD panel */ |
wim | 29:a3663151aa65 | 369 | // LCD20x1, /**< 20x1 LCD panel */ |
wim | 8:03116f75b66e | 370 | LCD20x2, /**< 20x2 LCD panel */ |
wim | 8:03116f75b66e | 371 | LCD20x4, /**< 20x4 LCD panel */ |
wim | 29:a3663151aa65 | 372 | LCD24x4B, /**< 24x4 LCD panel, special mode KS0078 */ |
wim | 29:a3663151aa65 | 373 | LCD24x1, /**< 24x1 LCD panel */ |
wim | 9:0893d986e717 | 374 | LCD24x2, /**< 24x2 LCD panel */ |
wim | 30:033048611c01 | 375 | // LCD40x1, /**< 40x1 LCD panel */ |
wim | 15:b70ebfffb258 | 376 | LCD40x2, /**< 40x2 LCD panel */ |
wim | 15:b70ebfffb258 | 377 | LCD40x4 /**< 40x4 LCD panel, Two controller version */ |
simon | 1:ac48b187213c | 378 | }; |
wim | 30:033048611c01 | 379 | #endif |
simon | 1:ac48b187213c | 380 | |
wim | 30:033048611c01 | 381 | |
wim | 30:033048611c01 | 382 | /** LCD Controller Device */ |
wim | 30:033048611c01 | 383 | enum LCDCtrl { |
wim | 30:033048611c01 | 384 | HD44780 = 0, /**< HD44780 (default) */ |
wim | 30:033048611c01 | 385 | WS0010 = 1 | (LCD_C_SPI3_10 | LCD_C_BST), /**< WS0010 OLED Controller, 4/8 bit, SPI3 */ |
wim | 30:033048611c01 | 386 | ST7036 = 2 | (LCD_C_SPI4 | LCD_C_BST), /**< ST7036 3V3 with Booster, 4/8 bit, SPI4 */ |
wim | 30:033048611c01 | 387 | ST7032_3V3 = 3 | (LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST), /**< ST7032 3V3 with Booster, 4/8 bit, SPI4, I2C */ |
wim | 30:033048611c01 | 388 | ST7032_5V = 4 | (LCD_C_SPI4 | LCD_C_I2C), /**< ST7032 5V no Booster, 4/8 bit, SPI4, I2C */ |
wim | 30:033048611c01 | 389 | KS0078 = 5, /**< KS0078 24x4 support, 4/8 bit */ |
wim | 30:033048611c01 | 390 | PCF2113_3V3 = 6 | (LCD_C_I2C | LCD_C_BST), /**< PCF2113 3V3 with Booster, 4/8 bit, I2C */ |
wim | 30:033048611c01 | 391 | PCF2116_3V3 = 7 | (LCD_C_I2C | LCD_C_BST), /**< PCF2116 3V3 with Booster, 4/8 bit, I2C */ |
wim | 30:033048611c01 | 392 | // PCF2116_5V = 8 | (LCD_C_I2C), /**< PCF2116 5V no Booster, 4/8 bit, I2C */ |
wim | 30:033048611c01 | 393 | AIP31068 = 9 | (LCD_C_SPI3_9 | LCD_C_I2C | LCD_C_BST) /**< AIP31068 I2C, SPI3 */ |
wim | 30:033048611c01 | 394 | }; |
wim | 30:033048611c01 | 395 | |
wim | 30:033048611c01 | 396 | |
wim | 30:033048611c01 | 397 | #if(0) |
wim | 19:c747b9e2e7b8 | 398 | /** LCD Controller Device */ |
wim | 19:c747b9e2e7b8 | 399 | enum LCDCtrl { |
wim | 29:a3663151aa65 | 400 | HD44780, /**< HD44780 (default) */ |
wim | 30:033048611c01 | 401 | WS0010, /**< WS0010 OLED Controller, 4/8 bit, SPI */ |
wim | 29:a3663151aa65 | 402 | ST7036, /**< ST7036 3V3 with Booster, 4/8 bit, SPI */ |
wim | 29:a3663151aa65 | 403 | ST7032_3V3, /**< ST7032 3V3 with Booster, 4/8 bit, SPI, I2C */ |
wim | 29:a3663151aa65 | 404 | ST7032_5V, /**< ST7032 5V no Booster, 4/8 bit, SPI, I2C */ |
wim | 30:033048611c01 | 405 | KS0078, /**< KS0078 24x4 support, 4/8 bit */ |
wim | 29:a3663151aa65 | 406 | PCF21XX_3V3, /**< PCF21XX 3V3 with Booster, 4/8 bit, I2C */ |
wim | 29:a3663151aa65 | 407 | // PCF21XX_5V /**< PCF21XX 5V no Booster, 4/8 bit, I2C */ |
wim | 19:c747b9e2e7b8 | 408 | }; |
wim | 30:033048611c01 | 409 | #endif |
wim | 19:c747b9e2e7b8 | 410 | |
wim | 10:dd9b3a696acd | 411 | /** LCD Cursor control */ |
wim | 10:dd9b3a696acd | 412 | enum LCDCursor { |
wim | 17:652ab113bc2e | 413 | CurOff_BlkOff = 0x00, /**< Cursor Off, Blinking Char Off */ |
wim | 17:652ab113bc2e | 414 | CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */ |
wim | 17:652ab113bc2e | 415 | CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */ |
wim | 17:652ab113bc2e | 416 | CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */ |
wim | 17:652ab113bc2e | 417 | }; |
wim | 17:652ab113bc2e | 418 | |
wim | 17:652ab113bc2e | 419 | /** LCD Display control */ |
wim | 17:652ab113bc2e | 420 | enum LCDMode { |
wim | 17:652ab113bc2e | 421 | DispOff = 0x00, /**< Display Off */ |
wim | 17:652ab113bc2e | 422 | DispOn = 0x04 /**< Display On */ |
wim | 10:dd9b3a696acd | 423 | }; |
wim | 10:dd9b3a696acd | 424 | |
wim | 20:e0da005a777f | 425 | /** LCD Backlight control */ |
wim | 20:e0da005a777f | 426 | enum LCDBacklight { |
wim | 20:e0da005a777f | 427 | LightOff, /**< Backlight Off */ |
wim | 20:e0da005a777f | 428 | LightOn /**< Backlight On */ |
wim | 20:e0da005a777f | 429 | }; |
wim | 10:dd9b3a696acd | 430 | |
simon | 2:227356c7d12c | 431 | #if DOXYGEN_ONLY |
simon | 2:227356c7d12c | 432 | /** Write a character to the LCD |
simon | 2:227356c7d12c | 433 | * |
simon | 2:227356c7d12c | 434 | * @param c The character to write to the display |
simon | 2:227356c7d12c | 435 | */ |
simon | 2:227356c7d12c | 436 | int putc(int c); |
simon | 2:227356c7d12c | 437 | |
simon | 2:227356c7d12c | 438 | /** Write a formated string to the LCD |
simon | 2:227356c7d12c | 439 | * |
simon | 2:227356c7d12c | 440 | * @param format A printf-style format string, followed by the |
simon | 2:227356c7d12c | 441 | * variables to use in formating the string. |
simon | 2:227356c7d12c | 442 | */ |
simon | 2:227356c7d12c | 443 | int printf(const char* format, ...); |
simon | 2:227356c7d12c | 444 | #endif |
simon | 2:227356c7d12c | 445 | |
wim | 29:a3663151aa65 | 446 | /** Locate cursor to a screen column and row |
simon | 2:227356c7d12c | 447 | * |
simon | 2:227356c7d12c | 448 | * @param column The horizontal position from the left, indexed from 0 |
simon | 2:227356c7d12c | 449 | * @param row The vertical position from the top, indexed from 0 |
simon | 2:227356c7d12c | 450 | */ |
simon | 1:ac48b187213c | 451 | void locate(int column, int row); |
simon | 2:227356c7d12c | 452 | |
wim | 10:dd9b3a696acd | 453 | /** Return the memoryaddress of screen column and row location |
wim | 10:dd9b3a696acd | 454 | * |
wim | 10:dd9b3a696acd | 455 | * @param column The horizontal position from the left, indexed from 0 |
wim | 10:dd9b3a696acd | 456 | * @param row The vertical position from the top, indexed from 0 |
wim | 10:dd9b3a696acd | 457 | * @param return The memoryaddress of screen column and row location |
wim | 10:dd9b3a696acd | 458 | */ |
wim | 30:033048611c01 | 459 | int getAddress(int column, int row); |
wim | 10:dd9b3a696acd | 460 | |
wim | 10:dd9b3a696acd | 461 | /** Set the memoryaddress of screen column and row location |
wim | 10:dd9b3a696acd | 462 | * |
wim | 10:dd9b3a696acd | 463 | * @param column The horizontal position from the left, indexed from 0 |
wim | 10:dd9b3a696acd | 464 | * @param row The vertical position from the top, indexed from 0 |
wim | 10:dd9b3a696acd | 465 | */ |
wim | 9:0893d986e717 | 466 | void setAddress(int column, int row); |
wim | 9:0893d986e717 | 467 | |
wim | 22:35742ec80c24 | 468 | /** Clear the screen and locate to 0,0 |
wim | 22:35742ec80c24 | 469 | */ |
simon | 1:ac48b187213c | 470 | void cls(); |
simon | 2:227356c7d12c | 471 | |
wim | 10:dd9b3a696acd | 472 | /** Return the number of rows |
wim | 10:dd9b3a696acd | 473 | * |
wim | 10:dd9b3a696acd | 474 | * @param return The number of rows |
wim | 10:dd9b3a696acd | 475 | */ |
simon | 1:ac48b187213c | 476 | int rows(); |
wim | 10:dd9b3a696acd | 477 | |
wim | 10:dd9b3a696acd | 478 | /** Return the number of columns |
wim | 10:dd9b3a696acd | 479 | * |
wim | 10:dd9b3a696acd | 480 | * @param return The number of columns |
wim | 10:dd9b3a696acd | 481 | */ |
wim | 10:dd9b3a696acd | 482 | int columns(); |
simon | 2:227356c7d12c | 483 | |
wim | 11:9ec02df863a1 | 484 | /** Set the Cursormode |
wim | 11:9ec02df863a1 | 485 | * |
wim | 17:652ab113bc2e | 486 | * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn) |
wim | 11:9ec02df863a1 | 487 | */ |
wim | 17:652ab113bc2e | 488 | void setCursor(LCDCursor cursorMode); |
wim | 17:652ab113bc2e | 489 | |
wim | 17:652ab113bc2e | 490 | /** Set the Displaymode |
wim | 17:652ab113bc2e | 491 | * |
wim | 17:652ab113bc2e | 492 | * @param displayMode The Display mode (DispOff, DispOn) |
wim | 17:652ab113bc2e | 493 | */ |
wim | 21:9eb628d9e164 | 494 | void setMode(LCDMode displayMode); |
wim | 11:9ec02df863a1 | 495 | |
wim | 20:e0da005a777f | 496 | /** Set the Backlight mode |
wim | 20:e0da005a777f | 497 | * |
wim | 21:9eb628d9e164 | 498 | * @param backlightMode The Backlight mode (LightOff, LightOn) |
wim | 20:e0da005a777f | 499 | */ |
wim | 21:9eb628d9e164 | 500 | void setBacklight(LCDBacklight backlightMode); |
wim | 20:e0da005a777f | 501 | |
wim | 11:9ec02df863a1 | 502 | /** Set User Defined Characters |
wim | 11:9ec02df863a1 | 503 | * |
wim | 11:9ec02df863a1 | 504 | * @param unsigned char c The Index of the UDC (0..7) |
wim | 12:6bf9d9957d31 | 505 | * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits) |
wim | 11:9ec02df863a1 | 506 | */ |
wim | 11:9ec02df863a1 | 507 | void setUDC(unsigned char c, char *udc_data); |
wim | 11:9ec02df863a1 | 508 | |
wim | 29:a3663151aa65 | 509 | //test |
wim | 30:033048611c01 | 510 | // void _initCtrl(); |
wim | 29:a3663151aa65 | 511 | |
simon | 1:ac48b187213c | 512 | protected: |
wim | 13:24506ba22480 | 513 | |
wim | 21:9eb628d9e164 | 514 | /** LCD controller select, mainly used for LCD40x4 |
wim | 21:9eb628d9e164 | 515 | */ |
wim | 19:c747b9e2e7b8 | 516 | enum _LCDCtrl_Idx { |
wim | 15:b70ebfffb258 | 517 | _LCDCtrl_0, /*< Primary */ |
wim | 15:b70ebfffb258 | 518 | _LCDCtrl_1, /*< Secondary */ |
wim | 15:b70ebfffb258 | 519 | }; |
wim | 21:9eb628d9e164 | 520 | |
wim | 21:9eb628d9e164 | 521 | /** Create a TextLCD_Base interface |
wim | 21:9eb628d9e164 | 522 | * @brief Base class, can not be instantiated |
wim | 21:9eb628d9e164 | 523 | * |
wim | 21:9eb628d9e164 | 524 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 21:9eb628d9e164 | 525 | * @param ctrl LCD controller (default = HD44780) |
wim | 21:9eb628d9e164 | 526 | */ |
wim | 21:9eb628d9e164 | 527 | TextLCD_Base(LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); |
wim | 15:b70ebfffb258 | 528 | |
simon | 1:ac48b187213c | 529 | // Stream implementation functions |
simon | 1:ac48b187213c | 530 | virtual int _putc(int value); |
simon | 1:ac48b187213c | 531 | virtual int _getc(); |
simon | 1:ac48b187213c | 532 | |
wim | 29:a3663151aa65 | 533 | /** Low level method for LCD controller |
wim | 21:9eb628d9e164 | 534 | */ |
wim | 13:24506ba22480 | 535 | void _init(); |
wim | 29:a3663151aa65 | 536 | |
wim | 29:a3663151aa65 | 537 | /** Low level initialisation method for LCD controller |
wim | 29:a3663151aa65 | 538 | */ |
wim | 30:033048611c01 | 539 | void _initCtrl(); |
wim | 29:a3663151aa65 | 540 | |
wim | 29:a3663151aa65 | 541 | /** Low level character address set method |
wim | 29:a3663151aa65 | 542 | */ |
wim | 13:24506ba22480 | 543 | int _address(int column, int row); |
wim | 29:a3663151aa65 | 544 | |
wim | 29:a3663151aa65 | 545 | /** Low level cursor enable or disable method |
wim | 29:a3663151aa65 | 546 | */ |
wim | 21:9eb628d9e164 | 547 | void _setCursor(LCDCursor show); |
wim | 29:a3663151aa65 | 548 | |
wim | 29:a3663151aa65 | 549 | /** Low level method to store user defined characters for current controller |
wim | 29:a3663151aa65 | 550 | */ |
wim | 17:652ab113bc2e | 551 | void _setUDC(unsigned char c, char *udc_data); |
wim | 29:a3663151aa65 | 552 | |
wim | 29:a3663151aa65 | 553 | /** Low level method to restore the cursortype and display mode for current controller |
wim | 29:a3663151aa65 | 554 | */ |
wim | 21:9eb628d9e164 | 555 | void _setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType); |
wim | 13:24506ba22480 | 556 | |
wim | 29:a3663151aa65 | 557 | /** Low level nibble write operation to LCD controller (serial or parallel) |
wim | 21:9eb628d9e164 | 558 | */ |
wim | 17:652ab113bc2e | 559 | void _writeNibble(int value); |
wim | 29:a3663151aa65 | 560 | |
wim | 29:a3663151aa65 | 561 | /** Low level command byte write operation to LCD controller. |
wim | 29:a3663151aa65 | 562 | * Methods resets the RS bit and provides the required timing for the command. |
wim | 29:a3663151aa65 | 563 | */ |
wim | 15:b70ebfffb258 | 564 | void _writeCommand(int command); |
wim | 29:a3663151aa65 | 565 | |
wim | 29:a3663151aa65 | 566 | /** Low level data byte write operation to LCD controller (serial or parallel). |
wim | 29:a3663151aa65 | 567 | * Methods sets the RS bit and provides the required timing for the data. |
wim | 29:a3663151aa65 | 568 | */ |
wim | 15:b70ebfffb258 | 569 | void _writeData(int data); |
wim | 15:b70ebfffb258 | 570 | |
wim | 29:a3663151aa65 | 571 | /** Pure Virtual Low level writes to LCD Bus (serial or parallel) |
wim | 29:a3663151aa65 | 572 | * Set the Enable pin. |
wim | 29:a3663151aa65 | 573 | */ |
wim | 29:a3663151aa65 | 574 | virtual void _setEnable(bool value) = 0; |
wim | 29:a3663151aa65 | 575 | |
wim | 21:9eb628d9e164 | 576 | /** Pure Virtual Low level writes to LCD Bus (serial or parallel) |
wim | 29:a3663151aa65 | 577 | * Set the RS pin ( 0 = Command, 1 = Data). |
wim | 29:a3663151aa65 | 578 | */ |
wim | 21:9eb628d9e164 | 579 | virtual void _setRS(bool value) = 0; |
wim | 29:a3663151aa65 | 580 | |
wim | 29:a3663151aa65 | 581 | /** Pure Virtual Low level writes to LCD Bus (serial or parallel) |
wim | 29:a3663151aa65 | 582 | * Set the BL pin (0 = Backlight Off, 1 = Backlight On). |
wim | 29:a3663151aa65 | 583 | */ |
wim | 21:9eb628d9e164 | 584 | virtual void _setBL(bool value) = 0; |
wim | 29:a3663151aa65 | 585 | |
wim | 29:a3663151aa65 | 586 | /** Pure Virtual Low level writes to LCD Bus (serial or parallel) |
wim | 29:a3663151aa65 | 587 | * Set the databus value (4 bit). |
wim | 29:a3663151aa65 | 588 | */ |
wim | 21:9eb628d9e164 | 589 | virtual void _setData(int value) = 0; |
wim | 13:24506ba22480 | 590 | |
wim | 29:a3663151aa65 | 591 | /** Low level byte write operation to LCD controller (serial or parallel) |
wim | 29:a3663151aa65 | 592 | * Depending on the RS pin this byte will be interpreted as data or command |
wim | 29:a3663151aa65 | 593 | */ |
wim | 29:a3663151aa65 | 594 | virtual void _writeByte(int value); |
wim | 13:24506ba22480 | 595 | |
wim | 13:24506ba22480 | 596 | //Display type |
simon | 1:ac48b187213c | 597 | LCDType _type; |
wim | 30:033048611c01 | 598 | int _nr_cols; |
wim | 30:033048611c01 | 599 | int _nr_rows; |
wim | 30:033048611c01 | 600 | int _addr_mode; |
wim | 30:033048611c01 | 601 | |
wim | 21:9eb628d9e164 | 602 | //Display mode |
wim | 17:652ab113bc2e | 603 | LCDMode _currentMode; |
wim | 17:652ab113bc2e | 604 | |
wim | 19:c747b9e2e7b8 | 605 | //Controller type |
wim | 19:c747b9e2e7b8 | 606 | LCDCtrl _ctrl; |
wim | 19:c747b9e2e7b8 | 607 | |
wim | 15:b70ebfffb258 | 608 | //Controller select, mainly used for LCD40x4 |
wim | 19:c747b9e2e7b8 | 609 | _LCDCtrl_Idx _ctrl_idx; |
wim | 15:b70ebfffb258 | 610 | |
wim | 13:24506ba22480 | 611 | // Cursor |
simon | 1:ac48b187213c | 612 | int _column; |
simon | 1:ac48b187213c | 613 | int _row; |
wim | 15:b70ebfffb258 | 614 | LCDCursor _currentCursor; |
simon | 1:ac48b187213c | 615 | }; |
simon | 1:ac48b187213c | 616 | |
wim | 23:d47f226efb24 | 617 | //--------- End TextLCD_Base ----------- |
wim | 22:35742ec80c24 | 618 | |
wim | 22:35742ec80c24 | 619 | |
wim | 22:35742ec80c24 | 620 | |
wim | 23:d47f226efb24 | 621 | //--------- Start TextLCD Bus ----------- |
wim | 21:9eb628d9e164 | 622 | |
wim | 21:9eb628d9e164 | 623 | /** Create a TextLCD interface for using regular mbed pins |
wim | 21:9eb628d9e164 | 624 | * |
wim | 21:9eb628d9e164 | 625 | */ |
wim | 21:9eb628d9e164 | 626 | class TextLCD : public TextLCD_Base { |
wim | 21:9eb628d9e164 | 627 | public: |
wim | 21:9eb628d9e164 | 628 | /** Create a TextLCD interface for using regular mbed pins |
wim | 21:9eb628d9e164 | 629 | * |
wim | 21:9eb628d9e164 | 630 | * @param rs Instruction/data control line |
wim | 21:9eb628d9e164 | 631 | * @param e Enable line (clock) |
wim | 21:9eb628d9e164 | 632 | * @param d4-d7 Data lines for using as a 4-bit interface |
wim | 21:9eb628d9e164 | 633 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 21:9eb628d9e164 | 634 | * @param bl Backlight control line (optional, default = NC) |
wim | 21:9eb628d9e164 | 635 | * @param e2 Enable2 line (clock for second controller, LCD40x4 only) |
wim | 21:9eb628d9e164 | 636 | * @param ctrl LCD controller (default = HD44780) |
wim | 21:9eb628d9e164 | 637 | */ |
wim | 21:9eb628d9e164 | 638 | 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 | 639 | |
wim | 22:35742ec80c24 | 640 | /** Destruct a TextLCD interface for using regular mbed pins |
wim | 22:35742ec80c24 | 641 | * |
wim | 22:35742ec80c24 | 642 | * @param none |
wim | 22:35742ec80c24 | 643 | * @return none |
wim | 22:35742ec80c24 | 644 | */ |
wim | 22:35742ec80c24 | 645 | virtual ~TextLCD(); |
wim | 22:35742ec80c24 | 646 | |
wim | 21:9eb628d9e164 | 647 | private: |
wim | 29:a3663151aa65 | 648 | |
wim | 29:a3663151aa65 | 649 | /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) |
wim | 29:a3663151aa65 | 650 | * Set the Enable pin. |
wim | 29:a3663151aa65 | 651 | */ |
wim | 21:9eb628d9e164 | 652 | virtual void _setEnable(bool value); |
wim | 29:a3663151aa65 | 653 | |
wim | 29:a3663151aa65 | 654 | /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) |
wim | 29:a3663151aa65 | 655 | * Set the RS pin ( 0 = Command, 1 = Data). |
wim | 29:a3663151aa65 | 656 | */ |
wim | 21:9eb628d9e164 | 657 | virtual void _setRS(bool value); |
wim | 29:a3663151aa65 | 658 | |
wim | 29:a3663151aa65 | 659 | /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) |
wim | 29:a3663151aa65 | 660 | * Set the BL pin (0 = Backlight Off, 1 = Backlight On). |
wim | 29:a3663151aa65 | 661 | */ |
wim | 21:9eb628d9e164 | 662 | virtual void _setBL(bool value); |
wim | 29:a3663151aa65 | 663 | |
wim | 29:a3663151aa65 | 664 | /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) |
wim | 29:a3663151aa65 | 665 | * Set the databus value (4 bit). |
wim | 29:a3663151aa65 | 666 | */ |
wim | 21:9eb628d9e164 | 667 | virtual void _setData(int value); |
wim | 21:9eb628d9e164 | 668 | |
wim | 29:a3663151aa65 | 669 | |
wim | 22:35742ec80c24 | 670 | /** Regular mbed pins bus |
wim | 22:35742ec80c24 | 671 | */ |
wim | 22:35742ec80c24 | 672 | DigitalOut _rs, _e; |
wim | 22:35742ec80c24 | 673 | BusOut _d; |
wim | 22:35742ec80c24 | 674 | |
wim | 22:35742ec80c24 | 675 | /** Optional Hardware pins for the Backlight and LCD40x4 device |
wim | 22:35742ec80c24 | 676 | * Default PinName value is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins |
wim | 22:35742ec80c24 | 677 | */ |
wim | 22:35742ec80c24 | 678 | DigitalOut *_bl, *_e2; |
wim | 21:9eb628d9e164 | 679 | }; |
wim | 21:9eb628d9e164 | 680 | |
wim | 22:35742ec80c24 | 681 | |
wim | 23:d47f226efb24 | 682 | //----------- End TextLCD --------------- |
wim | 21:9eb628d9e164 | 683 | |
wim | 21:9eb628d9e164 | 684 | |
wim | 23:d47f226efb24 | 685 | //--------- Start TextLCD_I2C ----------- |
wim | 22:35742ec80c24 | 686 | |
wim | 22:35742ec80c24 | 687 | |
wim | 26:bd897a001012 | 688 | /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander |
wim | 21:9eb628d9e164 | 689 | * |
wim | 21:9eb628d9e164 | 690 | */ |
wim | 21:9eb628d9e164 | 691 | class TextLCD_I2C : public TextLCD_Base { |
wim | 21:9eb628d9e164 | 692 | public: |
wim | 26:bd897a001012 | 693 | /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander |
wim | 21:9eb628d9e164 | 694 | * |
wim | 21:9eb628d9e164 | 695 | * @param i2c I2C Bus |
wim | 26:bd897a001012 | 696 | * @param deviceAddress I2C slave address (PCF8574 or PCF8574A, default = PCF8574_SA0 = 0x40) |
wim | 21:9eb628d9e164 | 697 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 21:9eb628d9e164 | 698 | * @param ctrl LCD controller (default = HD44780) |
wim | 21:9eb628d9e164 | 699 | */ |
wim | 26:bd897a001012 | 700 | TextLCD_I2C(I2C *i2c, char deviceAddress = PCF8574_SA0, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); |
wim | 21:9eb628d9e164 | 701 | |
wim | 21:9eb628d9e164 | 702 | private: |
wim | 29:a3663151aa65 | 703 | |
wim | 29:a3663151aa65 | 704 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) |
wim | 29:a3663151aa65 | 705 | * Set the Enable pin. |
wim | 29:a3663151aa65 | 706 | */ |
wim | 21:9eb628d9e164 | 707 | virtual void _setEnable(bool value); |
wim | 29:a3663151aa65 | 708 | |
wim | 29:a3663151aa65 | 709 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) |
wim | 29:a3663151aa65 | 710 | * Set the RS pin ( 0 = Command, 1 = Data). |
wim | 29:a3663151aa65 | 711 | */ |
wim | 21:9eb628d9e164 | 712 | virtual void _setRS(bool value); |
wim | 29:a3663151aa65 | 713 | |
wim | 29:a3663151aa65 | 714 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) |
wim | 29:a3663151aa65 | 715 | * Set the BL pin (0 = Backlight Off, 1 = Backlight On). |
wim | 29:a3663151aa65 | 716 | */ |
wim | 21:9eb628d9e164 | 717 | virtual void _setBL(bool value); |
wim | 29:a3663151aa65 | 718 | |
wim | 29:a3663151aa65 | 719 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) |
wim | 29:a3663151aa65 | 720 | * Set the databus value (4 bit). |
wim | 29:a3663151aa65 | 721 | */ |
wim | 29:a3663151aa65 | 722 | virtual void _setData(int value); |
wim | 30:033048611c01 | 723 | |
wim | 29:a3663151aa65 | 724 | /** Write data to MCP23008 I2C portexpander |
wim | 29:a3663151aa65 | 725 | * @param reg register to write |
wim | 29:a3663151aa65 | 726 | * @param value data to write |
wim | 29:a3663151aa65 | 727 | * @return none |
wim | 29:a3663151aa65 | 728 | * |
wim | 29:a3663151aa65 | 729 | */ |
wim | 26:bd897a001012 | 730 | void _write_register (int reg, int value); |
wim | 21:9eb628d9e164 | 731 | |
wim | 21:9eb628d9e164 | 732 | //I2C bus |
wim | 21:9eb628d9e164 | 733 | I2C *_i2c; |
wim | 21:9eb628d9e164 | 734 | char _slaveAddress; |
wim | 21:9eb628d9e164 | 735 | |
wim | 21:9eb628d9e164 | 736 | // Internal bus mirror value for serial bus only |
wim | 30:033048611c01 | 737 | char _lcd_bus; |
wim | 21:9eb628d9e164 | 738 | }; |
wim | 21:9eb628d9e164 | 739 | |
wim | 23:d47f226efb24 | 740 | //---------- End TextLCD_I2C ------------ |
wim | 22:35742ec80c24 | 741 | |
wim | 22:35742ec80c24 | 742 | |
wim | 23:d47f226efb24 | 743 | //--------- Start TextLCD_SPI ----------- |
wim | 22:35742ec80c24 | 744 | |
wim | 21:9eb628d9e164 | 745 | /** Create a TextLCD interface using an SPI 74595 portexpander |
wim | 21:9eb628d9e164 | 746 | * |
wim | 21:9eb628d9e164 | 747 | */ |
wim | 21:9eb628d9e164 | 748 | class TextLCD_SPI : public TextLCD_Base { |
wim | 21:9eb628d9e164 | 749 | public: |
wim | 21:9eb628d9e164 | 750 | /** Create a TextLCD interface using an SPI 74595 portexpander |
wim | 21:9eb628d9e164 | 751 | * |
wim | 21:9eb628d9e164 | 752 | * @param spi SPI Bus |
wim | 21:9eb628d9e164 | 753 | * @param cs chip select pin (active low) |
wim | 21:9eb628d9e164 | 754 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 21:9eb628d9e164 | 755 | * @param ctrl LCD controller (default = HD44780) |
wim | 21:9eb628d9e164 | 756 | */ |
wim | 21:9eb628d9e164 | 757 | TextLCD_SPI(SPI *spi, PinName cs, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); |
wim | 21:9eb628d9e164 | 758 | |
wim | 21:9eb628d9e164 | 759 | private: |
wim | 29:a3663151aa65 | 760 | |
wim | 29:a3663151aa65 | 761 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) |
wim | 29:a3663151aa65 | 762 | * Set the Enable pin. |
wim | 29:a3663151aa65 | 763 | */ |
wim | 21:9eb628d9e164 | 764 | virtual void _setEnable(bool value); |
wim | 29:a3663151aa65 | 765 | |
wim | 29:a3663151aa65 | 766 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) |
wim | 29:a3663151aa65 | 767 | * Set the RS pin ( 0 = Command, 1 = Data). |
wim | 29:a3663151aa65 | 768 | */ |
wim | 21:9eb628d9e164 | 769 | virtual void _setRS(bool value); |
wim | 29:a3663151aa65 | 770 | |
wim | 29:a3663151aa65 | 771 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) |
wim | 29:a3663151aa65 | 772 | * Set the BL pin (0 = Backlight Off, 1 = Backlight On). |
wim | 29:a3663151aa65 | 773 | */ |
wim | 21:9eb628d9e164 | 774 | virtual void _setBL(bool value); |
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 databus value (4 bit). |
wim | 29:a3663151aa65 | 778 | */ |
wim | 21:9eb628d9e164 | 779 | virtual void _setData(int value); |
wim | 29:a3663151aa65 | 780 | |
wim | 29:a3663151aa65 | 781 | /** Implementation of Low level writes to LCD Bus (serial expander) |
wim | 29:a3663151aa65 | 782 | * Set the CS pin (0 = select, 1 = deselect). |
wim | 29:a3663151aa65 | 783 | */ |
wim | 21:9eb628d9e164 | 784 | virtual void _setCS(bool value); |
wim | 21:9eb628d9e164 | 785 | |
wim | 29:a3663151aa65 | 786 | ///** Low level writes to LCD serial bus only (serial expander) |
wim | 29:a3663151aa65 | 787 | // */ |
wim | 29:a3663151aa65 | 788 | // void _writeBus(); |
wim | 21:9eb628d9e164 | 789 | |
wim | 21:9eb628d9e164 | 790 | // SPI bus |
wim | 21:9eb628d9e164 | 791 | SPI *_spi; |
wim | 21:9eb628d9e164 | 792 | DigitalOut _cs; |
wim | 21:9eb628d9e164 | 793 | |
wim | 21:9eb628d9e164 | 794 | // Internal bus mirror value for serial bus only |
wim | 21:9eb628d9e164 | 795 | char _lcd_bus; |
wim | 21:9eb628d9e164 | 796 | }; |
wim | 21:9eb628d9e164 | 797 | |
wim | 23:d47f226efb24 | 798 | //---------- End TextLCD_SPI ------------ |
wim | 21:9eb628d9e164 | 799 | |
Sissors | 24:fb3399713710 | 800 | |
wim | 26:bd897a001012 | 801 | //--------- Start TextLCD_SPI_N ----------- |
Sissors | 24:fb3399713710 | 802 | |
wim | 30:033048611c01 | 803 | /** Create a TextLCD interface using a controller with native SPI4 interface |
Sissors | 24:fb3399713710 | 804 | * |
Sissors | 24:fb3399713710 | 805 | */ |
wim | 25:6162b31128c9 | 806 | class TextLCD_SPI_N : public TextLCD_Base { |
Sissors | 24:fb3399713710 | 807 | public: |
wim | 30:033048611c01 | 808 | /** Create a TextLCD interface using a controller with native SPI4 interface |
Sissors | 24:fb3399713710 | 809 | * |
Sissors | 24:fb3399713710 | 810 | * @param spi SPI Bus |
Sissors | 24:fb3399713710 | 811 | * @param cs chip select pin (active low) |
Sissors | 24:fb3399713710 | 812 | * @param rs Instruction/data control line |
Sissors | 24:fb3399713710 | 813 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
Sissors | 24:fb3399713710 | 814 | * @param bl Backlight control line (optional, default = NC) |
wim | 26:bd897a001012 | 815 | * @param ctrl LCD controller (default = ST7032_3V3) |
Sissors | 24:fb3399713710 | 816 | */ |
wim | 26:bd897a001012 | 817 | TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3); |
wim | 25:6162b31128c9 | 818 | virtual ~TextLCD_SPI_N(void); |
Sissors | 24:fb3399713710 | 819 | |
Sissors | 24:fb3399713710 | 820 | private: |
wim | 29:a3663151aa65 | 821 | |
wim | 29:a3663151aa65 | 822 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 29:a3663151aa65 | 823 | * Set the Enable pin. |
wim | 29:a3663151aa65 | 824 | */ |
Sissors | 24:fb3399713710 | 825 | virtual void _setEnable(bool value); |
wim | 29:a3663151aa65 | 826 | |
wim | 29:a3663151aa65 | 827 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 29:a3663151aa65 | 828 | * Set the RS pin ( 0 = Command, 1 = Data). |
wim | 29:a3663151aa65 | 829 | */ |
Sissors | 24:fb3399713710 | 830 | virtual void _setRS(bool value); |
wim | 29:a3663151aa65 | 831 | |
wim | 29:a3663151aa65 | 832 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 29:a3663151aa65 | 833 | * Set the BL pin (0 = Backlight Off, 1 = Backlight On). |
wim | 29:a3663151aa65 | 834 | */ |
Sissors | 24:fb3399713710 | 835 | virtual void _setBL(bool value); |
wim | 29:a3663151aa65 | 836 | |
wim | 29:a3663151aa65 | 837 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 29:a3663151aa65 | 838 | * Set the databus value (4 bit). |
wim | 29:a3663151aa65 | 839 | */ |
Sissors | 24:fb3399713710 | 840 | virtual void _setData(int value); |
wim | 29:a3663151aa65 | 841 | |
wim | 29:a3663151aa65 | 842 | /** Low level writes to LCD serial bus only (serial native) |
wim | 29:a3663151aa65 | 843 | */ |
Sissors | 24:fb3399713710 | 844 | virtual void _writeByte(int value); |
Sissors | 24:fb3399713710 | 845 | |
Sissors | 24:fb3399713710 | 846 | // SPI bus |
Sissors | 24:fb3399713710 | 847 | SPI *_spi; |
Sissors | 24:fb3399713710 | 848 | DigitalOut _cs; |
Sissors | 24:fb3399713710 | 849 | DigitalOut _rs; |
wim | 30:033048611c01 | 850 | |
wim | 30:033048611c01 | 851 | //Backlight |
Sissors | 24:fb3399713710 | 852 | DigitalOut *_bl; |
Sissors | 24:fb3399713710 | 853 | }; |
Sissors | 24:fb3399713710 | 854 | |
wim | 25:6162b31128c9 | 855 | //---------- End TextLCD_SPI_N ------------ |
Sissors | 24:fb3399713710 | 856 | |
wim | 26:bd897a001012 | 857 | |
wim | 30:033048611c01 | 858 | #if(0) |
wim | 30:033048611c01 | 859 | //Code checked out on logic analyser. Not yet tested on hardware.. |
wim | 30:033048611c01 | 860 | |
wim | 30:033048611c01 | 861 | //------- Start TextLCD_SPI_N_3_9 --------- |
wim | 30:033048611c01 | 862 | |
wim | 30:033048611c01 | 863 | /** Create a TextLCD interface using a controller with native SPI3 9 bits interface |
wim | 30:033048611c01 | 864 | * Note: current mbed libs only support SPI 9 bit mode for NXP platforms |
wim | 30:033048611c01 | 865 | * |
wim | 30:033048611c01 | 866 | */ |
wim | 30:033048611c01 | 867 | class TextLCD_SPI_N_3_9 : public TextLCD_Base { |
wim | 30:033048611c01 | 868 | public: |
wim | 30:033048611c01 | 869 | /** Create a TextLCD interface using a controller with native SPI3 9 bits interface |
wim | 30:033048611c01 | 870 | * Note: current mbed libs only support SPI 9 bit mode for NXP platforms |
wim | 30:033048611c01 | 871 | * |
wim | 30:033048611c01 | 872 | * @param spi SPI Bus |
wim | 30:033048611c01 | 873 | * @param cs chip select pin (active low) |
wim | 30:033048611c01 | 874 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 30:033048611c01 | 875 | * @param bl Backlight control line (optional, default = NC) |
wim | 30:033048611c01 | 876 | * @param ctrl LCD controller (default = AIP31068) |
wim | 30:033048611c01 | 877 | */ |
wim | 30:033048611c01 | 878 | TextLCD_SPI_N_3_9(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = AIP31068); |
wim | 30:033048611c01 | 879 | virtual ~TextLCD_SPI_N_3_9(void); |
wim | 30:033048611c01 | 880 | |
wim | 30:033048611c01 | 881 | private: |
wim | 30:033048611c01 | 882 | |
wim | 30:033048611c01 | 883 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 30:033048611c01 | 884 | * Set the Enable pin. |
wim | 30:033048611c01 | 885 | */ |
wim | 30:033048611c01 | 886 | virtual void _setEnable(bool value); |
wim | 30:033048611c01 | 887 | |
wim | 30:033048611c01 | 888 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 30:033048611c01 | 889 | * Set the RS pin ( 0 = Command, 1 = Data). |
wim | 30:033048611c01 | 890 | */ |
wim | 30:033048611c01 | 891 | virtual void _setRS(bool value); |
wim | 30:033048611c01 | 892 | |
wim | 30:033048611c01 | 893 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 30:033048611c01 | 894 | * Set the BL pin (0 = Backlight Off, 1 = Backlight On). |
wim | 30:033048611c01 | 895 | */ |
wim | 30:033048611c01 | 896 | virtual void _setBL(bool value); |
wim | 30:033048611c01 | 897 | |
wim | 30:033048611c01 | 898 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 30:033048611c01 | 899 | * Set the databus value (4 bit). |
wim | 30:033048611c01 | 900 | */ |
wim | 30:033048611c01 | 901 | virtual void _setData(int value); |
wim | 30:033048611c01 | 902 | |
wim | 30:033048611c01 | 903 | /** Low level writes to LCD serial bus only (serial native) |
wim | 30:033048611c01 | 904 | */ |
wim | 30:033048611c01 | 905 | virtual void _writeByte(int value); |
wim | 30:033048611c01 | 906 | |
wim | 30:033048611c01 | 907 | // SPI bus |
wim | 30:033048611c01 | 908 | SPI *_spi; |
wim | 30:033048611c01 | 909 | DigitalOut _cs; |
wim | 30:033048611c01 | 910 | |
wim | 30:033048611c01 | 911 | // controlbyte to select between data and command. Internal value for serial bus only |
wim | 30:033048611c01 | 912 | char _controlbyte; |
wim | 30:033048611c01 | 913 | |
wim | 30:033048611c01 | 914 | //Backlight |
wim | 30:033048611c01 | 915 | DigitalOut *_bl; |
wim | 30:033048611c01 | 916 | }; |
wim | 30:033048611c01 | 917 | |
wim | 30:033048611c01 | 918 | //-------- End TextLCD_SPI_N_3_9 ---------- |
wim | 30:033048611c01 | 919 | #endif |
wim | 30:033048611c01 | 920 | |
wim | 30:033048611c01 | 921 | |
wim | 30:033048611c01 | 922 | #if(0) |
wim | 30:033048611c01 | 923 | //Code checked out on logic analyser. Not yet tested on hardware.. |
wim | 30:033048611c01 | 924 | |
wim | 30:033048611c01 | 925 | //------- Start TextLCD_SPI_N_3_10 --------- |
wim | 30:033048611c01 | 926 | |
wim | 30:033048611c01 | 927 | /** Create a TextLCD interface using a controller with native SPI3 10 bits interface |
wim | 30:033048611c01 | 928 | * Note: current mbed libs only support SPI 10 bit mode for NXP platforms |
wim | 30:033048611c01 | 929 | * |
wim | 30:033048611c01 | 930 | */ |
wim | 30:033048611c01 | 931 | class TextLCD_SPI_N_3_10 : public TextLCD_Base { |
wim | 30:033048611c01 | 932 | public: |
wim | 30:033048611c01 | 933 | /** Create a TextLCD interface using a controller with native SPI3 10 bits interface |
wim | 30:033048611c01 | 934 | * Note: current mbed libs only support SPI 10 bit mode for NXP platforms |
wim | 30:033048611c01 | 935 | * |
wim | 30:033048611c01 | 936 | * @param spi SPI Bus |
wim | 30:033048611c01 | 937 | * @param cs chip select pin (active low) |
wim | 30:033048611c01 | 938 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 30:033048611c01 | 939 | * @param bl Backlight control line (optional, default = NC) |
wim | 30:033048611c01 | 940 | * @param ctrl LCD controller (default = AIP31068) |
wim | 30:033048611c01 | 941 | */ |
wim | 30:033048611c01 | 942 | TextLCD_SPI_N_3_10(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = AIP31068); |
wim | 30:033048611c01 | 943 | virtual ~TextLCD_SPI_N_3_10(void); |
wim | 30:033048611c01 | 944 | |
wim | 30:033048611c01 | 945 | private: |
wim | 30:033048611c01 | 946 | |
wim | 30:033048611c01 | 947 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 30:033048611c01 | 948 | * Set the Enable pin. |
wim | 30:033048611c01 | 949 | */ |
wim | 30:033048611c01 | 950 | virtual void _setEnable(bool value); |
wim | 30:033048611c01 | 951 | |
wim | 30:033048611c01 | 952 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 30:033048611c01 | 953 | * Set the RS pin ( 0 = Command, 1 = Data). |
wim | 30:033048611c01 | 954 | */ |
wim | 30:033048611c01 | 955 | virtual void _setRS(bool value); |
wim | 30:033048611c01 | 956 | |
wim | 30:033048611c01 | 957 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 30:033048611c01 | 958 | * Set the BL pin (0 = Backlight Off, 1 = Backlight On). |
wim | 30:033048611c01 | 959 | */ |
wim | 30:033048611c01 | 960 | virtual void _setBL(bool value); |
wim | 30:033048611c01 | 961 | |
wim | 30:033048611c01 | 962 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 30:033048611c01 | 963 | * Set the databus value (4 bit). |
wim | 30:033048611c01 | 964 | */ |
wim | 30:033048611c01 | 965 | virtual void _setData(int value); |
wim | 30:033048611c01 | 966 | |
wim | 30:033048611c01 | 967 | /** Low level writes to LCD serial bus only (serial native) |
wim | 30:033048611c01 | 968 | */ |
wim | 30:033048611c01 | 969 | virtual void _writeByte(int value); |
wim | 30:033048611c01 | 970 | |
wim | 30:033048611c01 | 971 | // SPI bus |
wim | 30:033048611c01 | 972 | SPI *_spi; |
wim | 30:033048611c01 | 973 | DigitalOut _cs; |
wim | 30:033048611c01 | 974 | |
wim | 30:033048611c01 | 975 | // controlbyte to select between data and command. Internal value for serial bus only |
wim | 30:033048611c01 | 976 | char _controlbyte; |
wim | 30:033048611c01 | 977 | |
wim | 30:033048611c01 | 978 | //Backlight |
wim | 30:033048611c01 | 979 | DigitalOut *_bl; |
wim | 30:033048611c01 | 980 | }; |
wim | 30:033048611c01 | 981 | |
wim | 30:033048611c01 | 982 | //-------- End TextLCD_SPI_N_3_10 ---------- |
wim | 30:033048611c01 | 983 | #endif |
wim | 30:033048611c01 | 984 | |
wim | 30:033048611c01 | 985 | |
wim | 26:bd897a001012 | 986 | //--------- Start TextLCD_I2C_N ----------- |
wim | 26:bd897a001012 | 987 | |
wim | 26:bd897a001012 | 988 | /** Create a TextLCD interface using a controller with native I2C interface |
wim | 26:bd897a001012 | 989 | * |
wim | 26:bd897a001012 | 990 | */ |
wim | 26:bd897a001012 | 991 | class TextLCD_I2C_N : public TextLCD_Base { |
wim | 26:bd897a001012 | 992 | public: |
wim | 26:bd897a001012 | 993 | /** Create a TextLCD interface using a controller with native I2C interface |
wim | 26:bd897a001012 | 994 | * |
wim | 26:bd897a001012 | 995 | * @param i2c I2C Bus |
wim | 28:30fa94f7341c | 996 | * @param deviceAddress I2C slave address (default = ST7032_SA = 0x7C) |
wim | 26:bd897a001012 | 997 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 28:30fa94f7341c | 998 | * @param bl Backlight control line (optional, default = NC) |
wim | 26:bd897a001012 | 999 | * @param ctrl LCD controller (default = ST7032_3V3) |
wim | 26:bd897a001012 | 1000 | */ |
wim | 28:30fa94f7341c | 1001 | TextLCD_I2C_N(I2C *i2c, char deviceAddress = ST7032_SA, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3); |
wim | 26:bd897a001012 | 1002 | virtual ~TextLCD_I2C_N(void); |
wim | 26:bd897a001012 | 1003 | |
wim | 26:bd897a001012 | 1004 | private: |
wim | 29:a3663151aa65 | 1005 | |
wim | 29:a3663151aa65 | 1006 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 29:a3663151aa65 | 1007 | * Set the Enable pin. |
wim | 29:a3663151aa65 | 1008 | */ |
wim | 26:bd897a001012 | 1009 | virtual void _setEnable(bool value); |
wim | 29:a3663151aa65 | 1010 | |
wim | 29:a3663151aa65 | 1011 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 29:a3663151aa65 | 1012 | * Set the RS pin ( 0 = Command, 1 = Data). |
wim | 29:a3663151aa65 | 1013 | */ |
wim | 26:bd897a001012 | 1014 | virtual void _setRS(bool value); |
wim | 29:a3663151aa65 | 1015 | |
wim | 29:a3663151aa65 | 1016 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 29:a3663151aa65 | 1017 | * Set the BL pin (0 = Backlight Off, 1 = Backlight On). |
wim | 29:a3663151aa65 | 1018 | */ |
wim | 26:bd897a001012 | 1019 | virtual void _setBL(bool value); |
wim | 29:a3663151aa65 | 1020 | |
wim | 29:a3663151aa65 | 1021 | /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) |
wim | 29:a3663151aa65 | 1022 | * Set the databus value (4 bit). |
wim | 29:a3663151aa65 | 1023 | */ |
wim | 26:bd897a001012 | 1024 | virtual void _setData(int value); |
wim | 29:a3663151aa65 | 1025 | |
wim | 29:a3663151aa65 | 1026 | /** Low level writes to LCD serial bus only (serial native) |
wim | 29:a3663151aa65 | 1027 | */ |
wim | 26:bd897a001012 | 1028 | virtual void _writeByte(int value); |
wim | 26:bd897a001012 | 1029 | |
wim | 26:bd897a001012 | 1030 | //I2C bus |
wim | 26:bd897a001012 | 1031 | I2C *_i2c; |
wim | 26:bd897a001012 | 1032 | char _slaveAddress; |
wim | 26:bd897a001012 | 1033 | |
wim | 28:30fa94f7341c | 1034 | // controlbyte to select between data and command. Internal value for serial bus only |
wim | 28:30fa94f7341c | 1035 | char _controlbyte; |
wim | 28:30fa94f7341c | 1036 | |
wim | 30:033048611c01 | 1037 | //Backlight |
wim | 28:30fa94f7341c | 1038 | DigitalOut *_bl; |
wim | 26:bd897a001012 | 1039 | }; |
wim | 26:bd897a001012 | 1040 | |
wim | 26:bd897a001012 | 1041 | //---------- End TextLCD_I2C_N ------------ |
wim | 26:bd897a001012 | 1042 | |
wim | 26:bd897a001012 | 1043 | |
simon | 1:ac48b187213c | 1044 | #endif |