fix for ILI9325
Fork of TFTLCD by
Embed:
(wiki syntax)
Show/hide line numbers
ili9328.cpp
00001 /* 00002 * Copyright (C)2010-2012 Henning Karlsen. All right reserved. 00003 * Copyright (C)2012-2013 Todor Todorov. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to: 00017 * 00018 * Free Software Foundation, Inc. 00019 * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA 00020 * 00021 *********************************************************************/ 00022 #include "ili9328.h" 00023 #include "helpers.h" 00024 00025 ILI9328_LCD::ILI9328_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, BusOut* DATA_PORT, PinName BL, PinName RD, backlight_t blType, float defaultBackLightLevel ) 00026 : LCD( 240, 320, CS, RS, RESET, BL, blType, defaultBackLightLevel ), _lcd_pin_wr( WR ) 00027 { 00028 _lcd_port = DATA_PORT; 00029 if ( RD != NC ) _lcd_pin_rd = new DigitalOut( RD ); 00030 else _lcd_pin_rd = 0; 00031 } 00032 00033 void ILI9328_LCD::Initialize( orientation_t orientation, colordepth_t colors ) 00034 { 00035 _orientation = orientation; 00036 _colorDepth = colors; 00037 00038 _lcd_pin_reset = HIGH; 00039 wait_ms( 50 ); 00040 _lcd_pin_reset = LOW; 00041 wait_ms( 100 ); 00042 _lcd_pin_reset = HIGH; 00043 wait_ms( 1000 ); 00044 _lcd_pin_cs = HIGH; 00045 if ( _lcd_pin_bl != 0 ) 00046 *_lcd_pin_bl = HIGH; 00047 else if ( _bl_pwm != 0 ) 00048 *_bl_pwm = _bl_pwm_default; 00049 if ( _lcd_pin_rd != 0 ) 00050 *_lcd_pin_rd = HIGH; 00051 _lcd_pin_wr = HIGH; 00052 wait_ms( 15 ); 00053 00054 Activate(); 00055 00056 short drivOut = 0; 00057 short entryMod = 0; 00058 short gateScan = 0x2700; 00059 switch ( _orientation ) 00060 { 00061 case LANDSCAPE: 00062 drivOut = 0x0100; 00063 entryMod |= 0x0038; 00064 gateScan |= 0x0000; 00065 break; 00066 00067 case LANDSCAPE_REV: 00068 drivOut = 0x0000; 00069 entryMod |= 0x0038; 00070 gateScan |= 0x8000; 00071 break; 00072 00073 case PORTRAIT_REV: 00074 drivOut = 0x0000; 00075 entryMod |= 0x0030; 00076 gateScan |= 0x0000; 00077 break; 00078 00079 case PORTRAIT: 00080 default: 00081 drivOut = 0x0100; 00082 entryMod |= 0x0030; 00083 gateScan |= 0x8000; 00084 break; 00085 } 00086 switch ( _colorDepth ) 00087 { 00088 case RGB18: 00089 entryMod |= 0x9000; 00090 break; 00091 00092 case RGB16: 00093 default: 00094 entryMod |= 0x1000; 00095 break; 00096 } 00097 00098 WriteCmdData( ILI932X_DRIV_OUT_CTRL, drivOut ); // set Driver Output Control 00099 WriteCmdData( ILI932X_DRIV_WAV_CTRL, 0x0700 ); // set 1 line inversion 00100 WriteCmdData( ILI932X_ENTRY_MOD, entryMod ); // set GRAM write direction and BGR=1. 00101 WriteCmdData( ILI932X_RESIZE_CTRL, 0x0000 ); // Resize register 00102 WriteCmdData( ILI932X_DISP_CTRL2, 0x0202 ); // set the back porch and front porch 00103 WriteCmdData( ILI932X_DISP_CTRL3, 0x0000 ); // set non-display area refresh cycle ISC[3:0] 00104 WriteCmdData( ILI932X_DISP_CTRL4, 0x0000 ); // FMARK function 00105 WriteCmdData( ILI932X_RGB_DISP_IF_CTRL1, 0x0000 ); // RGB interface setting 00106 WriteCmdData( ILI932X_FRM_MARKER_POS, 0x0000 ); // Frame marker Position 00107 WriteCmdData( ILI932X_RGB_DISP_IF_CTRL2, 0x0000 ); // RGB interface polarity 00108 // ----------- Power On sequence ----------- // 00109 WriteCmdData( ILI932X_POW_CTRL1, 0x0000 ); // SAP, BT[3:0], AP, DSTB, SLP, STB 00110 WriteCmdData( ILI932X_POW_CTRL2, 0x0007 ); // DC1[2:0], DC0[2:0], VC[2:0] 00111 WriteCmdData( ILI932X_POW_CTRL3, 0x0000 ); // VREG1OUT voltage 00112 WriteCmdData( ILI932X_POW_CTRL4, 0x0000 ); // VDV[4:0] for VCOM amplitude 00113 wait_ms( 200 ); // Dis-charge capacitor power voltage 00114 WriteCmdData( ILI932X_POW_CTRL1, 0x1690 ); // SAP, BT[3:0], AP, DSTB, SLP, STB 00115 WriteCmdData( ILI932X_POW_CTRL2, 0x0227 ); // Set DC1[2:0], DC0[2:0], VC[2:0] 00116 wait_ms( 50 ); // Delay 50ms 00117 WriteCmdData( ILI932X_POW_CTRL3, 0x001A ); // 0012 00118 wait_ms( 50 ); // Delay 50ms 00119 WriteCmdData( ILI932X_POW_CTRL4, 0x1800 ); // VDV[4:0] for VCOM amplitude 00120 WriteCmdData( ILI932X_POW_CTRL7, 0x002A ); // 04 VCM[5:0] for VCOMH 00121 wait_ms( 50 ); // Delay 50ms 00122 WriteCmdData( ILI932X_GRAM_HOR_AD, 0x0000 ); // GRAM horizontal Address 00123 WriteCmdData( ILI932X_GRAM_VER_AD, 0x0000 ); // GRAM Vertical Address 00124 // ----------- Adjust the Gamma Curve ----------// 00125 WriteCmdData( ILI932X_GAMMA_CTRL1, 0x0000 ); 00126 WriteCmdData( ILI932X_GAMMA_CTRL2, 0x0000 ); 00127 WriteCmdData( ILI932X_GAMMA_CTRL3, 0x0000 ); 00128 WriteCmdData( ILI932X_GAMMA_CTRL4, 0x0206 ); 00129 WriteCmdData( ILI932X_GAMMA_CTRL5, 0x0808 ); 00130 WriteCmdData( ILI932X_GAMMA_CTRL6, 0x0007 ); 00131 WriteCmdData( ILI932X_GAMMA_CTRL7, 0x0201 ); 00132 WriteCmdData( ILI932X_GAMMA_CTRL8, 0x0000 ); 00133 WriteCmdData( ILI932X_GAMMA_CTRL9, 0x0000 ); 00134 WriteCmdData( ILI932X_GAMMA_CTRL10, 0x0000 ); 00135 //------------------ Set GRAM area ---------------// 00136 WriteCmdData( ILI932X_HOR_END_AD, 0x00EF ); // Horizontal GRAM End Address 00137 WriteCmdData( ILI932X_VER_START_AD, 0x0000 ); // Vertical GRAM Start Address 00138 WriteCmdData( ILI932X_VER_END_AD, 0x013F ); // Vertical GRAM Start Address 00139 WriteCmdData( ILI932X_GATE_SCAN_CTRL1, gateScan ); // Gate Scan Line (0xA700) 00140 WriteCmdData( ILI932X_GATE_SCAN_CTRL2, 0x0003 ); // NDL,VLE, REV 00141 WriteCmdData( ILI932X_GATE_SCAN_CTRL3, 0x0000 ); // set scrolling line 00142 //-------------- Panel Control -------------------// 00143 WriteCmdData( ILI932X_PANEL_IF_CTRL1, 0x0010 ); 00144 WriteCmdData( ILI932X_PANEL_IF_CTRL2, 0x0000 ); 00145 WriteCmdData( ILI932X_PANEL_IF_CTRL4, 0X1100 ); 00146 WriteCmdData( ILI932X_DISP_CTRL1, 0x0133 ); // 262K color and display ON 00147 00148 Deactivate(); 00149 } 00150 00151 void ILI9328_LCD::Sleep( void ) 00152 { 00153 Activate(); 00154 WriteCmdData( 0x10, 0x1692 ); // enter sleep mode 00155 wait_ms( 200 ); 00156 LCD::Sleep(); 00157 Deactivate(); 00158 } 00159 00160 void ILI9328_LCD::WakeUp( void ) 00161 { 00162 Activate(); 00163 WriteCmdData( 0x10, 0x1690 ); // exit sleep mode 00164 wait_ms( 200 ); 00165 LCD::WakeUp(); 00166 Deactivate(); 00167 } 00168 00169 //fix to 8bit mode 00170 void ILI9328_LCD::WriteCmd( unsigned short cmd ) 00171 { 00172 _lcd_pin_rs = LOW; 00173 _lcd_port->write( 0 ); 00174 pulseLow( _lcd_pin_wr ); 00175 _lcd_port->write( cmd ); 00176 pulseLow( _lcd_pin_wr ); 00177 } 00178 //fix to 8bit mode 00179 void ILI9328_LCD::WriteData( unsigned short data ) 00180 { 00181 _lcd_pin_rs = HIGH; 00182 _lcd_port->write( data>>8 ); 00183 pulseLow( _lcd_pin_wr ); 00184 _lcd_port->write( data&0xff ); 00185 pulseLow( _lcd_pin_wr ); 00186 } 00187 00188 void ILI9328_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 ) 00189 { 00190 switch ( _orientation ) 00191 { 00192 case LANDSCAPE: 00193 case LANDSCAPE_REV: 00194 WriteCmdData( 0x20, y1 ); 00195 WriteCmdData( 0x21, x1 ); 00196 WriteCmdData( 0x50, y1 ); 00197 WriteCmdData( 0x52, x1 ); 00198 WriteCmdData( 0x51, y2 ); 00199 WriteCmdData( 0x53, x2 ); 00200 break; 00201 00202 case PORTRAIT_REV: 00203 case PORTRAIT: 00204 default: 00205 WriteCmdData( 0x20, x1 ); 00206 WriteCmdData( 0x21, y1 ); 00207 WriteCmdData( 0x50, x1 ); 00208 WriteCmdData( 0x52, y1 ); 00209 WriteCmdData( 0x51, x2 ); 00210 WriteCmdData( 0x53, y2 ); 00211 break; 00212 } 00213 WriteCmd( 0x22 ); 00214 } 00215 00216 void ILI9328_LCD::SetPixelColor( unsigned int color, colordepth_t mode ) 00217 { 00218 unsigned char r, g, b; 00219 unsigned short clr; 00220 r = g = b = 0; 00221 if ( _colorDepth == RGB16 ) 00222 { 00223 switch ( mode ) 00224 { 00225 case RGB16: 00226 WriteData( color & 0xFFFF ); 00227 break; 00228 case RGB18: 00229 r = ( color >> 10 ) & 0xF8; 00230 g = ( color >> 4 ) & 0xFC; 00231 b = ( color >> 1 ) & 0x1F; 00232 clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | b ); 00233 WriteData( clr ); 00234 break; 00235 case RGB24: 00236 r = ( color >> 16 ) & 0xF8; 00237 g = ( color >> 8 ) & 0xFC; 00238 b = color & 0xF8; 00239 clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | ( b >> 3 ) ); 00240 WriteData( clr ); 00241 break; 00242 } 00243 } 00244 else if ( _colorDepth == RGB18 ) 00245 { 00246 switch ( mode ) 00247 { 00248 case RGB16: 00249 r = ( ( color >> 8 ) & 0xF8 ) | ( ( color & 0x8000 ) >> 13 ); 00250 g = ( color >> 3 ) & 0xFC; 00251 b = ( ( color << 3 ) & 0xFC ) | ( ( color >> 3 ) & 0x01 ); 00252 break; 00253 case RGB18: 00254 b = ( color << 2 ) & 0xFC; 00255 g = ( color >> 4 ) & 0xFC; 00256 r = ( color >> 10 ) & 0xFC; 00257 break; 00258 case RGB24: 00259 r = ( color >> 16 ) & 0xFC; 00260 g = ( color >> 8 ) & 0xFC; 00261 b = color & 0xFC; 00262 break; 00263 } 00264 clr = ( r << 8 ) | ( g << 2 ) | ( b >> 4 ); 00265 WriteData( clr ); 00266 WriteData( b << 4 ); 00267 } 00268 }
Generated on Wed Jul 13 2022 00:39:16 by
1.7.2
