add UTF-8 recode support, Cyrilic rus/ukr tables
Fork of TextLCD by
TextLCD Library UTF-8 recode support, Cyrilic rus/ukr tables
TextLCD.cpp@34:e5a0dcb43ecc, 2014-09-27 (annotated)
- Committer:
- wim
- Date:
- Sat Sep 27 12:38:27 2014 +0000
- Revision:
- 34:e5a0dcb43ecc
- Parent:
- 33:900a94bc7585
- Child:
- 35:311be6444a39
Added support for PT6314 (VFD), added setOrient() method for supported devices (eg SSD1803, US2066), added Double Height lines and 16 UDCs for supported devices. Added separate files for UDC defines and feature/footprint configuration.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 1:ac48b187213c | 1 | /* mbed TextLCD Library, for a 4-bit LCD based on HD44780 |
simon | 6:e4cb7ddee0d3 | 2 | * Copyright (c) 2007-2010, sford, http://mbed.org |
wim | 14:0c32b66b14b8 | 3 | * 2013, v01: WH, Added LCD types, fixed LCD address issues, added Cursor and UDCs |
wim | 14:0c32b66b14b8 | 4 | * 2013, v02: WH, Added I2C and SPI bus interfaces |
wim | 15:b70ebfffb258 | 5 | * 2013, v03: WH, Added support for LCD40x4 which uses 2 controllers |
wim | 18:bd65dc10f27f | 6 | * 2013, v04: WH, Added support for Display On/Off, improved 4bit bootprocess |
wim | 18:bd65dc10f27f | 7 | * 2013, v05: WH, Added support for 8x2B, added some UDCs |
wim | 19:c747b9e2e7b8 | 8 | * 2013, v06: WH, Added support for devices that use internal DC/DC converters |
wim | 20:e0da005a777f | 9 | * 2013, v07: WH, Added support for backlight and include portdefinitions for LCD2004 Module from DFROBOT |
wim | 22:35742ec80c24 | 10 | * 2014, v08: WH, Refactored in Base and Derived Classes to deal with mbed lib change regarding 'NC' defined pins |
wim | 25:6162b31128c9 | 11 | * 2014, v09: WH/EO, Added Class for Native SPI controllers such as ST7032 |
wim | 26:bd897a001012 | 12 | * 2014, v10: WH, Added Class for Native I2C controllers such as ST7032i, Added support for MCP23008 I2C portexpander, Added support for Adafruit module |
wim | 30:033048611c01 | 13 | * 2014, v11: WH, Added support for native I2C controllers such as PCF21XX, Improved the _initCtrl() method to deal with differences between all supported controllers |
wim | 32:59c4b8f648d4 | 14 | * 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) |
wim | 34:e5a0dcb43ecc | 15 | * 2014, v13: WH, Added support for controllers US2066/SSD1311 (OLED), added setUDCBlink() method for supported devices (eg SSD1803), fixed issue in setPower() |
wim | 34:e5a0dcb43ecc | 16 | * 2014, v14: WH, Added support for PT6314 (VFD), added setOrient() method for supported devices (eg SSD1803, US2066), added Double Height lines for supported devices, |
wim | 34:e5a0dcb43ecc | 17 | * added 16 UDCs for supported devices (eg PCF2103), moved UDC defines to TextLCD_UDC file, added TextLCD_Config.h for feature and footprint settings. |
simon | 1:ac48b187213c | 18 | * |
simon | 1:ac48b187213c | 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
simon | 1:ac48b187213c | 20 | * of this software and associated documentation files (the "Software"), to deal |
simon | 1:ac48b187213c | 21 | * in the Software without restriction, including without limitation the rights |
simon | 1:ac48b187213c | 22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
simon | 1:ac48b187213c | 23 | * copies of the Software, and to permit persons to whom the Software is |
simon | 1:ac48b187213c | 24 | * furnished to do so, subject to the following conditions: |
simon | 1:ac48b187213c | 25 | * |
simon | 1:ac48b187213c | 26 | * The above copyright notice and this permission notice shall be included in |
simon | 1:ac48b187213c | 27 | * all copies or substantial portions of the Software. |
simon | 1:ac48b187213c | 28 | * |
simon | 1:ac48b187213c | 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
simon | 1:ac48b187213c | 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
simon | 1:ac48b187213c | 31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
simon | 1:ac48b187213c | 32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
simon | 1:ac48b187213c | 33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
simon | 1:ac48b187213c | 34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
simon | 1:ac48b187213c | 35 | * THE SOFTWARE. |
simon | 1:ac48b187213c | 36 | */ |
wim | 34:e5a0dcb43ecc | 37 | #include "mbed.h" |
simon | 1:ac48b187213c | 38 | #include "TextLCD.h" |
wim | 34:e5a0dcb43ecc | 39 | #include "TextLCD_UDC.inc" |
wim | 34:e5a0dcb43ecc | 40 | |
wim | 21:9eb628d9e164 | 41 | /** Create a TextLCD_Base interface |
wim | 15:b70ebfffb258 | 42 | * |
wim | 21:9eb628d9e164 | 43 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 21:9eb628d9e164 | 44 | * @param ctrl LCD controller (default = HD44780) |
wim | 15:b70ebfffb258 | 45 | */ |
wim | 21:9eb628d9e164 | 46 | TextLCD_Base::TextLCD_Base(LCDType type, LCDCtrl ctrl) : _type(type), _ctrl(ctrl) { |
wim | 30:033048611c01 | 47 | |
wim | 30:033048611c01 | 48 | // Extract LCDType data |
wim | 30:033048611c01 | 49 | |
wim | 30:033048611c01 | 50 | // Columns encoded in b7..b0 |
wim | 30:033048611c01 | 51 | _nr_cols = (_type & 0xFF); |
wim | 30:033048611c01 | 52 | |
wim | 30:033048611c01 | 53 | // Rows encoded in b15..b8 |
wim | 30:033048611c01 | 54 | _nr_rows = ((_type >> 8) & 0xFF); |
wim | 30:033048611c01 | 55 | |
wim | 30:033048611c01 | 56 | // Addressing mode encoded in b19..b16 |
wim | 30:033048611c01 | 57 | _addr_mode = _type & LCD_T_ADR_MSK; |
wim | 14:0c32b66b14b8 | 58 | } |
wim | 14:0c32b66b14b8 | 59 | |
wim | 14:0c32b66b14b8 | 60 | |
wim | 21:9eb628d9e164 | 61 | /** Init the LCD Controller(s) |
wim | 21:9eb628d9e164 | 62 | * Clear display |
wim | 21:9eb628d9e164 | 63 | */ |
wim | 21:9eb628d9e164 | 64 | void TextLCD_Base::_init() { |
wim | 15:b70ebfffb258 | 65 | |
wim | 15:b70ebfffb258 | 66 | // Select and configure second LCD controller when needed |
wim | 15:b70ebfffb258 | 67 | if(_type==LCD40x4) { |
wim | 30:033048611c01 | 68 | _ctrl_idx=_LCDCtrl_1; // Select 2nd controller |
wim | 30:033048611c01 | 69 | _initCtrl(); // Init 2nd controller |
wim | 15:b70ebfffb258 | 70 | } |
wim | 15:b70ebfffb258 | 71 | |
wim | 15:b70ebfffb258 | 72 | // Select and configure primary LCD controller |
wim | 27:22d5086f6ba6 | 73 | _ctrl_idx=_LCDCtrl_0; // Select primary controller |
wim | 19:c747b9e2e7b8 | 74 | _initCtrl(); // Init primary controller |
wim | 28:30fa94f7341c | 75 | |
wim | 32:59c4b8f648d4 | 76 | // Clear whole display and Reset Cursor location |
wim | 32:59c4b8f648d4 | 77 | // Note: This will make sure that some 3-line displays that skip topline of a 4-line configuration |
wim | 32:59c4b8f648d4 | 78 | // are cleared and init cursor correctly. |
wim | 32:59c4b8f648d4 | 79 | cls(); |
wim | 15:b70ebfffb258 | 80 | } |
wim | 15:b70ebfffb258 | 81 | |
wim | 21:9eb628d9e164 | 82 | /** Init the LCD controller |
wim | 21:9eb628d9e164 | 83 | * 4-bit mode, number of lines, fonttype, no cursor etc |
wim | 30:033048611c01 | 84 | * |
wim | 30:033048611c01 | 85 | * Note: some configurations are commented out because they have not yet been tested due to lack of hardware |
wim | 21:9eb628d9e164 | 86 | */ |
wim | 21:9eb628d9e164 | 87 | void TextLCD_Base::_initCtrl() { |
wim | 32:59c4b8f648d4 | 88 | int _bias_lines=0; // Set Bias and lines (Instr Set 1), temporary variable. |
wim | 32:59c4b8f648d4 | 89 | int _lines=0; // Set lines (Ext Instr Set), temporary variable. |
wim | 32:59c4b8f648d4 | 90 | |
wim | 26:bd897a001012 | 91 | this->_setRS(false); // command mode |
wim | 13:24506ba22480 | 92 | |
wim | 26:bd897a001012 | 93 | wait_ms(20); // Wait 20ms to ensure powered up |
simon | 1:ac48b187213c | 94 | |
wim | 33:900a94bc7585 | 95 | // The Controller could be in 8 bit mode (power-on reset) or in 4 bit mode (warm reboot) at this point. |
wim | 33:900a94bc7585 | 96 | // Follow this procedure to make sure the Controller enters the correct state. The hardware interface |
wim | 33:900a94bc7585 | 97 | // between the uP and the LCD can only write the 4 most significant bits (Most Significant Nibble, MSN). |
wim | 33:900a94bc7585 | 98 | // In 4 bit mode the LCD expects the MSN first, followed by the LSN. |
wim | 33:900a94bc7585 | 99 | // |
wim | 33:900a94bc7585 | 100 | // Current state: 8 bit mode | 4 bit mode, MSN is next | 4 bit mode, LSN is next |
wim | 33:900a94bc7585 | 101 | //------------------------------------------------------------------------------------------------- |
wim | 33:900a94bc7585 | 102 | _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set 8 bit mode (MSN), | set dummy LSN, |
wim | 33:900a94bc7585 | 103 | // remains in 8 bit mode | change to 8 bit mode | remains in 4 bit mode |
wim | 33:900a94bc7585 | 104 | wait_ms(15); // |
wim | 33:900a94bc7585 | 105 | |
wim | 33:900a94bc7585 | 106 | _writeNibble(0x3); // set 8 bit mode and dummy LSN, | set 8 bit mode and dummy LSN, | set 8bit mode (MSN), |
wim | 33:900a94bc7585 | 107 | // remains in 8 bit mode | remains in 8 bit mode | remains in 4 bit mode |
wim | 33:900a94bc7585 | 108 | wait_ms(15); // |
wim | 33:900a94bc7585 | 109 | |
wim | 33:900a94bc7585 | 110 | _writeNibble(0x3); // set 8 bit mode and dummy LSN, | set 8 bit mode and dummy LSN, | set dummy LSN, |
wim | 33:900a94bc7585 | 111 | // remains in 8 bit mode | remains in 8 bit mode | change to 8 bit mode |
wim | 33:900a94bc7585 | 112 | wait_ms(15); // |
wim | 33:900a94bc7585 | 113 | |
wim | 33:900a94bc7585 | 114 | // Controller is now in 8 bit mode |
wim | 33:900a94bc7585 | 115 | |
wim | 33:900a94bc7585 | 116 | _writeNibble(0x2); // Change to 4-bit mode (MSN), the LSN is undefined dummy |
wim | 17:652ab113bc2e | 117 | wait_us(40); // most instructions take 40us |
wim | 18:bd65dc10f27f | 118 | |
wim | 18:bd65dc10f27f | 119 | // Display is now in 4-bit mode |
wim | 33:900a94bc7585 | 120 | // Note: 4/8 bit mode is ignored for most native SPI and I2C devices. They dont use the parallel bus. |
wim | 33:900a94bc7585 | 121 | // However, _writeNibble() method is void anyway for native SPI and I2C devices. |
wim | 25:6162b31128c9 | 122 | |
wim | 29:a3663151aa65 | 123 | // Device specific initialisations: DC/DC converter to generate VLCD or VLED, number of lines etc |
wim | 19:c747b9e2e7b8 | 124 | switch (_ctrl) { |
wim | 32:59c4b8f648d4 | 125 | |
wim | 29:a3663151aa65 | 126 | case KS0078: |
wim | 29:a3663151aa65 | 127 | // Initialise Display configuration |
wim | 29:a3663151aa65 | 128 | switch (_type) { |
wim | 29:a3663151aa65 | 129 | case LCD8x1: //8x1 is a regular 1 line display |
wim | 29:a3663151aa65 | 130 | case LCD8x2B: //8x2B is a special case of 16x1 |
wim | 29:a3663151aa65 | 131 | // case LCD12x1: |
wim | 29:a3663151aa65 | 132 | case LCD16x1: |
wim | 30:033048611c01 | 133 | // case LCD20x1: |
wim | 29:a3663151aa65 | 134 | case LCD24x1: |
wim | 32:59c4b8f648d4 | 135 | _function = 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs) |
wim | 32:59c4b8f648d4 | 136 | // DL=0 (4 bits bus) |
wim | 32:59c4b8f648d4 | 137 | // N=0 (1 line mode), N=1 (2 line mode) |
wim | 32:59c4b8f648d4 | 138 | // RE=0 (Dis. Extended Regs, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 139 | // DH=1 (Disp shift enable, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 140 | // REV=0 (Reverse normal, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 141 | |
wim | 33:900a94bc7585 | 142 | _function_1 = 0x04; // Function set 001 DL N RE(1) BE 0 (Ext Regs) |
wim | 32:59c4b8f648d4 | 143 | // DL=0 (4 bits bus) |
wim | 32:59c4b8f648d4 | 144 | // N=0 (1 line mode), N=1 (2 line mode) |
wim | 32:59c4b8f648d4 | 145 | // RE=1 (Ena Extended Regs, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 146 | // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 147 | // 0 |
wim | 30:033048611c01 | 148 | |
wim | 32:59c4b8f648d4 | 149 | _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs) |
wim | 32:59c4b8f648d4 | 150 | // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078) |
wim | 29:a3663151aa65 | 151 | break; |
wim | 29:a3663151aa65 | 152 | |
wim | 32:59c4b8f648d4 | 153 | // case LCD12x3D: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 154 | // case LCD12x3D1: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 155 | // case LCD12x4D: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 156 | // case LCD16x3D: // Special mode for KS0078 |
wim | 32:59c4b8f648d4 | 157 | // case LCD16x4D: // Special mode for KS0078 |
wim | 30:033048611c01 | 158 | // case LCD24x3D: // Special mode for KS0078 |
wim | 30:033048611c01 | 159 | // case LCD24x3D1: // Special mode for KS0078 |
wim | 30:033048611c01 | 160 | case LCD24x4D: // Special mode for KS0078 |
wim | 32:59c4b8f648d4 | 161 | _function = 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs) |
wim | 32:59c4b8f648d4 | 162 | // DL=0 (4 bits bus) |
wim | 32:59c4b8f648d4 | 163 | // N=0 (dont care for 4 line mode) |
wim | 32:59c4b8f648d4 | 164 | // RE=0 (Dis. Extended Regs, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 165 | // DH=1 (Disp shift enable, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 166 | // REV=0 (Reverse normal, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 167 | |
wim | 33:900a94bc7585 | 168 | _function_1 = 0x04; // Function set 001 DL N RE(1) BE 0 (Ext Regs) |
wim | 32:59c4b8f648d4 | 169 | // DL=0 (4 bits bus) |
wim | 32:59c4b8f648d4 | 170 | // N=0 (1 line mode), N=1 (2 line mode) |
wim | 32:59c4b8f648d4 | 171 | // RE=1 (Ena Extended Regs, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 172 | // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 173 | // 0 |
wim | 29:a3663151aa65 | 174 | |
wim | 32:59c4b8f648d4 | 175 | _function_x = 0x01; // Ext Function set 0000 1 FW BW NW (Ext Regs) |
wim | 32:59c4b8f648d4 | 176 | // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078) |
wim | 30:033048611c01 | 177 | break; |
wim | 33:900a94bc7585 | 178 | |
wim | 33:900a94bc7585 | 179 | case LCD16x3G: // Special mode for ST7036 |
wim | 33:900a94bc7585 | 180 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 33:900a94bc7585 | 181 | break; |
wim | 30:033048611c01 | 182 | |
wim | 29:a3663151aa65 | 183 | default: |
wim | 30:033048611c01 | 184 | // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4) |
wim | 32:59c4b8f648d4 | 185 | _function = 0x0A; // Function set 001 DL N RE(0) DH REV (Std Regs) |
wim | 32:59c4b8f648d4 | 186 | // DL=0 (4 bits bus) |
wim | 32:59c4b8f648d4 | 187 | // N=1 (1 line mode), N=1 (2 line mode) |
wim | 32:59c4b8f648d4 | 188 | // RE=0 (Dis. Extended Regs, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 189 | // DH=1 (Disp shift enable, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 190 | // REV=0 (Reverse normal, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 191 | |
wim | 33:900a94bc7585 | 192 | _function_1 = 0x0C; // Function set 001 DL N RE(1) BE 0 (Ext Regs) |
wim | 32:59c4b8f648d4 | 193 | // DL=0 (4 bits bus) |
wim | 32:59c4b8f648d4 | 194 | // N=1 (1 line mode), N=1 (2 line mode) |
wim | 32:59c4b8f648d4 | 195 | // RE=1 (Ena Extended Regs, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 196 | // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 197 | // 0 |
wim | 30:033048611c01 | 198 | |
wim | 32:59c4b8f648d4 | 199 | _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs) |
wim | 32:59c4b8f648d4 | 200 | // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078) |
wim | 29:a3663151aa65 | 201 | break; |
wim | 29:a3663151aa65 | 202 | } // switch type |
wim | 29:a3663151aa65 | 203 | |
wim | 32:59c4b8f648d4 | 204 | // init special features |
wim | 32:59c4b8f648d4 | 205 | _writeCommand(0x20 | _function_1);// Function set 001 DL N RE(1) BE 0 (Ext Regs) |
wim | 32:59c4b8f648d4 | 206 | // DL=0 (4 bits bus), DL=1 (8 bits mode) |
wim | 32:59c4b8f648d4 | 207 | // N=0 (1 line mode), N=1 (2 line mode) |
wim | 32:59c4b8f648d4 | 208 | // RE=1 (Ena Extended Regs, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 209 | // BE=0 (Blink Enable/Disable, CG/SEG RAM, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 210 | // 0 |
wim | 32:59c4b8f648d4 | 211 | |
wim | 32:59c4b8f648d4 | 212 | _writeCommand(0x08 | _function_x); // Ext Function set 0000 1 FW BW NW (Ext Regs) |
wim | 32:59c4b8f648d4 | 213 | // FW=0 (5-dot font, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 214 | // BW=0 (Cur BW invert disable, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 215 | // NW=0 (1,2 Line), NW=1 (4 line, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 216 | |
wim | 32:59c4b8f648d4 | 217 | _writeCommand(0x10); // Scroll/Shift set 0001 DS/HS4 DS/HS3 DS/HS2 DS/HS1 (Ext Regs) |
wim | 32:59c4b8f648d4 | 218 | // Dotscroll/Display shift enable (Special mode for KS0078) |
wim | 32:59c4b8f648d4 | 219 | |
wim | 32:59c4b8f648d4 | 220 | _writeCommand(0x80); // Scroll Quantity set 1 0 SQ5 SQ4 SQ3 SQ2 SQ1 SQ0 (Ext Regs) |
wim | 32:59c4b8f648d4 | 221 | // Scroll quantity (Special mode for KS0078) |
wim | 32:59c4b8f648d4 | 222 | |
wim | 32:59c4b8f648d4 | 223 | _writeCommand(0x20 | _function); // Function set 001 DL N RE(0) DH REV (Std Regs) |
wim | 32:59c4b8f648d4 | 224 | // DL=0 (4 bits bus), DL=1 (8 bits mode) |
wim | 32:59c4b8f648d4 | 225 | // N=0 (1 line mode), N=1 (2 line mode) |
wim | 32:59c4b8f648d4 | 226 | // RE=0 (Dis. Extended Regs, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 227 | // DH=1 (Disp shift enable/disable, special mode for KS0078) |
wim | 32:59c4b8f648d4 | 228 | // REV=0 (Reverse/Normal, special mode for KS0078) |
wim | 29:a3663151aa65 | 229 | break; // case KS0078 Controller |
wim | 29:a3663151aa65 | 230 | |
wim | 26:bd897a001012 | 231 | case ST7032_3V3: |
wim | 26:bd897a001012 | 232 | // ST7032 controller: Initialise Voltage booster for VLCD. VDD=3V3 |
wim | 26:bd897a001012 | 233 | case ST7032_5V: |
wim | 32:59c4b8f648d4 | 234 | // ST7032 controller: Disable Voltage booster for VLCD. VDD=5V |
wim | 29:a3663151aa65 | 235 | |
wim | 29:a3663151aa65 | 236 | // Initialise Display configuration |
wim | 29:a3663151aa65 | 237 | switch (_type) { |
wim | 29:a3663151aa65 | 238 | case LCD8x1: //8x1 is a regular 1 line display |
wim | 29:a3663151aa65 | 239 | case LCD8x2B: //8x2B is a special case of 16x1 |
wim | 29:a3663151aa65 | 240 | // case LCD12x1: |
wim | 29:a3663151aa65 | 241 | case LCD16x1: |
wim | 30:033048611c01 | 242 | // case LCD20x1: |
wim | 32:59c4b8f648d4 | 243 | case LCD24x1: |
wim | 32:59c4b8f648d4 | 244 | _function = 0x00; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=0 (1-line display mode), F=0 (5*7dot), 0, IS |
wim | 32:59c4b8f648d4 | 245 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 246 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 247 | break; |
wim | 28:30fa94f7341c | 248 | |
wim | 32:59c4b8f648d4 | 249 | case LCD12x3D: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 250 | case LCD12x3D1: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 251 | case LCD12x4D: // Special mode for KS0078 and PCF21XX |
wim | 33:900a94bc7585 | 252 | case LCD16x3G: // Special mode for ST7036 |
wim | 32:59c4b8f648d4 | 253 | case LCD24x4D: // Special mode for KS0078 |
wim | 32:59c4b8f648d4 | 254 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 30:033048611c01 | 255 | break; |
wim | 29:a3663151aa65 | 256 | |
wim | 32:59c4b8f648d4 | 257 | default: |
wim | 32:59c4b8f648d4 | 258 | // All other LCD types are initialised as 2 Line displays |
wim | 32:59c4b8f648d4 | 259 | _function = 0x08; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=1 (2-line display mode), F=0 (5*7dot), 0, IS |
wim | 32:59c4b8f648d4 | 260 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 261 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 262 | break; |
wim | 32:59c4b8f648d4 | 263 | } // switch type |
wim | 32:59c4b8f648d4 | 264 | |
wim | 32:59c4b8f648d4 | 265 | // init special features |
wim | 33:900a94bc7585 | 266 | _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1 |
wim | 33:900a94bc7585 | 267 | |
wim | 33:900a94bc7585 | 268 | _writeCommand(0x1C); // Internal OSC frequency adjustment Framefreq=183HZ, Bias will be 1/4 (Instr Set=1) |
wim | 32:59c4b8f648d4 | 269 | |
wim | 32:59c4b8f648d4 | 270 | _contrast = LCD_ST7032_CONTRAST; |
wim | 32:59c4b8f648d4 | 271 | _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast Low bits, 0 1 1 1 C3 C2 C1 C0 (IS=1) |
wim | 32:59c4b8f648d4 | 272 | |
wim | 32:59c4b8f648d4 | 273 | |
wim | 32:59c4b8f648d4 | 274 | if (_ctrl == ST7032_3V3) { |
wim | 32:59c4b8f648d4 | 275 | _icon_power = 0x04; // Icon display off, Booster circuit is turned on (IS=1) |
wim | 32:59c4b8f648d4 | 276 | // Saved to allow contrast change at later time |
wim | 32:59c4b8f648d4 | 277 | } |
wim | 32:59c4b8f648d4 | 278 | else { |
wim | 32:59c4b8f648d4 | 279 | _icon_power = 0x00; // Icon display off, Booster circuit is turned off (IS=1) |
wim | 32:59c4b8f648d4 | 280 | // Saved to allow contrast change at later time |
wim | 32:59c4b8f648d4 | 281 | } |
wim | 32:59c4b8f648d4 | 282 | _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Set Icon, Booster and Contrast High bits, 0 1 0 1 Ion Bon C5 C4 (IS=1) |
wim | 32:59c4b8f648d4 | 283 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 284 | |
wim | 32:59c4b8f648d4 | 285 | _writeCommand(0x68 | (LCD_ST7032_RAB & 0x07)); // Voltage follower, 0 1 1 0 FOn=1, Ampl ratio Rab2=1, Rab1=0, Rab0=0 (IS=1) |
wim | 32:59c4b8f648d4 | 286 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 287 | |
wim | 32:59c4b8f648d4 | 288 | _writeCommand(0x20 | _function); // Select Instruction Set = 0 |
wim | 32:59c4b8f648d4 | 289 | |
wim | 32:59c4b8f648d4 | 290 | break; // case ST7032_3V3 Controller |
wim | 32:59c4b8f648d4 | 291 | // case ST7032_5V Controller |
wim | 32:59c4b8f648d4 | 292 | |
wim | 32:59c4b8f648d4 | 293 | case ST7036_3V3: |
wim | 32:59c4b8f648d4 | 294 | // ST7036 controller: Initialise Voltage booster for VLCD. VDD=3V3 |
wim | 32:59c4b8f648d4 | 295 | // Note: supports 1,2 (LCD_T_A) or 3 lines (LCD_T_G) |
wim | 32:59c4b8f648d4 | 296 | case ST7036_5V: |
wim | 32:59c4b8f648d4 | 297 | // ST7036 controller: Disable Voltage booster for VLCD. VDD=5V |
wim | 32:59c4b8f648d4 | 298 | // Note: supports 1,2 (LCD_T_A) or 3 lines (LCD_T_G) |
wim | 32:59c4b8f648d4 | 299 | |
wim | 32:59c4b8f648d4 | 300 | // Initialise Display configuration |
wim | 32:59c4b8f648d4 | 301 | switch (_type) { |
wim | 32:59c4b8f648d4 | 302 | case LCD8x1: //8x1 is a regular 1 line display |
wim | 32:59c4b8f648d4 | 303 | case LCD8x2B: //8x2D is a special case of 16x1 |
wim | 32:59c4b8f648d4 | 304 | // case LCD12x1: |
wim | 32:59c4b8f648d4 | 305 | case LCD16x1: |
wim | 32:59c4b8f648d4 | 306 | case LCD24x1: |
wim | 32:59c4b8f648d4 | 307 | _function = 0x00; // Set function, 0 0 1 DL=0 (4-bit Databus), N=0 (1 Line), DH=0 (5x7font), IS2, IS1 (Select Instruction Set) |
wim | 32:59c4b8f648d4 | 308 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 309 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 310 | |
wim | 32:59c4b8f648d4 | 311 | _bias_lines = 0x04; // Bias: 1/5, 1 or 2-Lines LCD |
wim | 32:59c4b8f648d4 | 312 | break; |
wim | 32:59c4b8f648d4 | 313 | |
wim | 32:59c4b8f648d4 | 314 | // case LCD12x3G: // Special mode for ST7036 |
wim | 32:59c4b8f648d4 | 315 | case LCD16x3G: // Special mode for ST7036 |
wim | 32:59c4b8f648d4 | 316 | _function = 0x08; // Set function, 0 0 1 DL=0 (4-bit Databus), N=1 (2 Line), DH=0 (5x7font), IS2,IS1 (Select Instruction Set) |
wim | 32:59c4b8f648d4 | 317 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 318 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 319 | |
wim | 32:59c4b8f648d4 | 320 | _bias_lines = 0x05; // Bias: 1/5, 3-Lines LCD |
wim | 32:59c4b8f648d4 | 321 | break; |
wim | 32:59c4b8f648d4 | 322 | |
wim | 32:59c4b8f648d4 | 323 | // case LCD12x3D1: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 324 | // case LCD16x3D1: // Special mode for SSD1803 |
wim | 30:033048611c01 | 325 | case LCD12x4D: // Special mode for PCF2116 |
wim | 30:033048611c01 | 326 | case LCD24x4D: // Special mode for KS0078 |
wim | 30:033048611c01 | 327 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 29:a3663151aa65 | 328 | break; |
wim | 28:30fa94f7341c | 329 | |
wim | 29:a3663151aa65 | 330 | default: |
wim | 32:59c4b8f648d4 | 331 | // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4) |
wim | 32:59c4b8f648d4 | 332 | _function = 0x08; // Set function, 0 0 1 DL=0 (4-bit Databus), N=1 (2 Line), DH=0 (5x7font), IS2,IS1 (Select Instruction Set) |
wim | 32:59c4b8f648d4 | 333 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 334 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 335 | |
wim | 32:59c4b8f648d4 | 336 | _bias_lines = 0x04; // Bias: 1/5, 1 or 2-Lines LCD |
wim | 32:59c4b8f648d4 | 337 | break; |
wim | 32:59c4b8f648d4 | 338 | } // switch type |
wim | 32:59c4b8f648d4 | 339 | |
wim | 29:a3663151aa65 | 340 | |
wim | 32:59c4b8f648d4 | 341 | // init special features |
wim | 33:900a94bc7585 | 342 | _writeCommand(0x20 | _function | 0x01); // Set function, IS2,IS1 = 01 (Select Instr Set = 1) |
wim | 32:59c4b8f648d4 | 343 | _writeCommand(0x10 | _bias_lines); // Set Bias and 1,2 or 3 lines (Instr Set 1) |
wim | 29:a3663151aa65 | 344 | |
wim | 32:59c4b8f648d4 | 345 | _contrast = LCD_ST7036_CONTRAST; |
wim | 32:59c4b8f648d4 | 346 | _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast, 0 1 1 1 C3 C2 C1 C0 (Instr Set 1) |
wim | 32:59c4b8f648d4 | 347 | |
wim | 32:59c4b8f648d4 | 348 | if (_ctrl == ST7036_3V3) { |
wim | 32:59c4b8f648d4 | 349 | _icon_power = 0x04; // Set Icon, Booster, Contrast High bits, 0 1 0 1 Ion=0 Bon=1 C5 C4 (Instr Set 1) |
wim | 32:59c4b8f648d4 | 350 | // Saved to allow contrast change at later time |
wim | 32:59c4b8f648d4 | 351 | } |
wim | 32:59c4b8f648d4 | 352 | else { |
wim | 32:59c4b8f648d4 | 353 | _icon_power = 0x00; // Set Icon, Booster, Contrast High bits, 0 1 0 1 Ion=0 Bon=0 C5 C4 (Instr Set 1) |
wim | 32:59c4b8f648d4 | 354 | } |
wim | 29:a3663151aa65 | 355 | |
wim | 32:59c4b8f648d4 | 356 | _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Set Contrast C5, C4 (Instr Set 1) |
wim | 32:59c4b8f648d4 | 357 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 358 | |
wim | 32:59c4b8f648d4 | 359 | _writeCommand(0x68 | (LCD_ST7036_RAB & 0x07)); // Voltagefollower On = 1, Ampl ratio Rab2, Rab1, Rab0 = 1 0 1 (Instr Set 1) |
wim | 32:59c4b8f648d4 | 360 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 28:30fa94f7341c | 361 | |
wim | 32:59c4b8f648d4 | 362 | _writeCommand(0x20 | _function); // Set function, IS2,IS1 = 00 (Select Instruction Set = 0) |
wim | 32:59c4b8f648d4 | 363 | |
wim | 32:59c4b8f648d4 | 364 | break; // case ST7036_3V3 Controller |
wim | 32:59c4b8f648d4 | 365 | // case ST7036_5V Controller |
wim | 32:59c4b8f648d4 | 366 | |
wim | 32:59c4b8f648d4 | 367 | case SSD1803_3V3: |
wim | 32:59c4b8f648d4 | 368 | // SSD1803 controller: Initialise Voltage booster for VLCD. VDD=3V3 |
wim | 32:59c4b8f648d4 | 369 | // Note: supports 1,2, 3 or 4 lines |
wim | 32:59c4b8f648d4 | 370 | // case SSD1803_5V: |
wim | 32:59c4b8f648d4 | 371 | // SSD1803 controller: No Voltage booster for VLCD. VDD=5V |
wim | 32:59c4b8f648d4 | 372 | |
wim | 29:a3663151aa65 | 373 | // Initialise Display configuration |
wim | 29:a3663151aa65 | 374 | switch (_type) { |
wim | 29:a3663151aa65 | 375 | case LCD8x1: //8x1 is a regular 1 line display |
wim | 30:033048611c01 | 376 | case LCD8x2B: //8x2D is a special case of 16x1 |
wim | 29:a3663151aa65 | 377 | // case LCD12x1: |
wim | 29:a3663151aa65 | 378 | case LCD16x1: |
wim | 29:a3663151aa65 | 379 | case LCD24x1: |
wim | 32:59c4b8f648d4 | 380 | _function = 0x00; // Set function 0 0 1 DL N DH RE(0) IS |
wim | 32:59c4b8f648d4 | 381 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 382 | // DL=0 4-bit Databus, |
wim | 32:59c4b8f648d4 | 383 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 384 | // N=0 1 Line / 3 Line |
wim | 32:59c4b8f648d4 | 385 | // DH=0 Double Height disable |
wim | 32:59c4b8f648d4 | 386 | // IS=0 |
wim | 32:59c4b8f648d4 | 387 | |
wim | 33:900a94bc7585 | 388 | _function_1 = 0x02; // Set function, 0 0 1 DL N BE RE(1) REV |
wim | 32:59c4b8f648d4 | 389 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 390 | // DL=0 4-bit Databus, |
wim | 32:59c4b8f648d4 | 391 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 392 | // N=0 1 Line / 3 Line |
wim | 32:59c4b8f648d4 | 393 | // BE=0 Blink Enable off, special feature of SSD1803 |
wim | 32:59c4b8f648d4 | 394 | // REV=0 Reverse off, special feature of SSD1803 |
wim | 32:59c4b8f648d4 | 395 | |
wim | 32:59c4b8f648d4 | 396 | _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW |
wim | 32:59c4b8f648d4 | 397 | // NW=0 1-Line LCD (N=0) |
wim | 29:a3663151aa65 | 398 | break; |
wim | 32:59c4b8f648d4 | 399 | |
wim | 33:900a94bc7585 | 400 | case LCD12x3D: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 401 | // case LCD12x3D1: // Special mode for KS0078 and PCF21XX |
wim | 33:900a94bc7585 | 402 | case LCD16x3D: // Special mode for KS0078 |
wim | 32:59c4b8f648d4 | 403 | // case LCD16x3D1: // Special mode for SSD1803 |
wim | 32:59c4b8f648d4 | 404 | // case LCD20x3D: // Special mode for SSD1803 |
wim | 32:59c4b8f648d4 | 405 | _function = 0x00; // Set function 0 0 1 DL N DH RE(0) IS |
wim | 32:59c4b8f648d4 | 406 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 407 | // DL=0 4-bit Databus, |
wim | 32:59c4b8f648d4 | 408 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 409 | // N=0 1 Line / 3 Line |
wim | 32:59c4b8f648d4 | 410 | // DH=0 Double Height disable |
wim | 32:59c4b8f648d4 | 411 | // IS=0 |
wim | 32:59c4b8f648d4 | 412 | |
wim | 33:900a94bc7585 | 413 | _function_1 = 0x02; // Set function, 0 0 1 DL N BE RE(1) REV |
wim | 32:59c4b8f648d4 | 414 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 415 | // DL=0 4-bit Databus, |
wim | 32:59c4b8f648d4 | 416 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 417 | // N=0 1 Line / 3 Line |
wim | 32:59c4b8f648d4 | 418 | // BE=0 Blink Enable off, special feature of SSD1803 |
wim | 32:59c4b8f648d4 | 419 | // REV=0 Reverse off, special feature of SSD1803 |
wim | 32:59c4b8f648d4 | 420 | |
wim | 32:59c4b8f648d4 | 421 | _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW |
wim | 32:59c4b8f648d4 | 422 | // NW=1 3-Line LCD (N=0) |
wim | 29:a3663151aa65 | 423 | break; |
wim | 30:033048611c01 | 424 | |
wim | 32:59c4b8f648d4 | 425 | case LCD20x4D: // Special mode for SSD1803 |
wim | 32:59c4b8f648d4 | 426 | _function = 0x08; // Set function 0 0 1 DL N DH RE(0) IS |
wim | 32:59c4b8f648d4 | 427 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 428 | // DL=0 4-bit Databus, |
wim | 32:59c4b8f648d4 | 429 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 430 | // N=1 4 Line |
wim | 32:59c4b8f648d4 | 431 | // DH=0 Double Height disable |
wim | 32:59c4b8f648d4 | 432 | // IS=0 |
wim | 32:59c4b8f648d4 | 433 | |
wim | 33:900a94bc7585 | 434 | _function_1 = 0x0A; // Set function, 0 0 1 DL N BE RE(1) REV |
wim | 32:59c4b8f648d4 | 435 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 436 | // DL=0 4-bit Databus, |
wim | 32:59c4b8f648d4 | 437 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 438 | // N=1 4 Line |
wim | 32:59c4b8f648d4 | 439 | // BE=0 Blink Enable off, special feature of SSD1803 |
wim | 32:59c4b8f648d4 | 440 | // REV=0 Reverse off, special feature of SSD1803 |
wim | 32:59c4b8f648d4 | 441 | |
wim | 32:59c4b8f648d4 | 442 | _lines = 0x01; // Ext function set 0 0 0 0 1 FW BW NW |
wim | 32:59c4b8f648d4 | 443 | // NW=1 4-Line LCD (N=1) |
wim | 32:59c4b8f648d4 | 444 | break; |
wim | 32:59c4b8f648d4 | 445 | |
wim | 33:900a94bc7585 | 446 | case LCD16x3G: // Special mode for ST7036 |
wim | 32:59c4b8f648d4 | 447 | case LCD24x4D: // Special mode for KS0078 |
wim | 30:033048611c01 | 448 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 30:033048611c01 | 449 | break; |
wim | 30:033048611c01 | 450 | |
wim | 29:a3663151aa65 | 451 | default: |
wim | 30:033048611c01 | 452 | // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4) |
wim | 32:59c4b8f648d4 | 453 | _function = 0x08; // Set function 0 0 1 DL N DH RE(0) IS |
wim | 32:59c4b8f648d4 | 454 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 455 | // DL=0 4-bit Databus, |
wim | 32:59c4b8f648d4 | 456 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 457 | // N=1 2 line / 4 Line |
wim | 32:59c4b8f648d4 | 458 | // DH=0 Double Height disable |
wim | 32:59c4b8f648d4 | 459 | // IS=0 |
wim | 29:a3663151aa65 | 460 | |
wim | 33:900a94bc7585 | 461 | _function_1 = 0x0A; // Set function, 0 0 1 DL N BE RE(1) REV |
wim | 32:59c4b8f648d4 | 462 | // Saved to allow switch between Instruction sets at later time |
wim | 32:59c4b8f648d4 | 463 | // DL=0 4-bit Databus, |
wim | 32:59c4b8f648d4 | 464 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 32:59c4b8f648d4 | 465 | // N=1 2 line / 4 Line |
wim | 32:59c4b8f648d4 | 466 | // BE=0 Blink Enable off, special feature of SSD1803 |
wim | 32:59c4b8f648d4 | 467 | // REV=0 Reverse off, special feature of SSD1803 |
wim | 32:59c4b8f648d4 | 468 | |
wim | 32:59c4b8f648d4 | 469 | _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW |
wim | 32:59c4b8f648d4 | 470 | // NW=0 2-Line LCD (N=1) |
wim | 32:59c4b8f648d4 | 471 | break; |
wim | 32:59c4b8f648d4 | 472 | } // switch type |
wim | 32:59c4b8f648d4 | 473 | |
wim | 32:59c4b8f648d4 | 474 | |
wim | 32:59c4b8f648d4 | 475 | // init special features |
wim | 33:900a94bc7585 | 476 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV |
wim | 32:59c4b8f648d4 | 477 | // Select Extended Instruction Set |
wim | 33:900a94bc7585 | 478 | |
wim | 33:900a94bc7585 | 479 | _writeCommand(0x06); // Set ext entry mode, 0 0 0 0 0 1 BDC=1 COM1-32, BDS=0 SEG100-1 "Bottom View" (Ext Instr Set) |
wim | 33:900a94bc7585 | 480 | // _writeCommand(0x05); // Set ext entry mode, 0 0 0 0 0 1 BDC=0 COM32-1, BDS=1 SEG1-100 "Top View" (Ext Instr Set) |
wim | 33:900a94bc7585 | 481 | wait_ms(5); // Wait to ensure completion or SSD1803 fails to set Top/Bottom after reset.. |
wim | 33:900a94bc7585 | 482 | |
wim | 33:900a94bc7585 | 483 | _writeCommand(0x08 | _lines); // Set ext function 0 0 0 0 1 FW BW NW 1,2,3 or 4 lines (Ext Instr Set) |
wim | 32:59c4b8f648d4 | 484 | |
wim | 32:59c4b8f648d4 | 485 | _writeCommand(0x10); // Double Height and Bias, 0 0 0 1 UD2=0, UD1=0, BS1=0 Bias 1/5, DH=0 (Ext Instr Set) |
wim | 32:59c4b8f648d4 | 486 | |
wim | 32:59c4b8f648d4 | 487 | // _writeCommand(0x76); // Set TC Control, 0 1 1 1 0 1 1 0 (Ext Instr Set) |
wim | 32:59c4b8f648d4 | 488 | // _writeData(0x02); // Set TC data, 0 0 0 0 0 TC2,TC1,TC0 = 0 1 0 (Ext Instr Set) |
wim | 32:59c4b8f648d4 | 489 | |
wim | 32:59c4b8f648d4 | 490 | _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N DH RE(0) IS=1 Select Instruction Set 1 |
wim | 32:59c4b8f648d4 | 491 | // Select Std Instr set, Select IS=1 |
wim | 32:59c4b8f648d4 | 492 | |
wim | 32:59c4b8f648d4 | 493 | _contrast = LCD_SSD1_CONTRAST; |
wim | 32:59c4b8f648d4 | 494 | _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast 0 1 1 1 C3, C2, C1, C0 (Instr Set 1) |
wim | 32:59c4b8f648d4 | 495 | |
wim | 32:59c4b8f648d4 | 496 | _icon_power = 0x04; // Icon off, Booster on (Instr Set 1) |
wim | 32:59c4b8f648d4 | 497 | // Saved to allow contrast change at later time |
wim | 32:59c4b8f648d4 | 498 | _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Set Power, Icon and Contrast, 0 1 0 1 Ion Bon C5 C4 (Instr Set 1) |
wim | 32:59c4b8f648d4 | 499 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 500 | |
wim | 32:59c4b8f648d4 | 501 | _writeCommand(0x68 | (LCD_SSD1_RAB & 0x07)); // Set Voltagefollower 0 1 1 0 Don = 1, Ampl ratio Rab2, Rab1, Rab0 = 1 1 0 (Instr Set 1) |
wim | 32:59c4b8f648d4 | 502 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 503 | |
wim | 33:900a94bc7585 | 504 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV |
wim | 32:59c4b8f648d4 | 505 | // Select Extended Instruction Set 1 |
wim | 32:59c4b8f648d4 | 506 | _writeCommand(0x10); // Shift/Scroll enable, 0 0 0 1 DS4/HS4 DS3/HS3 DS2/HS2 DS1/HS1 (Ext Instr Set 1) |
wim | 32:59c4b8f648d4 | 507 | |
wim | 32:59c4b8f648d4 | 508 | |
wim | 32:59c4b8f648d4 | 509 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 32:59c4b8f648d4 | 510 | // Select Std Instr set, Select IS=0 |
wim | 32:59c4b8f648d4 | 511 | |
wim | 32:59c4b8f648d4 | 512 | break; // case SSD1803 Controller |
wim | 32:59c4b8f648d4 | 513 | |
wim | 29:a3663151aa65 | 514 | |
wim | 32:59c4b8f648d4 | 515 | // Note1: The PCF21XX family of controllers has several types that dont have an onboard voltage generator for V-LCD. |
wim | 32:59c4b8f648d4 | 516 | // You must supply this LCD voltage externally and not try to enable VGen. |
wim | 32:59c4b8f648d4 | 517 | // Note2: The early versions of PCF2116 controllers (eg PCF2116C) can not generate sufficiently negative voltage for the LCD at a VDD of 3V3. |
wim | 32:59c4b8f648d4 | 518 | // You must supply this voltage externally and not enable VGen or you must use a higher VDD (e.g. 5V) and enable VGen. |
wim | 32:59c4b8f648d4 | 519 | // More recent versions of the controller (eg PCF2116K) have an improved VGen that will work with 3V3. |
wim | 32:59c4b8f648d4 | 520 | // Note3: See datasheet, PCF2116 and other types provide a V0 pin to control the LCD contrast voltage that is provided by VGen. This pins allows |
wim | 32:59c4b8f648d4 | 521 | // contrast control similar to that of pin 3 on the standard 14pin LCD module connector. |
wim | 32:59c4b8f648d4 | 522 | // You can disable VGen by connecting Vo to VDD. VLCD will then be used directly as LCD voltage. |
wim | 32:59c4b8f648d4 | 523 | // Note4: PCF2113 and PCF2119 are different wrt to VLCD generator! There is no V0 pin. The contrast voltage is software controlled by setting the VA and VB registers. |
wim | 32:59c4b8f648d4 | 524 | // Vgen is automatically switched off when the contrast voltage VA or VB is set to 0x00. Note that certain limits apply to allowed values for VA and VB. |
wim | 32:59c4b8f648d4 | 525 | // Note5: See datasheet, members of the PCF21XX family support different numbers of rows/columns. Not all can support 3 or 4 rows. |
wim | 32:59c4b8f648d4 | 526 | // Note6: See datasheet, the PCF21XX-C and PCF21XX-K use a non-standard character set. This may result is strange looking text when not corrected.. |
wim | 32:59c4b8f648d4 | 527 | |
wim | 34:e5a0dcb43ecc | 528 | case PCF2103_3V3: |
wim | 34:e5a0dcb43ecc | 529 | // PCF2103 controller: No Voltage generator for VLCD, VDD=3V3..5V, VLCD input controls contrast voltage. |
wim | 34:e5a0dcb43ecc | 530 | // Initialise Display configuration |
wim | 34:e5a0dcb43ecc | 531 | switch (_type) { |
wim | 34:e5a0dcb43ecc | 532 | case LCD24x1: |
wim | 34:e5a0dcb43ecc | 533 | _function = 0x00; //FUNCTION SET 0 0 1 DL=0 4-bit, 0, M=0 1-line/24 chars display mode, 0, H=0 |
wim | 34:e5a0dcb43ecc | 534 | //Note: 4 bit mode is ignored for I2C mode |
wim | 34:e5a0dcb43ecc | 535 | break; |
wim | 34:e5a0dcb43ecc | 536 | |
wim | 34:e5a0dcb43ecc | 537 | // case LCD12x1D: //Special mode for PCF21XX, Only top line used |
wim | 34:e5a0dcb43ecc | 538 | case LCD12x2: |
wim | 34:e5a0dcb43ecc | 539 | _function = 0x04; //FUNCTION SET 0 0 1 DL=0 4-bit, 0, M=1 2-line/12 chars display mode, 0, H=0 |
wim | 34:e5a0dcb43ecc | 540 | //Note: 4 bit mode is ignored for I2C mode |
wim | 34:e5a0dcb43ecc | 541 | break; |
wim | 34:e5a0dcb43ecc | 542 | |
wim | 34:e5a0dcb43ecc | 543 | default: |
wim | 34:e5a0dcb43ecc | 544 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 34:e5a0dcb43ecc | 545 | break; |
wim | 34:e5a0dcb43ecc | 546 | |
wim | 34:e5a0dcb43ecc | 547 | } // switch type |
wim | 34:e5a0dcb43ecc | 548 | |
wim | 34:e5a0dcb43ecc | 549 | _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1 |
wim | 34:e5a0dcb43ecc | 550 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 34:e5a0dcb43ecc | 551 | |
wim | 34:e5a0dcb43ecc | 552 | // Note: Display from GA628 shows 12 chars. This is actually the right half of a 24x1 display. The commons have been connected in reverse order. |
wim | 34:e5a0dcb43ecc | 553 | _writeCommand(0x05); // Display Conf Set 0000 0, 1, P=0, Q=1 (Instr. Set 1) |
wim | 34:e5a0dcb43ecc | 554 | |
wim | 34:e5a0dcb43ecc | 555 | _writeCommand(0x02); // Screen Config 0000 001, L=0 (Instr. Set 1) |
wim | 34:e5a0dcb43ecc | 556 | _writeCommand(0x08); // ICON Conf 0000 1, IM=0 (Char mode), IB=0 (no Icon blink), 0 (Instr. Set 1) |
wim | 34:e5a0dcb43ecc | 557 | |
wim | 34:e5a0dcb43ecc | 558 | _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0 |
wim | 34:e5a0dcb43ecc | 559 | |
wim | 34:e5a0dcb43ecc | 560 | // Select CG RAM |
wim | 34:e5a0dcb43ecc | 561 | _writeCommand(0x40); //Set CG-RAM address, 8 sequential locations needed per UDC |
wim | 34:e5a0dcb43ecc | 562 | // Store UDC/Icon pattern: |
wim | 34:e5a0dcb43ecc | 563 | // 3 x 8 rows x 5 bits = 120 bits for Normal pattern (UDC 0..2) and |
wim | 34:e5a0dcb43ecc | 564 | // 3 x 8 rows x 5 bits = 120 bits for Blink pattern (UDC 4..6) |
wim | 34:e5a0dcb43ecc | 565 | for (int i=0; i<(8 * 8); i++) { |
wim | 34:e5a0dcb43ecc | 566 | // _writeData(0x1F); // All On |
wim | 34:e5a0dcb43ecc | 567 | _writeData(0x00); // All Off |
wim | 34:e5a0dcb43ecc | 568 | } |
wim | 34:e5a0dcb43ecc | 569 | |
wim | 34:e5a0dcb43ecc | 570 | break; // case PCF2103_3V3 Controller |
wim | 34:e5a0dcb43ecc | 571 | |
wim | 30:033048611c01 | 572 | case PCF2113_3V3: |
wim | 32:59c4b8f648d4 | 573 | // PCF2113 controller: Initialise Voltage booster for VLCD. VDD=3V3. VA and VB control contrast. |
wim | 29:a3663151aa65 | 574 | // Initialise Display configuration |
wim | 29:a3663151aa65 | 575 | switch (_type) { |
wim | 29:a3663151aa65 | 576 | // case LCD12x1: |
wim | 33:900a94bc7585 | 577 | // _function = 0x02; // FUNCTION SET 0 0 1 DL=0 4 bit, 0, M=0 1-line/12 chars display mode, SL=1, IS=0 |
wim | 32:59c4b8f648d4 | 578 | // Note: 4 bit mode is ignored for I2C mode |
wim | 29:a3663151aa65 | 579 | case LCD24x1: |
wim | 33:900a94bc7585 | 580 | _function = 0x00; // FUNCTION SET 0 0 1 DL=0 4 bit, 0, M=0 1-line/24 chars display mode, SL=0, IS=0 |
wim | 32:59c4b8f648d4 | 581 | // Note: 4 bit mode is ignored for I2C mode |
wim | 30:033048611c01 | 582 | break; |
wim | 30:033048611c01 | 583 | |
wim | 30:033048611c01 | 584 | case LCD12x2: |
wim | 33:900a94bc7585 | 585 | _function = 0x04; // FUNCTION SET 0 0 1 DL=0 4 bit, 0, M=1 2-line/12 chars display mode, SL=0, IS=0 |
wim | 30:033048611c01 | 586 | break; |
wim | 30:033048611c01 | 587 | |
wim | 30:033048611c01 | 588 | default: |
wim | 30:033048611c01 | 589 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 30:033048611c01 | 590 | break; |
wim | 30:033048611c01 | 591 | |
wim | 30:033048611c01 | 592 | } // switch type |
wim | 30:033048611c01 | 593 | |
wim | 32:59c4b8f648d4 | 594 | // Init special features |
wim | 33:900a94bc7585 | 595 | _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1 |
wim | 33:900a94bc7585 | 596 | |
wim | 33:900a94bc7585 | 597 | _writeCommand(0x04); // Display Conf Set 0000 0, 1, P=0, Q=0 (Instr. Set 1) |
wim | 33:900a94bc7585 | 598 | _writeCommand(0x10); // Temp Compensation Set 0001 0, 0, TC1=0, TC2=0 (Instr. Set 1) |
wim | 33:900a94bc7585 | 599 | // _writeCommand(0x42); // HV GEN 0100 S1=1, S2=0 (2x multiplier) (Instr. Set 1) |
wim | 33:900a94bc7585 | 600 | _writeCommand(0x40 | (LCD_PCF2_S12 & 0x03)); // HV Gen 0100 S1=1, S2=0 (2x multiplier) (Instr. Set 1) |
wim | 32:59c4b8f648d4 | 601 | |
wim | 32:59c4b8f648d4 | 602 | _contrast = LCD_PCF2_CONTRAST; |
wim | 33:900a94bc7585 | 603 | _writeCommand(0x80 | 0x00 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) 1, V=0, VA=contrast |
wim | 33:900a94bc7585 | 604 | _writeCommand(0x80 | 0x40 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) 1, V=1, VB=contrast |
wim | 32:59c4b8f648d4 | 605 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 606 | |
wim | 33:900a94bc7585 | 607 | _writeCommand(0x02); // Screen Config 0000 001, L=0 (Instr. Set 1) |
wim | 33:900a94bc7585 | 608 | _writeCommand(0x08); // ICON Conf 0000 1, IM=0 (Char mode), IB=0 (no icon blink) DM=0 (no direct mode) (Instr. Set 1) |
wim | 33:900a94bc7585 | 609 | |
wim | 33:900a94bc7585 | 610 | _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0 |
wim | 32:59c4b8f648d4 | 611 | |
wim | 30:033048611c01 | 612 | break; // case PCF2113_3V3 Controller |
wim | 30:033048611c01 | 613 | |
wim | 30:033048611c01 | 614 | |
wim | 32:59c4b8f648d4 | 615 | // case PCF2113_5V: |
wim | 32:59c4b8f648d4 | 616 | // PCF2113 controller: No Voltage generator for VLCD. VDD=5V. Contrast voltage controlled by VA or VB. |
wim | 32:59c4b8f648d4 | 617 | //@TODO |
wim | 32:59c4b8f648d4 | 618 | |
wim | 30:033048611c01 | 619 | |
wim | 30:033048611c01 | 620 | case PCF2116_3V3: |
wim | 32:59c4b8f648d4 | 621 | // PCF2116 controller: Voltage generator for VLCD. VDD=5V. V0 controls contrast voltage. |
wim | 30:033048611c01 | 622 | // Initialise Display configuration |
wim | 30:033048611c01 | 623 | switch (_type) { |
wim | 30:033048611c01 | 624 | // case LCD12x1: |
wim | 30:033048611c01 | 625 | // case LCD12x2: |
wim | 30:033048611c01 | 626 | case LCD24x1: |
wim | 34:e5a0dcb43ecc | 627 | _writeCommand(0x22); //FUNCTION SET 0 0 1 DL=0 4-bit, N=0/M=0 1-line/24 chars display mode, G=1 Vgen on, 0 |
wim | 29:a3663151aa65 | 628 | //Note: 4 bit mode is ignored for I2C mode |
wim | 29:a3663151aa65 | 629 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 29:a3663151aa65 | 630 | break; |
wim | 29:a3663151aa65 | 631 | |
wim | 32:59c4b8f648d4 | 632 | case LCD12x3D: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 633 | case LCD12x3D1: // Special mode for PCF21XX |
wim | 32:59c4b8f648d4 | 634 | case LCD12x4D: // Special mode for PCF21XX: |
wim | 34:e5a0dcb43ecc | 635 | _writeCommand(0x2E); //FUNCTION SET 0 0 1 DL=0 4-bit, N=1/M=1 4-line/12 chars display mode, G=1 VGen on, 0 |
wim | 29:a3663151aa65 | 636 | //Note: 4 bit mode is ignored for I2C mode |
wim | 29:a3663151aa65 | 637 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 29:a3663151aa65 | 638 | break; |
wim | 30:033048611c01 | 639 | |
wim | 30:033048611c01 | 640 | case LCD24x2: |
wim | 34:e5a0dcb43ecc | 641 | _writeCommand(0x2A); //FUNCTION SET 0 0 1 DL=0 4-bit, N=1/M=0 2-line/24 chars display mode, G=1 VGen on, 0 |
wim | 29:a3663151aa65 | 642 | //Note: 4 bit mode is ignored for I2C mode |
wim | 30:033048611c01 | 643 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 644 | break; |
wim | 32:59c4b8f648d4 | 645 | |
wim | 30:033048611c01 | 646 | default: |
wim | 30:033048611c01 | 647 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 30:033048611c01 | 648 | break; |
wim | 30:033048611c01 | 649 | |
wim | 29:a3663151aa65 | 650 | } // switch type |
wim | 29:a3663151aa65 | 651 | |
wim | 30:033048611c01 | 652 | break; // case PCF2116_3V3 Controller |
wim | 29:a3663151aa65 | 653 | |
wim | 32:59c4b8f648d4 | 654 | |
wim | 32:59c4b8f648d4 | 655 | //Experimental for cellphone 3-line display, SA=0x74, No Ack supported, Character set C or K, DL = 8 bit, N=0,M=1 (reserved mode !!), external VLCD -2V5 |
wim | 32:59c4b8f648d4 | 656 | //@TODO |
wim | 32:59c4b8f648d4 | 657 | case PCF2116_5V: |
wim | 32:59c4b8f648d4 | 658 | // PCF2116 controller: No Voltage generator for VLCD. VDD=5V. V0 controls contrast voltage. |
wim | 32:59c4b8f648d4 | 659 | // Initialise Display configuration |
wim | 32:59c4b8f648d4 | 660 | switch (_type) { |
wim | 32:59c4b8f648d4 | 661 | // case LCD12x1: |
wim | 32:59c4b8f648d4 | 662 | // case LCD12x2: |
wim | 32:59c4b8f648d4 | 663 | // case LCD24x1: |
wim | 34:e5a0dcb43ecc | 664 | // _writeCommand(0x20); //FUNCTION SET 0 0 1 DL=0 4-bit, N=0/M=0 1-line/24 chars display mode, G=0 no Vgen, 0 |
wim | 32:59c4b8f648d4 | 665 | //Note: 4 bit mode is ignored for I2C mode |
wim | 32:59c4b8f648d4 | 666 | // wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 667 | // break; |
wim | 32:59c4b8f648d4 | 668 | |
wim | 32:59c4b8f648d4 | 669 | case LCD12x3D: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 670 | case LCD12x3D1: // Special mode for PCF21XX |
wim | 32:59c4b8f648d4 | 671 | case LCD12x4D: // Special mode for PCF21XX: |
wim | 32:59c4b8f648d4 | 672 | // _writeCommand(0x34); //FUNCTION SET 8 bit, N=0/M=1 4-line/12 chars display mode OK |
wim | 32:59c4b8f648d4 | 673 | // _writeCommand(0x24); //FUNCTION SET 4 bit, N=0/M=1 4-line/12 chars display mode OK |
wim | 34:e5a0dcb43ecc | 674 | _writeCommand(0x2C); //FUNCTION SET 0 0 1 DL=0 4-bit, N=1/M=1 4-line/12 chars display mode, G=0 no Vgen, 0 OK |
wim | 32:59c4b8f648d4 | 675 | //Note: 4 bit mode is ignored for I2C mode |
wim | 32:59c4b8f648d4 | 676 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 677 | break; |
wim | 32:59c4b8f648d4 | 678 | |
wim | 32:59c4b8f648d4 | 679 | // case LCD24x2: |
wim | 32:59c4b8f648d4 | 680 | // _writeCommand(0x28); //FUNCTION SET 4 bit, N=1/M=0 2-line/24 chars display mode |
wim | 32:59c4b8f648d4 | 681 | //Note: 4 bit mode is ignored for I2C mode |
wim | 32:59c4b8f648d4 | 682 | // wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 683 | // break; |
wim | 32:59c4b8f648d4 | 684 | |
wim | 32:59c4b8f648d4 | 685 | default: |
wim | 32:59c4b8f648d4 | 686 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 32:59c4b8f648d4 | 687 | break; |
wim | 32:59c4b8f648d4 | 688 | |
wim | 32:59c4b8f648d4 | 689 | } // switch type |
wim | 32:59c4b8f648d4 | 690 | |
wim | 32:59c4b8f648d4 | 691 | break; // case PCF2116_5V Controller |
wim | 32:59c4b8f648d4 | 692 | |
wim | 32:59c4b8f648d4 | 693 | case PCF2119_3V3: |
wim | 32:59c4b8f648d4 | 694 | // PCF2119 controller: Initialise Voltage booster for VLCD. VDD=3V3. VA and VB control contrast. |
wim | 32:59c4b8f648d4 | 695 | // Note1: See datasheet, the PCF2119 supports icons and provides separate constrast control for Icons and characters. |
wim | 32:59c4b8f648d4 | 696 | // Note2: Vgen is switched off when the contrast voltage VA or VB is set to 0x00. |
wim | 32:59c4b8f648d4 | 697 | |
wim | 32:59c4b8f648d4 | 698 | //POR or Hardware Reset should be applied |
wim | 32:59c4b8f648d4 | 699 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 700 | |
wim | 32:59c4b8f648d4 | 701 | // Initialise Display configuration |
wim | 32:59c4b8f648d4 | 702 | switch (_type) { |
wim | 32:59c4b8f648d4 | 703 | case LCD8x1: |
wim | 32:59c4b8f648d4 | 704 | // case LCD12x1: |
wim | 32:59c4b8f648d4 | 705 | case LCD16x1: |
wim | 34:e5a0dcb43ecc | 706 | _function = 0x02; // FUNCTION SET 0 0 1 DL=0 4-bit, 0 , M=0 1-line/16 chars display mode, SL=1 |
wim | 32:59c4b8f648d4 | 707 | // Note: 4 bit mode is ignored for I2C mode |
wim | 32:59c4b8f648d4 | 708 | break; |
wim | 32:59c4b8f648d4 | 709 | |
wim | 32:59c4b8f648d4 | 710 | case LCD24x1: |
wim | 32:59c4b8f648d4 | 711 | // case LCD32x1: |
wim | 34:e5a0dcb43ecc | 712 | _function = 0x00; // FUNCTION SET 0 0 1 DL=0 4-bit, 0 , M=0 1-line/32 chars display mode, SL=0 |
wim | 32:59c4b8f648d4 | 713 | // Note: 4 bit mode is ignored for I2C mode |
wim | 32:59c4b8f648d4 | 714 | break; |
wim | 32:59c4b8f648d4 | 715 | |
wim | 32:59c4b8f648d4 | 716 | case LCD8x2: |
wim | 32:59c4b8f648d4 | 717 | // case LCD12x2: |
wim | 32:59c4b8f648d4 | 718 | case LCD16x2: |
wim | 34:e5a0dcb43ecc | 719 | _function = 0x04; // FUNCTION SET 0 0 1 DL=0 4-bit, 0, M=1 2-line/16 chars display mode, SL=0 |
wim | 32:59c4b8f648d4 | 720 | // Note: 4 bit mode is ignored for I2C mode |
wim | 32:59c4b8f648d4 | 721 | break; |
wim | 32:59c4b8f648d4 | 722 | |
wim | 32:59c4b8f648d4 | 723 | default: |
wim | 32:59c4b8f648d4 | 724 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 32:59c4b8f648d4 | 725 | break; |
wim | 32:59c4b8f648d4 | 726 | |
wim | 32:59c4b8f648d4 | 727 | } // switch type |
wim | 32:59c4b8f648d4 | 728 | |
wim | 32:59c4b8f648d4 | 729 | // Init special features |
wim | 32:59c4b8f648d4 | 730 | _writeCommand(0x20 | _function | 0x01); // Set function, Select Instruction Set = 1 |
wim | 32:59c4b8f648d4 | 731 | |
wim | 32:59c4b8f648d4 | 732 | _writeCommand(0x04); // DISP CONF SET (Instr. Set 1) 0000, 0, 1, P=0, Q=0 |
wim | 32:59c4b8f648d4 | 733 | _writeCommand(0x10); // TEMP CTRL SET (Instr. Set 1) 0001, 0, 0, TC1=0, TC2=0 |
wim | 32:59c4b8f648d4 | 734 | // _writeCommand(0x42); // HV GEN (Instr. Set 1) 0100, 0, 0, S1=1, S2=0 (2x multiplier) |
wim | 32:59c4b8f648d4 | 735 | _writeCommand(0x40 | (LCD_PCF2_S12 & 0x03)); // HV GEN (Instr. Set 1) 0100, 0, 0, S1=1, S2=0 (2x multiplier) |
wim | 32:59c4b8f648d4 | 736 | |
wim | 32:59c4b8f648d4 | 737 | _contrast = LCD_PCF2_CONTRAST; |
wim | 32:59c4b8f648d4 | 738 | _writeCommand(0x80 | 0x00 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=0, VA=contrast |
wim | 32:59c4b8f648d4 | 739 | _writeCommand(0x80 | 0x40 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=1, VB=contrast |
wim | 32:59c4b8f648d4 | 740 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 32:59c4b8f648d4 | 741 | |
wim | 32:59c4b8f648d4 | 742 | _writeCommand(0x02); // SCRN CONF (Instr. Set 1) L=0 |
wim | 32:59c4b8f648d4 | 743 | _writeCommand(0x08); // ICON CONF (Instr. Set 1) IM=0 (Char mode) IB=0 (no icon blink) DM=0 (no direct mode) |
wim | 32:59c4b8f648d4 | 744 | |
wim | 32:59c4b8f648d4 | 745 | _writeCommand(0x20 | _function); // Select Instruction Set = 0 |
wim | 32:59c4b8f648d4 | 746 | |
wim | 32:59c4b8f648d4 | 747 | break; // case PCF2119_3V3 Controller |
wim | 32:59c4b8f648d4 | 748 | |
wim | 32:59c4b8f648d4 | 749 | // case PCF2119_5V: |
wim | 32:59c4b8f648d4 | 750 | // PCF2119 controller: No Voltage booster for VLCD. VDD=3V3. VA and VB control contrast. |
wim | 32:59c4b8f648d4 | 751 | // Note1: See datasheet, the PCF2119 supports icons and provides separate constrast control for Icons and characters. |
wim | 32:59c4b8f648d4 | 752 | // Note2: Vgen is switched off when the contrast voltage VA or VB is set to 0x00. |
wim | 30:033048611c01 | 753 | //@TODO |
wim | 29:a3663151aa65 | 754 | |
wim | 19:c747b9e2e7b8 | 755 | case WS0010: |
wim | 19:c747b9e2e7b8 | 756 | // WS0010 OLED controller: Initialise DC/DC Voltage converter for LEDs |
wim | 30:033048611c01 | 757 | // Note1: Identical to RS0010 |
wim | 30:033048611c01 | 758 | // Note2: supports 1 or 2 lines (and 16x100 graphics) |
wim | 30:033048611c01 | 759 | // supports 4 fonts (English/Japanese (default), Western European-I, English/Russian, Western European-II) |
wim | 19:c747b9e2e7b8 | 760 | // Cursor/Disp shift set 0001 SC RL 0 0 |
wim | 19:c747b9e2e7b8 | 761 | // |
wim | 30:033048611c01 | 762 | // Mode and Power set 0001 GC PWR 1 1 |
wim | 19:c747b9e2e7b8 | 763 | // GC = 0 (Graph Mode=1, Char Mode=0) |
wim | 30:033048611c01 | 764 | // PWR = 1 (DC/DC On/Off) |
wim | 30:033048611c01 | 765 | |
wim | 30:033048611c01 | 766 | //@Todo: This may be needed to enable a warm reboot |
wim | 32:59c4b8f648d4 | 767 | //_writeCommand(0x13); // Char mode, DC/DC off |
wim | 30:033048611c01 | 768 | //wait_ms(10); // Wait 10ms to ensure powered down |
wim | 32:59c4b8f648d4 | 769 | _writeCommand(0x17); // Char mode, DC/DC on |
wim | 30:033048611c01 | 770 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 29:a3663151aa65 | 771 | |
wim | 29:a3663151aa65 | 772 | // Initialise Display configuration |
wim | 29:a3663151aa65 | 773 | switch (_type) { |
wim | 29:a3663151aa65 | 774 | case LCD8x1: //8x1 is a regular 1 line display |
wim | 29:a3663151aa65 | 775 | case LCD8x2B: //8x2B is a special case of 16x1 |
wim | 29:a3663151aa65 | 776 | // case LCD12x1: |
wim | 29:a3663151aa65 | 777 | case LCD16x1: |
wim | 30:033048611c01 | 778 | case LCD24x1: |
wim | 30:033048611c01 | 779 | _writeCommand(0x20); // Function set 001 DL N F FT1 FT0 |
wim | 30:033048611c01 | 780 | // DL=0 (4 bits bus) |
wim | 30:033048611c01 | 781 | // N=0 (1 line) |
wim | 30:033048611c01 | 782 | // F=0 (5x7 dots font) |
wim | 30:033048611c01 | 783 | // FT=00 (00 = Engl/Jap, 01 = WestEur1, 10 = Engl/Russian, 11 = WestEur2 |
wim | 30:033048611c01 | 784 | break; |
wim | 30:033048611c01 | 785 | |
wim | 32:59c4b8f648d4 | 786 | case LCD12x3D: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 787 | case LCD12x3D1: // Special mode for PCF21XX |
wim | 32:59c4b8f648d4 | 788 | case LCD12x4D: // Special mode for PCF21XX: |
wim | 33:900a94bc7585 | 789 | case LCD16x3G: // Special mode for ST7036 |
wim | 30:033048611c01 | 790 | case LCD24x4D: // Special mode for KS0078 |
wim | 30:033048611c01 | 791 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 29:a3663151aa65 | 792 | break; |
wim | 29:a3663151aa65 | 793 | |
wim | 29:a3663151aa65 | 794 | default: |
wim | 30:033048611c01 | 795 | // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4) |
wim | 30:033048611c01 | 796 | _writeCommand(0x28); // Function set 001 DL N F FT1 FT0 |
wim | 30:033048611c01 | 797 | // DL=0 (4 bits bus) |
wim | 30:033048611c01 | 798 | // N=1 (2 lines) |
wim | 30:033048611c01 | 799 | // F=0 (5x7 dots font) |
wim | 30:033048611c01 | 800 | // FT=00 (00 = Engl/Jap, 01 = WestEur1, 10 = Engl/Russian, 11 = WestEur2 |
wim | 30:033048611c01 | 801 | |
wim | 29:a3663151aa65 | 802 | break; |
wim | 29:a3663151aa65 | 803 | } // switch type |
wim | 29:a3663151aa65 | 804 | |
wim | 32:59c4b8f648d4 | 805 | break; // case WS0010 Controller |
wim | 33:900a94bc7585 | 806 | |
wim | 33:900a94bc7585 | 807 | |
wim | 33:900a94bc7585 | 808 | case US2066_3V3: |
wim | 33:900a94bc7585 | 809 | // US2066/SSD1311 OLED controller, Initialise for VDD=3V3 |
wim | 33:900a94bc7585 | 810 | // Note: supports 1,2, 3 or 4 lines |
wim | 33:900a94bc7585 | 811 | // case USS2066_5V: |
wim | 33:900a94bc7585 | 812 | // US2066 controller, VDD=5V |
wim | 33:900a94bc7585 | 813 | |
wim | 33:900a94bc7585 | 814 | // Initialise Display configuration |
wim | 33:900a94bc7585 | 815 | switch (_type) { |
wim | 33:900a94bc7585 | 816 | case LCD8x1: //8x1 is a regular 1 line display |
wim | 33:900a94bc7585 | 817 | case LCD8x2B: //8x2D is a special case of 16x1 |
wim | 33:900a94bc7585 | 818 | // case LCD12x1: |
wim | 33:900a94bc7585 | 819 | case LCD16x1: |
wim | 33:900a94bc7585 | 820 | // case LCD20x1: |
wim | 33:900a94bc7585 | 821 | _function = 0x00; // Set function 0 0 1 X N DH RE(0) IS |
wim | 33:900a94bc7585 | 822 | // Saved to allow switch between Instruction sets at later time |
wim | 33:900a94bc7585 | 823 | // DL=X bit is ignored for US2066. Uses hardwired pins instead |
wim | 33:900a94bc7585 | 824 | // N=0 1 Line / 3 Line |
wim | 33:900a94bc7585 | 825 | // DH=0 Double Height disable |
wim | 33:900a94bc7585 | 826 | // IS=0 |
wim | 33:900a94bc7585 | 827 | |
wim | 33:900a94bc7585 | 828 | _function_1 = 0x02; // Set function, 0 0 1 X N BE RE(1) REV |
wim | 33:900a94bc7585 | 829 | // Saved to allow switch between Instruction sets at later time |
wim | 33:900a94bc7585 | 830 | // DL=X bit is ignored for US2066. Uses hardwired pins instead |
wim | 33:900a94bc7585 | 831 | // N=0 1 Line / 3 Line |
wim | 33:900a94bc7585 | 832 | // BE=0 Blink Enable off, special feature of SSD1803, US2066 |
wim | 33:900a94bc7585 | 833 | // REV=0 Reverse off, special feature of SSD1803, US2066 |
wim | 33:900a94bc7585 | 834 | |
wim | 33:900a94bc7585 | 835 | _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW |
wim | 33:900a94bc7585 | 836 | // NW=0 1-Line LCD (N=0) |
wim | 33:900a94bc7585 | 837 | break; |
wim | 33:900a94bc7585 | 838 | |
wim | 33:900a94bc7585 | 839 | case LCD16x1C: |
wim | 33:900a94bc7585 | 840 | case LCD8x2: |
wim | 33:900a94bc7585 | 841 | case LCD16x2: |
wim | 33:900a94bc7585 | 842 | case LCD20x2: |
wim | 33:900a94bc7585 | 843 | _function = 0x08; // Set function 0 0 1 X N DH RE(0) IS |
wim | 33:900a94bc7585 | 844 | // Saved to allow switch between Instruction sets at later time |
wim | 33:900a94bc7585 | 845 | // DL=X bit is ignored for US2066. Uses hardwired pins instead |
wim | 33:900a94bc7585 | 846 | // N=1 2 line / 4 Line |
wim | 33:900a94bc7585 | 847 | // DH=0 Double Height disable |
wim | 33:900a94bc7585 | 848 | // IS=0 |
wim | 33:900a94bc7585 | 849 | |
wim | 33:900a94bc7585 | 850 | _function_1 = 0x0A; // Set function, 0 0 1 X N BE RE(1) REV |
wim | 33:900a94bc7585 | 851 | // Saved to allow switch between Instruction sets at later time |
wim | 33:900a94bc7585 | 852 | // DL=X bit is ignored for US2066. Uses hardwired pins instead |
wim | 33:900a94bc7585 | 853 | // N=1 2 line / 4 Line |
wim | 33:900a94bc7585 | 854 | // BE=0 Blink Enable off, special feature of SSD1803, US2066 |
wim | 33:900a94bc7585 | 855 | // REV=0 Reverse off, special feature of SSD1803, US2066 |
wim | 33:900a94bc7585 | 856 | |
wim | 33:900a94bc7585 | 857 | _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW |
wim | 33:900a94bc7585 | 858 | // NW=0 2-Line LCD (N=1) |
wim | 33:900a94bc7585 | 859 | break; |
wim | 33:900a94bc7585 | 860 | |
wim | 33:900a94bc7585 | 861 | case LCD12x3D: // Special mode for KS0078 and PCF21XX |
wim | 33:900a94bc7585 | 862 | // case LCD12x3D1: // Special mode for KS0078 and PCF21XX |
wim | 33:900a94bc7585 | 863 | case LCD16x3D: // Special mode for KS0078, SSD1803 and US2066 |
wim | 33:900a94bc7585 | 864 | // case LCD16x3D1: // Special mode for SSD1803, US2066 |
wim | 33:900a94bc7585 | 865 | // case LCD20x3D: // Special mode for SSD1803, US2066 |
wim | 33:900a94bc7585 | 866 | _function = 0x00; // Set function 0 0 1 X N DH RE(0) IS |
wim | 33:900a94bc7585 | 867 | // Saved to allow switch between Instruction sets at later time |
wim | 33:900a94bc7585 | 868 | // DL=X bit is ignored for US2066. Uses hardwired pins instead |
wim | 33:900a94bc7585 | 869 | // N=0 1 Line / 3 Line |
wim | 33:900a94bc7585 | 870 | // DH=0 Double Height disable |
wim | 33:900a94bc7585 | 871 | // IS=0 |
wim | 33:900a94bc7585 | 872 | |
wim | 33:900a94bc7585 | 873 | _function_1 = 0x02; // Set function, 0 0 1 X N BE RE(1) REV |
wim | 33:900a94bc7585 | 874 | // Saved to allow switch between Instruction sets at later time |
wim | 33:900a94bc7585 | 875 | // DL=X bit is ignored for US2066. Uses hardwired pins instead |
wim | 33:900a94bc7585 | 876 | // N=0 1 Line / 3 Line |
wim | 33:900a94bc7585 | 877 | // BE=0 Blink Enable off, special feature of SSD1803, US2066 |
wim | 33:900a94bc7585 | 878 | // REV=0 Reverse off, special feature of SSD1803, US2066 |
wim | 33:900a94bc7585 | 879 | |
wim | 33:900a94bc7585 | 880 | _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW |
wim | 33:900a94bc7585 | 881 | // NW=1 3-Line LCD (N=0) |
wim | 33:900a94bc7585 | 882 | break; |
wim | 33:900a94bc7585 | 883 | |
wim | 33:900a94bc7585 | 884 | case LCD20x4D: // Special mode for SSD1803, US2066 |
wim | 33:900a94bc7585 | 885 | _function = 0x08; // Set function 0 0 1 X N DH RE(0) IS |
wim | 33:900a94bc7585 | 886 | // Saved to allow switch between Instruction sets at later time |
wim | 33:900a94bc7585 | 887 | // DL=X bit is ignored for US2066. Uses hardwired pins instead |
wim | 33:900a94bc7585 | 888 | // N=1 2 line / 4 Line |
wim | 33:900a94bc7585 | 889 | // DH=0 Double Height disable |
wim | 33:900a94bc7585 | 890 | // IS=0 |
wim | 33:900a94bc7585 | 891 | |
wim | 33:900a94bc7585 | 892 | _function_1 = 0x0A; // Set function, 0 0 1 DL N BE RE(1) REV |
wim | 33:900a94bc7585 | 893 | // Saved to allow switch between Instruction sets at later time |
wim | 33:900a94bc7585 | 894 | // DL=0 bit is ignored for US2066. Uses hardwired pins instead |
wim | 33:900a94bc7585 | 895 | // N=1 2 line / 4 Line |
wim | 33:900a94bc7585 | 896 | // BE=0 Blink Enable off, special feature of SSD1803, US2066 |
wim | 33:900a94bc7585 | 897 | // REV=0 Reverse off, special feature of SSD1803, US2066 |
wim | 33:900a94bc7585 | 898 | |
wim | 33:900a94bc7585 | 899 | _lines = 0x01; // Ext function set 0 0 0 0 1 FW BW NW |
wim | 33:900a94bc7585 | 900 | // NW=1 4-Line LCD (N=1) |
wim | 33:900a94bc7585 | 901 | break; |
wim | 33:900a94bc7585 | 902 | |
wim | 33:900a94bc7585 | 903 | // case LCD24x1: |
wim | 33:900a94bc7585 | 904 | // case LCD16x3G: // Special mode for ST7036 |
wim | 33:900a94bc7585 | 905 | // case LCD24x4D: // Special mode for KS0078 |
wim | 33:900a94bc7585 | 906 | default: |
wim | 33:900a94bc7585 | 907 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 33:900a94bc7585 | 908 | break; |
wim | 33:900a94bc7585 | 909 | |
wim | 33:900a94bc7585 | 910 | } // switch type |
wim | 33:900a94bc7585 | 911 | |
wim | 34:e5a0dcb43ecc | 912 | _writeCommand(0x00); // NOP, make sure to sync SPI |
wim | 33:900a94bc7585 | 913 | |
wim | 33:900a94bc7585 | 914 | // init special features |
wim | 33:900a94bc7585 | 915 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV |
wim | 33:900a94bc7585 | 916 | // Select Extended Instruction Set |
wim | 33:900a94bc7585 | 917 | |
wim | 33:900a94bc7585 | 918 | _writeCommand(0x71); // Function Select A: 0 1 1 1 0 0 0 1 (Ext Instr Set) |
wim | 33:900a94bc7585 | 919 | _writeData(0x00); // Disable Internal VDD |
wim | 33:900a94bc7585 | 920 | |
wim | 33:900a94bc7585 | 921 | _writeCommand(0x79); // Function Select OLED: 0 1 1 1 1 0 0 1 (Ext Instr Set) |
wim | 33:900a94bc7585 | 922 | |
wim | 33:900a94bc7585 | 923 | _writeCommand(0xD5); // Display Clock Divide Ratio: 1 1 0 1 0 1 0 1 (Ext Instr Set, OLED Instr Set) |
wim | 33:900a94bc7585 | 924 | _writeCommand(0x70); // Display Clock Divide Ratio value: 0 1 1 1 0 0 0 0 (Ext Instr Set, OLED Instr Set) |
wim | 33:900a94bc7585 | 925 | |
wim | 33:900a94bc7585 | 926 | _writeCommand(0x78); // Function Disable OLED: 0 1 1 1 1 0 0 0 (Ext Instr Set) |
wim | 33:900a94bc7585 | 927 | |
wim | 33:900a94bc7585 | 928 | // _writeCommand(0x06); // Set ext entry mode, 0 0 0 0 0 1 BDC=1 COM1-32, BDS=0 SEG100-1 "Bottom View" (Ext Instr Set) |
wim | 33:900a94bc7585 | 929 | _writeCommand(0x05); // Set ext entry mode, 0 0 0 0 0 1 BDC=0 COM32-1, BDS=1 SEG1-100 "Top View" (Ext Instr Set) |
wim | 33:900a94bc7585 | 930 | |
wim | 33:900a94bc7585 | 931 | _writeCommand(0x08 | _lines); // Set ext function 0 0 0 0 1 FW BW NW 1,2,3 or 4 lines (Ext Instr Set) |
wim | 33:900a94bc7585 | 932 | |
wim | 34:e5a0dcb43ecc | 933 | // _writeCommand(0x1C); // Double Height, 0 0 0 1 UD2=1, UD1=1, X, DH'=0 (Ext Instr Set) |
wim | 33:900a94bc7585 | 934 | // // Default |
wim | 33:900a94bc7585 | 935 | |
wim | 33:900a94bc7585 | 936 | _writeCommand(0x72); // Function Select B: 0 1 1 1 0 0 1 0 (Ext Instr Set) |
wim | 33:900a94bc7585 | 937 | _writeData(0x01); // Select ROM A (CGRAM 8, CGROM 248) |
wim | 33:900a94bc7585 | 938 | |
wim | 33:900a94bc7585 | 939 | _writeCommand(0x79); // Function Select OLED: 0 1 1 1 1 0 0 1 (Ext Instr Set) |
wim | 33:900a94bc7585 | 940 | |
wim | 33:900a94bc7585 | 941 | _writeCommand(0xDA); // Set Segm Pins Config: 1 1 0 1 1 0 1 0 (Ext Instr Set, OLED) |
wim | 33:900a94bc7585 | 942 | _writeCommand(0x10); // Set Segm Pins Config value: Altern Odd/Even, Disable Remap (Ext Instr Set, OLED) |
wim | 33:900a94bc7585 | 943 | |
wim | 33:900a94bc7585 | 944 | _writeCommand(0xDC); // Function Select C: 1 1 0 1 1 1 0 0 (Ext Instr Set, OLED) |
wim | 33:900a94bc7585 | 945 | // _writeCommand(0x00); // Set internal VSL, GPIO pin HiZ (always read low) |
wim | 33:900a94bc7585 | 946 | _writeCommand(0x80); // Set external VSL, GPIO pin HiZ (always read low) |
wim | 33:900a94bc7585 | 947 | |
wim | 33:900a94bc7585 | 948 | _contrast = LCD_US20_CONTRAST; |
wim | 33:900a94bc7585 | 949 | _writeCommand(0x81); // Set Contrast Control: 1 0 0 0 0 0 0 1 (Ext Instr Set, OLED) |
wim | 33:900a94bc7585 | 950 | _writeCommand((_contrast << 2) | 0x03); // Set Contrast Value: 8 bits, use 6 bits for compatibility |
wim | 33:900a94bc7585 | 951 | |
wim | 33:900a94bc7585 | 952 | _writeCommand(0xD9); // Set Phase Length: 1 1 0 1 1 0 0 1 (Ext Instr Set, OLED) |
wim | 33:900a94bc7585 | 953 | _writeCommand(0xF1); // Set Phase Length Value: |
wim | 33:900a94bc7585 | 954 | |
wim | 33:900a94bc7585 | 955 | _writeCommand(0xDB); // Set VCOMH Deselect Lvl: 1 1 0 1 1 0 1 1 (Ext Instr Set, OLED) |
wim | 33:900a94bc7585 | 956 | _writeCommand(0x30); // Set VCOMH Deselect Value: 0.83 x VCC |
wim | 33:900a94bc7585 | 957 | |
wim | 33:900a94bc7585 | 958 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 33:900a94bc7585 | 959 | |
wim | 33:900a94bc7585 | 960 | //Test Fade/Blinking. Hard Blink on/off, No fade in/out ?? |
wim | 33:900a94bc7585 | 961 | // _writeCommand(0x23); // Set (Ext Instr Set, OLED) |
wim | 33:900a94bc7585 | 962 | // _writeCommand(0x3F); // Set interval 128 frames |
wim | 33:900a94bc7585 | 963 | //End Test Blinking |
wim | 33:900a94bc7585 | 964 | |
wim | 33:900a94bc7585 | 965 | _writeCommand(0x78); // Function Disable OLED: 0 1 1 1 1 0 0 0 (Ext Instr Set) |
wim | 33:900a94bc7585 | 966 | |
wim | 33:900a94bc7585 | 967 | _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 X N DH RE(0) IS=1 Select Instruction Set 1 |
wim | 33:900a94bc7585 | 968 | // Select Std Instr set, Select IS=1 |
wim | 33:900a94bc7585 | 969 | |
wim | 33:900a94bc7585 | 970 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV |
wim | 33:900a94bc7585 | 971 | // Select Ext Instr Set, IS=1 |
wim | 33:900a94bc7585 | 972 | _writeCommand(0x10); // Shift/Scroll enable, 0 0 0 1 DS4/HS4 DS3/HS3 DS2/HS2 DS1/HS1 (Ext Instr Set, IS=1) |
wim | 33:900a94bc7585 | 973 | |
wim | 33:900a94bc7585 | 974 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 975 | // Select Std Instr set, Select IS=0 |
wim | 33:900a94bc7585 | 976 | break; // case US2066/SSD1311 Controller |
wim | 33:900a94bc7585 | 977 | |
wim | 34:e5a0dcb43ecc | 978 | //not yet tested on hardware |
wim | 34:e5a0dcb43ecc | 979 | case PT6314 : |
wim | 34:e5a0dcb43ecc | 980 | // Initialise Display configuration |
wim | 34:e5a0dcb43ecc | 981 | switch (_type) { |
wim | 34:e5a0dcb43ecc | 982 | case LCD8x1: //8x1 is a regular 1 line display |
wim | 34:e5a0dcb43ecc | 983 | case LCD8x2B: //8x2B is a special case of 16x1 |
wim | 34:e5a0dcb43ecc | 984 | // case LCD12x1: |
wim | 34:e5a0dcb43ecc | 985 | case LCD16x1: |
wim | 34:e5a0dcb43ecc | 986 | case LCD20x1: |
wim | 34:e5a0dcb43ecc | 987 | case LCD24x1: |
wim | 34:e5a0dcb43ecc | 988 | _function = 0x00; // Function set 001 DL N X BR1 BR0 |
wim | 34:e5a0dcb43ecc | 989 | // DL=0 (4 bits bus) |
wim | 34:e5a0dcb43ecc | 990 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 34:e5a0dcb43ecc | 991 | // N=0 (1 line) |
wim | 34:e5a0dcb43ecc | 992 | // X |
wim | 34:e5a0dcb43ecc | 993 | // BR1=0 (2 significant bits for brightness |
wim | 34:e5a0dcb43ecc | 994 | // BR0=0 |
wim | 34:e5a0dcb43ecc | 995 | // 0x0 = 100% |
wim | 34:e5a0dcb43ecc | 996 | // 0x1 = 75% |
wim | 34:e5a0dcb43ecc | 997 | // 0x2 = 50% |
wim | 34:e5a0dcb43ecc | 998 | // 0x3 = 25% |
wim | 34:e5a0dcb43ecc | 999 | |
wim | 34:e5a0dcb43ecc | 1000 | break; |
wim | 34:e5a0dcb43ecc | 1001 | |
wim | 34:e5a0dcb43ecc | 1002 | // All other valid LCD types are initialised as 2 Line displays |
wim | 34:e5a0dcb43ecc | 1003 | case LCD8x2: |
wim | 34:e5a0dcb43ecc | 1004 | case LCD16x2: |
wim | 34:e5a0dcb43ecc | 1005 | case LCD20x2: |
wim | 34:e5a0dcb43ecc | 1006 | case LCD24x2: |
wim | 34:e5a0dcb43ecc | 1007 | _function = 0x08; // Function set 001 DL N X BR1 BR2 |
wim | 34:e5a0dcb43ecc | 1008 | // DL=0 (4 bits bus) |
wim | 34:e5a0dcb43ecc | 1009 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 34:e5a0dcb43ecc | 1010 | // N=1 (2 lines) |
wim | 34:e5a0dcb43ecc | 1011 | // X |
wim | 34:e5a0dcb43ecc | 1012 | // BR1=0 (2 significant bits for brightness |
wim | 34:e5a0dcb43ecc | 1013 | // BR0=0 |
wim | 34:e5a0dcb43ecc | 1014 | break; |
wim | 34:e5a0dcb43ecc | 1015 | |
wim | 34:e5a0dcb43ecc | 1016 | default: |
wim | 34:e5a0dcb43ecc | 1017 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 34:e5a0dcb43ecc | 1018 | break; |
wim | 34:e5a0dcb43ecc | 1019 | } // switch type |
wim | 34:e5a0dcb43ecc | 1020 | |
wim | 34:e5a0dcb43ecc | 1021 | _contrast = LCD_PT63_CONTRAST; |
wim | 34:e5a0dcb43ecc | 1022 | _writeCommand(0x20 | _function | ((~_contrast) >> 4)); // Invert and shift to use 2 MSBs |
wim | 34:e5a0dcb43ecc | 1023 | break; // case PT6314 Controller (VFD) |
wim | 29:a3663151aa65 | 1024 | |
wim | 19:c747b9e2e7b8 | 1025 | default: |
wim | 32:59c4b8f648d4 | 1026 | // Devices fully compatible to HD44780 that do not use any DC/DC Voltage converters but external VLCD, no icons etc |
wim | 10:dd9b3a696acd | 1027 | |
wim | 29:a3663151aa65 | 1028 | // Initialise Display configuration |
wim | 29:a3663151aa65 | 1029 | switch (_type) { |
wim | 29:a3663151aa65 | 1030 | case LCD8x1: //8x1 is a regular 1 line display |
wim | 29:a3663151aa65 | 1031 | case LCD8x2B: //8x2B is a special case of 16x1 |
wim | 29:a3663151aa65 | 1032 | // case LCD12x1: |
wim | 29:a3663151aa65 | 1033 | case LCD16x1: |
wim | 30:033048611c01 | 1034 | // case LCD20x1: |
wim | 29:a3663151aa65 | 1035 | case LCD24x1: |
wim | 30:033048611c01 | 1036 | // case LCD40x1: |
wim | 32:59c4b8f648d4 | 1037 | _function = 0x00; // Function set 001 DL N F - - |
wim | 29:a3663151aa65 | 1038 | // DL=0 (4 bits bus) |
wim | 29:a3663151aa65 | 1039 | // N=0 (1 line) |
wim | 29:a3663151aa65 | 1040 | // F=0 (5x7 dots font) |
wim | 29:a3663151aa65 | 1041 | break; |
wim | 29:a3663151aa65 | 1042 | |
wim | 32:59c4b8f648d4 | 1043 | case LCD12x3D: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 1044 | case LCD12x3D1: // Special mode for KS0078 and PCF21XX |
wim | 32:59c4b8f648d4 | 1045 | case LCD12x4D: // Special mode for KS0078 and PCF21XX: |
wim | 33:900a94bc7585 | 1046 | case LCD16x3D: // Special mode for KS0078 |
wim | 32:59c4b8f648d4 | 1047 | // case LCD16x3D1: // Special mode for KS0078 |
wim | 30:033048611c01 | 1048 | // case LCD24x3D: // Special mode for KS0078 |
wim | 32:59c4b8f648d4 | 1049 | // case LCD24x3D1: // Special mode for KS0078 |
wim | 30:033048611c01 | 1050 | case LCD24x4D: // Special mode for KS0078 |
wim | 30:033048611c01 | 1051 | error("Error: LCD Controller type does not support this Display type\n\r"); |
wim | 30:033048611c01 | 1052 | break; |
wim | 30:033048611c01 | 1053 | |
wim | 30:033048611c01 | 1054 | // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4) |
wim | 29:a3663151aa65 | 1055 | default: |
wim | 32:59c4b8f648d4 | 1056 | _function = 0x08; // Function set 001 DL N F - - |
wim | 29:a3663151aa65 | 1057 | // DL=0 (4 bits bus) |
wim | 29:a3663151aa65 | 1058 | // Note: 4 bit mode is ignored for native SPI and I2C devices |
wim | 29:a3663151aa65 | 1059 | // N=1 (2 lines) |
wim | 29:a3663151aa65 | 1060 | // F=0 (5x7 dots font, only option for 2 line display) |
wim | 32:59c4b8f648d4 | 1061 | // - (Don't care) |
wim | 29:a3663151aa65 | 1062 | break; |
wim | 29:a3663151aa65 | 1063 | } // switch type |
wim | 10:dd9b3a696acd | 1064 | |
wim | 34:e5a0dcb43ecc | 1065 | _writeCommand(0x20 | _function); |
wim | 29:a3663151aa65 | 1066 | break; // case default Controller |
wim | 29:a3663151aa65 | 1067 | |
wim | 34:e5a0dcb43ecc | 1068 | } // switch Controller specific initialisations |
wim | 10:dd9b3a696acd | 1069 | |
wim | 30:033048611c01 | 1070 | // Controller general initialisations |
wim | 32:59c4b8f648d4 | 1071 | // _writeCommand(0x01); // cls, and set cursor to 0 |
wim | 32:59c4b8f648d4 | 1072 | // wait_ms(10); // The CLS command takes 1.64 ms. |
wim | 32:59c4b8f648d4 | 1073 | // // Since we are not using the Busy flag, Lets be safe and take 10 ms |
wim | 28:30fa94f7341c | 1074 | |
wim | 28:30fa94f7341c | 1075 | _writeCommand(0x02); // Return Home |
wim | 28:30fa94f7341c | 1076 | // Cursor Home, DDRAM Address to Origin |
wim | 28:30fa94f7341c | 1077 | |
wim | 28:30fa94f7341c | 1078 | _writeCommand(0x06); // Entry Mode 0000 0 1 I/D S |
wim | 13:24506ba22480 | 1079 | // Cursor Direction and Display Shift |
wim | 28:30fa94f7341c | 1080 | // I/D=1 (Cur incr) |
wim | 28:30fa94f7341c | 1081 | // S=0 (No display shift) |
wim | 10:dd9b3a696acd | 1082 | |
wim | 29:a3663151aa65 | 1083 | _writeCommand(0x14); // Cursor or Display shift 0001 S/C R/L x x |
wim | 29:a3663151aa65 | 1084 | // S/C=0 Cursor moves |
wim | 29:a3663151aa65 | 1085 | // R/L=1 Right |
wim | 29:a3663151aa65 | 1086 | // |
wim | 29:a3663151aa65 | 1087 | |
wim | 13:24506ba22480 | 1088 | // _writeCommand(0x0C); // Display Ctrl 0000 1 D C B |
wim | 17:652ab113bc2e | 1089 | // // Display On, Cursor Off, Blink Off |
wim | 21:9eb628d9e164 | 1090 | setCursor(CurOff_BlkOff); |
wim | 21:9eb628d9e164 | 1091 | setMode(DispOn); |
simon | 1:ac48b187213c | 1092 | } |
simon | 1:ac48b187213c | 1093 | |
wim | 8:03116f75b66e | 1094 | |
wim | 21:9eb628d9e164 | 1095 | /** Clear the screen, Cursor home. |
wim | 21:9eb628d9e164 | 1096 | */ |
wim | 21:9eb628d9e164 | 1097 | void TextLCD_Base::cls() { |
wim | 15:b70ebfffb258 | 1098 | |
wim | 15:b70ebfffb258 | 1099 | // Select and configure second LCD controller when needed |
wim | 15:b70ebfffb258 | 1100 | if(_type==LCD40x4) { |
wim | 21:9eb628d9e164 | 1101 | _ctrl_idx=_LCDCtrl_1; // Select 2nd controller |
wim | 15:b70ebfffb258 | 1102 | |
wim | 15:b70ebfffb258 | 1103 | // Second LCD controller Cursor always Off |
wim | 21:9eb628d9e164 | 1104 | _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff); |
wim | 15:b70ebfffb258 | 1105 | |
wim | 15:b70ebfffb258 | 1106 | // Second LCD controller Clearscreen |
wim | 27:22d5086f6ba6 | 1107 | _writeCommand(0x01); // cls, and set cursor to 0 |
wim | 29:a3663151aa65 | 1108 | wait_ms(10); // The CLS command takes 1.64 ms. |
wim | 29:a3663151aa65 | 1109 | // Since we are not using the Busy flag, Lets be safe and take 10 ms |
wim | 15:b70ebfffb258 | 1110 | |
wim | 21:9eb628d9e164 | 1111 | _ctrl_idx=_LCDCtrl_0; // Select primary controller |
wim | 15:b70ebfffb258 | 1112 | } |
wim | 15:b70ebfffb258 | 1113 | |
wim | 15:b70ebfffb258 | 1114 | // Primary LCD controller Clearscreen |
wim | 27:22d5086f6ba6 | 1115 | _writeCommand(0x01); // cls, and set cursor to 0 |
wim | 29:a3663151aa65 | 1116 | wait_ms(10); // The CLS command takes 1.64 ms. |
wim | 29:a3663151aa65 | 1117 | // Since we are not using the Busy flag, Lets be safe and take 10 ms |
wim | 15:b70ebfffb258 | 1118 | |
wim | 15:b70ebfffb258 | 1119 | // Restore cursormode on primary LCD controller when needed |
wim | 15:b70ebfffb258 | 1120 | if(_type==LCD40x4) { |
wim | 17:652ab113bc2e | 1121 | _setCursorAndDisplayMode(_currentMode,_currentCursor); |
wim | 15:b70ebfffb258 | 1122 | } |
wim | 15:b70ebfffb258 | 1123 | |
wim | 29:a3663151aa65 | 1124 | setAddress(0, 0); // Reset Cursor location |
wim | 32:59c4b8f648d4 | 1125 | // Note: This is needed because some displays (eg PCF21XX) don't use line 0 in the '3 Line' mode. |
simon | 1:ac48b187213c | 1126 | } |
simon | 1:ac48b187213c | 1127 | |
wim | 29:a3663151aa65 | 1128 | /** Locate cursor to a screen column and row |
wim | 29:a3663151aa65 | 1129 | * |
wim | 29:a3663151aa65 | 1130 | * @param column The horizontal position from the left, indexed from 0 |
wim | 29:a3663151aa65 | 1131 | * @param row The vertical position from the top, indexed from 0 |
wim | 29:a3663151aa65 | 1132 | */ |
wim | 21:9eb628d9e164 | 1133 | void TextLCD_Base::locate(int column, int row) { |
wim | 15:b70ebfffb258 | 1134 | |
wim | 15:b70ebfffb258 | 1135 | // setAddress() does all the heavy lifting: |
wim | 15:b70ebfffb258 | 1136 | // check column and row sanity, |
wim | 15:b70ebfffb258 | 1137 | // switch controllers for LCD40x4 if needed |
wim | 15:b70ebfffb258 | 1138 | // switch cursor for LCD40x4 if needed |
wim | 15:b70ebfffb258 | 1139 | // set the new memory address to show cursor at correct location |
wim | 32:59c4b8f648d4 | 1140 | setAddress(column, row); |
wim | 15:b70ebfffb258 | 1141 | } |
wim | 30:033048611c01 | 1142 | |
wim | 15:b70ebfffb258 | 1143 | |
wim | 21:9eb628d9e164 | 1144 | /** Write a single character (Stream implementation) |
wim | 21:9eb628d9e164 | 1145 | */ |
wim | 21:9eb628d9e164 | 1146 | int TextLCD_Base::_putc(int value) { |
wim | 15:b70ebfffb258 | 1147 | int addr; |
wim | 15:b70ebfffb258 | 1148 | |
wim | 15:b70ebfffb258 | 1149 | if (value == '\n') { |
wim | 15:b70ebfffb258 | 1150 | //No character to write |
wim | 15:b70ebfffb258 | 1151 | |
wim | 15:b70ebfffb258 | 1152 | //Update Cursor |
wim | 15:b70ebfffb258 | 1153 | _column = 0; |
wim | 15:b70ebfffb258 | 1154 | _row++; |
wim | 15:b70ebfffb258 | 1155 | if (_row >= rows()) { |
wim | 15:b70ebfffb258 | 1156 | _row = 0; |
wim | 15:b70ebfffb258 | 1157 | } |
wim | 15:b70ebfffb258 | 1158 | } |
wim | 15:b70ebfffb258 | 1159 | else { |
wim | 15:b70ebfffb258 | 1160 | //Character to write |
wim | 15:b70ebfffb258 | 1161 | _writeData(value); |
wim | 15:b70ebfffb258 | 1162 | |
wim | 15:b70ebfffb258 | 1163 | //Update Cursor |
wim | 15:b70ebfffb258 | 1164 | _column++; |
wim | 15:b70ebfffb258 | 1165 | if (_column >= columns()) { |
wim | 15:b70ebfffb258 | 1166 | _column = 0; |
wim | 15:b70ebfffb258 | 1167 | _row++; |
wim | 15:b70ebfffb258 | 1168 | if (_row >= rows()) { |
wim | 15:b70ebfffb258 | 1169 | _row = 0; |
wim | 15:b70ebfffb258 | 1170 | } |
wim | 15:b70ebfffb258 | 1171 | } |
wim | 15:b70ebfffb258 | 1172 | } //else |
wim | 15:b70ebfffb258 | 1173 | |
wim | 15:b70ebfffb258 | 1174 | //Set next memoryaddress, make sure cursor blinks at next location |
wim | 15:b70ebfffb258 | 1175 | addr = getAddress(_column, _row); |
wim | 15:b70ebfffb258 | 1176 | _writeCommand(0x80 | addr); |
wim | 15:b70ebfffb258 | 1177 | |
wim | 15:b70ebfffb258 | 1178 | return value; |
wim | 15:b70ebfffb258 | 1179 | } |
wim | 15:b70ebfffb258 | 1180 | |
wim | 15:b70ebfffb258 | 1181 | |
wim | 16:c276b75e6585 | 1182 | // get a single character (Stream implementation) |
wim | 21:9eb628d9e164 | 1183 | int TextLCD_Base::_getc() { |
simon | 1:ac48b187213c | 1184 | return -1; |
simon | 1:ac48b187213c | 1185 | } |
simon | 1:ac48b187213c | 1186 | |
wim | 14:0c32b66b14b8 | 1187 | |
wim | 34:e5a0dcb43ecc | 1188 | #if(LCD_PRINTF != 1) |
wim | 34:e5a0dcb43ecc | 1189 | /** Write a character to the LCD |
wim | 34:e5a0dcb43ecc | 1190 | * |
wim | 34:e5a0dcb43ecc | 1191 | * @param c The character to write to the display |
wim | 34:e5a0dcb43ecc | 1192 | */ |
wim | 34:e5a0dcb43ecc | 1193 | int TextLCD_Base::putc(int c){ |
wim | 34:e5a0dcb43ecc | 1194 | return _putc(c); |
wim | 34:e5a0dcb43ecc | 1195 | } |
wim | 34:e5a0dcb43ecc | 1196 | |
wim | 34:e5a0dcb43ecc | 1197 | |
wim | 34:e5a0dcb43ecc | 1198 | /** Write a raw string to the LCD |
wim | 34:e5a0dcb43ecc | 1199 | * |
wim | 34:e5a0dcb43ecc | 1200 | * @param string text, may be followed by variables to emulate formatting the string. |
wim | 34:e5a0dcb43ecc | 1201 | * However, printf formatting is NOT supported and variables will be ignored! |
wim | 34:e5a0dcb43ecc | 1202 | */ |
wim | 34:e5a0dcb43ecc | 1203 | int TextLCD_Base::printf(const char* text, ...) { |
wim | 34:e5a0dcb43ecc | 1204 | |
wim | 34:e5a0dcb43ecc | 1205 | while (*text !=0) { |
wim | 34:e5a0dcb43ecc | 1206 | _putc(*text); |
wim | 34:e5a0dcb43ecc | 1207 | text++; |
wim | 34:e5a0dcb43ecc | 1208 | } |
wim | 34:e5a0dcb43ecc | 1209 | return 0; |
wim | 34:e5a0dcb43ecc | 1210 | } |
wim | 34:e5a0dcb43ecc | 1211 | #endif |
wim | 34:e5a0dcb43ecc | 1212 | |
wim | 34:e5a0dcb43ecc | 1213 | |
wim | 34:e5a0dcb43ecc | 1214 | |
wim | 17:652ab113bc2e | 1215 | // Write a nibble using the 4-bit interface |
wim | 21:9eb628d9e164 | 1216 | void TextLCD_Base::_writeNibble(int value) { |
wim | 17:652ab113bc2e | 1217 | |
wim | 17:652ab113bc2e | 1218 | // Enable is Low |
wim | 21:9eb628d9e164 | 1219 | this->_setEnable(true); |
wim | 21:9eb628d9e164 | 1220 | this->_setData(value & 0x0F); // Low nibble |
wim | 17:652ab113bc2e | 1221 | wait_us(1); // Data setup time |
wim | 21:9eb628d9e164 | 1222 | this->_setEnable(false); |
wim | 17:652ab113bc2e | 1223 | wait_us(1); // Datahold time |
wim | 17:652ab113bc2e | 1224 | |
wim | 17:652ab113bc2e | 1225 | // Enable is Low |
wim | 17:652ab113bc2e | 1226 | } |
wim | 17:652ab113bc2e | 1227 | |
wim | 16:c276b75e6585 | 1228 | // Write a byte using the 4-bit interface |
wim | 21:9eb628d9e164 | 1229 | void TextLCD_Base::_writeByte(int value) { |
wim | 15:b70ebfffb258 | 1230 | |
wim | 15:b70ebfffb258 | 1231 | // Enable is Low |
wim | 21:9eb628d9e164 | 1232 | this->_setEnable(true); |
wim | 21:9eb628d9e164 | 1233 | this->_setData(value >> 4); // High nibble |
wim | 15:b70ebfffb258 | 1234 | wait_us(1); // Data setup time |
wim | 21:9eb628d9e164 | 1235 | this->_setEnable(false); |
wim | 15:b70ebfffb258 | 1236 | wait_us(1); // Data hold time |
wim | 15:b70ebfffb258 | 1237 | |
wim | 21:9eb628d9e164 | 1238 | this->_setEnable(true); |
wim | 21:9eb628d9e164 | 1239 | this->_setData(value >> 0); // Low nibble |
wim | 15:b70ebfffb258 | 1240 | wait_us(1); // Data setup time |
wim | 21:9eb628d9e164 | 1241 | this->_setEnable(false); |
wim | 15:b70ebfffb258 | 1242 | wait_us(1); // Datahold time |
wim | 15:b70ebfffb258 | 1243 | |
wim | 15:b70ebfffb258 | 1244 | // Enable is Low |
simon | 1:ac48b187213c | 1245 | } |
simon | 1:ac48b187213c | 1246 | |
wim | 21:9eb628d9e164 | 1247 | // Write a command byte to the LCD controller |
wim | 21:9eb628d9e164 | 1248 | void TextLCD_Base::_writeCommand(int command) { |
wim | 15:b70ebfffb258 | 1249 | |
wim | 21:9eb628d9e164 | 1250 | this->_setRS(false); |
wim | 16:c276b75e6585 | 1251 | wait_us(1); // Data setup time for RS |
wim | 15:b70ebfffb258 | 1252 | |
wim | 21:9eb628d9e164 | 1253 | this->_writeByte(command); |
wim | 15:b70ebfffb258 | 1254 | wait_us(40); // most instructions take 40us |
simon | 1:ac48b187213c | 1255 | } |
simon | 1:ac48b187213c | 1256 | |
wim | 21:9eb628d9e164 | 1257 | // Write a data byte to the LCD controller |
wim | 21:9eb628d9e164 | 1258 | void TextLCD_Base::_writeData(int data) { |
wim | 15:b70ebfffb258 | 1259 | |
wim | 21:9eb628d9e164 | 1260 | this->_setRS(true); |
wim | 16:c276b75e6585 | 1261 | wait_us(1); // Data setup time for RS |
wim | 15:b70ebfffb258 | 1262 | |
wim | 21:9eb628d9e164 | 1263 | this->_writeByte(data); |
wim | 15:b70ebfffb258 | 1264 | wait_us(40); // data writes take 40us |
simon | 1:ac48b187213c | 1265 | } |
simon | 1:ac48b187213c | 1266 | |
wim | 8:03116f75b66e | 1267 | |
wim | 32:59c4b8f648d4 | 1268 | // This replaces the original _address() method. |
wim | 8:03116f75b66e | 1269 | // It is confusing since it returns the memoryaddress or-ed with the set memorycommand 0x80. |
wim | 8:03116f75b66e | 1270 | // Left it in here for compatibility with older code. New applications should use getAddress() instead. |
wim | 21:9eb628d9e164 | 1271 | int TextLCD_Base::_address(int column, int row) { |
wim | 8:03116f75b66e | 1272 | return 0x80 | getAddress(column, row); |
wim | 8:03116f75b66e | 1273 | } |
wim | 8:03116f75b66e | 1274 | |
wim | 30:033048611c01 | 1275 | |
wim | 30:033048611c01 | 1276 | // This is new method to return the memory address based on row, column and displaytype. |
wim | 30:033048611c01 | 1277 | // |
wim | 30:033048611c01 | 1278 | /** Return the memoryaddress of screen column and row location |
wim | 30:033048611c01 | 1279 | * |
wim | 30:033048611c01 | 1280 | * @param column The horizontal position from the left, indexed from 0 |
wim | 30:033048611c01 | 1281 | * @param row The vertical position from the top, indexed from 0 |
wim | 30:033048611c01 | 1282 | * @param return The memoryaddress of screen column and row location |
wim | 30:033048611c01 | 1283 | * |
wim | 30:033048611c01 | 1284 | */ |
wim | 30:033048611c01 | 1285 | int TextLCD_Base::getAddress(int column, int row) { |
wim | 30:033048611c01 | 1286 | |
wim | 30:033048611c01 | 1287 | switch (_addr_mode) { |
wim | 30:033048611c01 | 1288 | |
wim | 30:033048611c01 | 1289 | case LCD_T_A: |
wim | 30:033048611c01 | 1290 | //Default addressing mode for 1, 2 and 4 rows (except 40x4) |
wim | 30:033048611c01 | 1291 | //The two available rows are split and stacked on top of eachother. Addressing for 3rd and 4th line continues where lines 1 and 2 were split. |
wim | 30:033048611c01 | 1292 | //Displays top rows when less than four are used. |
wim | 30:033048611c01 | 1293 | switch (row) { |
wim | 30:033048611c01 | 1294 | case 0: |
wim | 30:033048611c01 | 1295 | return 0x00 + column; |
wim | 30:033048611c01 | 1296 | case 1: |
wim | 30:033048611c01 | 1297 | return 0x40 + column; |
wim | 30:033048611c01 | 1298 | case 2: |
wim | 30:033048611c01 | 1299 | return 0x00 + _nr_cols + column; |
wim | 30:033048611c01 | 1300 | case 3: |
wim | 30:033048611c01 | 1301 | return 0x40 + _nr_cols + column; |
wim | 30:033048611c01 | 1302 | // Should never get here. |
wim | 30:033048611c01 | 1303 | default: |
wim | 30:033048611c01 | 1304 | return 0x00; |
wim | 30:033048611c01 | 1305 | } |
wim | 30:033048611c01 | 1306 | |
wim | 30:033048611c01 | 1307 | case LCD_T_B: |
wim | 30:033048611c01 | 1308 | // LCD8x2B is a special layout of LCD16x1 |
wim | 30:033048611c01 | 1309 | if (row==0) |
wim | 30:033048611c01 | 1310 | return 0x00 + column; |
wim | 30:033048611c01 | 1311 | else |
wim | 30:033048611c01 | 1312 | // return _nr_cols + column; |
wim | 30:033048611c01 | 1313 | return 0x08 + column; |
wim | 30:033048611c01 | 1314 | |
wim | 30:033048611c01 | 1315 | case LCD_T_C: |
wim | 30:033048611c01 | 1316 | // LCD16x1C is a special layout of LCD8x2 |
wim | 33:900a94bc7585 | 1317 | // LCD32x1C is a special layout of LCD16x2 |
wim | 33:900a94bc7585 | 1318 | // LCD40x1C is a special layout of LCD20x2 |
wim | 33:900a94bc7585 | 1319 | #if(0) |
wim | 32:59c4b8f648d4 | 1320 | if (column < 8) |
wim | 30:033048611c01 | 1321 | return 0x00 + column; |
wim | 30:033048611c01 | 1322 | else |
wim | 30:033048611c01 | 1323 | return 0x40 + (column - 8); |
wim | 32:59c4b8f648d4 | 1324 | #else |
wim | 32:59c4b8f648d4 | 1325 | if (column < (_nr_cols >> 1)) |
wim | 32:59c4b8f648d4 | 1326 | return 0x00 + column; |
wim | 32:59c4b8f648d4 | 1327 | else |
wim | 32:59c4b8f648d4 | 1328 | return 0x40 + (column - (_nr_cols >> 1)); |
wim | 32:59c4b8f648d4 | 1329 | #endif |
wim | 30:033048611c01 | 1330 | |
wim | 30:033048611c01 | 1331 | // Not sure about this one, seems wrong. |
wim | 30:033048611c01 | 1332 | // Left in for compatibility with original library |
wim | 30:033048611c01 | 1333 | // case LCD16x2B: |
wim | 30:033048611c01 | 1334 | // return 0x00 + (row * 40) + column; |
wim | 30:033048611c01 | 1335 | |
wim | 30:033048611c01 | 1336 | case LCD_T_D: |
wim | 33:900a94bc7585 | 1337 | //Alternate addressing mode for 3 and 4 row displays (except 40x4). Used by PCF21XX, KS0078, SSD1803 |
wim | 30:033048611c01 | 1338 | //The 4 available rows start at a hardcoded address. |
wim | 30:033048611c01 | 1339 | //Displays top rows when less than four are used. |
wim | 30:033048611c01 | 1340 | switch (row) { |
wim | 30:033048611c01 | 1341 | case 0: |
wim | 30:033048611c01 | 1342 | return 0x00 + column; |
wim | 30:033048611c01 | 1343 | case 1: |
wim | 30:033048611c01 | 1344 | return 0x20 + column; |
wim | 30:033048611c01 | 1345 | case 2: |
wim | 30:033048611c01 | 1346 | return 0x40 + column; |
wim | 30:033048611c01 | 1347 | case 3: |
wim | 30:033048611c01 | 1348 | return 0x60 + column; |
wim | 30:033048611c01 | 1349 | // Should never get here. |
wim | 30:033048611c01 | 1350 | default: |
wim | 30:033048611c01 | 1351 | return 0x00; |
wim | 30:033048611c01 | 1352 | } |
wim | 30:033048611c01 | 1353 | |
wim | 30:033048611c01 | 1354 | case LCD_T_D1: |
wim | 32:59c4b8f648d4 | 1355 | //Alternate addressing mode for 3 row displays. Used by PCF21XX, KS0078, SSD1803 |
wim | 30:033048611c01 | 1356 | //The 4 available rows start at a hardcoded address. |
wim | 30:033048611c01 | 1357 | //Skips top row of 4 row display and starts display at row 1 |
wim | 30:033048611c01 | 1358 | switch (row) { |
wim | 30:033048611c01 | 1359 | case 0: |
wim | 30:033048611c01 | 1360 | return 0x20 + column; |
wim | 30:033048611c01 | 1361 | case 1: |
wim | 30:033048611c01 | 1362 | return 0x40 + column; |
wim | 30:033048611c01 | 1363 | case 2: |
wim | 30:033048611c01 | 1364 | return 0x60 + column; |
wim | 30:033048611c01 | 1365 | // Should never get here. |
wim | 30:033048611c01 | 1366 | default: |
wim | 30:033048611c01 | 1367 | return 0x00; |
wim | 30:033048611c01 | 1368 | } |
wim | 30:033048611c01 | 1369 | |
wim | 30:033048611c01 | 1370 | case LCD_T_E: |
wim | 30:033048611c01 | 1371 | // LCD40x4 is a special case since it has 2 controllers. |
wim | 30:033048611c01 | 1372 | // Each controller is configured as 40x2 (Type A) |
wim | 30:033048611c01 | 1373 | if (row<2) { |
wim | 30:033048611c01 | 1374 | // Test to see if we need to switch between controllers |
wim | 30:033048611c01 | 1375 | if (_ctrl_idx != _LCDCtrl_0) { |
wim | 30:033048611c01 | 1376 | |
wim | 30:033048611c01 | 1377 | // Second LCD controller Cursor Off |
wim | 30:033048611c01 | 1378 | _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff); |
wim | 30:033048611c01 | 1379 | |
wim | 30:033048611c01 | 1380 | // Select primary controller |
wim | 30:033048611c01 | 1381 | _ctrl_idx = _LCDCtrl_0; |
wim | 30:033048611c01 | 1382 | |
wim | 30:033048611c01 | 1383 | // Restore cursormode on primary LCD controller |
wim | 30:033048611c01 | 1384 | _setCursorAndDisplayMode(_currentMode, _currentCursor); |
wim | 30:033048611c01 | 1385 | } |
wim | 30:033048611c01 | 1386 | |
wim | 30:033048611c01 | 1387 | return 0x00 + (row * 0x40) + column; |
wim | 30:033048611c01 | 1388 | } |
wim | 30:033048611c01 | 1389 | else { |
wim | 30:033048611c01 | 1390 | |
wim | 30:033048611c01 | 1391 | // Test to see if we need to switch between controllers |
wim | 30:033048611c01 | 1392 | if (_ctrl_idx != _LCDCtrl_1) { |
wim | 30:033048611c01 | 1393 | // Primary LCD controller Cursor Off |
wim | 30:033048611c01 | 1394 | _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff); |
wim | 30:033048611c01 | 1395 | |
wim | 30:033048611c01 | 1396 | // Select secondary controller |
wim | 30:033048611c01 | 1397 | _ctrl_idx = _LCDCtrl_1; |
wim | 30:033048611c01 | 1398 | |
wim | 30:033048611c01 | 1399 | // Restore cursormode on secondary LCD controller |
wim | 30:033048611c01 | 1400 | _setCursorAndDisplayMode(_currentMode, _currentCursor); |
wim | 30:033048611c01 | 1401 | } |
wim | 30:033048611c01 | 1402 | |
wim | 30:033048611c01 | 1403 | return 0x00 + ((row-2) * 0x40) + column; |
wim | 30:033048611c01 | 1404 | } |
wim | 30:033048611c01 | 1405 | |
wim | 32:59c4b8f648d4 | 1406 | case LCD_T_F: |
wim | 32:59c4b8f648d4 | 1407 | //Alternate addressing mode for 3 row displays. |
wim | 32:59c4b8f648d4 | 1408 | //The first half of 3rd row continues from 1st row, the second half continues from 2nd row. |
wim | 32:59c4b8f648d4 | 1409 | switch (row) { |
wim | 32:59c4b8f648d4 | 1410 | case 0: |
wim | 32:59c4b8f648d4 | 1411 | return 0x00 + column; |
wim | 32:59c4b8f648d4 | 1412 | case 1: |
wim | 32:59c4b8f648d4 | 1413 | return 0x40 + column; |
wim | 32:59c4b8f648d4 | 1414 | case 2: |
wim | 32:59c4b8f648d4 | 1415 | if (column < (_nr_cols >> 1)) // check first or second half of line |
wim | 32:59c4b8f648d4 | 1416 | return (0x00 + _nr_cols + column); |
wim | 32:59c4b8f648d4 | 1417 | else |
wim | 32:59c4b8f648d4 | 1418 | return (0x40 + _nr_cols + (column - (_nr_cols >> 1))); |
wim | 32:59c4b8f648d4 | 1419 | // Should never get here. |
wim | 32:59c4b8f648d4 | 1420 | default: |
wim | 32:59c4b8f648d4 | 1421 | return 0x00; |
wim | 32:59c4b8f648d4 | 1422 | } |
wim | 32:59c4b8f648d4 | 1423 | |
wim | 32:59c4b8f648d4 | 1424 | case LCD_T_G: |
wim | 32:59c4b8f648d4 | 1425 | //Alternate addressing mode for 3 row displays. Used by ST7036 |
wim | 32:59c4b8f648d4 | 1426 | switch (row) { |
wim | 32:59c4b8f648d4 | 1427 | case 0: |
wim | 32:59c4b8f648d4 | 1428 | return 0x00 + column; |
wim | 32:59c4b8f648d4 | 1429 | case 1: |
wim | 32:59c4b8f648d4 | 1430 | return 0x10 + column; |
wim | 32:59c4b8f648d4 | 1431 | case 2: |
wim | 32:59c4b8f648d4 | 1432 | return 0x20 + column; |
wim | 32:59c4b8f648d4 | 1433 | // Should never get here. |
wim | 32:59c4b8f648d4 | 1434 | default: |
wim | 32:59c4b8f648d4 | 1435 | return 0x00; |
wim | 32:59c4b8f648d4 | 1436 | } |
wim | 32:59c4b8f648d4 | 1437 | |
wim | 30:033048611c01 | 1438 | // Should never get here. |
wim | 30:033048611c01 | 1439 | default: |
wim | 30:033048611c01 | 1440 | return 0x00; |
wim | 32:59c4b8f648d4 | 1441 | |
wim | 32:59c4b8f648d4 | 1442 | } // switch _addr_mode |
wim | 30:033048611c01 | 1443 | } |
wim | 30:033048611c01 | 1444 | |
wim | 30:033048611c01 | 1445 | |
wim | 29:a3663151aa65 | 1446 | /** Set the memoryaddress of screen column and row location |
wim | 29:a3663151aa65 | 1447 | * |
wim | 29:a3663151aa65 | 1448 | * @param column The horizontal position from the left, indexed from 0 |
wim | 29:a3663151aa65 | 1449 | * @param row The vertical position from the top, indexed from 0 |
wim | 29:a3663151aa65 | 1450 | */ |
wim | 21:9eb628d9e164 | 1451 | void TextLCD_Base::setAddress(int column, int row) { |
wim | 15:b70ebfffb258 | 1452 | |
wim | 15:b70ebfffb258 | 1453 | // Sanity Check column |
wim | 15:b70ebfffb258 | 1454 | if (column < 0) { |
wim | 15:b70ebfffb258 | 1455 | _column = 0; |
wim | 15:b70ebfffb258 | 1456 | } |
wim | 15:b70ebfffb258 | 1457 | else if (column >= columns()) { |
wim | 15:b70ebfffb258 | 1458 | _column = columns() - 1; |
wim | 15:b70ebfffb258 | 1459 | } else _column = column; |
wim | 8:03116f75b66e | 1460 | |
wim | 15:b70ebfffb258 | 1461 | // Sanity Check row |
wim | 15:b70ebfffb258 | 1462 | if (row < 0) { |
wim | 15:b70ebfffb258 | 1463 | _row = 0; |
wim | 15:b70ebfffb258 | 1464 | } |
wim | 15:b70ebfffb258 | 1465 | else if (row >= rows()) { |
wim | 15:b70ebfffb258 | 1466 | _row = rows() - 1; |
wim | 15:b70ebfffb258 | 1467 | } else _row = row; |
wim | 15:b70ebfffb258 | 1468 | |
wim | 15:b70ebfffb258 | 1469 | |
wim | 15:b70ebfffb258 | 1470 | // Compute the memory address |
wim | 15:b70ebfffb258 | 1471 | // For LCD40x4: switch controllers if needed |
wim | 15:b70ebfffb258 | 1472 | // switch cursor if needed |
wim | 15:b70ebfffb258 | 1473 | int addr = getAddress(_column, _row); |
wim | 8:03116f75b66e | 1474 | |
wim | 13:24506ba22480 | 1475 | _writeCommand(0x80 | addr); |
wim | 8:03116f75b66e | 1476 | } |
simon | 1:ac48b187213c | 1477 | |
wim | 29:a3663151aa65 | 1478 | |
wim | 29:a3663151aa65 | 1479 | /** Return the number of columns |
wim | 29:a3663151aa65 | 1480 | * |
wim | 29:a3663151aa65 | 1481 | * @param return The number of columns |
wim | 30:033048611c01 | 1482 | * |
wim | 30:033048611c01 | 1483 | * Note: some configurations are commented out because they have not yet been tested due to lack of hardware |
wim | 29:a3663151aa65 | 1484 | */ |
wim | 21:9eb628d9e164 | 1485 | int TextLCD_Base::columns() { |
wim | 30:033048611c01 | 1486 | |
wim | 30:033048611c01 | 1487 | // Columns encoded in b7..b0 |
wim | 30:033048611c01 | 1488 | //return (_type & 0xFF); |
wim | 31:ef31cd8a00d1 | 1489 | return _nr_cols; |
simon | 1:ac48b187213c | 1490 | } |
simon | 1:ac48b187213c | 1491 | |
wim | 29:a3663151aa65 | 1492 | /** Return the number of rows |
wim | 29:a3663151aa65 | 1493 | * |
wim | 29:a3663151aa65 | 1494 | * @param return The number of rows |
wim | 30:033048611c01 | 1495 | * |
wim | 30:033048611c01 | 1496 | * Note: some configurations are commented out because they have not yet been tested due to lack of hardware |
wim | 29:a3663151aa65 | 1497 | */ |
wim | 21:9eb628d9e164 | 1498 | int TextLCD_Base::rows() { |
wim | 30:033048611c01 | 1499 | |
wim | 30:033048611c01 | 1500 | // Rows encoded in b15..b8 |
wim | 30:033048611c01 | 1501 | //return ((_type >> 8) & 0xFF); |
wim | 30:033048611c01 | 1502 | return _nr_rows; |
simon | 1:ac48b187213c | 1503 | } |
wim | 10:dd9b3a696acd | 1504 | |
wim | 29:a3663151aa65 | 1505 | /** Set the Cursormode |
wim | 29:a3663151aa65 | 1506 | * |
wim | 29:a3663151aa65 | 1507 | * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn) |
wim | 29:a3663151aa65 | 1508 | */ |
wim | 21:9eb628d9e164 | 1509 | void TextLCD_Base::setCursor(LCDCursor cursorMode) { |
wim | 15:b70ebfffb258 | 1510 | |
wim | 17:652ab113bc2e | 1511 | // Save new cursor mode, needed when 2 controllers are in use or when display is switched off/on |
wim | 17:652ab113bc2e | 1512 | _currentCursor = cursorMode; |
wim | 10:dd9b3a696acd | 1513 | |
wim | 17:652ab113bc2e | 1514 | // Configure only current LCD controller |
wim | 31:ef31cd8a00d1 | 1515 | _setCursorAndDisplayMode(_currentMode, _currentCursor); |
wim | 15:b70ebfffb258 | 1516 | } |
wim | 15:b70ebfffb258 | 1517 | |
wim | 29:a3663151aa65 | 1518 | /** Set the Displaymode |
wim | 29:a3663151aa65 | 1519 | * |
wim | 29:a3663151aa65 | 1520 | * @param displayMode The Display mode (DispOff, DispOn) |
wim | 29:a3663151aa65 | 1521 | */ |
wim | 21:9eb628d9e164 | 1522 | void TextLCD_Base::setMode(LCDMode displayMode) { |
wim | 17:652ab113bc2e | 1523 | |
wim | 17:652ab113bc2e | 1524 | // Save new displayMode, needed when 2 controllers are in use or when cursor is changed |
wim | 17:652ab113bc2e | 1525 | _currentMode = displayMode; |
wim | 15:b70ebfffb258 | 1526 | |
wim | 17:652ab113bc2e | 1527 | // Select and configure second LCD controller when needed |
wim | 17:652ab113bc2e | 1528 | if(_type==LCD40x4) { |
wim | 21:9eb628d9e164 | 1529 | if (_ctrl_idx==_LCDCtrl_0) { |
wim | 17:652ab113bc2e | 1530 | // Configure primary LCD controller |
wim | 17:652ab113bc2e | 1531 | _setCursorAndDisplayMode(_currentMode, _currentCursor); |
wim | 11:9ec02df863a1 | 1532 | |
wim | 17:652ab113bc2e | 1533 | // Select 2nd controller |
wim | 21:9eb628d9e164 | 1534 | _ctrl_idx=_LCDCtrl_1; |
wim | 17:652ab113bc2e | 1535 | |
wim | 17:652ab113bc2e | 1536 | // Configure secondary LCD controller |
wim | 21:9eb628d9e164 | 1537 | _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff); |
wim | 11:9ec02df863a1 | 1538 | |
wim | 17:652ab113bc2e | 1539 | // Restore current controller |
wim | 21:9eb628d9e164 | 1540 | _ctrl_idx=_LCDCtrl_0; |
wim | 17:652ab113bc2e | 1541 | } |
wim | 17:652ab113bc2e | 1542 | else { |
wim | 17:652ab113bc2e | 1543 | // Select primary controller |
wim | 21:9eb628d9e164 | 1544 | _ctrl_idx=_LCDCtrl_0; |
wim | 17:652ab113bc2e | 1545 | |
wim | 17:652ab113bc2e | 1546 | // Configure primary LCD controller |
wim | 21:9eb628d9e164 | 1547 | _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff); |
wim | 17:652ab113bc2e | 1548 | |
wim | 17:652ab113bc2e | 1549 | // Restore current controller |
wim | 21:9eb628d9e164 | 1550 | _ctrl_idx=_LCDCtrl_1; |
wim | 11:9ec02df863a1 | 1551 | |
wim | 17:652ab113bc2e | 1552 | // Configure secondary LCD controller |
wim | 17:652ab113bc2e | 1553 | _setCursorAndDisplayMode(_currentMode, _currentCursor); |
wim | 10:dd9b3a696acd | 1554 | } |
wim | 17:652ab113bc2e | 1555 | } |
wim | 17:652ab113bc2e | 1556 | else { |
wim | 17:652ab113bc2e | 1557 | // Configure primary LCD controller |
wim | 17:652ab113bc2e | 1558 | _setCursorAndDisplayMode(_currentMode, _currentCursor); |
wim | 30:033048611c01 | 1559 | } |
wim | 17:652ab113bc2e | 1560 | } |
wim | 17:652ab113bc2e | 1561 | |
wim | 17:652ab113bc2e | 1562 | |
wim | 29:a3663151aa65 | 1563 | /** Low level method to restore the cursortype and display mode for current controller |
wim | 29:a3663151aa65 | 1564 | */ |
wim | 21:9eb628d9e164 | 1565 | void TextLCD_Base::_setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType) { |
wim | 17:652ab113bc2e | 1566 | |
wim | 17:652ab113bc2e | 1567 | // Configure current LCD controller |
wim | 17:652ab113bc2e | 1568 | _writeCommand(0x08 | displayMode | cursorType); |
wim | 10:dd9b3a696acd | 1569 | } |
wim | 10:dd9b3a696acd | 1570 | |
wim | 29:a3663151aa65 | 1571 | /** Set the Backlight mode |
wim | 29:a3663151aa65 | 1572 | * |
wim | 29:a3663151aa65 | 1573 | * @param backlightMode The Backlight mode (LightOff, LightOn) |
wim | 29:a3663151aa65 | 1574 | */ |
wim | 21:9eb628d9e164 | 1575 | void TextLCD_Base::setBacklight(LCDBacklight backlightMode) { |
wim | 20:e0da005a777f | 1576 | |
wim | 20:e0da005a777f | 1577 | if (backlightMode == LightOn) { |
wim | 21:9eb628d9e164 | 1578 | this->_setBL(true); |
wim | 20:e0da005a777f | 1579 | } |
wim | 20:e0da005a777f | 1580 | else { |
wim | 21:9eb628d9e164 | 1581 | this->_setBL(false); |
wim | 20:e0da005a777f | 1582 | } |
wim | 20:e0da005a777f | 1583 | } |
wim | 20:e0da005a777f | 1584 | |
wim | 29:a3663151aa65 | 1585 | /** Set User Defined Characters |
wim | 29:a3663151aa65 | 1586 | * |
wim | 34:e5a0dcb43ecc | 1587 | * @param unsigned char c The Index of the UDC (0..7) for HD44780 or clones and (0..15) for some more advanced controllers |
wim | 34:e5a0dcb43ecc | 1588 | * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits for bitpattern and 3 bits for blinkmode (advanced types)) |
wim | 29:a3663151aa65 | 1589 | */ |
wim | 21:9eb628d9e164 | 1590 | void TextLCD_Base::setUDC(unsigned char c, char *udc_data) { |
wim | 15:b70ebfffb258 | 1591 | |
wim | 15:b70ebfffb258 | 1592 | // Select and configure second LCD controller when needed |
wim | 15:b70ebfffb258 | 1593 | if(_type==LCD40x4) { |
wim | 19:c747b9e2e7b8 | 1594 | _LCDCtrl_Idx current_ctrl_idx = _ctrl_idx; // Temp save current controller |
wim | 15:b70ebfffb258 | 1595 | |
wim | 15:b70ebfffb258 | 1596 | // Select primary controller |
wim | 21:9eb628d9e164 | 1597 | _ctrl_idx=_LCDCtrl_0; |
wim | 15:b70ebfffb258 | 1598 | |
wim | 15:b70ebfffb258 | 1599 | // Configure primary LCD controller |
wim | 15:b70ebfffb258 | 1600 | _setUDC(c, udc_data); |
wim | 15:b70ebfffb258 | 1601 | |
wim | 15:b70ebfffb258 | 1602 | // Select 2nd controller |
wim | 21:9eb628d9e164 | 1603 | _ctrl_idx=_LCDCtrl_1; |
wim | 15:b70ebfffb258 | 1604 | |
wim | 15:b70ebfffb258 | 1605 | // Configure secondary LCD controller |
wim | 15:b70ebfffb258 | 1606 | _setUDC(c, udc_data); |
wim | 11:9ec02df863a1 | 1607 | |
wim | 15:b70ebfffb258 | 1608 | // Restore current controller |
wim | 19:c747b9e2e7b8 | 1609 | _ctrl_idx=current_ctrl_idx; |
wim | 15:b70ebfffb258 | 1610 | } |
wim | 15:b70ebfffb258 | 1611 | else { |
wim | 15:b70ebfffb258 | 1612 | // Configure primary LCD controller |
wim | 15:b70ebfffb258 | 1613 | _setUDC(c, udc_data); |
wim | 34:e5a0dcb43ecc | 1614 | } |
wim | 15:b70ebfffb258 | 1615 | } |
wim | 15:b70ebfffb258 | 1616 | |
wim | 34:e5a0dcb43ecc | 1617 | |
wim | 34:e5a0dcb43ecc | 1618 | #if(0) |
wim | 29:a3663151aa65 | 1619 | /** Low level method to store user defined characters for current controller |
wim | 34:e5a0dcb43ecc | 1620 | * |
wim | 34:e5a0dcb43ecc | 1621 | * @param unsigned char c The Index of the UDC (0..7) for HD44780 clones |
wim | 34:e5a0dcb43ecc | 1622 | * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits) |
wim | 29:a3663151aa65 | 1623 | */ |
wim | 21:9eb628d9e164 | 1624 | void TextLCD_Base::_setUDC(unsigned char c, char *udc_data) { |
wim | 15:b70ebfffb258 | 1625 | |
wim | 15:b70ebfffb258 | 1626 | // Select CG RAM for current LCD controller |
wim | 15:b70ebfffb258 | 1627 | _writeCommand(0x40 + ((c & 0x07) << 3)); //Set CG-RAM address, |
wim | 15:b70ebfffb258 | 1628 | //8 sequential locations needed per UDC |
wim | 15:b70ebfffb258 | 1629 | // Store UDC pattern |
wim | 11:9ec02df863a1 | 1630 | for (int i=0; i<8; i++) { |
wim | 13:24506ba22480 | 1631 | _writeData(*udc_data++); |
wim | 11:9ec02df863a1 | 1632 | } |
wim | 15:b70ebfffb258 | 1633 | |
wim | 15:b70ebfffb258 | 1634 | //Select DD RAM again for current LCD controller |
wim | 15:b70ebfffb258 | 1635 | int addr = getAddress(_column, _row); |
wim | 30:033048611c01 | 1636 | _writeCommand(0x80 | addr); |
wim | 11:9ec02df863a1 | 1637 | } |
wim | 34:e5a0dcb43ecc | 1638 | #else |
wim | 34:e5a0dcb43ecc | 1639 | /** Low level method to store user defined characters for current controller |
wim | 34:e5a0dcb43ecc | 1640 | * |
wim | 34:e5a0dcb43ecc | 1641 | * @param unsigned char c The Index of the UDC (0..7) for HD44780 clones and (0..15) for some more advanced controllers |
wim | 34:e5a0dcb43ecc | 1642 | * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits for bitpattern and 3 bits for blinkmode (advanced types)) |
wim | 34:e5a0dcb43ecc | 1643 | */ |
wim | 34:e5a0dcb43ecc | 1644 | void TextLCD_Base::_setUDC(unsigned char c, char *udc_data) { |
wim | 34:e5a0dcb43ecc | 1645 | |
wim | 34:e5a0dcb43ecc | 1646 | switch (_ctrl) { |
wim | 34:e5a0dcb43ecc | 1647 | case PCF2103_3V3 : // Some UDCs may be used for Icons |
wim | 34:e5a0dcb43ecc | 1648 | case PCF2113_3V3 : // Some UDCs may be used for Icons |
wim | 34:e5a0dcb43ecc | 1649 | case PCF2116_3V3 : |
wim | 34:e5a0dcb43ecc | 1650 | case PCF2116_5V : |
wim | 34:e5a0dcb43ecc | 1651 | case PCF2119_3V3 : // Some UDCs may be used for Icons |
wim | 34:e5a0dcb43ecc | 1652 | c = c & 0x0F; // mask down to valid range |
wim | 34:e5a0dcb43ecc | 1653 | break; |
wim | 34:e5a0dcb43ecc | 1654 | |
wim | 34:e5a0dcb43ecc | 1655 | default: |
wim | 34:e5a0dcb43ecc | 1656 | c = c & 0x07; // mask down to valid range |
wim | 34:e5a0dcb43ecc | 1657 | break; |
wim | 34:e5a0dcb43ecc | 1658 | } //switch _ctrl |
wim | 34:e5a0dcb43ecc | 1659 | |
wim | 34:e5a0dcb43ecc | 1660 | // Select DD RAM for current LCD controller |
wim | 34:e5a0dcb43ecc | 1661 | // This is needed to correctly set Bit 6 of the addresspointer for controllers that support 16 UDCs |
wim | 34:e5a0dcb43ecc | 1662 | _writeCommand(0x80 | ((c << 3) & 0x40)) ; |
wim | 34:e5a0dcb43ecc | 1663 | |
wim | 34:e5a0dcb43ecc | 1664 | // Select CG RAM for current LCD controller |
wim | 34:e5a0dcb43ecc | 1665 | _writeCommand(0x40 | ((c << 3) & 0x3F)); //Set CG-RAM address, (note that Bit 6 is retained and can not be set by this command !) |
wim | 34:e5a0dcb43ecc | 1666 | //8 sequential locations needed per UDC |
wim | 34:e5a0dcb43ecc | 1667 | // Store UDC pattern |
wim | 34:e5a0dcb43ecc | 1668 | for (int i=0; i<8; i++) { |
wim | 34:e5a0dcb43ecc | 1669 | _writeData(*udc_data++); |
wim | 34:e5a0dcb43ecc | 1670 | } |
wim | 34:e5a0dcb43ecc | 1671 | |
wim | 34:e5a0dcb43ecc | 1672 | //Select DD RAM again for current LCD controller and restore the addresspointer |
wim | 34:e5a0dcb43ecc | 1673 | int addr = getAddress(_column, _row); |
wim | 34:e5a0dcb43ecc | 1674 | _writeCommand(0x80 | addr); |
wim | 34:e5a0dcb43ecc | 1675 | } |
wim | 34:e5a0dcb43ecc | 1676 | #endif |
wim | 32:59c4b8f648d4 | 1677 | |
wim | 33:900a94bc7585 | 1678 | /** Set UDC Blink |
wim | 33:900a94bc7585 | 1679 | * setUDCBlink method is supported by some compatible devices (eg SSD1803) |
wim | 33:900a94bc7585 | 1680 | * |
wim | 33:900a94bc7585 | 1681 | * @param blinkMode The Blink mode (BlinkOff, BlinkOn) |
wim | 33:900a94bc7585 | 1682 | */ |
wim | 33:900a94bc7585 | 1683 | void TextLCD_Base::setUDCBlink(LCDBlink blinkMode){ |
wim | 33:900a94bc7585 | 1684 | // Blinking UDCs are enabled when a specific controlbit (BE) is set. |
wim | 33:900a94bc7585 | 1685 | // The blinking pixels in the UDC can be controlled by setting additional bits in the UDC bitpattern. |
wim | 33:900a94bc7585 | 1686 | // UDCs are defined by an 8 byte bitpattern. The P0..P5 form the character pattern. |
wim | 33:900a94bc7585 | 1687 | // P7 P6 P5 P4 P3 P2 P1 P0 |
wim | 33:900a94bc7585 | 1688 | // 0 B1 B0 x 0 1 1 1 0 |
wim | 33:900a94bc7585 | 1689 | // 1 B1 B0 x 1 0 0 0 1 |
wim | 33:900a94bc7585 | 1690 | // ............. |
wim | 33:900a94bc7585 | 1691 | // 7 B1 B0 x 1 0 0 0 1 |
wim | 33:900a94bc7585 | 1692 | // |
wim | 33:900a94bc7585 | 1693 | // Bit 6 and Bit 7 in the pattern will control the blinking mode when Blink is enabled through BE. |
wim | 33:900a94bc7585 | 1694 | // B1 B0 Mode |
wim | 33:900a94bc7585 | 1695 | // 0 0 No Blinking in this row of the UDC |
wim | 33:900a94bc7585 | 1696 | // 0 1 Enabled pixels in P4 will blink |
wim | 33:900a94bc7585 | 1697 | // 1 x Enabled pixels in P0..P4 will blink |
wim | 33:900a94bc7585 | 1698 | |
wim | 33:900a94bc7585 | 1699 | switch (blinkMode) { |
wim | 33:900a94bc7585 | 1700 | case BlinkOn: |
wim | 33:900a94bc7585 | 1701 | // Controllers that support UDC Blink |
wim | 33:900a94bc7585 | 1702 | switch (_ctrl) { |
wim | 33:900a94bc7585 | 1703 | case KS0078 : |
wim | 33:900a94bc7585 | 1704 | _function_1 |= 0x02; // Enable UDC Blink |
wim | 33:900a94bc7585 | 1705 | _writeCommand(0x20 | _function_1); // Function set 0 0 1 DL N RE(1) BE 0 (Ext Regs) |
wim | 33:900a94bc7585 | 1706 | |
wim | 33:900a94bc7585 | 1707 | _writeCommand(0x20 | _function); // Function set 0 0 1 DL N RE(0) DH REV (Std Regs) |
wim | 33:900a94bc7585 | 1708 | break; // case KS0078 Controller |
wim | 33:900a94bc7585 | 1709 | |
wim | 33:900a94bc7585 | 1710 | case US2066_3V3 : |
wim | 33:900a94bc7585 | 1711 | case SSD1803_3V3 : |
wim | 33:900a94bc7585 | 1712 | _function_1 |= 0x04; // Enable UDC Blink |
wim | 33:900a94bc7585 | 1713 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV |
wim | 33:900a94bc7585 | 1714 | // Select Ext Instr Set |
wim | 33:900a94bc7585 | 1715 | |
wim | 33:900a94bc7585 | 1716 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 33:900a94bc7585 | 1717 | // Select Std Instr set, Select IS=0 |
wim | 33:900a94bc7585 | 1718 | break; // case SSD1803, US2066 |
wim | 33:900a94bc7585 | 1719 | |
wim | 33:900a94bc7585 | 1720 | default: |
wim | 33:900a94bc7585 | 1721 | //Unsupported feature for other controllers |
wim | 33:900a94bc7585 | 1722 | break; |
wim | 33:900a94bc7585 | 1723 | } //switch _ctrl |
wim | 33:900a94bc7585 | 1724 | |
wim | 33:900a94bc7585 | 1725 | break; |
wim | 33:900a94bc7585 | 1726 | |
wim | 33:900a94bc7585 | 1727 | case BlinkOff: |
wim | 33:900a94bc7585 | 1728 | // Controllers that support UDC Blink |
wim | 33:900a94bc7585 | 1729 | switch (_ctrl) { |
wim | 33:900a94bc7585 | 1730 | case KS0078 : |
wim | 33:900a94bc7585 | 1731 | _function_1 &= ~0x02; // Disable UDC Blink |
wim | 33:900a94bc7585 | 1732 | _writeCommand(0x20 | _function_1); // Function set 0 0 1 DL N RE(1) BE 0 (Ext Regs) |
wim | 33:900a94bc7585 | 1733 | |
wim | 33:900a94bc7585 | 1734 | _writeCommand(0x20 | _function); // Function set 0 0 1 DL N RE(0) DH REV (Std Regs) |
wim | 33:900a94bc7585 | 1735 | break; // case KS0078 Controller |
wim | 33:900a94bc7585 | 1736 | |
wim | 33:900a94bc7585 | 1737 | case US2066_3V3 : |
wim | 33:900a94bc7585 | 1738 | case SSD1803_3V3 : |
wim | 33:900a94bc7585 | 1739 | _function_1 &= ~0x04; // Disable UDC Blink |
wim | 33:900a94bc7585 | 1740 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV |
wim | 33:900a94bc7585 | 1741 | // Select Ext Instr Set |
wim | 33:900a94bc7585 | 1742 | |
wim | 33:900a94bc7585 | 1743 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 33:900a94bc7585 | 1744 | // Select Std Instr set, Select IS=0 |
wim | 33:900a94bc7585 | 1745 | break; // case SSD1803, US2066 |
wim | 33:900a94bc7585 | 1746 | |
wim | 33:900a94bc7585 | 1747 | default: |
wim | 33:900a94bc7585 | 1748 | //Unsupported feature for other controllers |
wim | 33:900a94bc7585 | 1749 | break; |
wim | 33:900a94bc7585 | 1750 | } //switch _ctrl |
wim | 33:900a94bc7585 | 1751 | |
wim | 33:900a94bc7585 | 1752 | break; |
wim | 33:900a94bc7585 | 1753 | |
wim | 33:900a94bc7585 | 1754 | default: |
wim | 33:900a94bc7585 | 1755 | break; |
wim | 33:900a94bc7585 | 1756 | } // blinkMode |
wim | 33:900a94bc7585 | 1757 | |
wim | 33:900a94bc7585 | 1758 | } // setUDCBlink() |
wim | 33:900a94bc7585 | 1759 | |
wim | 33:900a94bc7585 | 1760 | |
wim | 32:59c4b8f648d4 | 1761 | /** Set Contrast |
wim | 32:59c4b8f648d4 | 1762 | * setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation |
wim | 32:59c4b8f648d4 | 1763 | * Initial code for ST70XX imported from fork by JH1PJL |
wim | 32:59c4b8f648d4 | 1764 | * |
wim | 32:59c4b8f648d4 | 1765 | * @param unsigned char c contrast data (6 significant bits, valid range 0..63, Value 0 will disable the Vgen) |
wim | 32:59c4b8f648d4 | 1766 | * @return none |
wim | 32:59c4b8f648d4 | 1767 | */ |
wim | 32:59c4b8f648d4 | 1768 | //@TODO Add support for 40x4 dual controller |
wim | 32:59c4b8f648d4 | 1769 | void TextLCD_Base::setContrast(unsigned char c) { |
wim | 32:59c4b8f648d4 | 1770 | |
wim | 32:59c4b8f648d4 | 1771 | // Function set mode stored during Init. Make sure we dont accidentally switch between 1-line and 2-line mode! |
wim | 32:59c4b8f648d4 | 1772 | // Icon/Booster mode stored during Init. Make sure we dont accidentally change this! |
wim | 32:59c4b8f648d4 | 1773 | |
wim | 32:59c4b8f648d4 | 1774 | _contrast = c & 0x3F; // Sanity check |
wim | 32:59c4b8f648d4 | 1775 | |
wim | 33:900a94bc7585 | 1776 | switch (_ctrl) { |
wim | 32:59c4b8f648d4 | 1777 | case PCF2113_3V3 : |
wim | 32:59c4b8f648d4 | 1778 | case PCF2119_3V3 : |
wim | 32:59c4b8f648d4 | 1779 | if (_contrast < 5) _contrast = 0; // See datasheet. Sanity check for PCF2113/PCF2119 |
wim | 32:59c4b8f648d4 | 1780 | if (_contrast > 55) _contrast = 55; |
wim | 32:59c4b8f648d4 | 1781 | |
wim | 32:59c4b8f648d4 | 1782 | _writeCommand(0x20 | _function | 0x01); // Set function, Select Instruction Set = 1 |
wim | 32:59c4b8f648d4 | 1783 | _writeCommand(0x80 | 0x00 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=0, VA=contrast |
wim | 32:59c4b8f648d4 | 1784 | _writeCommand(0x80 | 0x40 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=1, VB=contrast |
wim | 32:59c4b8f648d4 | 1785 | _writeCommand(0x20 | _function); // Select Instruction Set = 0 |
wim | 32:59c4b8f648d4 | 1786 | break; |
wim | 32:59c4b8f648d4 | 1787 | |
wim | 32:59c4b8f648d4 | 1788 | case ST7032_3V3 : |
wim | 32:59c4b8f648d4 | 1789 | case ST7032_5V : |
wim | 32:59c4b8f648d4 | 1790 | case ST7036_3V3 : |
wim | 32:59c4b8f648d4 | 1791 | // case ST7036_5V : |
wim | 32:59c4b8f648d4 | 1792 | case SSD1803_3V3 : |
wim | 32:59c4b8f648d4 | 1793 | _writeCommand(0x20 | _function | 0x01); // Select Instruction Set = 1 |
wim | 32:59c4b8f648d4 | 1794 | _writeCommand(0x70 | (_contrast & 0x0F)); // Contrast Low bits |
wim | 32:59c4b8f648d4 | 1795 | _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Contrast High bits |
wim | 32:59c4b8f648d4 | 1796 | _writeCommand(0x20 | _function); // Select Instruction Set = 0 |
wim | 32:59c4b8f648d4 | 1797 | break; |
wim | 32:59c4b8f648d4 | 1798 | |
wim | 33:900a94bc7585 | 1799 | case US2066_3V3 : |
wim | 33:900a94bc7585 | 1800 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV |
wim | 33:900a94bc7585 | 1801 | // Select Extended Instruction Set |
wim | 33:900a94bc7585 | 1802 | |
wim | 33:900a94bc7585 | 1803 | _writeCommand(0x79); // Function Select OLED: 0 1 1 1 1 0 0 1 (Ext Instr Set) |
wim | 33:900a94bc7585 | 1804 | |
wim | 33:900a94bc7585 | 1805 | _writeCommand(0x81); // Set Contrast Control: 1 0 0 0 0 0 0 1 (Ext Instr Set, OLED) |
wim | 33:900a94bc7585 | 1806 | _writeCommand((_contrast << 2) | 0x03); // Set Contrast Value: 8 bits. Use 6 bits for compatibility |
wim | 33:900a94bc7585 | 1807 | |
wim | 33:900a94bc7585 | 1808 | _writeCommand(0x78); // Function Disable OLED: 0 1 1 1 1 0 0 0 (Ext Instr Set) |
wim | 33:900a94bc7585 | 1809 | |
wim | 33:900a94bc7585 | 1810 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 33:900a94bc7585 | 1811 | // Select Std Instr set, Select IS=0 |
wim | 33:900a94bc7585 | 1812 | break; |
wim | 33:900a94bc7585 | 1813 | |
wim | 34:e5a0dcb43ecc | 1814 | //not yet tested on hardware |
wim | 32:59c4b8f648d4 | 1815 | case PT6314 : |
wim | 32:59c4b8f648d4 | 1816 | // Only 2 significant bits |
wim | 32:59c4b8f648d4 | 1817 | // 0x00 = 100% |
wim | 32:59c4b8f648d4 | 1818 | // 0x01 = 75% |
wim | 32:59c4b8f648d4 | 1819 | // 0x02 = 50% |
wim | 32:59c4b8f648d4 | 1820 | // 0x03 = 25% |
wim | 32:59c4b8f648d4 | 1821 | _writeCommand(0x20 | _function | ((~_contrast) >> 4)); // Invert and shift to use 2 MSBs |
wim | 32:59c4b8f648d4 | 1822 | break; |
wim | 32:59c4b8f648d4 | 1823 | |
wim | 32:59c4b8f648d4 | 1824 | default: |
wim | 32:59c4b8f648d4 | 1825 | //Unsupported feature for other controllers |
wim | 33:900a94bc7585 | 1826 | break; |
wim | 33:900a94bc7585 | 1827 | } // end switch |
wim | 33:900a94bc7585 | 1828 | } // end setContrast() |
wim | 32:59c4b8f648d4 | 1829 | |
wim | 32:59c4b8f648d4 | 1830 | |
wim | 32:59c4b8f648d4 | 1831 | /** Set Power |
wim | 32:59c4b8f648d4 | 1832 | * setPower method is supported by some compatible devices (eg SSD1803) that have power down modes |
wim | 32:59c4b8f648d4 | 1833 | * |
wim | 32:59c4b8f648d4 | 1834 | * @param bool powerOn Power on/off |
wim | 32:59c4b8f648d4 | 1835 | * @return none |
wim | 32:59c4b8f648d4 | 1836 | */ |
wim | 32:59c4b8f648d4 | 1837 | //@TODO Add support for 40x4 dual controller |
wim | 32:59c4b8f648d4 | 1838 | void TextLCD_Base::setPower(bool powerOn) { |
wim | 32:59c4b8f648d4 | 1839 | |
wim | 32:59c4b8f648d4 | 1840 | if (powerOn) { |
wim | 32:59c4b8f648d4 | 1841 | // Switch on |
wim | 32:59c4b8f648d4 | 1842 | setMode(DispOn); |
wim | 32:59c4b8f648d4 | 1843 | |
wim | 32:59c4b8f648d4 | 1844 | // Controllers that supports specific Power Down mode |
wim | 32:59c4b8f648d4 | 1845 | switch (_ctrl) { |
wim | 32:59c4b8f648d4 | 1846 | |
wim | 32:59c4b8f648d4 | 1847 | // case PCF2113_3V3 : |
wim | 32:59c4b8f648d4 | 1848 | // case PCF2119_3V3 : |
wim | 32:59c4b8f648d4 | 1849 | // case ST7032_3V3 : |
wim | 32:59c4b8f648d4 | 1850 | //@todo |
wim | 33:900a94bc7585 | 1851 | // enable Booster Bon |
wim | 33:900a94bc7585 | 1852 | |
wim | 33:900a94bc7585 | 1853 | case WS0010: |
wim | 33:900a94bc7585 | 1854 | _writeCommand(0x17); // Char mode, DC/DC on |
wim | 33:900a94bc7585 | 1855 | wait_ms(10); // Wait 10ms to ensure powered up |
wim | 33:900a94bc7585 | 1856 | break; |
wim | 33:900a94bc7585 | 1857 | |
wim | 33:900a94bc7585 | 1858 | case KS0078: |
wim | 32:59c4b8f648d4 | 1859 | case SSD1803_3V3 : |
wim | 32:59c4b8f648d4 | 1860 | // case SSD1803_5V : |
wim | 33:900a94bc7585 | 1861 | _writeCommand(0x20 | _function_1); // Select Ext Instr Set |
wim | 33:900a94bc7585 | 1862 | _writeCommand(0x02); // Power On |
wim | 32:59c4b8f648d4 | 1863 | _writeCommand(0x20 | _function); // Select Std Instr Set |
wim | 32:59c4b8f648d4 | 1864 | break; |
wim | 32:59c4b8f648d4 | 1865 | |
wim | 32:59c4b8f648d4 | 1866 | default: |
wim | 32:59c4b8f648d4 | 1867 | //Unsupported feature for other controllers |
wim | 32:59c4b8f648d4 | 1868 | break; |
wim | 32:59c4b8f648d4 | 1869 | } // end switch |
wim | 32:59c4b8f648d4 | 1870 | } |
wim | 32:59c4b8f648d4 | 1871 | else { |
wim | 32:59c4b8f648d4 | 1872 | // Switch off |
wim | 32:59c4b8f648d4 | 1873 | setMode(DispOff); |
wim | 32:59c4b8f648d4 | 1874 | |
wim | 32:59c4b8f648d4 | 1875 | // Controllers that support specific Power Down mode |
wim | 32:59c4b8f648d4 | 1876 | switch (_ctrl) { |
wim | 32:59c4b8f648d4 | 1877 | |
wim | 32:59c4b8f648d4 | 1878 | // case PCF2113_3V3 : |
wim | 32:59c4b8f648d4 | 1879 | // case PCF2119_3V3 : |
wim | 32:59c4b8f648d4 | 1880 | // case ST7032_3V3 : |
wim | 32:59c4b8f648d4 | 1881 | //@todo |
wim | 33:900a94bc7585 | 1882 | // disable Booster Bon |
wim | 33:900a94bc7585 | 1883 | |
wim | 33:900a94bc7585 | 1884 | case WS0010: |
wim | 33:900a94bc7585 | 1885 | _writeCommand(0x13); // Char mode, DC/DC off |
wim | 33:900a94bc7585 | 1886 | break; |
wim | 33:900a94bc7585 | 1887 | |
wim | 33:900a94bc7585 | 1888 | case KS0078: |
wim | 32:59c4b8f648d4 | 1889 | case SSD1803_3V3 : |
wim | 32:59c4b8f648d4 | 1890 | // case SSD1803_5V : |
wim | 33:900a94bc7585 | 1891 | _writeCommand(0x20 | _function_1); // Select Ext Instr Set |
wim | 33:900a94bc7585 | 1892 | _writeCommand(0x03); // Power Down |
wim | 32:59c4b8f648d4 | 1893 | _writeCommand(0x20 | _function); // Select Std Instr Set |
wim | 32:59c4b8f648d4 | 1894 | break; |
wim | 32:59c4b8f648d4 | 1895 | |
wim | 32:59c4b8f648d4 | 1896 | default: |
wim | 32:59c4b8f648d4 | 1897 | //Unsupported feature for other controllers |
wim | 32:59c4b8f648d4 | 1898 | break; |
wim | 32:59c4b8f648d4 | 1899 | } // end switch |
wim | 32:59c4b8f648d4 | 1900 | } |
wim | 33:900a94bc7585 | 1901 | } // end setPower() |
wim | 33:900a94bc7585 | 1902 | |
wim | 33:900a94bc7585 | 1903 | |
wim | 33:900a94bc7585 | 1904 | /** Set Orient |
wim | 33:900a94bc7585 | 1905 | * setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes |
wim | 33:900a94bc7585 | 1906 | * |
wim | 33:900a94bc7585 | 1907 | * @param LCDOrient orient Orientation |
wim | 33:900a94bc7585 | 1908 | * @return none |
wim | 33:900a94bc7585 | 1909 | */ |
wim | 33:900a94bc7585 | 1910 | void TextLCD_Base::setOrient(LCDOrient orient){ |
wim | 33:900a94bc7585 | 1911 | |
wim | 33:900a94bc7585 | 1912 | switch (orient) { |
wim | 33:900a94bc7585 | 1913 | |
wim | 33:900a94bc7585 | 1914 | case Top: |
wim | 33:900a94bc7585 | 1915 | switch (_ctrl) { |
wim | 34:e5a0dcb43ecc | 1916 | case PCF2103_3V3: |
wim | 34:e5a0dcb43ecc | 1917 | case PCF2116_3V3: |
wim | 34:e5a0dcb43ecc | 1918 | case PCF2116_5V: |
wim | 34:e5a0dcb43ecc | 1919 | case PCF2119_3V3: |
wim | 34:e5a0dcb43ecc | 1920 | _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1 |
wim | 34:e5a0dcb43ecc | 1921 | _writeCommand(0x05); // Display Conf Set 0000 0, 1, P=0, Q=1 (Instr. Set 1) |
wim | 34:e5a0dcb43ecc | 1922 | _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0 |
wim | 34:e5a0dcb43ecc | 1923 | break; |
wim | 34:e5a0dcb43ecc | 1924 | |
wim | 33:900a94bc7585 | 1925 | case SSD1803_3V3 : |
wim | 33:900a94bc7585 | 1926 | // case SSD1803_5V : |
wim | 33:900a94bc7585 | 1927 | case US2066_3V3 : |
wim | 33:900a94bc7585 | 1928 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV |
wim | 33:900a94bc7585 | 1929 | // Select Extended Instruction Set |
wim | 33:900a94bc7585 | 1930 | // _writeCommand(0x06); // Set ext entry mode, 0 0 0 0 0 1 BDC=1 COM1-32, BDS=0 SEG100-1 "Bottom View" (Ext Instr Set) |
wim | 33:900a94bc7585 | 1931 | _writeCommand(0x05); // Set ext entry mode, 0 0 0 0 0 1 BDC=0 COM32-1, BDS=1 SEG1-100 "Top View" (Ext Instr Set) |
wim | 33:900a94bc7585 | 1932 | |
wim | 33:900a94bc7585 | 1933 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 33:900a94bc7585 | 1934 | // Select Std Instr set, Select IS=0 |
wim | 33:900a94bc7585 | 1935 | break; |
wim | 33:900a94bc7585 | 1936 | |
wim | 33:900a94bc7585 | 1937 | default: |
wim | 33:900a94bc7585 | 1938 | //Unsupported feature for other controllers |
wim | 33:900a94bc7585 | 1939 | break; |
wim | 33:900a94bc7585 | 1940 | |
wim | 33:900a94bc7585 | 1941 | } // end switch _ctrl |
wim | 33:900a94bc7585 | 1942 | break; // end Top |
wim | 33:900a94bc7585 | 1943 | |
wim | 33:900a94bc7585 | 1944 | case Bottom: |
wim | 33:900a94bc7585 | 1945 | switch (_ctrl) { |
wim | 34:e5a0dcb43ecc | 1946 | case PCF2103_3V3: |
wim | 34:e5a0dcb43ecc | 1947 | case PCF2116_3V3: |
wim | 34:e5a0dcb43ecc | 1948 | case PCF2116_5V: |
wim | 34:e5a0dcb43ecc | 1949 | case PCF2119_3V3: |
wim | 34:e5a0dcb43ecc | 1950 | _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1 |
wim | 34:e5a0dcb43ecc | 1951 | _writeCommand(0x06); // Display Conf Set 0000 0, 1, P=1, Q=0 (Instr. Set 1) |
wim | 34:e5a0dcb43ecc | 1952 | _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0 |
wim | 34:e5a0dcb43ecc | 1953 | break; |
wim | 34:e5a0dcb43ecc | 1954 | |
wim | 33:900a94bc7585 | 1955 | case SSD1803_3V3 : |
wim | 33:900a94bc7585 | 1956 | // case SSD1803_5V : |
wim | 33:900a94bc7585 | 1957 | case US2066_3V3 : |
wim | 33:900a94bc7585 | 1958 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV |
wim | 33:900a94bc7585 | 1959 | // Select Extended Instruction Set |
wim | 33:900a94bc7585 | 1960 | _writeCommand(0x06); // Set ext entry mode, 0 0 0 0 0 1 BDC=1 COM1-32, BDS=0 SEG100-1 "Bottom View" (Ext Instr Set) |
wim | 33:900a94bc7585 | 1961 | // _writeCommand(0x05); // Set ext entry mode, 0 0 0 0 0 1 BDC=0 COM32-1, BDS=1 SEG1-100 "Top View" (Ext Instr Set) |
wim | 33:900a94bc7585 | 1962 | |
wim | 33:900a94bc7585 | 1963 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 33:900a94bc7585 | 1964 | // Select Std Instr set, Select IS=0 |
wim | 33:900a94bc7585 | 1965 | break; |
wim | 33:900a94bc7585 | 1966 | |
wim | 33:900a94bc7585 | 1967 | default: |
wim | 33:900a94bc7585 | 1968 | //Unsupported feature for other controllers |
wim | 33:900a94bc7585 | 1969 | break; |
wim | 33:900a94bc7585 | 1970 | |
wim | 33:900a94bc7585 | 1971 | } // end switch _ctrl |
wim | 33:900a94bc7585 | 1972 | |
wim | 33:900a94bc7585 | 1973 | break; // end Bottom |
wim | 33:900a94bc7585 | 1974 | } // end switch orient |
wim | 33:900a94bc7585 | 1975 | } // end setOrient() |
wim | 33:900a94bc7585 | 1976 | |
wim | 33:900a94bc7585 | 1977 | |
wim | 34:e5a0dcb43ecc | 1978 | /** Set Big Font |
wim | 34:e5a0dcb43ecc | 1979 | * setBigFont method is supported by some compatible devices (eg SSD1803, US2066) |
wim | 34:e5a0dcb43ecc | 1980 | * |
wim | 34:e5a0dcb43ecc | 1981 | * @param lines The selected Big Font lines (None, TopLine, CenterLine, BottomLine, TopBottomLine) |
wim | 34:e5a0dcb43ecc | 1982 | * Double height characters can be shown on lines 1+2, 2+3, 3+4 or 1+2 and 3+4 |
wim | 34:e5a0dcb43ecc | 1983 | * Valid double height lines depend on the LCDs number of rows. |
wim | 34:e5a0dcb43ecc | 1984 | */ |
wim | 34:e5a0dcb43ecc | 1985 | void TextLCD_Base::setBigFont(LCDBigFont lines) { |
wim | 34:e5a0dcb43ecc | 1986 | |
wim | 34:e5a0dcb43ecc | 1987 | switch (lines) { |
wim | 34:e5a0dcb43ecc | 1988 | case None: |
wim | 34:e5a0dcb43ecc | 1989 | switch (_ctrl) { |
wim | 34:e5a0dcb43ecc | 1990 | case SSD1803_3V3 : |
wim | 34:e5a0dcb43ecc | 1991 | case US2066_3V3 : |
wim | 34:e5a0dcb43ecc | 1992 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV |
wim | 34:e5a0dcb43ecc | 1993 | // Select Extended Instruction Set |
wim | 34:e5a0dcb43ecc | 1994 | _writeCommand(0x1C); // Double Height, 0 0 0 1 UD2=1, UD1=1, X, DH'=0 (Ext Instr Set) |
wim | 34:e5a0dcb43ecc | 1995 | // Default |
wim | 34:e5a0dcb43ecc | 1996 | _function = _function & ~0x04; // Set function, 0 0 1 DL N DH=0 RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 1997 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 1998 | // Select Std Instr set, Select IS=0 |
wim | 34:e5a0dcb43ecc | 1999 | break; // end US2066 |
wim | 34:e5a0dcb43ecc | 2000 | |
wim | 34:e5a0dcb43ecc | 2001 | default: |
wim | 34:e5a0dcb43ecc | 2002 | break; // end default |
wim | 34:e5a0dcb43ecc | 2003 | } // end switch _ctrl |
wim | 34:e5a0dcb43ecc | 2004 | break; // end None |
wim | 34:e5a0dcb43ecc | 2005 | |
wim | 34:e5a0dcb43ecc | 2006 | case TopLine: |
wim | 34:e5a0dcb43ecc | 2007 | if (_nr_rows < 2) return; //Sanity check |
wim | 34:e5a0dcb43ecc | 2008 | |
wim | 34:e5a0dcb43ecc | 2009 | switch (_ctrl) { |
wim | 34:e5a0dcb43ecc | 2010 | case SSD1803_3V3 : |
wim | 34:e5a0dcb43ecc | 2011 | case US2066_3V3 : |
wim | 34:e5a0dcb43ecc | 2012 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV |
wim | 34:e5a0dcb43ecc | 2013 | // Select Extended Instruction Set |
wim | 34:e5a0dcb43ecc | 2014 | _writeCommand(0x1C); // Double Height, 0 0 0 1 UD2=1, UD1=1, X, DH'=0 (Ext Instr Set) |
wim | 34:e5a0dcb43ecc | 2015 | // Default |
wim | 34:e5a0dcb43ecc | 2016 | _function = _function | 0x04; // Set function, 0 0 1 DL N DH=1 RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 2017 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 2018 | // Select Std Instr set, Select IS=0 |
wim | 34:e5a0dcb43ecc | 2019 | break; // end US2066, SSD1803 |
wim | 34:e5a0dcb43ecc | 2020 | |
wim | 34:e5a0dcb43ecc | 2021 | default: |
wim | 34:e5a0dcb43ecc | 2022 | break; // end default |
wim | 34:e5a0dcb43ecc | 2023 | } // end switch _ctrl |
wim | 34:e5a0dcb43ecc | 2024 | break; // end TopLine |
wim | 34:e5a0dcb43ecc | 2025 | |
wim | 34:e5a0dcb43ecc | 2026 | case CenterLine: |
wim | 34:e5a0dcb43ecc | 2027 | if (_nr_rows != 4) return; //Sanity check |
wim | 34:e5a0dcb43ecc | 2028 | |
wim | 34:e5a0dcb43ecc | 2029 | switch (_ctrl) { |
wim | 34:e5a0dcb43ecc | 2030 | case SSD1803_3V3 : |
wim | 34:e5a0dcb43ecc | 2031 | case US2066_3V3 : |
wim | 34:e5a0dcb43ecc | 2032 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV |
wim | 34:e5a0dcb43ecc | 2033 | // Select Extended Instruction Set |
wim | 34:e5a0dcb43ecc | 2034 | _writeCommand(0x14); // Double Height, 0 0 0 1 UD2=0, UD1=1, X, DH'=0 (Ext Instr Set) |
wim | 34:e5a0dcb43ecc | 2035 | // Default |
wim | 34:e5a0dcb43ecc | 2036 | _function = _function | 0x04; // Set function, 0 0 1 DL N DH=1 RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 2037 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 2038 | // Select Std Instr set, Select IS=0 |
wim | 34:e5a0dcb43ecc | 2039 | break; // end US2066, SSD1803 |
wim | 34:e5a0dcb43ecc | 2040 | |
wim | 34:e5a0dcb43ecc | 2041 | default: |
wim | 34:e5a0dcb43ecc | 2042 | break; // end default |
wim | 34:e5a0dcb43ecc | 2043 | } // end switch _ctrl |
wim | 34:e5a0dcb43ecc | 2044 | break; // end CenterLine |
wim | 34:e5a0dcb43ecc | 2045 | |
wim | 34:e5a0dcb43ecc | 2046 | case BottomLine: |
wim | 34:e5a0dcb43ecc | 2047 | if (_nr_rows < 3) return; //Sanity check |
wim | 34:e5a0dcb43ecc | 2048 | |
wim | 34:e5a0dcb43ecc | 2049 | switch (_ctrl) { |
wim | 34:e5a0dcb43ecc | 2050 | case SSD1803_3V3 : |
wim | 34:e5a0dcb43ecc | 2051 | case US2066_3V3 : |
wim | 34:e5a0dcb43ecc | 2052 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV |
wim | 34:e5a0dcb43ecc | 2053 | // Select Extended Instruction Set |
wim | 34:e5a0dcb43ecc | 2054 | if (_nr_rows == 3) { |
wim | 34:e5a0dcb43ecc | 2055 | _writeCommand(0x14); // Double Height, 0 0 0 1 UD2=0, UD1=1, X, DH'=0 (Ext Instr Set) |
wim | 34:e5a0dcb43ecc | 2056 | } |
wim | 34:e5a0dcb43ecc | 2057 | else { |
wim | 34:e5a0dcb43ecc | 2058 | _writeCommand(0x10); // Double Height, 0 0 0 1 UD2=0, UD1=0, X, DH'=0 (Ext Instr Set) |
wim | 34:e5a0dcb43ecc | 2059 | } |
wim | 34:e5a0dcb43ecc | 2060 | _function = _function | 0x04; // Set function, 0 0 1 DL N DH=1 RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 2061 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 2062 | // Select Std Instr set, Select IS=0 |
wim | 34:e5a0dcb43ecc | 2063 | break; // end US2066, SSD1803 |
wim | 34:e5a0dcb43ecc | 2064 | |
wim | 34:e5a0dcb43ecc | 2065 | default: |
wim | 34:e5a0dcb43ecc | 2066 | break; // end default |
wim | 34:e5a0dcb43ecc | 2067 | } // end switch _ctrl |
wim | 34:e5a0dcb43ecc | 2068 | break; // end BottomLine |
wim | 34:e5a0dcb43ecc | 2069 | |
wim | 34:e5a0dcb43ecc | 2070 | case TopBottomLine: |
wim | 34:e5a0dcb43ecc | 2071 | if (_nr_rows != 4) return; //Sanity check |
wim | 34:e5a0dcb43ecc | 2072 | |
wim | 34:e5a0dcb43ecc | 2073 | switch (_ctrl) { |
wim | 34:e5a0dcb43ecc | 2074 | case SSD1803_3V3 : |
wim | 34:e5a0dcb43ecc | 2075 | case US2066_3V3 : |
wim | 34:e5a0dcb43ecc | 2076 | _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV |
wim | 34:e5a0dcb43ecc | 2077 | // Select Extended Instruction Set |
wim | 34:e5a0dcb43ecc | 2078 | _writeCommand(0x18); // Double Height, 0 0 0 1 UD2=1, UD1=0, X, DH'=0 (Ext Instr Set) |
wim | 34:e5a0dcb43ecc | 2079 | // Default |
wim | 34:e5a0dcb43ecc | 2080 | _function = _function | 0x04; // Set function, 0 0 1 DL N DH=1 RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 2081 | _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0 |
wim | 34:e5a0dcb43ecc | 2082 | // Select Std Instr set, Select IS=0 |
wim | 34:e5a0dcb43ecc | 2083 | break; // end US2066, SSD1803 |
wim | 34:e5a0dcb43ecc | 2084 | |
wim | 34:e5a0dcb43ecc | 2085 | default: |
wim | 34:e5a0dcb43ecc | 2086 | break; // end default |
wim | 34:e5a0dcb43ecc | 2087 | } // end switch _ctrl |
wim | 34:e5a0dcb43ecc | 2088 | break; // end TopBottomLine |
wim | 34:e5a0dcb43ecc | 2089 | |
wim | 34:e5a0dcb43ecc | 2090 | } // end switch lines |
wim | 34:e5a0dcb43ecc | 2091 | |
wim | 34:e5a0dcb43ecc | 2092 | } // end setBigFont() |
wim | 32:59c4b8f648d4 | 2093 | |
wim | 23:d47f226efb24 | 2094 | //--------- End TextLCD_Base ----------- |
wim | 21:9eb628d9e164 | 2095 | |
wim | 22:35742ec80c24 | 2096 | |
wim | 23:d47f226efb24 | 2097 | //--------- Start TextLCD Bus ----------- |
wim | 21:9eb628d9e164 | 2098 | |
wim | 21:9eb628d9e164 | 2099 | /* Create a TextLCD interface for using regular mbed pins |
wim | 21:9eb628d9e164 | 2100 | * |
wim | 21:9eb628d9e164 | 2101 | * @param rs Instruction/data control line |
wim | 21:9eb628d9e164 | 2102 | * @param e Enable line (clock) |
wim | 21:9eb628d9e164 | 2103 | * @param d4-d7 Data lines for using as a 4-bit interface |
wim | 21:9eb628d9e164 | 2104 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 21:9eb628d9e164 | 2105 | * @param bl Backlight control line (optional, default = NC) |
wim | 21:9eb628d9e164 | 2106 | * @param e2 Enable2 line (clock for second controller, LCD40x4 only) |
wim | 21:9eb628d9e164 | 2107 | * @param ctrl LCD controller (default = HD44780) |
wim | 21:9eb628d9e164 | 2108 | */ |
wim | 21:9eb628d9e164 | 2109 | TextLCD::TextLCD(PinName rs, PinName e, |
wim | 21:9eb628d9e164 | 2110 | PinName d4, PinName d5, PinName d6, PinName d7, |
wim | 21:9eb628d9e164 | 2111 | LCDType type, PinName bl, PinName e2, LCDCtrl ctrl) : |
wim | 21:9eb628d9e164 | 2112 | TextLCD_Base(type, ctrl), |
wim | 22:35742ec80c24 | 2113 | _rs(rs), _e(e), _d(d4, d5, d6, d7) { |
wim | 22:35742ec80c24 | 2114 | |
wim | 22:35742ec80c24 | 2115 | // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access. |
wim | 22:35742ec80c24 | 2116 | if (bl != NC) { |
wim | 22:35742ec80c24 | 2117 | _bl = new DigitalOut(bl); //Construct new pin |
wim | 22:35742ec80c24 | 2118 | _bl->write(0); //Deactivate |
wim | 22:35742ec80c24 | 2119 | } |
wim | 22:35742ec80c24 | 2120 | else { |
wim | 22:35742ec80c24 | 2121 | // No Hardware Backlight pin |
wim | 22:35742ec80c24 | 2122 | _bl = NULL; //Construct dummy pin |
wim | 22:35742ec80c24 | 2123 | } |
wim | 22:35742ec80c24 | 2124 | |
wim | 22:35742ec80c24 | 2125 | // The hardware Enable2 pin is only needed for LCD40x4. Test and make sure whether it exists or not to prevent illegal access. |
wim | 22:35742ec80c24 | 2126 | if (e2 != NC) { |
wim | 22:35742ec80c24 | 2127 | _e2 = new DigitalOut(e2); //Construct new pin |
wim | 22:35742ec80c24 | 2128 | _e2->write(0); //Deactivate |
wim | 22:35742ec80c24 | 2129 | } |
wim | 22:35742ec80c24 | 2130 | else { |
wim | 22:35742ec80c24 | 2131 | // No Hardware Enable pin |
wim | 22:35742ec80c24 | 2132 | _e2 = NULL; //Construct dummy pin |
wim | 22:35742ec80c24 | 2133 | } |
wim | 21:9eb628d9e164 | 2134 | |
wim | 21:9eb628d9e164 | 2135 | _init(); |
wim | 21:9eb628d9e164 | 2136 | } |
wim | 21:9eb628d9e164 | 2137 | |
wim | 29:a3663151aa65 | 2138 | /** Destruct a TextLCD interface for using regular mbed pins |
wim | 29:a3663151aa65 | 2139 | * |
wim | 29:a3663151aa65 | 2140 | * @param none |
wim | 29:a3663151aa65 | 2141 | * @return none |
wim | 29:a3663151aa65 | 2142 | */ |
wim | 29:a3663151aa65 | 2143 | TextLCD::~TextLCD() { |
wim | 29:a3663151aa65 | 2144 | if (_bl != NULL) {delete _bl;} // BL pin |
wim | 29:a3663151aa65 | 2145 | if (_e2 != NULL) {delete _e2;} // E2 pin |
wim | 29:a3663151aa65 | 2146 | } |
wim | 29:a3663151aa65 | 2147 | |
wim | 29:a3663151aa65 | 2148 | |
wim | 22:35742ec80c24 | 2149 | /** Set E pin (or E2 pin) |
wim | 22:35742ec80c24 | 2150 | * Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 22:35742ec80c24 | 2151 | * Default PinName value for E2 is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins |
wim | 22:35742ec80c24 | 2152 | * @param value true or false |
wim | 22:35742ec80c24 | 2153 | * @return none |
wim | 22:35742ec80c24 | 2154 | */ |
wim | 21:9eb628d9e164 | 2155 | void TextLCD::_setEnable(bool value) { |
wim | 21:9eb628d9e164 | 2156 | |
wim | 22:35742ec80c24 | 2157 | if(_ctrl_idx==_LCDCtrl_0) { |
wim | 22:35742ec80c24 | 2158 | if (value) { |
wim | 22:35742ec80c24 | 2159 | _e = 1; // Set E bit |
wim | 22:35742ec80c24 | 2160 | } |
wim | 22:35742ec80c24 | 2161 | else { |
wim | 22:35742ec80c24 | 2162 | _e = 0; // Reset E bit |
wim | 22:35742ec80c24 | 2163 | } |
wim | 22:35742ec80c24 | 2164 | } |
wim | 22:35742ec80c24 | 2165 | else { |
wim | 22:35742ec80c24 | 2166 | if (value) { |
wim | 22:35742ec80c24 | 2167 | if (_e2 != NULL) {_e2->write(1);} //Set E2 bit |
wim | 22:35742ec80c24 | 2168 | } |
wim | 22:35742ec80c24 | 2169 | else { |
wim | 22:35742ec80c24 | 2170 | if (_e2 != NULL) {_e2->write(0);} //Reset E2 bit |
wim | 22:35742ec80c24 | 2171 | } |
wim | 22:35742ec80c24 | 2172 | } |
wim | 21:9eb628d9e164 | 2173 | } |
wim | 21:9eb628d9e164 | 2174 | |
wim | 21:9eb628d9e164 | 2175 | // Set RS pin |
wim | 21:9eb628d9e164 | 2176 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 21:9eb628d9e164 | 2177 | void TextLCD::_setRS(bool value) { |
wim | 21:9eb628d9e164 | 2178 | |
wim | 22:35742ec80c24 | 2179 | if (value) { |
wim | 21:9eb628d9e164 | 2180 | _rs = 1; // Set RS bit |
wim | 22:35742ec80c24 | 2181 | } |
wim | 22:35742ec80c24 | 2182 | else { |
wim | 21:9eb628d9e164 | 2183 | _rs = 0; // Reset RS bit |
wim | 22:35742ec80c24 | 2184 | } |
wim | 21:9eb628d9e164 | 2185 | } |
wim | 21:9eb628d9e164 | 2186 | |
wim | 22:35742ec80c24 | 2187 | /** Set BL pin |
wim | 22:35742ec80c24 | 2188 | * Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 22:35742ec80c24 | 2189 | * Default PinName value is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins |
wim | 22:35742ec80c24 | 2190 | * @param value true or false |
wim | 22:35742ec80c24 | 2191 | * @return none |
wim | 22:35742ec80c24 | 2192 | */ |
wim | 21:9eb628d9e164 | 2193 | void TextLCD::_setBL(bool value) { |
wim | 21:9eb628d9e164 | 2194 | |
wim | 22:35742ec80c24 | 2195 | if (value) { |
wim | 22:35742ec80c24 | 2196 | if (_bl != NULL) {_bl->write(1);} //Set BL bit |
wim | 22:35742ec80c24 | 2197 | } |
wim | 22:35742ec80c24 | 2198 | else { |
wim | 22:35742ec80c24 | 2199 | if (_bl != NULL) {_bl->write(0);} //Reset BL bit |
wim | 22:35742ec80c24 | 2200 | } |
wim | 21:9eb628d9e164 | 2201 | } |
wim | 21:9eb628d9e164 | 2202 | |
wim | 21:9eb628d9e164 | 2203 | // Place the 4bit data on the databus |
wim | 21:9eb628d9e164 | 2204 | // Used for mbed pins, I2C bus expander or SPI shifregister |
wim | 21:9eb628d9e164 | 2205 | void TextLCD::_setData(int value) { |
wim | 21:9eb628d9e164 | 2206 | _d = value & 0x0F; // Write Databits |
wim | 21:9eb628d9e164 | 2207 | } |
wim | 34:e5a0dcb43ecc | 2208 | |
wim | 23:d47f226efb24 | 2209 | //----------- End TextLCD --------------- |
wim | 21:9eb628d9e164 | 2210 | |
wim | 21:9eb628d9e164 | 2211 | |
wim | 23:d47f226efb24 | 2212 | //--------- Start TextLCD_I2C ----------- |
wim | 34:e5a0dcb43ecc | 2213 | #if(LCD_I2C == 1) /* I2C Expander PCF8574/MCP23008 */ |
wim | 26:bd897a001012 | 2214 | /** Create a TextLCD interface using an I2C PC8574 (or PCF8574A) or MCP23008 portexpander |
wim | 22:35742ec80c24 | 2215 | * |
wim | 22:35742ec80c24 | 2216 | * @param i2c I2C Bus |
wim | 26:bd897a001012 | 2217 | * @param deviceAddress I2C slave address (PCF8574, PCF8574A or MCP23008, default = 0x40) |
wim | 22:35742ec80c24 | 2218 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 22:35742ec80c24 | 2219 | * @param ctrl LCD controller (default = HD44780) |
wim | 22:35742ec80c24 | 2220 | */ |
wim | 21:9eb628d9e164 | 2221 | TextLCD_I2C::TextLCD_I2C(I2C *i2c, char deviceAddress, LCDType type, LCDCtrl ctrl) : |
wim | 21:9eb628d9e164 | 2222 | TextLCD_Base(type, ctrl), |
wim | 21:9eb628d9e164 | 2223 | _i2c(i2c){ |
wim | 21:9eb628d9e164 | 2224 | |
wim | 22:35742ec80c24 | 2225 | _slaveAddress = deviceAddress & 0xFE; |
wim | 28:30fa94f7341c | 2226 | |
wim | 28:30fa94f7341c | 2227 | // Setup the I2C bus |
wim | 28:30fa94f7341c | 2228 | // The max bitrate for PCF8574 is 100kbit, the max bitrate for MCP23008 is 400kbit, |
wim | 32:59c4b8f648d4 | 2229 | _i2c->frequency(100000); |
wim | 21:9eb628d9e164 | 2230 | |
wim | 26:bd897a001012 | 2231 | #if (MCP23008==1) |
wim | 26:bd897a001012 | 2232 | // MCP23008 portexpander Init |
wim | 27:22d5086f6ba6 | 2233 | _write_register(IODIR, 0x00); // All outputs |
wim | 27:22d5086f6ba6 | 2234 | _write_register(IPOL, 0x00); // No reverse polarity |
wim | 27:22d5086f6ba6 | 2235 | _write_register(GPINTEN, 0x00); // No interrupt |
wim | 27:22d5086f6ba6 | 2236 | _write_register(DEFVAL, 0x00); // Default value to compare against for interrupts |
wim | 27:22d5086f6ba6 | 2237 | _write_register(INTCON, 0x00); // No interrupt on changes |
wim | 27:22d5086f6ba6 | 2238 | _write_register(IOCON, 0x00); // Interrupt polarity |
wim | 27:22d5086f6ba6 | 2239 | _write_register(GPPU, 0x00); // No Pullup |
wim | 27:22d5086f6ba6 | 2240 | _write_register(INTF, 0x00); // |
wim | 27:22d5086f6ba6 | 2241 | _write_register(INTCAP, 0x00); // |
wim | 27:22d5086f6ba6 | 2242 | _write_register(GPIO, 0x00); // Output/Input pins |
wim | 27:22d5086f6ba6 | 2243 | _write_register(OLAT, 0x00); // Output Latch |
wim | 26:bd897a001012 | 2244 | |
wim | 21:9eb628d9e164 | 2245 | // Init the portexpander bus |
wim | 21:9eb628d9e164 | 2246 | _lcd_bus = D_LCD_BUS_DEF; |
wim | 21:9eb628d9e164 | 2247 | |
wim | 21:9eb628d9e164 | 2248 | // write the new data to the portexpander |
wim | 26:bd897a001012 | 2249 | _write_register(GPIO, _lcd_bus); |
wim | 26:bd897a001012 | 2250 | #else |
wim | 26:bd897a001012 | 2251 | // PCF8574 of PCF8574A portexpander |
wim | 26:bd897a001012 | 2252 | |
wim | 26:bd897a001012 | 2253 | // Init the portexpander bus |
wim | 26:bd897a001012 | 2254 | _lcd_bus = D_LCD_BUS_DEF; |
wim | 26:bd897a001012 | 2255 | |
wim | 26:bd897a001012 | 2256 | // write the new data to the portexpander |
wim | 21:9eb628d9e164 | 2257 | _i2c->write(_slaveAddress, &_lcd_bus, 1); |
wim | 26:bd897a001012 | 2258 | #endif |
wim | 21:9eb628d9e164 | 2259 | |
wim | 30:033048611c01 | 2260 | _init(); |
wim | 21:9eb628d9e164 | 2261 | } |
wim | 21:9eb628d9e164 | 2262 | |
wim | 21:9eb628d9e164 | 2263 | // Set E pin (or E2 pin) |
wim | 21:9eb628d9e164 | 2264 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 21:9eb628d9e164 | 2265 | void TextLCD_I2C::_setEnable(bool value) { |
wim | 21:9eb628d9e164 | 2266 | |
wim | 22:35742ec80c24 | 2267 | if(_ctrl_idx==_LCDCtrl_0) { |
wim | 26:bd897a001012 | 2268 | if (value) { |
wim | 22:35742ec80c24 | 2269 | _lcd_bus |= D_LCD_E; // Set E bit |
wim | 26:bd897a001012 | 2270 | } |
wim | 26:bd897a001012 | 2271 | else { |
wim | 22:35742ec80c24 | 2272 | _lcd_bus &= ~D_LCD_E; // Reset E bit |
wim | 26:bd897a001012 | 2273 | } |
wim | 22:35742ec80c24 | 2274 | } |
wim | 22:35742ec80c24 | 2275 | else { |
wim | 26:bd897a001012 | 2276 | if (value) { |
wim | 22:35742ec80c24 | 2277 | _lcd_bus |= D_LCD_E2; // Set E2 bit |
wim | 26:bd897a001012 | 2278 | } |
wim | 26:bd897a001012 | 2279 | else { |
wim | 22:35742ec80c24 | 2280 | _lcd_bus &= ~D_LCD_E2; // Reset E2bit |
wim | 26:bd897a001012 | 2281 | } |
wim | 26:bd897a001012 | 2282 | } |
wim | 26:bd897a001012 | 2283 | |
wim | 26:bd897a001012 | 2284 | #if (MCP23008==1) |
wim | 26:bd897a001012 | 2285 | // MCP23008 portexpander |
wim | 26:bd897a001012 | 2286 | |
wim | 26:bd897a001012 | 2287 | // write the new data to the portexpander |
wim | 26:bd897a001012 | 2288 | _write_register(GPIO, _lcd_bus); |
wim | 26:bd897a001012 | 2289 | #else |
wim | 26:bd897a001012 | 2290 | // PCF8574 of PCF8574A portexpander |
wim | 21:9eb628d9e164 | 2291 | |
wim | 22:35742ec80c24 | 2292 | // write the new data to the I2C portexpander |
wim | 22:35742ec80c24 | 2293 | _i2c->write(_slaveAddress, &_lcd_bus, 1); |
wim | 26:bd897a001012 | 2294 | #endif |
wim | 21:9eb628d9e164 | 2295 | } |
wim | 21:9eb628d9e164 | 2296 | |
wim | 21:9eb628d9e164 | 2297 | // Set RS pin |
wim | 21:9eb628d9e164 | 2298 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 21:9eb628d9e164 | 2299 | void TextLCD_I2C::_setRS(bool value) { |
wim | 21:9eb628d9e164 | 2300 | |
wim | 26:bd897a001012 | 2301 | if (value) { |
wim | 22:35742ec80c24 | 2302 | _lcd_bus |= D_LCD_RS; // Set RS bit |
wim | 26:bd897a001012 | 2303 | } |
wim | 26:bd897a001012 | 2304 | else { |
wim | 22:35742ec80c24 | 2305 | _lcd_bus &= ~D_LCD_RS; // Reset RS bit |
wim | 26:bd897a001012 | 2306 | } |
wim | 26:bd897a001012 | 2307 | |
wim | 26:bd897a001012 | 2308 | #if (MCP23008==1) |
wim | 26:bd897a001012 | 2309 | // MCP23008 portexpander |
wim | 26:bd897a001012 | 2310 | |
wim | 26:bd897a001012 | 2311 | // write the new data to the portexpander |
wim | 26:bd897a001012 | 2312 | _write_register(GPIO, _lcd_bus); |
wim | 26:bd897a001012 | 2313 | #else |
wim | 26:bd897a001012 | 2314 | // PCF8574 of PCF8574A portexpander |
wim | 21:9eb628d9e164 | 2315 | |
wim | 22:35742ec80c24 | 2316 | // write the new data to the I2C portexpander |
wim | 22:35742ec80c24 | 2317 | _i2c->write(_slaveAddress, &_lcd_bus, 1); |
wim | 30:033048611c01 | 2318 | #endif |
wim | 21:9eb628d9e164 | 2319 | } |
wim | 21:9eb628d9e164 | 2320 | |
wim | 21:9eb628d9e164 | 2321 | // Set BL pin |
wim | 21:9eb628d9e164 | 2322 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 21:9eb628d9e164 | 2323 | void TextLCD_I2C::_setBL(bool value) { |
wim | 21:9eb628d9e164 | 2324 | |
wim | 33:900a94bc7585 | 2325 | #if (DFROBOT==1) |
wim | 33:900a94bc7585 | 2326 | value = !value; // The DFRobot module uses PNP transistor to drive the Backlight. Reverse logic level. |
wim | 33:900a94bc7585 | 2327 | #endif |
wim | 33:900a94bc7585 | 2328 | |
wim | 26:bd897a001012 | 2329 | if (value) { |
wim | 21:9eb628d9e164 | 2330 | _lcd_bus |= D_LCD_BL; // Set BL bit |
wim | 26:bd897a001012 | 2331 | } |
wim | 26:bd897a001012 | 2332 | else { |
wim | 21:9eb628d9e164 | 2333 | _lcd_bus &= ~D_LCD_BL; // Reset BL bit |
wim | 26:bd897a001012 | 2334 | } |
wim | 26:bd897a001012 | 2335 | |
wim | 26:bd897a001012 | 2336 | #if (MCP23008==1) |
wim | 26:bd897a001012 | 2337 | // MCP23008 portexpander |
wim | 26:bd897a001012 | 2338 | |
wim | 26:bd897a001012 | 2339 | // write the new data to the portexpander |
wim | 26:bd897a001012 | 2340 | _write_register(GPIO, _lcd_bus); |
wim | 26:bd897a001012 | 2341 | #else |
wim | 26:bd897a001012 | 2342 | // PCF8574 of PCF8574A portexpander |
wim | 21:9eb628d9e164 | 2343 | |
wim | 21:9eb628d9e164 | 2344 | // write the new data to the I2C portexpander |
wim | 21:9eb628d9e164 | 2345 | _i2c->write(_slaveAddress, &_lcd_bus, 1); |
wim | 30:033048611c01 | 2346 | #endif |
wim | 21:9eb628d9e164 | 2347 | } |
wim | 21:9eb628d9e164 | 2348 | |
wim | 21:9eb628d9e164 | 2349 | |
wim | 21:9eb628d9e164 | 2350 | // Place the 4bit data on the databus |
wim | 21:9eb628d9e164 | 2351 | // Used for mbed pins, I2C bus expander or SPI shifregister |
wim | 21:9eb628d9e164 | 2352 | void TextLCD_I2C::_setData(int value) { |
wim | 21:9eb628d9e164 | 2353 | int data; |
wim | 22:35742ec80c24 | 2354 | |
wim | 22:35742ec80c24 | 2355 | // Set bit by bit to support any mapping of expander portpins to LCD pins |
wim | 21:9eb628d9e164 | 2356 | |
wim | 22:35742ec80c24 | 2357 | data = value & 0x0F; |
wim | 26:bd897a001012 | 2358 | if (data & 0x01){ |
wim | 22:35742ec80c24 | 2359 | _lcd_bus |= D_LCD_D4; // Set Databit |
wim | 26:bd897a001012 | 2360 | } |
wim | 26:bd897a001012 | 2361 | else { |
wim | 26:bd897a001012 | 2362 | _lcd_bus &= ~D_LCD_D4; // Reset Databit |
wim | 26:bd897a001012 | 2363 | } |
wim | 21:9eb628d9e164 | 2364 | |
wim | 26:bd897a001012 | 2365 | if (data & 0x02){ |
wim | 22:35742ec80c24 | 2366 | _lcd_bus |= D_LCD_D5; // Set Databit |
wim | 26:bd897a001012 | 2367 | } |
wim | 26:bd897a001012 | 2368 | else { |
wim | 26:bd897a001012 | 2369 | _lcd_bus &= ~D_LCD_D5; // Reset Databit |
wim | 26:bd897a001012 | 2370 | } |
wim | 21:9eb628d9e164 | 2371 | |
wim | 26:bd897a001012 | 2372 | if (data & 0x04) { |
wim | 22:35742ec80c24 | 2373 | _lcd_bus |= D_LCD_D6; // Set Databit |
wim | 26:bd897a001012 | 2374 | } |
wim | 26:bd897a001012 | 2375 | else { |
wim | 26:bd897a001012 | 2376 | _lcd_bus &= ~D_LCD_D6; // Reset Databit |
wim | 26:bd897a001012 | 2377 | } |
wim | 21:9eb628d9e164 | 2378 | |
wim | 26:bd897a001012 | 2379 | if (data & 0x08) { |
wim | 22:35742ec80c24 | 2380 | _lcd_bus |= D_LCD_D7; // Set Databit |
wim | 26:bd897a001012 | 2381 | } |
wim | 26:bd897a001012 | 2382 | else { |
wim | 26:bd897a001012 | 2383 | _lcd_bus &= ~D_LCD_D7; // Reset Databit |
wim | 26:bd897a001012 | 2384 | } |
wim | 21:9eb628d9e164 | 2385 | |
wim | 26:bd897a001012 | 2386 | #if (MCP23008==1) |
wim | 26:bd897a001012 | 2387 | // MCP23008 portexpander |
wim | 26:bd897a001012 | 2388 | |
wim | 26:bd897a001012 | 2389 | // write the new data to the portexpander |
wim | 26:bd897a001012 | 2390 | _write_register(GPIO, _lcd_bus); |
wim | 26:bd897a001012 | 2391 | #else |
wim | 26:bd897a001012 | 2392 | // PCF8574 of PCF8574A portexpander |
wim | 26:bd897a001012 | 2393 | |
wim | 22:35742ec80c24 | 2394 | // write the new data to the I2C portexpander |
wim | 26:bd897a001012 | 2395 | _i2c->write(_slaveAddress, &_lcd_bus, 1); |
wim | 26:bd897a001012 | 2396 | #endif |
wim | 22:35742ec80c24 | 2397 | |
wim | 22:35742ec80c24 | 2398 | } |
wim | 21:9eb628d9e164 | 2399 | |
wim | 26:bd897a001012 | 2400 | // Write data to MCP23008 I2C portexpander |
wim | 26:bd897a001012 | 2401 | void TextLCD_I2C::_write_register (int reg, int value) { |
wim | 26:bd897a001012 | 2402 | char data[] = {reg, value}; |
wim | 26:bd897a001012 | 2403 | |
wim | 30:033048611c01 | 2404 | _i2c->write(_slaveAddress, data, 2); |
wim | 26:bd897a001012 | 2405 | } |
wim | 34:e5a0dcb43ecc | 2406 | #endif /* I2C Expander PCF8574/MCP23008 */ |
wim | 23:d47f226efb24 | 2407 | //---------- End TextLCD_I2C ------------ |
wim | 21:9eb628d9e164 | 2408 | |
wim | 21:9eb628d9e164 | 2409 | |
wim | 28:30fa94f7341c | 2410 | //--------- Start TextLCD_I2C_N --------- |
wim | 34:e5a0dcb43ecc | 2411 | #if(LCD_I2C_N == 1) /* Native I2C */ |
wim | 28:30fa94f7341c | 2412 | |
wim | 28:30fa94f7341c | 2413 | /** Create a TextLCD interface using a controller with native I2C interface |
wim | 28:30fa94f7341c | 2414 | * |
wim | 28:30fa94f7341c | 2415 | * @param i2c I2C Bus |
wim | 28:30fa94f7341c | 2416 | * @param deviceAddress I2C slave address (default = 0x7C) |
wim | 28:30fa94f7341c | 2417 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 28:30fa94f7341c | 2418 | * @param bl Backlight control line (optional, default = NC) |
wim | 28:30fa94f7341c | 2419 | * @param ctrl LCD controller (default = ST7032_3V3) |
wim | 28:30fa94f7341c | 2420 | */ |
wim | 28:30fa94f7341c | 2421 | TextLCD_I2C_N::TextLCD_I2C_N(I2C *i2c, char deviceAddress, LCDType type, PinName bl, LCDCtrl ctrl) : |
wim | 28:30fa94f7341c | 2422 | TextLCD_Base(type, ctrl), |
wim | 32:59c4b8f648d4 | 2423 | |
wim | 33:900a94bc7585 | 2424 | _i2c(i2c){ |
wim | 30:033048611c01 | 2425 | |
wim | 28:30fa94f7341c | 2426 | _slaveAddress = deviceAddress & 0xFE; |
wim | 28:30fa94f7341c | 2427 | |
wim | 28:30fa94f7341c | 2428 | // Setup the I2C bus |
wim | 29:a3663151aa65 | 2429 | // The max bitrate for ST7032i is 400kbit, lets stick to default here |
wim | 29:a3663151aa65 | 2430 | _i2c->frequency(100000); |
wim | 32:59c4b8f648d4 | 2431 | |
wim | 30:033048611c01 | 2432 | |
wim | 28:30fa94f7341c | 2433 | // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access. |
wim | 28:30fa94f7341c | 2434 | if (bl != NC) { |
wim | 28:30fa94f7341c | 2435 | _bl = new DigitalOut(bl); //Construct new pin |
wim | 28:30fa94f7341c | 2436 | _bl->write(0); //Deactivate |
wim | 28:30fa94f7341c | 2437 | } |
wim | 28:30fa94f7341c | 2438 | else { |
wim | 28:30fa94f7341c | 2439 | // No Hardware Backlight pin |
wim | 28:30fa94f7341c | 2440 | _bl = NULL; //Construct dummy pin |
wim | 28:30fa94f7341c | 2441 | } |
wim | 28:30fa94f7341c | 2442 | |
wim | 30:033048611c01 | 2443 | //Sanity check |
wim | 30:033048611c01 | 2444 | if (_ctrl & LCD_C_I2C) { |
wim | 30:033048611c01 | 2445 | _init(); |
wim | 30:033048611c01 | 2446 | } |
wim | 30:033048611c01 | 2447 | else { |
wim | 30:033048611c01 | 2448 | error("Error: LCD Controller type does not support native I2C interface\n\r"); |
wim | 30:033048611c01 | 2449 | } |
wim | 30:033048611c01 | 2450 | |
wim | 28:30fa94f7341c | 2451 | } |
wim | 28:30fa94f7341c | 2452 | |
wim | 28:30fa94f7341c | 2453 | TextLCD_I2C_N::~TextLCD_I2C_N() { |
wim | 28:30fa94f7341c | 2454 | if (_bl != NULL) {delete _bl;} // BL pin |
wim | 28:30fa94f7341c | 2455 | } |
wim | 28:30fa94f7341c | 2456 | |
wim | 28:30fa94f7341c | 2457 | // Not used in this mode |
wim | 28:30fa94f7341c | 2458 | void TextLCD_I2C_N::_setEnable(bool value) { |
wim | 28:30fa94f7341c | 2459 | } |
wim | 28:30fa94f7341c | 2460 | |
wim | 28:30fa94f7341c | 2461 | // Set RS pin |
wim | 28:30fa94f7341c | 2462 | // Used for mbed pins, I2C bus expander or SPI shiftregister and native I2C or SPI |
wim | 28:30fa94f7341c | 2463 | void TextLCD_I2C_N::_setRS(bool value) { |
wim | 30:033048611c01 | 2464 | // The controlbyte defines the meaning of the next byte. This next byte can either be data or command. |
wim | 30:033048611c01 | 2465 | // Start Slaveaddress+RW b7 b6 b5 b4 b3 b2 b1 b0 b7...........b0 Stop |
wim | 30:033048611c01 | 2466 | // Co RS RW 0 0 0 0 0 command or data |
wim | 30:033048611c01 | 2467 | // |
wim | 30:033048611c01 | 2468 | // C0=1 indicates that another controlbyte will follow after the next data or command byte |
wim | 30:033048611c01 | 2469 | // RS=1 means that next byte is data, RS=0 means that next byte is command |
wim | 30:033048611c01 | 2470 | // RW=0 means write to controller. RW=1 means that controller will be read from after the next command. |
wim | 30:033048611c01 | 2471 | // Many native I2C controllers dont support this option and it is not used by this lib. |
wim | 30:033048611c01 | 2472 | // |
wim | 30:033048611c01 | 2473 | |
wim | 28:30fa94f7341c | 2474 | if (value) { |
wim | 28:30fa94f7341c | 2475 | _controlbyte = 0x40; // Next byte is data, No more control bytes will follow |
wim | 28:30fa94f7341c | 2476 | } |
wim | 28:30fa94f7341c | 2477 | else { |
wim | 28:30fa94f7341c | 2478 | _controlbyte = 0x00; // Next byte is command, No more control bytes will follow |
wim | 28:30fa94f7341c | 2479 | } |
wim | 28:30fa94f7341c | 2480 | } |
wim | 28:30fa94f7341c | 2481 | |
wim | 28:30fa94f7341c | 2482 | // Set BL pin |
wim | 28:30fa94f7341c | 2483 | void TextLCD_I2C_N::_setBL(bool value) { |
wim | 28:30fa94f7341c | 2484 | if (_bl) { |
wim | 28:30fa94f7341c | 2485 | _bl->write(value); |
wim | 28:30fa94f7341c | 2486 | } |
wim | 28:30fa94f7341c | 2487 | } |
wim | 29:a3663151aa65 | 2488 | |
wim | 29:a3663151aa65 | 2489 | // Not used in this mode |
wim | 29:a3663151aa65 | 2490 | void TextLCD_I2C_N::_setData(int value) { |
wim | 29:a3663151aa65 | 2491 | } |
wim | 29:a3663151aa65 | 2492 | |
wim | 28:30fa94f7341c | 2493 | // Write a byte using I2C |
wim | 28:30fa94f7341c | 2494 | void TextLCD_I2C_N::_writeByte(int value) { |
wim | 30:033048611c01 | 2495 | // The controlbyte defines the meaning of the next byte. This next byte can either be data or command. |
wim | 30:033048611c01 | 2496 | // Start Slaveaddress+RW b7 b6 b5 b4 b3 b2 b1 b0 b7...........b0 Stop |
wim | 30:033048611c01 | 2497 | // Co RS RW 0 0 0 0 0 command or data |
wim | 30:033048611c01 | 2498 | // |
wim | 30:033048611c01 | 2499 | // C0=1 indicates that another controlbyte will follow after the next data or command byte |
wim | 30:033048611c01 | 2500 | // RS=1 means that next byte is data, RS=0 means that next byte is command |
wim | 30:033048611c01 | 2501 | // RW=0 means write to controller. RW=1 means that controller will be read from after the next command. |
wim | 30:033048611c01 | 2502 | // Many native I2C controllers dont support this option and it is not used by this lib. |
wim | 30:033048611c01 | 2503 | // |
wim | 28:30fa94f7341c | 2504 | char data[] = {_controlbyte, value}; |
wim | 28:30fa94f7341c | 2505 | |
wim | 32:59c4b8f648d4 | 2506 | #if(LCD_I2C_ACK==1) |
wim | 32:59c4b8f648d4 | 2507 | //Controllers that support ACK |
wim | 30:033048611c01 | 2508 | _i2c->write(_slaveAddress, data, 2); |
wim | 32:59c4b8f648d4 | 2509 | #else |
wim | 32:59c4b8f648d4 | 2510 | //Controllers that dont support ACK |
wim | 32:59c4b8f648d4 | 2511 | _i2c->start(); |
wim | 32:59c4b8f648d4 | 2512 | _i2c->write(_slaveAddress); |
wim | 32:59c4b8f648d4 | 2513 | _i2c->write(data[0]); |
wim | 32:59c4b8f648d4 | 2514 | _i2c->write(data[1]); |
wim | 32:59c4b8f648d4 | 2515 | _i2c->stop(); |
wim | 32:59c4b8f648d4 | 2516 | #endif |
wim | 28:30fa94f7341c | 2517 | } |
wim | 34:e5a0dcb43ecc | 2518 | #endif /* Native I2C */ |
wim | 28:30fa94f7341c | 2519 | //-------- End TextLCD_I2C_N ------------ |
wim | 28:30fa94f7341c | 2520 | |
wim | 28:30fa94f7341c | 2521 | |
wim | 23:d47f226efb24 | 2522 | //--------- Start TextLCD_SPI ----------- |
wim | 34:e5a0dcb43ecc | 2523 | #if(LCD_SPI == 1) /* SPI Expander SN74595 */ |
wim | 21:9eb628d9e164 | 2524 | |
wim | 22:35742ec80c24 | 2525 | /** Create a TextLCD interface using an SPI 74595 portexpander |
wim | 22:35742ec80c24 | 2526 | * |
wim | 22:35742ec80c24 | 2527 | * @param spi SPI Bus |
wim | 22:35742ec80c24 | 2528 | * @param cs chip select pin (active low) |
wim | 22:35742ec80c24 | 2529 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 22:35742ec80c24 | 2530 | * @param ctrl LCD controller (default = HD44780) |
wim | 22:35742ec80c24 | 2531 | */ |
wim | 21:9eb628d9e164 | 2532 | TextLCD_SPI::TextLCD_SPI(SPI *spi, PinName cs, LCDType type, LCDCtrl ctrl) : |
wim | 21:9eb628d9e164 | 2533 | TextLCD_Base(type, ctrl), |
wim | 21:9eb628d9e164 | 2534 | _spi(spi), |
wim | 21:9eb628d9e164 | 2535 | _cs(cs) { |
wim | 21:9eb628d9e164 | 2536 | |
wim | 32:59c4b8f648d4 | 2537 | // Init cs |
wim | 32:59c4b8f648d4 | 2538 | _setCS(true); |
wim | 32:59c4b8f648d4 | 2539 | |
wim | 21:9eb628d9e164 | 2540 | // Setup the spi for 8 bit data, low steady state clock, |
wim | 21:9eb628d9e164 | 2541 | // rising edge capture, with a 500KHz or 1MHz clock rate |
wim | 21:9eb628d9e164 | 2542 | _spi->format(8,0); |
wim | 21:9eb628d9e164 | 2543 | _spi->frequency(500000); |
wim | 21:9eb628d9e164 | 2544 | //_spi.frequency(1000000); |
wim | 21:9eb628d9e164 | 2545 | |
wim | 21:9eb628d9e164 | 2546 | // Init the portexpander bus |
wim | 21:9eb628d9e164 | 2547 | _lcd_bus = D_LCD_BUS_DEF; |
wim | 21:9eb628d9e164 | 2548 | |
wim | 21:9eb628d9e164 | 2549 | // write the new data to the portexpander |
wim | 21:9eb628d9e164 | 2550 | _setCS(false); |
wim | 21:9eb628d9e164 | 2551 | _spi->write(_lcd_bus); |
wim | 21:9eb628d9e164 | 2552 | _setCS(true); |
wim | 30:033048611c01 | 2553 | |
wim | 30:033048611c01 | 2554 | _init(); |
wim | 21:9eb628d9e164 | 2555 | } |
wim | 21:9eb628d9e164 | 2556 | |
wim | 21:9eb628d9e164 | 2557 | // Set E pin (or E2 pin) |
wim | 21:9eb628d9e164 | 2558 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 21:9eb628d9e164 | 2559 | void TextLCD_SPI::_setEnable(bool value) { |
wim | 21:9eb628d9e164 | 2560 | |
wim | 22:35742ec80c24 | 2561 | if(_ctrl_idx==_LCDCtrl_0) { |
wim | 26:bd897a001012 | 2562 | if (value) { |
wim | 22:35742ec80c24 | 2563 | _lcd_bus |= D_LCD_E; // Set E bit |
wim | 26:bd897a001012 | 2564 | } |
wim | 26:bd897a001012 | 2565 | else { |
wim | 22:35742ec80c24 | 2566 | _lcd_bus &= ~D_LCD_E; // Reset E bit |
wim | 26:bd897a001012 | 2567 | } |
wim | 22:35742ec80c24 | 2568 | } |
wim | 22:35742ec80c24 | 2569 | else { |
wim | 26:bd897a001012 | 2570 | if (value) { |
wim | 22:35742ec80c24 | 2571 | _lcd_bus |= D_LCD_E2; // Set E2 bit |
wim | 26:bd897a001012 | 2572 | } |
wim | 26:bd897a001012 | 2573 | else { |
wim | 22:35742ec80c24 | 2574 | _lcd_bus &= ~D_LCD_E2; // Reset E2 bit |
wim | 26:bd897a001012 | 2575 | } |
wim | 22:35742ec80c24 | 2576 | } |
wim | 21:9eb628d9e164 | 2577 | |
wim | 22:35742ec80c24 | 2578 | // write the new data to the SPI portexpander |
wim | 22:35742ec80c24 | 2579 | _setCS(false); |
wim | 22:35742ec80c24 | 2580 | _spi->write(_lcd_bus); |
wim | 30:033048611c01 | 2581 | _setCS(true); |
wim | 21:9eb628d9e164 | 2582 | } |
wim | 21:9eb628d9e164 | 2583 | |
wim | 21:9eb628d9e164 | 2584 | // Set RS pin |
wim | 21:9eb628d9e164 | 2585 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 21:9eb628d9e164 | 2586 | void TextLCD_SPI::_setRS(bool value) { |
wim | 21:9eb628d9e164 | 2587 | |
wim | 22:35742ec80c24 | 2588 | if (value) { |
wim | 21:9eb628d9e164 | 2589 | _lcd_bus |= D_LCD_RS; // Set RS bit |
wim | 22:35742ec80c24 | 2590 | } |
wim | 22:35742ec80c24 | 2591 | else { |
wim | 21:9eb628d9e164 | 2592 | _lcd_bus &= ~D_LCD_RS; // Reset RS bit |
wim | 22:35742ec80c24 | 2593 | } |
wim | 21:9eb628d9e164 | 2594 | |
wim | 21:9eb628d9e164 | 2595 | // write the new data to the SPI portexpander |
wim | 21:9eb628d9e164 | 2596 | _setCS(false); |
wim | 21:9eb628d9e164 | 2597 | _spi->write(_lcd_bus); |
wim | 21:9eb628d9e164 | 2598 | _setCS(true); |
wim | 21:9eb628d9e164 | 2599 | } |
wim | 21:9eb628d9e164 | 2600 | |
wim | 21:9eb628d9e164 | 2601 | // Set BL pin |
wim | 21:9eb628d9e164 | 2602 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 21:9eb628d9e164 | 2603 | void TextLCD_SPI::_setBL(bool value) { |
wim | 21:9eb628d9e164 | 2604 | |
wim | 22:35742ec80c24 | 2605 | if (value) { |
wim | 21:9eb628d9e164 | 2606 | _lcd_bus |= D_LCD_BL; // Set BL bit |
wim | 22:35742ec80c24 | 2607 | } |
wim | 22:35742ec80c24 | 2608 | else { |
wim | 21:9eb628d9e164 | 2609 | _lcd_bus &= ~D_LCD_BL; // Reset BL bit |
wim | 22:35742ec80c24 | 2610 | } |
wim | 21:9eb628d9e164 | 2611 | |
wim | 21:9eb628d9e164 | 2612 | // write the new data to the SPI portexpander |
wim | 21:9eb628d9e164 | 2613 | _setCS(false); |
wim | 21:9eb628d9e164 | 2614 | _spi->write(_lcd_bus); |
wim | 30:033048611c01 | 2615 | _setCS(true); |
wim | 21:9eb628d9e164 | 2616 | } |
wim | 21:9eb628d9e164 | 2617 | |
wim | 21:9eb628d9e164 | 2618 | // Place the 4bit data on the databus |
wim | 21:9eb628d9e164 | 2619 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 21:9eb628d9e164 | 2620 | void TextLCD_SPI::_setData(int value) { |
wim | 21:9eb628d9e164 | 2621 | int data; |
wim | 21:9eb628d9e164 | 2622 | |
wim | 22:35742ec80c24 | 2623 | // Set bit by bit to support any mapping of expander portpins to LCD pins |
wim | 22:35742ec80c24 | 2624 | |
wim | 22:35742ec80c24 | 2625 | data = value & 0x0F; |
wim | 26:bd897a001012 | 2626 | if (data & 0x01) { |
wim | 22:35742ec80c24 | 2627 | _lcd_bus |= D_LCD_D4; // Set Databit |
wim | 26:bd897a001012 | 2628 | } |
wim | 26:bd897a001012 | 2629 | else { |
wim | 22:35742ec80c24 | 2630 | _lcd_bus &= ~D_LCD_D4; // Reset Databit |
wim | 26:bd897a001012 | 2631 | } |
wim | 26:bd897a001012 | 2632 | |
wim | 26:bd897a001012 | 2633 | if (data & 0x02) { |
wim | 22:35742ec80c24 | 2634 | _lcd_bus |= D_LCD_D5; // Set Databit |
wim | 26:bd897a001012 | 2635 | } |
wim | 26:bd897a001012 | 2636 | else { |
wim | 22:35742ec80c24 | 2637 | _lcd_bus &= ~D_LCD_D5; // Reset Databit |
wim | 26:bd897a001012 | 2638 | } |
wim | 26:bd897a001012 | 2639 | |
wim | 26:bd897a001012 | 2640 | if (data & 0x04) { |
wim | 22:35742ec80c24 | 2641 | _lcd_bus |= D_LCD_D6; // Set Databit |
wim | 26:bd897a001012 | 2642 | } |
wim | 26:bd897a001012 | 2643 | else { |
wim | 22:35742ec80c24 | 2644 | _lcd_bus &= ~D_LCD_D6; // Reset Databit |
wim | 26:bd897a001012 | 2645 | } |
wim | 26:bd897a001012 | 2646 | |
wim | 26:bd897a001012 | 2647 | if (data & 0x08) { |
wim | 22:35742ec80c24 | 2648 | _lcd_bus |= D_LCD_D7; // Set Databit |
wim | 26:bd897a001012 | 2649 | } |
wim | 26:bd897a001012 | 2650 | else { |
wim | 26:bd897a001012 | 2651 | _lcd_bus &= ~D_LCD_D7; // Reset Databit |
wim | 26:bd897a001012 | 2652 | } |
wim | 21:9eb628d9e164 | 2653 | |
wim | 22:35742ec80c24 | 2654 | // write the new data to the SPI portexpander |
wim | 22:35742ec80c24 | 2655 | _setCS(false); |
wim | 22:35742ec80c24 | 2656 | _spi->write(_lcd_bus); |
wim | 30:033048611c01 | 2657 | _setCS(true); |
wim | 21:9eb628d9e164 | 2658 | } |
wim | 21:9eb628d9e164 | 2659 | |
wim | 21:9eb628d9e164 | 2660 | // Set CS line. |
wim | 21:9eb628d9e164 | 2661 | // Only used for SPI bus |
wim | 21:9eb628d9e164 | 2662 | void TextLCD_SPI::_setCS(bool value) { |
wim | 21:9eb628d9e164 | 2663 | |
wim | 21:9eb628d9e164 | 2664 | if (value) { |
wim | 21:9eb628d9e164 | 2665 | _cs = 1; // Set CS pin |
wim | 21:9eb628d9e164 | 2666 | } |
wim | 22:35742ec80c24 | 2667 | else { |
wim | 21:9eb628d9e164 | 2668 | _cs = 0; // Reset CS pin |
wim | 22:35742ec80c24 | 2669 | } |
wim | 21:9eb628d9e164 | 2670 | } |
wim | 34:e5a0dcb43ecc | 2671 | #endif /* SPI Expander SN74595 */ |
wim | 23:d47f226efb24 | 2672 | //---------- End TextLCD_SPI ------------ |
wim | 22:35742ec80c24 | 2673 | |
wim | 22:35742ec80c24 | 2674 | |
wim | 25:6162b31128c9 | 2675 | //--------- Start TextLCD_SPI_N --------- |
wim | 34:e5a0dcb43ecc | 2676 | #if(LCD_SPI_N == 1) /* Native SPI bus */ |
wim | 30:033048611c01 | 2677 | /** Create a TextLCD interface using a controller with a native SPI4 interface |
Sissors | 24:fb3399713710 | 2678 | * |
Sissors | 24:fb3399713710 | 2679 | * @param spi SPI Bus |
Sissors | 24:fb3399713710 | 2680 | * @param cs chip select pin (active low) |
wim | 25:6162b31128c9 | 2681 | * @param rs Instruction/data control line |
Sissors | 24:fb3399713710 | 2682 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 25:6162b31128c9 | 2683 | * @param bl Backlight control line (optional, default = NC) |
wim | 26:bd897a001012 | 2684 | * @param ctrl LCD controller (default = ST7032_3V3) |
wim | 25:6162b31128c9 | 2685 | */ |
wim | 25:6162b31128c9 | 2686 | TextLCD_SPI_N::TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type, PinName bl, LCDCtrl ctrl) : |
wim | 25:6162b31128c9 | 2687 | TextLCD_Base(type, ctrl), |
wim | 25:6162b31128c9 | 2688 | _spi(spi), |
wim | 25:6162b31128c9 | 2689 | _cs(cs), |
wim | 25:6162b31128c9 | 2690 | _rs(rs) { |
Sissors | 24:fb3399713710 | 2691 | |
wim | 32:59c4b8f648d4 | 2692 | // Init CS |
wim | 32:59c4b8f648d4 | 2693 | _cs = 1; |
wim | 32:59c4b8f648d4 | 2694 | |
Sissors | 24:fb3399713710 | 2695 | // Setup the spi for 8 bit data, low steady state clock, |
Sissors | 24:fb3399713710 | 2696 | // rising edge capture, with a 500KHz or 1MHz clock rate |
Sissors | 24:fb3399713710 | 2697 | _spi->format(8,0); |
Sissors | 24:fb3399713710 | 2698 | _spi->frequency(1000000); |
Sissors | 24:fb3399713710 | 2699 | |
Sissors | 24:fb3399713710 | 2700 | // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access. |
Sissors | 24:fb3399713710 | 2701 | if (bl != NC) { |
Sissors | 24:fb3399713710 | 2702 | _bl = new DigitalOut(bl); //Construct new pin |
Sissors | 24:fb3399713710 | 2703 | _bl->write(0); //Deactivate |
Sissors | 24:fb3399713710 | 2704 | } |
Sissors | 24:fb3399713710 | 2705 | else { |
Sissors | 24:fb3399713710 | 2706 | // No Hardware Backlight pin |
Sissors | 24:fb3399713710 | 2707 | _bl = NULL; //Construct dummy pin |
Sissors | 24:fb3399713710 | 2708 | } |
wim | 30:033048611c01 | 2709 | |
wim | 30:033048611c01 | 2710 | //Sanity check |
wim | 30:033048611c01 | 2711 | if (_ctrl & LCD_C_SPI4) { |
wim | 30:033048611c01 | 2712 | _init(); |
wim | 30:033048611c01 | 2713 | } |
wim | 30:033048611c01 | 2714 | else { |
wim | 30:033048611c01 | 2715 | error("Error: LCD Controller type does not support native SPI4 interface\n\r"); |
wim | 30:033048611c01 | 2716 | } |
Sissors | 24:fb3399713710 | 2717 | } |
Sissors | 24:fb3399713710 | 2718 | |
wim | 25:6162b31128c9 | 2719 | TextLCD_SPI_N::~TextLCD_SPI_N() { |
Sissors | 24:fb3399713710 | 2720 | if (_bl != NULL) {delete _bl;} // BL pin |
Sissors | 24:fb3399713710 | 2721 | } |
Sissors | 24:fb3399713710 | 2722 | |
Sissors | 24:fb3399713710 | 2723 | // Not used in this mode |
wim | 25:6162b31128c9 | 2724 | void TextLCD_SPI_N::_setEnable(bool value) { |
Sissors | 24:fb3399713710 | 2725 | } |
Sissors | 24:fb3399713710 | 2726 | |
Sissors | 24:fb3399713710 | 2727 | // Set RS pin |
Sissors | 24:fb3399713710 | 2728 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 25:6162b31128c9 | 2729 | void TextLCD_SPI_N::_setRS(bool value) { |
Sissors | 24:fb3399713710 | 2730 | _rs = value; |
Sissors | 24:fb3399713710 | 2731 | } |
Sissors | 24:fb3399713710 | 2732 | |
Sissors | 24:fb3399713710 | 2733 | // Set BL pin |
wim | 25:6162b31128c9 | 2734 | void TextLCD_SPI_N::_setBL(bool value) { |
wim | 26:bd897a001012 | 2735 | if (_bl) { |
Sissors | 24:fb3399713710 | 2736 | _bl->write(value); |
wim | 26:bd897a001012 | 2737 | } |
Sissors | 24:fb3399713710 | 2738 | } |
Sissors | 24:fb3399713710 | 2739 | |
wim | 29:a3663151aa65 | 2740 | // Not used in this mode |
wim | 29:a3663151aa65 | 2741 | void TextLCD_SPI_N::_setData(int value) { |
wim | 29:a3663151aa65 | 2742 | } |
wim | 29:a3663151aa65 | 2743 | |
Sissors | 24:fb3399713710 | 2744 | // Write a byte using SPI |
wim | 25:6162b31128c9 | 2745 | void TextLCD_SPI_N::_writeByte(int value) { |
Sissors | 24:fb3399713710 | 2746 | _cs = 0; |
Sissors | 24:fb3399713710 | 2747 | wait_us(1); |
Sissors | 24:fb3399713710 | 2748 | _spi->write(value); |
Sissors | 24:fb3399713710 | 2749 | wait_us(1); |
Sissors | 24:fb3399713710 | 2750 | _cs = 1; |
Sissors | 24:fb3399713710 | 2751 | } |
wim | 34:e5a0dcb43ecc | 2752 | #endif /* Native SPI bus */ |
wim | 25:6162b31128c9 | 2753 | //-------- End TextLCD_SPI_N ------------ |
wim | 21:9eb628d9e164 | 2754 | |
wim | 21:9eb628d9e164 | 2755 | |
wim | 30:033048611c01 | 2756 | //-------- Start TextLCD_SPI_N_3_9 -------- |
wim | 34:e5a0dcb43ecc | 2757 | #if(LCD_SPI_N_3_9 == 1) /* Native SPI bus */ |
wim | 34:e5a0dcb43ecc | 2758 | //Code checked out on logic analyser. Not yet tested on hardware.. |
wim | 30:033048611c01 | 2759 | |
wim | 30:033048611c01 | 2760 | /** Create a TextLCD interface using a controller with a native SPI3 9 bits interface |
wim | 30:033048611c01 | 2761 | * |
wim | 30:033048611c01 | 2762 | * @param spi SPI Bus |
wim | 30:033048611c01 | 2763 | * @param cs chip select pin (active low) |
wim | 30:033048611c01 | 2764 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 30:033048611c01 | 2765 | * @param bl Backlight control line (optional, default = NC) |
wim | 30:033048611c01 | 2766 | * @param ctrl LCD controller (default = AIP31068) |
wim | 30:033048611c01 | 2767 | */ |
wim | 30:033048611c01 | 2768 | TextLCD_SPI_N_3_9::TextLCD_SPI_N_3_9(SPI *spi, PinName cs, LCDType type, PinName bl, LCDCtrl ctrl) : |
wim | 30:033048611c01 | 2769 | TextLCD_Base(type, ctrl), |
wim | 30:033048611c01 | 2770 | _spi(spi), |
wim | 33:900a94bc7585 | 2771 | _cs(cs) { |
wim | 32:59c4b8f648d4 | 2772 | |
wim | 32:59c4b8f648d4 | 2773 | // Init CS |
wim | 32:59c4b8f648d4 | 2774 | _cs = 1; |
wim | 32:59c4b8f648d4 | 2775 | |
wim | 34:e5a0dcb43ecc | 2776 | // Setup the spi for 9 bit data, high steady state clock, |
wim | 30:033048611c01 | 2777 | // rising edge capture, with a 500KHz or 1MHz clock rate |
wim | 32:59c4b8f648d4 | 2778 | _spi->format(9,3); |
wim | 30:033048611c01 | 2779 | _spi->frequency(1000000); |
wim | 30:033048611c01 | 2780 | |
wim | 30:033048611c01 | 2781 | // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access. |
wim | 30:033048611c01 | 2782 | if (bl != NC) { |
wim | 30:033048611c01 | 2783 | _bl = new DigitalOut(bl); //Construct new pin |
wim | 30:033048611c01 | 2784 | _bl->write(0); //Deactivate |
wim | 30:033048611c01 | 2785 | } |
wim | 30:033048611c01 | 2786 | else { |
wim | 30:033048611c01 | 2787 | // No Hardware Backlight pin |
wim | 30:033048611c01 | 2788 | _bl = NULL; //Construct dummy pin |
wim | 30:033048611c01 | 2789 | } |
wim | 30:033048611c01 | 2790 | |
wim | 30:033048611c01 | 2791 | //Sanity check |
wim | 30:033048611c01 | 2792 | if (_ctrl & LCD_C_SPI3_9) { |
wim | 30:033048611c01 | 2793 | _init(); |
wim | 30:033048611c01 | 2794 | } |
wim | 30:033048611c01 | 2795 | else { |
wim | 30:033048611c01 | 2796 | error("Error: LCD Controller type does not support native SPI3 9 bits interface\n\r"); |
wim | 30:033048611c01 | 2797 | } |
wim | 30:033048611c01 | 2798 | } |
wim | 30:033048611c01 | 2799 | |
wim | 30:033048611c01 | 2800 | TextLCD_SPI_N_3_9::~TextLCD_SPI_N_3_9() { |
wim | 30:033048611c01 | 2801 | if (_bl != NULL) {delete _bl;} // BL pin |
wim | 30:033048611c01 | 2802 | } |
wim | 30:033048611c01 | 2803 | |
wim | 30:033048611c01 | 2804 | // Not used in this mode |
wim | 30:033048611c01 | 2805 | void TextLCD_SPI_N_3_9::_setEnable(bool value) { |
wim | 30:033048611c01 | 2806 | } |
wim | 30:033048611c01 | 2807 | |
wim | 30:033048611c01 | 2808 | // Set RS pin |
wim | 30:033048611c01 | 2809 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 30:033048611c01 | 2810 | void TextLCD_SPI_N_3_9::_setRS(bool value) { |
wim | 30:033048611c01 | 2811 | // The controlbits define the meaning of the next byte. This next byte can either be data or command. |
wim | 30:033048611c01 | 2812 | // b8 b7...........b0 |
wim | 30:033048611c01 | 2813 | // RS command or data |
wim | 30:033048611c01 | 2814 | // |
wim | 30:033048611c01 | 2815 | // RS=1 means that next byte is data, RS=0 means that next byte is command |
wim | 30:033048611c01 | 2816 | // |
wim | 30:033048611c01 | 2817 | |
wim | 30:033048611c01 | 2818 | if (value) { |
wim | 30:033048611c01 | 2819 | _controlbyte = 0x01; // Next byte is data |
wim | 30:033048611c01 | 2820 | } |
wim | 30:033048611c01 | 2821 | else { |
wim | 30:033048611c01 | 2822 | _controlbyte = 0x00; // Next byte is command |
wim | 34:e5a0dcb43ecc | 2823 | } |
wim | 30:033048611c01 | 2824 | } |
wim | 30:033048611c01 | 2825 | |
wim | 30:033048611c01 | 2826 | // Set BL pin |
wim | 30:033048611c01 | 2827 | void TextLCD_SPI_N_3_9::_setBL(bool value) { |
wim | 30:033048611c01 | 2828 | if (_bl) { |
wim | 30:033048611c01 | 2829 | _bl->write(value); |
wim | 30:033048611c01 | 2830 | } |
wim | 30:033048611c01 | 2831 | } |
wim | 30:033048611c01 | 2832 | |
wim | 30:033048611c01 | 2833 | // Not used in this mode |
wim | 30:033048611c01 | 2834 | void TextLCD_SPI_N_3_9::_setData(int value) { |
wim | 30:033048611c01 | 2835 | } |
wim | 30:033048611c01 | 2836 | |
wim | 30:033048611c01 | 2837 | // Write a byte using SPI3 9 bits mode |
wim | 30:033048611c01 | 2838 | void TextLCD_SPI_N_3_9::_writeByte(int value) { |
wim | 30:033048611c01 | 2839 | _cs = 0; |
wim | 30:033048611c01 | 2840 | wait_us(1); |
wim | 30:033048611c01 | 2841 | _spi->write( (_controlbyte << 8) | (value & 0xFF)); |
wim | 30:033048611c01 | 2842 | wait_us(1); |
wim | 30:033048611c01 | 2843 | _cs = 1; |
wim | 30:033048611c01 | 2844 | } |
wim | 34:e5a0dcb43ecc | 2845 | #endif /* Native SPI bus */ |
wim | 30:033048611c01 | 2846 | //------- End TextLCD_SPI_N_3_9 ----------- |
wim | 34:e5a0dcb43ecc | 2847 | |
wim | 34:e5a0dcb43ecc | 2848 | |
wim | 30:033048611c01 | 2849 | //------- Start TextLCD_SPI_N_3_10 -------- |
wim | 34:e5a0dcb43ecc | 2850 | #if(LCD_SPI_N_3_10 == 1) /* Native SPI bus */ |
wim | 30:033048611c01 | 2851 | |
wim | 30:033048611c01 | 2852 | /** Create a TextLCD interface using a controller with a native SPI3 10 bits interface |
wim | 30:033048611c01 | 2853 | * |
wim | 30:033048611c01 | 2854 | * @param spi SPI Bus |
wim | 30:033048611c01 | 2855 | * @param cs chip select pin (active low) |
wim | 30:033048611c01 | 2856 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 30:033048611c01 | 2857 | * @param bl Backlight control line (optional, default = NC) |
wim | 30:033048611c01 | 2858 | * @param ctrl LCD controller (default = AIP31068) |
wim | 30:033048611c01 | 2859 | */ |
wim | 30:033048611c01 | 2860 | TextLCD_SPI_N_3_10::TextLCD_SPI_N_3_10(SPI *spi, PinName cs, LCDType type, PinName bl, LCDCtrl ctrl) : |
wim | 30:033048611c01 | 2861 | TextLCD_Base(type, ctrl), |
wim | 30:033048611c01 | 2862 | _spi(spi), |
wim | 30:033048611c01 | 2863 | _cs(cs) { |
wim | 30:033048611c01 | 2864 | |
wim | 32:59c4b8f648d4 | 2865 | // Init CS |
wim | 32:59c4b8f648d4 | 2866 | _cs = 1; |
wim | 32:59c4b8f648d4 | 2867 | |
wim | 30:033048611c01 | 2868 | // Setup the spi for 10 bit data, low steady state clock, |
wim | 30:033048611c01 | 2869 | // rising edge capture, with a 500KHz or 1MHz clock rate |
wim | 30:033048611c01 | 2870 | _spi->format(10,0); |
wim | 30:033048611c01 | 2871 | _spi->frequency(1000000); |
wim | 30:033048611c01 | 2872 | |
wim | 30:033048611c01 | 2873 | // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access. |
wim | 30:033048611c01 | 2874 | if (bl != NC) { |
wim | 30:033048611c01 | 2875 | _bl = new DigitalOut(bl); //Construct new pin |
wim | 30:033048611c01 | 2876 | _bl->write(0); //Deactivate |
wim | 30:033048611c01 | 2877 | } |
wim | 30:033048611c01 | 2878 | else { |
wim | 30:033048611c01 | 2879 | // No Hardware Backlight pin |
wim | 30:033048611c01 | 2880 | _bl = NULL; //Construct dummy pin |
wim | 30:033048611c01 | 2881 | } |
wim | 30:033048611c01 | 2882 | |
wim | 30:033048611c01 | 2883 | //Sanity check |
wim | 30:033048611c01 | 2884 | if (_ctrl & LCD_C_SPI3_10) { |
wim | 30:033048611c01 | 2885 | _init(); |
wim | 30:033048611c01 | 2886 | } |
wim | 30:033048611c01 | 2887 | else { |
wim | 30:033048611c01 | 2888 | error("Error: LCD Controller type does not support native SPI3 10 bits interface\n\r"); |
wim | 30:033048611c01 | 2889 | } |
wim | 30:033048611c01 | 2890 | } |
wim | 30:033048611c01 | 2891 | |
wim | 30:033048611c01 | 2892 | TextLCD_SPI_N_3_10::~TextLCD_SPI_N_3_10() { |
wim | 30:033048611c01 | 2893 | if (_bl != NULL) {delete _bl;} // BL pin |
wim | 30:033048611c01 | 2894 | } |
wim | 30:033048611c01 | 2895 | |
wim | 30:033048611c01 | 2896 | // Not used in this mode |
wim | 30:033048611c01 | 2897 | void TextLCD_SPI_N_3_10::_setEnable(bool value) { |
wim | 30:033048611c01 | 2898 | } |
wim | 30:033048611c01 | 2899 | |
wim | 30:033048611c01 | 2900 | // Set RS pin |
wim | 30:033048611c01 | 2901 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 30:033048611c01 | 2902 | void TextLCD_SPI_N_3_10::_setRS(bool value) { |
wim | 30:033048611c01 | 2903 | // The controlbits define the meaning of the next byte. This next byte can either be data or command. |
wim | 30:033048611c01 | 2904 | // b9 b8 b7...........b0 |
wim | 30:033048611c01 | 2905 | // RS RW command or data |
wim | 30:033048611c01 | 2906 | // |
wim | 30:033048611c01 | 2907 | // RS=1 means that next byte is data, RS=0 means that next byte is command |
wim | 30:033048611c01 | 2908 | // RW=0 means that next byte is writen, RW=1 means that next byte is read (not used in this lib) |
wim | 30:033048611c01 | 2909 | // |
wim | 30:033048611c01 | 2910 | |
wim | 30:033048611c01 | 2911 | if (value) { |
wim | 30:033048611c01 | 2912 | _controlbyte = 0x02; // Next byte is data |
wim | 30:033048611c01 | 2913 | } |
wim | 30:033048611c01 | 2914 | else { |
wim | 30:033048611c01 | 2915 | _controlbyte = 0x00; // Next byte is command |
wim | 34:e5a0dcb43ecc | 2916 | } |
wim | 30:033048611c01 | 2917 | } |
wim | 30:033048611c01 | 2918 | |
wim | 30:033048611c01 | 2919 | // Set BL pin |
wim | 30:033048611c01 | 2920 | void TextLCD_SPI_N_3_10::_setBL(bool value) { |
wim | 30:033048611c01 | 2921 | if (_bl) { |
wim | 30:033048611c01 | 2922 | _bl->write(value); |
wim | 30:033048611c01 | 2923 | } |
wim | 30:033048611c01 | 2924 | } |
wim | 30:033048611c01 | 2925 | |
wim | 30:033048611c01 | 2926 | // Not used in this mode |
wim | 30:033048611c01 | 2927 | void TextLCD_SPI_N_3_10::_setData(int value) { |
wim | 30:033048611c01 | 2928 | } |
wim | 30:033048611c01 | 2929 | |
wim | 30:033048611c01 | 2930 | // Write a byte using SPI3 10 bits mode |
wim | 30:033048611c01 | 2931 | void TextLCD_SPI_N_3_10::_writeByte(int value) { |
wim | 30:033048611c01 | 2932 | _cs = 0; |
wim | 30:033048611c01 | 2933 | wait_us(1); |
wim | 30:033048611c01 | 2934 | _spi->write( (_controlbyte << 8) | (value & 0xFF)); |
wim | 30:033048611c01 | 2935 | wait_us(1); |
wim | 30:033048611c01 | 2936 | _cs = 1; |
wim | 30:033048611c01 | 2937 | } |
wim | 34:e5a0dcb43ecc | 2938 | #endif /* Native SPI bus */ |
wim | 30:033048611c01 | 2939 | //------- End TextLCD_SPI_N_3_10 ---------- |
wim | 34:e5a0dcb43ecc | 2940 | |
wim | 32:59c4b8f648d4 | 2941 | |
wim | 32:59c4b8f648d4 | 2942 | //------- Start TextLCD_SPI_N_3_16 -------- |
wim | 34:e5a0dcb43ecc | 2943 | #if(LCD_SPI_N_3_16 == 1) /* Native SPI bus */ |
wim | 34:e5a0dcb43ecc | 2944 | //Code checked out on logic analyser. Not yet tested on hardware.. |
wim | 32:59c4b8f648d4 | 2945 | |
wim | 32:59c4b8f648d4 | 2946 | /** Create a TextLCD interface using a controller with a native SPI3 16 bits interface |
wim | 32:59c4b8f648d4 | 2947 | * |
wim | 32:59c4b8f648d4 | 2948 | * @param spi SPI Bus |
wim | 32:59c4b8f648d4 | 2949 | * @param cs chip select pin (active low) |
wim | 32:59c4b8f648d4 | 2950 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 32:59c4b8f648d4 | 2951 | * @param bl Backlight control line (optional, default = NC) |
wim | 32:59c4b8f648d4 | 2952 | * @param ctrl LCD controller (default = PT6314) |
wim | 32:59c4b8f648d4 | 2953 | */ |
wim | 32:59c4b8f648d4 | 2954 | TextLCD_SPI_N_3_16::TextLCD_SPI_N_3_16(SPI *spi, PinName cs, LCDType type, PinName bl, LCDCtrl ctrl) : |
wim | 32:59c4b8f648d4 | 2955 | TextLCD_Base(type, ctrl), |
wim | 32:59c4b8f648d4 | 2956 | _spi(spi), |
wim | 32:59c4b8f648d4 | 2957 | _cs(cs) { |
wim | 32:59c4b8f648d4 | 2958 | |
wim | 32:59c4b8f648d4 | 2959 | // Init CS |
wim | 32:59c4b8f648d4 | 2960 | _cs = 1; |
wim | 32:59c4b8f648d4 | 2961 | |
wim | 32:59c4b8f648d4 | 2962 | // Setup the spi for 8 bit data, low steady state clock, |
wim | 32:59c4b8f648d4 | 2963 | // rising edge capture, with a 500KHz or 1MHz clock rate |
wim | 32:59c4b8f648d4 | 2964 | _spi->format(8,0); |
wim | 32:59c4b8f648d4 | 2965 | _spi->frequency(1000000); |
wim | 32:59c4b8f648d4 | 2966 | |
wim | 32:59c4b8f648d4 | 2967 | // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access. |
wim | 32:59c4b8f648d4 | 2968 | if (bl != NC) { |
wim | 32:59c4b8f648d4 | 2969 | _bl = new DigitalOut(bl); //Construct new pin |
wim | 32:59c4b8f648d4 | 2970 | _bl->write(0); //Deactivate |
wim | 32:59c4b8f648d4 | 2971 | } |
wim | 32:59c4b8f648d4 | 2972 | else { |
wim | 32:59c4b8f648d4 | 2973 | // No Hardware Backlight pin |
wim | 32:59c4b8f648d4 | 2974 | _bl = NULL; //Construct dummy pin |
wim | 32:59c4b8f648d4 | 2975 | } |
wim | 32:59c4b8f648d4 | 2976 | |
wim | 32:59c4b8f648d4 | 2977 | //Sanity check |
wim | 32:59c4b8f648d4 | 2978 | if (_ctrl & LCD_C_SPI3_16) { |
wim | 32:59c4b8f648d4 | 2979 | _init(); |
wim | 32:59c4b8f648d4 | 2980 | } |
wim | 32:59c4b8f648d4 | 2981 | else { |
wim | 32:59c4b8f648d4 | 2982 | error("Error: LCD Controller type does not support native SPI3 16 bits interface\n\r"); |
wim | 32:59c4b8f648d4 | 2983 | } |
wim | 32:59c4b8f648d4 | 2984 | } |
wim | 32:59c4b8f648d4 | 2985 | |
wim | 32:59c4b8f648d4 | 2986 | TextLCD_SPI_N_3_16::~TextLCD_SPI_N_3_16() { |
wim | 32:59c4b8f648d4 | 2987 | if (_bl != NULL) {delete _bl;} // BL pin |
wim | 32:59c4b8f648d4 | 2988 | } |
wim | 32:59c4b8f648d4 | 2989 | |
wim | 32:59c4b8f648d4 | 2990 | // Not used in this mode |
wim | 32:59c4b8f648d4 | 2991 | void TextLCD_SPI_N_3_16::_setEnable(bool value) { |
wim | 32:59c4b8f648d4 | 2992 | } |
wim | 32:59c4b8f648d4 | 2993 | |
wim | 32:59c4b8f648d4 | 2994 | // Set RS pin |
wim | 32:59c4b8f648d4 | 2995 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 32:59c4b8f648d4 | 2996 | void TextLCD_SPI_N_3_16::_setRS(bool value) { |
wim | 32:59c4b8f648d4 | 2997 | // The 16bit mode is split in 2 bytes. The first byte is for synchronisation and controlbits. The controlbits define the meaning of the next byte. |
wim | 32:59c4b8f648d4 | 2998 | // The 8 actual bits represent either a data or a command byte. |
wim | 32:59c4b8f648d4 | 2999 | // b15 b14 b13 b12 b11 b10 b9 b8 - b7 b6 b5 b4 b3 b2 b1 b0 |
wim | 32:59c4b8f648d4 | 3000 | // 1 1 1 1 1 RW RS 0 d7 d6 d5 d4 d3 d2 d1 d0 |
wim | 32:59c4b8f648d4 | 3001 | // |
wim | 32:59c4b8f648d4 | 3002 | // RS=1 means that next byte is data, RS=0 means that next byte is command |
wim | 32:59c4b8f648d4 | 3003 | // RW=0 means that next byte is writen, RW=1 means that next byte is read (not used in this lib) |
wim | 32:59c4b8f648d4 | 3004 | // |
wim | 32:59c4b8f648d4 | 3005 | |
wim | 32:59c4b8f648d4 | 3006 | if (value) { |
wim | 32:59c4b8f648d4 | 3007 | _controlbyte = 0xFA; // Next byte is data |
wim | 32:59c4b8f648d4 | 3008 | } |
wim | 32:59c4b8f648d4 | 3009 | else { |
wim | 32:59c4b8f648d4 | 3010 | _controlbyte = 0xF8; // Next byte is command |
wim | 32:59c4b8f648d4 | 3011 | } |
wim | 32:59c4b8f648d4 | 3012 | } |
wim | 32:59c4b8f648d4 | 3013 | |
wim | 32:59c4b8f648d4 | 3014 | // Set BL pin |
wim | 32:59c4b8f648d4 | 3015 | void TextLCD_SPI_N_3_16::_setBL(bool value) { |
wim | 32:59c4b8f648d4 | 3016 | if (_bl) { |
wim | 32:59c4b8f648d4 | 3017 | _bl->write(value); |
wim | 32:59c4b8f648d4 | 3018 | } |
wim | 32:59c4b8f648d4 | 3019 | } |
wim | 32:59c4b8f648d4 | 3020 | |
wim | 32:59c4b8f648d4 | 3021 | // Not used in this mode |
wim | 32:59c4b8f648d4 | 3022 | void TextLCD_SPI_N_3_16::_setData(int value) { |
wim | 32:59c4b8f648d4 | 3023 | } |
wim | 34:e5a0dcb43ecc | 3024 | |
wim | 32:59c4b8f648d4 | 3025 | // Write a byte using SPI3 16 bits mode |
wim | 32:59c4b8f648d4 | 3026 | void TextLCD_SPI_N_3_16::_writeByte(int value) { |
wim | 32:59c4b8f648d4 | 3027 | _cs = 0; |
wim | 32:59c4b8f648d4 | 3028 | wait_us(1); |
wim | 32:59c4b8f648d4 | 3029 | |
wim | 32:59c4b8f648d4 | 3030 | _spi->write(_controlbyte); |
wim | 32:59c4b8f648d4 | 3031 | |
wim | 32:59c4b8f648d4 | 3032 | _spi->write(value); |
wim | 32:59c4b8f648d4 | 3033 | |
wim | 32:59c4b8f648d4 | 3034 | wait_us(1); |
wim | 32:59c4b8f648d4 | 3035 | _cs = 1; |
wim | 32:59c4b8f648d4 | 3036 | } |
wim | 34:e5a0dcb43ecc | 3037 | #endif /* Native SPI bus */ |
wim | 32:59c4b8f648d4 | 3038 | //------- End TextLCD_SPI_N_3_16 ---------- |
wim | 34:e5a0dcb43ecc | 3039 | |
wim | 34:e5a0dcb43ecc | 3040 | |
wim | 32:59c4b8f648d4 | 3041 | //------- Start TextLCD_SPI_N_3_24 -------- |
wim | 34:e5a0dcb43ecc | 3042 | #if(LCD_SPI_N_3_24 == 1) /* Native SPI bus */ |
wim | 32:59c4b8f648d4 | 3043 | |
wim | 32:59c4b8f648d4 | 3044 | /** Create a TextLCD interface using a controller with a native SPI3 24 bits interface |
wim | 32:59c4b8f648d4 | 3045 | * |
wim | 32:59c4b8f648d4 | 3046 | * @param spi SPI Bus |
wim | 32:59c4b8f648d4 | 3047 | * @param cs chip select pin (active low) |
wim | 32:59c4b8f648d4 | 3048 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 32:59c4b8f648d4 | 3049 | * @param bl Backlight control line (optional, default = NC) |
wim | 32:59c4b8f648d4 | 3050 | * @param ctrl LCD controller (default = SSD1803) |
wim | 32:59c4b8f648d4 | 3051 | */ |
wim | 32:59c4b8f648d4 | 3052 | TextLCD_SPI_N_3_24::TextLCD_SPI_N_3_24(SPI *spi, PinName cs, LCDType type, PinName bl, LCDCtrl ctrl) : |
wim | 32:59c4b8f648d4 | 3053 | TextLCD_Base(type, ctrl), |
wim | 32:59c4b8f648d4 | 3054 | _spi(spi), |
wim | 32:59c4b8f648d4 | 3055 | _cs(cs) { |
wim | 32:59c4b8f648d4 | 3056 | |
wim | 32:59c4b8f648d4 | 3057 | // Init CS |
wim | 32:59c4b8f648d4 | 3058 | _cs = 1; |
wim | 32:59c4b8f648d4 | 3059 | |
wim | 34:e5a0dcb43ecc | 3060 | // Setup the spi for 8 bit data, high steady state clock, |
wim | 32:59c4b8f648d4 | 3061 | // rising edge capture, with a 500KHz or 1MHz clock rate |
wim | 34:e5a0dcb43ecc | 3062 | _spi->format(8,3); |
wim | 32:59c4b8f648d4 | 3063 | _spi->frequency(1000000); |
wim | 32:59c4b8f648d4 | 3064 | |
wim | 32:59c4b8f648d4 | 3065 | // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access. |
wim | 32:59c4b8f648d4 | 3066 | if (bl != NC) { |
wim | 32:59c4b8f648d4 | 3067 | _bl = new DigitalOut(bl); //Construct new pin |
wim | 32:59c4b8f648d4 | 3068 | _bl->write(0); //Deactivate |
wim | 32:59c4b8f648d4 | 3069 | } |
wim | 32:59c4b8f648d4 | 3070 | else { |
wim | 32:59c4b8f648d4 | 3071 | // No Hardware Backlight pin |
wim | 32:59c4b8f648d4 | 3072 | _bl = NULL; //Construct dummy pin |
wim | 32:59c4b8f648d4 | 3073 | } |
wim | 32:59c4b8f648d4 | 3074 | |
wim | 32:59c4b8f648d4 | 3075 | //Sanity check |
wim | 32:59c4b8f648d4 | 3076 | if (_ctrl & LCD_C_SPI3_24) { |
wim | 32:59c4b8f648d4 | 3077 | _init(); |
wim | 32:59c4b8f648d4 | 3078 | } |
wim | 32:59c4b8f648d4 | 3079 | else { |
wim | 32:59c4b8f648d4 | 3080 | error("Error: LCD Controller type does not support native SPI3 24 bits interface\n\r"); |
wim | 32:59c4b8f648d4 | 3081 | } |
wim | 32:59c4b8f648d4 | 3082 | } |
wim | 32:59c4b8f648d4 | 3083 | |
wim | 32:59c4b8f648d4 | 3084 | TextLCD_SPI_N_3_24::~TextLCD_SPI_N_3_24() { |
wim | 32:59c4b8f648d4 | 3085 | if (_bl != NULL) {delete _bl;} // BL pin |
wim | 32:59c4b8f648d4 | 3086 | } |
wim | 32:59c4b8f648d4 | 3087 | |
wim | 32:59c4b8f648d4 | 3088 | // Not used in this mode |
wim | 32:59c4b8f648d4 | 3089 | void TextLCD_SPI_N_3_24::_setEnable(bool value) { |
wim | 32:59c4b8f648d4 | 3090 | } |
wim | 32:59c4b8f648d4 | 3091 | |
wim | 32:59c4b8f648d4 | 3092 | // Set RS pin |
wim | 32:59c4b8f648d4 | 3093 | // Used for mbed pins, I2C bus expander or SPI shiftregister |
wim | 32:59c4b8f648d4 | 3094 | void TextLCD_SPI_N_3_24::_setRS(bool value) { |
wim | 32:59c4b8f648d4 | 3095 | // The 24bit mode is split in 3 bytes. The first byte is for synchronisation and controlbits. The controlbits define the meaning of the next two bytes. |
wim | 32:59c4b8f648d4 | 3096 | // Each byte encodes 4 actual bits. The 8 actual bits represent either a data or a command byte. |
wim | 32:59c4b8f648d4 | 3097 | // b23 b22 b21 b20 b19 b18 b17 b16 - b15 b14 b13 b12 b11 b10 b9 b8 - b7 b6 b5 b4 b3 b2 b1 b0 |
wim | 32:59c4b8f648d4 | 3098 | // 1 1 1 1 1 RW RS 0 d0 d1 d2 d3 0 0 0 0 d4 d5 d6 d7 0 0 0 0 |
wim | 32:59c4b8f648d4 | 3099 | // |
wim | 32:59c4b8f648d4 | 3100 | // RS=1 means that next byte is data, RS=0 means that next byte is command |
wim | 32:59c4b8f648d4 | 3101 | // RW=0 means that next byte is writen, RW=1 means that next byte is read (not used in this lib) |
wim | 32:59c4b8f648d4 | 3102 | // |
wim | 32:59c4b8f648d4 | 3103 | // Note: SPI3_24 expects LSB first. This is inconsistent with regular SPI convention (and hardware) that sends MSB first. |
wim | 32:59c4b8f648d4 | 3104 | |
wim | 32:59c4b8f648d4 | 3105 | if (value) { |
wim | 32:59c4b8f648d4 | 3106 | _controlbyte = 0xFA; // Next byte is data |
wim | 32:59c4b8f648d4 | 3107 | } |
wim | 32:59c4b8f648d4 | 3108 | else { |
wim | 32:59c4b8f648d4 | 3109 | _controlbyte = 0xF8; // Next byte is command |
wim | 34:e5a0dcb43ecc | 3110 | } |
wim | 32:59c4b8f648d4 | 3111 | } |
wim | 32:59c4b8f648d4 | 3112 | |
wim | 32:59c4b8f648d4 | 3113 | // Set BL pin |
wim | 32:59c4b8f648d4 | 3114 | void TextLCD_SPI_N_3_24::_setBL(bool value) { |
wim | 32:59c4b8f648d4 | 3115 | if (_bl) { |
wim | 32:59c4b8f648d4 | 3116 | _bl->write(value); |
wim | 32:59c4b8f648d4 | 3117 | } |
wim | 32:59c4b8f648d4 | 3118 | } |
wim | 32:59c4b8f648d4 | 3119 | |
wim | 32:59c4b8f648d4 | 3120 | // Not used in this mode |
wim | 32:59c4b8f648d4 | 3121 | void TextLCD_SPI_N_3_24::_setData(int value) { |
wim | 32:59c4b8f648d4 | 3122 | } |
wim | 32:59c4b8f648d4 | 3123 | |
wim | 32:59c4b8f648d4 | 3124 | //Mapping table to flip the bits around cause SPI3_24 expects LSB first. |
wim | 32:59c4b8f648d4 | 3125 | const uint8_t map3_24[16] = {0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0}; |
wim | 32:59c4b8f648d4 | 3126 | |
wim | 32:59c4b8f648d4 | 3127 | // Write a byte using SPI3 24 bits mode |
wim | 32:59c4b8f648d4 | 3128 | void TextLCD_SPI_N_3_24::_writeByte(int value) { |
wim | 32:59c4b8f648d4 | 3129 | _cs = 0; |
wim | 32:59c4b8f648d4 | 3130 | wait_us(1); |
wim | 32:59c4b8f648d4 | 3131 | _spi->write(_controlbyte); |
wim | 32:59c4b8f648d4 | 3132 | |
wim | 32:59c4b8f648d4 | 3133 | //Map and send the LSB nibble |
wim | 32:59c4b8f648d4 | 3134 | _spi->write( map3_24[value & 0x0F]); |
wim | 32:59c4b8f648d4 | 3135 | |
wim | 32:59c4b8f648d4 | 3136 | //Map and send the MSB nibble |
wim | 32:59c4b8f648d4 | 3137 | _spi->write( map3_24[(value >> 4) & 0x0F]); |
wim | 32:59c4b8f648d4 | 3138 | |
wim | 32:59c4b8f648d4 | 3139 | wait_us(1); |
wim | 32:59c4b8f648d4 | 3140 | _cs = 1; |
wim | 32:59c4b8f648d4 | 3141 | } |
wim | 34:e5a0dcb43ecc | 3142 | #endif /* Native SPI bus */ |
wim | 32:59c4b8f648d4 | 3143 | //------- End TextLCD_SPI_N_3_24 ---------- |