1

Dependents:   Program_R11

Committer:
wim
Date:
Sat Sep 27 12:38:27 2014 +0000
Revision:
34:e5a0dcb43ecc
Parent:
33:900a94bc7585
Child:
35:311be6444a39
Added support for PT6314 (VFD), added setOrient() method for supported devices (eg SSD1803, US2066), added Double Height lines and 16 UDCs for supported devices. Added separate files for UDC defines and feature/footprint configuration.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 1:ac48b187213c 1 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780
simon 6:e4cb7ddee0d3 2 * Copyright (c) 2007-2010, sford, http://mbed.org
wim 13:24506ba22480 3 * 2013, v01: WH, Added LCD types, fixed LCD address issues, added Cursor and UDCs
wim 15:b70ebfffb258 4 * 2013, v02: WH, Added I2C and SPI bus interfaces
wim 15:b70ebfffb258 5 * 2013, v03: WH, Added support for LCD40x4 which uses 2 controllers
wim 17:652ab113bc2e 6 * 2013, v04: WH, Added support for Display On/Off, improved 4bit bootprocess
wim 18:bd65dc10f27f 7 * 2013, v05: WH, Added support for 8x2B, added some UDCs
wim 19:c747b9e2e7b8 8 * 2013, v06: WH, Added support for devices that use internal DC/DC converters
wim 20:e0da005a777f 9 * 2013, v07: WH, Added support for backlight and include portdefinitions for LCD2004 Module from DFROBOT
wim 21:9eb628d9e164 10 * 2014, v08: WH, Refactored in Base and Derived Classes to deal with mbed lib change regarding 'NC' defined DigitalOut pins
wim 25:6162b31128c9 11 * 2014, v09: WH/EO, Added Class for Native SPI controllers such as ST7032
wim 26:bd897a001012 12 * 2014, v10: WH, Added Class for Native I2C controllers such as ST7032i, Added support for MCP23008 I2C portexpander, Added support for Adafruit module
wim 30:033048611c01 13 * 2014, v11: WH, Added support for native I2C controllers such as PCF21XX, Improved the _initCtrl() method to deal with differences between all supported controllers
wim 32:59c4b8f648d4 14 * 2014, v12: WH, Added support for native I2C controller PCF2119 and native I2C/SPI controllers SSD1803, ST7036, added setContrast method (by JH1PJL) for supported devices (eg ST7032i)
wim 34:e5a0dcb43ecc 15 * 2014, v13: WH, Added support for controllers US2066/SSD1311 (OLED), added setUDCBlink() method for supported devices (eg SSD1803), fixed issue in setPower()
wim 34:e5a0dcb43ecc 16 * 2014, v14: WH, Added support for PT6314 (VFD), added setOrient() method for supported devices (eg SSD1803, US2066), added Double Height lines for supported devices,
wim 34:e5a0dcb43ecc 17 * added 16 UDCs for supported devices (eg PCF2103), moved UDC defines to TextLCD_UDC file, added TextLCD_Config.h for feature and footprint settings.
simon 1:ac48b187213c 18 *
simon 1:ac48b187213c 19 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 1:ac48b187213c 20 * of this software and associated documentation files (the "Software"), to deal
simon 1:ac48b187213c 21 * in the Software without restriction, including without limitation the rights
simon 1:ac48b187213c 22 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 1:ac48b187213c 23 * copies of the Software, and to permit persons to whom the Software is
simon 1:ac48b187213c 24 * furnished to do so, subject to the following conditions:
simon 2:227356c7d12c 25 *
simon 1:ac48b187213c 26 * The above copyright notice and this permission notice shall be included in
simon 1:ac48b187213c 27 * all copies or substantial portions of the Software.
simon 2:227356c7d12c 28 *
simon 1:ac48b187213c 29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 1:ac48b187213c 30 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 1:ac48b187213c 31 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 1:ac48b187213c 32 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 1:ac48b187213c 33 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 1:ac48b187213c 34 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 1:ac48b187213c 35 * THE SOFTWARE.
simon 1:ac48b187213c 36 */
simon 1:ac48b187213c 37
simon 1:ac48b187213c 38 #ifndef MBED_TEXTLCD_H
simon 1:ac48b187213c 39 #define MBED_TEXTLCD_H
simon 1:ac48b187213c 40
simon 1:ac48b187213c 41 #include "mbed.h"
wim 34:e5a0dcb43ecc 42 #include "TextLCD_Config.h"
wim 34:e5a0dcb43ecc 43 #include "TextLCD_UDC.h"
simon 2:227356c7d12c 44
simon 5:a53b3e2d6f1e 45 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
simon 2:227356c7d12c 46 *
wim 34:e5a0dcb43ecc 47 * Currently supports 8x1, 8x2, 12x3, 12x4, 16x1, 16x2, 16x3, 16x4, 20x2, 20x4, 24x1, 24x2, 24x4, 40x2 and 40x4 panels.
wim 27:22d5086f6ba6 48 * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595).
wim 34:e5a0dcb43ecc 49 * Supports some controllers with native I2C or SPI interface. Supports some controllers that provide internal DC/DC converters for VLCD or VLED.
wim 34:e5a0dcb43ecc 50 * Supports some controllers that feature programmable contrast control, powerdown, blinking UDCs and/or top/down orientation modes.
simon 2:227356c7d12c 51 *
simon 2:227356c7d12c 52 * @code
simon 2:227356c7d12c 53 * #include "mbed.h"
simon 2:227356c7d12c 54 * #include "TextLCD.h"
simon 5:a53b3e2d6f1e 55 *
wim 16:c276b75e6585 56 * // I2C Communication
wim 16:c276b75e6585 57 * I2C i2c_lcd(p28,p27); // SDA, SCL
wim 16:c276b75e6585 58 *
wim 16:c276b75e6585 59 * // SPI Communication
wim 16:c276b75e6585 60 * SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK
wim 16:c276b75e6585 61 *
wim 22:35742ec80c24 62 * //TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=HD44780
wim 28:30fa94f7341c 63 * //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, 74595 expander, CS pin, LCD Type
wim 34:e5a0dcb43ecc 64 * TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type
wim 34:e5a0dcb43ecc 65 * //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type (OLED)
wim 27:22d5086f6ba6 66 * //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3
wim 34:e5a0dcb43ecc 67 * //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=ST7032_3V3
wim 34:e5a0dcb43ecc 68 * //TextLCD_SPI_N_3_24 lcd(&spi_lcd, p8, TextLCD::LCD20x4D, NC, TextLCD::SSD1803_3V3); // SPI bus, CS pin, LCDType=LCD20x4D, BL=NC, LCDTCtrl=SSD1803
wim 34:e5a0dcb43ecc 69 * //TextLCD_SPI_N_3_24 lcd(&spi_lcd, p8, TextLCD::LCD20x2, NC, TextLCD::US2066_3V3); // SPI bus, CS pin, LCDType=LCD20x2, BL=NC, LCDTCtrl=US2066 (OLED)
wim 34:e5a0dcb43ecc 70 *
simon 2:227356c7d12c 71 * int main() {
wim 16:c276b75e6585 72 * lcd.printf("Hello World!\n");
simon 2:227356c7d12c 73 * }
simon 2:227356c7d12c 74 * @endcode
simon 2:227356c7d12c 75 */
wim 8:03116f75b66e 76
wim 34:e5a0dcb43ecc 77 //The TextLCD_Config.h file selects hardware interface options to reduce memory footprint
wim 34:e5a0dcb43ecc 78 //and provides Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces.
wim 34:e5a0dcb43ecc 79 //The LCD and serial portexpanders should be wired accordingly.
wim 32:59c4b8f648d4 80
wim 30:033048611c01 81 /* LCD Type information on Rows, Columns and Variant. This information is encoded in
wim 30:033048611c01 82 * an int and used for the LCDType enumerators in order to simplify code maintenance */
wim 30:033048611c01 83 // Columns encoded in b7..b0
wim 30:033048611c01 84 #define LCD_T_COL_MSK 0x000000FF
wim 32:59c4b8f648d4 85 #define LCD_T_C6 0x00000006
wim 30:033048611c01 86 #define LCD_T_C8 0x00000008
wim 30:033048611c01 87 #define LCD_T_C10 0x0000000A
wim 30:033048611c01 88 #define LCD_T_C12 0x0000000C
wim 30:033048611c01 89 #define LCD_T_C16 0x00000010
wim 30:033048611c01 90 #define LCD_T_C20 0x00000014
wim 30:033048611c01 91 #define LCD_T_C24 0x00000018
wim 30:033048611c01 92 #define LCD_T_C32 0x00000020
wim 30:033048611c01 93 #define LCD_T_C40 0x00000028
wim 30:033048611c01 94
wim 30:033048611c01 95 // Rows encoded in b15..b8
wim 30:033048611c01 96 #define LCD_T_ROW_MSK 0x0000FF00
wim 30:033048611c01 97 #define LCD_T_R1 0x00000100
wim 30:033048611c01 98 #define LCD_T_R2 0x00000200
wim 30:033048611c01 99 #define LCD_T_R3 0x00000300
wim 30:033048611c01 100 #define LCD_T_R4 0x00000400
wim 30:033048611c01 101
wim 30:033048611c01 102 // Addressing mode encoded in b19..b16
wim 30:033048611c01 103 #define LCD_T_ADR_MSK 0x000F0000
wim 32:59c4b8f648d4 104 #define LCD_T_A 0x00000000 /*Mode A Default 1, 2 or 4 line display */
wim 32:59c4b8f648d4 105 #define LCD_T_B 0x00010000 /*Mode B, Alternate 8x2 (actually 16x1 display) */
wim 32:59c4b8f648d4 106 #define LCD_T_C 0x00020000 /*Mode C, Alternate 16x1 (actually 8x2 display) */
wim 32:59c4b8f648d4 107 #define LCD_T_D 0x00030000 /*Mode D, Alternate 3 or 4 line display (12x4, 20x4, 24x4) */
wim 32:59c4b8f648d4 108 #define LCD_T_D1 0x00040000 /*Mode D1, Alternate 3 out of 4 line display (12x3, 20x3, 24x3) */
wim 32:59c4b8f648d4 109 #define LCD_T_E 0x00050000 /*Mode E, 40x4 display (actually two 40x2) */
wim 32:59c4b8f648d4 110 #define LCD_T_F 0x00060000 /*Mode F, 16x3 display (actually 24x2) */
wim 32:59c4b8f648d4 111 #define LCD_T_G 0x00070000 /*Mode G, 16x3 display */
wim 30:033048611c01 112
wim 30:033048611c01 113 /* LCD Ctrl information on interface support and features. This information is encoded in
wim 30:033048611c01 114 * an int and used for the LCDCtrl enumerators in order to simplify code maintenance */
wim 30:033048611c01 115 // Interface encoded in b31..b24
wim 30:033048611c01 116 #define LCD_C_BUS_MSK 0xFF000000
wim 32:59c4b8f648d4 117 #define LCD_C_PAR 0x01000000 /*Parallel 4 or 8 bit data, E pin, RS pin, RW=GND */
wim 30:033048611c01 118 #define LCD_C_SPI3_9 0x02000000 /*SPI 3 line (MOSI, SCL, CS pins), 9 bits (RS + 8 Data) */
wim 30:033048611c01 119 #define LCD_C_SPI3_10 0x04000000 /*SPI 3 line (MOSI, SCL, CS pins), 10 bits (RS, RW + 8 Data) */
wim 32:59c4b8f648d4 120 #define LCD_C_SPI3_16 0x08000000 /*SPI 3 line (MOSI, SCL, CS pins), 16 bits (RS, RW + 8 Data) */
wim 32:59c4b8f648d4 121 #define LCD_C_SPI3_24 0x10000000 /*SPI 3 line (MOSI, SCL, CS pins), 24 bits (RS, RW + 8 Data) */
wim 32:59c4b8f648d4 122 #define LCD_C_SPI4 0x20000000 /*SPI 4 line (MOSI, SCL, CS, RS pin), RS pin + 8 Data */
wim 32:59c4b8f648d4 123 #define LCD_C_I2C 0x40000000 /*I2C (SDA, SCL pin), 8 control bits (Co, RS, RW) + 8 Data */
wim 30:033048611c01 124 // Features encoded in b23..b16
wim 30:033048611c01 125 #define LCD_C_FTR_MSK 0x00FF0000
wim 30:033048611c01 126 #define LCD_C_BST 0x00010000 /*Booster */
wim 32:59c4b8f648d4 127 #define LCD_C_CTR 0x00020000 /*Contrast Control */
wim 32:59c4b8f648d4 128 #define LCD_C_ICN 0x00040000 /*Icons */
wim 32:59c4b8f648d4 129 #define LCD_C_PDN 0x00080000 /*Power Down */
wim 32:59c4b8f648d4 130
wim 32:59c4b8f648d4 131
wim 11:9ec02df863a1 132 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
wim 11:9ec02df863a1 133 *
wim 33:900a94bc7585 134 * @brief Currently supports 8x1, 8x2, 12x2, 12x3, 12x4, 16x1, 16x2, 16x3, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
wim 27:22d5086f6ba6 135 * 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 136 *
wim 11:9ec02df863a1 137 */
wim 34:e5a0dcb43ecc 138 #if(LCD_PRINTF == 1)
wim 21:9eb628d9e164 139 class TextLCD_Base : public Stream {
wim 34:e5a0dcb43ecc 140 #else
wim 34:e5a0dcb43ecc 141 class TextLCD_Base{
wim 34:e5a0dcb43ecc 142 #endif
simon 1:ac48b187213c 143 public:
simon 1:ac48b187213c 144
simon 2:227356c7d12c 145 /** LCD panel format */
wim 33:900a94bc7585 146 // The commented out types exist but have not yet been tested with the library
simon 1:ac48b187213c 147 enum LCDType {
wim 32:59c4b8f648d4 148 // LCD6x1 = (LCD_T_A | LCD_T_C6 | LCD_T_R1), /**< 6x1 LCD panel */
wim 32:59c4b8f648d4 149 // LCD6x2 = (LCD_T_A | LCD_T_C6 | LCD_T_R2), /**< 6x2 LCD panel */
wim 30:033048611c01 150 LCD8x1 = (LCD_T_A | LCD_T_C8 | LCD_T_R1), /**< 8x1 LCD panel */
wim 30:033048611c01 151 LCD8x2 = (LCD_T_A | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel */
wim 30:033048611c01 152 LCD8x2B = (LCD_T_D | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel (actually 16x1) */
wim 34:e5a0dcb43ecc 153 LCD12x1 = (LCD_T_A | LCD_T_C12 | LCD_T_R1), /**< 12x1 LCD panel */
wim 30:033048611c01 154 LCD12x2 = (LCD_T_A | LCD_T_C12 | LCD_T_R2), /**< 12x2 LCD panel */
wim 30:033048611c01 155 LCD12x3D = (LCD_T_D | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX */
wim 30:033048611c01 156 LCD12x3D1 = (LCD_T_D1 | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX */
wim 32:59c4b8f648d4 157 // LCD12x3G = (LCD_T_G | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode ST7036 */
wim 30:033048611c01 158 LCD12x4 = (LCD_T_A | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel */
wim 30:033048611c01 159 LCD12x4D = (LCD_T_B | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel, special mode PCF21XX */
wim 30:033048611c01 160 LCD16x1 = (LCD_T_A | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel */
wim 30:033048611c01 161 LCD16x1C = (LCD_T_C | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel (actually 8x2) */
wim 30:033048611c01 162 LCD16x2 = (LCD_T_A | LCD_T_C16 | LCD_T_R2), /**< 16x2 LCD panel (default) */
wim 30:033048611c01 163 // LCD16x2B = (LCD_T_B | LCD_T_C16 | LCD_T_R2), /**< 16x2 LCD panel, alternate addressing, wrong.. */
wim 32:59c4b8f648d4 164 LCD16x3D = (LCD_T_D | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */
wim 32:59c4b8f648d4 165 // LCD16x3D1 = (LCD_T_D1 | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */
wim 32:59c4b8f648d4 166 LCD16x3F = (LCD_T_F | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel (actually 24x2) */
wim 32:59c4b8f648d4 167 LCD16x3G = (LCD_T_G | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode ST7036 */
wim 30:033048611c01 168 LCD16x4 = (LCD_T_A | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel */
wim 32:59c4b8f648d4 169 // LCD16x4D = (LCD_T_D | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel, special mode SSD1803 */
wim 34:e5a0dcb43ecc 170 LCD20x1 = (LCD_T_A | LCD_T_C20 | LCD_T_R1), /**< 20x1 LCD panel */
wim 30:033048611c01 171 LCD20x2 = (LCD_T_A | LCD_T_C20 | LCD_T_R2), /**< 20x2 LCD panel */
wim 32:59c4b8f648d4 172 // LCD20x3 = (LCD_T_A | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel */
wim 32:59c4b8f648d4 173 // LCD20x3D = (LCD_T_D | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803 */
wim 32:59c4b8f648d4 174 // LCD20x3D1 = (LCD_T_D1 | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803 */
wim 30:033048611c01 175 LCD20x4 = (LCD_T_A | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel */
wim 32:59c4b8f648d4 176 LCD20x4D = (LCD_T_D | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel, special mode SSD1803 */
wim 30:033048611c01 177 LCD24x1 = (LCD_T_A | LCD_T_C24 | LCD_T_R1), /**< 24x1 LCD panel */
wim 30:033048611c01 178 LCD24x2 = (LCD_T_A | LCD_T_C24 | LCD_T_R2), /**< 24x2 LCD panel */
wim 32:59c4b8f648d4 179 // LCD24x3D = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */
wim 32:59c4b8f648d4 180 // LCD24x3D1 = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */
wim 30:033048611c01 181 LCD24x4D = (LCD_T_D | LCD_T_C24 | LCD_T_R4), /**< 24x4 LCD panel, special mode KS0078 */
wim 33:900a94bc7585 182 // LCD32x1 = (LCD_T_A | LCD_T_C32 | LCD_T_R1), /**< 32x1 LCD panel */
wim 33:900a94bc7585 183 // LCD32x1C = (LCD_T_C | LCD_T_C32 | LCD_T_R1), /**< 32x1 LCD panel (actually 16x2) */
wim 32:59c4b8f648d4 184 // LCD32x2 = (LCD_T_A | LCD_T_C32 | LCD_T_R2), /**< 32x2 LCD panel */
wim 32:59c4b8f648d4 185 // LCD32x4 = (LCD_T_A | LCD_T_C32 | LCD_T_R4), /**< 32x4 LCD panel */
wim 30:033048611c01 186 // LCD40x1 = (LCD_T_A | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel */
wim 33:900a94bc7585 187 // LCD40x1C = (LCD_T_C | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel (actually 20x2) */
wim 30:033048611c01 188 LCD40x2 = (LCD_T_A | LCD_T_C40 | LCD_T_R2), /**< 40x2 LCD panel */
wim 30:033048611c01 189 LCD40x4 = (LCD_T_E | LCD_T_C40 | LCD_T_R4) /**< 40x4 LCD panel, Two controller version */
wim 30:033048611c01 190 };
wim 30:033048611c01 191
wim 30:033048611c01 192
wim 30:033048611c01 193 /** LCD Controller Device */
wim 30:033048611c01 194 enum LCDCtrl {
wim 34:e5a0dcb43ecc 195 HD44780 = 0 | LCD_C_PAR, /**< HD44780 or full equivalent (default) */
wim 34:e5a0dcb43ecc 196 WS0010 = 1 | (LCD_C_PAR | LCD_C_SPI3_10 | LCD_C_PDN), /**< WS0010/RS0010 OLED Controller, 4/8 bit, SPI3 */
wim 34:e5a0dcb43ecc 197 ST7036_3V3 = 2 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7036 3V3 with Booster, 4/8 bit, SPI4, I2C */
wim 34:e5a0dcb43ecc 198 ST7036_5V = 3 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7036 5V no Booster, 4/8 bit, SPI4, I2C */
wim 34:e5a0dcb43ecc 199 ST7032_3V3 = 4 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7032 3V3 with Booster, 4/8 bit, SPI4, I2C */
wim 34:e5a0dcb43ecc 200 ST7032_5V = 5 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_CTR), /**< ST7032 5V no Booster, 4/8 bit, SPI4, I2C */
wim 34:e5a0dcb43ecc 201 KS0078 = 6 | (LCD_C_PAR | LCD_C_SPI3_24), /**< KS0078 24x4 support, 4/8 bit, SPI3 */
wim 34:e5a0dcb43ecc 202 PCF2103_3V3 = 7 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2103 3V3 no Booster, 4/8 bit, I2C */
wim 34:e5a0dcb43ecc 203 PCF2113_3V3 = 8 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2113 3V3 with Booster, 4/8 bit, I2C */
wim 34:e5a0dcb43ecc 204 PCF2116_3V3 = 9 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST), /**< PCF2116 3V3 with Booster, 4/8 bit, I2C */
wim 34:e5a0dcb43ecc 205 PCF2116_5V = 10 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2116 5V no Booster, 4/8 bit, I2C */
wim 34:e5a0dcb43ecc 206 PCF2119_3V3 = 11 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2119 3V3 with Booster, 4/8 bit, I2C */
wim 34:e5a0dcb43ecc 207 // PCF2119_5V = 12 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2119 5V no Booster, 4/8 bit, I2C */
wim 34:e5a0dcb43ecc 208 AIP31068 = 13 | (LCD_C_SPI3_9 | LCD_C_I2C | LCD_C_BST), /**< AIP31068 I2C, SPI3 */
wim 34:e5a0dcb43ecc 209 SSD1803_3V3 = 14 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_PDN), /**< SSD1803 3V3 with Booster, 4/8 bit, I2C, SPI3 */
wim 34:e5a0dcb43ecc 210 // SSD1803_5V = 15 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_PDN), /**< SSD1803 3V3 with Booster, 4/8 bit, I2C, SPI3 */
wim 34:e5a0dcb43ecc 211 US2066_3V3 = 16 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_CTR | LCD_C_PDN), /**< US2066/SSD1311 3V3, 4/8 bit, I2C, SPI3 */
wim 34:e5a0dcb43ecc 212 PT6314 = 17 | (LCD_C_PAR | LCD_C_SPI3_16 | LCD_C_CTR), /**< PT6314 VFD, 4/8 bit, SPI3 */
wim 34:e5a0dcb43ecc 213 // AC780 = 18 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_PDN) /**< AC780/KS0066i 4/8 bit, SPI, I2C */
wim 34:e5a0dcb43ecc 214 // WS0012 = 19 | (LCD_C_PAR | LCD_C_SPI3_10 | LCD_C_I2C | LCD_C_PDN) /**< WS0012 4/8 bit, SPI, I2C */
wim 30:033048611c01 215 };
wim 30:033048611c01 216
wim 30:033048611c01 217
wim 10:dd9b3a696acd 218 /** LCD Cursor control */
wim 10:dd9b3a696acd 219 enum LCDCursor {
wim 17:652ab113bc2e 220 CurOff_BlkOff = 0x00, /**< Cursor Off, Blinking Char Off */
wim 17:652ab113bc2e 221 CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */
wim 17:652ab113bc2e 222 CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */
wim 17:652ab113bc2e 223 CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */
wim 17:652ab113bc2e 224 };
wim 17:652ab113bc2e 225
wim 17:652ab113bc2e 226 /** LCD Display control */
wim 17:652ab113bc2e 227 enum LCDMode {
wim 17:652ab113bc2e 228 DispOff = 0x00, /**< Display Off */
wim 17:652ab113bc2e 229 DispOn = 0x04 /**< Display On */
wim 10:dd9b3a696acd 230 };
wim 10:dd9b3a696acd 231
wim 20:e0da005a777f 232 /** LCD Backlight control */
wim 20:e0da005a777f 233 enum LCDBacklight {
wim 20:e0da005a777f 234 LightOff, /**< Backlight Off */
wim 20:e0da005a777f 235 LightOn /**< Backlight On */
wim 20:e0da005a777f 236 };
wim 10:dd9b3a696acd 237
wim 33:900a94bc7585 238 /** LCD Blink control (UDC), supported for some Controllers */
wim 33:900a94bc7585 239 enum LCDBlink {
wim 33:900a94bc7585 240 BlinkOff, /**< Blink Off */
wim 33:900a94bc7585 241 BlinkOn /**< Blink On */
wim 33:900a94bc7585 242 };
wim 33:900a94bc7585 243
wim 33:900a94bc7585 244 /** LCD Orientation control, supported for some Controllers */
wim 33:900a94bc7585 245 enum LCDOrient {
wim 33:900a94bc7585 246 Top, /**< Top view */
wim 33:900a94bc7585 247 Bottom /**< Upside down view */
wim 33:900a94bc7585 248 };
wim 33:900a94bc7585 249
wim 34:e5a0dcb43ecc 250 /** LCD BigFont control, supported for some Controllers */
wim 34:e5a0dcb43ecc 251 enum LCDBigFont {
wim 34:e5a0dcb43ecc 252 None, /**< no lines */
wim 34:e5a0dcb43ecc 253 TopLine, /**< 1+2 line */
wim 34:e5a0dcb43ecc 254 CenterLine, /**< 2+3 line */
wim 34:e5a0dcb43ecc 255 BottomLine, /**< 2+3 line or 3+4 line */
wim 34:e5a0dcb43ecc 256 TopBottomLine /**< 1+2 line and 3+4 line */
wim 34:e5a0dcb43ecc 257 };
wim 33:900a94bc7585 258
wim 34:e5a0dcb43ecc 259
wim 34:e5a0dcb43ecc 260 #if(LCD_PRINTF != 1)
wim 34:e5a0dcb43ecc 261 /** Write a character to the LCD
wim 34:e5a0dcb43ecc 262 *
wim 34:e5a0dcb43ecc 263 * @param c The character to write to the display
wim 34:e5a0dcb43ecc 264 */
wim 34:e5a0dcb43ecc 265 int putc(int c);
wim 34:e5a0dcb43ecc 266
wim 34:e5a0dcb43ecc 267 /** Write a raw string to the LCD
wim 34:e5a0dcb43ecc 268 *
wim 34:e5a0dcb43ecc 269 * @param string text, may be followed by variables to emulate formatting the string.
wim 34:e5a0dcb43ecc 270 * However, printf formatting is NOT supported and variables will be ignored!
wim 34:e5a0dcb43ecc 271 */
wim 34:e5a0dcb43ecc 272 int printf(const char* text, ...);
wim 34:e5a0dcb43ecc 273 #else
simon 2:227356c7d12c 274 #if DOXYGEN_ONLY
simon 2:227356c7d12c 275 /** Write a character to the LCD
simon 2:227356c7d12c 276 *
simon 2:227356c7d12c 277 * @param c The character to write to the display
simon 2:227356c7d12c 278 */
simon 2:227356c7d12c 279 int putc(int c);
simon 2:227356c7d12c 280
wim 34:e5a0dcb43ecc 281 /** Write a formatted string to the LCD
simon 2:227356c7d12c 282 *
simon 2:227356c7d12c 283 * @param format A printf-style format string, followed by the
wim 34:e5a0dcb43ecc 284 * variables to use in formatting the string.
simon 2:227356c7d12c 285 */
wim 34:e5a0dcb43ecc 286 int printf(const char* format, ...);
simon 2:227356c7d12c 287 #endif
wim 34:e5a0dcb43ecc 288
wim 34:e5a0dcb43ecc 289 #endif
simon 2:227356c7d12c 290
wim 29:a3663151aa65 291 /** Locate cursor to a screen column and row
simon 2:227356c7d12c 292 *
simon 2:227356c7d12c 293 * @param column The horizontal position from the left, indexed from 0
simon 2:227356c7d12c 294 * @param row The vertical position from the top, indexed from 0
simon 2:227356c7d12c 295 */
simon 1:ac48b187213c 296 void locate(int column, int row);
simon 2:227356c7d12c 297
wim 10:dd9b3a696acd 298 /** Return the memoryaddress of screen column and row location
wim 10:dd9b3a696acd 299 *
wim 10:dd9b3a696acd 300 * @param column The horizontal position from the left, indexed from 0
wim 10:dd9b3a696acd 301 * @param row The vertical position from the top, indexed from 0
wim 10:dd9b3a696acd 302 * @param return The memoryaddress of screen column and row location
wim 10:dd9b3a696acd 303 */
wim 30:033048611c01 304 int getAddress(int column, int row);
wim 10:dd9b3a696acd 305
wim 10:dd9b3a696acd 306 /** Set the memoryaddress of screen column and row location
wim 10:dd9b3a696acd 307 *
wim 10:dd9b3a696acd 308 * @param column The horizontal position from the left, indexed from 0
wim 10:dd9b3a696acd 309 * @param row The vertical position from the top, indexed from 0
wim 10:dd9b3a696acd 310 */
wim 9:0893d986e717 311 void setAddress(int column, int row);
wim 9:0893d986e717 312
wim 22:35742ec80c24 313 /** Clear the screen and locate to 0,0
wim 22:35742ec80c24 314 */
simon 1:ac48b187213c 315 void cls();
simon 2:227356c7d12c 316
wim 10:dd9b3a696acd 317 /** Return the number of rows
wim 10:dd9b3a696acd 318 *
wim 10:dd9b3a696acd 319 * @param return The number of rows
wim 10:dd9b3a696acd 320 */
simon 1:ac48b187213c 321 int rows();
wim 10:dd9b3a696acd 322
wim 10:dd9b3a696acd 323 /** Return the number of columns
wim 10:dd9b3a696acd 324 *
wim 10:dd9b3a696acd 325 * @param return The number of columns
wim 10:dd9b3a696acd 326 */
wim 10:dd9b3a696acd 327 int columns();
simon 2:227356c7d12c 328
wim 11:9ec02df863a1 329 /** Set the Cursormode
wim 11:9ec02df863a1 330 *
wim 17:652ab113bc2e 331 * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn)
wim 11:9ec02df863a1 332 */
wim 17:652ab113bc2e 333 void setCursor(LCDCursor cursorMode);
wim 17:652ab113bc2e 334
wim 17:652ab113bc2e 335 /** Set the Displaymode
wim 17:652ab113bc2e 336 *
wim 17:652ab113bc2e 337 * @param displayMode The Display mode (DispOff, DispOn)
wim 17:652ab113bc2e 338 */
wim 21:9eb628d9e164 339 void setMode(LCDMode displayMode);
wim 11:9ec02df863a1 340
wim 20:e0da005a777f 341 /** Set the Backlight mode
wim 20:e0da005a777f 342 *
wim 21:9eb628d9e164 343 * @param backlightMode The Backlight mode (LightOff, LightOn)
wim 20:e0da005a777f 344 */
wim 21:9eb628d9e164 345 void setBacklight(LCDBacklight backlightMode);
wim 20:e0da005a777f 346
wim 33:900a94bc7585 347 /** Set User Defined Characters (UDC)
wim 11:9ec02df863a1 348 *
wim 34:e5a0dcb43ecc 349 * @param unsigned char c The Index of the UDC (0..7) for HD44780 clones and (0..15) for some more advanced controllers
wim 34:e5a0dcb43ecc 350 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits for bitpattern and 3 bits for blinkmode (advanced types))
wim 11:9ec02df863a1 351 */
wim 11:9ec02df863a1 352 void setUDC(unsigned char c, char *udc_data);
wim 11:9ec02df863a1 353
wim 33:900a94bc7585 354 /** Set UDC Blink
wim 33:900a94bc7585 355 * setUDCBlink method is supported by some compatible devices (eg SSD1803)
wim 33:900a94bc7585 356 *
wim 33:900a94bc7585 357 * @param blinkMode The Blink mode (BlinkOff, BlinkOn)
wim 33:900a94bc7585 358 */
wim 33:900a94bc7585 359 void setUDCBlink(LCDBlink blinkMode);
wim 33:900a94bc7585 360
wim 32:59c4b8f648d4 361 /** Set Contrast
wim 32:59c4b8f648d4 362 * setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation
wim 32:59c4b8f648d4 363 * Code imported from fork by JH1PJL
wim 32:59c4b8f648d4 364 *
wim 32:59c4b8f648d4 365 * @param unsigned char c contrast data (6 significant bits, valid range 0..63, Value 0 will disable the Vgen)
wim 32:59c4b8f648d4 366 * @return none
wim 32:59c4b8f648d4 367 */
wim 32:59c4b8f648d4 368 void setContrast(unsigned char c = LCD_DEF_CONTRAST);
wim 32:59c4b8f648d4 369
wim 32:59c4b8f648d4 370 /** Set Power
wim 32:59c4b8f648d4 371 * setPower method is supported by some compatible devices (eg SSD1803) that have power down modes
wim 32:59c4b8f648d4 372 *
wim 32:59c4b8f648d4 373 * @param bool powerOn Power on/off
wim 32:59c4b8f648d4 374 * @return none
wim 32:59c4b8f648d4 375 */
wim 32:59c4b8f648d4 376 void setPower(bool powerOn = true);
wim 32:59c4b8f648d4 377
wim 33:900a94bc7585 378 /** Set Orient
wim 33:900a94bc7585 379 * setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes
wim 33:900a94bc7585 380 *
wim 33:900a94bc7585 381 * @param LCDOrient orient Orientation
wim 33:900a94bc7585 382 * @return none
wim 33:900a94bc7585 383 */
wim 33:900a94bc7585 384 void setOrient(LCDOrient orient = Top);
wim 33:900a94bc7585 385
wim 34:e5a0dcb43ecc 386 /** Set Big Font
wim 34:e5a0dcb43ecc 387 * setBigFont method is supported by some compatible devices (eg SSD1803, US2066)
wim 34:e5a0dcb43ecc 388 *
wim 34:e5a0dcb43ecc 389 * @param lines The selected Big Font lines (None, TopLine, CenterLine, BottomLine, TopBottomLine)
wim 34:e5a0dcb43ecc 390 * Double height characters can be shown on lines 1+2, 2+3, 3+4 or 1+2 and 3+4
wim 34:e5a0dcb43ecc 391 * Valid double height lines depend on the LCDs number of rows.
wim 34:e5a0dcb43ecc 392 */
wim 34:e5a0dcb43ecc 393 void setBigFont(LCDBigFont lines);
wim 32:59c4b8f648d4 394
wim 29:a3663151aa65 395 //test
wim 30:033048611c01 396 // void _initCtrl();
wim 34:e5a0dcb43ecc 397 // int _column;
wim 34:e5a0dcb43ecc 398 // int _row;
wim 29:a3663151aa65 399
simon 1:ac48b187213c 400 protected:
wim 13:24506ba22480 401
wim 21:9eb628d9e164 402 /** LCD controller select, mainly used for LCD40x4
wim 21:9eb628d9e164 403 */
wim 19:c747b9e2e7b8 404 enum _LCDCtrl_Idx {
wim 15:b70ebfffb258 405 _LCDCtrl_0, /*< Primary */
wim 15:b70ebfffb258 406 _LCDCtrl_1, /*< Secondary */
wim 15:b70ebfffb258 407 };
wim 21:9eb628d9e164 408
wim 21:9eb628d9e164 409 /** Create a TextLCD_Base interface
wim 21:9eb628d9e164 410 * @brief Base class, can not be instantiated
wim 21:9eb628d9e164 411 *
wim 21:9eb628d9e164 412 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 413 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 414 */
wim 21:9eb628d9e164 415 TextLCD_Base(LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 15:b70ebfffb258 416
simon 1:ac48b187213c 417 // Stream implementation functions
simon 1:ac48b187213c 418 virtual int _putc(int value);
simon 1:ac48b187213c 419 virtual int _getc();
simon 1:ac48b187213c 420
wim 29:a3663151aa65 421 /** Low level method for LCD controller
wim 21:9eb628d9e164 422 */
wim 13:24506ba22480 423 void _init();
wim 29:a3663151aa65 424
wim 29:a3663151aa65 425 /** Low level initialisation method for LCD controller
wim 29:a3663151aa65 426 */
wim 30:033048611c01 427 void _initCtrl();
wim 29:a3663151aa65 428
wim 29:a3663151aa65 429 /** Low level character address set method
wim 29:a3663151aa65 430 */
wim 13:24506ba22480 431 int _address(int column, int row);
wim 29:a3663151aa65 432
wim 29:a3663151aa65 433 /** Low level cursor enable or disable method
wim 29:a3663151aa65 434 */
wim 21:9eb628d9e164 435 void _setCursor(LCDCursor show);
wim 29:a3663151aa65 436
wim 29:a3663151aa65 437 /** Low level method to store user defined characters for current controller
wim 34:e5a0dcb43ecc 438 *
wim 34:e5a0dcb43ecc 439 * @param unsigned char c The Index of the UDC (0..7) for HD44780 clones and (0..15) for some more advanced controllers
wim 34:e5a0dcb43ecc 440 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits)
wim 29:a3663151aa65 441 */
wim 17:652ab113bc2e 442 void _setUDC(unsigned char c, char *udc_data);
wim 29:a3663151aa65 443
wim 29:a3663151aa65 444 /** Low level method to restore the cursortype and display mode for current controller
wim 29:a3663151aa65 445 */
wim 21:9eb628d9e164 446 void _setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType);
wim 13:24506ba22480 447
wim 29:a3663151aa65 448 /** Low level nibble write operation to LCD controller (serial or parallel)
wim 21:9eb628d9e164 449 */
wim 17:652ab113bc2e 450 void _writeNibble(int value);
wim 29:a3663151aa65 451
wim 29:a3663151aa65 452 /** Low level command byte write operation to LCD controller.
wim 29:a3663151aa65 453 * Methods resets the RS bit and provides the required timing for the command.
wim 29:a3663151aa65 454 */
wim 15:b70ebfffb258 455 void _writeCommand(int command);
wim 33:900a94bc7585 456
wim 29:a3663151aa65 457 /** Low level data byte write operation to LCD controller (serial or parallel).
wim 29:a3663151aa65 458 * Methods sets the RS bit and provides the required timing for the data.
wim 29:a3663151aa65 459 */
wim 15:b70ebfffb258 460 void _writeData(int data);
wim 15:b70ebfffb258 461
wim 29:a3663151aa65 462 /** Pure Virtual Low level writes to LCD Bus (serial or parallel)
wim 29:a3663151aa65 463 * Set the Enable pin.
wim 29:a3663151aa65 464 */
wim 29:a3663151aa65 465 virtual void _setEnable(bool value) = 0;
wim 29:a3663151aa65 466
wim 21:9eb628d9e164 467 /** Pure Virtual Low level writes to LCD Bus (serial or parallel)
wim 29:a3663151aa65 468 * Set the RS pin ( 0 = Command, 1 = Data).
wim 29:a3663151aa65 469 */
wim 21:9eb628d9e164 470 virtual void _setRS(bool value) = 0;
wim 29:a3663151aa65 471
wim 29:a3663151aa65 472 /** Pure Virtual Low level writes to LCD Bus (serial or parallel)
wim 29:a3663151aa65 473 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 474 */
wim 21:9eb628d9e164 475 virtual void _setBL(bool value) = 0;
wim 29:a3663151aa65 476
wim 29:a3663151aa65 477 /** Pure Virtual Low level writes to LCD Bus (serial or parallel)
wim 29:a3663151aa65 478 * Set the databus value (4 bit).
wim 29:a3663151aa65 479 */
wim 21:9eb628d9e164 480 virtual void _setData(int value) = 0;
wim 13:24506ba22480 481
wim 29:a3663151aa65 482 /** Low level byte write operation to LCD controller (serial or parallel)
wim 29:a3663151aa65 483 * Depending on the RS pin this byte will be interpreted as data or command
wim 29:a3663151aa65 484 */
wim 29:a3663151aa65 485 virtual void _writeByte(int value);
wim 33:900a94bc7585 486
wim 13:24506ba22480 487 //Display type
simon 1:ac48b187213c 488 LCDType _type;
wim 30:033048611c01 489 int _nr_cols;
wim 30:033048611c01 490 int _nr_rows;
wim 30:033048611c01 491 int _addr_mode;
wim 30:033048611c01 492
wim 21:9eb628d9e164 493 //Display mode
wim 17:652ab113bc2e 494 LCDMode _currentMode;
wim 17:652ab113bc2e 495
wim 19:c747b9e2e7b8 496 //Controller type
wim 19:c747b9e2e7b8 497 LCDCtrl _ctrl;
wim 19:c747b9e2e7b8 498
wim 15:b70ebfffb258 499 //Controller select, mainly used for LCD40x4
wim 19:c747b9e2e7b8 500 _LCDCtrl_Idx _ctrl_idx;
wim 15:b70ebfffb258 501
wim 13:24506ba22480 502 // Cursor
simon 1:ac48b187213c 503 int _column;
simon 1:ac48b187213c 504 int _row;
wim 32:59c4b8f648d4 505 LCDCursor _currentCursor;
wim 32:59c4b8f648d4 506
wim 32:59c4b8f648d4 507 // Function mode saved to allow switch between Instruction sets after initialisation time
wim 32:59c4b8f648d4 508 // Icon, Booster mode and contrast saved to allow contrast change at later time
wim 32:59c4b8f648d4 509 // Only available for controllers with added features
wim 32:59c4b8f648d4 510 int _function, _function_1, _function_x;
wim 32:59c4b8f648d4 511 int _icon_power;
wim 32:59c4b8f648d4 512 int _contrast;
wim 32:59c4b8f648d4 513
simon 1:ac48b187213c 514 };
simon 1:ac48b187213c 515
wim 23:d47f226efb24 516 //--------- End TextLCD_Base -----------
wim 22:35742ec80c24 517
wim 22:35742ec80c24 518
wim 23:d47f226efb24 519 //--------- Start TextLCD Bus -----------
wim 21:9eb628d9e164 520
wim 21:9eb628d9e164 521 /** Create a TextLCD interface for using regular mbed pins
wim 21:9eb628d9e164 522 *
wim 21:9eb628d9e164 523 */
wim 21:9eb628d9e164 524 class TextLCD : public TextLCD_Base {
wim 21:9eb628d9e164 525 public:
wim 21:9eb628d9e164 526 /** Create a TextLCD interface for using regular mbed pins
wim 21:9eb628d9e164 527 *
wim 21:9eb628d9e164 528 * @param rs Instruction/data control line
wim 21:9eb628d9e164 529 * @param e Enable line (clock)
wim 21:9eb628d9e164 530 * @param d4-d7 Data lines for using as a 4-bit interface
wim 21:9eb628d9e164 531 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 532 * @param bl Backlight control line (optional, default = NC)
wim 21:9eb628d9e164 533 * @param e2 Enable2 line (clock for second controller, LCD40x4 only)
wim 21:9eb628d9e164 534 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 535 */
wim 21:9eb628d9e164 536 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 537
wim 22:35742ec80c24 538 /** Destruct a TextLCD interface for using regular mbed pins
wim 22:35742ec80c24 539 *
wim 22:35742ec80c24 540 * @param none
wim 22:35742ec80c24 541 * @return none
wim 22:35742ec80c24 542 */
wim 22:35742ec80c24 543 virtual ~TextLCD();
wim 22:35742ec80c24 544
wim 21:9eb628d9e164 545 private:
wim 29:a3663151aa65 546
wim 29:a3663151aa65 547 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel)
wim 29:a3663151aa65 548 * Set the Enable pin.
wim 29:a3663151aa65 549 */
wim 21:9eb628d9e164 550 virtual void _setEnable(bool value);
wim 29:a3663151aa65 551
wim 29:a3663151aa65 552 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel)
wim 32:59c4b8f648d4 553 * Set the RS pin (0 = Command, 1 = Data).
wim 29:a3663151aa65 554 */
wim 21:9eb628d9e164 555 virtual void _setRS(bool value);
wim 29:a3663151aa65 556
wim 29:a3663151aa65 557 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel)
wim 29:a3663151aa65 558 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 559 */
wim 21:9eb628d9e164 560 virtual void _setBL(bool value);
wim 29:a3663151aa65 561
wim 29:a3663151aa65 562 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel)
wim 29:a3663151aa65 563 * Set the databus value (4 bit).
wim 29:a3663151aa65 564 */
wim 21:9eb628d9e164 565 virtual void _setData(int value);
wim 21:9eb628d9e164 566
wim 29:a3663151aa65 567
wim 22:35742ec80c24 568 /** Regular mbed pins bus
wim 22:35742ec80c24 569 */
wim 22:35742ec80c24 570 DigitalOut _rs, _e;
wim 22:35742ec80c24 571 BusOut _d;
wim 22:35742ec80c24 572
wim 22:35742ec80c24 573 /** Optional Hardware pins for the Backlight and LCD40x4 device
wim 22:35742ec80c24 574 * Default PinName value is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins
wim 22:35742ec80c24 575 */
wim 22:35742ec80c24 576 DigitalOut *_bl, *_e2;
wim 21:9eb628d9e164 577 };
wim 21:9eb628d9e164 578
wim 23:d47f226efb24 579 //----------- End TextLCD ---------------
wim 21:9eb628d9e164 580
wim 21:9eb628d9e164 581
wim 23:d47f226efb24 582 //--------- Start TextLCD_I2C -----------
wim 34:e5a0dcb43ecc 583 #if(LCD_I2C == 1) /* I2C Expander PCF8574/MCP23008 */
wim 22:35742ec80c24 584
wim 26:bd897a001012 585 /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander
wim 21:9eb628d9e164 586 *
wim 21:9eb628d9e164 587 */
wim 21:9eb628d9e164 588 class TextLCD_I2C : public TextLCD_Base {
wim 21:9eb628d9e164 589 public:
wim 26:bd897a001012 590 /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander
wim 21:9eb628d9e164 591 *
wim 21:9eb628d9e164 592 * @param i2c I2C Bus
wim 26:bd897a001012 593 * @param deviceAddress I2C slave address (PCF8574 or PCF8574A, default = PCF8574_SA0 = 0x40)
wim 21:9eb628d9e164 594 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 595 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 596 */
wim 26:bd897a001012 597 TextLCD_I2C(I2C *i2c, char deviceAddress = PCF8574_SA0, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 21:9eb628d9e164 598
wim 21:9eb628d9e164 599 private:
wim 29:a3663151aa65 600
wim 29:a3663151aa65 601 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 602 * Set the Enable pin.
wim 29:a3663151aa65 603 */
wim 21:9eb628d9e164 604 virtual void _setEnable(bool value);
wim 29:a3663151aa65 605
wim 29:a3663151aa65 606 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 32:59c4b8f648d4 607 * Set the RS pin (0 = Command, 1 = Data).
wim 29:a3663151aa65 608 */
wim 21:9eb628d9e164 609 virtual void _setRS(bool value);
wim 29:a3663151aa65 610
wim 29:a3663151aa65 611 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 612 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 613 */
wim 21:9eb628d9e164 614 virtual void _setBL(bool value);
wim 29:a3663151aa65 615
wim 29:a3663151aa65 616 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 617 * Set the databus value (4 bit).
wim 29:a3663151aa65 618 */
wim 29:a3663151aa65 619 virtual void _setData(int value);
wim 30:033048611c01 620
wim 29:a3663151aa65 621 /** Write data to MCP23008 I2C portexpander
wim 29:a3663151aa65 622 * @param reg register to write
wim 29:a3663151aa65 623 * @param value data to write
wim 29:a3663151aa65 624 * @return none
wim 29:a3663151aa65 625 *
wim 29:a3663151aa65 626 */
wim 26:bd897a001012 627 void _write_register (int reg, int value);
wim 21:9eb628d9e164 628
wim 21:9eb628d9e164 629 //I2C bus
wim 21:9eb628d9e164 630 I2C *_i2c;
wim 21:9eb628d9e164 631 char _slaveAddress;
wim 21:9eb628d9e164 632
wim 21:9eb628d9e164 633 // Internal bus mirror value for serial bus only
wim 30:033048611c01 634 char _lcd_bus;
wim 21:9eb628d9e164 635 };
wim 34:e5a0dcb43ecc 636 #endif /* I2C Expander PCF8574/MCP23008 */
wim 21:9eb628d9e164 637
wim 23:d47f226efb24 638 //---------- End TextLCD_I2C ------------
wim 22:35742ec80c24 639
wim 22:35742ec80c24 640
wim 23:d47f226efb24 641 //--------- Start TextLCD_SPI -----------
wim 34:e5a0dcb43ecc 642 #if(LCD_SPI == 1) /* SPI Expander SN74595 */
wim 22:35742ec80c24 643
wim 21:9eb628d9e164 644 /** Create a TextLCD interface using an SPI 74595 portexpander
wim 21:9eb628d9e164 645 *
wim 21:9eb628d9e164 646 */
wim 21:9eb628d9e164 647 class TextLCD_SPI : public TextLCD_Base {
wim 21:9eb628d9e164 648 public:
wim 21:9eb628d9e164 649 /** Create a TextLCD interface using an SPI 74595 portexpander
wim 21:9eb628d9e164 650 *
wim 21:9eb628d9e164 651 * @param spi SPI Bus
wim 21:9eb628d9e164 652 * @param cs chip select pin (active low)
wim 21:9eb628d9e164 653 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 654 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 655 */
wim 21:9eb628d9e164 656 TextLCD_SPI(SPI *spi, PinName cs, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 21:9eb628d9e164 657
wim 21:9eb628d9e164 658 private:
wim 29:a3663151aa65 659
wim 29:a3663151aa65 660 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 661 * Set the Enable pin.
wim 29:a3663151aa65 662 */
wim 21:9eb628d9e164 663 virtual void _setEnable(bool value);
wim 29:a3663151aa65 664
wim 29:a3663151aa65 665 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 32:59c4b8f648d4 666 * Set the RS pin (0 = Command, 1 = Data).
wim 29:a3663151aa65 667 */
wim 21:9eb628d9e164 668 virtual void _setRS(bool value);
wim 29:a3663151aa65 669
wim 29:a3663151aa65 670 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 671 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 672 */
wim 21:9eb628d9e164 673 virtual void _setBL(bool value);
wim 29:a3663151aa65 674
wim 29:a3663151aa65 675 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 676 * Set the databus value (4 bit).
wim 29:a3663151aa65 677 */
wim 21:9eb628d9e164 678 virtual void _setData(int value);
wim 29:a3663151aa65 679
wim 29:a3663151aa65 680 /** Implementation of Low level writes to LCD Bus (serial expander)
wim 29:a3663151aa65 681 * Set the CS pin (0 = select, 1 = deselect).
wim 29:a3663151aa65 682 */
wim 21:9eb628d9e164 683 virtual void _setCS(bool value);
wim 21:9eb628d9e164 684
wim 29:a3663151aa65 685 ///** Low level writes to LCD serial bus only (serial expander)
wim 29:a3663151aa65 686 // */
wim 29:a3663151aa65 687 // void _writeBus();
wim 21:9eb628d9e164 688
wim 21:9eb628d9e164 689 // SPI bus
wim 21:9eb628d9e164 690 SPI *_spi;
wim 21:9eb628d9e164 691 DigitalOut _cs;
wim 21:9eb628d9e164 692
wim 21:9eb628d9e164 693 // Internal bus mirror value for serial bus only
wim 21:9eb628d9e164 694 char _lcd_bus;
wim 21:9eb628d9e164 695 };
wim 34:e5a0dcb43ecc 696 #endif /* SPI Expander SN74595 */
wim 23:d47f226efb24 697 //---------- End TextLCD_SPI ------------
wim 21:9eb628d9e164 698
Sissors 24:fb3399713710 699
wim 26:bd897a001012 700 //--------- Start TextLCD_SPI_N -----------
wim 34:e5a0dcb43ecc 701 #if(LCD_SPI_N == 1) /* Native SPI bus */
Sissors 24:fb3399713710 702
wim 30:033048611c01 703 /** Create a TextLCD interface using a controller with native SPI4 interface
Sissors 24:fb3399713710 704 *
Sissors 24:fb3399713710 705 */
wim 25:6162b31128c9 706 class TextLCD_SPI_N : public TextLCD_Base {
Sissors 24:fb3399713710 707 public:
wim 30:033048611c01 708 /** Create a TextLCD interface using a controller with native SPI4 interface
Sissors 24:fb3399713710 709 *
Sissors 24:fb3399713710 710 * @param spi SPI Bus
Sissors 24:fb3399713710 711 * @param cs chip select pin (active low)
Sissors 24:fb3399713710 712 * @param rs Instruction/data control line
Sissors 24:fb3399713710 713 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Sissors 24:fb3399713710 714 * @param bl Backlight control line (optional, default = NC)
wim 26:bd897a001012 715 * @param ctrl LCD controller (default = ST7032_3V3)
Sissors 24:fb3399713710 716 */
wim 26:bd897a001012 717 TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3);
wim 25:6162b31128c9 718 virtual ~TextLCD_SPI_N(void);
Sissors 24:fb3399713710 719
Sissors 24:fb3399713710 720 private:
wim 29:a3663151aa65 721
wim 29:a3663151aa65 722 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 723 * Set the Enable pin.
wim 29:a3663151aa65 724 */
Sissors 24:fb3399713710 725 virtual void _setEnable(bool value);
wim 29:a3663151aa65 726
wim 29:a3663151aa65 727 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 728 * Set the RS pin (0 = Command, 1 = Data).
wim 29:a3663151aa65 729 */
Sissors 24:fb3399713710 730 virtual void _setRS(bool value);
wim 29:a3663151aa65 731
wim 29:a3663151aa65 732 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 733 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 734 */
Sissors 24:fb3399713710 735 virtual void _setBL(bool value);
wim 29:a3663151aa65 736
wim 29:a3663151aa65 737 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 738 * Set the databus value (4 bit).
wim 29:a3663151aa65 739 */
Sissors 24:fb3399713710 740 virtual void _setData(int value);
wim 29:a3663151aa65 741
wim 29:a3663151aa65 742 /** Low level writes to LCD serial bus only (serial native)
wim 29:a3663151aa65 743 */
Sissors 24:fb3399713710 744 virtual void _writeByte(int value);
Sissors 24:fb3399713710 745
Sissors 24:fb3399713710 746 // SPI bus
Sissors 24:fb3399713710 747 SPI *_spi;
Sissors 24:fb3399713710 748 DigitalOut _cs;
Sissors 24:fb3399713710 749 DigitalOut _rs;
wim 30:033048611c01 750
wim 30:033048611c01 751 //Backlight
Sissors 24:fb3399713710 752 DigitalOut *_bl;
Sissors 24:fb3399713710 753 };
wim 34:e5a0dcb43ecc 754 #endif /* Native SPI bus */
wim 25:6162b31128c9 755 //---------- End TextLCD_SPI_N ------------
Sissors 24:fb3399713710 756
wim 26:bd897a001012 757
wim 34:e5a0dcb43ecc 758 //------- Start TextLCD_SPI_N_3_9 ---------
wim 34:e5a0dcb43ecc 759 #if(LCD_SPI_N_3_9 == 1) /* Native SPI bus */
wim 30:033048611c01 760 //Code checked out on logic analyser. Not yet tested on hardware..
wim 30:033048611c01 761
wim 30:033048611c01 762 /** Create a TextLCD interface using a controller with native SPI3 9 bits interface
wim 30:033048611c01 763 * Note: current mbed libs only support SPI 9 bit mode for NXP platforms
wim 30:033048611c01 764 *
wim 30:033048611c01 765 */
wim 30:033048611c01 766 class TextLCD_SPI_N_3_9 : public TextLCD_Base {
wim 30:033048611c01 767 public:
wim 30:033048611c01 768 /** Create a TextLCD interface using a controller with native SPI3 9 bits interface
wim 30:033048611c01 769 * Note: current mbed libs only support SPI 9 bit mode for NXP platforms
wim 30:033048611c01 770 *
wim 30:033048611c01 771 * @param spi SPI Bus
wim 30:033048611c01 772 * @param cs chip select pin (active low)
wim 30:033048611c01 773 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 30:033048611c01 774 * @param bl Backlight control line (optional, default = NC)
wim 30:033048611c01 775 * @param ctrl LCD controller (default = AIP31068)
wim 30:033048611c01 776 */
wim 30:033048611c01 777 TextLCD_SPI_N_3_9(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = AIP31068);
wim 30:033048611c01 778 virtual ~TextLCD_SPI_N_3_9(void);
wim 30:033048611c01 779
wim 30:033048611c01 780 private:
wim 30:033048611c01 781
wim 30:033048611c01 782 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 783 * Set the Enable pin.
wim 30:033048611c01 784 */
wim 30:033048611c01 785 virtual void _setEnable(bool value);
wim 30:033048611c01 786
wim 30:033048611c01 787 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 788 * Set the RS pin (0 = Command, 1 = Data).
wim 32:59c4b8f648d4 789 */
wim 32:59c4b8f648d4 790 virtual void _setRS(bool value);
wim 32:59c4b8f648d4 791
wim 32:59c4b8f648d4 792 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 793 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 32:59c4b8f648d4 794 */
wim 32:59c4b8f648d4 795 virtual void _setBL(bool value);
wim 32:59c4b8f648d4 796
wim 32:59c4b8f648d4 797 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 798 * Set the databus value (4 bit).
wim 32:59c4b8f648d4 799 */
wim 32:59c4b8f648d4 800 virtual void _setData(int value);
wim 32:59c4b8f648d4 801
wim 32:59c4b8f648d4 802 /** Low level writes to LCD serial bus only (serial native)
wim 32:59c4b8f648d4 803 */
wim 32:59c4b8f648d4 804 virtual void _writeByte(int value);
wim 32:59c4b8f648d4 805
wim 32:59c4b8f648d4 806 // SPI bus
wim 32:59c4b8f648d4 807 SPI *_spi;
wim 32:59c4b8f648d4 808 DigitalOut _cs;
wim 32:59c4b8f648d4 809
wim 32:59c4b8f648d4 810
wim 32:59c4b8f648d4 811 // controlbyte to select between data and command. Internal value for serial bus only
wim 32:59c4b8f648d4 812 char _controlbyte;
wim 32:59c4b8f648d4 813
wim 32:59c4b8f648d4 814 //Backlight
wim 32:59c4b8f648d4 815 DigitalOut *_bl;
wim 32:59c4b8f648d4 816 };
wim 34:e5a0dcb43ecc 817 #endif /* Native SPI bus */
wim 32:59c4b8f648d4 818 //-------- End TextLCD_SPI_N_3_9 ----------
wim 32:59c4b8f648d4 819
wim 32:59c4b8f648d4 820
wim 32:59c4b8f648d4 821 //------- Start TextLCD_SPI_N_3_10 ---------
wim 34:e5a0dcb43ecc 822 #if(LCD_SPI_N_3_10 == 1) /* Native SPI bus */
wim 32:59c4b8f648d4 823
wim 32:59c4b8f648d4 824 /** Create a TextLCD interface using a controller with native SPI3 10 bits interface
wim 32:59c4b8f648d4 825 * Note: current mbed libs only support SPI 10 bit mode for NXP platforms
wim 32:59c4b8f648d4 826 *
wim 32:59c4b8f648d4 827 */
wim 32:59c4b8f648d4 828 class TextLCD_SPI_N_3_10 : public TextLCD_Base {
wim 32:59c4b8f648d4 829 public:
wim 32:59c4b8f648d4 830 /** Create a TextLCD interface using a controller with native SPI3 10 bits interface
wim 32:59c4b8f648d4 831 * Note: current mbed libs only support SPI 10 bit mode for NXP platforms
wim 32:59c4b8f648d4 832 *
wim 32:59c4b8f648d4 833 * @param spi SPI Bus
wim 32:59c4b8f648d4 834 * @param cs chip select pin (active low)
wim 32:59c4b8f648d4 835 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 32:59c4b8f648d4 836 * @param bl Backlight control line (optional, default = NC)
wim 32:59c4b8f648d4 837 * @param ctrl LCD controller (default = AIP31068)
wim 32:59c4b8f648d4 838 */
wim 32:59c4b8f648d4 839 TextLCD_SPI_N_3_10(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = AIP31068);
wim 32:59c4b8f648d4 840 virtual ~TextLCD_SPI_N_3_10(void);
wim 32:59c4b8f648d4 841
wim 32:59c4b8f648d4 842 private:
wim 32:59c4b8f648d4 843
wim 32:59c4b8f648d4 844 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 845 * Set the Enable pin.
wim 32:59c4b8f648d4 846 */
wim 32:59c4b8f648d4 847 virtual void _setEnable(bool value);
wim 32:59c4b8f648d4 848
wim 32:59c4b8f648d4 849 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 850 * Set the RS pin (0 = Command, 1 = Data).
wim 32:59c4b8f648d4 851 */
wim 32:59c4b8f648d4 852 virtual void _setRS(bool value);
wim 32:59c4b8f648d4 853
wim 32:59c4b8f648d4 854 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 855 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 32:59c4b8f648d4 856 */
wim 32:59c4b8f648d4 857 virtual void _setBL(bool value);
wim 32:59c4b8f648d4 858
wim 32:59c4b8f648d4 859 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 860 * Set the databus value (4 bit).
wim 32:59c4b8f648d4 861 */
wim 32:59c4b8f648d4 862 virtual void _setData(int value);
wim 32:59c4b8f648d4 863
wim 32:59c4b8f648d4 864 /** Low level writes to LCD serial bus only (serial native)
wim 32:59c4b8f648d4 865 */
wim 32:59c4b8f648d4 866 virtual void _writeByte(int value);
wim 32:59c4b8f648d4 867
wim 32:59c4b8f648d4 868 // SPI bus
wim 32:59c4b8f648d4 869 SPI *_spi;
wim 32:59c4b8f648d4 870 DigitalOut _cs;
wim 32:59c4b8f648d4 871
wim 32:59c4b8f648d4 872
wim 32:59c4b8f648d4 873 // controlbyte to select between data and command. Internal value for serial bus only
wim 32:59c4b8f648d4 874 char _controlbyte;
wim 32:59c4b8f648d4 875
wim 32:59c4b8f648d4 876 //Backlight
wim 32:59c4b8f648d4 877 DigitalOut *_bl;
wim 32:59c4b8f648d4 878 };
wim 32:59c4b8f648d4 879
wim 34:e5a0dcb43ecc 880 #endif /* Native SPI bus */
wim 32:59c4b8f648d4 881 //-------- End TextLCD_SPI_N_3_10 ----------
wim 32:59c4b8f648d4 882
wim 32:59c4b8f648d4 883
wim 32:59c4b8f648d4 884 //------- Start TextLCD_SPI_N_3_16 ---------
wim 34:e5a0dcb43ecc 885 #if(LCD_SPI_N_3_16 == 1) /* Native SPI bus */
wim 34:e5a0dcb43ecc 886 //Code checked out on logic analyser. Not yet tested on hardware..
wim 32:59c4b8f648d4 887
wim 32:59c4b8f648d4 888 /** Create a TextLCD interface using a controller with native SPI3 16 bits interface
wim 32:59c4b8f648d4 889 *
wim 32:59c4b8f648d4 890 */
wim 32:59c4b8f648d4 891 class TextLCD_SPI_N_3_16 : public TextLCD_Base {
wim 32:59c4b8f648d4 892 public:
wim 32:59c4b8f648d4 893 /** Create a TextLCD interface using a controller with native SPI3 16 bits interface
wim 32:59c4b8f648d4 894 *
wim 32:59c4b8f648d4 895 * @param spi SPI Bus
wim 32:59c4b8f648d4 896 * @param cs chip select pin (active low)
wim 32:59c4b8f648d4 897 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 32:59c4b8f648d4 898 * @param bl Backlight control line (optional, default = NC)
wim 32:59c4b8f648d4 899 * @param ctrl LCD controller (default = PT6314)
wim 32:59c4b8f648d4 900 */
wim 32:59c4b8f648d4 901 TextLCD_SPI_N_3_16(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = PT6314);
wim 32:59c4b8f648d4 902 virtual ~TextLCD_SPI_N_3_16(void);
wim 32:59c4b8f648d4 903
wim 32:59c4b8f648d4 904 private:
wim 32:59c4b8f648d4 905
wim 32:59c4b8f648d4 906 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 907 * Set the Enable pin.
wim 32:59c4b8f648d4 908 */
wim 32:59c4b8f648d4 909 virtual void _setEnable(bool value);
wim 32:59c4b8f648d4 910
wim 32:59c4b8f648d4 911 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 912 * Set the RS pin (0 = Command, 1 = Data).
wim 30:033048611c01 913 */
wim 30:033048611c01 914 virtual void _setRS(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 BL pin (0 = Backlight Off, 1 = Backlight On).
wim 30:033048611c01 918 */
wim 30:033048611c01 919 virtual void _setBL(bool value);
wim 30:033048611c01 920
wim 30:033048611c01 921 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 922 * Set the databus value (4 bit).
wim 30:033048611c01 923 */
wim 30:033048611c01 924 virtual void _setData(int value);
wim 30:033048611c01 925
wim 30:033048611c01 926 /** Low level writes to LCD serial bus only (serial native)
wim 30:033048611c01 927 */
wim 30:033048611c01 928 virtual void _writeByte(int value);
wim 30:033048611c01 929
wim 30:033048611c01 930 // SPI bus
wim 30:033048611c01 931 SPI *_spi;
wim 30:033048611c01 932 DigitalOut _cs;
wim 30:033048611c01 933
wim 30:033048611c01 934 // controlbyte to select between data and command. Internal value for serial bus only
wim 30:033048611c01 935 char _controlbyte;
wim 30:033048611c01 936
wim 30:033048611c01 937 //Backlight
wim 30:033048611c01 938 DigitalOut *_bl;
wim 30:033048611c01 939 };
wim 34:e5a0dcb43ecc 940 #endif /* Native SPI bus */
wim 32:59c4b8f648d4 941 //-------- End TextLCD_SPI_N_3_16 ----------
wim 34:e5a0dcb43ecc 942
wim 30:033048611c01 943
wim 32:59c4b8f648d4 944 //------- Start TextLCD_SPI_N_3_24 ---------
wim 34:e5a0dcb43ecc 945 #if(LCD_SPI_N_3_24 == 1) /* Native SPI bus */
wim 30:033048611c01 946
wim 32:59c4b8f648d4 947 /** Create a TextLCD interface using a controller with native SPI3 24 bits interface
wim 32:59c4b8f648d4 948 * Note: lib uses SPI 8 bit mode
wim 30:033048611c01 949 *
wim 30:033048611c01 950 */
wim 32:59c4b8f648d4 951 class TextLCD_SPI_N_3_24 : public TextLCD_Base {
wim 30:033048611c01 952 public:
wim 32:59c4b8f648d4 953 /** Create a TextLCD interface using a controller with native SPI3 24 bits interface
wim 32:59c4b8f648d4 954 * Note: lib uses SPI 8 bit mode
wim 30:033048611c01 955 *
wim 30:033048611c01 956 * @param spi SPI Bus
wim 30:033048611c01 957 * @param cs chip select pin (active low)
wim 30:033048611c01 958 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 30:033048611c01 959 * @param bl Backlight control line (optional, default = NC)
wim 32:59c4b8f648d4 960 * @param ctrl LCD controller (default = SSD1803)
wim 30:033048611c01 961 */
wim 32:59c4b8f648d4 962 TextLCD_SPI_N_3_24(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = SSD1803_3V3);
wim 32:59c4b8f648d4 963 virtual ~TextLCD_SPI_N_3_24(void);
wim 30:033048611c01 964
wim 30:033048611c01 965 private:
wim 30:033048611c01 966
wim 30:033048611c01 967 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 968 * Set the Enable pin.
wim 30:033048611c01 969 */
wim 30:033048611c01 970 virtual void _setEnable(bool value);
wim 30:033048611c01 971
wim 30:033048611c01 972 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 32:59c4b8f648d4 973 * Set the RS pin (0 = Command, 1 = Data).
wim 30:033048611c01 974 */
wim 30:033048611c01 975 virtual void _setRS(bool value);
wim 30:033048611c01 976
wim 30:033048611c01 977 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 978 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 30:033048611c01 979 */
wim 30:033048611c01 980 virtual void _setBL(bool value);
wim 30:033048611c01 981
wim 30:033048611c01 982 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 30:033048611c01 983 * Set the databus value (4 bit).
wim 30:033048611c01 984 */
wim 30:033048611c01 985 virtual void _setData(int value);
wim 30:033048611c01 986
wim 30:033048611c01 987 /** Low level writes to LCD serial bus only (serial native)
wim 30:033048611c01 988 */
wim 30:033048611c01 989 virtual void _writeByte(int value);
wim 30:033048611c01 990
wim 30:033048611c01 991 // SPI bus
wim 30:033048611c01 992 SPI *_spi;
wim 30:033048611c01 993 DigitalOut _cs;
wim 30:033048611c01 994
wim 30:033048611c01 995 // controlbyte to select between data and command. Internal value for serial bus only
wim 30:033048611c01 996 char _controlbyte;
wim 30:033048611c01 997
wim 30:033048611c01 998 //Backlight
wim 30:033048611c01 999 DigitalOut *_bl;
wim 30:033048611c01 1000 };
wim 34:e5a0dcb43ecc 1001 #endif /* Native SPI bus */
wim 32:59c4b8f648d4 1002 //-------- End TextLCD_SPI_N_3_24 ----------
wim 30:033048611c01 1003
wim 30:033048611c01 1004
wim 26:bd897a001012 1005 //--------- Start TextLCD_I2C_N -----------
wim 34:e5a0dcb43ecc 1006 #if(LCD_I2C_N == 1) /* Native I2C */
wim 26:bd897a001012 1007
wim 26:bd897a001012 1008 /** Create a TextLCD interface using a controller with native I2C interface
wim 26:bd897a001012 1009 *
wim 26:bd897a001012 1010 */
wim 26:bd897a001012 1011 class TextLCD_I2C_N : public TextLCD_Base {
wim 26:bd897a001012 1012 public:
wim 26:bd897a001012 1013 /** Create a TextLCD interface using a controller with native I2C interface
wim 26:bd897a001012 1014 *
wim 26:bd897a001012 1015 * @param i2c I2C Bus
wim 28:30fa94f7341c 1016 * @param deviceAddress I2C slave address (default = ST7032_SA = 0x7C)
wim 26:bd897a001012 1017 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 28:30fa94f7341c 1018 * @param bl Backlight control line (optional, default = NC)
wim 26:bd897a001012 1019 * @param ctrl LCD controller (default = ST7032_3V3)
wim 26:bd897a001012 1020 */
wim 28:30fa94f7341c 1021 TextLCD_I2C_N(I2C *i2c, char deviceAddress = ST7032_SA, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3);
wim 26:bd897a001012 1022 virtual ~TextLCD_I2C_N(void);
wim 26:bd897a001012 1023
wim 26:bd897a001012 1024 private:
wim 29:a3663151aa65 1025
wim 29:a3663151aa65 1026 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 1027 * Set the Enable pin.
wim 29:a3663151aa65 1028 */
wim 26:bd897a001012 1029 virtual void _setEnable(bool value);
wim 29:a3663151aa65 1030
wim 29:a3663151aa65 1031 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 1032 * Set the RS pin ( 0 = Command, 1 = Data).
wim 29:a3663151aa65 1033 */
wim 26:bd897a001012 1034 virtual void _setRS(bool value);
wim 29:a3663151aa65 1035
wim 29:a3663151aa65 1036 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 1037 * Set the BL pin (0 = Backlight Off, 1 = Backlight On).
wim 29:a3663151aa65 1038 */
wim 26:bd897a001012 1039 virtual void _setBL(bool value);
wim 29:a3663151aa65 1040
wim 29:a3663151aa65 1041 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native)
wim 29:a3663151aa65 1042 * Set the databus value (4 bit).
wim 29:a3663151aa65 1043 */
wim 26:bd897a001012 1044 virtual void _setData(int value);
wim 29:a3663151aa65 1045
wim 29:a3663151aa65 1046 /** Low level writes to LCD serial bus only (serial native)
wim 29:a3663151aa65 1047 */
wim 26:bd897a001012 1048 virtual void _writeByte(int value);
wim 26:bd897a001012 1049
wim 26:bd897a001012 1050 //I2C bus
wim 26:bd897a001012 1051 I2C *_i2c;
wim 26:bd897a001012 1052 char _slaveAddress;
wim 26:bd897a001012 1053
wim 28:30fa94f7341c 1054 // controlbyte to select between data and command. Internal value for serial bus only
wim 28:30fa94f7341c 1055 char _controlbyte;
wim 28:30fa94f7341c 1056
wim 30:033048611c01 1057 //Backlight
wim 33:900a94bc7585 1058 DigitalOut *_bl;
wim 33:900a94bc7585 1059
wim 26:bd897a001012 1060 };
wim 34:e5a0dcb43ecc 1061 #endif /* Native I2C */
wim 26:bd897a001012 1062 //---------- End TextLCD_I2C_N ------------
wim 26:bd897a001012 1063
simon 1:ac48b187213c 1064 #endif