LCDisplay with IIC (I2C)-bus and IC 8574
Fork of TextLCD by
Embed:
(wiki syntax)
Show/hide line numbers
TextLCD.h
00001 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780 00002 * Copyright (c) 2007-2010, sford, http://mbed.org 00003 * 2013, v01: WH, Added LCD types, fixed LCD address issues, added Cursor and UDCs 00004 * 2013, v02: WH, Added I2C and SPI bus interfaces 00005 * 2013, v03: WH, Added support for LCD40x4 which uses 2 controllers 00006 * 2013, v04: WH, Added support for Display On/Off, improved 4bit bootprocess 00007 * 2013, v05: WH, Added support for 8x2B, added some UDCs 00008 * 2013, v06: WH, Added support for devices that use internal DC/DC converters 00009 * 2013, v07: WH, Added support for backlight and include portdefinitions for LCD2004 Module from DFROBOT 00010 * 2014, v08: WH, Refactored in Base and Derived Classes to deal with mbed lib change regarding 'NC' defined DigitalOut pins 00011 * 2014, v09: WH/EO, Added Class for Native SPI controllers such as ST7032 00012 * 2014, v10: WH, Added Class for Native I2C controllers such as ST7032i, Added support for MCP23008 I2C portexpander, Added support for Adafruit module 00013 * 2014, v11: WH, Added support for native I2C controllers such as PCF21XX, Improved the _initCtrl() method to deal with differences between all supported controllers 00014 * 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) 00015 * 2014, v13: WH, Added support for controllers US2066/SSD1311 (OLED), added setUDCBlink method for supported devices (eg SSD1803), fixed issue in setPower() 00016 *@Todo Add AC780S/KS0066i 00017 * 00018 * Permission is hereby granted, free of charge, to any person obtaining a copy 00019 * of this software and associated documentation files (the "Software"), to deal 00020 * in the Software without restriction, including without limitation the rights 00021 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00022 * copies of the Software, and to permit persons to whom the Software is 00023 * furnished to do so, subject to the following conditions: 00024 * 00025 * The above copyright notice and this permission notice shall be included in 00026 * all copies or substantial portions of the Software. 00027 * 00028 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00029 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00030 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00031 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00032 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00033 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00034 * THE SOFTWARE. 00035 */ 00036 00037 #ifndef MBED_TEXTLCD_H 00038 #define MBED_TEXTLCD_H 00039 00040 #include "mbed.h" 00041 00042 /** A TextLCD interface for driving 4-bit HD44780-based LCDs 00043 * 00044 * Currently supports 8x1, 8x2, 12x3, 12x4, 16x1, 16x2, 16x3, 16x4, 20x2, 20x4, 24x1, 24x2, 24x4, 40x2 and 40x4 panels 00045 * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595). 00046 * Supports some controllers with native I2C or SP interface. Supports some controllers that provide internal DC/DC converters for VLCD or VLED. 00047 * 00048 * @code 00049 * #include "mbed.h" 00050 * #include "TextLCD.h" 00051 * 00052 * // I2C Communication 00053 * I2C i2c_lcd(p28,p27); // SDA, SCL 00054 * 00055 * // SPI Communication 00056 * SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK 00057 * 00058 * //TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=HD44780 00059 * //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, 74595 expander, CS pin, LCD Type 00060 * TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type 00061 * //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type 00062 * //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3 00063 * //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=ST7032_3V3 00064 * 00065 * int main() { 00066 * lcd.printf("Hello World!\n"); 00067 * } 00068 * @endcode 00069 */ 00070 00071 00072 //Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces 00073 //LCD and serial portexpanders should be wired accordingly 00074 // 00075 //Select Hardware module (one option only) 00076 #define DEFAULT 0 00077 #define ADAFRUIT 0 00078 #define DFROBOT 1 00079 00080 #if (DEFAULT==1) 00081 //Definitions for default (WH) mapping between serial port expander pins and LCD controller 00082 //This hardware supports the I2C bus expander (PCF8574/PCF8574A or MCP23008) and SPI bus expander (74595) interfaces 00083 //See https://mbed.org/cookbook/Text-LCD-Enhanced 00084 // 00085 //Note: LCD RW pin must be connected to GND 00086 // E2 is used for LCD40x4 (second controller) 00087 // BL may be used to control backlight 00088 #define D_LCD_PIN_D4 0 00089 #define D_LCD_PIN_D5 1 00090 #define D_LCD_PIN_D6 2 00091 #define D_LCD_PIN_D7 3 00092 #define D_LCD_PIN_RS 4 00093 #define D_LCD_PIN_E 5 00094 #define D_LCD_PIN_E2 6 00095 #define D_LCD_PIN_BL 7 00096 00097 #define D_LCD_PIN_RW D_LCD_PIN_E2 00098 00099 //Select I2C Portexpander type (one option only) 00100 #define PCF8574 1 00101 #define MCP23008 0 00102 #endif 00103 00104 #if (ADAFRUIT==1) 00105 //Definitions for Adafruit i2cspilcdbackpack mapping between serial port expander pins and LCD controller 00106 //This hardware supports both an I2C expander (MCP23008) and an SPI expander (74595) selectable by a jumper. 00107 //See http://www.ladyada.net/products/i2cspilcdbackpack 00108 // 00109 //Note: LCD RW pin must be kept LOW 00110 // E2 is not available on this hardware and so it does not support LCD40x4 (second controller) 00111 // BL is used to control backlight 00112 #define D_LCD_PIN_0 0 00113 #define D_LCD_PIN_RS 1 00114 #define D_LCD_PIN_E 2 00115 #define D_LCD_PIN_D4 3 00116 #define D_LCD_PIN_D5 4 00117 #define D_LCD_PIN_D6 5 00118 #define D_LCD_PIN_D7 6 00119 #define D_LCD_PIN_BL 7 00120 00121 #define D_LCD_PIN_E2 D_LCD_PIN_0 00122 00123 //Force I2C portexpander type 00124 #define PCF8574 0 00125 #define MCP23008 1 00126 #endif 00127 00128 #if (DFROBOT==1) 00129 //Definitions for DFROBOT LCD2004 Module mapping between serial port expander pins and LCD controller 00130 //This hardware uses PCF8574 and is different from earlier/different Arduino I2C LCD displays 00131 //See http://arduino-info.wikispaces.com/LCD-Blue-I2C 00132 // 00133 //Note: LCD RW pin must be kept LOW 00134 // E2 is not available on default Arduino hardware and so it does not support LCD40x4 (second controller) 00135 // BL is used to control backlight, reverse logic: Low turns on Backlight. This is handled in setBacklight() 00136 #define D_LCD_PIN_RS 0 00137 #define D_LCD_PIN_RW 1 00138 #define D_LCD_PIN_E 2 00139 #define D_LCD_PIN_BL 3 00140 #define D_LCD_PIN_D4 4 00141 #define D_LCD_PIN_D5 5 00142 #define D_LCD_PIN_D6 6 00143 #define D_LCD_PIN_D7 7 00144 00145 #define D_LCD_PIN_E2 D_LCD_PIN_RW 00146 00147 //Force I2C portexpander type 00148 #define PCF8574 1 00149 #define MCP23008 0 00150 #endif 00151 00152 //Bitpattern Defines for I2C PCF8574/PCF8574A, MCP23008 and SPI 74595 Bus expanders 00153 // 00154 #define D_LCD_D4 (1<<D_LCD_PIN_D4) 00155 #define D_LCD_D5 (1<<D_LCD_PIN_D5) 00156 #define D_LCD_D6 (1<<D_LCD_PIN_D6) 00157 #define D_LCD_D7 (1<<D_LCD_PIN_D7) 00158 #define D_LCD_RS (1<<D_LCD_PIN_RS) 00159 #define D_LCD_E (1<<D_LCD_PIN_E) 00160 #define D_LCD_E2 (1<<D_LCD_PIN_E2) 00161 #define D_LCD_BL (1<<D_LCD_PIN_BL) 00162 //#define D_LCD_RW (1<<D_LCD_PIN_RW) 00163 00164 #define D_LCD_BUS_MSK (D_LCD_D4 | D_LCD_D5 | D_LCD_D6 | D_LCD_D7) 00165 #define D_LCD_BUS_DEF 0x00 00166 00167 /* PCF8574/PCF8574A I2C portexpander slave address */ 00168 #define PCF8574_SA0 0x40 00169 #define PCF8574_SA1 0x42 00170 #define PCF8574_SA2 0x44 00171 #define PCF8574_SA3 0x46 00172 #define PCF8574_SA4 0x48 00173 #define PCF8574_SA5 0x4A 00174 #define PCF8574_SA6 0x4C 00175 #define PCF8574_SA7 0x4E 00176 00177 #define PCF8574A_SA0 0x70 00178 #define PCF8574A_SA1 0x72 00179 #define PCF8574A_SA2 0x74 00180 #define PCF8574A_SA3 0x76 00181 #define PCF8574A_SA4 0x78 00182 #define PCF8574A_SA5 0x7A 00183 #define PCF8574A_SA6 0x7C 00184 #define PCF8574A_SA7 0x7E 00185 00186 /* MCP23008 I2C portexpander slave address */ 00187 #define MCP23008_SA0 0x40 00188 #define MCP23008_SA1 0x42 00189 #define MCP23008_SA2 0x44 00190 #define MCP23008_SA3 0x46 00191 #define MCP23008_SA4 0x48 00192 #define MCP23008_SA5 0x4A 00193 #define MCP23008_SA6 0x4C 00194 #define MCP23008_SA7 0x4E 00195 00196 /* MCP23008 I2C portexpander internal registers */ 00197 #define IODIR 0x00 00198 #define IPOL 0x01 00199 #define GPINTEN 0x02 00200 #define DEFVAL 0x03 00201 #define INTCON 0x04 00202 #define IOCON 0x05 00203 #define GPPU 0x06 00204 #define INTF 0x07 00205 #define INTCAP 0x08 00206 #define GPIO 0x09 00207 #define OLAT 0x0A 00208 00209 00210 /* ST7032i I2C slave address */ 00211 #define ST7032_SA 0x7C 00212 00213 /* ST7036i I2C slave address */ 00214 #define ST7036_SA0 0x78 00215 #define ST7036_SA1 0x7A 00216 #define ST7036_SA2 0x7C 00217 #define ST7036_SA3 0x7E 00218 00219 /* PCF21XX I2C slave address */ 00220 #define PCF21XX_SA0 0x74 00221 #define PCF21XX_SA1 0x76 00222 00223 /* AIP31068 I2C slave address */ 00224 #define AIP31068_SA 0x7C 00225 00226 /* SSD1803 I2C slave address */ 00227 #define SSD1803_SA0 0x78 00228 #define SSD1803_SA1 0x7A 00229 00230 /* US2066/SSD1311 I2C slave address */ 00231 #define US2066_SA0 0x78 00232 #define US2066_SA1 0x7A 00233 00234 /* AC780 I2C slave address */ 00235 #define AC780_SA0 0x78 00236 #define AC780_SA1 0x7A 00237 #define AC780_SA2 0x7C 00238 #define AC780_SA3 0x7E 00239 00240 //Some native I2C controllers dont support ACK. Set define to '0' to allow code to proceed even without ACK 00241 //#define LCD_I2C_ACK 0 00242 #define LCD_I2C_ACK 1 00243 00244 /* LCD Type information on Rows, Columns and Variant. This information is encoded in 00245 * an int and used for the LCDType enumerators in order to simplify code maintenance */ 00246 // Columns encoded in b7..b0 00247 #define LCD_T_COL_MSK 0x000000FF 00248 #define LCD_T_C6 0x00000006 00249 #define LCD_T_C8 0x00000008 00250 #define LCD_T_C10 0x0000000A 00251 #define LCD_T_C12 0x0000000C 00252 #define LCD_T_C16 0x00000010 00253 #define LCD_T_C20 0x00000014 00254 #define LCD_T_C24 0x00000018 00255 #define LCD_T_C32 0x00000020 00256 #define LCD_T_C40 0x00000028 00257 00258 // Rows encoded in b15..b8 00259 #define LCD_T_ROW_MSK 0x0000FF00 00260 #define LCD_T_R1 0x00000100 00261 #define LCD_T_R2 0x00000200 00262 #define LCD_T_R3 0x00000300 00263 #define LCD_T_R4 0x00000400 00264 00265 // Addressing mode encoded in b19..b16 00266 #define LCD_T_ADR_MSK 0x000F0000 00267 #define LCD_T_A 0x00000000 /*Mode A Default 1, 2 or 4 line display */ 00268 #define LCD_T_B 0x00010000 /*Mode B, Alternate 8x2 (actually 16x1 display) */ 00269 #define LCD_T_C 0x00020000 /*Mode C, Alternate 16x1 (actually 8x2 display) */ 00270 #define LCD_T_D 0x00030000 /*Mode D, Alternate 3 or 4 line display (12x4, 20x4, 24x4) */ 00271 #define LCD_T_D1 0x00040000 /*Mode D1, Alternate 3 out of 4 line display (12x3, 20x3, 24x3) */ 00272 #define LCD_T_E 0x00050000 /*Mode E, 40x4 display (actually two 40x2) */ 00273 #define LCD_T_F 0x00060000 /*Mode F, 16x3 display (actually 24x2) */ 00274 #define LCD_T_G 0x00070000 /*Mode G, 16x3 display */ 00275 00276 /* LCD Ctrl information on interface support and features. This information is encoded in 00277 * an int and used for the LCDCtrl enumerators in order to simplify code maintenance */ 00278 // Interface encoded in b31..b24 00279 #define LCD_C_BUS_MSK 0xFF000000 00280 #define LCD_C_PAR 0x01000000 /*Parallel 4 or 8 bit data, E pin, RS pin, RW=GND */ 00281 #define LCD_C_SPI3_9 0x02000000 /*SPI 3 line (MOSI, SCL, CS pins), 9 bits (RS + 8 Data) */ 00282 #define LCD_C_SPI3_10 0x04000000 /*SPI 3 line (MOSI, SCL, CS pins), 10 bits (RS, RW + 8 Data) */ 00283 #define LCD_C_SPI3_16 0x08000000 /*SPI 3 line (MOSI, SCL, CS pins), 16 bits (RS, RW + 8 Data) */ 00284 #define LCD_C_SPI3_24 0x10000000 /*SPI 3 line (MOSI, SCL, CS pins), 24 bits (RS, RW + 8 Data) */ 00285 #define LCD_C_SPI4 0x20000000 /*SPI 4 line (MOSI, SCL, CS, RS pin), RS pin + 8 Data */ 00286 #define LCD_C_I2C 0x40000000 /*I2C (SDA, SCL pin), 8 control bits (Co, RS, RW) + 8 Data */ 00287 // Features encoded in b23..b16 00288 #define LCD_C_FTR_MSK 0x00FF0000 00289 #define LCD_C_BST 0x00010000 /*Booster */ 00290 #define LCD_C_CTR 0x00020000 /*Contrast Control */ 00291 #define LCD_C_ICN 0x00040000 /*Icons */ 00292 #define LCD_C_PDN 0x00080000 /*Power Down */ 00293 00294 00295 // Contrast setting, 6 significant bits (only supported for controllers with extended features) 00296 // Voltage Multiplier setting, 2 or 3 significant bits (only supported for controllers with extended features) 00297 #define LCD_DEF_CONTRAST 0x20 00298 00299 //ST7032 EastRising ERC1602FS-4 display 00300 //Contrast setting 6 significant bits 00301 //Voltage Multiplier setting 3 significant bits 00302 #define LCD_ST7032_CONTRAST 0x18 00303 #define LCD_ST7032_RAB 0x04 00304 00305 //ST7036 EA DOGM1603 display 00306 //Contrast setting 6 significant bits 00307 //Voltage Multiplier setting 3 significant bits 00308 #define LCD_ST7036_CONTRAST 0x28 00309 #define LCD_ST7036_RAB 0x04 00310 00311 //SSD1803 EA DOGM204 display 00312 //Contrast setting 6 significant bits 00313 //Voltage Multiplier setting 3 significant bits 00314 #define LCD_SSD1_CONTRAST 0x28 00315 #define LCD_SSD1_RAB 0x06 00316 00317 //US2066/SSD1311 EastRising ER-OLEDM2002-4 display 00318 //Contrast setting 8 significant bits, use 6 for compatibility 00319 #define LCD_US20_CONTRAST 0x3F 00320 //#define LCD_US20_CONTRAST 0x1F 00321 00322 //PCF2113, PCF2119 display 00323 //Contrast setting 6 significant bits 00324 //Voltage Multiplier setting 2 significant bits 00325 #define LCD_PCF2_CONTRAST 0x20 00326 #define LCD_PCF2_S12 0x02 00327 00328 //PT6314 VFD display 00329 //Contrast setting 2 significant bits 00330 #define LCD_PT63_CONTRAST 0x00 00331 00332 /** Some sample User Defined Chars 5x7 dots */ 00333 //extern const char udc_ae[]; //æ 00334 //extern const char udc_0e[]; //ø 00335 //extern const char udc_ao[]; //å 00336 //extern const char udc_AE[]; //Æ 00337 //extern const char udc_0E[]; //Ø 00338 //extern const char udc_Ao[]; //Å 00339 //extern const char udc_PO[]; //Padlock Open 00340 //extern const char udc_PC[]; //Padlock Closed 00341 00342 //extern const char udc_alpha[]; //alpha 00343 //extern const char udc_ohm[]; //ohm 00344 //extern const char udc_sigma[]; //sigma 00345 //extern const char udc_pi[]; //pi 00346 //extern const char udc_root[]; //root 00347 00348 00349 extern const char udc_0[]; // |> 00350 extern const char udc_1[]; // <| 00351 extern const char udc_2[]; // | 00352 extern const char udc_3[]; // || 00353 extern const char udc_4[]; // ||| 00354 extern const char udc_5[]; // = 00355 extern const char udc_6[]; // checkerboard 00356 extern const char udc_7[]; // \ 00357 00358 extern const char udc_degr[]; // Degree symbol 00359 00360 extern const char udc_TM_T[]; // Trademark T 00361 extern const char udc_TM_M[]; // Trademark M 00362 00363 //extern const char udc_Bat_Hi[]; // Battery Full 00364 //extern const char udc_Bat_Ha[]; // Battery Half 00365 //extern const char udc_Bat_Lo[]; // Battery Low 00366 extern const char udc_Bat_Hi[]; // Battery Full 00367 extern const char udc_Bat_Ha[]; // Battery Half 00368 extern const char udc_Bat_Lo[]; // Battery Low 00369 extern const char udc_AC[]; // AC Power 00370 00371 //extern const char udc_smiley[]; // Smiley 00372 //extern const char udc_droopy[]; // Droopey 00373 //extern const char udc_note[]; // Note 00374 00375 //extern const char udc_bar_1[]; // Bar 1 00376 //extern const char udc_bar_2[]; // Bar 11 00377 //extern const char udc_bar_3[]; // Bar 111 00378 //extern const char udc_bar_4[]; // Bar 1111 00379 //extern const char udc_bar_5[]; // Bar 11111 00380 00381 //extern const char udc_ch_1[]; // Hor bars 4 00382 //extern const char udc_ch_2[]; // Hor bars 4 (inverted) 00383 //extern const char udc_ch_3[]; // Ver bars 3 00384 //extern const char udc_ch_4[]; // Ver bars 3 (inverted) 00385 //extern const char udc_ch_yr[]; // Year (kana) 00386 //extern const char udc_ch_mo[]; // Month (kana) 00387 //extern const char udc_ch_dy[]; // Day (kana) 00388 //extern const char udc_ch_mi[]; // minute (kana) 00389 extern const char udc_None[]; 00390 extern const char udc_All[]; 00391 00392 /** A TextLCD interface for driving 4-bit HD44780-based LCDs 00393 * 00394 * @brief Currently supports 8x1, 8x2, 12x2, 12x3, 12x4, 16x1, 16x2, 16x3, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels 00395 * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595) and some native I2C or SPI devices 00396 * 00397 */ 00398 class TextLCD_Base : public Stream { 00399 public: 00400 00401 /** LCD panel format */ 00402 // The commented out types exist but have not yet been tested with the library 00403 enum LCDType { 00404 // LCD6x1 = (LCD_T_A | LCD_T_C6 | LCD_T_R1), /**< 6x1 LCD panel */ 00405 // LCD6x2 = (LCD_T_A | LCD_T_C6 | LCD_T_R2), /**< 6x2 LCD panel */ 00406 LCD8x1 = (LCD_T_A | LCD_T_C8 | LCD_T_R1), /**< 8x1 LCD panel */ 00407 LCD8x2 = (LCD_T_A | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel */ 00408 LCD8x2B = (LCD_T_D | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel (actually 16x1) */ 00409 // LCD12x1 = (LCD_T_A | LCD_T_C12 | LCD_T_R1), /**< 12x1 LCD panel */ 00410 LCD12x2 = (LCD_T_A | LCD_T_C12 | LCD_T_R2), /**< 12x2 LCD panel */ 00411 LCD12x3D = (LCD_T_D | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX */ 00412 LCD12x3D1 = (LCD_T_D1 | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX */ 00413 // LCD12x3G = (LCD_T_G | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode ST7036 */ 00414 LCD12x4 = (LCD_T_A | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel */ 00415 LCD12x4D = (LCD_T_B | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel, special mode PCF21XX */ 00416 LCD16x1 = (LCD_T_A | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel */ 00417 LCD16x1C = (LCD_T_C | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel (actually 8x2) */ 00418 LCD16x2 = (LCD_T_A | LCD_T_C16 | LCD_T_R2), /**< 16x2 LCD panel (default) */ 00419 // LCD16x2B = (LCD_T_B | LCD_T_C16 | LCD_T_R2), /**< 16x2 LCD panel, alternate addressing, wrong.. */ 00420 LCD16x3D = (LCD_T_D | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */ 00421 // LCD16x3D1 = (LCD_T_D1 | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */ 00422 LCD16x3F = (LCD_T_F | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel (actually 24x2) */ 00423 LCD16x3G = (LCD_T_G | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode ST7036 */ 00424 LCD16x4 = (LCD_T_A | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel */ 00425 // LCD16x4D = (LCD_T_D | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel, special mode SSD1803 */ 00426 // LCD20x1 = (LCD_T_A | LCD_T_C20 | LCD_T_R1), /**< 20x1 LCD panel */ 00427 LCD20x2 = (LCD_T_A | LCD_T_C20 | LCD_T_R2), /**< 20x2 LCD panel */ 00428 // LCD20x3 = (LCD_T_A | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel */ 00429 // LCD20x3D = (LCD_T_D | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803 */ 00430 // LCD20x3D1 = (LCD_T_D1 | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803 */ 00431 LCD20x4 = (LCD_T_A | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel */ 00432 LCD20x4D = (LCD_T_D | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel, special mode SSD1803 */ 00433 LCD24x1 = (LCD_T_A | LCD_T_C24 | LCD_T_R1), /**< 24x1 LCD panel */ 00434 LCD24x2 = (LCD_T_A | LCD_T_C24 | LCD_T_R2), /**< 24x2 LCD panel */ 00435 // LCD24x3D = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */ 00436 // LCD24x3D1 = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */ 00437 LCD24x4D = (LCD_T_D | LCD_T_C24 | LCD_T_R4), /**< 24x4 LCD panel, special mode KS0078 */ 00438 // LCD32x1 = (LCD_T_A | LCD_T_C32 | LCD_T_R1), /**< 32x1 LCD panel */ 00439 // LCD32x1C = (LCD_T_C | LCD_T_C32 | LCD_T_R1), /**< 32x1 LCD panel (actually 16x2) */ 00440 // LCD32x2 = (LCD_T_A | LCD_T_C32 | LCD_T_R2), /**< 32x2 LCD panel */ 00441 // LCD32x4 = (LCD_T_A | LCD_T_C32 | LCD_T_R4), /**< 32x4 LCD panel */ 00442 // LCD40x1 = (LCD_T_A | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel */ 00443 // LCD40x1C = (LCD_T_C | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel (actually 20x2) */ 00444 LCD40x2 = (LCD_T_A | LCD_T_C40 | LCD_T_R2), /**< 40x2 LCD panel */ 00445 LCD40x4 = (LCD_T_E | LCD_T_C40 | LCD_T_R4) /**< 40x4 LCD panel, Two controller version */ 00446 }; 00447 00448 00449 /** LCD Controller Device */ 00450 enum LCDCtrl { 00451 HD44780 = 0 | LCD_C_PAR, /**< HD44780 or full equivalent (default) */ 00452 WS0010 = 1 | (LCD_C_PAR | LCD_C_SPI3_10 | LCD_C_BST), /**< WS0010 OLED Controller, 4/8 bit, SPI3 */ 00453 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 */ 00454 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 */ 00455 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 */ 00456 ST7032_5V = 5 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_CTR), /**< ST7032 5V no Booster, 4/8 bit, SPI4, I2C */ 00457 KS0078 = 6 | (LCD_C_PAR | LCD_C_SPI3_24), /**< KS0078 24x4 support, 4/8 bit, SPI3 */ 00458 PCF2113_3V3 = 7 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2113 3V3 with Booster, 4/8 bit, I2C */ 00459 PCF2116_3V3 = 8 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST), /**< PCF2116 3V3 with Booster, 4/8 bit, I2C */ 00460 PCF2116_5V = 9 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2116 5V no Booster, 4/8 bit, I2C */ 00461 PCF2119_3V3 = 10 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2119 3V3 with Booster, 4/8 bit, I2C */ 00462 // PCF2119_5V = 11 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2119 5V no Booster, 4/8 bit, I2C */ 00463 AIP31068 = 12 | (LCD_C_SPI3_9 | LCD_C_I2C | LCD_C_BST), /**< AIP31068 I2C, SPI3 */ 00464 SSD1803_3V3 = 13 | (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 */ 00465 // SSD1803_5V = 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 */ 00466 US2066_3V3 = 15 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_CTR | LCD_C_PDN), /**< US2066/SSD1311 3V3, 4/8 bit, I2C, SPI3 */ 00467 // PT6314 = 16 | (LCD_C_PAR | LCD_C_SPI3_16 | LCD_C_CTR | LCD_C_PDN), /**< PT6314 VFD, 4/8 bit, SPI3 */ 00468 // AC780 = 17 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_PDN), /**< AC780 4/8 bit, SPI, I2C */ 00469 // KS0066 = 18 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_PDN) /**< KS0066i == AC780 4/8 bit, SPI, I2C */ 00470 }; 00471 00472 00473 /** LCD Cursor control */ 00474 enum LCDCursor { 00475 CurOff_BlkOff = 0x00, /**< Cursor Off, Blinking Char Off */ 00476 CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */ 00477 CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */ 00478 CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */ 00479 }; 00480 00481 /** LCD Display control */ 00482 enum LCDMode { 00483 DispOff = 0x00, /**< Display Off */ 00484 DispOn = 0x04 /**< Display On */ 00485 }; 00486 00487 /** LCD Backlight control */ 00488 enum LCDBacklight { 00489 LightOff, /**< Backlight Off */ 00490 LightOn /**< Backlight On */ 00491 }; 00492 00493 /** LCD Blink control (UDC), supported for some Controllers */ 00494 enum LCDBlink { 00495 BlinkOff, /**< Blink Off */ 00496 BlinkOn /**< Blink On */ 00497 }; 00498 00499 /** LCD Orientation control, supported for some Controllers */ 00500 enum LCDOrient { 00501 Top, /**< Top view */ 00502 Bottom /**< Upside down view */ 00503 }; 00504 00505 00506 #if DOXYGEN_ONLY 00507 /** Write a character to the LCD 00508 * 00509 * @param c The character to write to the display 00510 */ 00511 int putc(int c); 00512 00513 /** Write a formated string to the LCD 00514 * 00515 * @param format A printf-style format string, followed by the 00516 * variables to use in formating the string. 00517 */ 00518 int printf(const char* format, ...); 00519 #endif 00520 00521 /** Locate cursor to a screen column and row 00522 * 00523 * @param column The horizontal position from the left, indexed from 0 00524 * @param row The vertical position from the top, indexed from 0 00525 */ 00526 void locate(int column, int row); 00527 00528 /** Return the memoryaddress of screen column and row location 00529 * 00530 * @param column The horizontal position from the left, indexed from 0 00531 * @param row The vertical position from the top, indexed from 0 00532 * @param return The memoryaddress of screen column and row location 00533 */ 00534 int getAddress(int column, int row); 00535 00536 /** Set the memoryaddress of screen column and row location 00537 * 00538 * @param column The horizontal position from the left, indexed from 0 00539 * @param row The vertical position from the top, indexed from 0 00540 */ 00541 void setAddress(int column, int row); 00542 00543 /** Clear the screen and locate to 0,0 00544 */ 00545 void cls(); 00546 00547 /** Return the number of rows 00548 * 00549 * @param return The number of rows 00550 */ 00551 int rows(); 00552 00553 /** Return the number of columns 00554 * 00555 * @param return The number of columns 00556 */ 00557 int columns(); 00558 00559 /** Set the Cursormode 00560 * 00561 * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn) 00562 */ 00563 void setCursor(LCDCursor cursorMode); 00564 00565 /** Set the Displaymode 00566 * 00567 * @param displayMode The Display mode (DispOff, DispOn) 00568 */ 00569 void setMode(LCDMode displayMode); 00570 00571 /** Set the Backlight mode 00572 * 00573 * @param backlightMode The Backlight mode (LightOff, LightOn) 00574 */ 00575 void setBacklight(LCDBacklight backlightMode); 00576 00577 /** Set User Defined Characters (UDC) 00578 * 00579 * @param unsigned char c The Index of the UDC (0..7) 00580 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits) 00581 */ 00582 void setUDC(unsigned char c, char *udc_data); 00583 00584 /** Set UDC Blink 00585 * setUDCBlink method is supported by some compatible devices (eg SSD1803) 00586 * 00587 * @param blinkMode The Blink mode (BlinkOff, BlinkOn) 00588 */ 00589 void setUDCBlink(LCDBlink blinkMode); 00590 00591 /** Set Contrast 00592 * setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation 00593 * Code imported from fork by JH1PJL 00594 * 00595 * @param unsigned char c contrast data (6 significant bits, valid range 0..63, Value 0 will disable the Vgen) 00596 * @return none 00597 */ 00598 void setContrast(unsigned char c = LCD_DEF_CONTRAST); 00599 00600 /** Set Power 00601 * setPower method is supported by some compatible devices (eg SSD1803) that have power down modes 00602 * 00603 * @param bool powerOn Power on/off 00604 * @return none 00605 */ 00606 void setPower(bool powerOn = true); 00607 00608 /** Set Orient 00609 * setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes 00610 * 00611 * @param LCDOrient orient Orientation 00612 * @return none 00613 */ 00614 void setOrient(LCDOrient orient = Top); 00615 00616 00617 //test 00618 // void _initCtrl(); 00619 00620 protected: 00621 00622 /** LCD controller select, mainly used for LCD40x4 00623 */ 00624 enum _LCDCtrl_Idx { 00625 _LCDCtrl_0, /*< Primary */ 00626 _LCDCtrl_1, /*< Secondary */ 00627 }; 00628 00629 /** Create a TextLCD_Base interface 00630 * @brief Base class, can not be instantiated 00631 * 00632 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00633 * @param ctrl LCD controller (default = HD44780) 00634 */ 00635 TextLCD_Base(LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); 00636 00637 // Stream implementation functions 00638 virtual int _putc(int value); 00639 virtual int _getc(); 00640 00641 /** Low level method for LCD controller 00642 */ 00643 void _init(); 00644 00645 /** Low level initialisation method for LCD controller 00646 */ 00647 void _initCtrl(); 00648 00649 /** Low level character address set method 00650 */ 00651 int _address(int column, int row); 00652 00653 /** Low level cursor enable or disable method 00654 */ 00655 void _setCursor(LCDCursor show); 00656 00657 /** Low level method to store user defined characters for current controller 00658 */ 00659 void _setUDC(unsigned char c, char *udc_data); 00660 00661 /** Low level method to restore the cursortype and display mode for current controller 00662 */ 00663 void _setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType); 00664 00665 /** Low level nibble write operation to LCD controller (serial or parallel) 00666 */ 00667 void _writeNibble(int value); 00668 00669 /** Low level command byte write operation to LCD controller. 00670 * Methods resets the RS bit and provides the required timing for the command. 00671 */ 00672 void _writeCommand(int command); 00673 00674 /** Low level data byte write operation to LCD controller (serial or parallel). 00675 * Methods sets the RS bit and provides the required timing for the data. 00676 */ 00677 void _writeData(int data); 00678 00679 /** Pure Virtual Low level writes to LCD Bus (serial or parallel) 00680 * Set the Enable pin. 00681 */ 00682 virtual void _setEnable(bool value) = 0; 00683 00684 /** Pure Virtual Low level writes to LCD Bus (serial or parallel) 00685 * Set the RS pin ( 0 = Command, 1 = Data). 00686 */ 00687 virtual void _setRS(bool value) = 0; 00688 00689 /** Pure Virtual Low level writes to LCD Bus (serial or parallel) 00690 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00691 */ 00692 virtual void _setBL(bool value) = 0; 00693 00694 /** Pure Virtual Low level writes to LCD Bus (serial or parallel) 00695 * Set the databus value (4 bit). 00696 */ 00697 virtual void _setData(int value) = 0; 00698 00699 /** Low level byte write operation to LCD controller (serial or parallel) 00700 * Depending on the RS pin this byte will be interpreted as data or command 00701 */ 00702 virtual void _writeByte(int value); 00703 00704 //Display type 00705 LCDType _type; 00706 int _nr_cols; 00707 int _nr_rows; 00708 int _addr_mode; 00709 00710 //Display mode 00711 LCDMode _currentMode; 00712 00713 //Controller type 00714 LCDCtrl _ctrl; 00715 00716 //Controller select, mainly used for LCD40x4 00717 _LCDCtrl_Idx _ctrl_idx; 00718 00719 // Cursor 00720 int _column; 00721 int _row; 00722 LCDCursor _currentCursor; 00723 00724 // Function mode saved to allow switch between Instruction sets after initialisation time 00725 // Icon, Booster mode and contrast saved to allow contrast change at later time 00726 // Only available for controllers with added features 00727 int _function, _function_1, _function_x; 00728 int _icon_power; 00729 int _contrast; 00730 00731 }; 00732 00733 //--------- End TextLCD_Base ----------- 00734 00735 00736 00737 //--------- Start TextLCD Bus ----------- 00738 00739 /** Create a TextLCD interface for using regular mbed pins 00740 * 00741 */ 00742 class TextLCD : public TextLCD_Base { 00743 public: 00744 /** Create a TextLCD interface for using regular mbed pins 00745 * 00746 * @param rs Instruction/data control line 00747 * @param e Enable line (clock) 00748 * @param d4-d7 Data lines for using as a 4-bit interface 00749 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00750 * @param bl Backlight control line (optional, default = NC) 00751 * @param e2 Enable2 line (clock for second controller, LCD40x4 only) 00752 * @param ctrl LCD controller (default = HD44780) 00753 */ 00754 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); 00755 00756 /** Destruct a TextLCD interface for using regular mbed pins 00757 * 00758 * @param none 00759 * @return none 00760 */ 00761 virtual ~TextLCD(); 00762 00763 private: 00764 00765 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) 00766 * Set the Enable pin. 00767 */ 00768 virtual void _setEnable(bool value); 00769 00770 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) 00771 * Set the RS pin (0 = Command, 1 = Data). 00772 */ 00773 virtual void _setRS(bool value); 00774 00775 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) 00776 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00777 */ 00778 virtual void _setBL(bool value); 00779 00780 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) 00781 * Set the databus value (4 bit). 00782 */ 00783 virtual void _setData(int value); 00784 00785 00786 /** Regular mbed pins bus 00787 */ 00788 DigitalOut _rs, _e; 00789 BusOut _d; 00790 00791 /** Optional Hardware pins for the Backlight and LCD40x4 device 00792 * Default PinName value is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins 00793 */ 00794 DigitalOut *_bl, *_e2; 00795 }; 00796 00797 00798 //----------- End TextLCD --------------- 00799 00800 00801 //--------- Start TextLCD_I2C ----------- 00802 00803 00804 /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander 00805 * 00806 */ 00807 class TextLCD_I2C : public TextLCD_Base { 00808 public: 00809 /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander 00810 * 00811 * @param i2c I2C Bus 00812 * @param deviceAddress I2C slave address (PCF8574 or PCF8574A, default = PCF8574_SA0 = 0x40) 00813 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00814 * @param ctrl LCD controller (default = HD44780) 00815 */ 00816 TextLCD_I2C(I2C *i2c, char deviceAddress = PCF8574_SA0, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); 00817 00818 private: 00819 00820 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00821 * Set the Enable pin. 00822 */ 00823 virtual void _setEnable(bool value); 00824 00825 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00826 * Set the RS pin (0 = Command, 1 = Data). 00827 */ 00828 virtual void _setRS(bool value); 00829 00830 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00831 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00832 */ 00833 virtual void _setBL(bool value); 00834 00835 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00836 * Set the databus value (4 bit). 00837 */ 00838 virtual void _setData(int value); 00839 00840 /** Write data to MCP23008 I2C portexpander 00841 * @param reg register to write 00842 * @param value data to write 00843 * @return none 00844 * 00845 */ 00846 void _write_register (int reg, int value); 00847 00848 //I2C bus 00849 I2C *_i2c; 00850 char _slaveAddress; 00851 00852 // Internal bus mirror value for serial bus only 00853 char _lcd_bus; 00854 }; 00855 00856 //---------- End TextLCD_I2C ------------ 00857 00858 00859 //--------- Start TextLCD_SPI ----------- 00860 00861 /** Create a TextLCD interface using an SPI 74595 portexpander 00862 * 00863 */ 00864 class TextLCD_SPI : public TextLCD_Base { 00865 public: 00866 /** Create a TextLCD interface using an SPI 74595 portexpander 00867 * 00868 * @param spi SPI Bus 00869 * @param cs chip select pin (active low) 00870 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00871 * @param ctrl LCD controller (default = HD44780) 00872 */ 00873 TextLCD_SPI(SPI *spi, PinName cs, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); 00874 00875 private: 00876 00877 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00878 * Set the Enable pin. 00879 */ 00880 virtual void _setEnable(bool value); 00881 00882 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00883 * Set the RS pin (0 = Command, 1 = Data). 00884 */ 00885 virtual void _setRS(bool value); 00886 00887 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00888 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00889 */ 00890 virtual void _setBL(bool value); 00891 00892 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00893 * Set the databus value (4 bit). 00894 */ 00895 virtual void _setData(int value); 00896 00897 /** Implementation of Low level writes to LCD Bus (serial expander) 00898 * Set the CS pin (0 = select, 1 = deselect). 00899 */ 00900 virtual void _setCS(bool value); 00901 00902 ///** Low level writes to LCD serial bus only (serial expander) 00903 // */ 00904 // void _writeBus(); 00905 00906 // SPI bus 00907 SPI *_spi; 00908 DigitalOut _cs; 00909 00910 // Internal bus mirror value for serial bus only 00911 char _lcd_bus; 00912 }; 00913 00914 //---------- End TextLCD_SPI ------------ 00915 00916 00917 //--------- Start TextLCD_SPI_N ----------- 00918 00919 /** Create a TextLCD interface using a controller with native SPI4 interface 00920 * 00921 */ 00922 class TextLCD_SPI_N : public TextLCD_Base { 00923 public: 00924 /** Create a TextLCD interface using a controller with native SPI4 interface 00925 * 00926 * @param spi SPI Bus 00927 * @param cs chip select pin (active low) 00928 * @param rs Instruction/data control line 00929 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00930 * @param bl Backlight control line (optional, default = NC) 00931 * @param ctrl LCD controller (default = ST7032_3V3) 00932 */ 00933 TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3); 00934 virtual ~TextLCD_SPI_N(void); 00935 00936 private: 00937 00938 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00939 * Set the Enable pin. 00940 */ 00941 virtual void _setEnable(bool value); 00942 00943 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00944 * Set the RS pin (0 = Command, 1 = Data). 00945 */ 00946 virtual void _setRS(bool value); 00947 00948 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00949 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00950 */ 00951 virtual void _setBL(bool value); 00952 00953 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00954 * Set the databus value (4 bit). 00955 */ 00956 virtual void _setData(int value); 00957 00958 /** Low level writes to LCD serial bus only (serial native) 00959 */ 00960 virtual void _writeByte(int value); 00961 00962 // SPI bus 00963 SPI *_spi; 00964 DigitalOut _cs; 00965 DigitalOut _rs; 00966 00967 //Backlight 00968 DigitalOut *_bl; 00969 }; 00970 00971 //---------- End TextLCD_SPI_N ------------ 00972 00973 00974 #if(1) 00975 //Code checked out on logic analyser. Not yet tested on hardware.. 00976 00977 //------- Start TextLCD_SPI_N_3_9 --------- 00978 00979 /** Create a TextLCD interface using a controller with native SPI3 9 bits interface 00980 * Note: current mbed libs only support SPI 9 bit mode for NXP platforms 00981 * 00982 */ 00983 class TextLCD_SPI_N_3_9 : public TextLCD_Base { 00984 public: 00985 /** Create a TextLCD interface using a controller with native SPI3 9 bits interface 00986 * Note: current mbed libs only support SPI 9 bit mode for NXP platforms 00987 * 00988 * @param spi SPI Bus 00989 * @param cs chip select pin (active low) 00990 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00991 * @param bl Backlight control line (optional, default = NC) 00992 * @param ctrl LCD controller (default = AIP31068) 00993 */ 00994 TextLCD_SPI_N_3_9(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = AIP31068); 00995 virtual ~TextLCD_SPI_N_3_9(void); 00996 00997 private: 00998 00999 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01000 * Set the Enable pin. 01001 */ 01002 virtual void _setEnable(bool value); 01003 01004 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01005 * Set the RS pin (0 = Command, 1 = Data). 01006 */ 01007 virtual void _setRS(bool value); 01008 01009 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01010 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 01011 */ 01012 virtual void _setBL(bool value); 01013 01014 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01015 * Set the databus value (4 bit). 01016 */ 01017 virtual void _setData(int value); 01018 01019 /** Low level writes to LCD serial bus only (serial native) 01020 */ 01021 virtual void _writeByte(int value); 01022 01023 // SPI bus 01024 SPI *_spi; 01025 DigitalOut _cs; 01026 01027 01028 // controlbyte to select between data and command. Internal value for serial bus only 01029 char _controlbyte; 01030 01031 //Backlight 01032 DigitalOut *_bl; 01033 }; 01034 01035 //-------- End TextLCD_SPI_N_3_9 ---------- 01036 #endif 01037 01038 01039 #if(1) 01040 //------- Start TextLCD_SPI_N_3_10 --------- 01041 01042 /** Create a TextLCD interface using a controller with native SPI3 10 bits interface 01043 * Note: current mbed libs only support SPI 10 bit mode for NXP platforms 01044 * 01045 */ 01046 class TextLCD_SPI_N_3_10 : public TextLCD_Base { 01047 public: 01048 /** Create a TextLCD interface using a controller with native SPI3 10 bits interface 01049 * Note: current mbed libs only support SPI 10 bit mode for NXP platforms 01050 * 01051 * @param spi SPI Bus 01052 * @param cs chip select pin (active low) 01053 * @param type Sets the panel size/addressing mode (default = LCD16x2) 01054 * @param bl Backlight control line (optional, default = NC) 01055 * @param ctrl LCD controller (default = AIP31068) 01056 */ 01057 TextLCD_SPI_N_3_10(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = AIP31068); 01058 virtual ~TextLCD_SPI_N_3_10(void); 01059 01060 private: 01061 01062 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01063 * Set the Enable pin. 01064 */ 01065 virtual void _setEnable(bool value); 01066 01067 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01068 * Set the RS pin (0 = Command, 1 = Data). 01069 */ 01070 virtual void _setRS(bool value); 01071 01072 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01073 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 01074 */ 01075 virtual void _setBL(bool value); 01076 01077 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01078 * Set the databus value (4 bit). 01079 */ 01080 virtual void _setData(int value); 01081 01082 /** Low level writes to LCD serial bus only (serial native) 01083 */ 01084 virtual void _writeByte(int value); 01085 01086 // SPI bus 01087 SPI *_spi; 01088 DigitalOut _cs; 01089 01090 01091 // controlbyte to select between data and command. Internal value for serial bus only 01092 char _controlbyte; 01093 01094 //Backlight 01095 DigitalOut *_bl; 01096 }; 01097 01098 //-------- End TextLCD_SPI_N_3_10 ---------- 01099 #endif 01100 01101 #if(0) 01102 //Code not yet checked out on logic analyser. Not yet tested on hardware.. 01103 01104 //------- Start TextLCD_SPI_N_3_16 --------- 01105 01106 /** Create a TextLCD interface using a controller with native SPI3 16 bits interface 01107 * 01108 */ 01109 class TextLCD_SPI_N_3_16 : public TextLCD_Base { 01110 public: 01111 /** Create a TextLCD interface using a controller with native SPI3 16 bits interface 01112 * 01113 * @param spi SPI Bus 01114 * @param cs chip select pin (active low) 01115 * @param type Sets the panel size/addressing mode (default = LCD16x2) 01116 * @param bl Backlight control line (optional, default = NC) 01117 * @param ctrl LCD controller (default = PT6314) 01118 */ 01119 TextLCD_SPI_N_3_16(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = PT6314); 01120 virtual ~TextLCD_SPI_N_3_16(void); 01121 01122 private: 01123 01124 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01125 * Set the Enable pin. 01126 */ 01127 virtual void _setEnable(bool value); 01128 01129 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01130 * Set the RS pin (0 = Command, 1 = Data). 01131 */ 01132 virtual void _setRS(bool value); 01133 01134 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01135 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 01136 */ 01137 virtual void _setBL(bool value); 01138 01139 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01140 * Set the databus value (4 bit). 01141 */ 01142 virtual void _setData(int value); 01143 01144 /** Low level writes to LCD serial bus only (serial native) 01145 */ 01146 virtual void _writeByte(int value); 01147 01148 // SPI bus 01149 SPI *_spi; 01150 DigitalOut _cs; 01151 01152 // controlbyte to select between data and command. Internal value for serial bus only 01153 char _controlbyte; 01154 01155 //Backlight 01156 DigitalOut *_bl; 01157 }; 01158 01159 //-------- End TextLCD_SPI_N_3_16 ---------- 01160 #endif 01161 01162 #if(1) 01163 //------- Start TextLCD_SPI_N_3_24 --------- 01164 01165 /** Create a TextLCD interface using a controller with native SPI3 24 bits interface 01166 * Note: lib uses SPI 8 bit mode 01167 * 01168 */ 01169 class TextLCD_SPI_N_3_24 : public TextLCD_Base { 01170 public: 01171 /** Create a TextLCD interface using a controller with native SPI3 24 bits interface 01172 * Note: lib uses SPI 8 bit mode 01173 * 01174 * @param spi SPI Bus 01175 * @param cs chip select pin (active low) 01176 * @param type Sets the panel size/addressing mode (default = LCD16x2) 01177 * @param bl Backlight control line (optional, default = NC) 01178 * @param ctrl LCD controller (default = SSD1803) 01179 */ 01180 TextLCD_SPI_N_3_24(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = SSD1803_3V3); 01181 virtual ~TextLCD_SPI_N_3_24(void); 01182 01183 private: 01184 01185 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01186 * Set the Enable pin. 01187 */ 01188 virtual void _setEnable(bool value); 01189 01190 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01191 * Set the RS pin (0 = Command, 1 = Data). 01192 */ 01193 virtual void _setRS(bool value); 01194 01195 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01196 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 01197 */ 01198 virtual void _setBL(bool value); 01199 01200 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01201 * Set the databus value (4 bit). 01202 */ 01203 virtual void _setData(int value); 01204 01205 /** Low level writes to LCD serial bus only (serial native) 01206 */ 01207 virtual void _writeByte(int value); 01208 01209 // SPI bus 01210 SPI *_spi; 01211 DigitalOut _cs; 01212 01213 // controlbyte to select between data and command. Internal value for serial bus only 01214 char _controlbyte; 01215 01216 //Backlight 01217 DigitalOut *_bl; 01218 }; 01219 01220 //-------- End TextLCD_SPI_N_3_24 ---------- 01221 #endif 01222 01223 01224 //--------- Start TextLCD_I2C_N ----------- 01225 01226 /** Create a TextLCD interface using a controller with native I2C interface 01227 * 01228 */ 01229 class TextLCD_I2C_N : public TextLCD_Base { 01230 public: 01231 /** Create a TextLCD interface using a controller with native I2C interface 01232 * 01233 * @param i2c I2C Bus 01234 * @param deviceAddress I2C slave address (default = ST7032_SA = 0x7C) 01235 * @param type Sets the panel size/addressing mode (default = LCD16x2) 01236 * @param bl Backlight control line (optional, default = NC) 01237 * @param ctrl LCD controller (default = ST7032_3V3) 01238 */ 01239 TextLCD_I2C_N(I2C *i2c, char deviceAddress = ST7032_SA, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3); 01240 virtual ~TextLCD_I2C_N(void); 01241 01242 private: 01243 01244 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01245 * Set the Enable pin. 01246 */ 01247 virtual void _setEnable(bool value); 01248 01249 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01250 * Set the RS pin ( 0 = Command, 1 = Data). 01251 */ 01252 virtual void _setRS(bool value); 01253 01254 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01255 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 01256 */ 01257 virtual void _setBL(bool value); 01258 01259 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01260 * Set the databus value (4 bit). 01261 */ 01262 virtual void _setData(int value); 01263 01264 /** Low level writes to LCD serial bus only (serial native) 01265 */ 01266 virtual void _writeByte(int value); 01267 01268 //I2C bus 01269 I2C *_i2c; 01270 char _slaveAddress; 01271 01272 // controlbyte to select between data and command. Internal value for serial bus only 01273 char _controlbyte; 01274 01275 //Backlight 01276 DigitalOut *_bl; 01277 01278 }; 01279 01280 //---------- End TextLCD_I2C_N ------------ 01281 01282 01283 #endif
Generated on Wed Jul 13 2022 08:07:13 by 1.7.2