Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LPC1114_data_logger RTC_w_COM Frequency_Counter_w_GPS_1PPS CW_Decoder_using_FFT_on_F446 ... more
Fork of TextLCD by
TextLCD_UDC.h
00001 /* mbed TextLCD Library, for LCDs based on HD44780 controllers 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 * 2014, v14: WH, Added support for PT6314 (VFD), added setOrient() method for supported devices (eg SSD1803, US2066), added Double Height lines for supported devices, 00017 * added 16 UDCs for supported devices (eg PCF2103), moved UDC defines to TextLCD_UDC file, added TextLCD_Config.h for feature and footprint settings. 00018 * 2014, v15: WH, Added AC780 support, added I2C expander modules, fixed setBacklight() for inverted logic modules. Fixed bug in LCD_SPI_N define 00019 * 2014, v16: WH, Added ST7070 and KS0073 support, added setIcon(), clrIcon() and setInvert() method for supported devices 00020 * 2015, v17: WH, Clean up low-level _writeCommand() and _writeData(), Added support for alternative fonttables (eg PCF21XX), Added ST7066_ACM controller for ACM1602 module 00021 * 2015, v18: WH, Performance improvement I2C portexpander 00022 * 2015, v19: WH, Added 10x2D and 10x4D type for SSD1803 00023 * 2015, v20: WH, Fixed occasional Init fail caused by insufficient wait time after ReturnHome command (0x02), Added defines to reduce memory footprint (eg LCD_ICON), 00024 * Fixed and Added more fonttable support for PCF2119R_3V3, Added HD66712 controller. 00025 * 2015, v21: WH, Added LCD32x2 defines and code, Fixed LCD12x4D enum, Added font enums, Added SPLC792A controller, 00026 * Added UTF8_2_LCD decode for Cyrilic font (By Andriy Ribalko). Added setFont() 00027 * 00028 * Permission is hereby granted, free of charge, to any person obtaining a copy 00029 * of this software and associated documentation files (the "Software"), to deal 00030 * in the Software without restriction, including without limitation the rights 00031 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00032 * copies of the Software, and to permit persons to whom the Software is 00033 * furnished to do so, subject to the following conditions: 00034 * 00035 * The above copyright notice and this permission notice shall be included in 00036 * all copies or substantial portions of the Software. 00037 * 00038 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00039 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00040 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00041 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00042 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00043 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00044 * THE SOFTWARE. 00045 */ 00046 00047 #ifndef MBED_TEXTLCD_H 00048 #define MBED_TEXTLCD_H 00049 00050 #include "mbed.h" 00051 #include "TextLCD_Config.h" 00052 #include "TextLCD_UDC.h" 00053 00054 //// modified by by JH1PJL 00055 #if (MBED_MAJOR_VERSION == 2) 00056 #define WAIT_MS(x) wait_ms(x) 00057 #elif (MBED_MAJOR_VERSION == 5) || (MBED_MAJOR_VERSION == 6) 00058 #define WAIT_MS(x) ThisThread::sleep_for(x) 00059 #else 00060 #warning "I cannot control wait_ms()!!" 00061 #endif 00062 00063 /** A TextLCD interface for driving 4-bit HD44780-based LCDs 00064 * 00065 * Currently supports 8x1, 8x2, 12x3, 12x4, 16x1, 16x2, 16x3, 16x4, 20x2, 20x4, 24x1, 24x2, 24x4, 40x2 and 40x4 panels. 00066 * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595). 00067 * Supports some controllers with native I2C or SPI interface. Supports some controllers that provide internal DC/DC converters for VLCD or VLED. 00068 * Supports some controllers that feature programmable contrast control, powerdown, blinking UDCs and/or top/down orientation modes. 00069 * 00070 * @code 00071 * #include "mbed.h" 00072 * #include "TextLCD.h" 00073 * 00074 * // I2C Communication 00075 * I2C i2c_lcd(p28,p27); // SDA, SCL 00076 * 00077 * // SPI Communication 00078 * SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK 00079 * 00080 * //TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=HD44780 00081 * //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, 74595 expander, CS pin, LCD Type 00082 * TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type 00083 * //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type (OLED) 00084 * //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3 00085 * //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=ST7032_3V3 00086 * //TextLCD_SPI_N_3_24 lcd(&spi_lcd, p8, TextLCD::LCD20x4D, NC, TextLCD::SSD1803_3V3); // SPI bus, CS pin, LCDType=LCD20x4D, BL=NC, LCDTCtrl=SSD1803 00087 * //TextLCD_SPI_N_3_24 lcd(&spi_lcd, p8, TextLCD::LCD20x2, NC, TextLCD::US2066_3V3); // SPI bus, CS pin, LCDType=LCD20x2, BL=NC, LCDTCtrl=US2066 (OLED) 00088 * 00089 * int main() { 00090 * lcd.printf("Hello World!\n"); 00091 * } 00092 * @endcode 00093 */ 00094 00095 //The TextLCD_Config.h file selects hardware interface options to reduce memory footprint 00096 //and provides Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces. 00097 //The LCD and serial portexpanders should be wired accordingly. 00098 00099 /* LCD Type information on Rows, Columns and Variant. This information is encoded in 00100 * an int and used for the LCDType enumerators in order to simplify code maintenance */ 00101 00102 // Type ID encoded in b7..b0 00103 #define LCD_T_ID_MSK 0x000000FF 00104 #define LCD_T_ID_SHFT 0 00105 00106 // Columns encoded in b15..b8 00107 #define LCD_T_COL_MSK 0x0000FF00 00108 #define LCD_T_COL_SHFT 8 00109 #define LCD_T_C6 0x00000600 00110 #define LCD_T_C8 0x00000800 00111 #define LCD_T_C10 0x00000A00 00112 #define LCD_T_C12 0x00000C00 00113 #define LCD_T_C16 0x00001000 00114 #define LCD_T_C20 0x00001400 00115 #define LCD_T_C24 0x00001800 00116 #define LCD_T_C32 0x00002000 00117 #define LCD_T_C40 0x00002800 00118 //#define LCD_T_C52 0x00003400 00119 00120 // Rows encoded in b23..b16 00121 #define LCD_T_ROW_MSK 0x00FF0000 00122 #define LCD_T_ROW_SHFT 16 00123 #define LCD_T_R1 0x00010000 00124 #define LCD_T_R2 0x00020000 00125 #define LCD_T_R3 0x00030000 00126 #define LCD_T_R4 0x00040000 00127 #define LCD_T_R6 0x00060000 00128 00129 // Addressing mode encoded in b27..b24 00130 #define LCD_T_ADR_MSK 0x0F000000 00131 #define LCD_T_ADR_SHFT 24 00132 #define LCD_T_A 0x00000000 /*Mode A Default 1, 2 or 4 line display */ 00133 #define LCD_T_B 0x01000000 /*Mode B, Alternate 8x2 (actually 16x1 display) */ 00134 #define LCD_T_C 0x02000000 /*Mode C, Alternate 16x1 (actually 8x2 display) */ 00135 #define LCD_T_D 0x03000000 /*Mode D, Alternate 3 or 4 line display (12x4, 20x4, 24x4) */ 00136 #define LCD_T_D1 0x04000000 /*Mode D1, Alternate 3 out of 4 line display (12x3, 20x3, 24x3) */ 00137 #define LCD_T_E 0x05000000 /*Mode E, 40x4 display (actually two 40x2) */ 00138 #define LCD_T_F 0x06000000 /*Mode F, 16x3 display (actually 24x2) */ 00139 #define LCD_T_G 0x07000000 /*Mode G, 16x3 display */ 00140 00141 /* LCD Ctrl information on interface support and features. This information is encoded in 00142 * an int and used for the LCDCtrl enumerators in order to simplify code maintenance */ 00143 // Interface encoded in b31..b24 00144 #define LCD_C_BUS_MSK 0xFF000000 00145 #define LCD_C_BUS_SHFT 24 00146 #define LCD_C_PAR 0x01000000 /*Parallel 4 or 8 bit data, E pin, RS pin, RW=GND */ 00147 #define LCD_C_SPI3_8 0x02000000 /*SPI 3 line (MOSI, SCL, CS pins), 8 bits (Count Command initiates Data transfer) */ 00148 #define LCD_C_SPI3_9 0x04000000 /*SPI 3 line (MOSI, SCL, CS pins), 9 bits (RS + 8 Data) */ 00149 #define LCD_C_SPI3_10 0x08000000 /*SPI 3 line (MOSI, SCL, CS pins), 10 bits (RS, RW + 8 Data) */ 00150 #define LCD_C_SPI3_16 0x10000000 /*SPI 3 line (MOSI, SCL, CS pins), 16 bits (RS, RW + 8 Data) */ 00151 #define LCD_C_SPI3_24 0x20000000 /*SPI 3 line (MOSI, SCL, CS pins), 24 bits (RS, RW + 8 Data) */ 00152 #define LCD_C_SPI4 0x40000000 /*SPI 4 line (MOSI, SCL, CS, RS pin), RS pin + 8 Data */ 00153 #define LCD_C_I2C 0x80000000 /*I2C (SDA, SCL pin), 8 control bits (Co, RS, RW) + 8 Data */ 00154 // Features encoded in b23..b16 00155 #define LCD_C_FTR_MSK 0x00FF0000 00156 #define LCD_C_FTR_SHFT 16 00157 #define LCD_C_BST 0x00010000 /*Booster */ 00158 #define LCD_C_CTR 0x00020000 /*Contrast Control */ 00159 #define LCD_C_ICN 0x00040000 /*Icons */ 00160 #define LCD_C_PDN 0x00080000 /*Power Down */ 00161 // Fonttable encoded in b15..b12 00162 #define LCD_C_FNT_MSK 0x0000F000 00163 #define LCD_C_FNT_SHFT 12 00164 #define LCD_C_F0 0x00000000 /*Default HD44780 UK/JAP */ 00165 #define LCD_C_FC 0x00001000 /*PCF21xxC */ 00166 #define LCD_C_FR 0x00002000 /*PCF21XXR */ 00167 #define LCD_C_FK 0x00003000 /*PCF21XXK */ 00168 #define LCD_C_FRA 0x00004000 /*SSD1803 ROM_A UK/EU */ 00169 #define LCD_C_FRB 0x00005000 /*SSD1803 ROM_B UK/Cyrillic */ 00170 #define LCD_C_FRC 0x00006000 /*SSD1803 ROM_C UK/JAP */ 00171 #define LCD_C_FD 0x00007000 /*SPLC780D EU/Cyrillic */ 00172 #define LCD_C_FT 0x00008000 /*ST7066-0T EU/Cyrillic */ 00173 00174 // Type ID encoded in b7..b0 00175 #define LCD_C_ID_MSK 0x000000FF 00176 #define LCD_C_ID_SHFT 0 00177 00178 /** A TextLCD interface for driving 4-bit HD44780-based LCDs 00179 * 00180 * @brief Currently supports 8x1, 8x2, 12x2, 12x3, 12x4, 16x1, 16x2, 16x3, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels 00181 * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or 00182 * SPI bus shiftregister (74595) or native I2C or SPI interfaces for some supported devices. 00183 */ 00184 class TextLCD_Base : public Stream { 00185 //class TextLCD_Base { 00186 00187 //Unfortunately the following #define selection breaks Doxygen !!! 00188 //Add it manually when you want to disable the Stream inheritance 00189 //#if (LCD_PRINTF == 1) 00190 //class TextLCD_Base : public Stream { 00191 //#else 00192 //class TextLCD_Base { 00193 //#endif 00194 00195 public: 00196 00197 /** LCD panel format */ 00198 // The commented out types exist but have not yet been tested with the library 00199 enum LCDType { 00200 // LCD6x1 = (LCD_T_A | LCD_T_C6 | LCD_T_R1), /**< 6x1 LCD panel */ 00201 // LCD6x2 = (LCD_T_A | LCD_T_C6 | LCD_T_R2), /**< 6x2 LCD panel */ 00202 LCD8x1 = (LCD_T_A | LCD_T_C8 | LCD_T_R1), /**< 8x1 LCD panel */ 00203 LCD8x2 = (LCD_T_A | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel */ 00204 LCD8x2B = (LCD_T_B | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel (actually 16x1) */ 00205 // LCD10x2D = (LCD_T_D | LCD_T_C10 | LCD_T_R2), /**< 10x2 LCD panel, special mode SSD1803, 4-line but double height */ 00206 LCD10x4D = (LCD_T_D | LCD_T_C10 | LCD_T_R4), /**< 10x4 LCD panel, special mode SSD1803 */ 00207 LCD12x1 = (LCD_T_A | LCD_T_C12 | LCD_T_R1), /**< 12x1 LCD panel */ 00208 LCD12x2 = (LCD_T_A | LCD_T_C12 | LCD_T_R2), /**< 12x2 LCD panel */ 00209 LCD12x3D = (LCD_T_D | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX, KS0073 */ 00210 LCD12x3D1 = (LCD_T_D1 | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX, KS0073 */ 00211 // LCD12x3G = (LCD_T_G | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode ST7036 */ 00212 LCD12x4 = (LCD_T_A | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel */ 00213 LCD12x4D = (LCD_T_D | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel, special mode PCF21XX, KS0073 */ 00214 LCD16x1 = (LCD_T_A | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel */ 00215 LCD16x1C = (LCD_T_C | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel (actually 8x2) */ 00216 LCD16x2 = (LCD_T_A | LCD_T_C16 | LCD_T_R2), /**< 16x2 LCD panel (default) */ 00217 // LCD16x2B = (LCD_T_B | LCD_T_C16 | LCD_T_R2), /**< 16x2 LCD panel, alternate addressing, wrong.. */ 00218 LCD16x3D = (LCD_T_D | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */ 00219 // LCD16x3D1 = (LCD_T_D1 | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */ 00220 LCD16x3F = (LCD_T_F | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel (actually 24x2) */ 00221 LCD16x3G = (LCD_T_G | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode ST7036 */ 00222 LCD16x4 = (LCD_T_A | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel */ 00223 // LCD16x4D = (LCD_T_D | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel, special mode SSD1803 */ 00224 LCD20x1 = (LCD_T_A | LCD_T_C20 | LCD_T_R1), /**< 20x1 LCD panel */ 00225 LCD20x2 = (LCD_T_A | LCD_T_C20 | LCD_T_R2), /**< 20x2 LCD panel */ 00226 // LCD20x3 = (LCD_T_A | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel */ 00227 // LCD20x3D = (LCD_T_D | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803, KS0073 */ 00228 // LCD20x3D1 = (LCD_T_D1 | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803, KS0073 */ 00229 LCD20x4 = (LCD_T_A | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel */ 00230 LCD20x4D = (LCD_T_D | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel, special mode SSD1803, KS0073 */ 00231 // LCD20x6 = (LCD_T_E | LCD_T_C20 | LCD_T_R6), /**< 20x6 LCD panel, Two controller version */ 00232 LCD24x1 = (LCD_T_A | LCD_T_C24 | LCD_T_R1), /**< 24x1 LCD panel */ 00233 LCD24x2 = (LCD_T_A | LCD_T_C24 | LCD_T_R2), /**< 24x2 LCD panel */ 00234 // LCD24x3D = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */ 00235 // LCD24x3D1 = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */ 00236 LCD24x4D = (LCD_T_D | LCD_T_C24 | LCD_T_R4), /**< 24x4 LCD panel, special mode KS0078 */ 00237 // LCD32x1 = (LCD_T_A | LCD_T_C32 | LCD_T_R1), /**< 32x1 LCD panel */ 00238 // LCD32x1C = (LCD_T_C | LCD_T_C32 | LCD_T_R1), /**< 32x1 LCD panel (actually 16x2) */ 00239 LCD32x2 = (LCD_T_A | LCD_T_C32 | LCD_T_R2), /**< 32x2 LCD panel */ 00240 // LCD32x4 = (LCD_T_A | LCD_T_C32 | LCD_T_R4), /**< 32x4 LCD panel, Two controller version ? */ 00241 // LCD40x1 = (LCD_T_A | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel */ 00242 // LCD40x1C = (LCD_T_C | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel (actually 20x2) */ 00243 LCD40x2 = (LCD_T_A | LCD_T_C40 | LCD_T_R2), /**< 40x2 LCD panel */ 00244 // LCD52x1 = (LCD_T_A | LCD_T_C52 | LCD_T_R1), /**< 52x1 LCD panel, special mode KS0073 */ 00245 #if (LCD_TWO_CTRL == 1) 00246 LCD40x4 = (LCD_T_E | LCD_T_C40 | LCD_T_R4) /**< 40x4 LCD panel, Two controller version */ 00247 #endif 00248 }; 00249 00250 00251 /** LCD Controller Device */ 00252 enum LCDCtrl { 00253 HD44780 = 0 | LCD_C_PAR, /**< HD44780 or full equivalent (default) */ 00254 AC780 = 1 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_PDN), /**< AC780/KS0066i 4/8 bit, SPI, I2C */ 00255 AIP31068 = 2 | (LCD_C_SPI3_9 | LCD_C_I2C | LCD_C_BST), /**< AIP31068 I2C, SPI3 */ 00256 KS0073 = 3 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_PDN), /**< KS0073 4/8 bit, SPI3 */ 00257 KS0078 = 4 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_PDN), /**< KS0078 24x4 support, 4/8 bit, SPI3 */ 00258 PCF2103_3V3 = 5 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2103 3V3 no Booster, 4/8 bit, I2C */ 00259 PCF2113_3V3 = 6 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2113 3V3 with Booster, 4/8 bit, I2C */ 00260 PCF2116_3V3 = 7 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST), /**< PCF2116 3V3 with Booster, 4/8 bit, I2C */ 00261 // PCF2116C_3V3 = | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_FC), /**< PCF2116C 3V3 with Booster, 4/8 bit, I2C */ 00262 // PCF2116K_3V3 = | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_FK), /**< PCF2116K 3V3 with Booster, 4/8 bit, I2C */ 00263 PCF2116_5V = 8 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2116 5V no Booster, 4/8 bit, I2C */ 00264 PCF2116C_5V = 9 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_FC), /**< PCF2116C 3V3 with Booster, 4/8 bit, I2C */ 00265 PCF2119_3V3 = 10 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2119 3V3 with Booster, 4/8 bit, I2C */ 00266 // PCF2119C_3V3 = 11 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_FC), /**< PCF2119K 3V3 with Booster, 4/8 bit, I2C */ 00267 PCF2119R_3V3 = 12 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_FR), /**< PCF2119R 3V3 with Booster, 4/8 bit, I2C */ 00268 // PCF2119_5V = | (LCD_C_PAR | LCD_C_I2C), /**< PCF2119 5V no Booster, 4/8 bit, I2C */ 00269 PT6314 = 13 | (LCD_C_PAR | LCD_C_SPI3_16 | LCD_C_CTR), /**< PT6314 VFD Controller, 4/8 bit, SPI3 */ 00270 // PT6880 = xx | (LCD_C_PAR | LCD_C_SPI3_16 | LCD_C_CTR), /**< PT6880 OLED controller, 4/8 bit, SPI3 */ 00271 SSD1803_3V3 = 14 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_PDN), /**< SSD1803 3V3 with Booster, 4/8 bit, I2C, SPI3 */ 00272 // SSD1803_5V = 15 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_PDN), /**< SSD1803 3V3 with Booster, 4/8 bit, I2C, SPI3 */ 00273 ST7032_3V3 = 16 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7032/SPLC792A 3V3 with Booster, 4/8 bit, SPI4, I2C */ 00274 ST7032_5V = 17 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_CTR), /**< ST7032/SPLC792A 5V no Booster, 4/8 bit, SPI4, I2C */ 00275 ST7036_3V3 = 18 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7036 3V3 with Booster, 4/8 bit, SPI4, I2C */ 00276 ST7036_5V = 19 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7036 5V no Booster, 4/8 bit, SPI4, I2C */ 00277 ST7066_ACM = 20 | (LCD_C_PAR | LCD_C_I2C), /**< ST7066 4/8 bit, I2C on ACM1602 using a PIC */ 00278 ST7070 = 21 | (LCD_C_PAR | LCD_C_SPI3_8 | LCD_C_SPI4), /**< ST7070 4/8 bit, SPI3 */ 00279 US2066_3V3 = 22 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_CTR | LCD_C_PDN), /**< US2066/SSD1311 3V3, 4/8 bit, I2C, SPI3 */ 00280 WS0010 = 23 | (LCD_C_PAR | LCD_C_SPI3_10 | LCD_C_PDN), /**< WS0010/RS0010 OLED Controller, 4/8 bit, SPI3 */ 00281 // WS0012 = 24 | (LCD_C_PAR | LCD_C_SPI3_10 | LCD_C_I2C | LCD_C_PDN), /**< WS0012 4/8 bit, SPI, I2C */ 00282 HD66712 = 25 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_BST | LCD_C_PDN), /**< HD66712 Controller, 4/8 bit, SPI3 */ 00283 SPLC792A_3V3 = 26 | (LCD_C_PAR | LCD_C_SPI3_9 | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR) /**< ST7032/SPLC792A 3V3 with Booster, 4/8 bit, SPI3, SPI4, I2C */ 00284 }; 00285 00286 00287 /** LCD Cursor control */ 00288 enum LCDCursor { 00289 CurOff_BlkOff = 0x00, /**< Cursor Off, Blinking Char Off */ 00290 CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */ 00291 CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */ 00292 CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */ 00293 }; 00294 00295 /** LCD Display control */ 00296 enum LCDMode { 00297 DispOff = 0x00, /**< Display Off */ 00298 DispOn = 0x04 /**< Display On */ 00299 }; 00300 00301 /** LCD Backlight control */ 00302 enum LCDBacklight { 00303 LightOff, /**< Backlight Off */ 00304 LightOn /**< Backlight On */ 00305 }; 00306 00307 /** LCD Blink control (UDC), supported for some Controllers */ 00308 enum LCDBlink { 00309 BlinkOff, /**< Blink Off */ 00310 BlinkOn /**< Blink On */ 00311 }; 00312 00313 /** LCD Orientation control, supported for some Controllers */ 00314 enum LCDOrient { 00315 Top, /**< Top view */ 00316 Bottom /**< Upside down view */ 00317 }; 00318 00319 #if (LCD_BIGFONT == 1) 00320 /** LCD BigFont control, supported for some Controllers */ 00321 enum LCDBigFont { 00322 None, /**< no lines */ 00323 TopLine, /**< 1+2 line */ 00324 CenterLine, /**< 2+3 line */ 00325 BottomLine, /**< 2+3 line or 3+4 line */ 00326 TopBottomLine /**< 1+2 line and 3+4 line */ 00327 }; 00328 #endif 00329 00330 #if (LCD_FONTSEL == 1) 00331 /** LCD setFont control. 00332 Note: most controllers support only one font and the hardware specific 00333 fonttable is encoded as part of the controller type number (eg PCF21XXC or PCF21XXR). 00334 Some controllers support multiple tables that can only be selected by logic levels on a few pins. 00335 Some controllers also support runtime fontable switching through a specific instruction */ 00336 enum LCDFont { 00337 /**< HD44780 fonttable */ 00338 Font_0 = LCD_C_F0, /**< default, UK/JAP */ 00339 /**< PCF21XX fonttables */ 00340 Font_C = LCD_C_FC, /**< PCF21XXC */ 00341 Font_R = LCD_C_FR, /**< PCF21XXR */ 00342 /**< SSD1803 ROM tables */ 00343 Font_RA = LCD_C_FRA, /**< UK/EU */ 00344 Font_RB = LCD_C_FRB, /**< UK/Cyrillic */ 00345 Font_RC = LCD_C_FRC, /**< default, UK/JAP */ 00346 Font_D = LCD_C_FD, /**< SPLC780D Cyrillic */ 00347 Font_T = LCD_C_FT /**< ST7066-0T Cyrillic */ 00348 }; 00349 #endif 00350 00351 #if ((LCD_C_FONT == 1) || (LCD_R_FONT == 1)) //PCF21xxC or PCF21xxR font 00352 /** Convert ASCII character code to the LCD fonttable code 00353 * 00354 * @param c The character to write to the display 00355 * @return The character code for the specific fonttable of the controller 00356 */ 00357 int ASCII_2_LCD (int c); 00358 #endif 00359 00360 #if(LCD_UTF8_FONT == 1) 00361 /** Convert UTF8 2-byte character code to the LCD fonttable code 00362 * @param c The character to write to the display 00363 * @return character code for the specific fonttable of the controller or -1 if UTF8 code is not yet complete or incorrect 00364 * 00365 * Orig by Andriy, Modified by WH 00366 * 00367 * Note: The UTF8 decoding table for a specific controller is defined and selected in file TextLCD_UTF8.inc 00368 * The table is accessed in this UTF_2_LCD() method through 00369 * #define UTF_FIRST, UTF_LAST, UTF_SEQ_REC_FIRST, UTF_SEQ_REC_LAST and 00370 * #define UTF_SEQ_RECODE and UTF_RND_RECODE 00371 */ 00372 int UTF_2_LCD (int c); 00373 #endif 00374 00375 00376 #if(LCD_PRINTF != 1) 00377 /** Write a character to the LCD 00378 * 00379 * @param c The character to write to the display 00380 */ 00381 int putc(int c); 00382 00383 /** Write a raw string to the LCD 00384 * 00385 * @param string text, may be followed by variables to emulate formatting the string. 00386 * However, printf formatting is NOT supported and variables will be ignored! 00387 */ 00388 int printf(const char* text, ...); 00389 #else 00390 #if DOXYGEN_ONLY 00391 /** Write a character to the LCD 00392 * 00393 * @param c The character to write to the display 00394 */ 00395 int putc(int c); 00396 00397 /** Write a formatted string to the LCD 00398 * 00399 * @param format A printf-style format string, followed by the 00400 * variables to use in formatting the string. 00401 */ 00402 int printf(const char* format, ...); 00403 #endif 00404 00405 #endif 00406 00407 /** Locate cursor to a screen column and row 00408 * 00409 * @param column The horizontal position from the left, indexed from 0 00410 * @param row The vertical position from the top, indexed from 0 00411 */ 00412 void locate(int column, int row); 00413 00414 /** Return the memoryaddress of screen column and row location 00415 * 00416 * @param column The horizontal position from the left, indexed from 0 00417 * @param row The vertical position from the top, indexed from 0 00418 * @return The memoryaddress of screen column and row location 00419 */ 00420 int getAddress(int column, int row); 00421 00422 /** Set the memoryaddress of screen column and row location 00423 * 00424 * @param column The horizontal position from the left, indexed from 0 00425 * @param row The vertical position from the top, indexed from 0 00426 */ 00427 void setAddress(int column, int row); 00428 00429 /** Clear the screen and locate to 0,0 00430 */ 00431 void cls(); 00432 00433 /** Return the number of rows 00434 * 00435 * @return The number of rows 00436 */ 00437 int rows(); 00438 00439 /** Return the number of columns 00440 * 00441 * @return The number of columns 00442 */ 00443 int columns(); 00444 00445 /** Set the Cursormode 00446 * 00447 * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn) 00448 */ 00449 void setCursor(LCDCursor cursorMode); 00450 00451 /** Set the Displaymode 00452 * 00453 * @param displayMode The Display mode (DispOff, DispOn) 00454 */ 00455 void setMode(LCDMode displayMode); 00456 00457 /** Set the Backlight mode 00458 * 00459 * @param backlightMode The Backlight mode (LightOff, LightOn) 00460 */ 00461 void setBacklight(LCDBacklight backlightMode); 00462 00463 /** Set User Defined Characters (UDC) 00464 * 00465 * @param unsigned char c The Index of the UDC (0..7) for HD44780 clones and (0..15) for some more advanced controllers 00466 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits for bitpattern and 3 bits for blinkmode (advanced types)) 00467 */ 00468 void setUDC(unsigned char c, char *udc_data); 00469 00470 #if(LCD_BLINK == 1) 00471 /** Set UDC Blink and Icon blink 00472 * setUDCBlink method is supported by some compatible devices (eg SSD1803) 00473 * 00474 * @param blinkMode The Blink mode (BlinkOff, BlinkOn) 00475 */ 00476 void setUDCBlink(LCDBlink blinkMode); 00477 #endif 00478 00479 #if(LCD_CONTRAST == 1) 00480 /** Set Contrast 00481 * setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation 00482 * Code imported from fork by JH1PJL 00483 * 00484 * @param unsigned char c contrast data (6 significant bits, valid range 0..63, Value 0 will disable the Vgen) 00485 * @return none 00486 */ 00487 void setContrast(unsigned char c = LCD_DEF_CONTRAST); 00488 #endif 00489 00490 #if(LCD_POWER == 1) 00491 /** Set Power 00492 * setPower method is supported by some compatible devices (eg SSD1803) that have power down modes 00493 * 00494 * @param bool powerOn Power on/off 00495 * @return none 00496 */ 00497 void setPower(bool powerOn = true); 00498 #endif 00499 00500 #if(LCD_ORIENT == 1) 00501 /** Set Orient 00502 * setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes 00503 * 00504 * @param LCDOrient orient Orientation 00505 * @return none 00506 */ 00507 void setOrient(LCDOrient orient = Top); 00508 #endif 00509 00510 #if(LCD_BIGFONT == 1) 00511 /** Set Big Font 00512 * setBigFont method is supported by some compatible devices (eg SSD1803, US2066) 00513 * 00514 * @param lines The selected Big Font lines (None, TopLine, CenterLine, BottomLine, TopBottomLine) 00515 * Double height characters can be shown on lines 1+2, 2+3, 3+4 or 1+2 and 3+4 00516 * Valid double height lines depend on the LCDs number of rows. 00517 * @return none 00518 */ 00519 void setBigFont(LCDBigFont lines); 00520 #endif 00521 00522 #if(LCD_FONTSEL == 1) 00523 /** Set Font 00524 * setFont method is supported by some compatible devices (eg SSD1803, US2066, ST7070) 00525 * 00526 * @param LCDFont font The selected Font 00527 * @return none 00528 */ 00529 void setFont(LCDFont font = Font_0); 00530 #endif 00531 00532 00533 #if(LCD_ICON==1) 00534 /** Set Icons 00535 * 00536 * @param unsigned char idx The Index of the icon pattern (0..15) for KS0073 and similar controllers 00537 * and Index (0..31) for PCF2103 and similar controllers 00538 * @param unsigned char data The bitpattern for the icons (6 lsb for KS0073 bitpattern (5 lsb for KS0078) and 2 msb for blinkmode) 00539 * The bitpattern for the PCF2103 icons is 5 lsb (UDC 0..2) and 5 lsb for blinkmode (UDC 4..6) 00540 */ 00541 void setIcon(unsigned char idx, unsigned char data); 00542 00543 /** Clear Icons 00544 * 00545 * @param none 00546 * @return none 00547 */ 00548 //@TODO Add support for 40x4 dual controller 00549 void clrIcon(); 00550 #endif 00551 00552 #if(LCD_INVERT == 1) 00553 /** Set Invert 00554 * setInvert method is supported by some compatible devices (eg KS0073) to swap between black and white 00555 * 00556 * @param bool invertOn Invert on/off 00557 * @return none 00558 */ 00559 //@TODO Add support for 40x4 dual controller 00560 void setInvert(bool invertOn); 00561 #endif 00562 00563 protected: 00564 00565 /** LCD controller select, mainly used for LCD40x4 00566 */ 00567 enum _LCDCtrl_Idx { 00568 _LCDCtrl_0, /*< Primary */ 00569 _LCDCtrl_1, /*< Secondary */ 00570 }; 00571 00572 /** LCD Datalength control to select between 4 or 8 bit data/commands, mainly used for native Serial interface */ 00573 enum _LCDDatalength { 00574 _LCD_DL_4 = 0x00, /**< Datalength 4 bit */ 00575 _LCD_DL_8 = 0x10 /**< Datalength 8 bit */ 00576 }; 00577 00578 /** Create a TextLCD_Base interface 00579 * @brief Base class, can not be instantiated 00580 * 00581 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00582 * @param ctrl LCD controller (default = HD44780) 00583 */ 00584 TextLCD_Base(LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); 00585 00586 // Stream implementation functions 00587 virtual int _putc(int value); 00588 virtual int _getc(); 00589 00590 /** Medium level initialisation method for LCD controller 00591 * @param _LCDDatalength dl sets the datalength of data/commands 00592 * @return none 00593 */ 00594 void _init(_LCDDatalength dl = _LCD_DL_4); 00595 00596 /** Low level initialisation method for LCD controller 00597 * Set number of lines, fonttype, no cursor etc 00598 * The controller is accessed in 4-bit parallel mode either directly via mbed pins or through I2C or SPI expander. 00599 * Some controllers also support native I2C or SPI interfaces. 00600 * 00601 * @param _LCDDatalength dl sets the 4 or 8 bit datalength of data/commands. Required for some native serial modes. 00602 * @return none 00603 */ 00604 void _initCtrl(_LCDDatalength dl = _LCD_DL_4); 00605 00606 /** Low level character address set method 00607 */ 00608 int _address(int column, int row); 00609 00610 /** Low level cursor enable or disable method 00611 */ 00612 void _setCursor(LCDCursor show); 00613 00614 /** Low level method to store user defined characters for current controller 00615 * 00616 * @param unsigned char c The Index of the UDC (0..7) for HD44780 clones and (0..15) for some more advanced controllers 00617 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits) 00618 */ 00619 void _setUDC(unsigned char c, char *udc_data); 00620 00621 /** Low level method to restore the cursortype and display mode for current controller 00622 */ 00623 void _setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType); 00624 00625 /** Low level nibble write operation to LCD controller (serial or parallel) 00626 */ 00627 void _writeNibble(int value); 00628 00629 /** Low level command byte write operation to LCD controller. 00630 * Methods resets the RS bit and provides the required timing for the command. 00631 */ 00632 void _writeCommand(int command); 00633 00634 /** Low level data byte write operation to LCD controller (serial or parallel). 00635 * Methods sets the RS bit and provides the required timing for the data. 00636 */ 00637 void _writeData(int data); 00638 00639 /** Pure Virtual Low level writes to LCD Bus (serial or parallel) 00640 * Set the Enable pin. 00641 */ 00642 virtual void _setEnable(bool value) = 0; 00643 00644 /** Pure Virtual Low level writes to LCD Bus (serial or parallel) 00645 * Set the RS pin ( 0 = Command, 1 = Data). 00646 */ 00647 virtual void _setRS(bool value) = 0; 00648 00649 /** Pure Virtual Low level writes to LCD Bus (serial or parallel) 00650 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00651 */ 00652 virtual void _setBL(bool value) = 0; 00653 00654 /** Pure Virtual Low level writes to LCD Bus (serial or parallel) 00655 * Set the databus value (4 bit). 00656 */ 00657 virtual void _setData(int value) = 0; 00658 00659 /** Low level byte write operation to LCD controller (serial or parallel) 00660 * Depending on the RS pin this byte will be interpreted as data or command 00661 */ 00662 virtual void _writeByte(int value); 00663 00664 //Display type 00665 LCDType _type; // Display type 00666 int _nr_cols; 00667 int _nr_rows; 00668 int _addr_mode; // Addressing mode of LCDType, defines relation between display row,col and controller memory address 00669 00670 //Display mode 00671 LCDMode _currentMode; 00672 00673 //Controller type 00674 LCDCtrl _ctrl; // Controller type 00675 int _font; // ASCII character fonttable 00676 00677 //Controller select, mainly used for LCD40x4 00678 _LCDCtrl_Idx _ctrl_idx; 00679 00680 // Cursor 00681 int _column; 00682 int _row; 00683 LCDCursor _currentCursor; 00684 00685 // Function modes saved to allow switch between Instruction sets after initialisation time 00686 int _function, _function_1, _function_x; 00687 00688 // Icon, Booster mode and contrast saved to allow contrast change at later time 00689 // Only available for controllers with added features 00690 int _icon_power, _contrast; 00691 }; 00692 00693 //--------- End TextLCD_Base ----------- 00694 00695 00696 //--------- Start TextLCD Bus ----------- 00697 00698 /** Create a TextLCD interface for using regular mbed pins 00699 * 00700 */ 00701 class TextLCD : public TextLCD_Base { 00702 public: 00703 /** Create a TextLCD interface for using regular mbed pins 00704 * 00705 * @param rs Instruction/data control line 00706 * @param e Enable line (clock) 00707 * @param d4-d7 Data lines for using as a 4-bit interface 00708 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00709 * @param bl Backlight control line (optional, default = NC) 00710 * @param e2 Enable2 line (clock for second controller, LCD40x4 only) 00711 * @param ctrl LCD controller (default = HD44780) 00712 */ 00713 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); 00714 00715 /** Destruct a TextLCD interface for using regular mbed pins 00716 * 00717 * @param none 00718 * @return none 00719 */ 00720 virtual ~TextLCD(); 00721 00722 private: 00723 00724 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) 00725 * Set the Enable pin. 00726 */ 00727 virtual void _setEnable(bool value); 00728 00729 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) 00730 * Set the RS pin (0 = Command, 1 = Data). 00731 */ 00732 virtual void _setRS(bool value); 00733 00734 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) 00735 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00736 */ 00737 virtual void _setBL(bool value); 00738 00739 /** Implementation of pure Virtual Low level writes to LCD Bus (parallel) 00740 * Set the databus value (4 bit). 00741 */ 00742 virtual void _setData(int value); 00743 00744 /** Regular mbed pins bus 00745 */ 00746 DigitalOut _rs, _e; 00747 BusOut _d; 00748 00749 /** Optional Hardware pins for the Backlight and LCD40x4 device 00750 * Default PinName value is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins 00751 */ 00752 DigitalOut *_bl, *_e2; 00753 }; 00754 00755 //----------- End TextLCD --------------- 00756 00757 00758 //--------- Start TextLCD_I2C ----------- 00759 #if(LCD_I2C == 1) /* I2C Expander PCF8574/MCP23008 */ 00760 00761 /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander 00762 * 00763 */ 00764 class TextLCD_I2C : public TextLCD_Base { 00765 public: 00766 /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander 00767 * 00768 * @param i2c I2C Bus 00769 * @param deviceAddress I2C slave address (PCF8574 (or PCF8574A) or MCP23008 portexpander, default = PCF8574_SA0 = 0x40) 00770 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00771 * @param ctrl LCD controller (default = HD44780) 00772 */ 00773 TextLCD_I2C(I2C *i2c, char deviceAddress = PCF8574_SA0, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); 00774 00775 private: 00776 00777 /** Place the Enable bit in the databus shadowvalue 00778 * Used for mbed I2C portexpander 00779 * @param value data to write 00780 * @return none 00781 */ 00782 void _setEnableBit(bool value); 00783 00784 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00785 * Set the Enable pin. 00786 */ 00787 virtual void _setEnable(bool value); 00788 00789 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00790 * Set the RS pin (0 = Command, 1 = Data). 00791 */ 00792 virtual void _setRS(bool value); 00793 00794 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00795 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00796 */ 00797 virtual void _setBL(bool value); 00798 00799 /** Place the 4bit data in the databus shadowvalue 00800 * Used for mbed I2C portexpander 00801 * @param value data to write 00802 * @return none 00803 */ 00804 void _setDataBits(int value); 00805 00806 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00807 * Set the databus value (4 bit). 00808 */ 00809 virtual void _setData(int value); 00810 00811 //New optimized 00812 //Test faster _writeByte 0.11s vs 0.27s for a 20x4 fillscreen (PCF8574) 00813 //Test faster _writeByte 0.14s vs 0.34s for a 20x4 fillscreen (MCP23008) 00814 00815 /** Low level writes to LCD serial bus expander 00816 */ 00817 virtual void _writeByte(int value); 00818 00819 /** Write data to MCP23008 I2C portexpander 00820 * @param reg register to write 00821 * @param value data to write 00822 * @return none 00823 */ 00824 void _writeRegister (int reg, int value); 00825 00826 //I2C bus 00827 I2C *_i2c; 00828 char _slaveAddress; 00829 00830 // Internal bus shadow value for serial bus only 00831 char _lcd_bus; 00832 }; 00833 #endif /* I2C Expander PCF8574/MCP23008 */ 00834 00835 //---------- End TextLCD_I2C ------------ 00836 00837 00838 //--------- Start TextLCD_SPI ----------- 00839 #if(LCD_SPI == 1) /* SPI Expander SN74595 */ 00840 00841 /** Create a TextLCD interface using an SPI 74595 portexpander 00842 * 00843 */ 00844 class TextLCD_SPI : public TextLCD_Base { 00845 public: 00846 /** Create a TextLCD interface using an SPI 74595 portexpander 00847 * 00848 * @param spi SPI Bus 00849 * @param cs chip select pin (active low) 00850 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00851 * @param ctrl LCD controller (default = HD44780) 00852 */ 00853 TextLCD_SPI(SPI *spi, PinName cs, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); 00854 00855 private: 00856 00857 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00858 * Set the Enable pin. 00859 */ 00860 virtual void _setEnable(bool value); 00861 00862 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00863 * Set the RS pin (0 = Command, 1 = Data). 00864 */ 00865 virtual void _setRS(bool value); 00866 00867 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00868 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00869 */ 00870 virtual void _setBL(bool value); 00871 00872 /** Implementation of pure Virtual Low level writes to LCD Bus (serial expander) 00873 * Set the databus value (4 bit). 00874 */ 00875 virtual void _setData(int value); 00876 00877 // SPI bus 00878 SPI *_spi; 00879 DigitalOut _cs; 00880 00881 // Internal bus shadow value for serial bus only 00882 char _lcd_bus; 00883 }; 00884 #endif /* SPI Expander SN74595 */ 00885 //---------- End TextLCD_SPI ------------ 00886 00887 00888 //--------- Start TextLCD_I2C_N ----------- 00889 #if(LCD_I2C_N == 1) /* Native I2C */ 00890 00891 /** Create a TextLCD interface using a controller with native I2C interface 00892 * 00893 */ 00894 class TextLCD_I2C_N : public TextLCD_Base { 00895 public: 00896 /** Create a TextLCD interface using a controller with native I2C interface 00897 * 00898 * @param i2c I2C Bus 00899 * @param deviceAddress I2C slave address (default = ST7032_SA = 0x7C) 00900 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00901 * @param bl Backlight control line (optional, default = NC) 00902 * @param ctrl LCD controller (default = ST7032_3V3) 00903 */ 00904 TextLCD_I2C_N(I2C *i2c, char deviceAddress = ST7032_SA, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3); 00905 00906 /** Destruct a TextLCD interface using a controller with native I2C interface 00907 */ 00908 virtual ~TextLCD_I2C_N(void); 00909 00910 private: 00911 00912 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00913 * Set the Enable pin. 00914 */ 00915 virtual void _setEnable(bool value); 00916 00917 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00918 * Set the RS pin ( 0 = Command, 1 = Data). 00919 */ 00920 virtual void _setRS(bool value); 00921 00922 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00923 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00924 */ 00925 virtual void _setBL(bool value); 00926 00927 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00928 * Set the databus value (4 bit). 00929 */ 00930 virtual void _setData(int value); 00931 00932 /** Low level writes to LCD serial bus only (serial native) 00933 */ 00934 virtual void _writeByte(int value); 00935 00936 //I2C bus 00937 I2C *_i2c; 00938 char _slaveAddress; 00939 00940 // controlbyte to select between data and command. Internal shadow value for serial bus only 00941 char _controlbyte; 00942 00943 //Backlight 00944 DigitalOut *_bl; 00945 00946 }; 00947 #endif /* Native I2C */ 00948 //---------- End TextLCD_I2C_N ------------ 00949 00950 00951 //--------- Start TextLCD_SPI_N ----------- 00952 #if(LCD_SPI_N == 1) /* Native SPI bus */ 00953 00954 /** Create a TextLCD interface using a controller with native SPI4 interface 00955 * 00956 */ 00957 class TextLCD_SPI_N : public TextLCD_Base { 00958 public: 00959 /** Create a TextLCD interface using a controller with native SPI4 interface 00960 * 00961 * @param spi SPI Bus 00962 * @param cs chip select pin (active low) 00963 * @param rs Instruction/data control line 00964 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00965 * @param bl Backlight control line (optional, default = NC) 00966 * @param ctrl LCD controller (default = ST7032_3V3) 00967 */ 00968 TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3); 00969 00970 /** Destruct a TextLCD interface using a controller with native SPI4 interface 00971 */ 00972 virtual ~TextLCD_SPI_N(void); 00973 00974 private: 00975 00976 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00977 * Set the Enable pin. 00978 */ 00979 virtual void _setEnable(bool value); 00980 00981 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00982 * Set the RS pin (0 = Command, 1 = Data). 00983 */ 00984 virtual void _setRS(bool value); 00985 00986 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00987 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 00988 */ 00989 virtual void _setBL(bool value); 00990 00991 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 00992 * Set the databus value (4 bit). 00993 */ 00994 virtual void _setData(int value); 00995 00996 /** Low level writes to LCD serial bus only (serial native) 00997 */ 00998 virtual void _writeByte(int value); 00999 01000 // SPI bus 01001 SPI *_spi; 01002 DigitalOut _cs; 01003 DigitalOut _rs; 01004 01005 //Backlight 01006 DigitalOut *_bl; 01007 }; 01008 #endif /* Native SPI bus */ 01009 //---------- End TextLCD_SPI_N ------------ 01010 01011 01012 //-------- Start TextLCD_SPI_N_3_8 -------- 01013 #if(LCD_SPI_N_3_8 == 1) /* Native SPI bus */ 01014 /** Create a TextLCD interface using a controller with native SPI3 8 bits interface 01015 * This mode is supported by ST7070. 01016 * 01017 */ 01018 class TextLCD_SPI_N_3_8 : public TextLCD_Base { 01019 public: 01020 /** Create a TextLCD interface using a controller with a native SPI3 8 bits interface 01021 * This mode is supported by ST7070. Note that implementation in TexTLCD is not very efficient due to 01022 * structure of the TextLCD library: each databyte is written separately and requires a separate 'count command' set to 1 byte. 01023 * 01024 * @param spi SPI Bus 01025 * @param cs chip select pin (active low) 01026 * @param type Sets the panel size/addressing mode (default = LCD16x2) 01027 * @param bl Backlight control line (optional, default = NC) 01028 * @param ctrl LCD controller (default = ST7070) 01029 */ 01030 TextLCD_SPI_N_3_8(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7070); 01031 01032 /** Destruct a TextLCD interface using a controller with native SPI3_8 interface 01033 */ 01034 virtual ~TextLCD_SPI_N_3_8(void); 01035 01036 private: 01037 01038 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01039 * Set the Enable pin. 01040 */ 01041 virtual void _setEnable(bool value); 01042 01043 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01044 * Set the RS pin (0 = Command, 1 = Data). 01045 */ 01046 virtual void _setRS(bool value); 01047 01048 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01049 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 01050 */ 01051 virtual void _setBL(bool value); 01052 01053 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01054 * Set the databus value (4 bit). 01055 */ 01056 virtual void _setData(int value); 01057 01058 /** Low level writes to LCD serial bus only (serial native) 01059 */ 01060 virtual void _writeByte(int value); 01061 01062 // SPI bus 01063 SPI *_spi; 01064 DigitalOut _cs; 01065 01066 // controlbyte to select between data and command. Internal shadow value for serial bus only 01067 char _controlbyte; 01068 01069 //Backlight 01070 DigitalOut *_bl; 01071 }; 01072 01073 #endif /* Native SPI bus */ 01074 //------- End TextLCD_SPI_N_3_8 ----------- 01075 01076 01077 //------- Start TextLCD_SPI_N_3_9 --------- 01078 #if(LCD_SPI_N_3_9 == 1) /* Native SPI bus */ 01079 //Code checked out on logic analyser. Not yet tested on hardware.. 01080 01081 /** Create a TextLCD interface using a controller with native SPI3 9 bits interface 01082 * Note: current mbed libs only support SPI 9 bit mode for NXP platforms 01083 * 01084 */ 01085 class TextLCD_SPI_N_3_9 : public TextLCD_Base { 01086 public: 01087 /** Create a TextLCD interface using a controller with native SPI3 9 bits interface 01088 * Note: current mbed libs only support SPI 9 bit mode for NXP platforms 01089 * 01090 * @param spi SPI Bus 01091 * @param cs chip select pin (active low) 01092 * @param type Sets the panel size/addressing mode (default = LCD16x2) 01093 * @param bl Backlight control line (optional, default = NC) 01094 * @param ctrl LCD controller (default = AIP31068) 01095 */ 01096 TextLCD_SPI_N_3_9(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = AIP31068); 01097 01098 /** Destruct a TextLCD interface using a controller with native SPI3_9 interface 01099 */ 01100 virtual ~TextLCD_SPI_N_3_9(void); 01101 01102 private: 01103 01104 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01105 * Set the Enable pin. 01106 */ 01107 virtual void _setEnable(bool value); 01108 01109 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01110 * Set the RS pin (0 = Command, 1 = Data). 01111 */ 01112 virtual void _setRS(bool value); 01113 01114 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01115 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 01116 */ 01117 virtual void _setBL(bool value); 01118 01119 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01120 * Set the databus value (4 bit). 01121 */ 01122 virtual void _setData(int value); 01123 01124 /** Low level writes to LCD serial bus only (serial native) 01125 */ 01126 virtual void _writeByte(int value); 01127 01128 // SPI bus 01129 SPI *_spi; 01130 DigitalOut _cs; 01131 01132 // controlbyte to select between data and command. Internal shadow value for serial bus only 01133 char _controlbyte; 01134 01135 //Backlight 01136 DigitalOut *_bl; 01137 }; 01138 #endif /* Native SPI bus */ 01139 //-------- End TextLCD_SPI_N_3_9 ---------- 01140 01141 01142 //------- Start TextLCD_SPI_N_3_10 --------- 01143 #if(LCD_SPI_N_3_10 == 1) /* Native SPI bus */ 01144 01145 /** Create a TextLCD interface using a controller with native SPI3 10 bits interface 01146 * Note: current mbed libs only support SPI 10 bit mode for NXP platforms 01147 * 01148 */ 01149 class TextLCD_SPI_N_3_10 : public TextLCD_Base { 01150 public: 01151 /** Create a TextLCD interface using a controller with native SPI3 10 bits interface 01152 * Note: current mbed libs only support SPI 10 bit mode for NXP platforms 01153 * 01154 * @param spi SPI Bus 01155 * @param cs chip select pin (active low) 01156 * @param type Sets the panel size/addressing mode (default = LCD16x2) 01157 * @param bl Backlight control line (optional, default = NC) 01158 * @param ctrl LCD controller (default = AIP31068) 01159 */ 01160 TextLCD_SPI_N_3_10(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = AIP31068); 01161 01162 /** Destruct a TextLCD interface using a controller with native SPI3_10 interface 01163 */ 01164 virtual ~TextLCD_SPI_N_3_10(void); 01165 01166 private: 01167 01168 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01169 * Set the Enable pin. 01170 */ 01171 virtual void _setEnable(bool value); 01172 01173 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01174 * Set the RS pin (0 = Command, 1 = Data). 01175 */ 01176 virtual void _setRS(bool value); 01177 01178 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01179 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 01180 */ 01181 virtual void _setBL(bool value); 01182 01183 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01184 * Set the databus value (4 bit). 01185 */ 01186 virtual void _setData(int value); 01187 01188 /** Low level writes to LCD serial bus only (serial native) 01189 */ 01190 virtual void _writeByte(int value); 01191 01192 // SPI bus 01193 SPI *_spi; 01194 DigitalOut _cs; 01195 01196 // controlbyte to select between data and command. Internal shadow value for serial bus only 01197 char _controlbyte; 01198 01199 //Backlight 01200 DigitalOut *_bl; 01201 }; 01202 01203 #endif /* Native SPI bus */ 01204 //-------- End TextLCD_SPI_N_3_10 ---------- 01205 01206 01207 //------- Start TextLCD_SPI_N_3_16 --------- 01208 #if(LCD_SPI_N_3_16 == 1) /* Native SPI bus */ 01209 01210 /** Create a TextLCD interface using a controller with native SPI3 16 bits interface 01211 * 01212 */ 01213 class TextLCD_SPI_N_3_16 : public TextLCD_Base { 01214 public: 01215 /** Create a TextLCD interface using a controller with native SPI3 16 bits interface 01216 * 01217 * @param spi SPI Bus 01218 * @param cs chip select pin (active low) 01219 * @param type Sets the panel size/addressing mode (default = LCD16x2) 01220 * @param bl Backlight control line (optional, default = NC) 01221 * @param ctrl LCD controller (default = PT6314) 01222 */ 01223 TextLCD_SPI_N_3_16(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = PT6314); 01224 01225 /** Destruct a TextLCD interface using a controller with native SPI3_16 interface 01226 */ 01227 virtual ~TextLCD_SPI_N_3_16(void); 01228 01229 private: 01230 01231 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01232 * Set the Enable pin. 01233 */ 01234 virtual void _setEnable(bool value); 01235 01236 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01237 * Set the RS pin (0 = Command, 1 = Data). 01238 */ 01239 virtual void _setRS(bool value); 01240 01241 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01242 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 01243 */ 01244 virtual void _setBL(bool value); 01245 01246 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01247 * Set the databus value (4 bit). 01248 */ 01249 virtual void _setData(int value); 01250 01251 /** Low level writes to LCD serial bus only (serial native) 01252 */ 01253 virtual void _writeByte(int value); 01254 01255 // SPI bus 01256 SPI *_spi; 01257 DigitalOut _cs; 01258 01259 // controlbyte to select between data and command. Internal shadow value for serial bus only 01260 char _controlbyte; 01261 01262 //Backlight 01263 DigitalOut *_bl; 01264 }; 01265 #endif /* Native SPI bus */ 01266 //-------- End TextLCD_SPI_N_3_16 ---------- 01267 01268 01269 //------- Start TextLCD_SPI_N_3_24 --------- 01270 #if(LCD_SPI_N_3_24 == 1) /* Native SPI bus */ 01271 01272 /** Create a TextLCD interface using a controller with native SPI3 24 bits interface 01273 * Note: lib uses SPI 8 bit mode 01274 * 01275 */ 01276 class TextLCD_SPI_N_3_24 : public TextLCD_Base { 01277 public: 01278 /** Create a TextLCD interface using a controller with native SPI3 24 bits interface 01279 * Note: lib uses SPI 8 bit mode 01280 * 01281 * @param spi SPI Bus 01282 * @param cs chip select pin (active low) 01283 * @param type Sets the panel size/addressing mode (default = LCD16x2) 01284 * @param bl Backlight control line (optional, default = NC) 01285 * @param ctrl LCD controller (default = SSD1803) 01286 */ 01287 TextLCD_SPI_N_3_24(SPI *spi, PinName cs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = SSD1803_3V3); 01288 01289 /** Destruct a TextLCD interface using a controller with native SPI3_24 interface 01290 */ 01291 virtual ~TextLCD_SPI_N_3_24(void); 01292 01293 private: 01294 01295 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01296 * Set the Enable pin. 01297 */ 01298 virtual void _setEnable(bool value); 01299 01300 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01301 * Set the RS pin (0 = Command, 1 = Data). 01302 */ 01303 virtual void _setRS(bool value); 01304 01305 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01306 * Set the BL pin (0 = Backlight Off, 1 = Backlight On). 01307 */ 01308 virtual void _setBL(bool value); 01309 01310 /** Implementation of pure Virtual Low level writes to LCD Bus (serial native) 01311 * Set the databus value (4 bit). 01312 */ 01313 virtual void _setData(int value); 01314 01315 /** Low level writes to LCD serial bus only (serial native) 01316 */ 01317 virtual void _writeByte(int value); 01318 01319 // SPI bus 01320 SPI *_spi; 01321 DigitalOut _cs; 01322 01323 // controlbyte to select between data and command. Internal value for serial bus only 01324 char _controlbyte; 01325 01326 //Backlight 01327 DigitalOut *_bl; 01328 }; 01329 #endif /* Native SPI bus */ 01330 //-------- End TextLCD_SPI_N_3_24 ---------- 01331 01332 01333 #endif
Generated on Tue Jul 12 2022 20:21:52 by
1.7.2
