Landtiger (LPC1768) graphics LCD demo.

Dependencies:   mbed

Committer:
wim
Date:
Sun Nov 04 16:49:27 2012 +0000
Revision:
0:a8090b59eb05
Child:
1:ea0f7b1c5daf
werkende versie, logo flipped, text flipped

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:a8090b59eb05 1 /******************************************************************************/
wim 0:a8090b59eb05 2 /* GLCD_LPC1700 low-level Graphic LCD (320x240 pixels) for LandTiger */
wim 0:a8090b59eb05 3 /* */
wim 0:a8090b59eb05 4 /******************************************************************************/
wim 0:a8090b59eb05 5 /* This file is modified from the uVision/ARM development tools. */
wim 0:a8090b59eb05 6 /* Copyright (c) 2005-2009 Keil Software. All rights reserved. */
wim 0:a8090b59eb05 7 /* This software may only be used under the terms of a valid, current, */
wim 0:a8090b59eb05 8 /* end user licence from KEIL for a compatible version of KEIL software */
wim 0:a8090b59eb05 9 /* development tools. Nothing else gives you the right to use this software. */
wim 0:a8090b59eb05 10 /******************************************************************************/
wim 0:a8090b59eb05 11
wim 0:a8090b59eb05 12 #include "mbed.h"
wim 0:a8090b59eb05 13 #include "GLCD.h"
wim 0:a8090b59eb05 14 #include "Font_24x16.h"
wim 0:a8090b59eb05 15
wim 0:a8090b59eb05 16 /*********************** Hardware specific configuration **********************/
wim 0:a8090b59eb05 17
wim 0:a8090b59eb05 18 /* LandTiger 8bit to 16bit LCD Interface
wim 0:a8090b59eb05 19
wim 0:a8090b59eb05 20 PINS:
wim 0:a8090b59eb05 21 - EN = P0.19
wim 0:a8090b59eb05 22 - LE = P0.20
wim 0:a8090b59eb05 23 - DIR = P0.21
wim 0:a8090b59eb05 24 - CS = P0.22
wim 0:a8090b59eb05 25 - RS = P0.23
wim 0:a8090b59eb05 26 - WR = P0.24
wim 0:a8090b59eb05 27 - RD = P0.25
wim 0:a8090b59eb05 28 - DB[0.7] = P2.0...P2.7
wim 0:a8090b59eb05 29 - DB[8.15]= P2.0...P2.7 */
wim 0:a8090b59eb05 30
wim 0:a8090b59eb05 31 #define PIN_EN (1 << 19)
wim 0:a8090b59eb05 32 #define PIN_LE (1 << 20)
wim 0:a8090b59eb05 33 #define PIN_DIR (1 << 21)
wim 0:a8090b59eb05 34 #define PIN_CS (1 << 22)
wim 0:a8090b59eb05 35 #define PIN_RS (1 << 23)
wim 0:a8090b59eb05 36 #define PIN_WR (1 << 24)
wim 0:a8090b59eb05 37 #define PIN_RD (1 << 25)
wim 0:a8090b59eb05 38
wim 0:a8090b59eb05 39 /*------------------------- Speed dependant settings -------------------------*/
wim 0:a8090b59eb05 40
wim 0:a8090b59eb05 41 /* If processor works on high frequency delay has to be increased, it can be
wim 0:a8090b59eb05 42 increased by factor 2^N by this constant */
wim 0:a8090b59eb05 43 #define DELAY_2N 18
wim 0:a8090b59eb05 44
wim 0:a8090b59eb05 45 /*---------------------- Graphic LCD size definitions ------------------------*/
wim 0:a8090b59eb05 46
wim 0:a8090b59eb05 47 #define WIDTH 320 /* Screen Width (in pixels) */
wim 0:a8090b59eb05 48 #define HEIGHT 240 /* Screen Hight (in pixels) */
wim 0:a8090b59eb05 49 #define BPP 16 /* Bits per pixel */
wim 0:a8090b59eb05 50 #define BYPP ((BPP+7)/8) /* Bytes per pixel */
wim 0:a8090b59eb05 51
wim 0:a8090b59eb05 52 /*--------------- Graphic LCD interface hardware definitions -----------------*/
wim 0:a8090b59eb05 53
wim 0:a8090b59eb05 54 /* Pin EN setting to 0 or 1 */
wim 0:a8090b59eb05 55 #define LCD_EN(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_EN) : (LPC_GPIO0->FIOCLR = PIN_EN));
wim 0:a8090b59eb05 56 /* Pin LE setting to 0 or 1 */
wim 0:a8090b59eb05 57 #define LCD_LE(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_LE) : (LPC_GPIO0->FIOCLR = PIN_LE));
wim 0:a8090b59eb05 58 /* Pin DIR setting to 0 or 1 */
wim 0:a8090b59eb05 59 #define LCD_DIR(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_DIR) : (LPC_GPIO0->FIOCLR = PIN_DIR));
wim 0:a8090b59eb05 60 /* Pin CS setting to 0 or 1 */
wim 0:a8090b59eb05 61 #define LCD_CS(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_CS) : (LPC_GPIO0->FIOCLR = PIN_CS));
wim 0:a8090b59eb05 62 /* Pin RS setting to 0 or 1 */
wim 0:a8090b59eb05 63 #define LCD_RS(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_RS) : (LPC_GPIO0->FIOCLR = PIN_RS));
wim 0:a8090b59eb05 64 /* Pin WR setting to 0 or 1 */
wim 0:a8090b59eb05 65 #define LCD_WR(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_WR) : (LPC_GPIO0->FIOCLR = PIN_WR));
wim 0:a8090b59eb05 66 /* Pin RD setting to 0 or 1 */
wim 0:a8090b59eb05 67 #define LCD_RD(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_RD) : (LPC_GPIO0->FIOCLR = PIN_RD));
wim 0:a8090b59eb05 68
wim 0:a8090b59eb05 69
wim 0:a8090b59eb05 70 #define swap(type, i, j) {type t = i; i = j; j = t;}
wim 0:a8090b59eb05 71
wim 0:a8090b59eb05 72
wim 0:a8090b59eb05 73 /*---------------------------- Global variables ------------------------------*/
wim 0:a8090b59eb05 74
wim 0:a8090b59eb05 75 /******************************************************************************/
wim 0:a8090b59eb05 76 static volatile unsigned short TextColor = Black, BackColor = White;
wim 0:a8090b59eb05 77 static unsigned short driverCode;
wim 0:a8090b59eb05 78
wim 0:a8090b59eb05 79 /************************ Local auxiliary functions ***************************/
wim 0:a8090b59eb05 80
wim 0:a8090b59eb05 81 /*******************************************************************************
wim 0:a8090b59eb05 82 * Delay in while loop cycles *
wim 0:a8090b59eb05 83 * Parameter: cnt: number of while cycles to delay *
wim 0:a8090b59eb05 84 * Return: *
wim 0:a8090b59eb05 85 *******************************************************************************/
wim 0:a8090b59eb05 86
wim 0:a8090b59eb05 87 static void delay (int cnt) {
wim 0:a8090b59eb05 88
wim 0:a8090b59eb05 89 cnt <<= DELAY_2N;
wim 0:a8090b59eb05 90 while (cnt--);
wim 0:a8090b59eb05 91 }
wim 0:a8090b59eb05 92
wim 0:a8090b59eb05 93 __asm void wait()
wim 0:a8090b59eb05 94 {
wim 0:a8090b59eb05 95 nop
wim 0:a8090b59eb05 96 BX lr
wim 0:a8090b59eb05 97 }
wim 0:a8090b59eb05 98
wim 0:a8090b59eb05 99 void wait_delay(int count)
wim 0:a8090b59eb05 100 {
wim 0:a8090b59eb05 101 while(count--);
wim 0:a8090b59eb05 102 }
wim 0:a8090b59eb05 103
wim 0:a8090b59eb05 104 /*******************************************************************************
wim 0:a8090b59eb05 105 * Send 1 short to LCD *
wim 0:a8090b59eb05 106 * Parameter: data: data to be sent *
wim 0:a8090b59eb05 107 * Return: *
wim 0:a8090b59eb05 108 *******************************************************************************/
wim 0:a8090b59eb05 109
wim 0:a8090b59eb05 110 static __inline unsigned char lcd_send (unsigned short data) {
wim 0:a8090b59eb05 111
wim 0:a8090b59eb05 112 LPC_GPIO2->FIODIR |= 0x000000ff; //P2.0...P2.7 Output
wim 0:a8090b59eb05 113 LCD_DIR(1) //Interface A->B
wim 0:a8090b59eb05 114 LCD_EN(0) //Enable 2A->2B
wim 0:a8090b59eb05 115 LPC_GPIO2->FIOPIN = data; //Write D0..D7
wim 0:a8090b59eb05 116 LCD_LE(1)
wim 0:a8090b59eb05 117 LCD_LE(0) //latch D0..D7
wim 0:a8090b59eb05 118 LPC_GPIO2->FIOPIN = data >> 8; //Write D8..D15
wim 0:a8090b59eb05 119 return(1);
wim 0:a8090b59eb05 120 }
wim 0:a8090b59eb05 121
wim 0:a8090b59eb05 122
wim 0:a8090b59eb05 123 /*******************************************************************************
wim 0:a8090b59eb05 124 * read 1 short from LCD *
wim 0:a8090b59eb05 125 * Parameter: *
wim 0:a8090b59eb05 126 * Return: short data from LCD *
wim 0:a8090b59eb05 127 *******************************************************************************/
wim 0:a8090b59eb05 128
wim 0:a8090b59eb05 129 static __inline unsigned short lcd_read (void) {
wim 0:a8090b59eb05 130 unsigned short id;
wim 0:a8090b59eb05 131 LPC_GPIO2->FIODIR &= 0xffffff00; //P2.0...P2.7 Input
wim 0:a8090b59eb05 132 LCD_DIR(0) //Interface B->A
wim 0:a8090b59eb05 133 LCD_EN(0) //Enable 2B->2A
wim 0:a8090b59eb05 134 wait_delay(80); //delay some times
wim 0:a8090b59eb05 135 id = LPC_GPIO2->FIOPIN & 0x00ff; //Read D8..D15
wim 0:a8090b59eb05 136 LCD_EN(1) //Enable 1B->1A
wim 0:a8090b59eb05 137 wait_delay(80); //delay some times
wim 0:a8090b59eb05 138 id = (id << 8) | (LPC_GPIO2->FIOPIN & 0x00ff); //Read D0..D7
wim 0:a8090b59eb05 139 LCD_DIR(1)
wim 0:a8090b59eb05 140 return(id);
wim 0:a8090b59eb05 141 }
wim 0:a8090b59eb05 142
wim 0:a8090b59eb05 143 /*******************************************************************************
wim 0:a8090b59eb05 144 * Write command to LCD controller *
wim 0:a8090b59eb05 145 * Parameter: c: command to be written *
wim 0:a8090b59eb05 146 * Return: *
wim 0:a8090b59eb05 147 *******************************************************************************/
wim 0:a8090b59eb05 148
wim 0:a8090b59eb05 149 static __inline void wr_cmd (unsigned char c) {
wim 0:a8090b59eb05 150
wim 0:a8090b59eb05 151 LCD_RS(0)
wim 0:a8090b59eb05 152 LCD_RD(1)
wim 0:a8090b59eb05 153 lcd_send(c);
wim 0:a8090b59eb05 154 LCD_WR(0)
wim 0:a8090b59eb05 155 wait();
wim 0:a8090b59eb05 156 LCD_WR(1)
wim 0:a8090b59eb05 157 }
wim 0:a8090b59eb05 158
wim 0:a8090b59eb05 159
wim 0:a8090b59eb05 160 /*******************************************************************************
wim 0:a8090b59eb05 161 * Write data to LCD controller *
wim 0:a8090b59eb05 162 * Parameter: c: data to be written *
wim 0:a8090b59eb05 163 * Return: *
wim 0:a8090b59eb05 164 *******************************************************************************/
wim 0:a8090b59eb05 165
wim 0:a8090b59eb05 166 static __inline void wr_dat (unsigned short c) {
wim 0:a8090b59eb05 167
wim 0:a8090b59eb05 168 LCD_RS(1)
wim 0:a8090b59eb05 169 LCD_RD(1)
wim 0:a8090b59eb05 170 lcd_send(c);
wim 0:a8090b59eb05 171 LCD_WR(0)
wim 0:a8090b59eb05 172 wait();
wim 0:a8090b59eb05 173 LCD_WR(1)
wim 0:a8090b59eb05 174 }
wim 0:a8090b59eb05 175
wim 0:a8090b59eb05 176 /*******************************************************************************
wim 0:a8090b59eb05 177 * Read data from LCD controller *
wim 0:a8090b59eb05 178 * Parameter: *
wim 0:a8090b59eb05 179 * Return: read data *
wim 0:a8090b59eb05 180 *******************************************************************************/
wim 0:a8090b59eb05 181
wim 0:a8090b59eb05 182 static __inline unsigned short rd_dat (void) {
wim 0:a8090b59eb05 183 unsigned short val = 0;
wim 0:a8090b59eb05 184
wim 0:a8090b59eb05 185 LCD_RS(1)
wim 0:a8090b59eb05 186 LCD_WR(1)
wim 0:a8090b59eb05 187 LCD_RD(0)
wim 0:a8090b59eb05 188 val = lcd_read();
wim 0:a8090b59eb05 189 LCD_RD(1)
wim 0:a8090b59eb05 190 return val;
wim 0:a8090b59eb05 191 }
wim 0:a8090b59eb05 192
wim 0:a8090b59eb05 193 /*******************************************************************************
wim 0:a8090b59eb05 194 * Start of data writing to LCD controller *
wim 0:a8090b59eb05 195 * Parameter: *
wim 0:a8090b59eb05 196 * Return: *
wim 0:a8090b59eb05 197 *******************************************************************************/
wim 0:a8090b59eb05 198
wim 0:a8090b59eb05 199 static __inline void wr_dat_start (void) {
wim 0:a8090b59eb05 200
wim 0:a8090b59eb05 201 LCD_CS(0)
wim 0:a8090b59eb05 202 LCD_RS(1)
wim 0:a8090b59eb05 203 }
wim 0:a8090b59eb05 204
wim 0:a8090b59eb05 205
wim 0:a8090b59eb05 206 /*******************************************************************************
wim 0:a8090b59eb05 207 * Stop of data writing to LCD controller *
wim 0:a8090b59eb05 208 * Parameter: *
wim 0:a8090b59eb05 209 * Return: *
wim 0:a8090b59eb05 210 *******************************************************************************/
wim 0:a8090b59eb05 211
wim 0:a8090b59eb05 212 static __inline void wr_dat_stop (void) {
wim 0:a8090b59eb05 213
wim 0:a8090b59eb05 214 LCD_CS(1)
wim 0:a8090b59eb05 215 }
wim 0:a8090b59eb05 216
wim 0:a8090b59eb05 217
wim 0:a8090b59eb05 218 /*******************************************************************************
wim 0:a8090b59eb05 219 * Data writing to LCD controller *
wim 0:a8090b59eb05 220 * Parameter: c: data to be written *
wim 0:a8090b59eb05 221 * Return: *
wim 0:a8090b59eb05 222 *******************************************************************************/
wim 0:a8090b59eb05 223
wim 0:a8090b59eb05 224 static __inline void wr_dat_only (unsigned short c) {
wim 0:a8090b59eb05 225
wim 0:a8090b59eb05 226 lcd_send(c);
wim 0:a8090b59eb05 227 LCD_WR(0)
wim 0:a8090b59eb05 228 wait();
wim 0:a8090b59eb05 229 LCD_WR(1)
wim 0:a8090b59eb05 230 }
wim 0:a8090b59eb05 231
wim 0:a8090b59eb05 232
wim 0:a8090b59eb05 233 /*******************************************************************************
wim 0:a8090b59eb05 234 * Write to LCD register *
wim 0:a8090b59eb05 235 * Parameter: reg: register to be read *
wim 0:a8090b59eb05 236 * val: value to write to register *
wim 0:a8090b59eb05 237 *******************************************************************************/
wim 0:a8090b59eb05 238
wim 0:a8090b59eb05 239 static __inline void wr_reg (unsigned char reg, unsigned short val) {
wim 0:a8090b59eb05 240
wim 0:a8090b59eb05 241 LCD_CS(0)
wim 0:a8090b59eb05 242 wr_cmd(reg);
wim 0:a8090b59eb05 243 wr_dat(val);
wim 0:a8090b59eb05 244 LCD_CS(1)
wim 0:a8090b59eb05 245 }
wim 0:a8090b59eb05 246
wim 0:a8090b59eb05 247
wim 0:a8090b59eb05 248 /*******************************************************************************
wim 0:a8090b59eb05 249 * Read from LCD register *
wim 0:a8090b59eb05 250 * Parameter: reg: register to be read *
wim 0:a8090b59eb05 251 * Return: value read from register *
wim 0:a8090b59eb05 252 *******************************************************************************/
wim 0:a8090b59eb05 253
wim 0:a8090b59eb05 254 static unsigned short rd_reg (unsigned short reg) {
wim 0:a8090b59eb05 255 unsigned short val = 0;
wim 0:a8090b59eb05 256
wim 0:a8090b59eb05 257 LCD_CS(0)
wim 0:a8090b59eb05 258 wr_cmd(reg);
wim 0:a8090b59eb05 259 val = rd_dat();
wim 0:a8090b59eb05 260 LCD_CS(1)
wim 0:a8090b59eb05 261 return (val);
wim 0:a8090b59eb05 262 }
wim 0:a8090b59eb05 263
wim 0:a8090b59eb05 264
wim 0:a8090b59eb05 265 /************************ Exported functions **********************************/
wim 0:a8090b59eb05 266
wim 0:a8090b59eb05 267 /*******************************************************************************
wim 0:a8090b59eb05 268 * Initialize the Graphic LCD controller *
wim 0:a8090b59eb05 269 * Parameter: *
wim 0:a8090b59eb05 270 * Return: *
wim 0:a8090b59eb05 271 *******************************************************************************/
wim 0:a8090b59eb05 272
wim 0:a8090b59eb05 273 void GLCD_Init (void) {
wim 0:a8090b59eb05 274
wim 0:a8090b59eb05 275 /* Configure the LCD Control pins */
wim 0:a8090b59eb05 276 LPC_GPIO0->FIODIR |= 0x03f80000;
wim 0:a8090b59eb05 277 LPC_GPIO0->FIOSET = 0x03f80000;
wim 0:a8090b59eb05 278
wim 0:a8090b59eb05 279 delay(5); /* Delay 50 ms */
wim 0:a8090b59eb05 280
wim 0:a8090b59eb05 281 driverCode = rd_reg(0x00);
wim 0:a8090b59eb05 282
wim 0:a8090b59eb05 283 switch (driverCode) {
wim 0:a8090b59eb05 284
wim 0:a8090b59eb05 285 case LGDP4531_ID: { //2.8" TFT LCD Module, DriverIC is LGDP4531
wim 0:a8090b59eb05 286
wim 0:a8090b59eb05 287 wr_reg(0x00,0x0001);
wim 0:a8090b59eb05 288 wr_reg(0x10,0x0628);
wim 0:a8090b59eb05 289 wr_reg(0x12,0x0006);
wim 0:a8090b59eb05 290 wr_reg(0x13,0x0A32);
wim 0:a8090b59eb05 291 wr_reg(0x11,0x0040);
wim 0:a8090b59eb05 292 wr_reg(0x15,0x0050);
wim 0:a8090b59eb05 293 wr_reg(0x12,0x0016);
wim 0:a8090b59eb05 294 delay(15);
wim 0:a8090b59eb05 295 wr_reg(0x10,0x5660);
wim 0:a8090b59eb05 296 delay(15);
wim 0:a8090b59eb05 297 wr_reg(0x13,0x2A4E);
wim 0:a8090b59eb05 298 wr_reg(0x01,0x0100);
wim 0:a8090b59eb05 299 wr_reg(0x02,0x0300);
wim 0:a8090b59eb05 300
wim 0:a8090b59eb05 301 wr_reg(0x03,0x1030);
wim 0:a8090b59eb05 302
wim 0:a8090b59eb05 303 wr_reg(0x08,0x0202);
wim 0:a8090b59eb05 304 wr_reg(0x0A,0x0000);
wim 0:a8090b59eb05 305 wr_reg(0x30,0x0000);
wim 0:a8090b59eb05 306 wr_reg(0x31,0x0402);
wim 0:a8090b59eb05 307 wr_reg(0x32,0x0106);
wim 0:a8090b59eb05 308 wr_reg(0x33,0x0700);
wim 0:a8090b59eb05 309 wr_reg(0x34,0x0104);
wim 0:a8090b59eb05 310 wr_reg(0x35,0x0301);
wim 0:a8090b59eb05 311 wr_reg(0x36,0x0707);
wim 0:a8090b59eb05 312 wr_reg(0x37,0x0305);
wim 0:a8090b59eb05 313 wr_reg(0x38,0x0208);
wim 0:a8090b59eb05 314 wr_reg(0x39,0x0F0B);
wim 0:a8090b59eb05 315 delay(15);
wim 0:a8090b59eb05 316 wr_reg(0x41,0x0002);
wim 0:a8090b59eb05 317 wr_reg(0x60,0x2700);
wim 0:a8090b59eb05 318 wr_reg(0x61,0x0001);
wim 0:a8090b59eb05 319 wr_reg(0x90,0x0119);
wim 0:a8090b59eb05 320 wr_reg(0x92,0x010A);
wim 0:a8090b59eb05 321 wr_reg(0x93,0x0004);
wim 0:a8090b59eb05 322 wr_reg(0xA0,0x0100);
wim 0:a8090b59eb05 323 delay(15);
wim 0:a8090b59eb05 324 wr_reg(0xA0,0x0000);
wim 0:a8090b59eb05 325 delay(20);
wim 0:a8090b59eb05 326
wim 0:a8090b59eb05 327 break;
wim 0:a8090b59eb05 328 }
wim 0:a8090b59eb05 329
wim 0:a8090b59eb05 330 case ILI9328_ID:
wim 0:a8090b59eb05 331 case ILI9325_ID: { //2.8" TFT LCD Module, DriverIC is ILI9325
wim 0:a8090b59eb05 332
wim 0:a8090b59eb05 333 wr_reg(0x00e7,0x0010);
wim 0:a8090b59eb05 334 wr_reg(0x0000,0x0001); //start internal osc
wim 0:a8090b59eb05 335 wr_reg(0x0001,0x0100);
wim 0:a8090b59eb05 336 wr_reg(0x0002,0x0700); //power on sequence
wim 0:a8090b59eb05 337 wr_reg(0x0003,(1<<12)|(1<<5)|(1<<4) ); //65K
wim 0:a8090b59eb05 338 wr_reg(0x0004,0x0000);
wim 0:a8090b59eb05 339 wr_reg(0x0008,0x0207);
wim 0:a8090b59eb05 340 wr_reg(0x0009,0x0000);
wim 0:a8090b59eb05 341 wr_reg(0x000a,0x0000); //display setting
wim 0:a8090b59eb05 342 wr_reg(0x000c,0x0001); //display setting
wim 0:a8090b59eb05 343 wr_reg(0x000d,0x0000); //0f3c
wim 0:a8090b59eb05 344 wr_reg(0x000f,0x0000);
wim 0:a8090b59eb05 345 //Power On sequence //
wim 0:a8090b59eb05 346 wr_reg(0x0010,0x0000);
wim 0:a8090b59eb05 347 wr_reg(0x0011,0x0007);
wim 0:a8090b59eb05 348 wr_reg(0x0012,0x0000);
wim 0:a8090b59eb05 349 wr_reg(0x0013,0x0000);
wim 0:a8090b59eb05 350 delay(15);
wim 0:a8090b59eb05 351 wr_reg(0x0010,0x1590);
wim 0:a8090b59eb05 352 wr_reg(0x0011,0x0227);
wim 0:a8090b59eb05 353 delay(15);
wim 0:a8090b59eb05 354 wr_reg(0x0012,0x009c);
wim 0:a8090b59eb05 355 delay(15);
wim 0:a8090b59eb05 356 wr_reg(0x0013,0x1900);
wim 0:a8090b59eb05 357 wr_reg(0x0029,0x0023);
wim 0:a8090b59eb05 358 wr_reg(0x002b,0x000e);
wim 0:a8090b59eb05 359 delay(15);
wim 0:a8090b59eb05 360 wr_reg(0x0020,0x0000);
wim 0:a8090b59eb05 361 wr_reg(0x0021,0x0000);
wim 0:a8090b59eb05 362 ///////////////////////////////////////////////////////
wim 0:a8090b59eb05 363 delay(15);
wim 0:a8090b59eb05 364 wr_reg(0x0030,0x0007);
wim 0:a8090b59eb05 365 wr_reg(0x0031,0x0707);
wim 0:a8090b59eb05 366 wr_reg(0x0032,0x0006);
wim 0:a8090b59eb05 367 wr_reg(0x0035,0x0704);
wim 0:a8090b59eb05 368 wr_reg(0x0036,0x1f04);
wim 0:a8090b59eb05 369 wr_reg(0x0037,0x0004);
wim 0:a8090b59eb05 370 wr_reg(0x0038,0x0000);
wim 0:a8090b59eb05 371 wr_reg(0x0039,0x0706);
wim 0:a8090b59eb05 372 wr_reg(0x003c,0x0701);
wim 0:a8090b59eb05 373 wr_reg(0x003d,0x000f);
wim 0:a8090b59eb05 374 delay(15);
wim 0:a8090b59eb05 375 wr_reg(0x0050,0x0000);
wim 0:a8090b59eb05 376 wr_reg(0x0051,0x00ef);
wim 0:a8090b59eb05 377 wr_reg(0x0052,0x0000);
wim 0:a8090b59eb05 378 wr_reg(0x0053,0x013f);
wim 0:a8090b59eb05 379 wr_reg(0x0060,0xa700);
wim 0:a8090b59eb05 380 wr_reg(0x0061,0x0001);
wim 0:a8090b59eb05 381 wr_reg(0x006a,0x0000);
wim 0:a8090b59eb05 382 wr_reg(0x0080,0x0000);
wim 0:a8090b59eb05 383 wr_reg(0x0081,0x0000);
wim 0:a8090b59eb05 384 wr_reg(0x0082,0x0000);
wim 0:a8090b59eb05 385 wr_reg(0x0083,0x0000);
wim 0:a8090b59eb05 386 wr_reg(0x0084,0x0000);
wim 0:a8090b59eb05 387 wr_reg(0x0085,0x0000);
wim 0:a8090b59eb05 388
wim 0:a8090b59eb05 389 wr_reg(0x0090,0x0010);
wim 0:a8090b59eb05 390 wr_reg(0x0092,0x0000);
wim 0:a8090b59eb05 391 wr_reg(0x0093,0x0003);
wim 0:a8090b59eb05 392 wr_reg(0x0095,0x0110);
wim 0:a8090b59eb05 393 wr_reg(0x0097,0x0000);
wim 0:a8090b59eb05 394 wr_reg(0x0098,0x0000);
wim 0:a8090b59eb05 395 //display on sequence
wim 0:a8090b59eb05 396 wr_reg(0x0007,0x0133);
wim 0:a8090b59eb05 397 wr_reg(0x0020,0x0000);
wim 0:a8090b59eb05 398 wr_reg(0x0021,0x0000);
wim 0:a8090b59eb05 399
wim 0:a8090b59eb05 400 break;
wim 0:a8090b59eb05 401 }
wim 0:a8090b59eb05 402
wim 0:a8090b59eb05 403 case ILI9320_ID: { //3.2" TFT LCD Module,DriverIC is ILI9320
wim 0:a8090b59eb05 404 /* Start Initial Sequence --------------------------------------------------*/
wim 0:a8090b59eb05 405 wr_reg(0xE5, 0x8000); /* Set the internal vcore voltage */
wim 0:a8090b59eb05 406 wr_reg(0x00, 0x0001); /* Start internal OSC */
wim 0:a8090b59eb05 407 wr_reg(0x01, 0x0100); /* Set SS and SM bit */
wim 0:a8090b59eb05 408 wr_reg(0x02, 0x0700); /* Set 1 line inversion */
wim 0:a8090b59eb05 409 wr_reg(0x03, 0x1030); /* Set GRAM write direction and BGR=1 */
wim 0:a8090b59eb05 410 wr_reg(0x04, 0x0000); /* Resize register */
wim 0:a8090b59eb05 411 wr_reg(0x08, 0x0202); /* 2 lines each, back and front porch */
wim 0:a8090b59eb05 412 wr_reg(0x09, 0x0000); /* Set non-disp area refresh cyc ISC */
wim 0:a8090b59eb05 413 wr_reg(0x0A, 0x0000); /* FMARK function */
wim 0:a8090b59eb05 414 wr_reg(0x0C, 0x0000); /* RGB interface setting */
wim 0:a8090b59eb05 415 wr_reg(0x0D, 0x0000); /* Frame marker Position */
wim 0:a8090b59eb05 416 wr_reg(0x0F, 0x0000); /* RGB interface polarity */
wim 0:a8090b59eb05 417
wim 0:a8090b59eb05 418 /* Power On sequence -------------------------------------------------------*/
wim 0:a8090b59eb05 419 wr_reg(0x10, 0x0000); /* Reset Power Control 1 */
wim 0:a8090b59eb05 420 wr_reg(0x11, 0x0000); /* Reset Power Control 2 */
wim 0:a8090b59eb05 421 wr_reg(0x12, 0x0000); /* Reset Power Control 3 */
wim 0:a8090b59eb05 422 wr_reg(0x13, 0x0000); /* Reset Power Control 4 */
wim 0:a8090b59eb05 423 delay(20); /* Discharge cap power voltage (200ms)*/
wim 0:a8090b59eb05 424 wr_reg(0x10, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
wim 0:a8090b59eb05 425 wr_reg(0x11, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
wim 0:a8090b59eb05 426 delay(5); /* Delay 50 ms */
wim 0:a8090b59eb05 427 wr_reg(0x12, 0x0139); /* VREG1OUT voltage */
wim 0:a8090b59eb05 428 delay(5); /* Delay 50 ms */
wim 0:a8090b59eb05 429 wr_reg(0x13, 0x1D00); /* VDV[4:0] for VCOM amplitude */
wim 0:a8090b59eb05 430 wr_reg(0x29, 0x0013); /* VCM[4:0] for VCOMH */
wim 0:a8090b59eb05 431 delay(5); /* Delay 50 ms */
wim 0:a8090b59eb05 432 wr_reg(0x20, 0x0000); /* GRAM horizontal Address */
wim 0:a8090b59eb05 433 wr_reg(0x21, 0x0000); /* GRAM Vertical Address */
wim 0:a8090b59eb05 434
wim 0:a8090b59eb05 435 /* Adjust the Gamma Curve --------------------------------------------------*/
wim 0:a8090b59eb05 436 wr_reg(0x30, 0x0006);
wim 0:a8090b59eb05 437 wr_reg(0x31, 0x0101);
wim 0:a8090b59eb05 438 wr_reg(0x32, 0x0003);
wim 0:a8090b59eb05 439 wr_reg(0x35, 0x0106);
wim 0:a8090b59eb05 440 wr_reg(0x36, 0x0B02);
wim 0:a8090b59eb05 441 wr_reg(0x37, 0x0302);
wim 0:a8090b59eb05 442 wr_reg(0x38, 0x0707);
wim 0:a8090b59eb05 443 wr_reg(0x39, 0x0007);
wim 0:a8090b59eb05 444 wr_reg(0x3C, 0x0600);
wim 0:a8090b59eb05 445 wr_reg(0x3D, 0x020B);
wim 0:a8090b59eb05 446
wim 0:a8090b59eb05 447 /* Set GRAM area -----------------------------------------------------------*/
wim 0:a8090b59eb05 448 wr_reg(0x50, 0x0000); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 449 wr_reg(0x51, (HEIGHT-1)); /* Horizontal GRAM End Address */
wim 0:a8090b59eb05 450 wr_reg(0x52, 0x0000); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 451 wr_reg(0x53, (WIDTH-1)); /* Vertical GRAM End Address */
wim 0:a8090b59eb05 452 wr_reg(0x60, 0x2700); /* Gate Scan Line */
wim 0:a8090b59eb05 453 wr_reg(0x61, 0x0001); /* NDL,VLE, REV */
wim 0:a8090b59eb05 454 wr_reg(0x6A, 0x0000); /* Set scrolling line */
wim 0:a8090b59eb05 455
wim 0:a8090b59eb05 456 /* Partial Display Control -------------------------------------------------*/
wim 0:a8090b59eb05 457 wr_reg(0x80, 0x0000);
wim 0:a8090b59eb05 458 wr_reg(0x81, 0x0000);
wim 0:a8090b59eb05 459 wr_reg(0x82, 0x0000);
wim 0:a8090b59eb05 460 wr_reg(0x83, 0x0000);
wim 0:a8090b59eb05 461 wr_reg(0x84, 0x0000);
wim 0:a8090b59eb05 462 wr_reg(0x85, 0x0000);
wim 0:a8090b59eb05 463
wim 0:a8090b59eb05 464 /* Panel Control -----------------------------------------------------------*/
wim 0:a8090b59eb05 465 wr_reg(0x90, 0x0010);
wim 0:a8090b59eb05 466 wr_reg(0x92, 0x0000);
wim 0:a8090b59eb05 467 wr_reg(0x93, 0x0003);
wim 0:a8090b59eb05 468 wr_reg(0x95, 0x0110);
wim 0:a8090b59eb05 469 wr_reg(0x97, 0x0000);
wim 0:a8090b59eb05 470 wr_reg(0x98, 0x0000);
wim 0:a8090b59eb05 471
wim 0:a8090b59eb05 472 break;
wim 0:a8090b59eb05 473 }
wim 0:a8090b59eb05 474
wim 0:a8090b59eb05 475 case ILI9331_ID: {
wim 0:a8090b59eb05 476 wr_reg(0x00E7, 0x1014);
wim 0:a8090b59eb05 477 wr_reg(0x0001, 0x0100); /* set SS and SM bit */
wim 0:a8090b59eb05 478 wr_reg(0x0002, 0x0200); /* set 1 line inversion */
wim 0:a8090b59eb05 479 wr_reg(0x0003, 0x1030); /* set GRAM write direction and BGR=1 */
wim 0:a8090b59eb05 480 wr_reg(0x0008, 0x0202); /* set the back porch and front porch */
wim 0:a8090b59eb05 481 wr_reg(0x0009, 0x0000); /* set non-display area refresh cycle ISC[3:0] */
wim 0:a8090b59eb05 482 wr_reg(0x000A, 0x0000); /* FMARK function */
wim 0:a8090b59eb05 483 wr_reg(0x000C, 0x0000); /* RGB interface setting */
wim 0:a8090b59eb05 484 wr_reg(0x000D, 0x0000); /* Frame marker Position */
wim 0:a8090b59eb05 485 wr_reg(0x000F, 0x0000); /* RGB interface polarity */
wim 0:a8090b59eb05 486 /* Power On sequence */
wim 0:a8090b59eb05 487 wr_reg(0x0010, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB   */
wim 0:a8090b59eb05 488 wr_reg(0x0011, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */
wim 0:a8090b59eb05 489 wr_reg(0x0012, 0x0000); /* VREG1OUT voltage   */
wim 0:a8090b59eb05 490 wr_reg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */
wim 0:a8090b59eb05 491 delay(200); /* delay 200 ms */
wim 0:a8090b59eb05 492 wr_reg(0x0010, 0x1690); /* SAP, BT[3:0], AP, DSTB, SLP, STB   */
wim 0:a8090b59eb05 493 wr_reg(0x0011, 0x0227); /* DC1[2:0], DC0[2:0], VC[2:0] */
wim 0:a8090b59eb05 494 delay(50); /* delay 50 ms */
wim 0:a8090b59eb05 495 wr_reg(0x0012, 0x000C); /* Internal reference voltage= Vci   */
wim 0:a8090b59eb05 496 delay(50); /* delay 50 ms */
wim 0:a8090b59eb05 497 wr_reg(0x0013, 0x0800); /* Set VDV[4:0] for VCOM amplitude */
wim 0:a8090b59eb05 498 wr_reg(0x0029, 0x0011); /* Set VCM[5:0] for VCOMH */
wim 0:a8090b59eb05 499 wr_reg(0x002B, 0x000B); /* Set Frame Rate */
wim 0:a8090b59eb05 500 delay(50); /* delay 50 ms */
wim 0:a8090b59eb05 501 wr_reg(0x0020, 0x0000); /* GRAM horizontal Address */
wim 0:a8090b59eb05 502 wr_reg(0x0021, 0x0000); /* GRAM Vertical Address */
wim 0:a8090b59eb05 503 /* Adjust the Gamma Curve */
wim 0:a8090b59eb05 504 wr_reg(0x0030, 0x0000);
wim 0:a8090b59eb05 505 wr_reg(0x0031, 0x0106);
wim 0:a8090b59eb05 506 wr_reg(0x0032, 0x0000);
wim 0:a8090b59eb05 507 wr_reg(0x0035, 0x0204);
wim 0:a8090b59eb05 508 wr_reg(0x0036, 0x160A);
wim 0:a8090b59eb05 509 wr_reg(0x0037, 0x0707);
wim 0:a8090b59eb05 510 wr_reg(0x0038, 0x0106);
wim 0:a8090b59eb05 511 wr_reg(0x0039, 0x0707);
wim 0:a8090b59eb05 512 wr_reg(0x003C, 0x0402);
wim 0:a8090b59eb05 513 wr_reg(0x003D, 0x0C0F);
wim 0:a8090b59eb05 514 /* Set GRAM area */
wim 0:a8090b59eb05 515 wr_reg(0x0050, 0x0000); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 516 wr_reg(0x0051, 0x00EF); /* Horizontal GRAM End Address */
wim 0:a8090b59eb05 517 wr_reg(0x0052, 0x0000); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 518 wr_reg(0x0053, 0x013F); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 519 wr_reg(0x0060, 0x2700); /* Gate Scan Line */
wim 0:a8090b59eb05 520 wr_reg(0x0061, 0x0001); /*  NDL,VLE, REV */
wim 0:a8090b59eb05 521 wr_reg(0x006A, 0x0000); /* set scrolling line */
wim 0:a8090b59eb05 522 /* Partial Display Control */
wim 0:a8090b59eb05 523 wr_reg(0x0080, 0x0000);
wim 0:a8090b59eb05 524 wr_reg(0x0081, 0x0000);
wim 0:a8090b59eb05 525 wr_reg(0x0082, 0x0000);
wim 0:a8090b59eb05 526 wr_reg(0x0083, 0x0000);
wim 0:a8090b59eb05 527 wr_reg(0x0084, 0x0000);
wim 0:a8090b59eb05 528 wr_reg(0x0085, 0x0000);
wim 0:a8090b59eb05 529 /* Panel Control */
wim 0:a8090b59eb05 530 wr_reg(0x0090, 0x0010);
wim 0:a8090b59eb05 531 wr_reg(0x0092, 0x0600);
wim 0:a8090b59eb05 532 wr_reg(0x0007,0x0021);
wim 0:a8090b59eb05 533 delay(50); /* delay 50 ms */
wim 0:a8090b59eb05 534 wr_reg(0x0007,0x0061);
wim 0:a8090b59eb05 535 delay(50); /* delay 50 ms */
wim 0:a8090b59eb05 536 wr_reg(0x0007,0x0133); /* 262K color and display ON */
wim 0:a8090b59eb05 537 break;
wim 0:a8090b59eb05 538 }
wim 0:a8090b59eb05 539
wim 0:a8090b59eb05 540 case SSD1289_ID: { //3.2" TFT LCD Module,DriverIC is SSD1289
wim 0:a8090b59eb05 541
wim 0:a8090b59eb05 542 /* Set GRAM write direction and BGR = 1
wim 0:a8090b59eb05 543 I/D=10 (Horizontal : increment, Vertical : increment)
wim 0:a8090b59eb05 544 AM=1 (address is updated in vertical writing direction) */
wim 0:a8090b59eb05 545 wr_reg(0x03, 0x1038);
wim 0:a8090b59eb05 546 wr_reg(0x07, 0x0173); /* 262K color and display ON */
wim 0:a8090b59eb05 547
wim 0:a8090b59eb05 548 /// case SSD1289_ID: { //3.2" TFT LCD Module,DriverIC is SSD1289
wim 0:a8090b59eb05 549
wim 0:a8090b59eb05 550 wr_reg(0x0000,0x0001); delay(5); // osc en
wim 0:a8090b59eb05 551
wim 0:a8090b59eb05 552 wr_reg(0x0003,0xA8A4); delay(5); // powercontrol 1 0xA8A4
wim 0:a8090b59eb05 553 wr_reg(0x000C,0x0000); delay(5); // powercontrol 2
wim 0:a8090b59eb05 554 wr_reg(0x000D,0x080C); delay(5); // powercontrol 3
wim 0:a8090b59eb05 555 wr_reg(0x000E,0x2B00); delay(5); // powercontrol 4
wim 0:a8090b59eb05 556 wr_reg(0x001E,0x00B0); delay(5); // powercontrol 5
wim 0:a8090b59eb05 557
wim 0:a8090b59eb05 558 //orig wr_reg(0x0001,0x2b3F); delay(5); // 0x2b3f Mux=320, BGR, RL=0, TB=1
wim 0:a8090b59eb05 559 wr_reg(0x0001,0x6B3F); delay(5); // 0x6B3F Mux=320, BGR, RL=1, TB=1
wim 0:a8090b59eb05 560 // wr_reg(0x0001,0x293F); delay(5); // 0x293f Mux=320, BGR, RL=0, TB=0
wim 0:a8090b59eb05 561
wim 0:a8090b59eb05 562
wim 0:a8090b59eb05 563 wr_reg(0x0002,0x0600); delay(5); // Driver AC mode
wim 0:a8090b59eb05 564 wr_reg(0x0010,0x0000); delay(5); // Exit Sleep
wim 0:a8090b59eb05 565
wim 0:a8090b59eb05 566 wr_reg(0x0011,0x6078); delay(5); // Entry mode 0x6078 = 65k colors, Hor and Vert Addr Incr, AM=1 vert writing dir
wim 0:a8090b59eb05 567 // wr_reg(0x0011,0x4030); delay(5); // Entry mode 0x4030 = 262k colors, Hor and Vert Addr Incr. AM=0 hor writing dir
wim 0:a8090b59eb05 568
wim 0:a8090b59eb05 569 wr_reg(0x0005,0x0000); delay(5); // Compare Regs (default)
wim 0:a8090b59eb05 570 wr_reg(0x0006,0x0000); delay(5);
wim 0:a8090b59eb05 571
wim 0:a8090b59eb05 572 wr_reg(0x0016,0xEF1C); delay(5); // Hor Porch (default)
wim 0:a8090b59eb05 573 wr_reg(0x0017,0x0003); delay(5); // Ver Porch (default 0103)
wim 0:a8090b59eb05 574 wr_reg(0x0007,0x0233); delay(5); //0x0233
wim 0:a8090b59eb05 575 wr_reg(0x000B,0x0000); delay(5); // Frame cycle control default 5308)
wim 0:a8090b59eb05 576
wim 0:a8090b59eb05 577 wr_reg(0x000F,0x0000); delay(5); // Gate scan start position
wim 0:a8090b59eb05 578
wim 0:a8090b59eb05 579 wr_reg(0x0041,0x0000); delay(5); // Vert Scroll control
wim 0:a8090b59eb05 580 wr_reg(0x0042,0x0000); delay(5);
wim 0:a8090b59eb05 581
wim 0:a8090b59eb05 582 wr_reg(0x0048,0x0000); delay(5); // First screen pos (default)
wim 0:a8090b59eb05 583 wr_reg(0x0049,0x013F); delay(5);
wim 0:a8090b59eb05 584
wim 0:a8090b59eb05 585 wr_reg(0x004A,0x0000); delay(5); // Second screen pos
wim 0:a8090b59eb05 586 wr_reg(0x004B,0x0000); delay(5);
wim 0:a8090b59eb05 587
wim 0:a8090b59eb05 588 wr_reg(0x0044,0xEF00); delay(5); // Hor addr pos
wim 0:a8090b59eb05 589 wr_reg(0x0045,0x0000); delay(5); // Vert Addr pos
wim 0:a8090b59eb05 590 wr_reg(0x0046,0x013F); delay(5);
wim 0:a8090b59eb05 591
wim 0:a8090b59eb05 592 wr_reg(0x0030,0x0707); delay(5); // Gamma
wim 0:a8090b59eb05 593 wr_reg(0x0031,0x0204); delay(5);
wim 0:a8090b59eb05 594 wr_reg(0x0032,0x0204); delay(5);
wim 0:a8090b59eb05 595 wr_reg(0x0033,0x0502); delay(5);
wim 0:a8090b59eb05 596 wr_reg(0x0034,0x0507); delay(5);
wim 0:a8090b59eb05 597 wr_reg(0x0035,0x0204); delay(5);
wim 0:a8090b59eb05 598 wr_reg(0x0036,0x0204); delay(5);
wim 0:a8090b59eb05 599 wr_reg(0x0037,0x0502); delay(5);
wim 0:a8090b59eb05 600 wr_reg(0x003A,0x0302); delay(5);
wim 0:a8090b59eb05 601 wr_reg(0x003B,0x0302); delay(5);
wim 0:a8090b59eb05 602
wim 0:a8090b59eb05 603 wr_reg(0x0023,0x0000); delay(5); // Write data mask (default)
wim 0:a8090b59eb05 604 wr_reg(0x0024,0x0000); delay(5);
wim 0:a8090b59eb05 605
wim 0:a8090b59eb05 606 wr_reg(0x0025,0x8000); delay(5); // Frame freq 65 Hz
wim 0:a8090b59eb05 607 wr_reg(0x004e,0); // Start x
wim 0:a8090b59eb05 608 wr_reg(0x004f,0); // Start y
wim 0:a8090b59eb05 609
wim 0:a8090b59eb05 610 break;
wim 0:a8090b59eb05 611 }
wim 0:a8090b59eb05 612
wim 0:a8090b59eb05 613
wim 0:a8090b59eb05 614 case SSD1298_ID: {
wim 0:a8090b59eb05 615 wr_reg(0x0028,0x0006);
wim 0:a8090b59eb05 616 wr_reg(0x0000,0x0001);
wim 0:a8090b59eb05 617 wr_reg(0x0003,0xaea4); /* power control 1---line frequency and VHG,VGL voltage */
wim 0:a8090b59eb05 618 wr_reg(0x000c,0x0004); /* power control 2---VCIX2 output voltage */
wim 0:a8090b59eb05 619 wr_reg(0x000d,0x000c); /* power control 3---Vlcd63 voltage */
wim 0:a8090b59eb05 620 wr_reg(0x000e,0x2800); /* power control 4---VCOMA voltage VCOML=VCOMH*0.9475-VCOMA */
wim 0:a8090b59eb05 621 wr_reg(0x001e,0x00b5); /* POWER CONTROL 5---VCOMH voltage */
wim 0:a8090b59eb05 622 wr_reg(0x0001,0x3b3f);
wim 0:a8090b59eb05 623 wr_reg(0x0002,0x0600);
wim 0:a8090b59eb05 624 wr_reg(0x0010,0x0000);
wim 0:a8090b59eb05 625 wr_reg(0x0011,0x6830);
wim 0:a8090b59eb05 626 wr_reg(0x0005,0x0000);
wim 0:a8090b59eb05 627 wr_reg(0x0006,0x0000);
wim 0:a8090b59eb05 628 wr_reg(0x0016,0xef1c);
wim 0:a8090b59eb05 629 wr_reg(0x0007,0x0033); /* Display control 1 */
wim 0:a8090b59eb05 630 /* when GON=1 and DTE=0,all gate outputs become VGL */
wim 0:a8090b59eb05 631 /* when GON=1 and DTE=0,all gate outputs become VGH */
wim 0:a8090b59eb05 632 /* non-selected gate wires become VGL */
wim 0:a8090b59eb05 633 wr_reg(0x000b,0x0000);
wim 0:a8090b59eb05 634 wr_reg(0x000f,0x0000);
wim 0:a8090b59eb05 635 wr_reg(0x0041,0x0000);
wim 0:a8090b59eb05 636 wr_reg(0x0042,0x0000);
wim 0:a8090b59eb05 637 wr_reg(0x0048,0x0000);
wim 0:a8090b59eb05 638 wr_reg(0x0049,0x013f);
wim 0:a8090b59eb05 639 wr_reg(0x004a,0x0000);
wim 0:a8090b59eb05 640 wr_reg(0x004b,0x0000);
wim 0:a8090b59eb05 641 wr_reg(0x0044,0xef00); /* Horizontal RAM start and end address */
wim 0:a8090b59eb05 642 wr_reg(0x0045,0x0000); /* Vretical RAM start address */
wim 0:a8090b59eb05 643 wr_reg(0x0046,0x013f); /* Vretical RAM end address */
wim 0:a8090b59eb05 644 wr_reg(0x004e,0x0000); /* set GDDRAM x address counter */
wim 0:a8090b59eb05 645 wr_reg(0x004f,0x0000); /* set GDDRAM y address counter */
wim 0:a8090b59eb05 646 /* y control */
wim 0:a8090b59eb05 647 wr_reg(0x0030,0x0707);
wim 0:a8090b59eb05 648 wr_reg(0x0031,0x0202);
wim 0:a8090b59eb05 649 wr_reg(0x0032,0x0204);
wim 0:a8090b59eb05 650 wr_reg(0x0033,0x0502);
wim 0:a8090b59eb05 651 wr_reg(0x0034,0x0507);
wim 0:a8090b59eb05 652 wr_reg(0x0035,0x0204);
wim 0:a8090b59eb05 653 wr_reg(0x0036,0x0204);
wim 0:a8090b59eb05 654 wr_reg(0x0037,0x0502);
wim 0:a8090b59eb05 655 wr_reg(0x003a,0x0302);
wim 0:a8090b59eb05 656 wr_reg(0x003b,0x0302);
wim 0:a8090b59eb05 657 wr_reg(0x0023,0x0000);
wim 0:a8090b59eb05 658 wr_reg(0x0024,0x0000);
wim 0:a8090b59eb05 659 wr_reg(0x0025,0x8000);
wim 0:a8090b59eb05 660 wr_reg(0x0026,0x7000);
wim 0:a8090b59eb05 661 wr_reg(0x0020,0xb0eb);
wim 0:a8090b59eb05 662 wr_reg(0x0027,0x007c);
wim 0:a8090b59eb05 663 break;
wim 0:a8090b59eb05 664 }
wim 0:a8090b59eb05 665
wim 0:a8090b59eb05 666 case SSD2119_ID: {
wim 0:a8090b59eb05 667 /* POWER ON & RESET DISPLAY OFF */
wim 0:a8090b59eb05 668 wr_reg(0x28,0x0006);
wim 0:a8090b59eb05 669 wr_reg(0x00,0x0001);
wim 0:a8090b59eb05 670 wr_reg(0x10,0x0000);
wim 0:a8090b59eb05 671 wr_reg(0x01,0x72ef);
wim 0:a8090b59eb05 672 wr_reg(0x02,0x0600);
wim 0:a8090b59eb05 673 wr_reg(0x03,0x6a38);
wim 0:a8090b59eb05 674 wr_reg(0x11,0x6874);
wim 0:a8090b59eb05 675 wr_reg(0x0f,0x0000); /* RAM WRITE DATA MASK */
wim 0:a8090b59eb05 676 wr_reg(0x0b,0x5308); /* RAM WRITE DATA MASK */
wim 0:a8090b59eb05 677 wr_reg(0x0c,0x0003);
wim 0:a8090b59eb05 678 wr_reg(0x0d,0x000a);
wim 0:a8090b59eb05 679 wr_reg(0x0e,0x2e00);
wim 0:a8090b59eb05 680 wr_reg(0x1e,0x00be);
wim 0:a8090b59eb05 681 wr_reg(0x25,0x8000);
wim 0:a8090b59eb05 682 wr_reg(0x26,0x7800);
wim 0:a8090b59eb05 683 wr_reg(0x27,0x0078);
wim 0:a8090b59eb05 684 wr_reg(0x4e,0x0000);
wim 0:a8090b59eb05 685 wr_reg(0x4f,0x0000);
wim 0:a8090b59eb05 686 wr_reg(0x12,0x08d9);
wim 0:a8090b59eb05 687 /* Adjust the Gamma Curve */
wim 0:a8090b59eb05 688 wr_reg(0x30,0x0000);
wim 0:a8090b59eb05 689 wr_reg(0x31,0x0104);
wim 0:a8090b59eb05 690 wr_reg(0x32,0x0100);
wim 0:a8090b59eb05 691 wr_reg(0x33,0x0305);
wim 0:a8090b59eb05 692 wr_reg(0x34,0x0505);
wim 0:a8090b59eb05 693 wr_reg(0x35,0x0305);
wim 0:a8090b59eb05 694 wr_reg(0x36,0x0707);
wim 0:a8090b59eb05 695 wr_reg(0x37,0x0300);
wim 0:a8090b59eb05 696 wr_reg(0x3a,0x1200);
wim 0:a8090b59eb05 697 wr_reg(0x3b,0x0800);
wim 0:a8090b59eb05 698 wr_reg(0x07,0x0033);
wim 0:a8090b59eb05 699 break;
wim 0:a8090b59eb05 700 }
wim 0:a8090b59eb05 701
wim 0:a8090b59eb05 702
wim 0:a8090b59eb05 703
wim 0:a8090b59eb05 704 #if(0)
wim 0:a8090b59eb05 705
wim 0:a8090b59eb05 706 // Note: unprintable char hidden as space and as nl !!!
wim 0:a8090b59eb05 707  case R61505U_ID1:
wim 0:a8090b59eb05 708  case R61505U_ID2:  {
wim 0:a8090b59eb05 709
wim 0:a8090b59eb05 710       /* second release on 3/5  ,luminance is acceptable,water wave appear during camera preview */
wim 0:a8090b59eb05 711        wr_reg(0x0007,0x0000);
wim 0:a8090b59eb05 712        delay(50);  /* delay 50 ms */      
wim 0:a8090b59eb05 713        wr_reg(0x0012,0x011C);    /* why need to set several times?   */
wim 0:a8090b59eb05 714        wr_reg(0x00A4,0x0001);    /* NVM */
wim 0:a8090b59eb05 715        wr_reg(0x0008,0x000F);
wim 0:a8090b59eb05 716        wr_reg(0x000A,0x0008);
wim 0:a8090b59eb05 717        wr_reg(0x000D,0x0008);
wim 0:a8090b59eb05 718        /* GAMMA CONTROL */
wim 0:a8090b59eb05 719        wr_reg(0x0030,0x0707);
wim 0:a8090b59eb05 720        wr_reg(0x0031,0x0007);
wim 0:a8090b59eb05 721        wr_reg(0x0032,0x0603);
wim 0:a8090b59eb05 722        wr_reg(0x0033,0x0700);
wim 0:a8090b59eb05 723        wr_reg(0x0034,0x0202);
wim 0:a8090b59eb05 724        wr_reg(0x0035,0x0002);
wim 0:a8090b59eb05 725        wr_reg(0x0036,0x1F0F);
wim 0:a8090b59eb05 726        wr_reg(0x0037,0x0707);
wim 0:a8090b59eb05 727        wr_reg(0x0038,0x0000);
wim 0:a8090b59eb05 728        wr_reg(0x0039,0x0000);
wim 0:a8090b59eb05 729        wr_reg(0x003A,0x0707);
wim 0:a8090b59eb05 730        wr_reg(0x003B,0x0000);
wim 0:a8090b59eb05 731        wr_reg(0x003C,0x0007);
wim 0:a8090b59eb05 732        wr_reg(0x003D,0x0000);
wim 0:a8090b59eb05 733        delay(50);  /* delay 50 ms */      
wim 0:a8090b59eb05 734        wr_reg(0x0007,0x0001);
wim 0:a8090b59eb05 735        wr_reg(0x0017,0x0001);    /* Power supply startup enable */
wim 0:a8090b59eb05 736        delay(50);  /* delay 50 ms */      
wim 0:a8090b59eb05 737        /* power control */
wim 0:a8090b59eb05 738        wr_reg(0x0010,0x17A0);
wim 0:a8090b59eb05 739        wr_reg(0x0011,0x0217); /* reference voltage VC[2:0]   Vciout = 1.00*Vcivl */
wim 0:a8090b59eb05 740        wr_reg(0x0012,0x011E); /* Vreg1out = Vcilvl*1.80   is it the same as Vgama1out ?   */
wim 0:a8090b59eb05 741        wr_reg(0x0013,0x0F00); /* VDV[4:0]-->VCOM Amplitude VcomL = VcomH - Vcom Ampl */
wim 0:a8090b59eb05 742        wr_reg(0x002A,0x0000);
wim 0:a8090b59eb05 743        wr_reg(0x0029,0x000A); /* Vcomh = VCM1[4:0]*Vreg1out    gate source voltage?? */
wim 0:a8090b59eb05 744        wr_reg(0x0012,0x013E); /* power supply on */
wim 0:a8090b59eb05 745        /* Coordinates Control */
wim 0:a8090b59eb05 746        wr_reg(0x0050,0x0000);
wim 0:a8090b59eb05 747        wr_reg(0x0051,0x00EF);
wim 0:a8090b59eb05 748        wr_reg(0x0052,0x0000);
wim 0:a8090b59eb05 749        wr_reg(0x0053,0x013F);
wim 0:a8090b59eb05 750        /* Pannel Image Control */
wim 0:a8090b59eb05 751        wr_reg(0x0060,0x2700);
wim 0:a8090b59eb05 752        wr_reg(0x0061,0x0001);
wim 0:a8090b59eb05 753        wr_reg(0x006A,0x0000);
wim 0:a8090b59eb05 754        wr_reg(0x0080,0x0000);
wim 0:a8090b59eb05 755        /* Partial Image Control */
wim 0:a8090b59eb05 756        wr_reg(0x0081,0x0000);
wim 0:a8090b59eb05 757        wr_reg(0x0082,0x0000);
wim 0:a8090b59eb05 758        wr_reg(0x0083,0x0000);
wim 0:a8090b59eb05 759        wr_reg(0x0084,0x0000);
wim 0:a8090b59eb05 760        wr_reg(0x0085,0x0000);
wim 0:a8090b59eb05 761        /* Panel Interface Control */
wim 0:a8090b59eb05 762        wr_reg(0x0090,0x0013);      /* frenqucy */   
wim 0:a8090b59eb05 763        wr_reg(0x0092,0x0300);
wim 0:a8090b59eb05 764        wr_reg(0x0093,0x0005);
wim 0:a8090b59eb05 765        wr_reg(0x0095,0x0000);
wim 0:a8090b59eb05 766        wr_reg(0x0097,0x0000);
wim 0:a8090b59eb05 767        wr_reg(0x0098,0x0000);
wim 0:a8090b59eb05 768
wim 0:a8090b59eb05 769        wr_reg(0x0001,0x0100);
wim 0:a8090b59eb05 770        wr_reg(0x0002,0x0700);
wim 0:a8090b59eb05 771        wr_reg(0x0003,0x1030);
wim 0:a8090b59eb05 772        wr_reg(0x0004,0x0000);
wim 0:a8090b59eb05 773        wr_reg(0x000C,0x0000);
wim 0:a8090b59eb05 774        wr_reg(0x000F,0x0000);
wim 0:a8090b59eb05 775        wr_reg(0x0020,0x0000);
wim 0:a8090b59eb05 776        wr_reg(0x0021,0x0000);
wim 0:a8090b59eb05 777        wr_reg(0x0007,0x0021);
wim 0:a8090b59eb05 778        delay(200);  /* delay 200 ms */      
wim 0:a8090b59eb05 779        wr_reg(0x0007,0x0061);
wim 0:a8090b59eb05 780        delay(200);  /* delay 200 ms */      
wim 0:a8090b59eb05 781        wr_reg(0x0007,0x0173);
wim 0:a8090b59eb05 782 break;
wim 0:a8090b59eb05 783    } 
wim 0:a8090b59eb05 784
wim 0:a8090b59eb05 785  case SPFD5408B_ID: {
wim 0:a8090b59eb05 786       
wim 0:a8090b59eb05 787       wr_reg(0x0001,0x0100);     /* Driver Output Contral Register */
wim 0:a8090b59eb05 788       wr_reg(0x0002,0x0700);      /* LCD Driving Waveform Contral */
wim 0:a8090b59eb05 789       wr_reg(0x0003,0x1030);     /* Entry ModeÉèÖÃ */
wim 0:a8090b59eb05 790       
wim 0:a8090b59eb05 791       wr_reg(0x0004,0x0000);     /* Scalling Control register */
wim 0:a8090b59eb05 792       wr_reg(0x0008,0x0207);     /* Display Control 2 */
wim 0:a8090b59eb05 793       wr_reg(0x0009,0x0000);     /* Display Control 3 */
wim 0:a8090b59eb05 794       wr_reg(0x000A,0x0000);     /* Frame Cycle Control */
wim 0:a8090b59eb05 795       wr_reg(0x000C,0x0000);     /* External Display Interface Control 1 */
wim 0:a8090b59eb05 796       wr_reg(0x000D,0x0000);      /* Frame Maker Position */
wim 0:a8090b59eb05 797       wr_reg(0x000F,0x0000);     /* External Display Interface Control 2 */
wim 0:a8090b59eb05 798       delay(50);
wim 0:a8090b59eb05 799       wr_reg(0x0007,0x0101);     /* Display Control */
wim 0:a8090b59eb05 800       delay(50);
wim 0:a8090b59eb05 801       wr_reg(0x0010,0x16B0);      /* Power Control 1 */
wim 0:a8090b59eb05 802       wr_reg(0x0011,0x0001);      /* Power Control 2 */
wim 0:a8090b59eb05 803       wr_reg(0x0017,0x0001);      /* Power Control 3 */
wim 0:a8090b59eb05 804       wr_reg(0x0012,0x0138);      /* Power Control 4 */
wim 0:a8090b59eb05 805       wr_reg(0x0013,0x0800);      /* Power Control 5 */
wim 0:a8090b59eb05 806       wr_reg(0x0029,0x0009);     /* NVM read data 2 */
wim 0:a8090b59eb05 807       wr_reg(0x002a,0x0009);     /* NVM read data 3 */
wim 0:a8090b59eb05 808       wr_reg(0x00a4,0x0000); 
wim 0:a8090b59eb05 809       wr_reg(0x0050,0x0000);     /* ÉèÖòÙ×÷´°¿ÚµÄXÖῪʼÁÐ */
wim 0:a8090b59eb05 810       wr_reg(0x0051,0x00EF);     /* ÉèÖòÙ×÷´°¿ÚµÄXÖá½áÊøÁÐ */
wim 0:a8090b59eb05 811       wr_reg(0x0052,0x0000);     /* ÉèÖòÙ×÷´°¿ÚµÄYÖῪʼÐÐ */
wim 0:a8090b59eb05 812       wr_reg(0x0053,0x013F);     /* ÉèÖòÙ×÷´°¿ÚµÄYÖá½áÊøÐÐ */
wim 0:a8090b59eb05 813          
wim 0:a8090b59eb05 814       wr_reg(0x0060,0x2700);     /* Driver Output Control */
wim 0:a8090b59eb05 815                                 /* ÉèÖÃÆÁÄ»µÄµãÊýÒÔ¼°É¨ÃèµÄÆðʼÐÐ */
wim 0:a8090b59eb05 816       wr_reg(0x0061,0x0003);     /* Driver Output Control */
wim 0:a8090b59eb05 817       wr_reg(0x006A,0x0000);     /* Vertical Scroll Control */
wim 0:a8090b59eb05 818       
wim 0:a8090b59eb05 819       wr_reg(0x0080,0x0000);     /* Display Position ¨C Partial Display 1 */
wim 0:a8090b59eb05 820       wr_reg(0x0081,0x0000);     /* RAM Address Start ¨C Partial Display 1 */
wim 0:a8090b59eb05 821       wr_reg(0x0082,0x0000);     /* RAM address End - Partial Display 1 */
wim 0:a8090b59eb05 822       wr_reg(0x0083,0x0000);     /* Display Position ¨C Partial Display 2 */
wim 0:a8090b59eb05 823       wr_reg(0x0084,0x0000);     /* RAM Address Start ¨C Partial Display 2 */
wim 0:a8090b59eb05 824       wr_reg(0x0085,0x0000);     /* RAM address End ¨C Partail Display2 */
wim 0:a8090b59eb05 825       wr_reg(0x0090,0x0013);     /* Frame Cycle Control */
wim 0:a8090b59eb05 826       wr_reg(0x0092,0x0000);      /* Panel Interface Control 2 */
wim 0:a8090b59eb05 827       wr_reg(0x0093,0x0003);     /* Panel Interface control 3 */
wim 0:a8090b59eb05 828       wr_reg(0x0095,0x0110);     /* Frame Cycle Control */
wim 0:a8090b59eb05 829       wr_reg(0x0007,0x0173);
wim 0:a8090b59eb05 830 break;
wim 0:a8090b59eb05 831    }
wim 0:a8090b59eb05 832
wim 0:a8090b59eb05 833   case LGDP4531_ID: {
wim 0:a8090b59eb05 834       /* Setup display */
wim 0:a8090b59eb05 835       wr_reg(0x00,0x0001);
wim 0:a8090b59eb05 836       wr_reg(0x10,0x0628);
wim 0:a8090b59eb05 837       wr_reg(0x12,0x0006);
wim 0:a8090b59eb05 838       wr_reg(0x13,0x0A32);
wim 0:a8090b59eb05 839       wr_reg(0x11,0x0040);
wim 0:a8090b59eb05 840       wr_reg(0x15,0x0050);
wim 0:a8090b59eb05 841       wr_reg(0x12,0x0016);
wim 0:a8090b59eb05 842       delay(50);
wim 0:a8090b59eb05 843       wr_reg(0x10,0x5660);
wim 0:a8090b59eb05 844       delay(50);
wim 0:a8090b59eb05 845       wr_reg(0x13,0x2A4E);
wim 0:a8090b59eb05 846       wr_reg(0x01,0x0100);
wim 0:a8090b59eb05 847       wr_reg(0x02,0x0300);   
wim 0:a8090b59eb05 848       wr_reg(0x03,0x1030);      
wim 0:a8090b59eb05 849       wr_reg(0x08,0x0202);
wim 0:a8090b59eb05 850       wr_reg(0x0A,0x0000);
wim 0:a8090b59eb05 851       wr_reg(0x30,0x0000);
wim 0:a8090b59eb05 852       wr_reg(0x31,0x0402);
wim 0:a8090b59eb05 853       wr_reg(0x32,0x0106);
wim 0:a8090b59eb05 854       wr_reg(0x33,0x0700);
wim 0:a8090b59eb05 855       wr_reg(0x34,0x0104);
wim 0:a8090b59eb05 856       wr_reg(0x35,0x0301);
wim 0:a8090b59eb05 857       wr_reg(0x36,0x0707);
wim 0:a8090b59eb05 858       wr_reg(0x37,0x0305);
wim 0:a8090b59eb05 859       wr_reg(0x38,0x0208);
wim 0:a8090b59eb05 860       wr_reg(0x39,0x0F0B);
wim 0:a8090b59eb05 861       delay(50);
wim 0:a8090b59eb05 862       wr_reg(0x41,0x0002);
wim 0:a8090b59eb05 863       wr_reg(0x60,0x2700);
wim 0:a8090b59eb05 864       wr_reg(0x61,0x0001);
wim 0:a8090b59eb05 865       wr_reg(0x90,0x0119);
wim 0:a8090b59eb05 866       wr_reg(0x92,0x010A);
wim 0:a8090b59eb05 867       wr_reg(0x93,0x0004);
wim 0:a8090b59eb05 868       wr_reg(0xA0,0x0100);
wim 0:a8090b59eb05 869       delay(50);
wim 0:a8090b59eb05 870       wr_reg(0x07,0x0133);
wim 0:a8090b59eb05 871       delay(50);
wim 0:a8090b59eb05 872       wr_reg(0xA0,0x0000);
wim 0:a8090b59eb05 873 break;
wim 0:a8090b59eb05 874    }
wim 0:a8090b59eb05 875
wim 0:a8090b59eb05 876   case LGDP4535_ID: {   
wim 0:a8090b59eb05 877       wr_reg(0x15, 0x0030);     /* Set the internal vcore voltage */                                             
wim 0:a8090b59eb05 878       wr_reg(0x9A, 0x0010);     /* Start internal OSC */
wim 0:a8090b59eb05 879       wr_reg(0x11, 0x0020);        /* set SS and SM bit */
wim 0:a8090b59eb05 880       wr_reg(0x10, 0x3428);        /* set 1 line inversion */
wim 0:a8090b59eb05 881       wr_reg(0x12, 0x0002);        /* set GRAM write direction and BGR=1 */
wim 0:a8090b59eb05 882       wr_reg(0x13, 0x1038);        /* Resize register */
wim 0:a8090b59eb05 883       delay(40);
wim 0:a8090b59eb05 884       wr_reg(0x12, 0x0012);        /* set the back porch and front porch */
wim 0:a8090b59eb05 885       delay(40);
wim 0:a8090b59eb05 886       wr_reg(0x10, 0x3420);        /* set non-display area refresh cycle ISC[3:0] */
wim 0:a8090b59eb05 887       wr_reg(0x13, 0x3045);        /* FMARK function */
wim 0:a8090b59eb05 888       delay(70);
wim 0:a8090b59eb05 889       wr_reg(0x30, 0x0000);      /* RGB interface setting */
wim 0:a8090b59eb05 890       wr_reg(0x31, 0x0402);        /* Frame marker Position */
wim 0:a8090b59eb05 891       wr_reg(0x32, 0x0307);      /* RGB interface polarity */
wim 0:a8090b59eb05 892       wr_reg(0x33, 0x0304);      /* SAP, BT[3:0], AP, DSTB, SLP, STB */
wim 0:a8090b59eb05 893       wr_reg(0x34, 0x0004);      /* DC1[2:0], DC0[2:0], VC[2:0] */
wim 0:a8090b59eb05 894       wr_reg(0x35, 0x0401);      /* VREG1OUT voltage */
wim 0:a8090b59eb05 895       wr_reg(0x36, 0x0707);      /* VDV[4:0] for VCOM amplitude */
wim 0:a8090b59eb05 896       wr_reg(0x37, 0x0305);      /* SAP, BT[3:0], AP, DSTB, SLP, STB */
wim 0:a8090b59eb05 897       wr_reg(0x38, 0x0610);      /* DC1[2:0], DC0[2:0], VC[2:0] */
wim 0:a8090b59eb05 898       wr_reg(0x39, 0x0610);      /* VREG1OUT voltage */
wim 0:a8090b59eb05 899       wr_reg(0x01, 0x0100);      /* VDV[4:0] for VCOM amplitude */
wim 0:a8090b59eb05 900       wr_reg(0x02, 0x0300);      /* VCM[4:0] for VCOMH */
wim 0:a8090b59eb05 901       wr_reg(0x03, 0x1030);      /* GRAM horizontal Address */
wim 0:a8090b59eb05 902       wr_reg(0x08, 0x0808);      /* GRAM Vertical Address */
wim 0:a8090b59eb05 903       wr_reg(0x0A, 0x0008);      
wim 0:a8090b59eb05 904       wr_reg(0x60, 0x2700);        /* Gate Scan Line */
wim 0:a8090b59eb05 905       wr_reg(0x61, 0x0001);        /* NDL,VLE, REV */
wim 0:a8090b59eb05 906       wr_reg(0x90, 0x013E);
wim 0:a8090b59eb05 907       wr_reg(0x92, 0x0100);
wim 0:a8090b59eb05 908       wr_reg(0x93, 0x0100);
wim 0:a8090b59eb05 909       wr_reg(0xA0, 0x3000);
wim 0:a8090b59eb05 910       wr_reg(0xA3, 0x0010);
wim 0:a8090b59eb05 911       wr_reg(0x07, 0x0001);
wim 0:a8090b59eb05 912       wr_reg(0x07, 0x0021);
wim 0:a8090b59eb05 913       wr_reg(0x07, 0x0023);
wim 0:a8090b59eb05 914       wr_reg(0x07, 0x0033);
wim 0:a8090b59eb05 915       wr_reg(0x07, 0x0133);
wim 0:a8090b59eb05 916 break;
wim 0:a8090b59eb05 917    }
wim 0:a8090b59eb05 918
wim 0:a8090b59eb05 919   case HX8347D_ID: {
wim 0:a8090b59eb05 920       /* Start Initial Sequence */
wim 0:a8090b59eb05 921       wr_reg(0xEA,0x00);                         
wim 0:a8090b59eb05 922       wr_reg(0xEB,0x20);                                                     
wim 0:a8090b59eb05 923       wr_reg(0xEC,0x0C);                                                   
wim 0:a8090b59eb05 924       wr_reg(0xED,0xC4);                                                   
wim 0:a8090b59eb05 925       wr_reg(0xE8,0x40);                                                     
wim 0:a8090b59eb05 926       wr_reg(0xE9,0x38);                                                   
wim 0:a8090b59eb05 927       wr_reg(0xF1,0x01);                                                   
wim 0:a8090b59eb05 928       wr_reg(0xF2,0x10);                                                   
wim 0:a8090b59eb05 929       wr_reg(0x27,0xA3);                                                   
wim 0:a8090b59eb05 930       /* GAMMA SETTING */
wim 0:a8090b59eb05 931       wr_reg(0x40,0x01);                           
wim 0:a8090b59eb05 932       wr_reg(0x41,0x00);                                                   
wim 0:a8090b59eb05 933       wr_reg(0x42,0x00);                                                   
wim 0:a8090b59eb05 934       wr_reg(0x43,0x10);                                                   
wim 0:a8090b59eb05 935       wr_reg(0x44,0x0E);                                                   
wim 0:a8090b59eb05 936       wr_reg(0x45,0x24);                                                 
wim 0:a8090b59eb05 937       wr_reg(0x46,0x04);                                                 
wim 0:a8090b59eb05 938       wr_reg(0x47,0x50);                                                   
wim 0:a8090b59eb05 939       wr_reg(0x48,0x02);                                                   
wim 0:a8090b59eb05 940       wr_reg(0x49,0x13);                                                 
wim 0:a8090b59eb05 941       wr_reg(0x4A,0x19);                                                 
wim 0:a8090b59eb05 942       wr_reg(0x4B,0x19);                                                 
wim 0:a8090b59eb05 943       wr_reg(0x4C,0x16);                                                 
wim 0:a8090b59eb05 944       wr_reg(0x50,0x1B);                                                   
wim 0:a8090b59eb05 945       wr_reg(0x51,0x31);                                                   
wim 0:a8090b59eb05 946       wr_reg(0x52,0x2F);                                                     
wim 0:a8090b59eb05 947       wr_reg(0x53,0x3F);                                                   
wim 0:a8090b59eb05 948       wr_reg(0x54,0x3F);                                                     
wim 0:a8090b59eb05 949       wr_reg(0x55,0x3E);                                                     
wim 0:a8090b59eb05 950       wr_reg(0x56,0x2F);                                                   
wim 0:a8090b59eb05 951       wr_reg(0x57,0x7B);                                                     
wim 0:a8090b59eb05 952       wr_reg(0x58,0x09);                                                 
wim 0:a8090b59eb05 953       wr_reg(0x59,0x06);                                                 
wim 0:a8090b59eb05 954       wr_reg(0x5A,0x06);                                                   
wim 0:a8090b59eb05 955       wr_reg(0x5B,0x0C);                                                   
wim 0:a8090b59eb05 956       wr_reg(0x5C,0x1D);                                                   
wim 0:a8090b59eb05 957       wr_reg(0x5D,0xCC);                                                   
wim 0:a8090b59eb05 958       /* Power Voltage Setting */
wim 0:a8090b59eb05 959       wr_reg(0x1B,0x18);                                                   
wim 0:a8090b59eb05 960       wr_reg(0x1A,0x01);                                                   
wim 0:a8090b59eb05 961       wr_reg(0x24,0x15);                                                   
wim 0:a8090b59eb05 962       wr_reg(0x25,0x50);                                                   
wim 0:a8090b59eb05 963       wr_reg(0x23,0x8B);                                                   
wim 0:a8090b59eb05 964       wr_reg(0x18,0x36);                           
wim 0:a8090b59eb05 965       wr_reg(0x19,0x01);                                                   
wim 0:a8090b59eb05 966       wr_reg(0x01,0x00);                                                   
wim 0:a8090b59eb05 967       wr_reg(0x1F,0x88);                                                   
wim 0:a8090b59eb05 968       delay(50);
wim 0:a8090b59eb05 969       wr_reg(0x1F,0x80);                                                 
wim 0:a8090b59eb05 970       delay(50);
wim 0:a8090b59eb05 971       wr_reg(0x1F,0x90);                                                   
wim 0:a8090b59eb05 972       delay(50);
wim 0:a8090b59eb05 973       wr_reg(0x1F,0xD0);                                                   
wim 0:a8090b59eb05 974       delay(50);
wim 0:a8090b59eb05 975       wr_reg(0x17,0x05);                                                   
wim 0:a8090b59eb05 976       wr_reg(0x36,0x00);                                                   
wim 0:a8090b59eb05 977       wr_reg(0x28,0x38);                                                 
wim 0:a8090b59eb05 978       delay(50);
wim 0:a8090b59eb05 979       wr_reg(0x28,0x3C);                                               
wim 0:a8090b59eb05 980 break;
wim 0:a8090b59eb05 981    }
wim 0:a8090b59eb05 982
wim 0:a8090b59eb05 983   case ST7781_ID: {
wim 0:a8090b59eb05 984       /* Start Initial Sequence */
wim 0:a8090b59eb05 985       wr_reg(0x00FF,0x0001);
wim 0:a8090b59eb05 986       wr_reg(0x00F3,0x0008);
wim 0:a8090b59eb05 987       wr_reg(0x0001,0x0100);
wim 0:a8090b59eb05 988       wr_reg(0x0002,0x0700);
wim 0:a8090b59eb05 989       wr_reg(0x0003,0x1030); 
wim 0:a8090b59eb05 990       wr_reg(0x0008,0x0302);
wim 0:a8090b59eb05 991       wr_reg(0x0008,0x0207);
wim 0:a8090b59eb05 992       wr_reg(0x0009,0x0000);
wim 0:a8090b59eb05 993       wr_reg(0x000A,0x0000);
wim 0:a8090b59eb05 994       wr_reg(0x0010,0x0000); 
wim 0:a8090b59eb05 995       wr_reg(0x0011,0x0005);
wim 0:a8090b59eb05 996       wr_reg(0x0012,0x0000);
wim 0:a8090b59eb05 997       wr_reg(0x0013,0x0000);
wim 0:a8090b59eb05 998       delay(50);
wim 0:a8090b59eb05 999       wr_reg(0x0010,0x12B0);
wim 0:a8090b59eb05 1000       delay(50);
wim 0:a8090b59eb05 1001       wr_reg(0x0011,0x0007);
wim 0:a8090b59eb05 1002       delay(50);
wim 0:a8090b59eb05 1003       wr_reg(0x0012,0x008B);
wim 0:a8090b59eb05 1004       delay(50);   
wim 0:a8090b59eb05 1005       wr_reg(0x0013,0x1700);
wim 0:a8090b59eb05 1006       delay(50);   
wim 0:a8090b59eb05 1007       wr_reg(0x0029,0x0022);      
wim 0:a8090b59eb05 1008       wr_reg(0x0030,0x0000);
wim 0:a8090b59eb05 1009       wr_reg(0x0031,0x0707);
wim 0:a8090b59eb05 1010       wr_reg(0x0032,0x0505);
wim 0:a8090b59eb05 1011       wr_reg(0x0035,0x0107);
wim 0:a8090b59eb05 1012       wr_reg(0x0036,0x0008);
wim 0:a8090b59eb05 1013       wr_reg(0x0037,0x0000);
wim 0:a8090b59eb05 1014       wr_reg(0x0038,0x0202);
wim 0:a8090b59eb05 1015       wr_reg(0x0039,0x0106);
wim 0:a8090b59eb05 1016       wr_reg(0x003C,0x0202);
wim 0:a8090b59eb05 1017       wr_reg(0x003D,0x0408);
wim 0:a8090b59eb05 1018       delay(50);            
wim 0:a8090b59eb05 1019       wr_reg(0x0050,0x0000);      
wim 0:a8090b59eb05 1020       wr_reg(0x0051,0x00EF);      
wim 0:a8090b59eb05 1021       wr_reg(0x0052,0x0000);      
wim 0:a8090b59eb05 1022       wr_reg(0x0053,0x013F);      
wim 0:a8090b59eb05 1023       wr_reg(0x0060,0xA700);      
wim 0:a8090b59eb05 1024       wr_reg(0x0061,0x0001);
wim 0:a8090b59eb05 1025       wr_reg(0x0090,0x0033);            
wim 0:a8090b59eb05 1026       wr_reg(0x002B,0x000B);      
wim 0:a8090b59eb05 1027       wr_reg(0x0007,0x0133);
wim 0:a8090b59eb05 1028 break;
wim 0:a8090b59eb05 1029    }
wim 0:a8090b59eb05 1030 #endif
wim 0:a8090b59eb05 1031
wim 0:a8090b59eb05 1032 default: {
wim 0:a8090b59eb05 1033 /* special ID */
wim 0:a8090b59eb05 1034 driverCode = rd_reg(0x67);
wim 0:a8090b59eb05 1035 if (driverCode == HX8347A_ID) {
wim 0:a8090b59eb05 1036 wr_reg(0x0042,0x0008);
wim 0:a8090b59eb05 1037 /* Gamma setting */
wim 0:a8090b59eb05 1038 wr_reg(0x0046,0x00B4);
wim 0:a8090b59eb05 1039 wr_reg(0x0047,0x0043);
wim 0:a8090b59eb05 1040 wr_reg(0x0048,0x0013);
wim 0:a8090b59eb05 1041 wr_reg(0x0049,0x0047);
wim 0:a8090b59eb05 1042 wr_reg(0x004A,0x0014);
wim 0:a8090b59eb05 1043 wr_reg(0x004B,0x0036);
wim 0:a8090b59eb05 1044 wr_reg(0x004C,0x0003);
wim 0:a8090b59eb05 1045 wr_reg(0x004D,0x0046);
wim 0:a8090b59eb05 1046 wr_reg(0x004E,0x0005);
wim 0:a8090b59eb05 1047 wr_reg(0x004F,0x0010);
wim 0:a8090b59eb05 1048 wr_reg(0x0050,0x0008);
wim 0:a8090b59eb05 1049 wr_reg(0x0051,0x000a);
wim 0:a8090b59eb05 1050 /* Window Setting */
wim 0:a8090b59eb05 1051 wr_reg(0x0002,0x0000);
wim 0:a8090b59eb05 1052 wr_reg(0x0003,0x0000);
wim 0:a8090b59eb05 1053 wr_reg(0x0004,0x0000);
wim 0:a8090b59eb05 1054 wr_reg(0x0005,0x00EF);
wim 0:a8090b59eb05 1055 wr_reg(0x0006,0x0000);
wim 0:a8090b59eb05 1056 wr_reg(0x0007,0x0000);
wim 0:a8090b59eb05 1057 wr_reg(0x0008,0x0001);
wim 0:a8090b59eb05 1058 wr_reg(0x0009,0x003F);
wim 0:a8090b59eb05 1059 delay(10);
wim 0:a8090b59eb05 1060 wr_reg(0x0001,0x0006);
wim 0:a8090b59eb05 1061 wr_reg(0x0016,0x00C8);
wim 0:a8090b59eb05 1062 wr_reg(0x0023,0x0095);
wim 0:a8090b59eb05 1063 wr_reg(0x0024,0x0095);
wim 0:a8090b59eb05 1064 wr_reg(0x0025,0x00FF);
wim 0:a8090b59eb05 1065 wr_reg(0x0027,0x0002);
wim 0:a8090b59eb05 1066 wr_reg(0x0028,0x0002);
wim 0:a8090b59eb05 1067 wr_reg(0x0029,0x0002);
wim 0:a8090b59eb05 1068 wr_reg(0x002A,0x0002);
wim 0:a8090b59eb05 1069 wr_reg(0x002C,0x0002);
wim 0:a8090b59eb05 1070 wr_reg(0x002D,0x0002);
wim 0:a8090b59eb05 1071 wr_reg(0x003A,0x0001);
wim 0:a8090b59eb05 1072 wr_reg(0x003B,0x0001);
wim 0:a8090b59eb05 1073 wr_reg(0x003C,0x00F0);
wim 0:a8090b59eb05 1074 wr_reg(0x003D,0x0000);
wim 0:a8090b59eb05 1075 delay(20);
wim 0:a8090b59eb05 1076 wr_reg(0x0035,0x0038);
wim 0:a8090b59eb05 1077 wr_reg(0x0036,0x0078);
wim 0:a8090b59eb05 1078 wr_reg(0x003E,0x0038);
wim 0:a8090b59eb05 1079 wr_reg(0x0040,0x000F);
wim 0:a8090b59eb05 1080 wr_reg(0x0041,0x00F0);
wim 0:a8090b59eb05 1081 wr_reg(0x0038,0x0000);
wim 0:a8090b59eb05 1082 /* Power Setting */
wim 0:a8090b59eb05 1083 wr_reg(0x0019,0x0049);
wim 0:a8090b59eb05 1084 wr_reg(0x0093,0x000A);
wim 0:a8090b59eb05 1085 delay(10);
wim 0:a8090b59eb05 1086 wr_reg(0x0020,0x0020);
wim 0:a8090b59eb05 1087 wr_reg(0x001D,0x0003);
wim 0:a8090b59eb05 1088 wr_reg(0x001E,0x0000);
wim 0:a8090b59eb05 1089 wr_reg(0x001F,0x0009);
wim 0:a8090b59eb05 1090 wr_reg(0x0044,0x0053);
wim 0:a8090b59eb05 1091 wr_reg(0x0045,0x0010);
wim 0:a8090b59eb05 1092 delay(10);
wim 0:a8090b59eb05 1093 wr_reg(0x001C,0x0004);
wim 0:a8090b59eb05 1094 delay(20);
wim 0:a8090b59eb05 1095 wr_reg(0x0043,0x0080);
wim 0:a8090b59eb05 1096 delay(5);
wim 0:a8090b59eb05 1097 wr_reg(0x001B,0x000a);
wim 0:a8090b59eb05 1098 delay(40);
wim 0:a8090b59eb05 1099 wr_reg(0x001B,0x0012);
wim 0:a8090b59eb05 1100 delay(40);
wim 0:a8090b59eb05 1101 /* Display On Setting */
wim 0:a8090b59eb05 1102 wr_reg(0x0090,0x007F);
wim 0:a8090b59eb05 1103 wr_reg(0x0026,0x0004);
wim 0:a8090b59eb05 1104 delay(40);
wim 0:a8090b59eb05 1105 wr_reg(0x0026,0x0024);
wim 0:a8090b59eb05 1106 wr_reg(0x0026,0x002C);
wim 0:a8090b59eb05 1107 delay(40);
wim 0:a8090b59eb05 1108 wr_reg(0x0070,0x0008);
wim 0:a8090b59eb05 1109 wr_reg(0x0026,0x003C);
wim 0:a8090b59eb05 1110 wr_reg(0x0057,0x0002);
wim 0:a8090b59eb05 1111 wr_reg(0x0055,0x0000);
wim 0:a8090b59eb05 1112 wr_reg(0x0057,0x0000);
wim 0:a8090b59eb05 1113 } // if
wim 0:a8090b59eb05 1114 break;
wim 0:a8090b59eb05 1115 } // default case
wim 0:a8090b59eb05 1116
wim 0:a8090b59eb05 1117 } // end switch
wim 0:a8090b59eb05 1118
wim 0:a8090b59eb05 1119
wim 0:a8090b59eb05 1120 }
wim 0:a8090b59eb05 1121
wim 0:a8090b59eb05 1122
wim 0:a8090b59eb05 1123
wim 0:a8090b59eb05 1124
wim 0:a8090b59eb05 1125
wim 0:a8090b59eb05 1126 /*******************************************************************************
wim 0:a8090b59eb05 1127 * Get LCD Controller ID *
wim 0:a8090b59eb05 1128 * Parameter: *
wim 0:a8090b59eb05 1129 * Return: short Controller ID *
wim 0:a8090b59eb05 1130 *******************************************************************************/
wim 0:a8090b59eb05 1131 unsigned short GLCD_DriverCode () {
wim 0:a8090b59eb05 1132
wim 0:a8090b59eb05 1133 return (driverCode);
wim 0:a8090b59eb05 1134 }
wim 0:a8090b59eb05 1135
wim 0:a8090b59eb05 1136
wim 0:a8090b59eb05 1137 /*******************************************************************************
wim 0:a8090b59eb05 1138 * Set draw window region to whole screen *
wim 0:a8090b59eb05 1139 * Parameter: *
wim 0:a8090b59eb05 1140 * Return: *
wim 0:a8090b59eb05 1141 *******************************************************************************/
wim 0:a8090b59eb05 1142
wim 0:a8090b59eb05 1143 void GLCD_WindowMax (void) {
wim 0:a8090b59eb05 1144
wim 0:a8090b59eb05 1145 if(driverCode==0x8989)
wim 0:a8090b59eb05 1146 {
wim 0:a8090b59eb05 1147 wr_reg(0x44, 0); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1148 wr_reg(0x44, 0 |((HEIGHT-1)<<8)); /* Horizontal GRAM End Address (-1) */
wim 0:a8090b59eb05 1149 wr_reg(0x45, 0); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1150 wr_reg(0x46, WIDTH-1); /* Vertical GRAM End Address (-1) */
wim 0:a8090b59eb05 1151 }
wim 0:a8090b59eb05 1152 else
wim 0:a8090b59eb05 1153 {
wim 0:a8090b59eb05 1154 wr_reg(0x50, 0); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1155 wr_reg(0x51, HEIGHT-1); /* Horizontal GRAM End Address (-1) */
wim 0:a8090b59eb05 1156 wr_reg(0x52, 0); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1157 wr_reg(0x53, WIDTH-1); /* Vertical GRAM End Address (-1) */
wim 0:a8090b59eb05 1158 }
wim 0:a8090b59eb05 1159 }
wim 0:a8090b59eb05 1160
wim 0:a8090b59eb05 1161 /*******************************************************************************
wim 0:a8090b59eb05 1162 * Set draw window region *
wim 0:a8090b59eb05 1163 * Parameter: *
wim 0:a8090b59eb05 1164 * Return: *
wim 0:a8090b59eb05 1165 *******************************************************************************/
wim 0:a8090b59eb05 1166
wim 0:a8090b59eb05 1167 void GLCD_Window (int x1, int y1, int x2, int y2) {
wim 0:a8090b59eb05 1168
wim 0:a8090b59eb05 1169 if(driverCode==0x8989)
wim 0:a8090b59eb05 1170 {
wim 0:a8090b59eb05 1171 // wr_reg(0x44, x1); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1172 // wr_reg(0x44, 0 | (x2<<8)); /* Horizontal GRAM End Address */
wim 0:a8090b59eb05 1173
wim 0:a8090b59eb05 1174 //Note x,y flipped
wim 0:a8090b59eb05 1175 wr_reg(0x44, ((y2 & 0xFF) <<8) | (y1 & 0xFF)); /* Horizontal GRAM End Address | Start Address */
wim 0:a8090b59eb05 1176 wr_reg(0x45, x1); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1177 wr_reg(0x46, x2); /* Vertical GRAM End Address */
wim 0:a8090b59eb05 1178
wim 0:a8090b59eb05 1179 wr_reg(0x4e, y1); // Init x,y to start of window
wim 0:a8090b59eb05 1180 wr_reg(0x4f, x1);
wim 0:a8090b59eb05 1181 }
wim 0:a8090b59eb05 1182 else
wim 0:a8090b59eb05 1183 {
wim 0:a8090b59eb05 1184 wr_reg(0x50, x1); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1185 wr_reg(0x51, x2); /* Horizontal GRAM End Address */
wim 0:a8090b59eb05 1186 wr_reg(0x52, y1); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1187 wr_reg(0x53, y2); /* Vertical GRAM End Address */
wim 0:a8090b59eb05 1188 }
wim 0:a8090b59eb05 1189 }
wim 0:a8090b59eb05 1190
wim 0:a8090b59eb05 1191 /*******************************************************************************
wim 0:a8090b59eb05 1192 * Draw a pixel in foreground color *
wim 0:a8090b59eb05 1193 * Parameter: x: horizontal position *
wim 0:a8090b59eb05 1194 * y: vertical position *
wim 0:a8090b59eb05 1195 * Return: *
wim 0:a8090b59eb05 1196 *******************************************************************************/
wim 0:a8090b59eb05 1197
wim 0:a8090b59eb05 1198 void GLCD_PutPixel (unsigned int x, unsigned int y) {
wim 0:a8090b59eb05 1199 // Set Cursor
wim 0:a8090b59eb05 1200 if(driverCode==0x8989)
wim 0:a8090b59eb05 1201 {
wim 0:a8090b59eb05 1202 wr_reg(0x4e, y);
wim 0:a8090b59eb05 1203 wr_reg(0x4f, WIDTH-1-x);
wim 0:a8090b59eb05 1204 }
wim 0:a8090b59eb05 1205 else
wim 0:a8090b59eb05 1206 {
wim 0:a8090b59eb05 1207 wr_reg(0x20, y);
wim 0:a8090b59eb05 1208 wr_reg(0x21, WIDTH-1-x);
wim 0:a8090b59eb05 1209 }
wim 0:a8090b59eb05 1210 LCD_CS(0)
wim 0:a8090b59eb05 1211 wr_cmd(0x22);
wim 0:a8090b59eb05 1212 wr_dat(TextColor);
wim 0:a8090b59eb05 1213 LCD_CS(1)
wim 0:a8090b59eb05 1214 }
wim 0:a8090b59eb05 1215
wim 0:a8090b59eb05 1216
wim 0:a8090b59eb05 1217 /*******************************************************************************
wim 0:a8090b59eb05 1218 * Set foreground color *
wim 0:a8090b59eb05 1219 * Parameter: color: foreground color *
wim 0:a8090b59eb05 1220 * Return: *
wim 0:a8090b59eb05 1221 *******************************************************************************/
wim 0:a8090b59eb05 1222
wim 0:a8090b59eb05 1223 void GLCD_SetTextColor (unsigned short color) {
wim 0:a8090b59eb05 1224
wim 0:a8090b59eb05 1225 TextColor = color;
wim 0:a8090b59eb05 1226 }
wim 0:a8090b59eb05 1227
wim 0:a8090b59eb05 1228
wim 0:a8090b59eb05 1229 /*******************************************************************************
wim 0:a8090b59eb05 1230 * Set background color *
wim 0:a8090b59eb05 1231 * Parameter: color: background color *
wim 0:a8090b59eb05 1232 * Return: *
wim 0:a8090b59eb05 1233 *******************************************************************************/
wim 0:a8090b59eb05 1234
wim 0:a8090b59eb05 1235 void GLCD_SetBackColor (unsigned short color) {
wim 0:a8090b59eb05 1236
wim 0:a8090b59eb05 1237 BackColor = color;
wim 0:a8090b59eb05 1238 }
wim 0:a8090b59eb05 1239
wim 0:a8090b59eb05 1240
wim 0:a8090b59eb05 1241 /*******************************************************************************
wim 0:a8090b59eb05 1242 * Clear display *
wim 0:a8090b59eb05 1243 * Parameter: color: display clearing color *
wim 0:a8090b59eb05 1244 * Return: *
wim 0:a8090b59eb05 1245 *******************************************************************************/
wim 0:a8090b59eb05 1246
wim 0:a8090b59eb05 1247 void GLCD_Clear (unsigned short color) {
wim 0:a8090b59eb05 1248 unsigned int i;
wim 0:a8090b59eb05 1249
wim 0:a8090b59eb05 1250 GLCD_WindowMax();
wim 0:a8090b59eb05 1251
wim 0:a8090b59eb05 1252 // Set Cursor
wim 0:a8090b59eb05 1253 if(driverCode==0x8989)
wim 0:a8090b59eb05 1254 {
wim 0:a8090b59eb05 1255 wr_reg(0x4e, 0);
wim 0:a8090b59eb05 1256 wr_reg(0x4f, 0);
wim 0:a8090b59eb05 1257 }
wim 0:a8090b59eb05 1258 else
wim 0:a8090b59eb05 1259 {
wim 0:a8090b59eb05 1260 wr_reg(0x20, 0);
wim 0:a8090b59eb05 1261 wr_reg(0x21, 0);
wim 0:a8090b59eb05 1262 }
wim 0:a8090b59eb05 1263 LCD_CS(0)
wim 0:a8090b59eb05 1264 wr_cmd(0x22);
wim 0:a8090b59eb05 1265 wr_dat_start();
wim 0:a8090b59eb05 1266 for(i = 0; i < (WIDTH*HEIGHT); i++)
wim 0:a8090b59eb05 1267 wr_dat_only(color);
wim 0:a8090b59eb05 1268 wr_dat_stop();
wim 0:a8090b59eb05 1269 }
wim 0:a8090b59eb05 1270
wim 0:a8090b59eb05 1271
wim 0:a8090b59eb05 1272 /*******************************************************************************
wim 0:a8090b59eb05 1273 * Draw character on given position *
wim 0:a8090b59eb05 1274 * Parameter: x: horizontal position *
wim 0:a8090b59eb05 1275 * y: vertical position *
wim 0:a8090b59eb05 1276 * c: pointer to character bitmap *
wim 0:a8090b59eb05 1277 * Return: *
wim 0:a8090b59eb05 1278 *******************************************************************************/
wim 0:a8090b59eb05 1279
wim 0:a8090b59eb05 1280 void GLCD_DrawChar (unsigned int x, unsigned int y, unsigned short *c) {
wim 0:a8090b59eb05 1281 int idx = 0, i, j;
wim 0:a8090b59eb05 1282
wim 0:a8090b59eb05 1283 x = WIDTH-x-CHAR_W;
wim 0:a8090b59eb05 1284
wim 0:a8090b59eb05 1285 if(driverCode==0x8989)
wim 0:a8090b59eb05 1286 {
wim 0:a8090b59eb05 1287 wr_reg(0x44, y); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1288 wr_reg(0x44, y |((y+CHAR_H-1)<<8)); /* Horizontal GRAM End Address (-1) */
wim 0:a8090b59eb05 1289 wr_reg(0x45, x); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1290 wr_reg(0x46, x+CHAR_W-1); /* Vertical GRAM End Address (-1) */
wim 0:a8090b59eb05 1291
wim 0:a8090b59eb05 1292 wr_reg(0x4e, y);
wim 0:a8090b59eb05 1293 wr_reg(0x4f, x);
wim 0:a8090b59eb05 1294 }
wim 0:a8090b59eb05 1295 else
wim 0:a8090b59eb05 1296 {
wim 0:a8090b59eb05 1297 wr_reg(0x50, y); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1298 wr_reg(0x51, y+CHAR_H-1); /* Horizontal GRAM End Address (-1) */
wim 0:a8090b59eb05 1299 wr_reg(0x52, x); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1300 wr_reg(0x53, x+CHAR_W-1); /* Vertical GRAM End Address (-1) */
wim 0:a8090b59eb05 1301
wim 0:a8090b59eb05 1302 wr_reg(0x20, y);
wim 0:a8090b59eb05 1303 wr_reg(0x21, x);
wim 0:a8090b59eb05 1304 }
wim 0:a8090b59eb05 1305 LCD_CS(0)
wim 0:a8090b59eb05 1306 wr_cmd(0x22);
wim 0:a8090b59eb05 1307 wr_dat_start();
wim 0:a8090b59eb05 1308 for (j = 0; j < CHAR_H; j++) {
wim 0:a8090b59eb05 1309 for (i = CHAR_W-1; i >= 0; i--) {
wim 0:a8090b59eb05 1310 if((c[idx] & (1 << i)) == 0x00) {
wim 0:a8090b59eb05 1311 wr_dat_only(BackColor);
wim 0:a8090b59eb05 1312 } else {
wim 0:a8090b59eb05 1313 wr_dat_only(TextColor);
wim 0:a8090b59eb05 1314 }
wim 0:a8090b59eb05 1315 }
wim 0:a8090b59eb05 1316 c++;
wim 0:a8090b59eb05 1317 }
wim 0:a8090b59eb05 1318 wr_dat_stop();
wim 0:a8090b59eb05 1319 }
wim 0:a8090b59eb05 1320
wim 0:a8090b59eb05 1321
wim 0:a8090b59eb05 1322 /*******************************************************************************
wim 0:a8090b59eb05 1323 * Display character on given line *
wim 0:a8090b59eb05 1324 * Parameter: ln: line number *
wim 0:a8090b59eb05 1325 * col: column number *
wim 0:a8090b59eb05 1326 * c: ascii character *
wim 0:a8090b59eb05 1327 * Return: *
wim 0:a8090b59eb05 1328 *******************************************************************************/
wim 0:a8090b59eb05 1329
wim 0:a8090b59eb05 1330 void GLCD_DisplayChar (unsigned int ln, unsigned int col, unsigned char c) {
wim 0:a8090b59eb05 1331
wim 0:a8090b59eb05 1332 c -= 32;
wim 0:a8090b59eb05 1333 GLCD_DrawChar(col * CHAR_W, ln * CHAR_H, (unsigned short *)&Font_24x16[c * CHAR_H]);
wim 0:a8090b59eb05 1334 }
wim 0:a8090b59eb05 1335
wim 0:a8090b59eb05 1336
wim 0:a8090b59eb05 1337 /*******************************************************************************
wim 0:a8090b59eb05 1338 * Disply string on given line *
wim 0:a8090b59eb05 1339 * Parameter: ln: line number *
wim 0:a8090b59eb05 1340 * col: column number *
wim 0:a8090b59eb05 1341 * s: pointer to string *
wim 0:a8090b59eb05 1342 * Return: *
wim 0:a8090b59eb05 1343 *******************************************************************************/
wim 0:a8090b59eb05 1344
wim 0:a8090b59eb05 1345 void GLCD_DisplayString (unsigned int ln, unsigned int col, unsigned char *s) {
wim 0:a8090b59eb05 1346
wim 0:a8090b59eb05 1347 GLCD_WindowMax();
wim 0:a8090b59eb05 1348 while (*s) {
wim 0:a8090b59eb05 1349 GLCD_DisplayChar(ln, col++, *s++);
wim 0:a8090b59eb05 1350 }
wim 0:a8090b59eb05 1351 }
wim 0:a8090b59eb05 1352
wim 0:a8090b59eb05 1353
wim 0:a8090b59eb05 1354 /*******************************************************************************
wim 0:a8090b59eb05 1355 * Clear given line *
wim 0:a8090b59eb05 1356 * Parameter: ln: line number *
wim 0:a8090b59eb05 1357 * Return: *
wim 0:a8090b59eb05 1358 *******************************************************************************/
wim 0:a8090b59eb05 1359
wim 0:a8090b59eb05 1360 void GLCD_ClearLn (unsigned int ln) {
wim 0:a8090b59eb05 1361
wim 0:a8090b59eb05 1362 GLCD_WindowMax();
wim 0:a8090b59eb05 1363 GLCD_DisplayString(ln, 0, (unsigned char*) " ");
wim 0:a8090b59eb05 1364 }
wim 0:a8090b59eb05 1365
wim 0:a8090b59eb05 1366 //SSD1289
wim 0:a8090b59eb05 1367 //static void lcd_SetCursor(unsigned int x,unsigned int y)
wim 0:a8090b59eb05 1368 //{
wim 0:a8090b59eb05 1369 // write_reg(0x004e,x); /* 0-239 */
wim 0:a8090b59eb05 1370 // write_reg(0x004f,y); /* 0-319 */
wim 0:a8090b59eb05 1371 //}
wim 0:a8090b59eb05 1372
wim 0:a8090b59eb05 1373
wim 0:a8090b59eb05 1374 void GLCD_drawHLine(int x, int y, int l)
wim 0:a8090b59eb05 1375 {
wim 0:a8090b59eb05 1376 // char ch, cl;
wim 0:a8090b59eb05 1377
wim 0:a8090b59eb05 1378 // ch=((fcolorr&248)|fcolorg>>5);
wim 0:a8090b59eb05 1379 // cl=((fcolorg&28)<<3|fcolorb>>3);
wim 0:a8090b59eb05 1380
wim 0:a8090b59eb05 1381 // cbi(P_CS, B_CS);
wim 0:a8090b59eb05 1382
wim 0:a8090b59eb05 1383 GLCD_Window (x, y, x+l, y);
wim 0:a8090b59eb05 1384
wim 0:a8090b59eb05 1385 // for (int i=0; i<l+1; i++)
wim 0:a8090b59eb05 1386 // {
wim 0:a8090b59eb05 1387 // LCD_Write_DATA(ch, cl);
wim 0:a8090b59eb05 1388 // }
wim 0:a8090b59eb05 1389
wim 0:a8090b59eb05 1390 LCD_CS(0)
wim 0:a8090b59eb05 1391 wr_cmd(0x22);
wim 0:a8090b59eb05 1392
wim 0:a8090b59eb05 1393 wr_dat_start();
wim 0:a8090b59eb05 1394 for (int i=0; i<l; i++)
wim 0:a8090b59eb05 1395 wr_dat_only(TextColor);
wim 0:a8090b59eb05 1396 wr_dat_stop();
wim 0:a8090b59eb05 1397
wim 0:a8090b59eb05 1398 // sbi(P_CS, B_CS);
wim 0:a8090b59eb05 1399 // clrXY();
wim 0:a8090b59eb05 1400 GLCD_WindowMax();
wim 0:a8090b59eb05 1401 }
wim 0:a8090b59eb05 1402
wim 0:a8090b59eb05 1403 void GLCD_drawVLine(int x, int y, int l)
wim 0:a8090b59eb05 1404 {
wim 0:a8090b59eb05 1405 // char ch, cl;
wim 0:a8090b59eb05 1406
wim 0:a8090b59eb05 1407 // ch=((fcolorr&248)|fcolorg>>5);
wim 0:a8090b59eb05 1408 // cl=((fcolorg&28)<<3|fcolorb>>3);
wim 0:a8090b59eb05 1409
wim 0:a8090b59eb05 1410 // cbi(P_CS, B_CS);
wim 0:a8090b59eb05 1411 GLCD_Window(x, y, x, y+l);
wim 0:a8090b59eb05 1412 // for (int i=0; i<l; i++)
wim 0:a8090b59eb05 1413 // {
wim 0:a8090b59eb05 1414 // GLCD_wr_dat(ch, cl);
wim 0:a8090b59eb05 1415 // }
wim 0:a8090b59eb05 1416 LCD_CS(0)
wim 0:a8090b59eb05 1417 wr_cmd(0x22);
wim 0:a8090b59eb05 1418
wim 0:a8090b59eb05 1419 wr_dat_start();
wim 0:a8090b59eb05 1420 for (int i=0; i<l; i++)
wim 0:a8090b59eb05 1421 wr_dat_only(TextColor);
wim 0:a8090b59eb05 1422 wr_dat_stop();
wim 0:a8090b59eb05 1423
wim 0:a8090b59eb05 1424
wim 0:a8090b59eb05 1425 // sbi(P_CS, B_CS);
wim 0:a8090b59eb05 1426 // clrXY();
wim 0:a8090b59eb05 1427 GLCD_WindowMax();
wim 0:a8090b59eb05 1428 }
wim 0:a8090b59eb05 1429
wim 0:a8090b59eb05 1430
wim 0:a8090b59eb05 1431 void GLCD_drawRect(int x1, int y1, int x2, int y2)
wim 0:a8090b59eb05 1432 {
wim 0:a8090b59eb05 1433 int tmp;
wim 0:a8090b59eb05 1434
wim 0:a8090b59eb05 1435 if (x1>x2)
wim 0:a8090b59eb05 1436 {
wim 0:a8090b59eb05 1437 swap(int, x1, x2);
wim 0:a8090b59eb05 1438 }
wim 0:a8090b59eb05 1439 if (y1>y2)
wim 0:a8090b59eb05 1440 {
wim 0:a8090b59eb05 1441 swap(int, y1, y2);
wim 0:a8090b59eb05 1442 }
wim 0:a8090b59eb05 1443
wim 0:a8090b59eb05 1444 GLCD_drawHLine(x1, y1, x2-x1);
wim 0:a8090b59eb05 1445 GLCD_drawHLine(x1, y2, x2-x1);
wim 0:a8090b59eb05 1446 GLCD_drawVLine(x1, y1, y2-y1);
wim 0:a8090b59eb05 1447 GLCD_drawVLine(x2, y1, y2-y1);
wim 0:a8090b59eb05 1448 }
wim 0:a8090b59eb05 1449
wim 0:a8090b59eb05 1450
wim 0:a8090b59eb05 1451
wim 0:a8090b59eb05 1452
wim 0:a8090b59eb05 1453 /*******************************************************************************
wim 0:a8090b59eb05 1454 * Draw bargraph *
wim 0:a8090b59eb05 1455 * Parameter: x: horizontal position *
wim 0:a8090b59eb05 1456 * y: vertical position *
wim 0:a8090b59eb05 1457 * w: maximum width of bargraph (in pixels) *
wim 0:a8090b59eb05 1458 * val: value of active bargraph (in 1/1024) *
wim 0:a8090b59eb05 1459 * Return: *
wim 0:a8090b59eb05 1460 *******************************************************************************/
wim 0:a8090b59eb05 1461
wim 0:a8090b59eb05 1462 void GLCD_Bargraph (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val) {
wim 0:a8090b59eb05 1463 int i,j;
wim 0:a8090b59eb05 1464
wim 0:a8090b59eb05 1465 x = WIDTH-x-w;
wim 0:a8090b59eb05 1466 if(driverCode==0x8989)
wim 0:a8090b59eb05 1467 {
wim 0:a8090b59eb05 1468 wr_reg(0x44, y); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1469 wr_reg(0x44, y |((y+CHAR_H-1)<<8)); /* Horizontal GRAM End Address (-1) */
wim 0:a8090b59eb05 1470 wr_reg(0x45, x); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1471 wr_reg(0x46, x+w-1); /* Vertical GRAM End Address (-1) */
wim 0:a8090b59eb05 1472 }
wim 0:a8090b59eb05 1473 else
wim 0:a8090b59eb05 1474 {
wim 0:a8090b59eb05 1475 wr_reg(0x50, y); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1476 wr_reg(0x51, y+CHAR_H-1); /* Horizontal GRAM End Address (-1) */
wim 0:a8090b59eb05 1477 wr_reg(0x52, x); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1478 wr_reg(0x53, x+w-1); /* Vertical GRAM End Address (-1) */
wim 0:a8090b59eb05 1479 }
wim 0:a8090b59eb05 1480
wim 0:a8090b59eb05 1481 val = (val * w) >> 10; /* Scale value for 24x12 characters */
wim 0:a8090b59eb05 1482 if(driverCode==0x8989)
wim 0:a8090b59eb05 1483 {
wim 0:a8090b59eb05 1484 wr_reg(0x4e, y);
wim 0:a8090b59eb05 1485 wr_reg(0x4f, x);
wim 0:a8090b59eb05 1486 }
wim 0:a8090b59eb05 1487 else
wim 0:a8090b59eb05 1488 {
wim 0:a8090b59eb05 1489 wr_reg(0x20, y);
wim 0:a8090b59eb05 1490 wr_reg(0x21, x);
wim 0:a8090b59eb05 1491 }
wim 0:a8090b59eb05 1492 LCD_CS(0)
wim 0:a8090b59eb05 1493 wr_cmd(0x22);
wim 0:a8090b59eb05 1494 wr_dat_start();
wim 0:a8090b59eb05 1495 for (i = 0; i < h; i++) {
wim 0:a8090b59eb05 1496 for (j = w-1; j >= 0; j--) {
wim 0:a8090b59eb05 1497 if(j >= val) {
wim 0:a8090b59eb05 1498 wr_dat_only(BackColor);
wim 0:a8090b59eb05 1499 } else {
wim 0:a8090b59eb05 1500 wr_dat_only(TextColor);
wim 0:a8090b59eb05 1501 }
wim 0:a8090b59eb05 1502 }
wim 0:a8090b59eb05 1503 }
wim 0:a8090b59eb05 1504 wr_dat_stop();
wim 0:a8090b59eb05 1505 }
wim 0:a8090b59eb05 1506
wim 0:a8090b59eb05 1507
wim 0:a8090b59eb05 1508 /*******************************************************************************
wim 0:a8090b59eb05 1509 * Display graphical bitmap image at position x horizontally and y vertically *
wim 0:a8090b59eb05 1510 * (This function is optimized for 16 bits per pixel format, it has to be *
wim 0:a8090b59eb05 1511 * adapted for any other bits per pixel format) *
wim 0:a8090b59eb05 1512 * Parameter: x: horizontal position *
wim 0:a8090b59eb05 1513 * y: vertical position *
wim 0:a8090b59eb05 1514 * w: width of bitmap *
wim 0:a8090b59eb05 1515 * h: height of bitmap *
wim 0:a8090b59eb05 1516 * bitmap: address at which the bitmap data resides *
wim 0:a8090b59eb05 1517 * Return: *
wim 0:a8090b59eb05 1518 *******************************************************************************/
wim 0:a8090b59eb05 1519
wim 0:a8090b59eb05 1520 void GLCD_Bitmap (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap) {
wim 0:a8090b59eb05 1521 unsigned int i, j;
wim 0:a8090b59eb05 1522 unsigned short *bitmap_ptr = (unsigned short *)bitmap;
wim 0:a8090b59eb05 1523
wim 0:a8090b59eb05 1524 x = WIDTH-x-w;
wim 0:a8090b59eb05 1525 if(driverCode==0x8989)
wim 0:a8090b59eb05 1526 {
wim 0:a8090b59eb05 1527 wr_reg(0x44, y); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1528 wr_reg(0x44, y |((y+h-1)<<8)); /* Horizontal GRAM End Address (-1) */
wim 0:a8090b59eb05 1529 wr_reg(0x45, x); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1530 wr_reg(0x46, x+w-1); /* Vertical GRAM End Address (-1) */
wim 0:a8090b59eb05 1531 wr_reg(0x4e, y);
wim 0:a8090b59eb05 1532 wr_reg(0x4f, x);
wim 0:a8090b59eb05 1533 }
wim 0:a8090b59eb05 1534 else
wim 0:a8090b59eb05 1535 {
wim 0:a8090b59eb05 1536 wr_reg(0x50, y); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1537 wr_reg(0x51, y+h-1); /* Horizontal GRAM End Address (-1) */
wim 0:a8090b59eb05 1538 wr_reg(0x52, x); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1539 wr_reg(0x53, x+w-1); /* Vertical GRAM End Address (-1) */
wim 0:a8090b59eb05 1540 wr_reg(0x20, y);
wim 0:a8090b59eb05 1541 wr_reg(0x21, x);
wim 0:a8090b59eb05 1542 }
wim 0:a8090b59eb05 1543 LCD_CS(0)
wim 0:a8090b59eb05 1544 wr_cmd(0x22);
wim 0:a8090b59eb05 1545 wr_dat_start();
wim 0:a8090b59eb05 1546 for (j = 0; j < h; j++) {
wim 0:a8090b59eb05 1547 bitmap_ptr += w-1;
wim 0:a8090b59eb05 1548 for (i = 0; i < w; i++) {
wim 0:a8090b59eb05 1549 wr_dat_only(*bitmap_ptr--);
wim 0:a8090b59eb05 1550 }
wim 0:a8090b59eb05 1551 bitmap_ptr += w+1;
wim 0:a8090b59eb05 1552 }
wim 0:a8090b59eb05 1553 wr_dat_stop();
wim 0:a8090b59eb05 1554 }
wim 0:a8090b59eb05 1555
wim 0:a8090b59eb05 1556
wim 0:a8090b59eb05 1557 /*******************************************************************************
wim 0:a8090b59eb05 1558 * Display graphical bmp file image at position x horizontally and y vertically *
wim 0:a8090b59eb05 1559 * (This function is optimized for 16 bits per pixel format, it has to be *
wim 0:a8090b59eb05 1560 * adapted for any other bits per pixel format) *
wim 0:a8090b59eb05 1561 * Parameter: x: horizontal position *
wim 0:a8090b59eb05 1562 * y: vertical position *
wim 0:a8090b59eb05 1563 * w: width of bitmap *
wim 0:a8090b59eb05 1564 * h: height of bitmap *
wim 0:a8090b59eb05 1565 * bmp: address at which the bmp data resides *
wim 0:a8090b59eb05 1566 * Return: *
wim 0:a8090b59eb05 1567 *******************************************************************************/
wim 0:a8090b59eb05 1568
wim 0:a8090b59eb05 1569 void GLCD_Bmp (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bmp) {
wim 0:a8090b59eb05 1570 unsigned int i, j;
wim 0:a8090b59eb05 1571 unsigned short *bitmap_ptr = (unsigned short *)bmp;
wim 0:a8090b59eb05 1572
wim 0:a8090b59eb05 1573 x = WIDTH-x-w;
wim 0:a8090b59eb05 1574
wim 0:a8090b59eb05 1575 if(driverCode==0x8989)
wim 0:a8090b59eb05 1576 {
wim 0:a8090b59eb05 1577 wr_reg(0x44, y); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1578 wr_reg(0x44, y |((y+h-1)<<8)); /* Horizontal GRAM End Address (-1) */
wim 0:a8090b59eb05 1579 wr_reg(0x45, x); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1580 wr_reg(0x46, x+w-1); /* Vertical GRAM End Address (-1) */
wim 0:a8090b59eb05 1581 wr_reg(0x4e, y);
wim 0:a8090b59eb05 1582 wr_reg(0x4f, x);
wim 0:a8090b59eb05 1583 }
wim 0:a8090b59eb05 1584 else
wim 0:a8090b59eb05 1585 {
wim 0:a8090b59eb05 1586 wr_reg(0x50, y); /* Horizontal GRAM Start Address */
wim 0:a8090b59eb05 1587 wr_reg(0x51, y+h-1); /* Horizontal GRAM End Address (-1) */
wim 0:a8090b59eb05 1588 wr_reg(0x52, x); /* Vertical GRAM Start Address */
wim 0:a8090b59eb05 1589 wr_reg(0x53, x+w-1); /* Vertical GRAM End Address (-1) */
wim 0:a8090b59eb05 1590 wr_reg(0x20, y);
wim 0:a8090b59eb05 1591 wr_reg(0x21, x);
wim 0:a8090b59eb05 1592 }
wim 0:a8090b59eb05 1593 LCD_CS(0)
wim 0:a8090b59eb05 1594 wr_cmd(0x22);
wim 0:a8090b59eb05 1595 wr_dat_start();
wim 0:a8090b59eb05 1596 bitmap_ptr += (h*w)-1;
wim 0:a8090b59eb05 1597 for (j = 0; j < h; j++) {
wim 0:a8090b59eb05 1598 for (i = 0; i < w; i++) {
wim 0:a8090b59eb05 1599 wr_dat_only(*bitmap_ptr--);
wim 0:a8090b59eb05 1600 }
wim 0:a8090b59eb05 1601 }
wim 0:a8090b59eb05 1602 wr_dat_stop();
wim 0:a8090b59eb05 1603 }
wim 0:a8090b59eb05 1604
wim 0:a8090b59eb05 1605 /******************************************************************************/