Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: GR-PEACH_TFTLCD_8bit
Fork of TFTLCD_8bit by
ili9325.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 "ili9325.h" 00023 #include "helpers.h" 00024 00025 ILI9325_LCD::ILI9325_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 ILI9325_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 wait_ms( 100 ); 00041 _lcd_pin_reset = LOW; 00042 // wait_ms( 100 ); 00043 wait_ms( 200 ); 00044 _lcd_pin_reset = HIGH; 00045 // wait_ms( 1000 ); 00046 wait_ms( 1000 ); 00047 _lcd_pin_cs = HIGH; 00048 if ( _lcd_pin_bl != 0 ) 00049 *_lcd_pin_bl = HIGH; 00050 else if ( _bl_pwm != 0 ) 00051 *_bl_pwm = _bl_pwm_default; 00052 if ( _lcd_pin_rd != 0 ) 00053 *_lcd_pin_rd = HIGH; 00054 _lcd_pin_wr = HIGH; 00055 // wait_ms( 15 ); 00056 wait_ms( 50 ); 00057 00058 Activate(); 00059 00060 short drivOut = 0; 00061 short entryMod = 0; 00062 short gateScan = 0x2700; 00063 switch ( _orientation ) 00064 { 00065 case LANDSCAPE: 00066 drivOut = 0x0100; 00067 entryMod |= 0x0038; 00068 gateScan |= 0x0000; 00069 break; 00070 00071 case LANDSCAPE_REV: 00072 drivOut = 0x0000; 00073 entryMod |= 0x0038; 00074 gateScan |= 0x8000; 00075 break; 00076 00077 case PORTRAIT_REV: 00078 drivOut = 0x0000; 00079 entryMod |= 0x0030; 00080 gateScan |= 0x0000; 00081 break; 00082 00083 case PORTRAIT: 00084 default: 00085 drivOut = 0x0100; 00086 entryMod |= 0x0030; 00087 gateScan |= 0x8000; 00088 break; 00089 } 00090 switch ( _colorDepth ) 00091 { 00092 case RGB18: 00093 entryMod |= 0x9000; 00094 break; 00095 00096 case RGB16: 00097 default: 00098 entryMod |= 0x1000; 00099 break; 00100 } 00101 00102 // WriteCmdData( 0xE5, 0x78F0 ); // set SRAM internal timing 00103 WriteCmdData( 0xE5, 0x8000 ); // set SRAM internal timing 00104 WriteCmdData( 0x00, 0x0000 ); // set Driver Output Control 00105 WriteCmdData( 0x01, drivOut ); // set Driver Output Control 00106 // WriteCmdData( 0x02, 0x0200 ); // set 1 line inversion 00107 WriteCmdData( 0x02, 0x0700 ); // set 1 line inversion 00108 WriteCmdData( 0x03, entryMod ); // set GRAM write direction and BGR=1. 00109 WriteCmdData( 0x04, 0x0000 ); // Resize register 00110 // WriteCmdData( 0x08, 0x0207 ); // set the back porch and front porch 00111 WriteCmdData( 0x08, 0x0202 ); // set the back porch and front porch 00112 00113 WriteCmdData( 0x09, 0x0000 ); // set non-display area refresh cycle ISC[3:0] 00114 WriteCmdData( 0x0A, 0x0000 ); // FMARK function 00115 WriteCmdData( 0x0C, 0x0000 ); // RGB interface setting 00116 WriteCmdData( 0x0D, 0x0000 ); // Frame marker Position 00117 WriteCmdData( 0x0F, 0x0000 ); // RGB interface polarity 00118 // ----------- Power On sequence ----------- // 00119 WriteCmdData( 0x10, 0x0000 ); // SAP, BT[3:0], AP, DSTB, SLP, STB 00120 // WriteCmdData( 0x11, 0x0007 ); // DC1[2:0], DC0[2:0], VC[2:0] 00121 WriteCmdData( 0x11, 0x0000 ); // DC1[2:0], DC0[2:0], VC[2:0] 00122 WriteCmdData( 0x12, 0x0000 ); // VREG1OUT voltage 00123 WriteCmdData( 0x13, 0x0000 ); // VDV[4:0] for VCOM amplitude 00124 // WriteCmdData( 0x07, 0x0001 ); 00125 wait_ms( 200 ); // Dis-charge capacitor power voltage 00126 00127 // WriteCmdData( 0x10, 0x1690 ); // SAP, BT[3:0], AP, DSTB, SLP, STB 00128 WriteCmdData( 0x10, 0x17B0 ); // SAP, BT[3:0], AP, DSTB, SLP, STB 00129 // WriteCmdData( 0x11, 0x0227 ); // Set DC1[2:0], DC0[2:0], VC[2:0] 00130 WriteCmdData( 0x11, 0x0037 ); // Set DC1[2:0], DC0[2:0], VC[2:0] 00131 wait_ms( 50 ); // Delay 50ms 00132 00133 // WriteCmdData( 0x12, 0x000D ); // 0012 00134 WriteCmdData( 0x12, 0x0138 ); // 0012 00135 wait_ms( 50 ); // Delay 50ms 00136 00137 // WriteCmdData( 0x13, 0x1200 ); // VDV[4:0] for VCOM amplitude 00138 WriteCmdData( 0x13, 0x1700 ); // VDV[4:0] for VCOM amplitude 00139 // WriteCmdData( 0x29, 0x000A ); // 04 VCM[5:0] for VCOMH 00140 WriteCmdData( 0x29, 0x000D ); // 04 VCM[5:0] for VCOMH 00141 WriteCmdData( 0x2B, 0x000D ); // Set Frame Rate 00142 wait_ms( 50 ); // Delay 50ms 00143 00144 WriteCmdData( 0x20, 0x0000 ); // GRAM horizontal Address 00145 WriteCmdData( 0x21, 0x0000 ); // GRAM Vertical Address 00146 00147 // ----------- Adjust the Gamma Curve ----------// 00148 // WriteCmdData( 0x30, 0x0000 ); 00149 WriteCmdData( 0x30, 0x0001 ); 00150 // WriteCmdData( 0x31, 0x0404 ); 00151 WriteCmdData( 0x31, 0x0606 ); 00152 // WriteCmdData( 0x32, 0x0003 ); 00153 WriteCmdData( 0x32, 0x0304 ); 00154 //new line 00155 WriteCmdData( 0x33, 0x0202 ); 00156 WriteCmdData( 0x34, 0x0202 ); 00157 // WriteCmdData( 0x35, 0x0405 ); 00158 WriteCmdData( 0x35, 0x0103 ); 00159 00160 // WriteCmdData( 0x36, 0x0808 ); 00161 WriteCmdData( 0x36, 0x011D ); 00162 // WriteCmdData( 0x37, 0x0407 ); 00163 WriteCmdData( 0x37, 0x0404 ); 00164 // WriteCmdData( 0x38, 0x0303 ); 00165 WriteCmdData( 0x38, 0x0404 ); 00166 // WriteCmdData( 0x39, 0x0707 ); 00167 WriteCmdData( 0x39, 0x0404 ); 00168 // WriteCmdData( 0x3C, 0x0504 ); 00169 WriteCmdData( 0x3C, 0x0700 ); 00170 // WriteCmdData( 0x3D, 0x0808 ); 00171 WriteCmdData( 0x3D, 0x0A1F ); 00172 00173 //------------------ Set GRAM area ---------------// 00174 WriteCmdData( 0x50, 0x0000 ); // Horizontal GRAM Start Address 00175 WriteCmdData( 0x51, 0x00EF ); // Horizontal GRAM End Address 00176 WriteCmdData( 0x52, 0x0000 ); // Vertical GRAM Start Address 00177 WriteCmdData( 0x53, 0x013F ); // Vertical GRAM Start Address 00178 WriteCmdData( 0x60, gateScan ); // Gate Scan Line (0xA700) 00179 // WriteCmdData( 0x61, 0x0000 ); // NDL,VLE, REV 00180 WriteCmdData( 0x61, 0x0001 ); // NDL,VLE, REV 00181 WriteCmdData( 0x6A, 0x0000 ); // set scrolling line 00182 //-------------- Partial Display Control ---------// 00183 WriteCmdData( 0x80, 0x0000 ); 00184 WriteCmdData( 0x81, 0x0000 ); 00185 WriteCmdData( 0x82, 0x0000 ); 00186 WriteCmdData( 0x83, 0x0000 ); 00187 WriteCmdData( 0x84, 0x0000 ); 00188 WriteCmdData( 0x85, 0x0000 ); 00189 //-------------- Panel Control -------------------// 00190 WriteCmdData( 0x90, 0x0010 ); 00191 WriteCmdData( 0x92, 0x0000 ); 00192 //new lines 00193 WriteCmdData( 0x93, 0x0003 ); 00194 WriteCmdData( 0x95, 0x0101 ); 00195 WriteCmdData( 0x97, 0x0000 ); 00196 WriteCmdData( 0x98, 0x0000 ); 00197 00198 // WriteCmdData( 0x07, 0x0133 ); // 262K color and display ON 00199 WriteCmdData( 0x07, 0x0021 ); // 262K color and display ON 00200 WriteCmdData( 0x07, 0x0031 ); // 262K color and display ON 00201 WriteCmdData( 0x07, 0x0173 ); // 262K color and display ON 00202 //new line 00203 wait_ms( 50 ); // Delay 50ms 00204 Deactivate(); 00205 } 00206 00207 void ILI9325_LCD::Sleep( void ) 00208 { 00209 Activate(); 00210 WriteCmdData( 0x10, 0x1692 ); // enter sleep mode 00211 wait_ms( 200 ); 00212 LCD::Sleep(); 00213 Deactivate(); 00214 } 00215 00216 void ILI9325_LCD::WakeUp( void ) 00217 { 00218 Activate(); 00219 WriteCmdData( 0x10, 0x1690 ); // exit sleep mode 00220 wait_ms( 200 ); 00221 LCD::WakeUp(); 00222 Deactivate(); 00223 } 00224 00225 void ILI9325_LCD::WriteCmd( unsigned short cmd ) 00226 { 00227 00228 unsigned short u,l; 00229 u = (cmd>>8) & 0xFF; 00230 l = cmd & 0xFF; 00231 00232 //New 00233 _lcd_pin_cs = LOW; 00234 // 00235 _lcd_pin_rs = LOW; 00236 00237 //New 00238 *_lcd_pin_rd = HIGH; 00239 _lcd_pin_wr = HIGH; 00240 // 00241 _lcd_port->write( u ); 00242 pulseLow( _lcd_pin_wr ); 00243 00244 _lcd_port->write( l ); 00245 pulseLow( _lcd_pin_wr ); 00246 00247 //New 00248 _lcd_pin_cs = HIGH; 00249 // 00250 } 00251 00252 void ILI9325_LCD::WriteData( unsigned short data ) 00253 { 00254 unsigned short u,l; 00255 u = (data>>8) & 0xFF; 00256 l = data & 0xFF; 00257 00258 //New 00259 _lcd_pin_cs = LOW; 00260 // 00261 _lcd_pin_rs = HIGH; 00262 //New 00263 *_lcd_pin_rd = HIGH; 00264 _lcd_pin_wr = HIGH; 00265 // 00266 _lcd_port->write( u ); 00267 pulseLow( _lcd_pin_wr ); 00268 00269 _lcd_port->write( l ); 00270 pulseLow( _lcd_pin_wr ); 00271 00272 //New 00273 _lcd_pin_cs = HIGH; 00274 // 00275 } 00276 00277 void ILI9325_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 ) 00278 { 00279 switch ( _orientation ) 00280 { 00281 case LANDSCAPE: 00282 case LANDSCAPE_REV: 00283 WriteCmdData( 0x20, y1 ); 00284 WriteCmdData( 0x21, x1 ); 00285 WriteCmdData( 0x50, y1 ); 00286 WriteCmdData( 0x52, x1 ); 00287 WriteCmdData( 0x51, y2 ); 00288 WriteCmdData( 0x53, x2 ); 00289 break; 00290 00291 case PORTRAIT_REV: 00292 case PORTRAIT: 00293 default: 00294 WriteCmdData( 0x20, x1 ); 00295 WriteCmdData( 0x21, y1 ); 00296 WriteCmdData( 0x50, x1 ); 00297 WriteCmdData( 0x52, y1 ); 00298 WriteCmdData( 0x51, x2 ); 00299 WriteCmdData( 0x53, y2 ); 00300 break; 00301 } 00302 WriteCmd( 0x22 ); 00303 } 00304 00305 void ILI9325_LCD::SetPixelColor( unsigned int color, colordepth_t mode ) 00306 { 00307 unsigned char r, g, b; 00308 unsigned short clr; 00309 r = g = b = 0; 00310 if ( _colorDepth == RGB16 ) 00311 { 00312 switch ( mode ) 00313 { 00314 case RGB16: 00315 WriteData( color & 0xFFFF ); 00316 break; 00317 case RGB18: 00318 r = ( color >> 10 ) & 0xF8; 00319 g = ( color >> 4 ) & 0xFC; 00320 b = ( color >> 1 ) & 0x1F; 00321 clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | b ); 00322 WriteData( clr ); 00323 break; 00324 case RGB24: 00325 r = ( color >> 16 ) & 0xF8; 00326 g = ( color >> 8 ) & 0xFC; 00327 b = color & 0xF8; 00328 clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | ( b >> 3 ) ); 00329 WriteData( clr ); 00330 break; 00331 } 00332 } 00333 else if ( _colorDepth == RGB18 ) 00334 { 00335 switch ( mode ) 00336 { 00337 case RGB16: 00338 r = ( ( color >> 8 ) & 0xF8 ) | ( ( color & 0x8000 ) >> 13 ); 00339 g = ( color >> 3 ) & 0xFC; 00340 b = ( ( color << 3 ) & 0xFC ) | ( ( color >> 3 ) & 0x01 ); 00341 break; 00342 case RGB18: 00343 b = ( color << 2 ) & 0xFC; 00344 g = ( color >> 4 ) & 0xFC; 00345 r = ( color >> 10 ) & 0xFC; 00346 break; 00347 case RGB24: 00348 r = ( color >> 16 ) & 0xFC; 00349 g = ( color >> 8 ) & 0xFC; 00350 b = color & 0xFC; 00351 break; 00352 } 00353 clr = ( r << 8 ) | ( g << 2 ) | ( b >> 4 ); 00354 WriteData( clr ); 00355 WriteData( b << 4 ); 00356 } 00357 }
Generated on Wed Jul 13 2022 02:32:27 by
1.7.2
