software about measure for robotic

Dependents:   A18_RobotmeasureV1

Fork of TextLCD by Wim Huiskamp

It's error WTF !!!

Committer:
wim
Date:
Sat Jun 14 17:04:25 2014 +0000
Revision:
28:30fa94f7341c
Parent:
27:22d5086f6ba6
Child:
29:a3663151aa65
Updated to support ST7032i with native I2C and SPI interface.

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
simon 1:ac48b187213c 13 *
simon 1:ac48b187213c 14 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 1:ac48b187213c 15 * of this software and associated documentation files (the "Software"), to deal
simon 1:ac48b187213c 16 * in the Software without restriction, including without limitation the rights
simon 1:ac48b187213c 17 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 1:ac48b187213c 18 * copies of the Software, and to permit persons to whom the Software is
simon 1:ac48b187213c 19 * furnished to do so, subject to the following conditions:
simon 2:227356c7d12c 20 *
simon 1:ac48b187213c 21 * The above copyright notice and this permission notice shall be included in
simon 1:ac48b187213c 22 * all copies or substantial portions of the Software.
simon 2:227356c7d12c 23 *
simon 1:ac48b187213c 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 1:ac48b187213c 25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 1:ac48b187213c 26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 1:ac48b187213c 27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 1:ac48b187213c 28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 1:ac48b187213c 29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 1:ac48b187213c 30 * THE SOFTWARE.
simon 1:ac48b187213c 31 */
simon 1:ac48b187213c 32
simon 1:ac48b187213c 33 #ifndef MBED_TEXTLCD_H
simon 1:ac48b187213c 34 #define MBED_TEXTLCD_H
simon 1:ac48b187213c 35
simon 1:ac48b187213c 36 #include "mbed.h"
simon 2:227356c7d12c 37
simon 5:a53b3e2d6f1e 38 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
simon 2:227356c7d12c 39 *
wim 16:c276b75e6585 40 * Currently supports 8x1, 8x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
wim 27:22d5086f6ba6 41 * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595).
wim 27:22d5086f6ba6 42 * 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 43 *
simon 2:227356c7d12c 44 * @code
simon 2:227356c7d12c 45 * #include "mbed.h"
simon 2:227356c7d12c 46 * #include "TextLCD.h"
simon 5:a53b3e2d6f1e 47 *
wim 16:c276b75e6585 48 * // I2C Communication
wim 16:c276b75e6585 49 * I2C i2c_lcd(p28,p27); // SDA, SCL
wim 16:c276b75e6585 50 *
wim 16:c276b75e6585 51 * // SPI Communication
wim 16:c276b75e6585 52 * SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK
wim 16:c276b75e6585 53 *
wim 22:35742ec80c24 54 * //TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=HD44780
wim 28:30fa94f7341c 55 * //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, 74595 expander, CS pin, LCD Type
wim 22:35742ec80c24 56 * TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type
wim 21:9eb628d9e164 57 * //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type
wim 27:22d5086f6ba6 58 * //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3
wim 28:30fa94f7341c 59 * //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 60 *
simon 2:227356c7d12c 61 * int main() {
wim 16:c276b75e6585 62 * lcd.printf("Hello World!\n");
simon 2:227356c7d12c 63 * }
simon 2:227356c7d12c 64 * @endcode
simon 2:227356c7d12c 65 */
wim 8:03116f75b66e 66
wim 26:bd897a001012 67
wim 26:bd897a001012 68 //Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces
wim 13:24506ba22480 69 //LCD and serial portexpanders should be wired accordingly
wim 20:e0da005a777f 70 //
wim 26:bd897a001012 71 //Select Hardware module (one option only)
wim 28:30fa94f7341c 72 #define DEFAULT 1
wim 28:30fa94f7341c 73 #define ADAFRUIT 0
wim 26:bd897a001012 74 #define DFROBOT 0
wim 26:bd897a001012 75
wim 26:bd897a001012 76
wim 26:bd897a001012 77 #if (DEFAULT==1)
wim 20:e0da005a777f 78 //Definitions for hardware used by WH
wim 26:bd897a001012 79 //This hardware supports the I2C bus expander (PCF8574/PCF8574A or MCP23008) and SPI bus expander (74595) interfaces
wim 26:bd897a001012 80 //
wim 13:24506ba22480 81 //Note: LCD RW pin must be connected to GND
wim 15:b70ebfffb258 82 // E2 is used for LCD40x4 (second controller)
wim 26:bd897a001012 83 // BL may be used to control backlight
wim 15:b70ebfffb258 84 #define D_LCD_PIN_D4 0
wim 15:b70ebfffb258 85 #define D_LCD_PIN_D5 1
wim 15:b70ebfffb258 86 #define D_LCD_PIN_D6 2
wim 15:b70ebfffb258 87 #define D_LCD_PIN_D7 3
wim 15:b70ebfffb258 88 #define D_LCD_PIN_RS 4
wim 15:b70ebfffb258 89 #define D_LCD_PIN_E 5
wim 15:b70ebfffb258 90 #define D_LCD_PIN_E2 6
wim 15:b70ebfffb258 91 #define D_LCD_PIN_BL 7
wim 13:24506ba22480 92
wim 20:e0da005a777f 93 #define D_LCD_PIN_RW D_LCD_PIN_E2
wim 20:e0da005a777f 94
wim 26:bd897a001012 95 //Select I2C Portexpander type (one option only)
wim 26:bd897a001012 96 #define PCF8574 1
wim 26:bd897a001012 97 #define MCP23008 0
wim 26:bd897a001012 98 #endif
wim 20:e0da005a777f 99
wim 26:bd897a001012 100 #if (ADAFRUIT==1)
wim 26:bd897a001012 101 //Definitions for i2cspilcdbackpack from Adafruit, See http://www.ladyada.net/products/i2cspilcdbackpack
wim 26:bd897a001012 102 //This hardware supports both an I2C expander (MCP23008) and an SPI expander (74595) selectable by a jumper.
wim 26:bd897a001012 103 //
wim 26:bd897a001012 104 //Note: LCD RW pin must be kept LOW
wim 26:bd897a001012 105 // E2 is not available on this hardware and so it does not support LCD40x4 (second controller)
wim 26:bd897a001012 106 // BL is used to control backlight
wim 26:bd897a001012 107 #define D_LCD_PIN_0 0
wim 26:bd897a001012 108 #define D_LCD_PIN_RS 1
wim 26:bd897a001012 109 #define D_LCD_PIN_E 2
wim 26:bd897a001012 110 #define D_LCD_PIN_D4 3
wim 26:bd897a001012 111 #define D_LCD_PIN_D5 4
wim 26:bd897a001012 112 #define D_LCD_PIN_D6 5
wim 26:bd897a001012 113 #define D_LCD_PIN_D7 6
wim 26:bd897a001012 114 #define D_LCD_PIN_BL 7
wim 26:bd897a001012 115
wim 26:bd897a001012 116 #define D_LCD_PIN_E2 D_LCD_PIN_0
wim 26:bd897a001012 117
wim 26:bd897a001012 118 //Force I2C portexpander type
wim 26:bd897a001012 119 #define PCF8574 0
wim 26:bd897a001012 120 #define MCP23008 1
wim 26:bd897a001012 121 #endif
wim 26:bd897a001012 122
wim 26:bd897a001012 123 #if (DFROBOT==1)
wim 20:e0da005a777f 124 //Definitions for LCD2004 Module from DFROBOT, See http://arduino-info.wikispaces.com/LCD-Blue-I2C
wim 26:bd897a001012 125 //This hardware uses PCF8574 and is different from earlier/different Arduino I2C LCD displays
wim 26:bd897a001012 126 //
wim 20:e0da005a777f 127 //Note: LCD RW pin must be kept LOW
wim 26:bd897a001012 128 // E2 is not available on default Arduino hardware and so it does not support LCD40x4 (second controller)
wim 20:e0da005a777f 129 // BL is used to control backlight
wim 20:e0da005a777f 130 #define D_LCD_PIN_RS 0
wim 20:e0da005a777f 131 #define D_LCD_PIN_RW 1
wim 20:e0da005a777f 132 #define D_LCD_PIN_E 2
wim 20:e0da005a777f 133 #define D_LCD_PIN_BL 3
wim 20:e0da005a777f 134 #define D_LCD_PIN_D4 4
wim 20:e0da005a777f 135 #define D_LCD_PIN_D5 5
wim 20:e0da005a777f 136 #define D_LCD_PIN_D6 6
wim 20:e0da005a777f 137 #define D_LCD_PIN_D7 7
wim 20:e0da005a777f 138
wim 20:e0da005a777f 139 #define D_LCD_PIN_E2 D_LCD_PIN_RW
wim 26:bd897a001012 140
wim 26:bd897a001012 141 //Force I2C portexpander type
wim 26:bd897a001012 142 #define PCF8574 1
wim 26:bd897a001012 143 #define MCP23008 0
wim 20:e0da005a777f 144 #endif
wim 13:24506ba22480 145
wim 26:bd897a001012 146 //Bitpattern Defines for I2C PCF8574/PCF8574A, MCP23008 and SPI 74595 Bus expanders
wim 13:24506ba22480 147 //
wim 13:24506ba22480 148 #define D_LCD_D4 (1<<D_LCD_PIN_D4)
wim 13:24506ba22480 149 #define D_LCD_D5 (1<<D_LCD_PIN_D5)
wim 13:24506ba22480 150 #define D_LCD_D6 (1<<D_LCD_PIN_D6)
wim 13:24506ba22480 151 #define D_LCD_D7 (1<<D_LCD_PIN_D7)
wim 13:24506ba22480 152 #define D_LCD_RS (1<<D_LCD_PIN_RS)
wim 13:24506ba22480 153 #define D_LCD_E (1<<D_LCD_PIN_E)
wim 13:24506ba22480 154 #define D_LCD_E2 (1<<D_LCD_PIN_E2)
wim 13:24506ba22480 155 #define D_LCD_BL (1<<D_LCD_PIN_BL)
wim 20:e0da005a777f 156 //#define D_LCD_RW (1<<D_LCD_PIN_RW)
wim 20:e0da005a777f 157
wim 20:e0da005a777f 158 #define D_LCD_BUS_MSK (D_LCD_D4 | D_LCD_D5 | D_LCD_D6 | D_LCD_D7)
wim 20:e0da005a777f 159 #define D_LCD_BUS_DEF 0x00
wim 13:24506ba22480 160
wim 26:bd897a001012 161 /* PCF8574/PCF8574A I2C portexpander slave address */
wim 26:bd897a001012 162 #define PCF8574_SA0 0x40
wim 26:bd897a001012 163 #define PCF8574_SA1 0x42
wim 26:bd897a001012 164 #define PCF8574_SA2 0x44
wim 26:bd897a001012 165 #define PCF8574_SA3 0x46
wim 26:bd897a001012 166 #define PCF8574_SA4 0x48
wim 26:bd897a001012 167 #define PCF8574_SA5 0x4A
wim 26:bd897a001012 168 #define PCF8574_SA6 0x4C
wim 26:bd897a001012 169 #define PCF8574_SA7 0x4E
wim 26:bd897a001012 170
wim 26:bd897a001012 171 #define PCF8574A_SA0 0x70
wim 26:bd897a001012 172 #define PCF8574A_SA1 0x72
wim 26:bd897a001012 173 #define PCF8574A_SA2 0x74
wim 26:bd897a001012 174 #define PCF8574A_SA3 0x76
wim 26:bd897a001012 175 #define PCF8574A_SA4 0x78
wim 26:bd897a001012 176 #define PCF8574A_SA5 0x7A
wim 26:bd897a001012 177 #define PCF8574A_SA6 0x7C
wim 26:bd897a001012 178 #define PCF8574A_SA7 0x7E
wim 26:bd897a001012 179
wim 26:bd897a001012 180 /* MCP23008 I2C portexpander slave address */
wim 26:bd897a001012 181 #define MCP23008_SA0 0x40
wim 26:bd897a001012 182 #define MCP23008_SA1 0x42
wim 26:bd897a001012 183 #define MCP23008_SA2 0x44
wim 26:bd897a001012 184 #define MCP23008_SA3 0x46
wim 26:bd897a001012 185 #define MCP23008_SA4 0x48
wim 26:bd897a001012 186 #define MCP23008_SA5 0x4A
wim 26:bd897a001012 187 #define MCP23008_SA6 0x4C
wim 26:bd897a001012 188 #define MCP23008_SA7 0x4E
wim 26:bd897a001012 189
wim 26:bd897a001012 190
wim 26:bd897a001012 191 /* MCP23008 I2C portexpander internal registers */
wim 26:bd897a001012 192 #define IODIR 0x00
wim 26:bd897a001012 193 #define IPOL 0x01
wim 26:bd897a001012 194 #define GPINTEN 0x02
wim 26:bd897a001012 195 #define DEFVAL 0x03
wim 26:bd897a001012 196 #define INTCON 0x04
wim 26:bd897a001012 197 #define IOCON 0x05
wim 26:bd897a001012 198 #define GPPU 0x06
wim 26:bd897a001012 199 #define INTF 0x07
wim 26:bd897a001012 200 #define INTCAP 0x08
wim 26:bd897a001012 201 #define GPIO 0x09
wim 26:bd897a001012 202 #define OLAT 0x0A
wim 26:bd897a001012 203
wim 26:bd897a001012 204
wim 26:bd897a001012 205 /* ST7032I I2C slave address */
wim 26:bd897a001012 206 #define ST7032_SA 0x7C
wim 26:bd897a001012 207
wim 13:24506ba22480 208
wim 13:24506ba22480 209 /** Some sample User Defined Chars 5x7 dots */
wim 11:9ec02df863a1 210 const char udc_ae[] = {0x00, 0x00, 0x1B, 0x05, 0x1F, 0x14, 0x1F, 0x00}; //æ
wim 11:9ec02df863a1 211 const char udc_0e[] = {0x00, 0x00, 0x0E, 0x13, 0x15, 0x19, 0x0E, 0x00}; //ø
wim 11:9ec02df863a1 212 const char udc_ao[] = {0x0E, 0x0A, 0x0E, 0x01, 0x0F, 0x11, 0x0F, 0x00}; //å
wim 11:9ec02df863a1 213 const char udc_AE[] = {0x0F, 0x14, 0x14, 0x1F, 0x14, 0x14, 0x17, 0x00}; //Æ
wim 11:9ec02df863a1 214 const char udc_0E[] = {0x0E, 0x13, 0x15, 0x15, 0x15, 0x19, 0x0E, 0x00}; //Ø
wim 18:bd65dc10f27f 215 const char udc_Ao[] = {0x0E, 0x0A, 0x0E, 0x11, 0x1F, 0x11, 0x11, 0x00}; //Å
wim 18:bd65dc10f27f 216 const char udc_PO[] = {0x04, 0x0A, 0x0A, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Open
wim 18:bd65dc10f27f 217 const char udc_PC[] = {0x1C, 0x10, 0x08, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Closed
wim 11:9ec02df863a1 218
wim 11:9ec02df863a1 219 const char udc_0[] = {0x18, 0x14, 0x12, 0x11, 0x12, 0x14, 0x18, 0x00}; // |>
wim 11:9ec02df863a1 220 const char udc_1[] = {0x03, 0x05, 0x09, 0x11, 0x09, 0x05, 0x03, 0x00}; // <|
wim 11:9ec02df863a1 221 const char udc_2[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}; // |
wim 11:9ec02df863a1 222 const char udc_3[] = {0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00}; // ||
wim 11:9ec02df863a1 223 const char udc_4[] = {0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00}; // |||
wim 11:9ec02df863a1 224 const char udc_5[] = {0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00}; // =
wim 11:9ec02df863a1 225 const char udc_6[] = {0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0x00}; // checkerboard
wim 11:9ec02df863a1 226 const char udc_7[] = {0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x10, 0x00}; // \
wim 11:9ec02df863a1 227
wim 13:24506ba22480 228 const char udc_degr[] = {0x06, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00}; // Degree symbol
wim 13:24506ba22480 229
wim 13:24506ba22480 230 const char udc_TM_T[] = {0x1F, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; // Trademark T
wim 13:24506ba22480 231 const char udc_TM_M[] = {0x11, 0x1B, 0x15, 0x11, 0x00, 0x00, 0x00, 0x00}; // Trademark M
wim 13:24506ba22480 232
wim 13:24506ba22480 233 //const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Full
wim 13:24506ba22480 234 //const char udc_Bat_Ha[] = {0x0E, 0x11, 0x13, 0x17, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Half
wim 13:24506ba22480 235 //const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x00}; // Battery Low
wim 13:24506ba22480 236 const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Full
wim 13:24506ba22480 237 const char udc_Bat_Ha[] = {0x0E, 0x11, 0x11, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Half
wim 13:24506ba22480 238 const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x1F, 0x00}; // Battery Low
wim 18:bd65dc10f27f 239 const char udc_AC[] = {0x0A, 0x0A, 0x1F, 0x11, 0x0E, 0x04, 0x04, 0x00}; // AC Power
wim 13:24506ba22480 240
wim 18:bd65dc10f27f 241 //const char udc_smiley[] = {0x00, 0x0A, 0x00, 0x04, 0x11, 0x0E, 0x00, 0x00}; // Smiley
wim 18:bd65dc10f27f 242 //const char udc_droopy[] = {0x00, 0x0A, 0x00, 0x04, 0x00, 0x0E, 0x11, 0x00}; // Droopey
wim 18:bd65dc10f27f 243 //const char udc_note[] = {0x01, 0x03, 0x05, 0x09, 0x0B, 0x1B, 0x18, 0x00}; // Note
wim 18:bd65dc10f27f 244
wim 18:bd65dc10f27f 245 //const char udc_bar_1[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}; // Bar 1
wim 18:bd65dc10f27f 246 //const char udc_bar_2[] = {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}; // Bar 11
wim 18:bd65dc10f27f 247 //const char udc_bar_3[] = {0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x00}; // Bar 111
wim 18:bd65dc10f27f 248 //const char udc_bar_4[] = {0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x00}; // Bar 1111
wim 18:bd65dc10f27f 249 //const char udc_bar_5[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Bar 11111
wim 13:24506ba22480 250
wim 28:30fa94f7341c 251 //const char udc_ch_1[] = {0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00}; // Hor bars 4
wim 28:30fa94f7341c 252 //const char udc_ch_2[] = {0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f}; // Hor bars 4 (inverted)
wim 28:30fa94f7341c 253 //const char udc_ch_3[] = {0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15}; // Ver bars 3
wim 28:30fa94f7341c 254 //const char udc_ch_4[] = {0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}; // Ver bars 3 (inverted)
wim 28:30fa94f7341c 255 //const char udc_ch_yr[] = {0x08, 0x0f, 0x12, 0x0f, 0x0a, 0x1f, 0x02, 0x02}; // Year (kanji)
wim 28:30fa94f7341c 256 //const char udc_ch_mo[] = {0x0f, 0x09, 0x0f, 0x09, 0x0f, 0x09, 0x09, 0x13}; // Month (kanji)
wim 28:30fa94f7341c 257 //const char udc_ch_dy[] = {0x1f, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11, 0x1F}; // Day (kanji)
wim 28:30fa94f7341c 258 //const char udc_ch_mi[] = {0x0C, 0x0a, 0x11, 0x1f, 0x09, 0x09, 0x09, 0x13}; // minute (kanji)
wim 28:30fa94f7341c 259
wim 11:9ec02df863a1 260
wim 11:9ec02df863a1 261 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
wim 11:9ec02df863a1 262 *
wim 22:35742ec80c24 263 * @brief Currently supports 8x1, 8x2, 12x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
wim 27:22d5086f6ba6 264 * 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 265 *
wim 11:9ec02df863a1 266 */
wim 21:9eb628d9e164 267 class TextLCD_Base : public Stream {
simon 1:ac48b187213c 268 public:
simon 1:ac48b187213c 269
simon 2:227356c7d12c 270 /** LCD panel format */
simon 1:ac48b187213c 271 enum LCDType {
wim 8:03116f75b66e 272 LCD8x1, /**< 8x1 LCD panel */
wim 13:24506ba22480 273 LCD8x2, /**< 8x2 LCD panel */
wim 18:bd65dc10f27f 274 LCD8x2B, /**< 8x2 LCD panel (actually 16x1) */
wim 15:b70ebfffb258 275 LCD12x2, /**< 12x2 LCD panel */
wim 28:30fa94f7341c 276 // LCD12x3, /**< 12x3 LCD panel, special mode PCF21XX */
wim 15:b70ebfffb258 277 LCD12x4, /**< 12x4 LCD panel */
wim 28:30fa94f7341c 278 // LCD12x4B, /**< 12x4 LCD panel, special mode PCF21XX */
wim 13:24506ba22480 279 LCD16x1, /**< 16x1 LCD panel (actually 8x2) */
wim 8:03116f75b66e 280 LCD16x2, /**< 16x2 LCD panel (default) */
wim 8:03116f75b66e 281 LCD16x2B, /**< 16x2 LCD panel alternate addressing */
wim 28:30fa94f7341c 282 // LCD16x3, /**< 16x3 LCD panel, special mode ST7036 */
wim 8:03116f75b66e 283 LCD16x4, /**< 16x4 LCD panel */
wim 8:03116f75b66e 284 LCD20x2, /**< 20x2 LCD panel */
wim 8:03116f75b66e 285 LCD20x4, /**< 20x4 LCD panel */
wim 9:0893d986e717 286 LCD24x2, /**< 24x2 LCD panel */
wim 10:dd9b3a696acd 287 LCD24x4, /**< 24x4 LCD panel, special mode KS0078 */
wim 15:b70ebfffb258 288 LCD40x2, /**< 40x2 LCD panel */
wim 15:b70ebfffb258 289 LCD40x4 /**< 40x4 LCD panel, Two controller version */
simon 1:ac48b187213c 290 };
simon 1:ac48b187213c 291
wim 19:c747b9e2e7b8 292 /** LCD Controller Device */
wim 19:c747b9e2e7b8 293 enum LCDCtrl {
wim 28:30fa94f7341c 294 HD44780, /**< HD44780 (default) */
wim 28:30fa94f7341c 295 WS0010, /**< WS0010 OLED Controller */
wim 28:30fa94f7341c 296 ST7036, /**< ST7036 3V3 with Booster */
wim 28:30fa94f7341c 297 ST7032_3V3, /**< ST7032 3V3 with Booster */
wim 28:30fa94f7341c 298 ST7032_5V /**< ST7032 5V no Booster */
wim 28:30fa94f7341c 299 // PCF210X, /**< PCF210X 5V no Booster */
wim 28:30fa94f7341c 300 // PCF211X /**< PCF211X 3V3 with Booster */
wim 19:c747b9e2e7b8 301 };
wim 19:c747b9e2e7b8 302
wim 19:c747b9e2e7b8 303
wim 10:dd9b3a696acd 304 /** LCD Cursor control */
wim 10:dd9b3a696acd 305 enum LCDCursor {
wim 17:652ab113bc2e 306 CurOff_BlkOff = 0x00, /**< Cursor Off, Blinking Char Off */
wim 17:652ab113bc2e 307 CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */
wim 17:652ab113bc2e 308 CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */
wim 17:652ab113bc2e 309 CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */
wim 17:652ab113bc2e 310 };
wim 17:652ab113bc2e 311
wim 17:652ab113bc2e 312
wim 17:652ab113bc2e 313 /** LCD Display control */
wim 17:652ab113bc2e 314 enum LCDMode {
wim 17:652ab113bc2e 315 DispOff = 0x00, /**< Display Off */
wim 17:652ab113bc2e 316 DispOn = 0x04 /**< Display On */
wim 10:dd9b3a696acd 317 };
wim 10:dd9b3a696acd 318
wim 20:e0da005a777f 319 /** LCD Backlight control */
wim 20:e0da005a777f 320 enum LCDBacklight {
wim 20:e0da005a777f 321 LightOff, /**< Backlight Off */
wim 20:e0da005a777f 322 LightOn /**< Backlight On */
wim 20:e0da005a777f 323 };
wim 10:dd9b3a696acd 324
simon 2:227356c7d12c 325
simon 2:227356c7d12c 326 #if DOXYGEN_ONLY
simon 2:227356c7d12c 327 /** Write a character to the LCD
simon 2:227356c7d12c 328 *
simon 2:227356c7d12c 329 * @param c The character to write to the display
simon 2:227356c7d12c 330 */
simon 2:227356c7d12c 331 int putc(int c);
simon 2:227356c7d12c 332
simon 2:227356c7d12c 333 /** Write a formated string to the LCD
simon 2:227356c7d12c 334 *
simon 2:227356c7d12c 335 * @param format A printf-style format string, followed by the
simon 2:227356c7d12c 336 * variables to use in formating the string.
simon 2:227356c7d12c 337 */
simon 2:227356c7d12c 338 int printf(const char* format, ...);
simon 2:227356c7d12c 339 #endif
simon 2:227356c7d12c 340
simon 2:227356c7d12c 341 /** Locate to a screen column and row
simon 2:227356c7d12c 342 *
simon 2:227356c7d12c 343 * @param column The horizontal position from the left, indexed from 0
simon 2:227356c7d12c 344 * @param row The vertical position from the top, indexed from 0
simon 2:227356c7d12c 345 */
simon 1:ac48b187213c 346 void locate(int column, int row);
simon 2:227356c7d12c 347
wim 10:dd9b3a696acd 348
wim 10:dd9b3a696acd 349 /** Return the memoryaddress of screen column and row location
wim 10:dd9b3a696acd 350 *
wim 10:dd9b3a696acd 351 * @param column The horizontal position from the left, indexed from 0
wim 10:dd9b3a696acd 352 * @param row The vertical position from the top, indexed from 0
wim 10:dd9b3a696acd 353 * @param return The memoryaddress of screen column and row location
wim 10:dd9b3a696acd 354 */
wim 9:0893d986e717 355 int getAddress(int column, int row);
wim 10:dd9b3a696acd 356
wim 10:dd9b3a696acd 357
wim 10:dd9b3a696acd 358 /** Set the memoryaddress of screen column and row location
wim 10:dd9b3a696acd 359 *
wim 10:dd9b3a696acd 360 * @param column The horizontal position from the left, indexed from 0
wim 10:dd9b3a696acd 361 * @param row The vertical position from the top, indexed from 0
wim 10:dd9b3a696acd 362 */
wim 9:0893d986e717 363 void setAddress(int column, int row);
wim 9:0893d986e717 364
wim 10:dd9b3a696acd 365
wim 22:35742ec80c24 366 /** Clear the screen and locate to 0,0
wim 22:35742ec80c24 367 */
simon 1:ac48b187213c 368 void cls();
simon 2:227356c7d12c 369
wim 10:dd9b3a696acd 370 /** Return the number of rows
wim 10:dd9b3a696acd 371 *
wim 10:dd9b3a696acd 372 * @param return The number of rows
wim 10:dd9b3a696acd 373 */
simon 1:ac48b187213c 374 int rows();
wim 10:dd9b3a696acd 375
wim 10:dd9b3a696acd 376 /** Return the number of columns
wim 10:dd9b3a696acd 377 *
wim 10:dd9b3a696acd 378 * @param return The number of columns
wim 10:dd9b3a696acd 379 */
wim 10:dd9b3a696acd 380 int columns();
simon 2:227356c7d12c 381
wim 11:9ec02df863a1 382 /** Set the Cursormode
wim 11:9ec02df863a1 383 *
wim 17:652ab113bc2e 384 * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn)
wim 11:9ec02df863a1 385 */
wim 17:652ab113bc2e 386 void setCursor(LCDCursor cursorMode);
wim 17:652ab113bc2e 387
wim 17:652ab113bc2e 388
wim 17:652ab113bc2e 389 /** Set the Displaymode
wim 17:652ab113bc2e 390 *
wim 17:652ab113bc2e 391 * @param displayMode The Display mode (DispOff, DispOn)
wim 17:652ab113bc2e 392 */
wim 21:9eb628d9e164 393 void setMode(LCDMode displayMode);
wim 11:9ec02df863a1 394
wim 20:e0da005a777f 395 /** Set the Backlight mode
wim 20:e0da005a777f 396 *
wim 21:9eb628d9e164 397 * @param backlightMode The Backlight mode (LightOff, LightOn)
wim 20:e0da005a777f 398 */
wim 21:9eb628d9e164 399 void setBacklight(LCDBacklight backlightMode);
wim 20:e0da005a777f 400
wim 11:9ec02df863a1 401
wim 11:9ec02df863a1 402 /** Set User Defined Characters
wim 11:9ec02df863a1 403 *
wim 11:9ec02df863a1 404 * @param unsigned char c The Index of the UDC (0..7)
wim 12:6bf9d9957d31 405 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits)
wim 11:9ec02df863a1 406 */
wim 11:9ec02df863a1 407 void setUDC(unsigned char c, char *udc_data);
wim 11:9ec02df863a1 408
wim 20:e0da005a777f 409
simon 1:ac48b187213c 410 protected:
wim 13:24506ba22480 411
wim 21:9eb628d9e164 412 /** LCD controller select, mainly used for LCD40x4
wim 21:9eb628d9e164 413 */
wim 19:c747b9e2e7b8 414 enum _LCDCtrl_Idx {
wim 15:b70ebfffb258 415 _LCDCtrl_0, /*< Primary */
wim 15:b70ebfffb258 416 _LCDCtrl_1, /*< Secondary */
wim 15:b70ebfffb258 417 };
wim 21:9eb628d9e164 418
wim 21:9eb628d9e164 419 /** Create a TextLCD_Base interface
wim 21:9eb628d9e164 420 * @brief Base class, can not be instantiated
wim 21:9eb628d9e164 421 *
wim 21:9eb628d9e164 422 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 423 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 424 */
wim 21:9eb628d9e164 425 TextLCD_Base(LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 21:9eb628d9e164 426
wim 15:b70ebfffb258 427
simon 1:ac48b187213c 428 // Stream implementation functions
simon 1:ac48b187213c 429 virtual int _putc(int value);
simon 1:ac48b187213c 430 virtual int _getc();
simon 1:ac48b187213c 431
wim 21:9eb628d9e164 432 /** Low level methods for LCD controller
wim 21:9eb628d9e164 433 */
wim 13:24506ba22480 434 void _init();
wim 15:b70ebfffb258 435 void _initCtrl();
wim 13:24506ba22480 436 int _address(int column, int row);
wim 21:9eb628d9e164 437 void _setCursor(LCDCursor show);
wim 17:652ab113bc2e 438 void _setUDC(unsigned char c, char *udc_data);
wim 21:9eb628d9e164 439 void _setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType);
wim 13:24506ba22480 440
wim 21:9eb628d9e164 441 /** Low level write operations to LCD controller
wim 21:9eb628d9e164 442 */
wim 17:652ab113bc2e 443 void _writeNibble(int value);
Sissors 24:fb3399713710 444 virtual void _writeByte(int value);
wim 15:b70ebfffb258 445 void _writeCommand(int command);
wim 15:b70ebfffb258 446 void _writeData(int data);
wim 15:b70ebfffb258 447
wim 21:9eb628d9e164 448 /** Pure Virtual Low level writes to LCD Bus (serial or parallel)
wim 21:9eb628d9e164 449 */
wim 21:9eb628d9e164 450 virtual void _setEnable(bool value) = 0;
wim 21:9eb628d9e164 451 virtual void _setRS(bool value) = 0;
wim 21:9eb628d9e164 452 virtual void _setBL(bool value) = 0;
wim 21:9eb628d9e164 453 virtual void _setData(int value) = 0;
wim 13:24506ba22480 454
wim 13:24506ba22480 455
wim 13:24506ba22480 456 //Display type
simon 1:ac48b187213c 457 LCDType _type;
simon 1:ac48b187213c 458
wim 21:9eb628d9e164 459 //Display mode
wim 17:652ab113bc2e 460 LCDMode _currentMode;
wim 17:652ab113bc2e 461
wim 19:c747b9e2e7b8 462 //Controller type
wim 19:c747b9e2e7b8 463 LCDCtrl _ctrl;
wim 19:c747b9e2e7b8 464
wim 15:b70ebfffb258 465 //Controller select, mainly used for LCD40x4
wim 19:c747b9e2e7b8 466 _LCDCtrl_Idx _ctrl_idx;
wim 15:b70ebfffb258 467
wim 13:24506ba22480 468 // Cursor
simon 1:ac48b187213c 469 int _column;
simon 1:ac48b187213c 470 int _row;
wim 15:b70ebfffb258 471 LCDCursor _currentCursor;
simon 1:ac48b187213c 472 };
simon 1:ac48b187213c 473
wim 23:d47f226efb24 474 //--------- End TextLCD_Base -----------
wim 22:35742ec80c24 475
wim 22:35742ec80c24 476
wim 22:35742ec80c24 477
wim 23:d47f226efb24 478 //--------- Start TextLCD Bus -----------
wim 21:9eb628d9e164 479
wim 21:9eb628d9e164 480 /** Create a TextLCD interface for using regular mbed pins
wim 21:9eb628d9e164 481 *
wim 21:9eb628d9e164 482 */
wim 21:9eb628d9e164 483 class TextLCD : public TextLCD_Base {
wim 21:9eb628d9e164 484 public:
wim 21:9eb628d9e164 485 /** Create a TextLCD interface for using regular mbed pins
wim 21:9eb628d9e164 486 *
wim 21:9eb628d9e164 487 * @param rs Instruction/data control line
wim 21:9eb628d9e164 488 * @param e Enable line (clock)
wim 21:9eb628d9e164 489 * @param d4-d7 Data lines for using as a 4-bit interface
wim 21:9eb628d9e164 490 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 491 * @param bl Backlight control line (optional, default = NC)
wim 21:9eb628d9e164 492 * @param e2 Enable2 line (clock for second controller, LCD40x4 only)
wim 21:9eb628d9e164 493 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 494 */
wim 21:9eb628d9e164 495 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 496
wim 22:35742ec80c24 497
wim 22:35742ec80c24 498 /** Destruct a TextLCD interface for using regular mbed pins
wim 22:35742ec80c24 499 *
wim 22:35742ec80c24 500 * @param none
wim 22:35742ec80c24 501 * @return none
wim 22:35742ec80c24 502 */
wim 22:35742ec80c24 503 virtual ~TextLCD();
wim 22:35742ec80c24 504
wim 21:9eb628d9e164 505 private:
wim 21:9eb628d9e164 506 //Low level writes to LCD Bus (serial or parallel)
wim 21:9eb628d9e164 507 virtual void _setEnable(bool value);
wim 21:9eb628d9e164 508 virtual void _setRS(bool value);
wim 21:9eb628d9e164 509 virtual void _setBL(bool value);
wim 21:9eb628d9e164 510 virtual void _setData(int value);
wim 21:9eb628d9e164 511
wim 22:35742ec80c24 512 /** Regular mbed pins bus
wim 22:35742ec80c24 513 */
wim 22:35742ec80c24 514 DigitalOut _rs, _e;
wim 22:35742ec80c24 515 BusOut _d;
wim 22:35742ec80c24 516
wim 22:35742ec80c24 517 /** Optional Hardware pins for the Backlight and LCD40x4 device
wim 22:35742ec80c24 518 * Default PinName value is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins
wim 22:35742ec80c24 519 */
wim 22:35742ec80c24 520 DigitalOut *_bl, *_e2;
wim 21:9eb628d9e164 521 };
wim 21:9eb628d9e164 522
wim 22:35742ec80c24 523
wim 23:d47f226efb24 524 //----------- End TextLCD ---------------
wim 21:9eb628d9e164 525
wim 21:9eb628d9e164 526
wim 23:d47f226efb24 527 //--------- Start TextLCD_I2C -----------
wim 22:35742ec80c24 528
wim 22:35742ec80c24 529
wim 26:bd897a001012 530 /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander
wim 21:9eb628d9e164 531 *
wim 21:9eb628d9e164 532 */
wim 21:9eb628d9e164 533 class TextLCD_I2C : public TextLCD_Base {
wim 21:9eb628d9e164 534 public:
wim 26:bd897a001012 535 /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander
wim 21:9eb628d9e164 536 *
wim 21:9eb628d9e164 537 * @param i2c I2C Bus
wim 26:bd897a001012 538 * @param deviceAddress I2C slave address (PCF8574 or PCF8574A, default = PCF8574_SA0 = 0x40)
wim 21:9eb628d9e164 539 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 540 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 541 */
wim 26:bd897a001012 542 TextLCD_I2C(I2C *i2c, char deviceAddress = PCF8574_SA0, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 21:9eb628d9e164 543
wim 21:9eb628d9e164 544 private:
wim 21:9eb628d9e164 545 //Low level writes to LCD Bus (serial or parallel)
wim 21:9eb628d9e164 546 virtual void _setEnable(bool value);
wim 21:9eb628d9e164 547 virtual void _setRS(bool value);
wim 21:9eb628d9e164 548 virtual void _setBL(bool value);
wim 26:bd897a001012 549 virtual void _setData(int value);
wim 26:bd897a001012 550
wim 26:bd897a001012 551 // Write data to MCP23008 I2C portexpander
wim 26:bd897a001012 552 void _write_register (int reg, int value);
wim 21:9eb628d9e164 553
wim 21:9eb628d9e164 554 //I2C bus
wim 21:9eb628d9e164 555 I2C *_i2c;
wim 21:9eb628d9e164 556 char _slaveAddress;
wim 21:9eb628d9e164 557
wim 21:9eb628d9e164 558 // Internal bus mirror value for serial bus only
wim 21:9eb628d9e164 559 char _lcd_bus;
wim 21:9eb628d9e164 560
wim 21:9eb628d9e164 561 };
wim 21:9eb628d9e164 562
wim 21:9eb628d9e164 563
wim 23:d47f226efb24 564 //---------- End TextLCD_I2C ------------
wim 22:35742ec80c24 565
wim 22:35742ec80c24 566
wim 22:35742ec80c24 567
wim 23:d47f226efb24 568 //--------- Start TextLCD_SPI -----------
wim 22:35742ec80c24 569
wim 21:9eb628d9e164 570
wim 21:9eb628d9e164 571 /** Create a TextLCD interface using an SPI 74595 portexpander
wim 21:9eb628d9e164 572 *
wim 21:9eb628d9e164 573 */
wim 21:9eb628d9e164 574 class TextLCD_SPI : public TextLCD_Base {
wim 21:9eb628d9e164 575 public:
wim 21:9eb628d9e164 576 /** Create a TextLCD interface using an SPI 74595 portexpander
wim 21:9eb628d9e164 577 *
wim 21:9eb628d9e164 578 * @param spi SPI Bus
wim 21:9eb628d9e164 579 * @param cs chip select pin (active low)
wim 21:9eb628d9e164 580 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 581 * @param ctrl LCD controller (default = HD44780)
wim 21:9eb628d9e164 582 */
wim 21:9eb628d9e164 583 TextLCD_SPI(SPI *spi, PinName cs, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 21:9eb628d9e164 584
wim 21:9eb628d9e164 585
wim 21:9eb628d9e164 586 private:
wim 21:9eb628d9e164 587 //Low level writes to LCD Bus (serial or parallel)
wim 21:9eb628d9e164 588 virtual void _setEnable(bool value);
wim 21:9eb628d9e164 589 virtual void _setRS(bool value);
wim 21:9eb628d9e164 590 virtual void _setBL(bool value);
wim 21:9eb628d9e164 591 virtual void _setData(int value);
wim 21:9eb628d9e164 592 virtual void _setCS(bool value);
wim 21:9eb628d9e164 593
wim 21:9eb628d9e164 594 //Low level writes to LCD serial bus only
wim 21:9eb628d9e164 595 void _writeBus();
wim 21:9eb628d9e164 596
wim 21:9eb628d9e164 597 // SPI bus
wim 21:9eb628d9e164 598 SPI *_spi;
wim 21:9eb628d9e164 599 DigitalOut _cs;
wim 21:9eb628d9e164 600
wim 21:9eb628d9e164 601 // Internal bus mirror value for serial bus only
wim 21:9eb628d9e164 602 char _lcd_bus;
wim 21:9eb628d9e164 603
wim 21:9eb628d9e164 604 };
wim 21:9eb628d9e164 605
wim 23:d47f226efb24 606 //---------- End TextLCD_SPI ------------
wim 21:9eb628d9e164 607
Sissors 24:fb3399713710 608
Sissors 24:fb3399713710 609
wim 26:bd897a001012 610 //--------- Start TextLCD_SPI_N -----------
Sissors 24:fb3399713710 611
wim 25:6162b31128c9 612 /** Create a TextLCD interface using a controller with native SPI interface
Sissors 24:fb3399713710 613 *
Sissors 24:fb3399713710 614 */
wim 25:6162b31128c9 615 class TextLCD_SPI_N : public TextLCD_Base {
Sissors 24:fb3399713710 616 public:
wim 25:6162b31128c9 617 /** Create a TextLCD interface using a controller with native SPI interface
Sissors 24:fb3399713710 618 *
Sissors 24:fb3399713710 619 * @param spi SPI Bus
Sissors 24:fb3399713710 620 * @param cs chip select pin (active low)
Sissors 24:fb3399713710 621 * @param rs Instruction/data control line
Sissors 24:fb3399713710 622 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Sissors 24:fb3399713710 623 * @param bl Backlight control line (optional, default = NC)
wim 26:bd897a001012 624 * @param ctrl LCD controller (default = ST7032_3V3)
Sissors 24:fb3399713710 625 */
wim 26:bd897a001012 626 TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3);
wim 25:6162b31128c9 627 virtual ~TextLCD_SPI_N(void);
Sissors 24:fb3399713710 628
Sissors 24:fb3399713710 629 private:
Sissors 24:fb3399713710 630 virtual void _setEnable(bool value);
Sissors 24:fb3399713710 631 virtual void _setRS(bool value);
Sissors 24:fb3399713710 632 virtual void _setBL(bool value);
Sissors 24:fb3399713710 633 virtual void _setData(int value);
Sissors 24:fb3399713710 634 virtual void _writeByte(int value);
Sissors 24:fb3399713710 635
Sissors 24:fb3399713710 636 // SPI bus
Sissors 24:fb3399713710 637 SPI *_spi;
Sissors 24:fb3399713710 638 DigitalOut _cs;
Sissors 24:fb3399713710 639 DigitalOut _rs;
Sissors 24:fb3399713710 640 DigitalOut *_bl;
Sissors 24:fb3399713710 641
Sissors 24:fb3399713710 642 };
Sissors 24:fb3399713710 643
wim 25:6162b31128c9 644 //---------- End TextLCD_SPI_N ------------
Sissors 24:fb3399713710 645
wim 26:bd897a001012 646
wim 26:bd897a001012 647 //--------- Start TextLCD_I2C_N -----------
wim 26:bd897a001012 648
wim 26:bd897a001012 649 /** Create a TextLCD interface using a controller with native I2C interface
wim 26:bd897a001012 650 *
wim 26:bd897a001012 651 */
wim 26:bd897a001012 652 class TextLCD_I2C_N : public TextLCD_Base {
wim 26:bd897a001012 653 public:
wim 26:bd897a001012 654 /** Create a TextLCD interface using a controller with native I2C interface
wim 26:bd897a001012 655 *
wim 26:bd897a001012 656 * @param i2c I2C Bus
wim 28:30fa94f7341c 657 * @param deviceAddress I2C slave address (default = ST7032_SA = 0x7C)
wim 26:bd897a001012 658 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 28:30fa94f7341c 659 * @param bl Backlight control line (optional, default = NC)
wim 26:bd897a001012 660 * @param ctrl LCD controller (default = ST7032_3V3)
wim 26:bd897a001012 661 */
wim 28:30fa94f7341c 662 TextLCD_I2C_N(I2C *i2c, char deviceAddress = ST7032_SA, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3);
wim 26:bd897a001012 663 virtual ~TextLCD_I2C_N(void);
wim 26:bd897a001012 664
wim 26:bd897a001012 665 private:
wim 26:bd897a001012 666 virtual void _setEnable(bool value);
wim 26:bd897a001012 667 virtual void _setRS(bool value);
wim 26:bd897a001012 668 virtual void _setBL(bool value);
wim 26:bd897a001012 669 virtual void _setData(int value);
wim 26:bd897a001012 670 virtual void _writeByte(int value);
wim 26:bd897a001012 671
wim 26:bd897a001012 672 //I2C bus
wim 26:bd897a001012 673 I2C *_i2c;
wim 26:bd897a001012 674 char _slaveAddress;
wim 26:bd897a001012 675
wim 28:30fa94f7341c 676 // controlbyte to select between data and command. Internal value for serial bus only
wim 28:30fa94f7341c 677 char _controlbyte;
wim 28:30fa94f7341c 678
wim 28:30fa94f7341c 679 DigitalOut *_bl;
wim 26:bd897a001012 680 };
wim 26:bd897a001012 681
wim 26:bd897a001012 682 //---------- End TextLCD_I2C_N ------------
wim 26:bd897a001012 683
wim 26:bd897a001012 684
simon 1:ac48b187213c 685 #endif