In TextLCD_I2C_N Class, added void setContrast(unsigned char c) function as temporary. This is for ST7032i non-volume type contrast control.

Dependents:   LPC1114_data_logger RTC_w_COM Frequency_Counter_w_GPS_1PPS CW_Decoder_using_FFT_on_F446 ... more

Fork of TextLCD by Wim Huiskamp

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TextLCD.h Source File

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