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