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.
Fork of TFTLCD by
hx8352a.cpp
00001 /* 00002 * Copyright (C)2010-2012 Henning Karlsen. All right reserved. 00003 * Copyright (C)2012 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 "hx8352a.h" 00023 #include "helpers.h" 00024 00025 HX8352A_LCD::HX8352A_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, BusOut* DATA_PORT, PinName BL, PinName RD, backlight_t blType, float defaultBackLightLevel ) 00026 : LCD( 240, 400, 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 HX8352A_LCD::Initialize( orientation_t orientation, colordepth_t colors ) 00034 { 00035 _orientation = orientation; 00036 _colorDepth = colors; 00037 00038 wait_ms( 100 ); 00039 _lcd_pin_reset = HIGH; 00040 wait_ms( 50 ); 00041 _lcd_pin_reset = LOW; 00042 wait_ms( 50 ); 00043 _lcd_pin_reset = HIGH; 00044 _lcd_pin_cs = HIGH; 00045 //_lcd_pin_rd = HIGH; 00046 if ( _lcd_pin_bl != 0 ) 00047 *_lcd_pin_bl = HIGH; 00048 else if ( _bl_pwm != 0 ) 00049 *_bl_pwm = _bl_pwm_default; 00050 _lcd_pin_wr = HIGH; 00051 wait_ms( 55 ); 00052 00053 Activate(); 00054 Activate(); 00055 WriteCmdData( 0x83, 0x0002 ); //TESTM=1 00056 00057 WriteCmdData( 0x85, 0x0003 ); //VDC_SEL=011 00058 WriteCmdData( 0x8B, 0x0001 ); 00059 WriteCmdData( 0x8C, 0x0093 ); //STBA[7]=1,STBA[5:4]=01,STBA[1:0]=11 00060 00061 WriteCmdData( 0x91, 0x0001 ); //DCDC_SYNC=1 00062 00063 WriteCmdData( 0x83, 0x0000 ); 00064 //WriteCmdData( 0x00, 0x0001 ); //TESTM=0 00065 00066 //Gamma Setting 00067 WriteCmdData( 0x3E, 0x00B0); 00068 WriteCmdData( 0x3F, 0x0003 ); 00069 WriteCmdData( 0x40, 0x0010 ); 00070 WriteCmdData( 0x41, 0x0056 ); 00071 WriteCmdData( 0x42, 0x0013 ); 00072 WriteCmdData( 0x43, 0x0046 ); 00073 WriteCmdData( 0x44, 0x0023 ); 00074 WriteCmdData( 0x45, 0x0076 ); 00075 WriteCmdData( 0x46, 0x0000 ); 00076 WriteCmdData( 0x47, 0x005E ); 00077 WriteCmdData( 0x48, 0x004F ); 00078 WriteCmdData( 0x49, 0x0040 ); 00079 00080 //**********Power On sequence************ 00081 WriteCmdData( 0x17, 0x0091 ); 00082 00083 WriteCmdData( 0x2B, 0x00F9 ); 00084 wait_ms( 15 ); 00085 00086 WriteCmdData( 0x1B, 0x0014 ); 00087 00088 WriteCmdData( 0x1A, 0x0011 ); 00089 00090 WriteCmdData( 0x1C, 0x0006 ); 00091 00092 WriteCmdData( 0x1F, 0x0042 ); 00093 wait_ms( 20 ); 00094 00095 WriteCmdData( 0x19, 0x000A ); 00096 00097 WriteCmdData( 0x19, 0x001A ); 00098 wait_ms( 40 ); 00099 00100 WriteCmdData( 0x19, 0x0012 ); 00101 wait_ms( 40 ); 00102 00103 WriteCmdData( 0x1E, 0x0027 ); 00104 wait_ms( 100 ); 00105 00106 //**********DISPLAY ON SETTING*********** 00107 00108 WriteCmdData( 0x24, 0x0060 ); 00109 00110 WriteCmdData( 0x3D, 0x0040 ); 00111 00112 WriteCmdData( 0x34, 0x0038 ); 00113 00114 WriteCmdData( 0x35, 0x0038 ); 00115 00116 WriteCmdData( 0x24, 0x0038 ); 00117 wait_ms( 40 ); 00118 00119 WriteCmdData( 0x24, 0x003C ); 00120 00121 //WriteCmdData( 0x16, 0x00B8 ); 00122 00123 WriteCmdData( 0x01, 0x0006 ); 00124 00125 WriteCmdData( 0x55, 0x0000 ); 00126 00127 WriteCmdData( 0x02, 0x0000 ); 00128 WriteCmdData( 0x03, 0x0000 ); 00129 WriteCmdData( 0x04, 0x0000 ); 00130 WriteCmdData( 0x05, 0x00EF ); 00131 00132 WriteCmdData( 0x06, 0x0000 ); 00133 WriteCmdData( 0x07, 0x0000 ); 00134 WriteCmdData( 0x08, 0x0001 ); 00135 WriteCmdData( 0x09, 0x008F ); 00136 00137 00138 WriteCmd( 0x16 ); 00139 switch ( _orientation ) 00140 { 00141 case LANDSCAPE: WriteData( 0xA8 ); break; 00142 case PORTRAIT_REV: WriteData( 0xDC ); break; 00143 case LANDSCAPE_REV: WriteData( 0x6C ); break; 00144 case PORTRAIT: 00145 default: WriteData( 0x08 ); break; 00146 } 00147 00148 WriteCmd( 0x22 ); 00149 wait_ms( 10 ); 00150 00151 ClearXY(); 00152 Deactivate(); 00153 } 00154 00155 /* 00156 void HX8352A_LCD::Sleep( void ) 00157 { 00158 Activate(); 00159 WriteCmd( 0x28 ); 00160 wait_ms( 10 ); 00161 WriteCmd( 0x10 ); 00162 wait_ms( 125 ); 00163 LCD::Sleep(); 00164 Deactivate(); 00165 } 00166 00167 void HX8352A_LCD::WakeUp( void ) 00168 { 00169 Activate(); 00170 WriteCmd( 0x29 ); 00171 wait_ms( 10 ); 00172 WriteCmd( 0x11 ); 00173 wait_ms( 125 ); 00174 LCD::WakeUp(); 00175 Deactivate(); 00176 } 00177 */ 00178 00179 void HX8352A_LCD::WriteCmd( unsigned short cmd ) 00180 { 00181 _lcd_pin_rs = LOW; 00182 _lcd_port->write( cmd ); 00183 pulseLow( _lcd_pin_wr );} 00184 00185 void HX8352A_LCD::WriteData( unsigned short data ) 00186 { 00187 _lcd_pin_rs = HIGH; 00188 _lcd_port->write( data ); 00189 pulseLow( _lcd_pin_wr ); 00190 } 00191 00192 void HX8352A_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 ) 00193 { 00194 switch ( _orientation ) { 00195 case LANDSCAPE: 00196 case LANDSCAPE_REV: 00197 WriteCmdData( 0x02,x1>>8 ); 00198 WriteCmdData( 0x03,x1 ); 00199 WriteCmdData( 0x04,x2>>8 ); 00200 WriteCmdData( 0x05,x2 ); 00201 WriteCmdData( 0x06,y1>>8 ); 00202 WriteCmdData( 0x07,y1 ); 00203 WriteCmdData( 0x08,y2>>8 ); 00204 WriteCmdData( 0x09,y2 ); 00205 break; 00206 00207 case PORTRAIT_REV: 00208 case PORTRAIT: 00209 default: 00210 WriteCmdData( 0x02,x1>>8 ); 00211 WriteCmdData( 0x03,x1 ); 00212 WriteCmdData( 0x04,x2>>8 ); 00213 WriteCmdData( 0x05,x2 ); 00214 WriteCmdData( 0x06,y1>>8 ); 00215 WriteCmdData( 0x07,y1 ); 00216 WriteCmdData( 0x08,y2>>8 ); 00217 WriteCmdData( 0x09,y2 ); 00218 break; 00219 } 00220 WriteCmd( 0x22 ); // RAMWR 00221 } 00222 00223 void HX8352A_LCD::SetPixelColor( unsigned int color, colordepth_t mode ) 00224 { 00225 unsigned char r = 0, g = 0, b = 0; 00226 unsigned short clr; 00227 if ( _colorDepth == RGB16 ) 00228 { 00229 switch ( mode ) 00230 { 00231 case RGB16: 00232 WriteData( color & 0xFFFF ); 00233 break; 00234 case RGB18: 00235 r = ( color >> 10 ) & 0xF8; 00236 g = ( color >> 4 ) & 0xFC; 00237 b = ( color >> 1 ) & 0x1F; 00238 clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | b ); 00239 WriteData( clr ); 00240 break; 00241 case RGB24: 00242 r = ( color >> 16 ) & 0xF8; 00243 g = ( color >> 8 ) & 0xFC; 00244 b = color & 0xF8; 00245 clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | ( b >> 3 ) ); 00246 WriteData( clr ); 00247 break; 00248 } 00249 } 00250 else if ( _colorDepth == RGB18 ) 00251 { 00252 switch ( mode ) 00253 { 00254 case RGB16: 00255 r = ( ( color >> 8 ) & 0xF8 ) | ( ( color & 0x8000 ) >> 13 ); 00256 g = ( color >> 3 ) & 0xFC; 00257 b = ( ( color << 3 ) & 0xFC ) | ( ( color >> 3 ) & 0x01 ); 00258 break; 00259 case RGB18: 00260 b = ( color << 2 ) & 0xFC; 00261 g = ( color >> 4 ) & 0xFC; 00262 r = ( color >> 10 ) & 0xFC; 00263 break; 00264 case RGB24: 00265 r = ( color >> 16 ) & 0xFC; 00266 g = ( color >> 8 ) & 0xFC; 00267 b = color & 0xFC; 00268 break; 00269 } 00270 WriteData( r ); 00271 WriteData( g ); 00272 WriteData( b ); 00273 } 00274 } 00275
Generated on Tue Jul 12 2022 22:53:43 by
1.7.2
