sd

Fork of TextLCD by Wim Huiskamp

Committer:
wim
Date:
Sat Mar 09 19:39:53 2013 +0000
Revision:
18:bd65dc10f27f
Parent:
17:652ab113bc2e
Child:
19:c747b9e2e7b8
Added some UDCs, Updated documentation.

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
simon 1:ac48b187213c 8 *
simon 1:ac48b187213c 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 1:ac48b187213c 10 * of this software and associated documentation files (the "Software"), to deal
simon 1:ac48b187213c 11 * in the Software without restriction, including without limitation the rights
simon 1:ac48b187213c 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 1:ac48b187213c 13 * copies of the Software, and to permit persons to whom the Software is
simon 1:ac48b187213c 14 * furnished to do so, subject to the following conditions:
simon 2:227356c7d12c 15 *
simon 1:ac48b187213c 16 * The above copyright notice and this permission notice shall be included in
simon 1:ac48b187213c 17 * all copies or substantial portions of the Software.
simon 2:227356c7d12c 18 *
simon 1:ac48b187213c 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 1:ac48b187213c 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 1:ac48b187213c 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 1:ac48b187213c 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 1:ac48b187213c 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 1:ac48b187213c 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 1:ac48b187213c 25 * THE SOFTWARE.
simon 1:ac48b187213c 26 */
simon 1:ac48b187213c 27
simon 1:ac48b187213c 28 #ifndef MBED_TEXTLCD_H
simon 1:ac48b187213c 29 #define MBED_TEXTLCD_H
simon 1:ac48b187213c 30
simon 1:ac48b187213c 31 #include "mbed.h"
simon 2:227356c7d12c 32
wim 15:b70ebfffb258 33
simon 5:a53b3e2d6f1e 34 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
simon 2:227356c7d12c 35 *
wim 16:c276b75e6585 36 * Currently supports 8x1, 8x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
wim 16:c276b75e6585 37 * Interface options include direct mbed pins, I2C portexpander (PCF8474) or SPI bus shiftregister (74595)
simon 2:227356c7d12c 38 *
simon 2:227356c7d12c 39 * @code
simon 2:227356c7d12c 40 * #include "mbed.h"
simon 2:227356c7d12c 41 * #include "TextLCD.h"
simon 5:a53b3e2d6f1e 42 *
wim 16:c276b75e6585 43 * // I2C Communication
wim 16:c276b75e6585 44 * I2C i2c_lcd(p28,p27); // SDA, SCL
wim 16:c276b75e6585 45 *
wim 16:c276b75e6585 46 * // SPI Communication
wim 16:c276b75e6585 47 * SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK
wim 16:c276b75e6585 48 *
wim 16:c276b75e6585 49 * TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2
wim 16:c276b75e6585 50 * //TextLCD lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, CS pin, LCD Type
wim 16:c276b75e6585 51 * //TextLCD lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type
simon 5:a53b3e2d6f1e 52 *
simon 2:227356c7d12c 53 * int main() {
wim 16:c276b75e6585 54 * lcd.printf("Hello World!\n");
simon 2:227356c7d12c 55 * }
simon 2:227356c7d12c 56 * @endcode
simon 2:227356c7d12c 57 */
wim 8:03116f75b66e 58
wim 13:24506ba22480 59
wim 16:c276b75e6585 60 //Pin Defines for I2C PCF8574 and SPI 74595 Bus interfaces
wim 13:24506ba22480 61 //LCD and serial portexpanders should be wired accordingly
wim 13:24506ba22480 62 //Note: LCD RW pin must be connected to GND
wim 15:b70ebfffb258 63 // E2 is used for LCD40x4 (second controller)
wim 13:24506ba22480 64 // BL may be used for future expansion to control backlight
wim 13:24506ba22480 65 //
wim 15:b70ebfffb258 66 #define D_LCD_PIN_D4 0
wim 15:b70ebfffb258 67 #define D_LCD_PIN_D5 1
wim 15:b70ebfffb258 68 #define D_LCD_PIN_D6 2
wim 15:b70ebfffb258 69 #define D_LCD_PIN_D7 3
wim 15:b70ebfffb258 70 #define D_LCD_PIN_RS 4
wim 15:b70ebfffb258 71 #define D_LCD_PIN_E 5
wim 15:b70ebfffb258 72 #define D_LCD_PIN_E2 6
wim 15:b70ebfffb258 73 #define D_LCD_PIN_BL 7
wim 13:24506ba22480 74
wim 13:24506ba22480 75 #define D_LCD_BUS_MSK 0x0F
wim 15:b70ebfffb258 76 #define D_LCD_BUS_DEF 0x00
wim 13:24506ba22480 77
wim 13:24506ba22480 78 //Bitpattern Defines for I2C PCF8574 and SPI 74595 Bus
wim 13:24506ba22480 79 //
wim 13:24506ba22480 80 #define D_LCD_D4 (1<<D_LCD_PIN_D4)
wim 13:24506ba22480 81 #define D_LCD_D5 (1<<D_LCD_PIN_D5)
wim 13:24506ba22480 82 #define D_LCD_D6 (1<<D_LCD_PIN_D6)
wim 13:24506ba22480 83 #define D_LCD_D7 (1<<D_LCD_PIN_D7)
wim 13:24506ba22480 84 #define D_LCD_RS (1<<D_LCD_PIN_RS)
wim 13:24506ba22480 85 #define D_LCD_E (1<<D_LCD_PIN_E)
wim 13:24506ba22480 86 #define D_LCD_E2 (1<<D_LCD_PIN_E2)
wim 13:24506ba22480 87 #define D_LCD_BL (1<<D_LCD_PIN_BL)
wim 13:24506ba22480 88
wim 13:24506ba22480 89
wim 13:24506ba22480 90 /** Some sample User Defined Chars 5x7 dots */
wim 11:9ec02df863a1 91 const char udc_ae[] = {0x00, 0x00, 0x1B, 0x05, 0x1F, 0x14, 0x1F, 0x00}; //æ
wim 11:9ec02df863a1 92 const char udc_0e[] = {0x00, 0x00, 0x0E, 0x13, 0x15, 0x19, 0x0E, 0x00}; //ø
wim 11:9ec02df863a1 93 const char udc_ao[] = {0x0E, 0x0A, 0x0E, 0x01, 0x0F, 0x11, 0x0F, 0x00}; //å
wim 11:9ec02df863a1 94 const char udc_AE[] = {0x0F, 0x14, 0x14, 0x1F, 0x14, 0x14, 0x17, 0x00}; //Æ
wim 11:9ec02df863a1 95 const char udc_0E[] = {0x0E, 0x13, 0x15, 0x15, 0x15, 0x19, 0x0E, 0x00}; //Ø
wim 18:bd65dc10f27f 96 const char udc_Ao[] = {0x0E, 0x0A, 0x0E, 0x11, 0x1F, 0x11, 0x11, 0x00}; //Å
wim 18:bd65dc10f27f 97 const char udc_PO[] = {0x04, 0x0A, 0x0A, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Open
wim 18:bd65dc10f27f 98 const char udc_PC[] = {0x1C, 0x10, 0x08, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Closed
wim 11:9ec02df863a1 99
wim 11:9ec02df863a1 100 const char udc_0[] = {0x18, 0x14, 0x12, 0x11, 0x12, 0x14, 0x18, 0x00}; // |>
wim 11:9ec02df863a1 101 const char udc_1[] = {0x03, 0x05, 0x09, 0x11, 0x09, 0x05, 0x03, 0x00}; // <|
wim 11:9ec02df863a1 102 const char udc_2[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}; // |
wim 11:9ec02df863a1 103 const char udc_3[] = {0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00}; // ||
wim 11:9ec02df863a1 104 const char udc_4[] = {0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00}; // |||
wim 11:9ec02df863a1 105 const char udc_5[] = {0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00}; // =
wim 11:9ec02df863a1 106 const char udc_6[] = {0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0x00}; // checkerboard
wim 11:9ec02df863a1 107 const char udc_7[] = {0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x10, 0x00}; // \
wim 11:9ec02df863a1 108
wim 13:24506ba22480 109 const char udc_degr[] = {0x06, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00}; // Degree symbol
wim 13:24506ba22480 110
wim 13:24506ba22480 111 const char udc_TM_T[] = {0x1F, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; // Trademark T
wim 13:24506ba22480 112 const char udc_TM_M[] = {0x11, 0x1B, 0x15, 0x11, 0x00, 0x00, 0x00, 0x00}; // Trademark M
wim 13:24506ba22480 113
wim 13:24506ba22480 114 //const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Full
wim 13:24506ba22480 115 //const char udc_Bat_Ha[] = {0x0E, 0x11, 0x13, 0x17, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Half
wim 13:24506ba22480 116 //const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x00}; // Battery Low
wim 13:24506ba22480 117 const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Full
wim 13:24506ba22480 118 const char udc_Bat_Ha[] = {0x0E, 0x11, 0x11, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Half
wim 13:24506ba22480 119 const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x1F, 0x00}; // Battery Low
wim 18:bd65dc10f27f 120 const char udc_AC[] = {0x0A, 0x0A, 0x1F, 0x11, 0x0E, 0x04, 0x04, 0x00}; // AC Power
wim 13:24506ba22480 121
wim 18:bd65dc10f27f 122 //const char udc_smiley[] = {0x00, 0x0A, 0x00, 0x04, 0x11, 0x0E, 0x00, 0x00}; // Smiley
wim 18:bd65dc10f27f 123 //const char udc_droopy[] = {0x00, 0x0A, 0x00, 0x04, 0x00, 0x0E, 0x11, 0x00}; // Droopey
wim 18:bd65dc10f27f 124 //const char udc_note[] = {0x01, 0x03, 0x05, 0x09, 0x0B, 0x1B, 0x18, 0x00}; // Note
wim 18:bd65dc10f27f 125
wim 18:bd65dc10f27f 126 //const char udc_bar_1[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}; // Bar 1
wim 18:bd65dc10f27f 127 //const char udc_bar_2[] = {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}; // Bar 11
wim 18:bd65dc10f27f 128 //const char udc_bar_3[] = {0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x00}; // Bar 111
wim 18:bd65dc10f27f 129 //const char udc_bar_4[] = {0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x00}; // Bar 1111
wim 18:bd65dc10f27f 130 //const char udc_bar_5[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Bar 11111
wim 13:24506ba22480 131
wim 11:9ec02df863a1 132
wim 11:9ec02df863a1 133 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
wim 11:9ec02df863a1 134 *
wim 16:c276b75e6585 135 * Currently supports 8x1, 8x2, 12x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
wim 11:9ec02df863a1 136 *
wim 11:9ec02df863a1 137 */
simon 1:ac48b187213c 138 class TextLCD : public Stream {
simon 1:ac48b187213c 139 public:
simon 1:ac48b187213c 140
simon 2:227356c7d12c 141 /** LCD panel format */
simon 1:ac48b187213c 142 enum LCDType {
wim 8:03116f75b66e 143 LCD8x1, /**< 8x1 LCD panel */
wim 13:24506ba22480 144 LCD8x2, /**< 8x2 LCD panel */
wim 18:bd65dc10f27f 145 LCD8x2B, /**< 8x2 LCD panel (actually 16x1) */
wim 15:b70ebfffb258 146 LCD12x2, /**< 12x2 LCD panel */
wim 15:b70ebfffb258 147 LCD12x4, /**< 12x4 LCD panel */
wim 13:24506ba22480 148 LCD16x1, /**< 16x1 LCD panel (actually 8x2) */
wim 8:03116f75b66e 149 LCD16x2, /**< 16x2 LCD panel (default) */
wim 8:03116f75b66e 150 LCD16x2B, /**< 16x2 LCD panel alternate addressing */
wim 8:03116f75b66e 151 LCD16x4, /**< 16x4 LCD panel */
wim 8:03116f75b66e 152 LCD20x2, /**< 20x2 LCD panel */
wim 8:03116f75b66e 153 LCD20x4, /**< 20x4 LCD panel */
wim 9:0893d986e717 154 LCD24x2, /**< 24x2 LCD panel */
wim 10:dd9b3a696acd 155 LCD24x4, /**< 24x4 LCD panel, special mode KS0078 */
wim 15:b70ebfffb258 156 LCD40x2, /**< 40x2 LCD panel */
wim 15:b70ebfffb258 157 LCD40x4 /**< 40x4 LCD panel, Two controller version */
simon 1:ac48b187213c 158 };
simon 1:ac48b187213c 159
wim 10:dd9b3a696acd 160 /** LCD Cursor control */
wim 10:dd9b3a696acd 161 enum LCDCursor {
wim 17:652ab113bc2e 162 CurOff_BlkOff = 0x00, /**< Cursor Off, Blinking Char Off */
wim 17:652ab113bc2e 163 CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */
wim 17:652ab113bc2e 164 CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */
wim 17:652ab113bc2e 165 CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */
wim 17:652ab113bc2e 166 };
wim 17:652ab113bc2e 167
wim 17:652ab113bc2e 168
wim 17:652ab113bc2e 169 /** LCD Display control */
wim 17:652ab113bc2e 170 enum LCDMode {
wim 17:652ab113bc2e 171 DispOff = 0x00, /**< Display Off */
wim 17:652ab113bc2e 172 DispOn = 0x04 /**< Display On */
wim 10:dd9b3a696acd 173 };
wim 10:dd9b3a696acd 174
wim 10:dd9b3a696acd 175
wim 15:b70ebfffb258 176 /** Create a TextLCD interface for using regular mbed pins
simon 2:227356c7d12c 177 *
simon 2:227356c7d12c 178 * @param rs Instruction/data control line
simon 2:227356c7d12c 179 * @param e Enable line (clock)
simon 7:44f34c09bd37 180 * @param d4-d7 Data lines for using as a 4-bit interface
simon 2:227356c7d12c 181 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 15:b70ebfffb258 182 * @param e2 Enable2 line (clock for second controller, LCD40x4 only)
simon 2:227356c7d12c 183 */
wim 15:b70ebfffb258 184 TextLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2, PinName e2 = NC);
wim 13:24506ba22480 185
wim 13:24506ba22480 186 /** Create a TextLCD interface using an I2C PC8574 portexpander
wim 13:24506ba22480 187 *
wim 13:24506ba22480 188 * @param i2c I2C Bus
wim 13:24506ba22480 189 * @param deviceAddress I2C slave address (PCF8574)
wim 13:24506ba22480 190 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 13:24506ba22480 191 */
wim 13:24506ba22480 192 TextLCD(I2C *i2c, char deviceAddress, LCDType type = LCD16x2);
wim 13:24506ba22480 193
wim 13:24506ba22480 194
wim 13:24506ba22480 195 /** Create a TextLCD interface using an SPI 74595 portexpander
wim 13:24506ba22480 196 *
wim 13:24506ba22480 197 * @param spi SPI Bus
wim 13:24506ba22480 198 * @param cs chip select pin (active low)
wim 13:24506ba22480 199 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 13:24506ba22480 200 */
wim 14:0c32b66b14b8 201 TextLCD(SPI *spi, PinName cs, LCDType type = LCD16x2);
wim 13:24506ba22480 202
simon 2:227356c7d12c 203
simon 2:227356c7d12c 204 #if DOXYGEN_ONLY
simon 2:227356c7d12c 205 /** Write a character to the LCD
simon 2:227356c7d12c 206 *
simon 2:227356c7d12c 207 * @param c The character to write to the display
simon 2:227356c7d12c 208 */
simon 2:227356c7d12c 209 int putc(int c);
simon 2:227356c7d12c 210
simon 2:227356c7d12c 211 /** Write a formated string to the LCD
simon 2:227356c7d12c 212 *
simon 2:227356c7d12c 213 * @param format A printf-style format string, followed by the
simon 2:227356c7d12c 214 * variables to use in formating the string.
simon 2:227356c7d12c 215 */
simon 2:227356c7d12c 216 int printf(const char* format, ...);
simon 2:227356c7d12c 217 #endif
simon 2:227356c7d12c 218
simon 2:227356c7d12c 219 /** Locate to a screen column and row
simon 2:227356c7d12c 220 *
simon 2:227356c7d12c 221 * @param column The horizontal position from the left, indexed from 0
simon 2:227356c7d12c 222 * @param row The vertical position from the top, indexed from 0
simon 2:227356c7d12c 223 */
simon 1:ac48b187213c 224 void locate(int column, int row);
simon 2:227356c7d12c 225
wim 10:dd9b3a696acd 226
wim 10:dd9b3a696acd 227 /** Return the memoryaddress of screen column and row location
wim 10:dd9b3a696acd 228 *
wim 10:dd9b3a696acd 229 * @param column The horizontal position from the left, indexed from 0
wim 10:dd9b3a696acd 230 * @param row The vertical position from the top, indexed from 0
wim 10:dd9b3a696acd 231 * @param return The memoryaddress of screen column and row location
wim 10:dd9b3a696acd 232 */
wim 9:0893d986e717 233 int getAddress(int column, int row);
wim 10:dd9b3a696acd 234
wim 10:dd9b3a696acd 235
wim 10:dd9b3a696acd 236 /** Set the memoryaddress of screen column and row location
wim 10:dd9b3a696acd 237 *
wim 10:dd9b3a696acd 238 * @param column The horizontal position from the left, indexed from 0
wim 10:dd9b3a696acd 239 * @param row The vertical position from the top, indexed from 0
wim 10:dd9b3a696acd 240 */
wim 9:0893d986e717 241 void setAddress(int column, int row);
wim 9:0893d986e717 242
wim 10:dd9b3a696acd 243
simon 2:227356c7d12c 244 /** Clear the screen and locate to 0,0 */
simon 1:ac48b187213c 245 void cls();
simon 2:227356c7d12c 246
wim 10:dd9b3a696acd 247 /** Return the number of rows
wim 10:dd9b3a696acd 248 *
wim 10:dd9b3a696acd 249 * @param return The number of rows
wim 10:dd9b3a696acd 250 */
simon 1:ac48b187213c 251 int rows();
wim 10:dd9b3a696acd 252
wim 10:dd9b3a696acd 253 /** Return the number of columns
wim 10:dd9b3a696acd 254 *
wim 10:dd9b3a696acd 255 * @param return The number of columns
wim 10:dd9b3a696acd 256 */
wim 10:dd9b3a696acd 257 int columns();
simon 2:227356c7d12c 258
wim 11:9ec02df863a1 259 /** Set the Cursormode
wim 11:9ec02df863a1 260 *
wim 17:652ab113bc2e 261 * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn)
wim 11:9ec02df863a1 262 */
wim 17:652ab113bc2e 263 void setCursor(LCDCursor cursorMode);
wim 17:652ab113bc2e 264
wim 17:652ab113bc2e 265
wim 17:652ab113bc2e 266 /** Set the Displaymode
wim 17:652ab113bc2e 267 *
wim 17:652ab113bc2e 268 * @param displayMode The Display mode (DispOff, DispOn)
wim 17:652ab113bc2e 269 */
wim 17:652ab113bc2e 270 void setMode(TextLCD::LCDMode displayMode);
wim 11:9ec02df863a1 271
wim 11:9ec02df863a1 272
wim 11:9ec02df863a1 273 /** Set User Defined Characters
wim 11:9ec02df863a1 274 *
wim 11:9ec02df863a1 275 * @param unsigned char c The Index of the UDC (0..7)
wim 12:6bf9d9957d31 276 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits)
wim 11:9ec02df863a1 277 */
wim 11:9ec02df863a1 278 void setUDC(unsigned char c, char *udc_data);
wim 11:9ec02df863a1 279
simon 1:ac48b187213c 280 protected:
wim 14:0c32b66b14b8 281 /* LCD Bus control */
wim 13:24506ba22480 282 enum _LCDBus {
wim 14:0c32b66b14b8 283 _PinBus, /*< Regular mbed pins */
wim 14:0c32b66b14b8 284 _I2CBus, /*< I2C PCF8574 Portexpander */
wim 15:b70ebfffb258 285 _SPIBus /*< SPI 74595 Shiftregister */
wim 13:24506ba22480 286 };
wim 13:24506ba22480 287
wim 15:b70ebfffb258 288 /* LCD controller select, mainly used for LCD40x4 */
wim 15:b70ebfffb258 289 enum _LCDCtrl {
wim 15:b70ebfffb258 290 _LCDCtrl_0, /*< Primary */
wim 15:b70ebfffb258 291 _LCDCtrl_1, /*< Secondary */
wim 15:b70ebfffb258 292 };
wim 15:b70ebfffb258 293
simon 1:ac48b187213c 294 // Stream implementation functions
simon 1:ac48b187213c 295 virtual int _putc(int value);
simon 1:ac48b187213c 296 virtual int _getc();
simon 1:ac48b187213c 297
wim 15:b70ebfffb258 298 //Low level methods for LCD controller
wim 13:24506ba22480 299 void _init();
wim 15:b70ebfffb258 300 void _initCtrl();
wim 13:24506ba22480 301 int _address(int column, int row);
wim 15:b70ebfffb258 302 void _setCursor(TextLCD::LCDCursor show);
wim 17:652ab113bc2e 303 void _setUDC(unsigned char c, char *udc_data);
wim 17:652ab113bc2e 304 void _setCursorAndDisplayMode(TextLCD::LCDMode displayMode, TextLCD::LCDCursor cursorType);
wim 13:24506ba22480 305
wim 15:b70ebfffb258 306 //Low level write operations to LCD controller
wim 17:652ab113bc2e 307 void _writeNibble(int value);
wim 15:b70ebfffb258 308 void _writeByte(int value);
wim 15:b70ebfffb258 309 void _writeCommand(int command);
wim 15:b70ebfffb258 310 void _writeData(int data);
wim 15:b70ebfffb258 311
wim 13:24506ba22480 312 //Low level writes to LCD Bus (serial or parallel)
wim 13:24506ba22480 313 void _setEnable(bool value);
wim 13:24506ba22480 314 void _setRS(bool value);
wim 13:24506ba22480 315 void _setData(int value);
wim 14:0c32b66b14b8 316 void _setCS(bool value);
wim 14:0c32b66b14b8 317
wim 13:24506ba22480 318 //Low level writes to LCD serial bus only
wim 13:24506ba22480 319 void _writeBus();
wim 13:24506ba22480 320
wim 13:24506ba22480 321
wim 13:24506ba22480 322 // Regular mbed pins bus
wim 15:b70ebfffb258 323 DigitalOut _rs, _e, _e2;
simon 1:ac48b187213c 324 BusOut _d;
wim 13:24506ba22480 325
wim 13:24506ba22480 326 // I2C bus
wim 13:24506ba22480 327 I2C *_i2c;
wim 13:24506ba22480 328 unsigned char _slaveAddress;
wim 13:24506ba22480 329
wim 13:24506ba22480 330 // SPI bus
wim 14:0c32b66b14b8 331 SPI *_spi;
wim 14:0c32b66b14b8 332 DigitalOut _cs;
wim 13:24506ba22480 333
wim 13:24506ba22480 334 //Bus Interface type
wim 13:24506ba22480 335 _LCDBus _busType;
wim 13:24506ba22480 336
wim 15:b70ebfffb258 337 // Internal bus mirror value for serial bus only
wim 13:24506ba22480 338 char _lcd_bus;
wim 13:24506ba22480 339
wim 13:24506ba22480 340 //Display type
simon 1:ac48b187213c 341 LCDType _type;
simon 1:ac48b187213c 342
wim 17:652ab113bc2e 343 //Display type
wim 17:652ab113bc2e 344 LCDMode _currentMode;
wim 17:652ab113bc2e 345
wim 15:b70ebfffb258 346 //Controller select, mainly used for LCD40x4
wim 15:b70ebfffb258 347 _LCDCtrl _ctrl;
wim 15:b70ebfffb258 348
wim 13:24506ba22480 349 // Cursor
simon 1:ac48b187213c 350 int _column;
simon 1:ac48b187213c 351 int _row;
wim 15:b70ebfffb258 352 LCDCursor _currentCursor;
simon 1:ac48b187213c 353 };
simon 1:ac48b187213c 354
simon 1:ac48b187213c 355 #endif