Code to run the cheap 2.4" TFT made by mcufriend.com on the STM nucleo. No modifications required, this plugs into the arduino header.

Dependents:   ST7735_V2_STM32F407

Fork of TFTLCD_8bit by Thiha Electronics

Committer:
cdtsilva
Date:
Mon Jun 30 17:29:42 2014 +0000
Revision:
29:060b167a46ba
Parent:
28:8808898a7f0c
This is a modified Library to work with the ST Nucleo and the Cheap Red PCB 2.4" TFT displays from china.
; No modifications required, just plug the shield into the arduino header.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThihaElectronics 28:8808898a7f0c 1 /*
ThihaElectronics 28:8808898a7f0c 2 * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
ThihaElectronics 28:8808898a7f0c 3 * Copyright (C)2012-2013 Todor Todorov.
ThihaElectronics 28:8808898a7f0c 4 *
ThihaElectronics 28:8808898a7f0c 5 * This library is free software; you can redistribute it and/or
ThihaElectronics 28:8808898a7f0c 6 * modify it under the terms of the GNU Lesser General Public
ThihaElectronics 28:8808898a7f0c 7 * License as published by the Free Software Foundation; either
ThihaElectronics 28:8808898a7f0c 8 * version 2.1 of the License, or (at your option) any later version.
ThihaElectronics 28:8808898a7f0c 9 *
ThihaElectronics 28:8808898a7f0c 10 * This library is distributed in the hope that it will be useful,
ThihaElectronics 28:8808898a7f0c 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ThihaElectronics 28:8808898a7f0c 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ThihaElectronics 28:8808898a7f0c 13 * Lesser General Public License for more details.
ThihaElectronics 28:8808898a7f0c 14 *
ThihaElectronics 28:8808898a7f0c 15 * You should have received a copy of the GNU Lesser General Public
ThihaElectronics 28:8808898a7f0c 16 * License along with this library; if not, write to:
ThihaElectronics 28:8808898a7f0c 17 *
ThihaElectronics 28:8808898a7f0c 18 * Free Software Foundation, Inc.
ThihaElectronics 28:8808898a7f0c 19 * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
ThihaElectronics 28:8808898a7f0c 20 *
ThihaElectronics 28:8808898a7f0c 21 *********************************************************************/
ThihaElectronics 28:8808898a7f0c 22 #include "ili9325.h"
ThihaElectronics 28:8808898a7f0c 23 #include "helpers.h"
ThihaElectronics 28:8808898a7f0c 24
ThihaElectronics 28:8808898a7f0c 25 ILI9328_LCD::ILI9328_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, BusOut* DATA_PORT, PinName BL, PinName RD, backlight_t blType, float defaultBackLightLevel )
ThihaElectronics 28:8808898a7f0c 26 : LCD( 240, 320, CS, RS, RESET, BL, blType, defaultBackLightLevel ), _lcd_pin_wr( WR )
ThihaElectronics 28:8808898a7f0c 27 {
ThihaElectronics 28:8808898a7f0c 28 _lcd_port = DATA_PORT;
ThihaElectronics 28:8808898a7f0c 29 if ( RD != NC ) _lcd_pin_rd = new DigitalOut( RD );
ThihaElectronics 28:8808898a7f0c 30 else _lcd_pin_rd = 0;
ThihaElectronics 28:8808898a7f0c 31 }
ThihaElectronics 28:8808898a7f0c 32
ThihaElectronics 28:8808898a7f0c 33 void ILI9328_LCD::Initialize( orientation_t orientation, colordepth_t colors )
ThihaElectronics 28:8808898a7f0c 34 {
ThihaElectronics 28:8808898a7f0c 35 _orientation = orientation;
ThihaElectronics 28:8808898a7f0c 36 _colorDepth = colors;
ThihaElectronics 28:8808898a7f0c 37
ThihaElectronics 28:8808898a7f0c 38 _lcd_pin_reset = HIGH;
cdtsilva 29:060b167a46ba 39 wait_ms( 10 );
ThihaElectronics 28:8808898a7f0c 40 _lcd_pin_reset = LOW;
cdtsilva 29:060b167a46ba 41 wait_ms( 10 );
ThihaElectronics 28:8808898a7f0c 42 _lcd_pin_reset = HIGH;
cdtsilva 29:060b167a46ba 43 wait_ms( 10 );
ThihaElectronics 28:8808898a7f0c 44 _lcd_pin_cs = HIGH;
ThihaElectronics 28:8808898a7f0c 45 if ( _lcd_pin_bl != 0 )
ThihaElectronics 28:8808898a7f0c 46 *_lcd_pin_bl = HIGH;
ThihaElectronics 28:8808898a7f0c 47 else if ( _bl_pwm != 0 )
ThihaElectronics 28:8808898a7f0c 48 *_bl_pwm = _bl_pwm_default;
ThihaElectronics 28:8808898a7f0c 49 if ( _lcd_pin_rd != 0 )
ThihaElectronics 28:8808898a7f0c 50 *_lcd_pin_rd = HIGH;
ThihaElectronics 28:8808898a7f0c 51 _lcd_pin_wr = HIGH;
cdtsilva 29:060b167a46ba 52 wait_ms( 5 );
ThihaElectronics 28:8808898a7f0c 53
ThihaElectronics 28:8808898a7f0c 54 Activate();
ThihaElectronics 28:8808898a7f0c 55
ThihaElectronics 28:8808898a7f0c 56 short drivOut = 0;
ThihaElectronics 28:8808898a7f0c 57 short entryMod = 0;
ThihaElectronics 28:8808898a7f0c 58 short gateScan = 0x2700;
ThihaElectronics 28:8808898a7f0c 59 switch ( _orientation )
ThihaElectronics 28:8808898a7f0c 60 {
ThihaElectronics 28:8808898a7f0c 61 case LANDSCAPE:
ThihaElectronics 28:8808898a7f0c 62 drivOut = 0x0100;
ThihaElectronics 28:8808898a7f0c 63 entryMod |= 0x0038;
ThihaElectronics 28:8808898a7f0c 64 gateScan |= 0x0000;
ThihaElectronics 28:8808898a7f0c 65 break;
ThihaElectronics 28:8808898a7f0c 66
ThihaElectronics 28:8808898a7f0c 67 case LANDSCAPE_REV:
ThihaElectronics 28:8808898a7f0c 68 drivOut = 0x0000;
ThihaElectronics 28:8808898a7f0c 69 entryMod |= 0x0038;
ThihaElectronics 28:8808898a7f0c 70 gateScan |= 0x8000;
ThihaElectronics 28:8808898a7f0c 71 break;
ThihaElectronics 28:8808898a7f0c 72
ThihaElectronics 28:8808898a7f0c 73 case PORTRAIT_REV:
ThihaElectronics 28:8808898a7f0c 74 drivOut = 0x0000;
ThihaElectronics 28:8808898a7f0c 75 entryMod |= 0x0030;
ThihaElectronics 28:8808898a7f0c 76 gateScan |= 0x0000;
ThihaElectronics 28:8808898a7f0c 77 break;
ThihaElectronics 28:8808898a7f0c 78
ThihaElectronics 28:8808898a7f0c 79 case PORTRAIT:
ThihaElectronics 28:8808898a7f0c 80 default:
ThihaElectronics 28:8808898a7f0c 81 drivOut = 0x0100;
ThihaElectronics 28:8808898a7f0c 82 entryMod |= 0x0030;
ThihaElectronics 28:8808898a7f0c 83 gateScan |= 0x8000;
ThihaElectronics 28:8808898a7f0c 84 break;
ThihaElectronics 28:8808898a7f0c 85 }
ThihaElectronics 28:8808898a7f0c 86 switch ( _colorDepth )
ThihaElectronics 28:8808898a7f0c 87 {
ThihaElectronics 28:8808898a7f0c 88 case RGB18:
ThihaElectronics 28:8808898a7f0c 89 entryMod |= 0x9000;
ThihaElectronics 28:8808898a7f0c 90 break;
ThihaElectronics 28:8808898a7f0c 91
ThihaElectronics 28:8808898a7f0c 92 case RGB16:
ThihaElectronics 28:8808898a7f0c 93 default:
cdtsilva 29:060b167a46ba 94 entryMod |= 0x1030;
ThihaElectronics 28:8808898a7f0c 95 break;
ThihaElectronics 28:8808898a7f0c 96 }
ThihaElectronics 28:8808898a7f0c 97
cdtsilva 29:060b167a46ba 98 //WriteCmdData( 0xE5, 0xFFFF ); // set SRAM internal timing
cdtsilva 29:060b167a46ba 99 WriteCmdData( 0x0001,0x0100);//0x01, drivOut ); // set Driver Output Control
cdtsilva 29:060b167a46ba 100 WriteCmdData( 0x0002,0x0700 ); // set 1 line inversion
cdtsilva 29:060b167a46ba 101 WriteCmdData( 0x0003,entryMod );//0x03, entryMod ); // set GRAM write direction and BGR=1.
cdtsilva 29:060b167a46ba 102 //WriteCmdData( 0x04, 0x0000 ); // Resize register
cdtsilva 29:060b167a46ba 103 WriteCmdData( 0x0008,0x0302 ); // set the back porch and front porch
cdtsilva 29:060b167a46ba 104 WriteCmdData( 0x0009,0x0000 ); // set non-display area refresh cycle ISC[3:0]
cdtsilva 29:060b167a46ba 105 WriteCmdData( 0x000A,0x0008 ); // FMARK function
cdtsilva 29:060b167a46ba 106 //WriteCmdData( 0x0C, 0x0000 ); // RGB interface setting
cdtsilva 29:060b167a46ba 107 //WriteCmdData( 0x0D, 0x0000 ); // Frame marker Position
cdtsilva 29:060b167a46ba 108 //WriteCmdData( 0x0F, 0x0000 ); // RGB interface polarity
ThihaElectronics 28:8808898a7f0c 109 // ----------- Power On sequence ----------- //
cdtsilva 29:060b167a46ba 110 WriteCmdData( 0x0010,0x0790 ); // SAP, BT[3:0], AP, DSTB, SLP, STB
cdtsilva 29:060b167a46ba 111 WriteCmdData( 0x0011,0x0005 ); // DC1[2:0], DC0[2:0], VC[2:0]
cdtsilva 29:060b167a46ba 112 WriteCmdData( 0x0012,0x0000 ); // VREG1OUT voltage
cdtsilva 29:060b167a46ba 113 WriteCmdData( 0x0013,0x000 ); // VDV[4:0] for VCOM amplitude
cdtsilva 29:060b167a46ba 114 //WriteCmdData( 0x07, 0x0001 );
cdtsilva 29:060b167a46ba 115 //wait_ms( 50 ); // Dis-charge capacitor power voltage
cdtsilva 29:060b167a46ba 116 WriteCmdData( 0x0010,0x12B0 ); // SAP, BT[3:0], AP, DSTB, SLP, STB
cdtsilva 29:060b167a46ba 117 WriteCmdData( 0x0011,0x0007 ); // Set DC1[2:0], DC0[2:0], VC[2:0]
cdtsilva 29:060b167a46ba 118 //wait_ms( 50 ); // Delay 50ms
cdtsilva 29:060b167a46ba 119 WriteCmdData( 0x0012,0x008C ); // 0012
cdtsilva 29:060b167a46ba 120 //wait_ms( 50 ); // Delay 50ms
cdtsilva 29:060b167a46ba 121 WriteCmdData( 0x0013,0x1700 ); // VDV[4:0] for VCOM amplitude
cdtsilva 29:060b167a46ba 122 WriteCmdData( 0x0029,0x0022 ); // 04 VCM[5:0] for VCOMH
cdtsilva 29:060b167a46ba 123 //WriteCmdData( 0x2B, 0x00FD ); // Set Frame Rate
cdtsilva 29:060b167a46ba 124 //wait_ms( 50 ); // Delay 50ms
cdtsilva 29:060b167a46ba 125 //WriteCmdData( 0x20, 0x0000 ); // GRAM horizontal Address
cdtsilva 29:060b167a46ba 126 //WriteCmdData( 0x21, 0x0000 ); // GRAM Vertical Address
ThihaElectronics 28:8808898a7f0c 127 // ----------- Adjust the Gamma Curve ----------//
cdtsilva 29:060b167a46ba 128 WriteCmdData( 0x0030,0x0000 );
cdtsilva 29:060b167a46ba 129 WriteCmdData( 0x0031,0x0505 );
cdtsilva 29:060b167a46ba 130 WriteCmdData( 0x0032,0x0205 );
cdtsilva 29:060b167a46ba 131 WriteCmdData( 0x0035,0x0206 );
cdtsilva 29:060b167a46ba 132 WriteCmdData( 0x0036,0x0408 );
cdtsilva 29:060b167a46ba 133 WriteCmdData( 0x0037,0x0000 );
cdtsilva 29:060b167a46ba 134 WriteCmdData( 0x0038,0x0504 );
cdtsilva 29:060b167a46ba 135 WriteCmdData( 0x0039,0x0206 );
cdtsilva 29:060b167a46ba 136 WriteCmdData( 0x003C,0x0206 );
cdtsilva 29:060b167a46ba 137 WriteCmdData( 0x003D,0x0408 );
ThihaElectronics 28:8808898a7f0c 138 //------------------ Set GRAM area ---------------//
ThihaElectronics 28:8808898a7f0c 139 WriteCmdData( 0x50, 0x0000 ); // Horizontal GRAM Start Address
ThihaElectronics 28:8808898a7f0c 140 WriteCmdData( 0x51, 0x00EF ); // Horizontal GRAM End Address
ThihaElectronics 28:8808898a7f0c 141 WriteCmdData( 0x52, 0x0000 ); // Vertical GRAM Start Address
ThihaElectronics 28:8808898a7f0c 142 WriteCmdData( 0x53, 0x013F ); // Vertical GRAM Start Address
ThihaElectronics 28:8808898a7f0c 143 WriteCmdData( 0x60, gateScan ); // Gate Scan Line (0xA700)
cdtsilva 29:060b167a46ba 144 WriteCmdData( 0x0061,0x0001 ); // NDL,VLE, REV
cdtsilva 29:060b167a46ba 145 //WriteCmdData( 0x6A, 0x0000 ); // set scrolling line
ThihaElectronics 28:8808898a7f0c 146 //-------------- Partial Display Control ---------//
cdtsilva 29:060b167a46ba 147 //WriteCmdData( 0x80, 0x0000 );
cdtsilva 29:060b167a46ba 148 //WriteCmdData( 0x81, 0x0000 );
cdtsilva 29:060b167a46ba 149 //WriteCmdData( 0x82, 0x0000 );
cdtsilva 29:060b167a46ba 150 //WriteCmdData( 0x83, 0x0000 );
cdtsilva 29:060b167a46ba 151 //WriteCmdData( 0x84, 0x0000 );
cdtsilva 29:060b167a46ba 152 //WriteCmdData( 0x85, 0x0000 );
ThihaElectronics 28:8808898a7f0c 153 //-------------- Panel Control -------------------//
cdtsilva 29:060b167a46ba 154 WriteCmdData( 0x90, 0x0033 );
cdtsilva 29:060b167a46ba 155 //WriteCmdData( 0x92, 0x0000 );
cdtsilva 29:060b167a46ba 156 WriteCmdData( 0x0007,0x0133 ); // 262K color and display ON
ThihaElectronics 28:8808898a7f0c 157
ThihaElectronics 28:8808898a7f0c 158 Deactivate();
ThihaElectronics 28:8808898a7f0c 159 }
ThihaElectronics 28:8808898a7f0c 160
ThihaElectronics 28:8808898a7f0c 161 void ILI9328_LCD::Sleep( void )
ThihaElectronics 28:8808898a7f0c 162 {
ThihaElectronics 28:8808898a7f0c 163 Activate();
ThihaElectronics 28:8808898a7f0c 164 WriteCmdData( 0x10, 0x1692 ); // enter sleep mode
cdtsilva 29:060b167a46ba 165 wait_ms( 50 );
ThihaElectronics 28:8808898a7f0c 166 LCD::Sleep();
ThihaElectronics 28:8808898a7f0c 167 Deactivate();
ThihaElectronics 28:8808898a7f0c 168 }
ThihaElectronics 28:8808898a7f0c 169
ThihaElectronics 28:8808898a7f0c 170 void ILI9328_LCD::WakeUp( void )
ThihaElectronics 28:8808898a7f0c 171 {
ThihaElectronics 28:8808898a7f0c 172 Activate();
ThihaElectronics 28:8808898a7f0c 173 WriteCmdData( 0x10, 0x1690 ); // exit sleep mode
cdtsilva 29:060b167a46ba 174 wait_ms( 50 );
ThihaElectronics 28:8808898a7f0c 175 LCD::WakeUp();
ThihaElectronics 28:8808898a7f0c 176 Deactivate();
ThihaElectronics 28:8808898a7f0c 177 }
ThihaElectronics 28:8808898a7f0c 178
ThihaElectronics 28:8808898a7f0c 179 void ILI9328_LCD::WriteCmd( unsigned short cmd )
ThihaElectronics 28:8808898a7f0c 180 {
ThihaElectronics 28:8808898a7f0c 181
ThihaElectronics 28:8808898a7f0c 182 unsigned short u,l;
ThihaElectronics 28:8808898a7f0c 183 u = (cmd>>8) & 0xFF;
ThihaElectronics 28:8808898a7f0c 184 l = cmd & 0xFF;
ThihaElectronics 28:8808898a7f0c 185
ThihaElectronics 28:8808898a7f0c 186 //New
ThihaElectronics 28:8808898a7f0c 187 _lcd_pin_cs = LOW;
ThihaElectronics 28:8808898a7f0c 188 //
ThihaElectronics 28:8808898a7f0c 189 _lcd_pin_rs = LOW;
ThihaElectronics 28:8808898a7f0c 190
ThihaElectronics 28:8808898a7f0c 191 //New
ThihaElectronics 28:8808898a7f0c 192 *_lcd_pin_rd = HIGH;
ThihaElectronics 28:8808898a7f0c 193 _lcd_pin_wr = HIGH;
ThihaElectronics 28:8808898a7f0c 194 //
ThihaElectronics 28:8808898a7f0c 195 _lcd_port->write( u );
ThihaElectronics 28:8808898a7f0c 196 pulseLow( _lcd_pin_wr );
ThihaElectronics 28:8808898a7f0c 197
ThihaElectronics 28:8808898a7f0c 198 _lcd_port->write( l );
ThihaElectronics 28:8808898a7f0c 199 pulseLow( _lcd_pin_wr );
ThihaElectronics 28:8808898a7f0c 200
ThihaElectronics 28:8808898a7f0c 201 //New
ThihaElectronics 28:8808898a7f0c 202 _lcd_pin_cs = HIGH;
ThihaElectronics 28:8808898a7f0c 203 //
ThihaElectronics 28:8808898a7f0c 204 }
ThihaElectronics 28:8808898a7f0c 205
ThihaElectronics 28:8808898a7f0c 206 void ILI9328_LCD::WriteData( unsigned short data )
ThihaElectronics 28:8808898a7f0c 207 {
ThihaElectronics 28:8808898a7f0c 208 unsigned short u,l;
ThihaElectronics 28:8808898a7f0c 209 u = (data>>8) & 0xFF;
ThihaElectronics 28:8808898a7f0c 210 l = data & 0xFF;
ThihaElectronics 28:8808898a7f0c 211
ThihaElectronics 28:8808898a7f0c 212 //New
ThihaElectronics 28:8808898a7f0c 213 _lcd_pin_cs = LOW;
ThihaElectronics 28:8808898a7f0c 214 //
ThihaElectronics 28:8808898a7f0c 215 _lcd_pin_rs = HIGH;
ThihaElectronics 28:8808898a7f0c 216 //New
ThihaElectronics 28:8808898a7f0c 217 *_lcd_pin_rd = HIGH;
ThihaElectronics 28:8808898a7f0c 218 _lcd_pin_wr = HIGH;
ThihaElectronics 28:8808898a7f0c 219 //
ThihaElectronics 28:8808898a7f0c 220 _lcd_port->write( u );
ThihaElectronics 28:8808898a7f0c 221 pulseLow( _lcd_pin_wr );
ThihaElectronics 28:8808898a7f0c 222
ThihaElectronics 28:8808898a7f0c 223 _lcd_port->write( l );
ThihaElectronics 28:8808898a7f0c 224 pulseLow( _lcd_pin_wr );
ThihaElectronics 28:8808898a7f0c 225
ThihaElectronics 28:8808898a7f0c 226 //New
ThihaElectronics 28:8808898a7f0c 227 _lcd_pin_cs = HIGH;
ThihaElectronics 28:8808898a7f0c 228 //
ThihaElectronics 28:8808898a7f0c 229 }
ThihaElectronics 28:8808898a7f0c 230
ThihaElectronics 28:8808898a7f0c 231 void ILI9328_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 )
ThihaElectronics 28:8808898a7f0c 232 {
ThihaElectronics 28:8808898a7f0c 233 switch ( _orientation )
ThihaElectronics 28:8808898a7f0c 234 {
ThihaElectronics 28:8808898a7f0c 235 case LANDSCAPE:
ThihaElectronics 28:8808898a7f0c 236 case LANDSCAPE_REV:
ThihaElectronics 28:8808898a7f0c 237 WriteCmdData( 0x20, y1 );
ThihaElectronics 28:8808898a7f0c 238 WriteCmdData( 0x21, x1 );
ThihaElectronics 28:8808898a7f0c 239 WriteCmdData( 0x50, y1 );
ThihaElectronics 28:8808898a7f0c 240 WriteCmdData( 0x52, x1 );
ThihaElectronics 28:8808898a7f0c 241 WriteCmdData( 0x51, y2 );
ThihaElectronics 28:8808898a7f0c 242 WriteCmdData( 0x53, x2 );
ThihaElectronics 28:8808898a7f0c 243 break;
ThihaElectronics 28:8808898a7f0c 244
ThihaElectronics 28:8808898a7f0c 245 case PORTRAIT_REV:
ThihaElectronics 28:8808898a7f0c 246 case PORTRAIT:
ThihaElectronics 28:8808898a7f0c 247 default:
ThihaElectronics 28:8808898a7f0c 248 WriteCmdData( 0x20, x1 );
ThihaElectronics 28:8808898a7f0c 249 WriteCmdData( 0x21, y1 );
ThihaElectronics 28:8808898a7f0c 250 WriteCmdData( 0x50, x1 );
ThihaElectronics 28:8808898a7f0c 251 WriteCmdData( 0x52, y1 );
ThihaElectronics 28:8808898a7f0c 252 WriteCmdData( 0x51, x2 );
ThihaElectronics 28:8808898a7f0c 253 WriteCmdData( 0x53, y2 );
ThihaElectronics 28:8808898a7f0c 254 break;
ThihaElectronics 28:8808898a7f0c 255 }
ThihaElectronics 28:8808898a7f0c 256 WriteCmd( 0x22 );
ThihaElectronics 28:8808898a7f0c 257 }
ThihaElectronics 28:8808898a7f0c 258
ThihaElectronics 28:8808898a7f0c 259 void ILI9328_LCD::SetPixelColor( unsigned int color, colordepth_t mode )
ThihaElectronics 28:8808898a7f0c 260 {
ThihaElectronics 28:8808898a7f0c 261 unsigned char r, g, b;
ThihaElectronics 28:8808898a7f0c 262 unsigned short clr;
ThihaElectronics 28:8808898a7f0c 263 r = g = b = 0;
ThihaElectronics 28:8808898a7f0c 264 if ( _colorDepth == RGB16 )
ThihaElectronics 28:8808898a7f0c 265 {
ThihaElectronics 28:8808898a7f0c 266 switch ( mode )
ThihaElectronics 28:8808898a7f0c 267 {
ThihaElectronics 28:8808898a7f0c 268 case RGB16:
ThihaElectronics 28:8808898a7f0c 269 WriteData( color & 0xFFFF );
ThihaElectronics 28:8808898a7f0c 270 break;
ThihaElectronics 28:8808898a7f0c 271 case RGB18:
ThihaElectronics 28:8808898a7f0c 272 r = ( color >> 10 ) & 0xF8;
ThihaElectronics 28:8808898a7f0c 273 g = ( color >> 4 ) & 0xFC;
ThihaElectronics 28:8808898a7f0c 274 b = ( color >> 1 ) & 0x1F;
ThihaElectronics 28:8808898a7f0c 275 clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | b );
ThihaElectronics 28:8808898a7f0c 276 WriteData( clr );
ThihaElectronics 28:8808898a7f0c 277 break;
ThihaElectronics 28:8808898a7f0c 278 case RGB24:
ThihaElectronics 28:8808898a7f0c 279 r = ( color >> 16 ) & 0xF8;
ThihaElectronics 28:8808898a7f0c 280 g = ( color >> 8 ) & 0xFC;
ThihaElectronics 28:8808898a7f0c 281 b = color & 0xF8;
ThihaElectronics 28:8808898a7f0c 282 clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | ( b >> 3 ) );
ThihaElectronics 28:8808898a7f0c 283 WriteData( clr );
ThihaElectronics 28:8808898a7f0c 284 break;
ThihaElectronics 28:8808898a7f0c 285 }
ThihaElectronics 28:8808898a7f0c 286 }
ThihaElectronics 28:8808898a7f0c 287 else if ( _colorDepth == RGB18 )
ThihaElectronics 28:8808898a7f0c 288 {
ThihaElectronics 28:8808898a7f0c 289 switch ( mode )
ThihaElectronics 28:8808898a7f0c 290 {
ThihaElectronics 28:8808898a7f0c 291 case RGB16:
ThihaElectronics 28:8808898a7f0c 292 r = ( ( color >> 8 ) & 0xF8 ) | ( ( color & 0x8000 ) >> 13 );
ThihaElectronics 28:8808898a7f0c 293 g = ( color >> 3 ) & 0xFC;
ThihaElectronics 28:8808898a7f0c 294 b = ( ( color << 3 ) & 0xFC ) | ( ( color >> 3 ) & 0x01 );
ThihaElectronics 28:8808898a7f0c 295 break;
ThihaElectronics 28:8808898a7f0c 296 case RGB18:
ThihaElectronics 28:8808898a7f0c 297 b = ( color << 2 ) & 0xFC;
ThihaElectronics 28:8808898a7f0c 298 g = ( color >> 4 ) & 0xFC;
ThihaElectronics 28:8808898a7f0c 299 r = ( color >> 10 ) & 0xFC;
ThihaElectronics 28:8808898a7f0c 300 break;
ThihaElectronics 28:8808898a7f0c 301 case RGB24:
ThihaElectronics 28:8808898a7f0c 302 r = ( color >> 16 ) & 0xFC;
ThihaElectronics 28:8808898a7f0c 303 g = ( color >> 8 ) & 0xFC;
ThihaElectronics 28:8808898a7f0c 304 b = color & 0xFC;
ThihaElectronics 28:8808898a7f0c 305 break;
ThihaElectronics 28:8808898a7f0c 306 }
ThihaElectronics 28:8808898a7f0c 307 clr = ( r << 8 ) | ( g << 2 ) | ( b >> 4 );
ThihaElectronics 28:8808898a7f0c 308 WriteData( clr );
ThihaElectronics 28:8808898a7f0c 309 WriteData( b << 4 );
ThihaElectronics 28:8808898a7f0c 310 }
ThihaElectronics 28:8808898a7f0c 311 }