Wim Huiskamp / TextLCD

Dependents:   Projeto_CCM_Maquinas_MotorPasso Projeto_CCM_Maquinas_MotorDC

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