Behrooz Abdi
/
Tiger_LCD
Landtiger (LPC1768) graphics LCD demo.
GLCD_LPC1700.cpp@3:2dccfa0121de, 2015-10-30 (annotated)
- Committer:
- wim
- Date:
- Fri Oct 30 01:26:40 2015 +0000
- Revision:
- 3:2dccfa0121de
- Parent:
- 2:43ede88fb5a3
- Child:
- 4:cdeea87f25d8
Landtiger LCD demo (Mandelbrot). Code snippets merged from several sources.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:a8090b59eb05 | 1 | /******************************************************************************/ |
wim | 3:2dccfa0121de | 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 | 2:43ede88fb5a3 | 14 | #include "GLCD_Config.h" |
wim | 0:a8090b59eb05 | 15 | #include "Font_24x16.h" |
wim | 0:a8090b59eb05 | 16 | |
wim | 0:a8090b59eb05 | 17 | /*********************** Hardware specific configuration **********************/ |
wim | 0:a8090b59eb05 | 18 | |
wim | 0:a8090b59eb05 | 19 | /* LandTiger 8bit to 16bit LCD Interface |
wim | 0:a8090b59eb05 | 20 | |
wim | 0:a8090b59eb05 | 21 | PINS: |
wim | 0:a8090b59eb05 | 22 | - EN = P0.19 |
wim | 0:a8090b59eb05 | 23 | - LE = P0.20 |
wim | 0:a8090b59eb05 | 24 | - DIR = P0.21 |
wim | 0:a8090b59eb05 | 25 | - CS = P0.22 |
wim | 0:a8090b59eb05 | 26 | - RS = P0.23 |
wim | 0:a8090b59eb05 | 27 | - WR = P0.24 |
wim | 0:a8090b59eb05 | 28 | - RD = P0.25 |
wim | 0:a8090b59eb05 | 29 | - DB[0.7] = P2.0...P2.7 |
wim | 0:a8090b59eb05 | 30 | - DB[8.15]= P2.0...P2.7 */ |
wim | 0:a8090b59eb05 | 31 | |
wim | 0:a8090b59eb05 | 32 | #define PIN_EN (1 << 19) |
wim | 0:a8090b59eb05 | 33 | #define PIN_LE (1 << 20) |
wim | 0:a8090b59eb05 | 34 | #define PIN_DIR (1 << 21) |
wim | 0:a8090b59eb05 | 35 | #define PIN_CS (1 << 22) |
wim | 0:a8090b59eb05 | 36 | #define PIN_RS (1 << 23) |
wim | 0:a8090b59eb05 | 37 | #define PIN_WR (1 << 24) |
wim | 0:a8090b59eb05 | 38 | #define PIN_RD (1 << 25) |
wim | 0:a8090b59eb05 | 39 | |
wim | 0:a8090b59eb05 | 40 | /*------------------------- Speed dependant settings -------------------------*/ |
wim | 0:a8090b59eb05 | 41 | |
wim | 0:a8090b59eb05 | 42 | /* If processor works on high frequency delay has to be increased, it can be |
wim | 0:a8090b59eb05 | 43 | increased by factor 2^N by this constant */ |
wim | 0:a8090b59eb05 | 44 | #define DELAY_2N 18 |
wim | 0:a8090b59eb05 | 45 | |
wim | 0:a8090b59eb05 | 46 | /*---------------------- Graphic LCD size definitions ------------------------*/ |
wim | 0:a8090b59eb05 | 47 | |
wim | 0:a8090b59eb05 | 48 | #define WIDTH 320 /* Screen Width (in pixels) */ |
wim | 0:a8090b59eb05 | 49 | #define HEIGHT 240 /* Screen Hight (in pixels) */ |
wim | 0:a8090b59eb05 | 50 | #define BPP 16 /* Bits per pixel */ |
wim | 0:a8090b59eb05 | 51 | #define BYPP ((BPP+7)/8) /* Bytes per pixel */ |
wim | 0:a8090b59eb05 | 52 | |
wim | 0:a8090b59eb05 | 53 | /*--------------- Graphic LCD interface hardware definitions -----------------*/ |
wim | 0:a8090b59eb05 | 54 | |
wim | 0:a8090b59eb05 | 55 | /* Pin EN setting to 0 or 1 */ |
wim | 0:a8090b59eb05 | 56 | #define LCD_EN(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_EN) : (LPC_GPIO0->FIOCLR = PIN_EN)); |
wim | 0:a8090b59eb05 | 57 | /* Pin LE setting to 0 or 1 */ |
wim | 0:a8090b59eb05 | 58 | #define LCD_LE(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_LE) : (LPC_GPIO0->FIOCLR = PIN_LE)); |
wim | 0:a8090b59eb05 | 59 | /* Pin DIR setting to 0 or 1 */ |
wim | 0:a8090b59eb05 | 60 | #define LCD_DIR(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_DIR) : (LPC_GPIO0->FIOCLR = PIN_DIR)); |
wim | 0:a8090b59eb05 | 61 | /* Pin CS setting to 0 or 1 */ |
wim | 0:a8090b59eb05 | 62 | #define LCD_CS(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_CS) : (LPC_GPIO0->FIOCLR = PIN_CS)); |
wim | 0:a8090b59eb05 | 63 | /* Pin RS setting to 0 or 1 */ |
wim | 0:a8090b59eb05 | 64 | #define LCD_RS(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_RS) : (LPC_GPIO0->FIOCLR = PIN_RS)); |
wim | 0:a8090b59eb05 | 65 | /* Pin WR setting to 0 or 1 */ |
wim | 0:a8090b59eb05 | 66 | #define LCD_WR(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_WR) : (LPC_GPIO0->FIOCLR = PIN_WR)); |
wim | 0:a8090b59eb05 | 67 | /* Pin RD setting to 0 or 1 */ |
wim | 0:a8090b59eb05 | 68 | #define LCD_RD(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_RD) : (LPC_GPIO0->FIOCLR = PIN_RD)); |
wim | 0:a8090b59eb05 | 69 | |
wim | 0:a8090b59eb05 | 70 | |
wim | 0:a8090b59eb05 | 71 | /************************ Local auxiliary functions ***************************/ |
wim | 0:a8090b59eb05 | 72 | |
wim | 3:2dccfa0121de | 73 | #define MAX_POLY_CORNERS 200 |
wim | 3:2dccfa0121de | 74 | #define POLY_Y(Z) ((int32_t)((Points + Z)->X)) |
wim | 3:2dccfa0121de | 75 | #define POLY_X(Z) ((int32_t)((Points + Z)->Y)) |
wim | 3:2dccfa0121de | 76 | #define ABS(X) ((X) > 0 ? (X) : -(X)) |
wim | 3:2dccfa0121de | 77 | |
wim | 2:43ede88fb5a3 | 78 | #define swap(type, i, j) {type t = i; i = j; j = t;} |
wim | 2:43ede88fb5a3 | 79 | |
wim | 2:43ede88fb5a3 | 80 | // rrrrrggggggbbbbb |
wim | 2:43ede88fb5a3 | 81 | #define RGB24toRGB16(r,g,b) ((r & 0xF8)<<8) | ((g & 0xFC)<<3) | ((b & 0xF8)>>3) |
wim | 2:43ede88fb5a3 | 82 | |
wim | 2:43ede88fb5a3 | 83 | |
wim | 0:a8090b59eb05 | 84 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 85 | * Delay in while loop cycles * |
wim | 0:a8090b59eb05 | 86 | * Parameter: cnt: number of while cycles to delay * |
wim | 0:a8090b59eb05 | 87 | * Return: * |
wim | 0:a8090b59eb05 | 88 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 89 | |
wim | 2:43ede88fb5a3 | 90 | static __inline void delay (int cnt) { |
wim | 0:a8090b59eb05 | 91 | |
wim | 0:a8090b59eb05 | 92 | cnt <<= DELAY_2N; |
wim | 0:a8090b59eb05 | 93 | while (cnt--); |
wim | 0:a8090b59eb05 | 94 | } |
wim | 0:a8090b59eb05 | 95 | |
wim | 2:43ede88fb5a3 | 96 | static __inline __asm void wait() |
wim | 0:a8090b59eb05 | 97 | { |
wim | 0:a8090b59eb05 | 98 | nop |
wim | 0:a8090b59eb05 | 99 | BX lr |
wim | 0:a8090b59eb05 | 100 | } |
wim | 0:a8090b59eb05 | 101 | |
wim | 2:43ede88fb5a3 | 102 | static __inline void wait_delay(int count) |
wim | 0:a8090b59eb05 | 103 | { |
wim | 0:a8090b59eb05 | 104 | while(count--); |
wim | 0:a8090b59eb05 | 105 | } |
wim | 0:a8090b59eb05 | 106 | |
wim | 2:43ede88fb5a3 | 107 | |
wim | 2:43ede88fb5a3 | 108 | GLCD::GLCD() { |
wim | 3:2dccfa0121de | 109 | init(); |
wim | 2:43ede88fb5a3 | 110 | } |
wim | 2:43ede88fb5a3 | 111 | |
wim | 2:43ede88fb5a3 | 112 | |
wim | 0:a8090b59eb05 | 113 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 114 | * Send 1 short to LCD * |
wim | 0:a8090b59eb05 | 115 | * Parameter: data: data to be sent * |
wim | 0:a8090b59eb05 | 116 | * Return: * |
wim | 0:a8090b59eb05 | 117 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 118 | |
wim | 3:2dccfa0121de | 119 | uint8_t GLCD::_lcd_send (uint16_t data) { |
wim | 0:a8090b59eb05 | 120 | |
wim | 0:a8090b59eb05 | 121 | LPC_GPIO2->FIODIR |= 0x000000ff; //P2.0...P2.7 Output |
wim | 0:a8090b59eb05 | 122 | LCD_DIR(1) //Interface A->B |
wim | 0:a8090b59eb05 | 123 | LCD_EN(0) //Enable 2A->2B |
wim | 0:a8090b59eb05 | 124 | LPC_GPIO2->FIOPIN = data; //Write D0..D7 |
wim | 0:a8090b59eb05 | 125 | LCD_LE(1) |
wim | 0:a8090b59eb05 | 126 | LCD_LE(0) //latch D0..D7 |
wim | 0:a8090b59eb05 | 127 | LPC_GPIO2->FIOPIN = data >> 8; //Write D8..D15 |
wim | 0:a8090b59eb05 | 128 | return(1); |
wim | 0:a8090b59eb05 | 129 | } |
wim | 0:a8090b59eb05 | 130 | |
wim | 0:a8090b59eb05 | 131 | |
wim | 0:a8090b59eb05 | 132 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 133 | * read 1 short from LCD * |
wim | 0:a8090b59eb05 | 134 | * Parameter: * |
wim | 0:a8090b59eb05 | 135 | * Return: short data from LCD * |
wim | 0:a8090b59eb05 | 136 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 137 | |
wim | 3:2dccfa0121de | 138 | uint16_t GLCD::_lcd_read (void) { |
wim | 3:2dccfa0121de | 139 | uint16_t id; |
wim | 0:a8090b59eb05 | 140 | LPC_GPIO2->FIODIR &= 0xffffff00; //P2.0...P2.7 Input |
wim | 0:a8090b59eb05 | 141 | LCD_DIR(0) //Interface B->A |
wim | 0:a8090b59eb05 | 142 | LCD_EN(0) //Enable 2B->2A |
wim | 0:a8090b59eb05 | 143 | wait_delay(80); //delay some times |
wim | 0:a8090b59eb05 | 144 | id = LPC_GPIO2->FIOPIN & 0x00ff; //Read D8..D15 |
wim | 0:a8090b59eb05 | 145 | LCD_EN(1) //Enable 1B->1A |
wim | 0:a8090b59eb05 | 146 | wait_delay(80); //delay some times |
wim | 0:a8090b59eb05 | 147 | id = (id << 8) | (LPC_GPIO2->FIOPIN & 0x00ff); //Read D0..D7 |
wim | 0:a8090b59eb05 | 148 | LCD_DIR(1) |
wim | 0:a8090b59eb05 | 149 | return(id); |
wim | 0:a8090b59eb05 | 150 | } |
wim | 0:a8090b59eb05 | 151 | |
wim | 0:a8090b59eb05 | 152 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 153 | * Write command to LCD controller * |
wim | 0:a8090b59eb05 | 154 | * Parameter: c: command to be written * |
wim | 0:a8090b59eb05 | 155 | * Return: * |
wim | 0:a8090b59eb05 | 156 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 157 | |
wim | 3:2dccfa0121de | 158 | void GLCD::_wr_cmd (uint16_t c) { |
wim | 0:a8090b59eb05 | 159 | |
wim | 0:a8090b59eb05 | 160 | LCD_RS(0) |
wim | 0:a8090b59eb05 | 161 | LCD_RD(1) |
wim | 3:2dccfa0121de | 162 | _lcd_send(c); |
wim | 0:a8090b59eb05 | 163 | LCD_WR(0) |
wim | 0:a8090b59eb05 | 164 | wait(); |
wim | 0:a8090b59eb05 | 165 | LCD_WR(1) |
wim | 0:a8090b59eb05 | 166 | } |
wim | 0:a8090b59eb05 | 167 | |
wim | 0:a8090b59eb05 | 168 | |
wim | 0:a8090b59eb05 | 169 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 170 | * Write data to LCD controller * |
wim | 0:a8090b59eb05 | 171 | * Parameter: c: data to be written * |
wim | 0:a8090b59eb05 | 172 | * Return: * |
wim | 0:a8090b59eb05 | 173 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 174 | |
wim | 3:2dccfa0121de | 175 | void GLCD::_wr_dat (uint16_t c) { |
wim | 0:a8090b59eb05 | 176 | |
wim | 0:a8090b59eb05 | 177 | LCD_RS(1) |
wim | 0:a8090b59eb05 | 178 | LCD_RD(1) |
wim | 3:2dccfa0121de | 179 | _lcd_send(c); |
wim | 0:a8090b59eb05 | 180 | LCD_WR(0) |
wim | 0:a8090b59eb05 | 181 | wait(); |
wim | 0:a8090b59eb05 | 182 | LCD_WR(1) |
wim | 0:a8090b59eb05 | 183 | } |
wim | 0:a8090b59eb05 | 184 | |
wim | 0:a8090b59eb05 | 185 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 186 | * Read data from LCD controller * |
wim | 0:a8090b59eb05 | 187 | * Parameter: * |
wim | 0:a8090b59eb05 | 188 | * Return: read data * |
wim | 0:a8090b59eb05 | 189 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 190 | |
wim | 3:2dccfa0121de | 191 | uint16_t GLCD::_rd_dat (void) { |
wim | 3:2dccfa0121de | 192 | uint16_t val = 0; |
wim | 0:a8090b59eb05 | 193 | |
wim | 0:a8090b59eb05 | 194 | LCD_RS(1) |
wim | 0:a8090b59eb05 | 195 | LCD_WR(1) |
wim | 0:a8090b59eb05 | 196 | LCD_RD(0) |
wim | 3:2dccfa0121de | 197 | val = _lcd_read(); |
wim | 0:a8090b59eb05 | 198 | LCD_RD(1) |
wim | 0:a8090b59eb05 | 199 | return val; |
wim | 0:a8090b59eb05 | 200 | } |
wim | 0:a8090b59eb05 | 201 | |
wim | 0:a8090b59eb05 | 202 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 203 | * Start of data writing to LCD controller * |
wim | 0:a8090b59eb05 | 204 | * Parameter: * |
wim | 0:a8090b59eb05 | 205 | * Return: * |
wim | 0:a8090b59eb05 | 206 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 207 | |
wim | 3:2dccfa0121de | 208 | void GLCD::_wr_dat_start (void) { |
wim | 0:a8090b59eb05 | 209 | |
wim | 0:a8090b59eb05 | 210 | LCD_CS(0) |
wim | 0:a8090b59eb05 | 211 | LCD_RS(1) |
wim | 0:a8090b59eb05 | 212 | } |
wim | 0:a8090b59eb05 | 213 | |
wim | 0:a8090b59eb05 | 214 | |
wim | 0:a8090b59eb05 | 215 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 216 | * Stop of data writing to LCD controller * |
wim | 0:a8090b59eb05 | 217 | * Parameter: * |
wim | 0:a8090b59eb05 | 218 | * Return: * |
wim | 0:a8090b59eb05 | 219 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 220 | |
wim | 3:2dccfa0121de | 221 | void GLCD::_wr_dat_stop (void) { |
wim | 0:a8090b59eb05 | 222 | |
wim | 0:a8090b59eb05 | 223 | LCD_CS(1) |
wim | 0:a8090b59eb05 | 224 | } |
wim | 0:a8090b59eb05 | 225 | |
wim | 0:a8090b59eb05 | 226 | |
wim | 0:a8090b59eb05 | 227 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 228 | * Data writing to LCD controller * |
wim | 0:a8090b59eb05 | 229 | * Parameter: c: data to be written * |
wim | 0:a8090b59eb05 | 230 | * Return: * |
wim | 0:a8090b59eb05 | 231 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 232 | |
wim | 3:2dccfa0121de | 233 | void GLCD::_wr_dat_only (uint16_t c) { |
wim | 0:a8090b59eb05 | 234 | |
wim | 3:2dccfa0121de | 235 | _lcd_send(c); |
wim | 0:a8090b59eb05 | 236 | LCD_WR(0) |
wim | 0:a8090b59eb05 | 237 | wait(); |
wim | 0:a8090b59eb05 | 238 | LCD_WR(1) |
wim | 0:a8090b59eb05 | 239 | } |
wim | 0:a8090b59eb05 | 240 | |
wim | 0:a8090b59eb05 | 241 | |
wim | 0:a8090b59eb05 | 242 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 243 | * Write to LCD register * |
wim | 0:a8090b59eb05 | 244 | * Parameter: reg: register to be read * |
wim | 0:a8090b59eb05 | 245 | * val: value to write to register * |
wim | 0:a8090b59eb05 | 246 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 247 | |
wim | 3:2dccfa0121de | 248 | void GLCD::_wr_reg (uint16_t reg, uint16_t val) { |
wim | 0:a8090b59eb05 | 249 | |
wim | 0:a8090b59eb05 | 250 | LCD_CS(0) |
wim | 3:2dccfa0121de | 251 | _wr_cmd(reg); |
wim | 3:2dccfa0121de | 252 | _wr_dat(val); |
wim | 0:a8090b59eb05 | 253 | LCD_CS(1) |
wim | 0:a8090b59eb05 | 254 | } |
wim | 0:a8090b59eb05 | 255 | |
wim | 0:a8090b59eb05 | 256 | |
wim | 0:a8090b59eb05 | 257 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 258 | * Read from LCD register * |
wim | 0:a8090b59eb05 | 259 | * Parameter: reg: register to be read * |
wim | 0:a8090b59eb05 | 260 | * Return: value read from register * |
wim | 0:a8090b59eb05 | 261 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 262 | |
wim | 3:2dccfa0121de | 263 | uint16_t GLCD::_rd_reg (uint16_t reg) { |
wim | 3:2dccfa0121de | 264 | uint16_t val = 0; |
wim | 0:a8090b59eb05 | 265 | |
wim | 0:a8090b59eb05 | 266 | LCD_CS(0) |
wim | 3:2dccfa0121de | 267 | _wr_cmd(reg); |
wim | 3:2dccfa0121de | 268 | val = _rd_dat(); |
wim | 0:a8090b59eb05 | 269 | LCD_CS(1) |
wim | 0:a8090b59eb05 | 270 | return (val); |
wim | 0:a8090b59eb05 | 271 | } |
wim | 0:a8090b59eb05 | 272 | |
wim | 0:a8090b59eb05 | 273 | |
wim | 0:a8090b59eb05 | 274 | /************************ Exported functions **********************************/ |
wim | 0:a8090b59eb05 | 275 | |
wim | 0:a8090b59eb05 | 276 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 277 | * Initialize the Graphic LCD controller * |
wim | 0:a8090b59eb05 | 278 | * Parameter: * |
wim | 0:a8090b59eb05 | 279 | * Return: * |
wim | 0:a8090b59eb05 | 280 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 281 | |
wim | 3:2dccfa0121de | 282 | void GLCD::init (void) { |
wim | 0:a8090b59eb05 | 283 | |
wim | 0:a8090b59eb05 | 284 | /* Configure the LCD Control pins */ |
wim | 0:a8090b59eb05 | 285 | LPC_GPIO0->FIODIR |= 0x03f80000; |
wim | 0:a8090b59eb05 | 286 | LPC_GPIO0->FIOSET = 0x03f80000; |
wim | 0:a8090b59eb05 | 287 | |
wim | 0:a8090b59eb05 | 288 | delay(5); /* Delay 50 ms */ |
wim | 0:a8090b59eb05 | 289 | |
wim | 3:2dccfa0121de | 290 | _driverCode = _rd_reg(0x00); |
wim | 0:a8090b59eb05 | 291 | |
wim | 2:43ede88fb5a3 | 292 | switch (_driverCode) { |
wim | 0:a8090b59eb05 | 293 | |
wim | 0:a8090b59eb05 | 294 | case LGDP4531_ID: { //2.8" TFT LCD Module, DriverIC is LGDP4531 |
wim | 0:a8090b59eb05 | 295 | |
wim | 2:43ede88fb5a3 | 296 | #ifndef DISABLE_LGDP4531 |
wim | 3:2dccfa0121de | 297 | _wr_reg(0x00,0x0001); |
wim | 3:2dccfa0121de | 298 | _wr_reg(0x10,0x0628); |
wim | 3:2dccfa0121de | 299 | _wr_reg(0x12,0x0006); |
wim | 3:2dccfa0121de | 300 | _wr_reg(0x13,0x0A32); |
wim | 3:2dccfa0121de | 301 | _wr_reg(0x11,0x0040); |
wim | 3:2dccfa0121de | 302 | _wr_reg(0x15,0x0050); |
wim | 3:2dccfa0121de | 303 | _wr_reg(0x12,0x0016); |
wim | 0:a8090b59eb05 | 304 | delay(15); |
wim | 3:2dccfa0121de | 305 | _wr_reg(0x10,0x5660); |
wim | 0:a8090b59eb05 | 306 | delay(15); |
wim | 3:2dccfa0121de | 307 | _wr_reg(0x13,0x2A4E); |
wim | 3:2dccfa0121de | 308 | _wr_reg(0x01,0x0100); |
wim | 3:2dccfa0121de | 309 | _wr_reg(0x02,0x0300); |
wim | 0:a8090b59eb05 | 310 | |
wim | 3:2dccfa0121de | 311 | _wr_reg(0x03,0x1030); |
wim | 0:a8090b59eb05 | 312 | |
wim | 3:2dccfa0121de | 313 | _wr_reg(0x08,0x0202); |
wim | 3:2dccfa0121de | 314 | _wr_reg(0x0A,0x0000); |
wim | 3:2dccfa0121de | 315 | _wr_reg(0x30,0x0000); |
wim | 3:2dccfa0121de | 316 | _wr_reg(0x31,0x0402); |
wim | 3:2dccfa0121de | 317 | _wr_reg(0x32,0x0106); |
wim | 3:2dccfa0121de | 318 | _wr_reg(0x33,0x0700); |
wim | 3:2dccfa0121de | 319 | _wr_reg(0x34,0x0104); |
wim | 3:2dccfa0121de | 320 | _wr_reg(0x35,0x0301); |
wim | 3:2dccfa0121de | 321 | _wr_reg(0x36,0x0707); |
wim | 3:2dccfa0121de | 322 | _wr_reg(0x37,0x0305); |
wim | 3:2dccfa0121de | 323 | _wr_reg(0x38,0x0208); |
wim | 3:2dccfa0121de | 324 | _wr_reg(0x39,0x0F0B); |
wim | 0:a8090b59eb05 | 325 | delay(15); |
wim | 3:2dccfa0121de | 326 | _wr_reg(0x41,0x0002); |
wim | 3:2dccfa0121de | 327 | _wr_reg(0x60,0x2700); |
wim | 3:2dccfa0121de | 328 | _wr_reg(0x61,0x0001); |
wim | 3:2dccfa0121de | 329 | _wr_reg(0x90,0x0119); |
wim | 3:2dccfa0121de | 330 | _wr_reg(0x92,0x010A); |
wim | 3:2dccfa0121de | 331 | _wr_reg(0x93,0x0004); |
wim | 3:2dccfa0121de | 332 | _wr_reg(0xA0,0x0100); |
wim | 0:a8090b59eb05 | 333 | delay(15); |
wim | 3:2dccfa0121de | 334 | _wr_reg(0xA0,0x0000); |
wim | 0:a8090b59eb05 | 335 | delay(20); |
wim | 2:43ede88fb5a3 | 336 | #endif |
wim | 0:a8090b59eb05 | 337 | break; |
wim | 0:a8090b59eb05 | 338 | } |
wim | 0:a8090b59eb05 | 339 | |
wim | 0:a8090b59eb05 | 340 | case ILI9328_ID: |
wim | 0:a8090b59eb05 | 341 | case ILI9325_ID: { //2.8" TFT LCD Module, DriverIC is ILI9325 |
wim | 0:a8090b59eb05 | 342 | |
wim | 2:43ede88fb5a3 | 343 | #ifndef DISABLE_ILI9325 |
wim | 3:2dccfa0121de | 344 | _wr_reg(0x00e7,0x0010); |
wim | 3:2dccfa0121de | 345 | _wr_reg(0x0000,0x0001); //start internal osc |
wim | 3:2dccfa0121de | 346 | _wr_reg(0x0001,0x0100); |
wim | 3:2dccfa0121de | 347 | _wr_reg(0x0002,0x0700); //power on sequence |
wim | 3:2dccfa0121de | 348 | _wr_reg(0x0003,(1<<12)|(1<<5)|(1<<4) ); //65K |
wim | 3:2dccfa0121de | 349 | _wr_reg(0x0004,0x0000); |
wim | 3:2dccfa0121de | 350 | _wr_reg(0x0008,0x0207); |
wim | 3:2dccfa0121de | 351 | _wr_reg(0x0009,0x0000); |
wim | 3:2dccfa0121de | 352 | _wr_reg(0x000a,0x0000); //display setting |
wim | 3:2dccfa0121de | 353 | _wr_reg(0x000c,0x0001); //display setting |
wim | 3:2dccfa0121de | 354 | _wr_reg(0x000d,0x0000); //0f3c |
wim | 3:2dccfa0121de | 355 | _wr_reg(0x000f,0x0000); |
wim | 0:a8090b59eb05 | 356 | //Power On sequence // |
wim | 3:2dccfa0121de | 357 | _wr_reg(0x0010,0x0000); |
wim | 3:2dccfa0121de | 358 | _wr_reg(0x0011,0x0007); |
wim | 3:2dccfa0121de | 359 | _wr_reg(0x0012,0x0000); |
wim | 3:2dccfa0121de | 360 | _wr_reg(0x0013,0x0000); |
wim | 0:a8090b59eb05 | 361 | delay(15); |
wim | 3:2dccfa0121de | 362 | _wr_reg(0x0010,0x1590); |
wim | 3:2dccfa0121de | 363 | _wr_reg(0x0011,0x0227); |
wim | 0:a8090b59eb05 | 364 | delay(15); |
wim | 3:2dccfa0121de | 365 | _wr_reg(0x0012,0x009c); |
wim | 0:a8090b59eb05 | 366 | delay(15); |
wim | 3:2dccfa0121de | 367 | _wr_reg(0x0013,0x1900); |
wim | 3:2dccfa0121de | 368 | _wr_reg(0x0029,0x0023); |
wim | 3:2dccfa0121de | 369 | _wr_reg(0x002b,0x000e); |
wim | 0:a8090b59eb05 | 370 | delay(15); |
wim | 3:2dccfa0121de | 371 | _wr_reg(0x0020,0x0000); |
wim | 3:2dccfa0121de | 372 | _wr_reg(0x0021,0x0000); |
wim | 0:a8090b59eb05 | 373 | /////////////////////////////////////////////////////// |
wim | 0:a8090b59eb05 | 374 | delay(15); |
wim | 3:2dccfa0121de | 375 | _wr_reg(0x0030,0x0007); |
wim | 3:2dccfa0121de | 376 | _wr_reg(0x0031,0x0707); |
wim | 3:2dccfa0121de | 377 | _wr_reg(0x0032,0x0006); |
wim | 3:2dccfa0121de | 378 | _wr_reg(0x0035,0x0704); |
wim | 3:2dccfa0121de | 379 | _wr_reg(0x0036,0x1f04); |
wim | 3:2dccfa0121de | 380 | _wr_reg(0x0037,0x0004); |
wim | 3:2dccfa0121de | 381 | _wr_reg(0x0038,0x0000); |
wim | 3:2dccfa0121de | 382 | _wr_reg(0x0039,0x0706); |
wim | 3:2dccfa0121de | 383 | _wr_reg(0x003c,0x0701); |
wim | 3:2dccfa0121de | 384 | _wr_reg(0x003d,0x000f); |
wim | 0:a8090b59eb05 | 385 | delay(15); |
wim | 3:2dccfa0121de | 386 | _wr_reg(0x0050,0x0000); |
wim | 3:2dccfa0121de | 387 | _wr_reg(0x0051,0x00ef); |
wim | 3:2dccfa0121de | 388 | _wr_reg(0x0052,0x0000); |
wim | 3:2dccfa0121de | 389 | _wr_reg(0x0053,0x013f); |
wim | 3:2dccfa0121de | 390 | _wr_reg(0x0060,0xa700); |
wim | 3:2dccfa0121de | 391 | _wr_reg(0x0061,0x0001); |
wim | 3:2dccfa0121de | 392 | _wr_reg(0x006a,0x0000); |
wim | 3:2dccfa0121de | 393 | _wr_reg(0x0080,0x0000); |
wim | 3:2dccfa0121de | 394 | _wr_reg(0x0081,0x0000); |
wim | 3:2dccfa0121de | 395 | _wr_reg(0x0082,0x0000); |
wim | 3:2dccfa0121de | 396 | _wr_reg(0x0083,0x0000); |
wim | 3:2dccfa0121de | 397 | _wr_reg(0x0084,0x0000); |
wim | 3:2dccfa0121de | 398 | _wr_reg(0x0085,0x0000); |
wim | 0:a8090b59eb05 | 399 | |
wim | 3:2dccfa0121de | 400 | _wr_reg(0x0090,0x0010); |
wim | 3:2dccfa0121de | 401 | _wr_reg(0x0092,0x0000); |
wim | 3:2dccfa0121de | 402 | _wr_reg(0x0093,0x0003); |
wim | 3:2dccfa0121de | 403 | _wr_reg(0x0095,0x0110); |
wim | 3:2dccfa0121de | 404 | _wr_reg(0x0097,0x0000); |
wim | 3:2dccfa0121de | 405 | _wr_reg(0x0098,0x0000); |
wim | 0:a8090b59eb05 | 406 | //display on sequence |
wim | 3:2dccfa0121de | 407 | _wr_reg(0x0007,0x0133); |
wim | 3:2dccfa0121de | 408 | _wr_reg(0x0020,0x0000); |
wim | 3:2dccfa0121de | 409 | _wr_reg(0x0021,0x0000); |
wim | 2:43ede88fb5a3 | 410 | #endif |
wim | 0:a8090b59eb05 | 411 | break; |
wim | 0:a8090b59eb05 | 412 | } |
wim | 0:a8090b59eb05 | 413 | |
wim | 0:a8090b59eb05 | 414 | case ILI9320_ID: { //3.2" TFT LCD Module,DriverIC is ILI9320 |
wim | 2:43ede88fb5a3 | 415 | |
wim | 2:43ede88fb5a3 | 416 | #ifndef DISABLE_ILI9320 |
wim | 0:a8090b59eb05 | 417 | /* Start Initial Sequence --------------------------------------------------*/ |
wim | 3:2dccfa0121de | 418 | _wr_reg(0xE5, 0x8000); /* Set the internal vcore voltage */ |
wim | 3:2dccfa0121de | 419 | _wr_reg(0x00, 0x0001); /* Start internal OSC */ |
wim | 3:2dccfa0121de | 420 | _wr_reg(0x01, 0x0100); /* Set SS and SM bit */ |
wim | 3:2dccfa0121de | 421 | _wr_reg(0x02, 0x0700); /* Set 1 line inversion */ |
wim | 3:2dccfa0121de | 422 | _wr_reg(0x03, 0x1030); /* Set GRAM write direction and BGR=1 */ |
wim | 3:2dccfa0121de | 423 | _wr_reg(0x04, 0x0000); /* Resize register */ |
wim | 3:2dccfa0121de | 424 | _wr_reg(0x08, 0x0202); /* 2 lines each, back and front porch */ |
wim | 3:2dccfa0121de | 425 | _wr_reg(0x09, 0x0000); /* Set non-disp area refresh cyc ISC */ |
wim | 3:2dccfa0121de | 426 | _wr_reg(0x0A, 0x0000); /* FMARK function */ |
wim | 3:2dccfa0121de | 427 | _wr_reg(0x0C, 0x0000); /* RGB interface setting */ |
wim | 3:2dccfa0121de | 428 | _wr_reg(0x0D, 0x0000); /* Frame marker Position */ |
wim | 3:2dccfa0121de | 429 | _wr_reg(0x0F, 0x0000); /* RGB interface polarity */ |
wim | 0:a8090b59eb05 | 430 | |
wim | 0:a8090b59eb05 | 431 | /* Power On sequence -------------------------------------------------------*/ |
wim | 3:2dccfa0121de | 432 | _wr_reg(0x10, 0x0000); /* Reset Power Control 1 */ |
wim | 3:2dccfa0121de | 433 | _wr_reg(0x11, 0x0000); /* Reset Power Control 2 */ |
wim | 3:2dccfa0121de | 434 | _wr_reg(0x12, 0x0000); /* Reset Power Control 3 */ |
wim | 3:2dccfa0121de | 435 | _wr_reg(0x13, 0x0000); /* Reset Power Control 4 */ |
wim | 0:a8090b59eb05 | 436 | delay(20); /* Discharge cap power voltage (200ms)*/ |
wim | 3:2dccfa0121de | 437 | _wr_reg(0x10, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ |
wim | 3:2dccfa0121de | 438 | _wr_reg(0x11, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */ |
wim | 0:a8090b59eb05 | 439 | delay(5); /* Delay 50 ms */ |
wim | 3:2dccfa0121de | 440 | _wr_reg(0x12, 0x0139); /* VREG1OUT voltage */ |
wim | 0:a8090b59eb05 | 441 | delay(5); /* Delay 50 ms */ |
wim | 3:2dccfa0121de | 442 | _wr_reg(0x13, 0x1D00); /* VDV[4:0] for VCOM amplitude */ |
wim | 3:2dccfa0121de | 443 | _wr_reg(0x29, 0x0013); /* VCM[4:0] for VCOMH */ |
wim | 0:a8090b59eb05 | 444 | delay(5); /* Delay 50 ms */ |
wim | 3:2dccfa0121de | 445 | _wr_reg(0x20, 0x0000); /* GRAM horizontal Address */ |
wim | 3:2dccfa0121de | 446 | _wr_reg(0x21, 0x0000); /* GRAM Vertical Address */ |
wim | 0:a8090b59eb05 | 447 | |
wim | 0:a8090b59eb05 | 448 | /* Adjust the Gamma Curve --------------------------------------------------*/ |
wim | 3:2dccfa0121de | 449 | _wr_reg(0x30, 0x0006); |
wim | 3:2dccfa0121de | 450 | _wr_reg(0x31, 0x0101); |
wim | 3:2dccfa0121de | 451 | _wr_reg(0x32, 0x0003); |
wim | 3:2dccfa0121de | 452 | _wr_reg(0x35, 0x0106); |
wim | 3:2dccfa0121de | 453 | _wr_reg(0x36, 0x0B02); |
wim | 3:2dccfa0121de | 454 | _wr_reg(0x37, 0x0302); |
wim | 3:2dccfa0121de | 455 | _wr_reg(0x38, 0x0707); |
wim | 3:2dccfa0121de | 456 | _wr_reg(0x39, 0x0007); |
wim | 3:2dccfa0121de | 457 | _wr_reg(0x3C, 0x0600); |
wim | 3:2dccfa0121de | 458 | _wr_reg(0x3D, 0x020B); |
wim | 0:a8090b59eb05 | 459 | |
wim | 0:a8090b59eb05 | 460 | /* Set GRAM area -----------------------------------------------------------*/ |
wim | 3:2dccfa0121de | 461 | _wr_reg(0x50, 0x0000); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 462 | _wr_reg(0x51, (HEIGHT-1)); /* Horizontal GRAM End Address */ |
wim | 3:2dccfa0121de | 463 | _wr_reg(0x52, 0x0000); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 464 | _wr_reg(0x53, (WIDTH-1)); /* Vertical GRAM End Address */ |
wim | 3:2dccfa0121de | 465 | _wr_reg(0x60, 0x2700); /* Gate Scan Line */ |
wim | 3:2dccfa0121de | 466 | _wr_reg(0x61, 0x0001); /* NDL,VLE, REV */ |
wim | 3:2dccfa0121de | 467 | _wr_reg(0x6A, 0x0000); /* Set scrolling line */ |
wim | 0:a8090b59eb05 | 468 | |
wim | 0:a8090b59eb05 | 469 | /* Partial Display Control -------------------------------------------------*/ |
wim | 3:2dccfa0121de | 470 | _wr_reg(0x80, 0x0000); |
wim | 3:2dccfa0121de | 471 | _wr_reg(0x81, 0x0000); |
wim | 3:2dccfa0121de | 472 | _wr_reg(0x82, 0x0000); |
wim | 3:2dccfa0121de | 473 | _wr_reg(0x83, 0x0000); |
wim | 3:2dccfa0121de | 474 | _wr_reg(0x84, 0x0000); |
wim | 3:2dccfa0121de | 475 | _wr_reg(0x85, 0x0000); |
wim | 0:a8090b59eb05 | 476 | |
wim | 0:a8090b59eb05 | 477 | /* Panel Control -----------------------------------------------------------*/ |
wim | 3:2dccfa0121de | 478 | _wr_reg(0x90, 0x0010); |
wim | 3:2dccfa0121de | 479 | _wr_reg(0x92, 0x0000); |
wim | 3:2dccfa0121de | 480 | _wr_reg(0x93, 0x0003); |
wim | 3:2dccfa0121de | 481 | _wr_reg(0x95, 0x0110); |
wim | 3:2dccfa0121de | 482 | _wr_reg(0x97, 0x0000); |
wim | 3:2dccfa0121de | 483 | _wr_reg(0x98, 0x0000); |
wim | 2:43ede88fb5a3 | 484 | #endif |
wim | 0:a8090b59eb05 | 485 | |
wim | 0:a8090b59eb05 | 486 | break; |
wim | 0:a8090b59eb05 | 487 | } |
wim | 0:a8090b59eb05 | 488 | |
wim | 0:a8090b59eb05 | 489 | case ILI9331_ID: { |
wim | 2:43ede88fb5a3 | 490 | |
wim | 2:43ede88fb5a3 | 491 | #ifndef DISABLE_ILI9331 |
wim | 3:2dccfa0121de | 492 | _wr_reg(0x00E7, 0x1014); |
wim | 3:2dccfa0121de | 493 | _wr_reg(0x0001, 0x0100); /* set SS and SM bit */ |
wim | 3:2dccfa0121de | 494 | _wr_reg(0x0002, 0x0200); /* set 1 line inversion */ |
wim | 3:2dccfa0121de | 495 | _wr_reg(0x0003, 0x1030); /* set GRAM write direction and BGR=1 */ |
wim | 3:2dccfa0121de | 496 | _wr_reg(0x0008, 0x0202); /* set the back porch and front porch */ |
wim | 3:2dccfa0121de | 497 | _wr_reg(0x0009, 0x0000); /* set non-display area refresh cycle ISC[3:0] */ |
wim | 3:2dccfa0121de | 498 | _wr_reg(0x000A, 0x0000); /* FMARK function */ |
wim | 3:2dccfa0121de | 499 | _wr_reg(0x000C, 0x0000); /* RGB interface setting */ |
wim | 3:2dccfa0121de | 500 | _wr_reg(0x000D, 0x0000); /* Frame marker Position */ |
wim | 3:2dccfa0121de | 501 | _wr_reg(0x000F, 0x0000); /* RGB interface polarity */ |
wim | 0:a8090b59eb05 | 502 | /* Power On sequence */ |
wim | 3:2dccfa0121de | 503 | _wr_reg(0x0010, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ |
wim | 3:2dccfa0121de | 504 | _wr_reg(0x0011, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */ |
wim | 3:2dccfa0121de | 505 | _wr_reg(0x0012, 0x0000); /* VREG1OUT voltage */ |
wim | 3:2dccfa0121de | 506 | _wr_reg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */ |
wim | 0:a8090b59eb05 | 507 | delay(200); /* delay 200 ms */ |
wim | 3:2dccfa0121de | 508 | _wr_reg(0x0010, 0x1690); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ |
wim | 3:2dccfa0121de | 509 | _wr_reg(0x0011, 0x0227); /* DC1[2:0], DC0[2:0], VC[2:0] */ |
wim | 0:a8090b59eb05 | 510 | delay(50); /* delay 50 ms */ |
wim | 3:2dccfa0121de | 511 | _wr_reg(0x0012, 0x000C); /* Internal reference voltage= Vci */ |
wim | 0:a8090b59eb05 | 512 | delay(50); /* delay 50 ms */ |
wim | 3:2dccfa0121de | 513 | _wr_reg(0x0013, 0x0800); /* Set VDV[4:0] for VCOM amplitude */ |
wim | 3:2dccfa0121de | 514 | _wr_reg(0x0029, 0x0011); /* Set VCM[5:0] for VCOMH */ |
wim | 3:2dccfa0121de | 515 | _wr_reg(0x002B, 0x000B); /* Set Frame Rate */ |
wim | 0:a8090b59eb05 | 516 | delay(50); /* delay 50 ms */ |
wim | 3:2dccfa0121de | 517 | _wr_reg(0x0020, 0x0000); /* GRAM horizontal Address */ |
wim | 3:2dccfa0121de | 518 | _wr_reg(0x0021, 0x0000); /* GRAM Vertical Address */ |
wim | 0:a8090b59eb05 | 519 | /* Adjust the Gamma Curve */ |
wim | 3:2dccfa0121de | 520 | _wr_reg(0x0030, 0x0000); |
wim | 3:2dccfa0121de | 521 | _wr_reg(0x0031, 0x0106); |
wim | 3:2dccfa0121de | 522 | _wr_reg(0x0032, 0x0000); |
wim | 3:2dccfa0121de | 523 | _wr_reg(0x0035, 0x0204); |
wim | 3:2dccfa0121de | 524 | _wr_reg(0x0036, 0x160A); |
wim | 3:2dccfa0121de | 525 | _wr_reg(0x0037, 0x0707); |
wim | 3:2dccfa0121de | 526 | _wr_reg(0x0038, 0x0106); |
wim | 3:2dccfa0121de | 527 | _wr_reg(0x0039, 0x0707); |
wim | 3:2dccfa0121de | 528 | _wr_reg(0x003C, 0x0402); |
wim | 3:2dccfa0121de | 529 | _wr_reg(0x003D, 0x0C0F); |
wim | 0:a8090b59eb05 | 530 | /* Set GRAM area */ |
wim | 3:2dccfa0121de | 531 | _wr_reg(0x0050, 0x0000); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 532 | _wr_reg(0x0051, 0x00EF); /* Horizontal GRAM End Address */ |
wim | 3:2dccfa0121de | 533 | _wr_reg(0x0052, 0x0000); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 534 | _wr_reg(0x0053, 0x013F); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 535 | _wr_reg(0x0060, 0x2700); /* Gate Scan Line */ |
wim | 3:2dccfa0121de | 536 | _wr_reg(0x0061, 0x0001); /* NDL,VLE, REV */ |
wim | 3:2dccfa0121de | 537 | _wr_reg(0x006A, 0x0000); /* set scrolling line */ |
wim | 0:a8090b59eb05 | 538 | /* Partial Display Control */ |
wim | 3:2dccfa0121de | 539 | _wr_reg(0x0080, 0x0000); |
wim | 3:2dccfa0121de | 540 | _wr_reg(0x0081, 0x0000); |
wim | 3:2dccfa0121de | 541 | _wr_reg(0x0082, 0x0000); |
wim | 3:2dccfa0121de | 542 | _wr_reg(0x0083, 0x0000); |
wim | 3:2dccfa0121de | 543 | _wr_reg(0x0084, 0x0000); |
wim | 3:2dccfa0121de | 544 | _wr_reg(0x0085, 0x0000); |
wim | 0:a8090b59eb05 | 545 | /* Panel Control */ |
wim | 3:2dccfa0121de | 546 | _wr_reg(0x0090, 0x0010); |
wim | 3:2dccfa0121de | 547 | _wr_reg(0x0092, 0x0600); |
wim | 3:2dccfa0121de | 548 | _wr_reg(0x0007,0x0021); |
wim | 0:a8090b59eb05 | 549 | delay(50); /* delay 50 ms */ |
wim | 3:2dccfa0121de | 550 | _wr_reg(0x0007,0x0061); |
wim | 0:a8090b59eb05 | 551 | delay(50); /* delay 50 ms */ |
wim | 3:2dccfa0121de | 552 | _wr_reg(0x0007,0x0133); /* 262K color and display ON */ |
wim | 2:43ede88fb5a3 | 553 | #endif |
wim | 0:a8090b59eb05 | 554 | break; |
wim | 0:a8090b59eb05 | 555 | } |
wim | 0:a8090b59eb05 | 556 | |
wim | 0:a8090b59eb05 | 557 | case SSD1289_ID: { //3.2" TFT LCD Module,DriverIC is SSD1289 |
wim | 2:43ede88fb5a3 | 558 | |
wim | 2:43ede88fb5a3 | 559 | #ifndef DISABLE_SSD1289_ID |
wim | 3:2dccfa0121de | 560 | _wr_reg(0x0007,0x0233); delay(5); //0x0233 Set this first or init fails ! |
wim | 1:ea0f7b1c5daf | 561 | |
wim | 3:2dccfa0121de | 562 | _wr_reg(0x0000,0x0001); delay(5); // osc en |
wim | 0:a8090b59eb05 | 563 | |
wim | 3:2dccfa0121de | 564 | _wr_reg(0x0003,0xA8A4); delay(5); // powercontrol 1 0xA8A4 |
wim | 3:2dccfa0121de | 565 | _wr_reg(0x000C,0x0000); delay(5); // powercontrol 2 |
wim | 3:2dccfa0121de | 566 | _wr_reg(0x000D,0x080C); delay(5); // powercontrol 3 |
wim | 3:2dccfa0121de | 567 | _wr_reg(0x000E,0x2B00); delay(5); // powercontrol 4 |
wim | 3:2dccfa0121de | 568 | _wr_reg(0x001E,0x00B0); delay(5); // powercontrol 5 |
wim | 0:a8090b59eb05 | 569 | |
wim | 3:2dccfa0121de | 570 | //orig _wr_reg(0x0001,0x2b3F); delay(5); // 0x2b3f Mux=320, BGR, RL=0, TB=1 |
wim | 3:2dccfa0121de | 571 | _wr_reg(0x0001,0x6B3F); delay(5); // 0x6B3F Mux=320, BGR, RL=1, TB=1 |
wim | 3:2dccfa0121de | 572 | // _wr_reg(0x0001,0x293F); delay(5); // 0x293f Mux=320, BGR, RL=0, TB=0 |
wim | 0:a8090b59eb05 | 573 | |
wim | 0:a8090b59eb05 | 574 | |
wim | 3:2dccfa0121de | 575 | _wr_reg(0x0002,0x0600); delay(5); // Driver AC mode |
wim | 3:2dccfa0121de | 576 | _wr_reg(0x0010,0x0000); delay(5); // Exit Sleep |
wim | 0:a8090b59eb05 | 577 | |
wim | 3:2dccfa0121de | 578 | _wr_reg(0x0011,0x6078); delay(5); // Entry mode 0x6078 = 65k colors, Hor and Vert Addr Incr, AM=1 vert writing dir |
wim | 3:2dccfa0121de | 579 | // _wr_reg(0x0011,0x4030); delay(5); // Entry mode 0x4030 = 262k colors, Hor and Vert Addr Incr. AM=0 hor writing dir |
wim | 0:a8090b59eb05 | 580 | |
wim | 3:2dccfa0121de | 581 | _wr_reg(0x0005,0x0000); delay(5); // Compare Regs (default) |
wim | 3:2dccfa0121de | 582 | _wr_reg(0x0006,0x0000); delay(5); |
wim | 0:a8090b59eb05 | 583 | |
wim | 3:2dccfa0121de | 584 | _wr_reg(0x0016,0xEF1C); delay(5); // Hor Porch (default) |
wim | 3:2dccfa0121de | 585 | _wr_reg(0x0017,0x0003); delay(5); // Ver Porch (default 0103) |
wim | 3:2dccfa0121de | 586 | _wr_reg(0x0007,0x0233); delay(5); //0x0233 |
wim | 3:2dccfa0121de | 587 | _wr_reg(0x000B,0x0000); delay(5); // Frame cycle control default 5308) |
wim | 0:a8090b59eb05 | 588 | |
wim | 3:2dccfa0121de | 589 | _wr_reg(0x000F,0x0000); delay(5); // Gate scan start position |
wim | 0:a8090b59eb05 | 590 | |
wim | 3:2dccfa0121de | 591 | _wr_reg(0x0041,0x0000); delay(5); // Vert Scroll control |
wim | 3:2dccfa0121de | 592 | _wr_reg(0x0042,0x0000); delay(5); |
wim | 0:a8090b59eb05 | 593 | |
wim | 3:2dccfa0121de | 594 | _wr_reg(0x0048,0x0000); delay(5); // First screen pos (default) |
wim | 3:2dccfa0121de | 595 | _wr_reg(0x0049,0x013F); delay(5); |
wim | 0:a8090b59eb05 | 596 | |
wim | 3:2dccfa0121de | 597 | _wr_reg(0x004A,0x0000); delay(5); // Second screen pos |
wim | 3:2dccfa0121de | 598 | _wr_reg(0x004B,0x0000); delay(5); |
wim | 0:a8090b59eb05 | 599 | |
wim | 3:2dccfa0121de | 600 | _wr_reg(0x0044,0xEF00); delay(5); // Hor addr pos |
wim | 3:2dccfa0121de | 601 | _wr_reg(0x0045,0x0000); delay(5); // Vert Addr pos |
wim | 3:2dccfa0121de | 602 | _wr_reg(0x0046,0x013F); delay(5); |
wim | 0:a8090b59eb05 | 603 | |
wim | 3:2dccfa0121de | 604 | _wr_reg(0x0030,0x0707); delay(5); // Gamma |
wim | 3:2dccfa0121de | 605 | _wr_reg(0x0031,0x0204); delay(5); |
wim | 3:2dccfa0121de | 606 | _wr_reg(0x0032,0x0204); delay(5); |
wim | 3:2dccfa0121de | 607 | _wr_reg(0x0033,0x0502); delay(5); |
wim | 3:2dccfa0121de | 608 | _wr_reg(0x0034,0x0507); delay(5); |
wim | 3:2dccfa0121de | 609 | _wr_reg(0x0035,0x0204); delay(5); |
wim | 3:2dccfa0121de | 610 | _wr_reg(0x0036,0x0204); delay(5); |
wim | 3:2dccfa0121de | 611 | _wr_reg(0x0037,0x0502); delay(5); |
wim | 3:2dccfa0121de | 612 | _wr_reg(0x003A,0x0302); delay(5); |
wim | 3:2dccfa0121de | 613 | _wr_reg(0x003B,0x0302); delay(5); |
wim | 0:a8090b59eb05 | 614 | |
wim | 3:2dccfa0121de | 615 | _wr_reg(0x0023,0x0000); delay(5); // Write data mask (default) |
wim | 3:2dccfa0121de | 616 | _wr_reg(0x0024,0x0000); delay(5); |
wim | 0:a8090b59eb05 | 617 | |
wim | 3:2dccfa0121de | 618 | _wr_reg(0x0025,0x8000); delay(5); // Frame freq 65 Hz |
wim | 3:2dccfa0121de | 619 | _wr_reg(0x004e,0); // Start x |
wim | 3:2dccfa0121de | 620 | _wr_reg(0x004f,0); // Start y |
wim | 2:43ede88fb5a3 | 621 | #endif |
wim | 0:a8090b59eb05 | 622 | break; |
wim | 0:a8090b59eb05 | 623 | } |
wim | 0:a8090b59eb05 | 624 | |
wim | 0:a8090b59eb05 | 625 | |
wim | 0:a8090b59eb05 | 626 | case SSD1298_ID: { |
wim | 2:43ede88fb5a3 | 627 | |
wim | 2:43ede88fb5a3 | 628 | #ifndef DISABLE_SSD1298_ID |
wim | 3:2dccfa0121de | 629 | _wr_reg(0x0028,0x0006); |
wim | 3:2dccfa0121de | 630 | _wr_reg(0x0000,0x0001); |
wim | 3:2dccfa0121de | 631 | _wr_reg(0x0003,0xaea4); /* power control 1---line frequency and VHG,VGL voltage */ |
wim | 3:2dccfa0121de | 632 | _wr_reg(0x000c,0x0004); /* power control 2---VCIX2 output voltage */ |
wim | 3:2dccfa0121de | 633 | _wr_reg(0x000d,0x000c); /* power control 3---Vlcd63 voltage */ |
wim | 3:2dccfa0121de | 634 | _wr_reg(0x000e,0x2800); /* power control 4---VCOMA voltage VCOML=VCOMH*0.9475-VCOMA */ |
wim | 3:2dccfa0121de | 635 | _wr_reg(0x001e,0x00b5); /* POWER CONTROL 5---VCOMH voltage */ |
wim | 3:2dccfa0121de | 636 | _wr_reg(0x0001,0x3b3f); |
wim | 3:2dccfa0121de | 637 | _wr_reg(0x0002,0x0600); |
wim | 3:2dccfa0121de | 638 | _wr_reg(0x0010,0x0000); |
wim | 3:2dccfa0121de | 639 | _wr_reg(0x0011,0x6830); |
wim | 3:2dccfa0121de | 640 | _wr_reg(0x0005,0x0000); |
wim | 3:2dccfa0121de | 641 | _wr_reg(0x0006,0x0000); |
wim | 3:2dccfa0121de | 642 | _wr_reg(0x0016,0xef1c); |
wim | 3:2dccfa0121de | 643 | _wr_reg(0x0007,0x0033); /* Display control 1 */ |
wim | 0:a8090b59eb05 | 644 | /* when GON=1 and DTE=0,all gate outputs become VGL */ |
wim | 0:a8090b59eb05 | 645 | /* when GON=1 and DTE=0,all gate outputs become VGH */ |
wim | 0:a8090b59eb05 | 646 | /* non-selected gate wires become VGL */ |
wim | 3:2dccfa0121de | 647 | _wr_reg(0x000b,0x0000); |
wim | 3:2dccfa0121de | 648 | _wr_reg(0x000f,0x0000); |
wim | 3:2dccfa0121de | 649 | _wr_reg(0x0041,0x0000); |
wim | 3:2dccfa0121de | 650 | _wr_reg(0x0042,0x0000); |
wim | 3:2dccfa0121de | 651 | _wr_reg(0x0048,0x0000); |
wim | 3:2dccfa0121de | 652 | _wr_reg(0x0049,0x013f); |
wim | 3:2dccfa0121de | 653 | _wr_reg(0x004a,0x0000); |
wim | 3:2dccfa0121de | 654 | _wr_reg(0x004b,0x0000); |
wim | 3:2dccfa0121de | 655 | _wr_reg(0x0044,0xef00); /* Horizontal RAM start and end address */ |
wim | 3:2dccfa0121de | 656 | _wr_reg(0x0045,0x0000); /* Vretical RAM start address */ |
wim | 3:2dccfa0121de | 657 | _wr_reg(0x0046,0x013f); /* Vretical RAM end address */ |
wim | 3:2dccfa0121de | 658 | _wr_reg(0x004e,0x0000); /* set GDDRAM x address counter */ |
wim | 3:2dccfa0121de | 659 | _wr_reg(0x004f,0x0000); /* set GDDRAM y address counter */ |
wim | 0:a8090b59eb05 | 660 | /* y control */ |
wim | 3:2dccfa0121de | 661 | _wr_reg(0x0030,0x0707); |
wim | 3:2dccfa0121de | 662 | _wr_reg(0x0031,0x0202); |
wim | 3:2dccfa0121de | 663 | _wr_reg(0x0032,0x0204); |
wim | 3:2dccfa0121de | 664 | _wr_reg(0x0033,0x0502); |
wim | 3:2dccfa0121de | 665 | _wr_reg(0x0034,0x0507); |
wim | 3:2dccfa0121de | 666 | _wr_reg(0x0035,0x0204); |
wim | 3:2dccfa0121de | 667 | _wr_reg(0x0036,0x0204); |
wim | 3:2dccfa0121de | 668 | _wr_reg(0x0037,0x0502); |
wim | 3:2dccfa0121de | 669 | _wr_reg(0x003a,0x0302); |
wim | 3:2dccfa0121de | 670 | _wr_reg(0x003b,0x0302); |
wim | 3:2dccfa0121de | 671 | _wr_reg(0x0023,0x0000); |
wim | 3:2dccfa0121de | 672 | _wr_reg(0x0024,0x0000); |
wim | 3:2dccfa0121de | 673 | _wr_reg(0x0025,0x8000); |
wim | 3:2dccfa0121de | 674 | _wr_reg(0x0026,0x7000); |
wim | 3:2dccfa0121de | 675 | _wr_reg(0x0020,0xb0eb); |
wim | 3:2dccfa0121de | 676 | _wr_reg(0x0027,0x007c); |
wim | 2:43ede88fb5a3 | 677 | #endif |
wim | 0:a8090b59eb05 | 678 | break; |
wim | 0:a8090b59eb05 | 679 | } |
wim | 0:a8090b59eb05 | 680 | |
wim | 0:a8090b59eb05 | 681 | case SSD2119_ID: { |
wim | 2:43ede88fb5a3 | 682 | |
wim | 2:43ede88fb5a3 | 683 | #ifndef DISABLE_SSD2119_ID |
wim | 0:a8090b59eb05 | 684 | /* POWER ON & RESET DISPLAY OFF */ |
wim | 3:2dccfa0121de | 685 | _wr_reg(0x28,0x0006); |
wim | 3:2dccfa0121de | 686 | _wr_reg(0x00,0x0001); |
wim | 3:2dccfa0121de | 687 | _wr_reg(0x10,0x0000); |
wim | 3:2dccfa0121de | 688 | _wr_reg(0x01,0x72ef); |
wim | 3:2dccfa0121de | 689 | _wr_reg(0x02,0x0600); |
wim | 3:2dccfa0121de | 690 | _wr_reg(0x03,0x6a38); |
wim | 3:2dccfa0121de | 691 | _wr_reg(0x11,0x6874); |
wim | 3:2dccfa0121de | 692 | _wr_reg(0x0f,0x0000); /* RAM WRITE DATA MASK */ |
wim | 3:2dccfa0121de | 693 | _wr_reg(0x0b,0x5308); /* RAM WRITE DATA MASK */ |
wim | 3:2dccfa0121de | 694 | _wr_reg(0x0c,0x0003); |
wim | 3:2dccfa0121de | 695 | _wr_reg(0x0d,0x000a); |
wim | 3:2dccfa0121de | 696 | _wr_reg(0x0e,0x2e00); |
wim | 3:2dccfa0121de | 697 | _wr_reg(0x1e,0x00be); |
wim | 3:2dccfa0121de | 698 | _wr_reg(0x25,0x8000); |
wim | 3:2dccfa0121de | 699 | _wr_reg(0x26,0x7800); |
wim | 3:2dccfa0121de | 700 | _wr_reg(0x27,0x0078); |
wim | 3:2dccfa0121de | 701 | _wr_reg(0x4e,0x0000); |
wim | 3:2dccfa0121de | 702 | _wr_reg(0x4f,0x0000); |
wim | 3:2dccfa0121de | 703 | _wr_reg(0x12,0x08d9); |
wim | 0:a8090b59eb05 | 704 | /* Adjust the Gamma Curve */ |
wim | 3:2dccfa0121de | 705 | _wr_reg(0x30,0x0000); |
wim | 3:2dccfa0121de | 706 | _wr_reg(0x31,0x0104); |
wim | 3:2dccfa0121de | 707 | _wr_reg(0x32,0x0100); |
wim | 3:2dccfa0121de | 708 | _wr_reg(0x33,0x0305); |
wim | 3:2dccfa0121de | 709 | _wr_reg(0x34,0x0505); |
wim | 3:2dccfa0121de | 710 | _wr_reg(0x35,0x0305); |
wim | 3:2dccfa0121de | 711 | _wr_reg(0x36,0x0707); |
wim | 3:2dccfa0121de | 712 | _wr_reg(0x37,0x0300); |
wim | 3:2dccfa0121de | 713 | _wr_reg(0x3a,0x1200); |
wim | 3:2dccfa0121de | 714 | _wr_reg(0x3b,0x0800); |
wim | 3:2dccfa0121de | 715 | _wr_reg(0x07,0x0033); |
wim | 2:43ede88fb5a3 | 716 | #endif |
wim | 0:a8090b59eb05 | 717 | break; |
wim | 0:a8090b59eb05 | 718 | } |
wim | 0:a8090b59eb05 | 719 | |
wim | 0:a8090b59eb05 | 720 | |
wim | 0:a8090b59eb05 | 721 | |
wim | 0:a8090b59eb05 | 722 | #if(0) |
wim | 0:a8090b59eb05 | 723 | |
wim | 0:a8090b59eb05 | 724 | // Note: unprintable char hidden as space and as nl !!! |
wim | 0:a8090b59eb05 | 725 | case R61505U_ID1: |
wim | 0:a8090b59eb05 | 726 | case R61505U_ID2: { |
wim | 0:a8090b59eb05 | 727 | |
wim | 2:43ede88fb5a3 | 728 | #ifndef DISABLE_R61505U |
wim | 0:a8090b59eb05 | 729 | /* second release on 3/5 ,luminance is acceptable,water wave appear during camera preview */ |
wim | 3:2dccfa0121de | 730 | _wr_reg(0x0007,0x0000); |
wim | 0:a8090b59eb05 | 731 | delay(50); /* delay 50 ms */ |
wim | 3:2dccfa0121de | 732 | _wr_reg(0x0012,0x011C); /* why need to set several times? */ |
wim | 3:2dccfa0121de | 733 | _wr_reg(0x00A4,0x0001); /* NVM */ |
wim | 3:2dccfa0121de | 734 | _wr_reg(0x0008,0x000F); |
wim | 3:2dccfa0121de | 735 | _wr_reg(0x000A,0x0008); |
wim | 3:2dccfa0121de | 736 | _wr_reg(0x000D,0x0008); |
wim | 0:a8090b59eb05 | 737 | /* GAMMA CONTROL */ |
wim | 3:2dccfa0121de | 738 | _wr_reg(0x0030,0x0707); |
wim | 3:2dccfa0121de | 739 | _wr_reg(0x0031,0x0007); |
wim | 3:2dccfa0121de | 740 | _wr_reg(0x0032,0x0603); |
wim | 3:2dccfa0121de | 741 | _wr_reg(0x0033,0x0700); |
wim | 3:2dccfa0121de | 742 | _wr_reg(0x0034,0x0202); |
wim | 3:2dccfa0121de | 743 | _wr_reg(0x0035,0x0002); |
wim | 3:2dccfa0121de | 744 | _wr_reg(0x0036,0x1F0F); |
wim | 3:2dccfa0121de | 745 | _wr_reg(0x0037,0x0707); |
wim | 3:2dccfa0121de | 746 | _wr_reg(0x0038,0x0000); |
wim | 3:2dccfa0121de | 747 | _wr_reg(0x0039,0x0000); |
wim | 3:2dccfa0121de | 748 | _wr_reg(0x003A,0x0707); |
wim | 3:2dccfa0121de | 749 | _wr_reg(0x003B,0x0000); |
wim | 3:2dccfa0121de | 750 | _wr_reg(0x003C,0x0007); |
wim | 3:2dccfa0121de | 751 | _wr_reg(0x003D,0x0000); |
wim | 0:a8090b59eb05 | 752 | delay(50); /* delay 50 ms */ |
wim | 3:2dccfa0121de | 753 | _wr_reg(0x0007,0x0001); |
wim | 3:2dccfa0121de | 754 | _wr_reg(0x0017,0x0001); /* Power supply startup enable */ |
wim | 0:a8090b59eb05 | 755 | delay(50); /* delay 50 ms */ |
wim | 0:a8090b59eb05 | 756 | /* power control */ |
wim | 3:2dccfa0121de | 757 | _wr_reg(0x0010,0x17A0); |
wim | 3:2dccfa0121de | 758 | _wr_reg(0x0011,0x0217); /* reference voltage VC[2:0] Vciout = 1.00*Vcivl */ |
wim | 3:2dccfa0121de | 759 | _wr_reg(0x0012,0x011E); /* Vreg1out = Vcilvl*1.80 is it the same as Vgama1out ? */ |
wim | 3:2dccfa0121de | 760 | _wr_reg(0x0013,0x0F00); /* VDV[4:0]-->VCOM Amplitude VcomL = VcomH - Vcom Ampl */ |
wim | 3:2dccfa0121de | 761 | _wr_reg(0x002A,0x0000); |
wim | 3:2dccfa0121de | 762 | _wr_reg(0x0029,0x000A); /* Vcomh = VCM1[4:0]*Vreg1out gate source voltage?? */ |
wim | 3:2dccfa0121de | 763 | _wr_reg(0x0012,0x013E); /* power supply on */ |
wim | 0:a8090b59eb05 | 764 | /* Coordinates Control */ |
wim | 3:2dccfa0121de | 765 | _wr_reg(0x0050,0x0000); |
wim | 3:2dccfa0121de | 766 | _wr_reg(0x0051,0x00EF); |
wim | 3:2dccfa0121de | 767 | _wr_reg(0x0052,0x0000); |
wim | 3:2dccfa0121de | 768 | _wr_reg(0x0053,0x013F); |
wim | 0:a8090b59eb05 | 769 | /* Pannel Image Control */ |
wim | 3:2dccfa0121de | 770 | _wr_reg(0x0060,0x2700); |
wim | 3:2dccfa0121de | 771 | _wr_reg(0x0061,0x0001); |
wim | 3:2dccfa0121de | 772 | _wr_reg(0x006A,0x0000); |
wim | 3:2dccfa0121de | 773 | _wr_reg(0x0080,0x0000); |
wim | 0:a8090b59eb05 | 774 | /* Partial Image Control */ |
wim | 3:2dccfa0121de | 775 | _wr_reg(0x0081,0x0000); |
wim | 3:2dccfa0121de | 776 | _wr_reg(0x0082,0x0000); |
wim | 3:2dccfa0121de | 777 | _wr_reg(0x0083,0x0000); |
wim | 3:2dccfa0121de | 778 | _wr_reg(0x0084,0x0000); |
wim | 3:2dccfa0121de | 779 | _wr_reg(0x0085,0x0000); |
wim | 0:a8090b59eb05 | 780 | /* Panel Interface Control */ |
wim | 3:2dccfa0121de | 781 | _wr_reg(0x0090,0x0013); /* frenqucy */ |
wim | 3:2dccfa0121de | 782 | _wr_reg(0x0092,0x0300); |
wim | 3:2dccfa0121de | 783 | _wr_reg(0x0093,0x0005); |
wim | 3:2dccfa0121de | 784 | _wr_reg(0x0095,0x0000); |
wim | 3:2dccfa0121de | 785 | _wr_reg(0x0097,0x0000); |
wim | 3:2dccfa0121de | 786 | _wr_reg(0x0098,0x0000); |
wim | 0:a8090b59eb05 | 787 | |
wim | 3:2dccfa0121de | 788 | _wr_reg(0x0001,0x0100); |
wim | 3:2dccfa0121de | 789 | _wr_reg(0x0002,0x0700); |
wim | 3:2dccfa0121de | 790 | _wr_reg(0x0003,0x1030); |
wim | 3:2dccfa0121de | 791 | _wr_reg(0x0004,0x0000); |
wim | 3:2dccfa0121de | 792 | _wr_reg(0x000C,0x0000); |
wim | 3:2dccfa0121de | 793 | _wr_reg(0x000F,0x0000); |
wim | 3:2dccfa0121de | 794 | _wr_reg(0x0020,0x0000); |
wim | 3:2dccfa0121de | 795 | _wr_reg(0x0021,0x0000); |
wim | 3:2dccfa0121de | 796 | _wr_reg(0x0007,0x0021); |
wim | 0:a8090b59eb05 | 797 | delay(200); /* delay 200 ms */ |
wim | 3:2dccfa0121de | 798 | _wr_reg(0x0007,0x0061); |
wim | 0:a8090b59eb05 | 799 | delay(200); /* delay 200 ms */ |
wim | 3:2dccfa0121de | 800 | _wr_reg(0x0007,0x0173); |
wim | 2:43ede88fb5a3 | 801 | #endif |
wim | 0:a8090b59eb05 | 802 | break; |
wim | 0:a8090b59eb05 | 803 | } |
wim | 0:a8090b59eb05 | 804 | |
wim | 0:a8090b59eb05 | 805 | case SPFD5408B_ID: { |
wim | 2:43ede88fb5a3 | 806 | |
wim | 2:43ede88fb5a3 | 807 | #ifndef DISABLE_SPFD5408B |
wim | 3:2dccfa0121de | 808 | _wr_reg(0x0001,0x0100); /* Driver Output Contral Register */ |
wim | 3:2dccfa0121de | 809 | _wr_reg(0x0002,0x0700); /* LCD Driving Waveform Contral */ |
wim | 3:2dccfa0121de | 810 | _wr_reg(0x0003,0x1030); /* Entry ModeÉèÖÃ */ |
wim | 0:a8090b59eb05 | 811 | |
wim | 3:2dccfa0121de | 812 | _wr_reg(0x0004,0x0000); /* Scalling Control register */ |
wim | 3:2dccfa0121de | 813 | _wr_reg(0x0008,0x0207); /* Display Control 2 */ |
wim | 3:2dccfa0121de | 814 | _wr_reg(0x0009,0x0000); /* Display Control 3 */ |
wim | 3:2dccfa0121de | 815 | _wr_reg(0x000A,0x0000); /* Frame Cycle Control */ |
wim | 3:2dccfa0121de | 816 | _wr_reg(0x000C,0x0000); /* External Display Interface Control 1 */ |
wim | 3:2dccfa0121de | 817 | _wr_reg(0x000D,0x0000); /* Frame Maker Position */ |
wim | 3:2dccfa0121de | 818 | _wr_reg(0x000F,0x0000); /* External Display Interface Control 2 */ |
wim | 0:a8090b59eb05 | 819 | delay(50); |
wim | 3:2dccfa0121de | 820 | _wr_reg(0x0007,0x0101); /* Display Control */ |
wim | 0:a8090b59eb05 | 821 | delay(50); |
wim | 3:2dccfa0121de | 822 | _wr_reg(0x0010,0x16B0); /* Power Control 1 */ |
wim | 3:2dccfa0121de | 823 | _wr_reg(0x0011,0x0001); /* Power Control 2 */ |
wim | 3:2dccfa0121de | 824 | _wr_reg(0x0017,0x0001); /* Power Control 3 */ |
wim | 3:2dccfa0121de | 825 | _wr_reg(0x0012,0x0138); /* Power Control 4 */ |
wim | 3:2dccfa0121de | 826 | _wr_reg(0x0013,0x0800); /* Power Control 5 */ |
wim | 3:2dccfa0121de | 827 | _wr_reg(0x0029,0x0009); /* NVM read data 2 */ |
wim | 3:2dccfa0121de | 828 | _wr_reg(0x002a,0x0009); /* NVM read data 3 */ |
wim | 3:2dccfa0121de | 829 | _wr_reg(0x00a4,0x0000); |
wim | 3:2dccfa0121de | 830 | _wr_reg(0x0050,0x0000); /* ÉèÖòÙ×÷´°¿ÚµÄXÖῪʼÁÐ */ |
wim | 3:2dccfa0121de | 831 | _wr_reg(0x0051,0x00EF); /* ÉèÖòÙ×÷´°¿ÚµÄXÖá½áÊøÁÐ */ |
wim | 3:2dccfa0121de | 832 | _wr_reg(0x0052,0x0000); /* ÉèÖòÙ×÷´°¿ÚµÄYÖῪʼÐÐ */ |
wim | 3:2dccfa0121de | 833 | _wr_reg(0x0053,0x013F); /* ÉèÖòÙ×÷´°¿ÚµÄYÖá½áÊøÐÐ */ |
wim | 0:a8090b59eb05 | 834 | |
wim | 3:2dccfa0121de | 835 | _wr_reg(0x0060,0x2700); /* Driver Output Control */ |
wim | 0:a8090b59eb05 | 836 | /* ÉèÖÃÆÁÄ»µÄµãÊýÒÔ¼°É¨ÃèµÄÆðʼÐÐ */ |
wim | 3:2dccfa0121de | 837 | _wr_reg(0x0061,0x0003); /* Driver Output Control */ |
wim | 3:2dccfa0121de | 838 | _wr_reg(0x006A,0x0000); /* Vertical Scroll Control */ |
wim | 0:a8090b59eb05 | 839 | |
wim | 3:2dccfa0121de | 840 | _wr_reg(0x0080,0x0000); /* Display Position ¨C Partial Display 1 */ |
wim | 3:2dccfa0121de | 841 | _wr_reg(0x0081,0x0000); /* RAM Address Start ¨C Partial Display 1 */ |
wim | 3:2dccfa0121de | 842 | _wr_reg(0x0082,0x0000); /* RAM address End - Partial Display 1 */ |
wim | 3:2dccfa0121de | 843 | _wr_reg(0x0083,0x0000); /* Display Position ¨C Partial Display 2 */ |
wim | 3:2dccfa0121de | 844 | _wr_reg(0x0084,0x0000); /* RAM Address Start ¨C Partial Display 2 */ |
wim | 3:2dccfa0121de | 845 | _wr_reg(0x0085,0x0000); /* RAM address End ¨C Partail Display2 */ |
wim | 3:2dccfa0121de | 846 | _wr_reg(0x0090,0x0013); /* Frame Cycle Control */ |
wim | 3:2dccfa0121de | 847 | _wr_reg(0x0092,0x0000); /* Panel Interface Control 2 */ |
wim | 3:2dccfa0121de | 848 | _wr_reg(0x0093,0x0003); /* Panel Interface control 3 */ |
wim | 3:2dccfa0121de | 849 | _wr_reg(0x0095,0x0110); /* Frame Cycle Control */ |
wim | 3:2dccfa0121de | 850 | _wr_reg(0x0007,0x0173); |
wim | 2:43ede88fb5a3 | 851 | #endif |
wim | 0:a8090b59eb05 | 852 | break; |
wim | 0:a8090b59eb05 | 853 | } |
wim | 0:a8090b59eb05 | 854 | |
wim | 0:a8090b59eb05 | 855 | case LGDP4531_ID: { |
wim | 2:43ede88fb5a3 | 856 | |
wim | 2:43ede88fb5a3 | 857 | #ifndef DISABLE_LGDP4531 |
wim | 0:a8090b59eb05 | 858 | /* Setup display */ |
wim | 3:2dccfa0121de | 859 | _wr_reg(0x00,0x0001); |
wim | 3:2dccfa0121de | 860 | _wr_reg(0x10,0x0628); |
wim | 3:2dccfa0121de | 861 | _wr_reg(0x12,0x0006); |
wim | 3:2dccfa0121de | 862 | _wr_reg(0x13,0x0A32); |
wim | 3:2dccfa0121de | 863 | _wr_reg(0x11,0x0040); |
wim | 3:2dccfa0121de | 864 | _wr_reg(0x15,0x0050); |
wim | 3:2dccfa0121de | 865 | _wr_reg(0x12,0x0016); |
wim | 0:a8090b59eb05 | 866 | delay(50); |
wim | 3:2dccfa0121de | 867 | _wr_reg(0x10,0x5660); |
wim | 0:a8090b59eb05 | 868 | delay(50); |
wim | 3:2dccfa0121de | 869 | _wr_reg(0x13,0x2A4E); |
wim | 3:2dccfa0121de | 870 | _wr_reg(0x01,0x0100); |
wim | 3:2dccfa0121de | 871 | _wr_reg(0x02,0x0300); |
wim | 3:2dccfa0121de | 872 | _wr_reg(0x03,0x1030); |
wim | 3:2dccfa0121de | 873 | _wr_reg(0x08,0x0202); |
wim | 3:2dccfa0121de | 874 | _wr_reg(0x0A,0x0000); |
wim | 3:2dccfa0121de | 875 | _wr_reg(0x30,0x0000); |
wim | 3:2dccfa0121de | 876 | _wr_reg(0x31,0x0402); |
wim | 3:2dccfa0121de | 877 | _wr_reg(0x32,0x0106); |
wim | 3:2dccfa0121de | 878 | _wr_reg(0x33,0x0700); |
wim | 3:2dccfa0121de | 879 | _wr_reg(0x34,0x0104); |
wim | 3:2dccfa0121de | 880 | _wr_reg(0x35,0x0301); |
wim | 3:2dccfa0121de | 881 | _wr_reg(0x36,0x0707); |
wim | 3:2dccfa0121de | 882 | _wr_reg(0x37,0x0305); |
wim | 3:2dccfa0121de | 883 | _wr_reg(0x38,0x0208); |
wim | 3:2dccfa0121de | 884 | _wr_reg(0x39,0x0F0B); |
wim | 0:a8090b59eb05 | 885 | delay(50); |
wim | 3:2dccfa0121de | 886 | _wr_reg(0x41,0x0002); |
wim | 3:2dccfa0121de | 887 | _wr_reg(0x60,0x2700); |
wim | 3:2dccfa0121de | 888 | _wr_reg(0x61,0x0001); |
wim | 3:2dccfa0121de | 889 | _wr_reg(0x90,0x0119); |
wim | 3:2dccfa0121de | 890 | _wr_reg(0x92,0x010A); |
wim | 3:2dccfa0121de | 891 | _wr_reg(0x93,0x0004); |
wim | 3:2dccfa0121de | 892 | _wr_reg(0xA0,0x0100); |
wim | 0:a8090b59eb05 | 893 | delay(50); |
wim | 3:2dccfa0121de | 894 | _wr_reg(0x07,0x0133); |
wim | 0:a8090b59eb05 | 895 | delay(50); |
wim | 3:2dccfa0121de | 896 | _wr_reg(0xA0,0x0000); |
wim | 2:43ede88fb5a3 | 897 | #endif |
wim | 0:a8090b59eb05 | 898 | break; |
wim | 0:a8090b59eb05 | 899 | } |
wim | 0:a8090b59eb05 | 900 | |
wim | 0:a8090b59eb05 | 901 | case LGDP4535_ID: { |
wim | 2:43ede88fb5a3 | 902 | |
wim | 2:43ede88fb5a3 | 903 | #ifndef DISABLE_LGDP4535 |
wim | 3:2dccfa0121de | 904 | _wr_reg(0x15, 0x0030); /* Set the internal vcore voltage */ |
wim | 3:2dccfa0121de | 905 | _wr_reg(0x9A, 0x0010); /* Start internal OSC */ |
wim | 3:2dccfa0121de | 906 | _wr_reg(0x11, 0x0020); /* set SS and SM bit */ |
wim | 3:2dccfa0121de | 907 | _wr_reg(0x10, 0x3428); /* set 1 line inversion */ |
wim | 3:2dccfa0121de | 908 | _wr_reg(0x12, 0x0002); /* set GRAM write direction and BGR=1 */ |
wim | 3:2dccfa0121de | 909 | _wr_reg(0x13, 0x1038); /* Resize register */ |
wim | 0:a8090b59eb05 | 910 | delay(40); |
wim | 3:2dccfa0121de | 911 | _wr_reg(0x12, 0x0012); /* set the back porch and front porch */ |
wim | 0:a8090b59eb05 | 912 | delay(40); |
wim | 3:2dccfa0121de | 913 | _wr_reg(0x10, 0x3420); /* set non-display area refresh cycle ISC[3:0] */ |
wim | 3:2dccfa0121de | 914 | _wr_reg(0x13, 0x3045); /* FMARK function */ |
wim | 0:a8090b59eb05 | 915 | delay(70); |
wim | 3:2dccfa0121de | 916 | _wr_reg(0x30, 0x0000); /* RGB interface setting */ |
wim | 3:2dccfa0121de | 917 | _wr_reg(0x31, 0x0402); /* Frame marker Position */ |
wim | 3:2dccfa0121de | 918 | _wr_reg(0x32, 0x0307); /* RGB interface polarity */ |
wim | 3:2dccfa0121de | 919 | _wr_reg(0x33, 0x0304); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ |
wim | 3:2dccfa0121de | 920 | _wr_reg(0x34, 0x0004); /* DC1[2:0], DC0[2:0], VC[2:0] */ |
wim | 3:2dccfa0121de | 921 | _wr_reg(0x35, 0x0401); /* VREG1OUT voltage */ |
wim | 3:2dccfa0121de | 922 | _wr_reg(0x36, 0x0707); /* VDV[4:0] for VCOM amplitude */ |
wim | 3:2dccfa0121de | 923 | _wr_reg(0x37, 0x0305); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ |
wim | 3:2dccfa0121de | 924 | _wr_reg(0x38, 0x0610); /* DC1[2:0], DC0[2:0], VC[2:0] */ |
wim | 3:2dccfa0121de | 925 | _wr_reg(0x39, 0x0610); /* VREG1OUT voltage */ |
wim | 3:2dccfa0121de | 926 | _wr_reg(0x01, 0x0100); /* VDV[4:0] for VCOM amplitude */ |
wim | 3:2dccfa0121de | 927 | _wr_reg(0x02, 0x0300); /* VCM[4:0] for VCOMH */ |
wim | 3:2dccfa0121de | 928 | _wr_reg(0x03, 0x1030); /* GRAM horizontal Address */ |
wim | 3:2dccfa0121de | 929 | _wr_reg(0x08, 0x0808); /* GRAM Vertical Address */ |
wim | 3:2dccfa0121de | 930 | _wr_reg(0x0A, 0x0008); |
wim | 3:2dccfa0121de | 931 | _wr_reg(0x60, 0x2700); /* Gate Scan Line */ |
wim | 3:2dccfa0121de | 932 | _wr_reg(0x61, 0x0001); /* NDL,VLE, REV */ |
wim | 3:2dccfa0121de | 933 | _wr_reg(0x90, 0x013E); |
wim | 3:2dccfa0121de | 934 | _wr_reg(0x92, 0x0100); |
wim | 3:2dccfa0121de | 935 | _wr_reg(0x93, 0x0100); |
wim | 3:2dccfa0121de | 936 | _wr_reg(0xA0, 0x3000); |
wim | 3:2dccfa0121de | 937 | _wr_reg(0xA3, 0x0010); |
wim | 3:2dccfa0121de | 938 | _wr_reg(0x07, 0x0001); |
wim | 3:2dccfa0121de | 939 | _wr_reg(0x07, 0x0021); |
wim | 3:2dccfa0121de | 940 | _wr_reg(0x07, 0x0023); |
wim | 3:2dccfa0121de | 941 | _wr_reg(0x07, 0x0033); |
wim | 3:2dccfa0121de | 942 | _wr_reg(0x07, 0x0133); |
wim | 2:43ede88fb5a3 | 943 | #endif |
wim | 0:a8090b59eb05 | 944 | break; |
wim | 0:a8090b59eb05 | 945 | } |
wim | 0:a8090b59eb05 | 946 | |
wim | 0:a8090b59eb05 | 947 | case HX8347D_ID: { |
wim | 2:43ede88fb5a3 | 948 | |
wim | 2:43ede88fb5a3 | 949 | #ifndef DISABLE_HX8347D |
wim | 0:a8090b59eb05 | 950 | /* Start Initial Sequence */ |
wim | 3:2dccfa0121de | 951 | _wr_reg(0xEA,0x00); |
wim | 3:2dccfa0121de | 952 | _wr_reg(0xEB,0x20); |
wim | 3:2dccfa0121de | 953 | _wr_reg(0xEC,0x0C); |
wim | 3:2dccfa0121de | 954 | _wr_reg(0xED,0xC4); |
wim | 3:2dccfa0121de | 955 | _wr_reg(0xE8,0x40); |
wim | 3:2dccfa0121de | 956 | _wr_reg(0xE9,0x38); |
wim | 3:2dccfa0121de | 957 | _wr_reg(0xF1,0x01); |
wim | 3:2dccfa0121de | 958 | _wr_reg(0xF2,0x10); |
wim | 3:2dccfa0121de | 959 | _wr_reg(0x27,0xA3); |
wim | 0:a8090b59eb05 | 960 | /* GAMMA SETTING */ |
wim | 3:2dccfa0121de | 961 | _wr_reg(0x40,0x01); |
wim | 3:2dccfa0121de | 962 | _wr_reg(0x41,0x00); |
wim | 3:2dccfa0121de | 963 | _wr_reg(0x42,0x00); |
wim | 3:2dccfa0121de | 964 | _wr_reg(0x43,0x10); |
wim | 3:2dccfa0121de | 965 | _wr_reg(0x44,0x0E); |
wim | 3:2dccfa0121de | 966 | _wr_reg(0x45,0x24); |
wim | 3:2dccfa0121de | 967 | _wr_reg(0x46,0x04); |
wim | 3:2dccfa0121de | 968 | _wr_reg(0x47,0x50); |
wim | 3:2dccfa0121de | 969 | _wr_reg(0x48,0x02); |
wim | 3:2dccfa0121de | 970 | _wr_reg(0x49,0x13); |
wim | 3:2dccfa0121de | 971 | _wr_reg(0x4A,0x19); |
wim | 3:2dccfa0121de | 972 | _wr_reg(0x4B,0x19); |
wim | 3:2dccfa0121de | 973 | _wr_reg(0x4C,0x16); |
wim | 3:2dccfa0121de | 974 | _wr_reg(0x50,0x1B); |
wim | 3:2dccfa0121de | 975 | _wr_reg(0x51,0x31); |
wim | 3:2dccfa0121de | 976 | _wr_reg(0x52,0x2F); |
wim | 3:2dccfa0121de | 977 | _wr_reg(0x53,0x3F); |
wim | 3:2dccfa0121de | 978 | _wr_reg(0x54,0x3F); |
wim | 3:2dccfa0121de | 979 | _wr_reg(0x55,0x3E); |
wim | 3:2dccfa0121de | 980 | _wr_reg(0x56,0x2F); |
wim | 3:2dccfa0121de | 981 | _wr_reg(0x57,0x7B); |
wim | 3:2dccfa0121de | 982 | _wr_reg(0x58,0x09); |
wim | 3:2dccfa0121de | 983 | _wr_reg(0x59,0x06); |
wim | 3:2dccfa0121de | 984 | _wr_reg(0x5A,0x06); |
wim | 3:2dccfa0121de | 985 | _wr_reg(0x5B,0x0C); |
wim | 3:2dccfa0121de | 986 | _wr_reg(0x5C,0x1D); |
wim | 3:2dccfa0121de | 987 | _wr_reg(0x5D,0xCC); |
wim | 0:a8090b59eb05 | 988 | /* Power Voltage Setting */ |
wim | 3:2dccfa0121de | 989 | _wr_reg(0x1B,0x18); |
wim | 3:2dccfa0121de | 990 | _wr_reg(0x1A,0x01); |
wim | 3:2dccfa0121de | 991 | _wr_reg(0x24,0x15); |
wim | 3:2dccfa0121de | 992 | _wr_reg(0x25,0x50); |
wim | 3:2dccfa0121de | 993 | _wr_reg(0x23,0x8B); |
wim | 3:2dccfa0121de | 994 | _wr_reg(0x18,0x36); |
wim | 3:2dccfa0121de | 995 | _wr_reg(0x19,0x01); |
wim | 3:2dccfa0121de | 996 | _wr_reg(0x01,0x00); |
wim | 3:2dccfa0121de | 997 | _wr_reg(0x1F,0x88); |
wim | 0:a8090b59eb05 | 998 | delay(50); |
wim | 3:2dccfa0121de | 999 | _wr_reg(0x1F,0x80); |
wim | 0:a8090b59eb05 | 1000 | delay(50); |
wim | 3:2dccfa0121de | 1001 | _wr_reg(0x1F,0x90); |
wim | 0:a8090b59eb05 | 1002 | delay(50); |
wim | 3:2dccfa0121de | 1003 | _wr_reg(0x1F,0xD0); |
wim | 0:a8090b59eb05 | 1004 | delay(50); |
wim | 3:2dccfa0121de | 1005 | _wr_reg(0x17,0x05); |
wim | 3:2dccfa0121de | 1006 | _wr_reg(0x36,0x00); |
wim | 3:2dccfa0121de | 1007 | _wr_reg(0x28,0x38); |
wim | 0:a8090b59eb05 | 1008 | delay(50); |
wim | 3:2dccfa0121de | 1009 | _wr_reg(0x28,0x3C); |
wim | 2:43ede88fb5a3 | 1010 | #endif |
wim | 0:a8090b59eb05 | 1011 | break; |
wim | 0:a8090b59eb05 | 1012 | } |
wim | 0:a8090b59eb05 | 1013 | |
wim | 0:a8090b59eb05 | 1014 | case ST7781_ID: { |
wim | 2:43ede88fb5a3 | 1015 | |
wim | 2:43ede88fb5a3 | 1016 | #ifndef DISABLE_ST7781 |
wim | 0:a8090b59eb05 | 1017 | /* Start Initial Sequence */ |
wim | 3:2dccfa0121de | 1018 | _wr_reg(0x00FF,0x0001); |
wim | 3:2dccfa0121de | 1019 | _wr_reg(0x00F3,0x0008); |
wim | 3:2dccfa0121de | 1020 | _wr_reg(0x0001,0x0100); |
wim | 3:2dccfa0121de | 1021 | _wr_reg(0x0002,0x0700); |
wim | 3:2dccfa0121de | 1022 | _wr_reg(0x0003,0x1030); |
wim | 3:2dccfa0121de | 1023 | _wr_reg(0x0008,0x0302); |
wim | 3:2dccfa0121de | 1024 | _wr_reg(0x0008,0x0207); |
wim | 3:2dccfa0121de | 1025 | _wr_reg(0x0009,0x0000); |
wim | 3:2dccfa0121de | 1026 | _wr_reg(0x000A,0x0000); |
wim | 3:2dccfa0121de | 1027 | _wr_reg(0x0010,0x0000); |
wim | 3:2dccfa0121de | 1028 | _wr_reg(0x0011,0x0005); |
wim | 3:2dccfa0121de | 1029 | _wr_reg(0x0012,0x0000); |
wim | 3:2dccfa0121de | 1030 | _wr_reg(0x0013,0x0000); |
wim | 0:a8090b59eb05 | 1031 | delay(50); |
wim | 3:2dccfa0121de | 1032 | _wr_reg(0x0010,0x12B0); |
wim | 0:a8090b59eb05 | 1033 | delay(50); |
wim | 3:2dccfa0121de | 1034 | _wr_reg(0x0011,0x0007); |
wim | 0:a8090b59eb05 | 1035 | delay(50); |
wim | 3:2dccfa0121de | 1036 | _wr_reg(0x0012,0x008B); |
wim | 0:a8090b59eb05 | 1037 | delay(50); |
wim | 3:2dccfa0121de | 1038 | _wr_reg(0x0013,0x1700); |
wim | 0:a8090b59eb05 | 1039 | delay(50); |
wim | 3:2dccfa0121de | 1040 | _wr_reg(0x0029,0x0022); |
wim | 3:2dccfa0121de | 1041 | _wr_reg(0x0030,0x0000); |
wim | 3:2dccfa0121de | 1042 | _wr_reg(0x0031,0x0707); |
wim | 3:2dccfa0121de | 1043 | _wr_reg(0x0032,0x0505); |
wim | 3:2dccfa0121de | 1044 | _wr_reg(0x0035,0x0107); |
wim | 3:2dccfa0121de | 1045 | _wr_reg(0x0036,0x0008); |
wim | 3:2dccfa0121de | 1046 | _wr_reg(0x0037,0x0000); |
wim | 3:2dccfa0121de | 1047 | _wr_reg(0x0038,0x0202); |
wim | 3:2dccfa0121de | 1048 | _wr_reg(0x0039,0x0106); |
wim | 3:2dccfa0121de | 1049 | _wr_reg(0x003C,0x0202); |
wim | 3:2dccfa0121de | 1050 | _wr_reg(0x003D,0x0408); |
wim | 0:a8090b59eb05 | 1051 | delay(50); |
wim | 3:2dccfa0121de | 1052 | _wr_reg(0x0050,0x0000); |
wim | 3:2dccfa0121de | 1053 | _wr_reg(0x0051,0x00EF); |
wim | 3:2dccfa0121de | 1054 | _wr_reg(0x0052,0x0000); |
wim | 3:2dccfa0121de | 1055 | _wr_reg(0x0053,0x013F); |
wim | 3:2dccfa0121de | 1056 | _wr_reg(0x0060,0xA700); |
wim | 3:2dccfa0121de | 1057 | _wr_reg(0x0061,0x0001); |
wim | 3:2dccfa0121de | 1058 | _wr_reg(0x0090,0x0033); |
wim | 3:2dccfa0121de | 1059 | _wr_reg(0x002B,0x000B); |
wim | 3:2dccfa0121de | 1060 | _wr_reg(0x0007,0x0133); |
wim | 2:43ede88fb5a3 | 1061 | #endif |
wim | 0:a8090b59eb05 | 1062 | break; |
wim | 0:a8090b59eb05 | 1063 | } |
wim | 0:a8090b59eb05 | 1064 | #endif |
wim | 0:a8090b59eb05 | 1065 | |
wim | 0:a8090b59eb05 | 1066 | default: { |
wim | 0:a8090b59eb05 | 1067 | /* special ID */ |
wim | 3:2dccfa0121de | 1068 | _driverCode = _rd_reg(0x67); |
wim | 2:43ede88fb5a3 | 1069 | |
wim | 2:43ede88fb5a3 | 1070 | if (_driverCode == HX8347A_ID) { |
wim | 2:43ede88fb5a3 | 1071 | |
wim | 2:43ede88fb5a3 | 1072 | #ifndef DISABLE_HX8347A |
wim | 3:2dccfa0121de | 1073 | _wr_reg(0x0042,0x0008); |
wim | 0:a8090b59eb05 | 1074 | /* Gamma setting */ |
wim | 3:2dccfa0121de | 1075 | _wr_reg(0x0046,0x00B4); |
wim | 3:2dccfa0121de | 1076 | _wr_reg(0x0047,0x0043); |
wim | 3:2dccfa0121de | 1077 | _wr_reg(0x0048,0x0013); |
wim | 3:2dccfa0121de | 1078 | _wr_reg(0x0049,0x0047); |
wim | 3:2dccfa0121de | 1079 | _wr_reg(0x004A,0x0014); |
wim | 3:2dccfa0121de | 1080 | _wr_reg(0x004B,0x0036); |
wim | 3:2dccfa0121de | 1081 | _wr_reg(0x004C,0x0003); |
wim | 3:2dccfa0121de | 1082 | _wr_reg(0x004D,0x0046); |
wim | 3:2dccfa0121de | 1083 | _wr_reg(0x004E,0x0005); |
wim | 3:2dccfa0121de | 1084 | _wr_reg(0x004F,0x0010); |
wim | 3:2dccfa0121de | 1085 | _wr_reg(0x0050,0x0008); |
wim | 3:2dccfa0121de | 1086 | _wr_reg(0x0051,0x000a); |
wim | 0:a8090b59eb05 | 1087 | /* Window Setting */ |
wim | 3:2dccfa0121de | 1088 | _wr_reg(0x0002,0x0000); |
wim | 3:2dccfa0121de | 1089 | _wr_reg(0x0003,0x0000); |
wim | 3:2dccfa0121de | 1090 | _wr_reg(0x0004,0x0000); |
wim | 3:2dccfa0121de | 1091 | _wr_reg(0x0005,0x00EF); |
wim | 3:2dccfa0121de | 1092 | _wr_reg(0x0006,0x0000); |
wim | 3:2dccfa0121de | 1093 | _wr_reg(0x0007,0x0000); |
wim | 3:2dccfa0121de | 1094 | _wr_reg(0x0008,0x0001); |
wim | 3:2dccfa0121de | 1095 | _wr_reg(0x0009,0x003F); |
wim | 0:a8090b59eb05 | 1096 | delay(10); |
wim | 3:2dccfa0121de | 1097 | _wr_reg(0x0001,0x0006); |
wim | 3:2dccfa0121de | 1098 | _wr_reg(0x0016,0x00C8); |
wim | 3:2dccfa0121de | 1099 | _wr_reg(0x0023,0x0095); |
wim | 3:2dccfa0121de | 1100 | _wr_reg(0x0024,0x0095); |
wim | 3:2dccfa0121de | 1101 | _wr_reg(0x0025,0x00FF); |
wim | 3:2dccfa0121de | 1102 | _wr_reg(0x0027,0x0002); |
wim | 3:2dccfa0121de | 1103 | _wr_reg(0x0028,0x0002); |
wim | 3:2dccfa0121de | 1104 | _wr_reg(0x0029,0x0002); |
wim | 3:2dccfa0121de | 1105 | _wr_reg(0x002A,0x0002); |
wim | 3:2dccfa0121de | 1106 | _wr_reg(0x002C,0x0002); |
wim | 3:2dccfa0121de | 1107 | _wr_reg(0x002D,0x0002); |
wim | 3:2dccfa0121de | 1108 | _wr_reg(0x003A,0x0001); |
wim | 3:2dccfa0121de | 1109 | _wr_reg(0x003B,0x0001); |
wim | 3:2dccfa0121de | 1110 | _wr_reg(0x003C,0x00F0); |
wim | 3:2dccfa0121de | 1111 | _wr_reg(0x003D,0x0000); |
wim | 0:a8090b59eb05 | 1112 | delay(20); |
wim | 3:2dccfa0121de | 1113 | _wr_reg(0x0035,0x0038); |
wim | 3:2dccfa0121de | 1114 | _wr_reg(0x0036,0x0078); |
wim | 3:2dccfa0121de | 1115 | _wr_reg(0x003E,0x0038); |
wim | 3:2dccfa0121de | 1116 | _wr_reg(0x0040,0x000F); |
wim | 3:2dccfa0121de | 1117 | _wr_reg(0x0041,0x00F0); |
wim | 3:2dccfa0121de | 1118 | _wr_reg(0x0038,0x0000); |
wim | 0:a8090b59eb05 | 1119 | /* Power Setting */ |
wim | 3:2dccfa0121de | 1120 | _wr_reg(0x0019,0x0049); |
wim | 3:2dccfa0121de | 1121 | _wr_reg(0x0093,0x000A); |
wim | 0:a8090b59eb05 | 1122 | delay(10); |
wim | 3:2dccfa0121de | 1123 | _wr_reg(0x0020,0x0020); |
wim | 3:2dccfa0121de | 1124 | _wr_reg(0x001D,0x0003); |
wim | 3:2dccfa0121de | 1125 | _wr_reg(0x001E,0x0000); |
wim | 3:2dccfa0121de | 1126 | _wr_reg(0x001F,0x0009); |
wim | 3:2dccfa0121de | 1127 | _wr_reg(0x0044,0x0053); |
wim | 3:2dccfa0121de | 1128 | _wr_reg(0x0045,0x0010); |
wim | 0:a8090b59eb05 | 1129 | delay(10); |
wim | 3:2dccfa0121de | 1130 | _wr_reg(0x001C,0x0004); |
wim | 0:a8090b59eb05 | 1131 | delay(20); |
wim | 3:2dccfa0121de | 1132 | _wr_reg(0x0043,0x0080); |
wim | 0:a8090b59eb05 | 1133 | delay(5); |
wim | 3:2dccfa0121de | 1134 | _wr_reg(0x001B,0x000a); |
wim | 0:a8090b59eb05 | 1135 | delay(40); |
wim | 3:2dccfa0121de | 1136 | _wr_reg(0x001B,0x0012); |
wim | 0:a8090b59eb05 | 1137 | delay(40); |
wim | 0:a8090b59eb05 | 1138 | /* Display On Setting */ |
wim | 3:2dccfa0121de | 1139 | _wr_reg(0x0090,0x007F); |
wim | 3:2dccfa0121de | 1140 | _wr_reg(0x0026,0x0004); |
wim | 0:a8090b59eb05 | 1141 | delay(40); |
wim | 3:2dccfa0121de | 1142 | _wr_reg(0x0026,0x0024); |
wim | 3:2dccfa0121de | 1143 | _wr_reg(0x0026,0x002C); |
wim | 0:a8090b59eb05 | 1144 | delay(40); |
wim | 3:2dccfa0121de | 1145 | _wr_reg(0x0070,0x0008); |
wim | 3:2dccfa0121de | 1146 | _wr_reg(0x0026,0x003C); |
wim | 3:2dccfa0121de | 1147 | _wr_reg(0x0057,0x0002); |
wim | 3:2dccfa0121de | 1148 | _wr_reg(0x0055,0x0000); |
wim | 3:2dccfa0121de | 1149 | _wr_reg(0x0057,0x0000); |
wim | 2:43ede88fb5a3 | 1150 | #endif |
wim | 0:a8090b59eb05 | 1151 | } // if |
wim | 2:43ede88fb5a3 | 1152 | |
wim | 0:a8090b59eb05 | 1153 | break; |
wim | 0:a8090b59eb05 | 1154 | } // default case |
wim | 0:a8090b59eb05 | 1155 | |
wim | 0:a8090b59eb05 | 1156 | } // end switch |
wim | 0:a8090b59eb05 | 1157 | |
wim | 2:43ede88fb5a3 | 1158 | _textColor = Black; |
wim | 2:43ede88fb5a3 | 1159 | _backColor = White; |
wim | 0:a8090b59eb05 | 1160 | } |
wim | 0:a8090b59eb05 | 1161 | |
wim | 0:a8090b59eb05 | 1162 | |
wim | 2:43ede88fb5a3 | 1163 | int GLCD::getDisplayXSize() |
wim | 2:43ede88fb5a3 | 1164 | { |
wim | 2:43ede88fb5a3 | 1165 | return HEIGHT; |
wim | 2:43ede88fb5a3 | 1166 | } |
wim | 0:a8090b59eb05 | 1167 | |
wim | 2:43ede88fb5a3 | 1168 | int GLCD::getDisplayYSize() |
wim | 2:43ede88fb5a3 | 1169 | { |
wim | 2:43ede88fb5a3 | 1170 | return WIDTH; |
wim | 2:43ede88fb5a3 | 1171 | } |
wim | 0:a8090b59eb05 | 1172 | |
wim | 0:a8090b59eb05 | 1173 | |
wim | 0:a8090b59eb05 | 1174 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1175 | * Get LCD Controller ID * |
wim | 0:a8090b59eb05 | 1176 | * Parameter: * |
wim | 0:a8090b59eb05 | 1177 | * Return: short Controller ID * |
wim | 0:a8090b59eb05 | 1178 | *******************************************************************************/ |
wim | 3:2dccfa0121de | 1179 | uint16_t GLCD::getDriverCode () { |
wim | 0:a8090b59eb05 | 1180 | |
wim | 2:43ede88fb5a3 | 1181 | return (_driverCode); |
wim | 0:a8090b59eb05 | 1182 | } |
wim | 0:a8090b59eb05 | 1183 | |
wim | 0:a8090b59eb05 | 1184 | |
wim | 0:a8090b59eb05 | 1185 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1186 | * Set draw window region to whole screen * |
wim | 0:a8090b59eb05 | 1187 | * Parameter: * |
wim | 0:a8090b59eb05 | 1188 | * Return: * |
wim | 0:a8090b59eb05 | 1189 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1190 | |
wim | 3:2dccfa0121de | 1191 | void GLCD::setWindowMax (void) { |
wim | 0:a8090b59eb05 | 1192 | |
wim | 2:43ede88fb5a3 | 1193 | if(_driverCode==SSD1289_ID) |
wim | 0:a8090b59eb05 | 1194 | { |
wim | 3:2dccfa0121de | 1195 | _wr_reg(0x44, 0); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1196 | _wr_reg(0x44, 0 |((HEIGHT-1)<<8)); /* Horizontal GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1197 | _wr_reg(0x45, 0); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1198 | _wr_reg(0x46, WIDTH-1); /* Vertical GRAM End Address (-1) */ |
wim | 0:a8090b59eb05 | 1199 | } |
wim | 0:a8090b59eb05 | 1200 | else |
wim | 0:a8090b59eb05 | 1201 | { |
wim | 3:2dccfa0121de | 1202 | _wr_reg(0x50, 0); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1203 | _wr_reg(0x51, HEIGHT-1); /* Horizontal GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1204 | _wr_reg(0x52, 0); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1205 | _wr_reg(0x53, WIDTH-1); /* Vertical GRAM End Address (-1) */ |
wim | 0:a8090b59eb05 | 1206 | } |
wim | 0:a8090b59eb05 | 1207 | } |
wim | 0:a8090b59eb05 | 1208 | |
wim | 0:a8090b59eb05 | 1209 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1210 | * Set draw window region * |
wim | 0:a8090b59eb05 | 1211 | * Parameter: * |
wim | 0:a8090b59eb05 | 1212 | * Return: * |
wim | 0:a8090b59eb05 | 1213 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1214 | |
wim | 3:2dccfa0121de | 1215 | void GLCD::setWindow (int x1, int y1, int x2, int y2) { |
wim | 0:a8090b59eb05 | 1216 | |
wim | 2:43ede88fb5a3 | 1217 | if(_driverCode==SSD1289_ID) |
wim | 0:a8090b59eb05 | 1218 | { |
wim | 3:2dccfa0121de | 1219 | // _wr_reg(0x44, x1); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1220 | // _wr_reg(0x44, 0 | (x2<<8)); /* Horizontal GRAM End Address */ |
wim | 0:a8090b59eb05 | 1221 | |
wim | 2:43ede88fb5a3 | 1222 | //Note x,y flipped for landscape |
wim | 3:2dccfa0121de | 1223 | _wr_reg(0x44, ((y2 & 0xFF) <<8) | (y1 & 0xFF)); /* Horizontal GRAM End Address | Start Address */ |
wim | 3:2dccfa0121de | 1224 | _wr_reg(0x45, x1); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1225 | _wr_reg(0x46, x2); /* Vertical GRAM End Address */ |
wim | 0:a8090b59eb05 | 1226 | |
wim | 3:2dccfa0121de | 1227 | _wr_reg(0x4e, y1); // Init x,y to start of window |
wim | 3:2dccfa0121de | 1228 | _wr_reg(0x4f, x1); |
wim | 0:a8090b59eb05 | 1229 | } |
wim | 0:a8090b59eb05 | 1230 | else |
wim | 0:a8090b59eb05 | 1231 | { |
wim | 3:2dccfa0121de | 1232 | _wr_reg(0x50, x1); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1233 | _wr_reg(0x51, x2); /* Horizontal GRAM End Address */ |
wim | 3:2dccfa0121de | 1234 | _wr_reg(0x52, y1); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1235 | _wr_reg(0x53, y2); /* Vertical GRAM End Address */ |
wim | 0:a8090b59eb05 | 1236 | } |
wim | 0:a8090b59eb05 | 1237 | } |
wim | 0:a8090b59eb05 | 1238 | |
wim | 0:a8090b59eb05 | 1239 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1240 | * Draw a pixel in foreground color * |
wim | 0:a8090b59eb05 | 1241 | * Parameter: x: horizontal position * |
wim | 0:a8090b59eb05 | 1242 | * y: vertical position * |
wim | 0:a8090b59eb05 | 1243 | * Return: * |
wim | 0:a8090b59eb05 | 1244 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1245 | |
wim | 2:43ede88fb5a3 | 1246 | void GLCD::drawPixel (unsigned int x, unsigned int y) { |
wim | 0:a8090b59eb05 | 1247 | // Set Cursor |
wim | 2:43ede88fb5a3 | 1248 | if(_driverCode==SSD1289_ID) |
wim | 2:43ede88fb5a3 | 1249 | { |
wim | 3:2dccfa0121de | 1250 | _wr_reg(0x4e, y); |
wim | 3:2dccfa0121de | 1251 | // _wr_reg(0x4f, WIDTH-1-x); |
wim | 3:2dccfa0121de | 1252 | _wr_reg(0x4f, x); |
wim | 2:43ede88fb5a3 | 1253 | } |
wim | 2:43ede88fb5a3 | 1254 | else |
wim | 2:43ede88fb5a3 | 1255 | { |
wim | 3:2dccfa0121de | 1256 | _wr_reg(0x20, y); |
wim | 3:2dccfa0121de | 1257 | // _wr_reg(0x21, WIDTH-1-x); |
wim | 3:2dccfa0121de | 1258 | _wr_reg(0x21, x); |
wim | 2:43ede88fb5a3 | 1259 | } |
wim | 2:43ede88fb5a3 | 1260 | LCD_CS(0) |
wim | 3:2dccfa0121de | 1261 | _wr_cmd(0x22); |
wim | 3:2dccfa0121de | 1262 | _wr_dat(_textColor); |
wim | 2:43ede88fb5a3 | 1263 | LCD_CS(1) |
wim | 2:43ede88fb5a3 | 1264 | } |
wim | 2:43ede88fb5a3 | 1265 | |
wim | 3:2dccfa0121de | 1266 | void GLCD::drawPixel (unsigned int x, unsigned int y, uint16_t color) |
wim | 2:43ede88fb5a3 | 1267 | { |
wim | 2:43ede88fb5a3 | 1268 | // Set Cursor |
wim | 2:43ede88fb5a3 | 1269 | if(_driverCode==SSD1289_ID) |
wim | 0:a8090b59eb05 | 1270 | { |
wim | 3:2dccfa0121de | 1271 | _wr_reg(0x4e, y); |
wim | 3:2dccfa0121de | 1272 | // _wr_reg(0x4f, WIDTH-1-x); |
wim | 3:2dccfa0121de | 1273 | _wr_reg(0x4f, x); |
wim | 0:a8090b59eb05 | 1274 | } |
wim | 0:a8090b59eb05 | 1275 | else |
wim | 0:a8090b59eb05 | 1276 | { |
wim | 3:2dccfa0121de | 1277 | _wr_reg(0x20, y); |
wim | 3:2dccfa0121de | 1278 | _wr_reg(0x21, WIDTH-1-x); |
wim | 0:a8090b59eb05 | 1279 | } |
wim | 0:a8090b59eb05 | 1280 | LCD_CS(0) |
wim | 3:2dccfa0121de | 1281 | _wr_cmd(0x22); |
wim | 3:2dccfa0121de | 1282 | _wr_dat(color); |
wim | 0:a8090b59eb05 | 1283 | LCD_CS(1) |
wim | 0:a8090b59eb05 | 1284 | } |
wim | 0:a8090b59eb05 | 1285 | |
wim | 0:a8090b59eb05 | 1286 | |
wim | 2:43ede88fb5a3 | 1287 | void GLCD::drawPixel (unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b) |
wim | 2:43ede88fb5a3 | 1288 | { |
wim | 3:2dccfa0121de | 1289 | // uint16_t color = ((r & 0xF8)<<8) | ((g & 0xFC)<<3) | ((b & 0xF8)>>3); // rrrrrggggggbbbbb |
wim | 3:2dccfa0121de | 1290 | uint16_t color = RGB24toRGB16(r,g,b); |
wim | 2:43ede88fb5a3 | 1291 | |
wim | 2:43ede88fb5a3 | 1292 | |
wim | 2:43ede88fb5a3 | 1293 | // Set Cursor |
wim | 2:43ede88fb5a3 | 1294 | if(_driverCode==SSD1289_ID) |
wim | 2:43ede88fb5a3 | 1295 | { |
wim | 3:2dccfa0121de | 1296 | _wr_reg(0x4e, y); |
wim | 3:2dccfa0121de | 1297 | // _wr_reg(0x4f, WIDTH-1-x); |
wim | 3:2dccfa0121de | 1298 | _wr_reg(0x4f, x); |
wim | 2:43ede88fb5a3 | 1299 | } |
wim | 2:43ede88fb5a3 | 1300 | else |
wim | 2:43ede88fb5a3 | 1301 | { |
wim | 3:2dccfa0121de | 1302 | _wr_reg(0x20, y); |
wim | 3:2dccfa0121de | 1303 | // _wr_reg(0x21, WIDTH-1-x); |
wim | 3:2dccfa0121de | 1304 | _wr_reg(0x21, x); |
wim | 2:43ede88fb5a3 | 1305 | } |
wim | 2:43ede88fb5a3 | 1306 | LCD_CS(0) |
wim | 3:2dccfa0121de | 1307 | _wr_cmd(0x22); |
wim | 3:2dccfa0121de | 1308 | _wr_dat(color); |
wim | 2:43ede88fb5a3 | 1309 | LCD_CS(1) |
wim | 2:43ede88fb5a3 | 1310 | } |
wim | 2:43ede88fb5a3 | 1311 | |
wim | 2:43ede88fb5a3 | 1312 | |
wim | 2:43ede88fb5a3 | 1313 | |
wim | 2:43ede88fb5a3 | 1314 | |
wim | 0:a8090b59eb05 | 1315 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1316 | * Set foreground color * |
wim | 0:a8090b59eb05 | 1317 | * Parameter: color: foreground color * |
wim | 0:a8090b59eb05 | 1318 | * Return: * |
wim | 0:a8090b59eb05 | 1319 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1320 | |
wim | 3:2dccfa0121de | 1321 | void GLCD::setColor (uint16_t color) { |
wim | 2:43ede88fb5a3 | 1322 | |
wim | 2:43ede88fb5a3 | 1323 | _textColor = color; |
wim | 2:43ede88fb5a3 | 1324 | } |
wim | 0:a8090b59eb05 | 1325 | |
wim | 2:43ede88fb5a3 | 1326 | void GLCD::setColor (uint8_t r, uint8_t g, uint8_t b) { |
wim | 3:2dccfa0121de | 1327 | uint16_t color = RGB24toRGB16(r,g,b); |
wim | 2:43ede88fb5a3 | 1328 | |
wim | 2:43ede88fb5a3 | 1329 | _textColor = color; |
wim | 0:a8090b59eb05 | 1330 | } |
wim | 0:a8090b59eb05 | 1331 | |
wim | 0:a8090b59eb05 | 1332 | |
wim | 2:43ede88fb5a3 | 1333 | |
wim | 2:43ede88fb5a3 | 1334 | |
wim | 2:43ede88fb5a3 | 1335 | |
wim | 0:a8090b59eb05 | 1336 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1337 | * Set background color * |
wim | 0:a8090b59eb05 | 1338 | * Parameter: color: background color * |
wim | 0:a8090b59eb05 | 1339 | * Return: * |
wim | 0:a8090b59eb05 | 1340 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1341 | |
wim | 3:2dccfa0121de | 1342 | void GLCD::setBackColor (uint16_t color) { |
wim | 2:43ede88fb5a3 | 1343 | |
wim | 2:43ede88fb5a3 | 1344 | _backColor = color; |
wim | 2:43ede88fb5a3 | 1345 | } |
wim | 0:a8090b59eb05 | 1346 | |
wim | 2:43ede88fb5a3 | 1347 | |
wim | 2:43ede88fb5a3 | 1348 | void GLCD::setBackColor (uint8_t r, uint8_t g, uint8_t b) { |
wim | 3:2dccfa0121de | 1349 | uint16_t color = RGB24toRGB16(r,g,b); |
wim | 2:43ede88fb5a3 | 1350 | |
wim | 2:43ede88fb5a3 | 1351 | _backColor = color; |
wim | 0:a8090b59eb05 | 1352 | } |
wim | 0:a8090b59eb05 | 1353 | |
wim | 0:a8090b59eb05 | 1354 | |
wim | 0:a8090b59eb05 | 1355 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1356 | * Clear display * |
wim | 0:a8090b59eb05 | 1357 | * Parameter: color: display clearing color * |
wim | 0:a8090b59eb05 | 1358 | * Return: * |
wim | 0:a8090b59eb05 | 1359 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1360 | |
wim | 3:2dccfa0121de | 1361 | void GLCD::clearScreen (uint16_t color) { |
wim | 0:a8090b59eb05 | 1362 | unsigned int i; |
wim | 0:a8090b59eb05 | 1363 | |
wim | 3:2dccfa0121de | 1364 | setWindowMax(); |
wim | 0:a8090b59eb05 | 1365 | |
wim | 0:a8090b59eb05 | 1366 | // Set Cursor |
wim | 2:43ede88fb5a3 | 1367 | if (_driverCode==SSD1289_ID) |
wim | 0:a8090b59eb05 | 1368 | { |
wim | 3:2dccfa0121de | 1369 | _wr_reg(0x4e, 0); |
wim | 3:2dccfa0121de | 1370 | _wr_reg(0x4f, 0); |
wim | 0:a8090b59eb05 | 1371 | } |
wim | 0:a8090b59eb05 | 1372 | else |
wim | 0:a8090b59eb05 | 1373 | { |
wim | 3:2dccfa0121de | 1374 | _wr_reg(0x20, 0); |
wim | 3:2dccfa0121de | 1375 | _wr_reg(0x21, 0); |
wim | 0:a8090b59eb05 | 1376 | } |
wim | 0:a8090b59eb05 | 1377 | LCD_CS(0) |
wim | 3:2dccfa0121de | 1378 | _wr_cmd(0x22); |
wim | 3:2dccfa0121de | 1379 | _wr_dat_start(); |
wim | 0:a8090b59eb05 | 1380 | for(i = 0; i < (WIDTH*HEIGHT); i++) |
wim | 3:2dccfa0121de | 1381 | _wr_dat_only(color); |
wim | 3:2dccfa0121de | 1382 | _wr_dat_stop(); |
wim | 0:a8090b59eb05 | 1383 | } |
wim | 0:a8090b59eb05 | 1384 | |
wim | 0:a8090b59eb05 | 1385 | |
wim | 0:a8090b59eb05 | 1386 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1387 | * Draw character on given position * |
wim | 0:a8090b59eb05 | 1388 | * Parameter: x: horizontal position * |
wim | 0:a8090b59eb05 | 1389 | * y: vertical position * |
wim | 0:a8090b59eb05 | 1390 | * c: pointer to character bitmap * |
wim | 0:a8090b59eb05 | 1391 | * Return: * |
wim | 0:a8090b59eb05 | 1392 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1393 | |
wim | 3:2dccfa0121de | 1394 | void GLCD::DrawChar (unsigned int x, unsigned int y, uint16_t *c) { |
wim | 0:a8090b59eb05 | 1395 | int idx = 0, i, j; |
wim | 0:a8090b59eb05 | 1396 | |
wim | 1:ea0f7b1c5daf | 1397 | //wh x = WIDTH-x-CHAR_W; |
wim | 0:a8090b59eb05 | 1398 | |
wim | 2:43ede88fb5a3 | 1399 | if(_driverCode==SSD1289_ID) |
wim | 0:a8090b59eb05 | 1400 | { |
wim | 3:2dccfa0121de | 1401 | //wh _wr_reg(0x44, y); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1402 | _wr_reg(0x44, y |((y+CHAR_H-1)<<8)); /* Horizontal GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1403 | _wr_reg(0x45, x); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1404 | _wr_reg(0x46, x+CHAR_W-1); /* Vertical GRAM End Address (-1) */ |
wim | 0:a8090b59eb05 | 1405 | |
wim | 3:2dccfa0121de | 1406 | _wr_reg(0x4e, y); |
wim | 3:2dccfa0121de | 1407 | _wr_reg(0x4f, x); |
wim | 0:a8090b59eb05 | 1408 | } |
wim | 0:a8090b59eb05 | 1409 | else |
wim | 0:a8090b59eb05 | 1410 | { |
wim | 3:2dccfa0121de | 1411 | _wr_reg(0x50, y); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1412 | _wr_reg(0x51, y+CHAR_H-1); /* Horizontal GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1413 | _wr_reg(0x52, x); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1414 | _wr_reg(0x53, x+CHAR_W-1); /* Vertical GRAM End Address (-1) */ |
wim | 0:a8090b59eb05 | 1415 | |
wim | 3:2dccfa0121de | 1416 | _wr_reg(0x20, y); |
wim | 3:2dccfa0121de | 1417 | _wr_reg(0x21, x); |
wim | 0:a8090b59eb05 | 1418 | } |
wim | 0:a8090b59eb05 | 1419 | LCD_CS(0) |
wim | 3:2dccfa0121de | 1420 | _wr_cmd(0x22); |
wim | 3:2dccfa0121de | 1421 | _wr_dat_start(); |
wim | 0:a8090b59eb05 | 1422 | for (j = 0; j < CHAR_H; j++) { |
wim | 1:ea0f7b1c5daf | 1423 | //wh for (i = CHAR_W-1; i >= 0; i--) { |
wim | 1:ea0f7b1c5daf | 1424 | for (i = 0; i < CHAR_W; i++) { |
wim | 0:a8090b59eb05 | 1425 | if((c[idx] & (1 << i)) == 0x00) { |
wim | 3:2dccfa0121de | 1426 | _wr_dat_only(_backColor); |
wim | 0:a8090b59eb05 | 1427 | } else { |
wim | 3:2dccfa0121de | 1428 | _wr_dat_only(_textColor); |
wim | 0:a8090b59eb05 | 1429 | } |
wim | 0:a8090b59eb05 | 1430 | } |
wim | 0:a8090b59eb05 | 1431 | c++; |
wim | 0:a8090b59eb05 | 1432 | } |
wim | 3:2dccfa0121de | 1433 | _wr_dat_stop(); |
wim | 0:a8090b59eb05 | 1434 | } |
wim | 0:a8090b59eb05 | 1435 | |
wim | 0:a8090b59eb05 | 1436 | |
wim | 0:a8090b59eb05 | 1437 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1438 | * Display character on given line * |
wim | 0:a8090b59eb05 | 1439 | * Parameter: ln: line number * |
wim | 0:a8090b59eb05 | 1440 | * col: column number * |
wim | 0:a8090b59eb05 | 1441 | * c: ascii character * |
wim | 0:a8090b59eb05 | 1442 | * Return: * |
wim | 0:a8090b59eb05 | 1443 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1444 | |
wim | 3:2dccfa0121de | 1445 | void GLCD::DisplayChar (uint16_t ln, uint16_t col, uint8_t c) { |
wim | 0:a8090b59eb05 | 1446 | |
wim | 0:a8090b59eb05 | 1447 | c -= 32; |
wim | 1:ea0f7b1c5daf | 1448 | // x = column, y = line |
wim | 3:2dccfa0121de | 1449 | DrawChar(col * CHAR_W, ln * CHAR_H, (uint16_t *)&Font_24x16[c * CHAR_H]); |
wim | 1:ea0f7b1c5daf | 1450 | |
wim | 0:a8090b59eb05 | 1451 | } |
wim | 0:a8090b59eb05 | 1452 | |
wim | 0:a8090b59eb05 | 1453 | |
wim | 0:a8090b59eb05 | 1454 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1455 | * Disply string on given line * |
wim | 0:a8090b59eb05 | 1456 | * Parameter: ln: line number * |
wim | 0:a8090b59eb05 | 1457 | * col: column number * |
wim | 0:a8090b59eb05 | 1458 | * s: pointer to string * |
wim | 0:a8090b59eb05 | 1459 | * Return: * |
wim | 0:a8090b59eb05 | 1460 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1461 | |
wim | 3:2dccfa0121de | 1462 | void GLCD::DisplayString (uint16_t ln, uint16_t col, uint8_t *s) { |
wim | 0:a8090b59eb05 | 1463 | |
wim | 3:2dccfa0121de | 1464 | setWindowMax(); |
wim | 0:a8090b59eb05 | 1465 | while (*s) { |
wim | 2:43ede88fb5a3 | 1466 | DisplayChar(ln, col++, *s++); |
wim | 0:a8090b59eb05 | 1467 | } |
wim | 0:a8090b59eb05 | 1468 | } |
wim | 0:a8090b59eb05 | 1469 | |
wim | 0:a8090b59eb05 | 1470 | |
wim | 0:a8090b59eb05 | 1471 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1472 | * Clear given line * |
wim | 0:a8090b59eb05 | 1473 | * Parameter: ln: line number * |
wim | 0:a8090b59eb05 | 1474 | * Return: * |
wim | 0:a8090b59eb05 | 1475 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1476 | |
wim | 3:2dccfa0121de | 1477 | void GLCD::ClearLn (uint16_t ln) { |
wim | 0:a8090b59eb05 | 1478 | |
wim | 3:2dccfa0121de | 1479 | setWindowMax(); |
wim | 3:2dccfa0121de | 1480 | DisplayString(ln, 0, (uint8_t*) " "); |
wim | 0:a8090b59eb05 | 1481 | } |
wim | 0:a8090b59eb05 | 1482 | |
wim | 0:a8090b59eb05 | 1483 | //SSD1289 |
wim | 0:a8090b59eb05 | 1484 | //static void lcd_SetCursor(unsigned int x,unsigned int y) |
wim | 0:a8090b59eb05 | 1485 | //{ |
wim | 0:a8090b59eb05 | 1486 | // write_reg(0x004e,x); /* 0-239 */ |
wim | 0:a8090b59eb05 | 1487 | // write_reg(0x004f,y); /* 0-319 */ |
wim | 0:a8090b59eb05 | 1488 | //} |
wim | 0:a8090b59eb05 | 1489 | |
wim | 0:a8090b59eb05 | 1490 | |
wim | 3:2dccfa0121de | 1491 | |
wim | 3:2dccfa0121de | 1492 | /** @brief Write single character to the display using the 8x8 fontable |
wim | 3:2dccfa0121de | 1493 | * @brief Start at current cursor location |
wim | 3:2dccfa0121de | 1494 | * @param char chr character to write |
wim | 3:2dccfa0121de | 1495 | */ |
wim | 3:2dccfa0121de | 1496 | void GLCD::writeChar(uint8_t chr) { |
wim | 3:2dccfa0121de | 1497 | const uint8_t char_index = chr - 0x20; |
wim | 3:2dccfa0121de | 1498 | |
wim | 3:2dccfa0121de | 1499 | // for (uint8_t i = 0; i < 8; i++) { |
wim | 3:2dccfa0121de | 1500 | // _sendData( font_8x8[char_index][i] ); |
wim | 3:2dccfa0121de | 1501 | // } |
wim | 3:2dccfa0121de | 1502 | |
wim | 3:2dccfa0121de | 1503 | // x = column, y = line |
wim | 3:2dccfa0121de | 1504 | DrawChar(_col * CHAR_W, _ln * CHAR_H, (uint16_t *)&Font_24x16[chr * CHAR_H]); |
wim | 3:2dccfa0121de | 1505 | _col++; |
wim | 3:2dccfa0121de | 1506 | |
wim | 3:2dccfa0121de | 1507 | } |
wim | 3:2dccfa0121de | 1508 | |
wim | 2:43ede88fb5a3 | 1509 | void GLCD::drawHLine(int x, int y, int l) |
wim | 0:a8090b59eb05 | 1510 | { |
wim | 0:a8090b59eb05 | 1511 | // char ch, cl; |
wim | 0:a8090b59eb05 | 1512 | |
wim | 0:a8090b59eb05 | 1513 | // ch=((fcolorr&248)|fcolorg>>5); |
wim | 0:a8090b59eb05 | 1514 | // cl=((fcolorg&28)<<3|fcolorb>>3); |
wim | 0:a8090b59eb05 | 1515 | |
wim | 0:a8090b59eb05 | 1516 | // cbi(P_CS, B_CS); |
wim | 0:a8090b59eb05 | 1517 | |
wim | 3:2dccfa0121de | 1518 | setWindow (x, y, x+l, y); |
wim | 0:a8090b59eb05 | 1519 | |
wim | 0:a8090b59eb05 | 1520 | // for (int i=0; i<l+1; i++) |
wim | 0:a8090b59eb05 | 1521 | // { |
wim | 0:a8090b59eb05 | 1522 | // LCD_Write_DATA(ch, cl); |
wim | 0:a8090b59eb05 | 1523 | // } |
wim | 0:a8090b59eb05 | 1524 | |
wim | 0:a8090b59eb05 | 1525 | LCD_CS(0) |
wim | 3:2dccfa0121de | 1526 | _wr_cmd(0x22); |
wim | 0:a8090b59eb05 | 1527 | |
wim | 3:2dccfa0121de | 1528 | _wr_dat_start(); |
wim | 0:a8090b59eb05 | 1529 | for (int i=0; i<l; i++) |
wim | 3:2dccfa0121de | 1530 | _wr_dat_only(_textColor); |
wim | 3:2dccfa0121de | 1531 | _wr_dat_stop(); |
wim | 0:a8090b59eb05 | 1532 | |
wim | 0:a8090b59eb05 | 1533 | // sbi(P_CS, B_CS); |
wim | 0:a8090b59eb05 | 1534 | // clrXY(); |
wim | 3:2dccfa0121de | 1535 | setWindowMax(); |
wim | 0:a8090b59eb05 | 1536 | } |
wim | 0:a8090b59eb05 | 1537 | |
wim | 2:43ede88fb5a3 | 1538 | void GLCD::drawVLine(int x, int y, int l) |
wim | 0:a8090b59eb05 | 1539 | { |
wim | 0:a8090b59eb05 | 1540 | // char ch, cl; |
wim | 0:a8090b59eb05 | 1541 | |
wim | 0:a8090b59eb05 | 1542 | // ch=((fcolorr&248)|fcolorg>>5); |
wim | 0:a8090b59eb05 | 1543 | // cl=((fcolorg&28)<<3|fcolorb>>3); |
wim | 0:a8090b59eb05 | 1544 | |
wim | 0:a8090b59eb05 | 1545 | // cbi(P_CS, B_CS); |
wim | 3:2dccfa0121de | 1546 | setWindow(x, y, x, y+l); |
wim | 0:a8090b59eb05 | 1547 | // for (int i=0; i<l; i++) |
wim | 0:a8090b59eb05 | 1548 | // { |
wim | 3:2dccfa0121de | 1549 | // GLCD::_wr_dat(ch, cl); |
wim | 0:a8090b59eb05 | 1550 | // } |
wim | 0:a8090b59eb05 | 1551 | LCD_CS(0) |
wim | 3:2dccfa0121de | 1552 | _wr_cmd(0x22); |
wim | 0:a8090b59eb05 | 1553 | |
wim | 3:2dccfa0121de | 1554 | _wr_dat_start(); |
wim | 0:a8090b59eb05 | 1555 | for (int i=0; i<l; i++) |
wim | 3:2dccfa0121de | 1556 | _wr_dat_only(_textColor); |
wim | 3:2dccfa0121de | 1557 | _wr_dat_stop(); |
wim | 0:a8090b59eb05 | 1558 | |
wim | 0:a8090b59eb05 | 1559 | |
wim | 0:a8090b59eb05 | 1560 | // sbi(P_CS, B_CS); |
wim | 0:a8090b59eb05 | 1561 | // clrXY(); |
wim | 3:2dccfa0121de | 1562 | setWindowMax(); |
wim | 0:a8090b59eb05 | 1563 | } |
wim | 0:a8090b59eb05 | 1564 | |
wim | 0:a8090b59eb05 | 1565 | |
wim | 2:43ede88fb5a3 | 1566 | void GLCD::drawRect(int x1, int y1, int x2, int y2) |
wim | 0:a8090b59eb05 | 1567 | { |
wim | 2:43ede88fb5a3 | 1568 | //int tmp; |
wim | 0:a8090b59eb05 | 1569 | |
wim | 0:a8090b59eb05 | 1570 | if (x1>x2) |
wim | 0:a8090b59eb05 | 1571 | { |
wim | 0:a8090b59eb05 | 1572 | swap(int, x1, x2); |
wim | 0:a8090b59eb05 | 1573 | } |
wim | 0:a8090b59eb05 | 1574 | if (y1>y2) |
wim | 0:a8090b59eb05 | 1575 | { |
wim | 0:a8090b59eb05 | 1576 | swap(int, y1, y2); |
wim | 0:a8090b59eb05 | 1577 | } |
wim | 0:a8090b59eb05 | 1578 | |
wim | 2:43ede88fb5a3 | 1579 | drawHLine(x1, y1, x2-x1); |
wim | 2:43ede88fb5a3 | 1580 | drawHLine(x1, y2, x2-x1); |
wim | 2:43ede88fb5a3 | 1581 | drawVLine(x1, y1, y2-y1); |
wim | 2:43ede88fb5a3 | 1582 | drawVLine(x2, y1, y2-y1); |
wim | 2:43ede88fb5a3 | 1583 | } |
wim | 2:43ede88fb5a3 | 1584 | |
wim | 2:43ede88fb5a3 | 1585 | |
wim | 2:43ede88fb5a3 | 1586 | /// Replace by faster Bresenham int |
wim | 2:43ede88fb5a3 | 1587 | void GLCD::drawLine(int x1, int y1, int x2, int y2) |
wim | 2:43ede88fb5a3 | 1588 | { |
wim | 2:43ede88fb5a3 | 1589 | // int tmp; |
wim | 2:43ede88fb5a3 | 1590 | double delta, tx, ty; |
wim | 2:43ede88fb5a3 | 1591 | // double m, b, dx, dy; |
wim | 2:43ede88fb5a3 | 1592 | // char ch, cl; |
wim | 2:43ede88fb5a3 | 1593 | |
wim | 2:43ede88fb5a3 | 1594 | if (((x2-x1)<0)) |
wim | 2:43ede88fb5a3 | 1595 | { |
wim | 2:43ede88fb5a3 | 1596 | swap(int, x1, x2); |
wim | 2:43ede88fb5a3 | 1597 | swap(int, y1, y2); |
wim | 2:43ede88fb5a3 | 1598 | } |
wim | 2:43ede88fb5a3 | 1599 | if (((y2-y1)<0)) |
wim | 2:43ede88fb5a3 | 1600 | { |
wim | 2:43ede88fb5a3 | 1601 | swap(int, x1, x2); |
wim | 2:43ede88fb5a3 | 1602 | swap(int, y1, y2); |
wim | 2:43ede88fb5a3 | 1603 | } |
wim | 2:43ede88fb5a3 | 1604 | |
wim | 2:43ede88fb5a3 | 1605 | if (y1==y2) |
wim | 2:43ede88fb5a3 | 1606 | { |
wim | 2:43ede88fb5a3 | 1607 | if (x1>x2) |
wim | 2:43ede88fb5a3 | 1608 | { |
wim | 2:43ede88fb5a3 | 1609 | swap(int, x1, x2); |
wim | 2:43ede88fb5a3 | 1610 | } |
wim | 2:43ede88fb5a3 | 1611 | drawHLine(x1, y1, x2-x1); |
wim | 2:43ede88fb5a3 | 1612 | } |
wim | 2:43ede88fb5a3 | 1613 | else if (x1==x2) |
wim | 2:43ede88fb5a3 | 1614 | { |
wim | 2:43ede88fb5a3 | 1615 | if (y1>y2) |
wim | 2:43ede88fb5a3 | 1616 | { |
wim | 2:43ede88fb5a3 | 1617 | swap(int, y1, y2); |
wim | 2:43ede88fb5a3 | 1618 | } |
wim | 2:43ede88fb5a3 | 1619 | drawVLine(x1, y1, y2-y1); |
wim | 2:43ede88fb5a3 | 1620 | } |
wim | 2:43ede88fb5a3 | 1621 | else if (abs(x2-x1)>abs(y2-y1)) |
wim | 2:43ede88fb5a3 | 1622 | { |
wim | 2:43ede88fb5a3 | 1623 | delta=(double(y2-y1)/double(x2-x1)); |
wim | 2:43ede88fb5a3 | 1624 | ty=double(y1); |
wim | 2:43ede88fb5a3 | 1625 | if (x1>x2) |
wim | 2:43ede88fb5a3 | 1626 | { |
wim | 2:43ede88fb5a3 | 1627 | for (int i=x1; i>=x2; i--) |
wim | 2:43ede88fb5a3 | 1628 | { |
wim | 2:43ede88fb5a3 | 1629 | drawPixel(i, int(ty+0.5)); |
wim | 2:43ede88fb5a3 | 1630 | ty=ty-delta; |
wim | 2:43ede88fb5a3 | 1631 | } |
wim | 2:43ede88fb5a3 | 1632 | } |
wim | 2:43ede88fb5a3 | 1633 | else |
wim | 2:43ede88fb5a3 | 1634 | { |
wim | 2:43ede88fb5a3 | 1635 | for (int i=x1; i<=x2; i++) |
wim | 2:43ede88fb5a3 | 1636 | { |
wim | 2:43ede88fb5a3 | 1637 | drawPixel(i, int(ty+0.5)); |
wim | 2:43ede88fb5a3 | 1638 | ty=ty+delta; |
wim | 2:43ede88fb5a3 | 1639 | } |
wim | 2:43ede88fb5a3 | 1640 | } |
wim | 2:43ede88fb5a3 | 1641 | |
wim | 2:43ede88fb5a3 | 1642 | } |
wim | 2:43ede88fb5a3 | 1643 | else |
wim | 2:43ede88fb5a3 | 1644 | { |
wim | 2:43ede88fb5a3 | 1645 | delta=(float(x2-x1)/float(y2-y1)); |
wim | 2:43ede88fb5a3 | 1646 | tx=float(x1); |
wim | 2:43ede88fb5a3 | 1647 | if (y1>y2) |
wim | 2:43ede88fb5a3 | 1648 | { |
wim | 2:43ede88fb5a3 | 1649 | for (int i=y2+1; i>y1; i--) |
wim | 2:43ede88fb5a3 | 1650 | { |
wim | 2:43ede88fb5a3 | 1651 | drawPixel(int(tx+0.5), i); |
wim | 2:43ede88fb5a3 | 1652 | tx=tx+delta; |
wim | 2:43ede88fb5a3 | 1653 | } |
wim | 2:43ede88fb5a3 | 1654 | } |
wim | 2:43ede88fb5a3 | 1655 | else |
wim | 2:43ede88fb5a3 | 1656 | { |
wim | 2:43ede88fb5a3 | 1657 | for (int i=y1; i<y2+1; i++) |
wim | 2:43ede88fb5a3 | 1658 | { |
wim | 2:43ede88fb5a3 | 1659 | drawPixel(int(tx+0.5), i); |
wim | 2:43ede88fb5a3 | 1660 | tx=tx+delta; |
wim | 2:43ede88fb5a3 | 1661 | } |
wim | 2:43ede88fb5a3 | 1662 | } |
wim | 2:43ede88fb5a3 | 1663 | } |
wim | 2:43ede88fb5a3 | 1664 | |
wim | 3:2dccfa0121de | 1665 | setWindowMax(); |
wim | 2:43ede88fb5a3 | 1666 | } |
wim | 2:43ede88fb5a3 | 1667 | |
wim | 2:43ede88fb5a3 | 1668 | void GLCD::drawRoundRect(int x1, int y1, int x2, int y2) |
wim | 2:43ede88fb5a3 | 1669 | { |
wim | 2:43ede88fb5a3 | 1670 | // int tmp; |
wim | 2:43ede88fb5a3 | 1671 | |
wim | 2:43ede88fb5a3 | 1672 | if (x1>x2) |
wim | 2:43ede88fb5a3 | 1673 | { |
wim | 2:43ede88fb5a3 | 1674 | swap(int, x1, x2); |
wim | 2:43ede88fb5a3 | 1675 | } |
wim | 2:43ede88fb5a3 | 1676 | if (y1>y2) |
wim | 2:43ede88fb5a3 | 1677 | { |
wim | 2:43ede88fb5a3 | 1678 | swap(int, y1, y2); |
wim | 2:43ede88fb5a3 | 1679 | } |
wim | 2:43ede88fb5a3 | 1680 | if ((x2-x1)>4 && (y2-y1)>4) |
wim | 2:43ede88fb5a3 | 1681 | { |
wim | 2:43ede88fb5a3 | 1682 | drawPixel(x1+1,y1+1); |
wim | 2:43ede88fb5a3 | 1683 | drawPixel(x2-1,y1+1); |
wim | 2:43ede88fb5a3 | 1684 | drawPixel(x1+1,y2-1); |
wim | 2:43ede88fb5a3 | 1685 | drawPixel(x2-1,y2-1); |
wim | 2:43ede88fb5a3 | 1686 | drawHLine(x1+2, y1, x2-x1-4); |
wim | 2:43ede88fb5a3 | 1687 | drawHLine(x1+2, y2, x2-x1-4); |
wim | 2:43ede88fb5a3 | 1688 | drawVLine(x1, y1+2, y2-y1-4); |
wim | 2:43ede88fb5a3 | 1689 | drawVLine(x2, y1+2, y2-y1-4); |
wim | 2:43ede88fb5a3 | 1690 | } |
wim | 0:a8090b59eb05 | 1691 | } |
wim | 0:a8090b59eb05 | 1692 | |
wim | 2:43ede88fb5a3 | 1693 | void GLCD::fillRect(int x1, int y1, int x2, int y2) |
wim | 2:43ede88fb5a3 | 1694 | { |
wim | 2:43ede88fb5a3 | 1695 | // int tmp; |
wim | 2:43ede88fb5a3 | 1696 | |
wim | 2:43ede88fb5a3 | 1697 | if (x1>x2) |
wim | 2:43ede88fb5a3 | 1698 | { |
wim | 2:43ede88fb5a3 | 1699 | swap(int, x1, x2); |
wim | 2:43ede88fb5a3 | 1700 | } |
wim | 2:43ede88fb5a3 | 1701 | if (y1>y2) |
wim | 2:43ede88fb5a3 | 1702 | { |
wim | 2:43ede88fb5a3 | 1703 | swap(int, y1, y2); |
wim | 2:43ede88fb5a3 | 1704 | } |
wim | 2:43ede88fb5a3 | 1705 | |
wim | 2:43ede88fb5a3 | 1706 | // if (orient==PORTRAIT) |
wim | 2:43ede88fb5a3 | 1707 | // { |
wim | 2:43ede88fb5a3 | 1708 | // for (int i=0; i<((y2-y1)/2)+1; i++) |
wim | 2:43ede88fb5a3 | 1709 | // { |
wim | 2:43ede88fb5a3 | 1710 | // drawHLine(x1, y1+i, x2-x1); |
wim | 2:43ede88fb5a3 | 1711 | // drawHLine(x1, y2-i, x2-x1); |
wim | 2:43ede88fb5a3 | 1712 | // } |
wim | 2:43ede88fb5a3 | 1713 | // } |
wim | 2:43ede88fb5a3 | 1714 | // else |
wim | 2:43ede88fb5a3 | 1715 | // { |
wim | 2:43ede88fb5a3 | 1716 | for (int i=0; i<((x2-x1)/2)+1; i++) |
wim | 2:43ede88fb5a3 | 1717 | { |
wim | 2:43ede88fb5a3 | 1718 | drawVLine(x1+i, y1, y2-y1); |
wim | 2:43ede88fb5a3 | 1719 | drawVLine(x2-i, y1, y2-y1); |
wim | 2:43ede88fb5a3 | 1720 | } |
wim | 2:43ede88fb5a3 | 1721 | // } |
wim | 2:43ede88fb5a3 | 1722 | } |
wim | 2:43ede88fb5a3 | 1723 | |
wim | 2:43ede88fb5a3 | 1724 | void GLCD::fillRoundRect(int x1, int y1, int x2, int y2) |
wim | 2:43ede88fb5a3 | 1725 | { |
wim | 2:43ede88fb5a3 | 1726 | // int tmp; |
wim | 2:43ede88fb5a3 | 1727 | |
wim | 2:43ede88fb5a3 | 1728 | if (x1>x2) |
wim | 2:43ede88fb5a3 | 1729 | { |
wim | 2:43ede88fb5a3 | 1730 | swap(int, x1, x2); |
wim | 2:43ede88fb5a3 | 1731 | } |
wim | 2:43ede88fb5a3 | 1732 | if (y1>y2) |
wim | 2:43ede88fb5a3 | 1733 | { |
wim | 2:43ede88fb5a3 | 1734 | swap(int, y1, y2); |
wim | 2:43ede88fb5a3 | 1735 | } |
wim | 2:43ede88fb5a3 | 1736 | |
wim | 2:43ede88fb5a3 | 1737 | if ((x2-x1)>4 && (y2-y1)>4) |
wim | 2:43ede88fb5a3 | 1738 | { |
wim | 2:43ede88fb5a3 | 1739 | for (int i=0; i<((y2-y1)/2)+1; i++) |
wim | 2:43ede88fb5a3 | 1740 | { |
wim | 2:43ede88fb5a3 | 1741 | switch(i) |
wim | 2:43ede88fb5a3 | 1742 | { |
wim | 2:43ede88fb5a3 | 1743 | case 0: |
wim | 2:43ede88fb5a3 | 1744 | drawHLine(x1+2, y1+i, x2-x1-4); |
wim | 2:43ede88fb5a3 | 1745 | drawHLine(x1+2, y2-i, x2-x1-4); |
wim | 2:43ede88fb5a3 | 1746 | break; |
wim | 2:43ede88fb5a3 | 1747 | case 1: |
wim | 2:43ede88fb5a3 | 1748 | drawHLine(x1+1, y1+i, x2-x1-2); |
wim | 2:43ede88fb5a3 | 1749 | drawHLine(x1+1, y2-i, x2-x1-2); |
wim | 2:43ede88fb5a3 | 1750 | break; |
wim | 2:43ede88fb5a3 | 1751 | default: |
wim | 2:43ede88fb5a3 | 1752 | drawHLine(x1, y1+i, x2-x1); |
wim | 2:43ede88fb5a3 | 1753 | drawHLine(x1, y2-i, x2-x1); |
wim | 2:43ede88fb5a3 | 1754 | } |
wim | 2:43ede88fb5a3 | 1755 | } |
wim | 2:43ede88fb5a3 | 1756 | } |
wim | 2:43ede88fb5a3 | 1757 | } |
wim | 2:43ede88fb5a3 | 1758 | |
wim | 2:43ede88fb5a3 | 1759 | void GLCD::drawCircle(int x, int y, int radius) |
wim | 2:43ede88fb5a3 | 1760 | { |
wim | 2:43ede88fb5a3 | 1761 | int f = 1 - radius; |
wim | 2:43ede88fb5a3 | 1762 | int ddF_x = 1; |
wim | 2:43ede88fb5a3 | 1763 | int ddF_y = -2 * radius; |
wim | 2:43ede88fb5a3 | 1764 | int x1 = 0; |
wim | 2:43ede88fb5a3 | 1765 | int y1 = radius; |
wim | 2:43ede88fb5a3 | 1766 | // char ch, cl; |
wim | 2:43ede88fb5a3 | 1767 | |
wim | 2:43ede88fb5a3 | 1768 | // ch=((fcolorr&248)|fcolorg>>5); |
wim | 2:43ede88fb5a3 | 1769 | // cl=((fcolorg&28)<<3|fcolorb>>3); |
wim | 2:43ede88fb5a3 | 1770 | |
wim | 2:43ede88fb5a3 | 1771 | // cbi(P_CS, B_CS); |
wim | 2:43ede88fb5a3 | 1772 | drawPixel(x, y + radius); |
wim | 2:43ede88fb5a3 | 1773 | |
wim | 2:43ede88fb5a3 | 1774 | drawPixel(x, y - radius); |
wim | 2:43ede88fb5a3 | 1775 | |
wim | 2:43ede88fb5a3 | 1776 | drawPixel(x + radius, y); |
wim | 2:43ede88fb5a3 | 1777 | |
wim | 2:43ede88fb5a3 | 1778 | drawPixel(x - radius, y); |
wim | 2:43ede88fb5a3 | 1779 | |
wim | 2:43ede88fb5a3 | 1780 | |
wim | 2:43ede88fb5a3 | 1781 | while(x1 < y1) |
wim | 2:43ede88fb5a3 | 1782 | { |
wim | 2:43ede88fb5a3 | 1783 | if(f >= 0) |
wim | 2:43ede88fb5a3 | 1784 | { |
wim | 2:43ede88fb5a3 | 1785 | y1--; |
wim | 2:43ede88fb5a3 | 1786 | ddF_y += 2; |
wim | 2:43ede88fb5a3 | 1787 | f += ddF_y; |
wim | 2:43ede88fb5a3 | 1788 | } |
wim | 2:43ede88fb5a3 | 1789 | x1++; |
wim | 2:43ede88fb5a3 | 1790 | ddF_x += 2; |
wim | 2:43ede88fb5a3 | 1791 | f += ddF_x; |
wim | 2:43ede88fb5a3 | 1792 | drawPixel(x + x1, y + y1); |
wim | 2:43ede88fb5a3 | 1793 | |
wim | 2:43ede88fb5a3 | 1794 | drawPixel(x - x1, y + y1); |
wim | 2:43ede88fb5a3 | 1795 | |
wim | 2:43ede88fb5a3 | 1796 | drawPixel(x + x1, y - y1); |
wim | 2:43ede88fb5a3 | 1797 | |
wim | 2:43ede88fb5a3 | 1798 | drawPixel(x - x1, y - y1); |
wim | 2:43ede88fb5a3 | 1799 | |
wim | 2:43ede88fb5a3 | 1800 | drawPixel(x + y1, y + x1); |
wim | 2:43ede88fb5a3 | 1801 | |
wim | 2:43ede88fb5a3 | 1802 | drawPixel(x - y1, y + x1); |
wim | 2:43ede88fb5a3 | 1803 | |
wim | 2:43ede88fb5a3 | 1804 | drawPixel(x + y1, y - x1); |
wim | 2:43ede88fb5a3 | 1805 | |
wim | 2:43ede88fb5a3 | 1806 | drawPixel(x - y1, y - x1); |
wim | 2:43ede88fb5a3 | 1807 | |
wim | 2:43ede88fb5a3 | 1808 | } |
wim | 2:43ede88fb5a3 | 1809 | // sbi(P_CS, B_CS); |
wim | 2:43ede88fb5a3 | 1810 | // clrXY(); |
wim | 2:43ede88fb5a3 | 1811 | } |
wim | 2:43ede88fb5a3 | 1812 | |
wim | 2:43ede88fb5a3 | 1813 | void GLCD::fillCircle(int x, int y, int radius) |
wim | 2:43ede88fb5a3 | 1814 | { |
wim | 2:43ede88fb5a3 | 1815 | // cbi(P_CS, B_CS); |
wim | 2:43ede88fb5a3 | 1816 | for(int y1=-radius; y1<=radius; y1++) |
wim | 2:43ede88fb5a3 | 1817 | for(int x1=-radius; x1<=radius; x1++) |
wim | 2:43ede88fb5a3 | 1818 | if(x1*x1+y1*y1 <= radius*radius) |
wim | 2:43ede88fb5a3 | 1819 | { |
wim | 2:43ede88fb5a3 | 1820 | drawPixel(x+x1, y+y1); |
wim | 2:43ede88fb5a3 | 1821 | } |
wim | 2:43ede88fb5a3 | 1822 | // sbi(P_CS, B_CS); |
wim | 2:43ede88fb5a3 | 1823 | // clrXY(); |
wim | 2:43ede88fb5a3 | 1824 | } |
wim | 2:43ede88fb5a3 | 1825 | |
wim | 2:43ede88fb5a3 | 1826 | |
wim | 3:2dccfa0121de | 1827 | //not yet checked |
wim | 2:43ede88fb5a3 | 1828 | void GLCD::lcdOff() |
wim | 2:43ede88fb5a3 | 1829 | { |
wim | 3:2dccfa0121de | 1830 | _wr_reg(0x0007, 0x0000); |
wim | 2:43ede88fb5a3 | 1831 | } |
wim | 2:43ede88fb5a3 | 1832 | |
wim | 2:43ede88fb5a3 | 1833 | void GLCD::lcdOn() |
wim | 2:43ede88fb5a3 | 1834 | { |
wim | 3:2dccfa0121de | 1835 | _wr_reg(0x0007, 0x0173); |
wim | 2:43ede88fb5a3 | 1836 | } |
wim | 2:43ede88fb5a3 | 1837 | |
wim | 3:2dccfa0121de | 1838 | void GLCD::setContrast(uint8_t c) |
wim | 2:43ede88fb5a3 | 1839 | { |
wim | 2:43ede88fb5a3 | 1840 | } |
wim | 2:43ede88fb5a3 | 1841 | |
wim | 2:43ede88fb5a3 | 1842 | |
wim | 0:a8090b59eb05 | 1843 | |
wim | 0:a8090b59eb05 | 1844 | |
wim | 0:a8090b59eb05 | 1845 | |
wim | 0:a8090b59eb05 | 1846 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1847 | * Draw bargraph * |
wim | 0:a8090b59eb05 | 1848 | * Parameter: x: horizontal position * |
wim | 0:a8090b59eb05 | 1849 | * y: vertical position * |
wim | 0:a8090b59eb05 | 1850 | * w: maximum width of bargraph (in pixels) * |
wim | 0:a8090b59eb05 | 1851 | * val: value of active bargraph (in 1/1024) * |
wim | 0:a8090b59eb05 | 1852 | * Return: * |
wim | 0:a8090b59eb05 | 1853 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1854 | |
wim | 2:43ede88fb5a3 | 1855 | void GLCD::Bargraph (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val) { |
wim | 0:a8090b59eb05 | 1856 | int i,j; |
wim | 0:a8090b59eb05 | 1857 | |
wim | 0:a8090b59eb05 | 1858 | x = WIDTH-x-w; |
wim | 2:43ede88fb5a3 | 1859 | if(_driverCode==SSD1289_ID) |
wim | 0:a8090b59eb05 | 1860 | { |
wim | 3:2dccfa0121de | 1861 | _wr_reg(0x44, y); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1862 | _wr_reg(0x44, y |((y+CHAR_H-1)<<8)); /* Horizontal GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1863 | _wr_reg(0x45, x); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1864 | _wr_reg(0x46, x+w-1); /* Vertical GRAM End Address (-1) */ |
wim | 0:a8090b59eb05 | 1865 | } |
wim | 0:a8090b59eb05 | 1866 | else |
wim | 0:a8090b59eb05 | 1867 | { |
wim | 3:2dccfa0121de | 1868 | _wr_reg(0x50, y); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1869 | _wr_reg(0x51, y+CHAR_H-1); /* Horizontal GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1870 | _wr_reg(0x52, x); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1871 | _wr_reg(0x53, x+w-1); /* Vertical GRAM End Address (-1) */ |
wim | 0:a8090b59eb05 | 1872 | } |
wim | 0:a8090b59eb05 | 1873 | |
wim | 0:a8090b59eb05 | 1874 | val = (val * w) >> 10; /* Scale value for 24x12 characters */ |
wim | 2:43ede88fb5a3 | 1875 | if(_driverCode==SSD1289_ID) |
wim | 0:a8090b59eb05 | 1876 | { |
wim | 3:2dccfa0121de | 1877 | _wr_reg(0x4e, y); |
wim | 3:2dccfa0121de | 1878 | _wr_reg(0x4f, x); |
wim | 0:a8090b59eb05 | 1879 | } |
wim | 0:a8090b59eb05 | 1880 | else |
wim | 0:a8090b59eb05 | 1881 | { |
wim | 3:2dccfa0121de | 1882 | _wr_reg(0x20, y); |
wim | 3:2dccfa0121de | 1883 | _wr_reg(0x21, x); |
wim | 0:a8090b59eb05 | 1884 | } |
wim | 0:a8090b59eb05 | 1885 | LCD_CS(0) |
wim | 3:2dccfa0121de | 1886 | _wr_cmd(0x22); |
wim | 3:2dccfa0121de | 1887 | _wr_dat_start(); |
wim | 0:a8090b59eb05 | 1888 | for (i = 0; i < h; i++) { |
wim | 0:a8090b59eb05 | 1889 | for (j = w-1; j >= 0; j--) { |
wim | 0:a8090b59eb05 | 1890 | if(j >= val) { |
wim | 3:2dccfa0121de | 1891 | _wr_dat_only(_backColor); |
wim | 0:a8090b59eb05 | 1892 | } else { |
wim | 3:2dccfa0121de | 1893 | _wr_dat_only(_textColor); |
wim | 0:a8090b59eb05 | 1894 | } |
wim | 0:a8090b59eb05 | 1895 | } |
wim | 0:a8090b59eb05 | 1896 | } |
wim | 3:2dccfa0121de | 1897 | _wr_dat_stop(); |
wim | 0:a8090b59eb05 | 1898 | } |
wim | 0:a8090b59eb05 | 1899 | |
wim | 0:a8090b59eb05 | 1900 | |
wim | 0:a8090b59eb05 | 1901 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1902 | * Display graphical bitmap image at position x horizontally and y vertically * |
wim | 0:a8090b59eb05 | 1903 | * (This function is optimized for 16 bits per pixel format, it has to be * |
wim | 0:a8090b59eb05 | 1904 | * adapted for any other bits per pixel format) * |
wim | 0:a8090b59eb05 | 1905 | * Parameter: x: horizontal position * |
wim | 0:a8090b59eb05 | 1906 | * y: vertical position * |
wim | 0:a8090b59eb05 | 1907 | * w: width of bitmap * |
wim | 0:a8090b59eb05 | 1908 | * h: height of bitmap * |
wim | 0:a8090b59eb05 | 1909 | * bitmap: address at which the bitmap data resides * |
wim | 0:a8090b59eb05 | 1910 | * Return: * |
wim | 0:a8090b59eb05 | 1911 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1912 | |
wim | 3:2dccfa0121de | 1913 | void GLCD::Bitmap (unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint8_t *bitmap) { |
wim | 0:a8090b59eb05 | 1914 | unsigned int i, j; |
wim | 3:2dccfa0121de | 1915 | uint16_t *bitmap_ptr = (uint16_t *)bitmap; |
wim | 0:a8090b59eb05 | 1916 | |
wim | 0:a8090b59eb05 | 1917 | x = WIDTH-x-w; |
wim | 2:43ede88fb5a3 | 1918 | if(_driverCode==SSD1289_ID) |
wim | 0:a8090b59eb05 | 1919 | { |
wim | 3:2dccfa0121de | 1920 | _wr_reg(0x44, y); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1921 | _wr_reg(0x44, y |((y+h-1)<<8)); /* Horizontal GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1922 | _wr_reg(0x45, x); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1923 | _wr_reg(0x46, x+w-1); /* Vertical GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1924 | _wr_reg(0x4e, y); |
wim | 3:2dccfa0121de | 1925 | _wr_reg(0x4f, x); |
wim | 0:a8090b59eb05 | 1926 | } |
wim | 0:a8090b59eb05 | 1927 | else |
wim | 0:a8090b59eb05 | 1928 | { |
wim | 3:2dccfa0121de | 1929 | _wr_reg(0x50, y); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1930 | _wr_reg(0x51, y+h-1); /* Horizontal GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1931 | _wr_reg(0x52, x); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1932 | _wr_reg(0x53, x+w-1); /* Vertical GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1933 | _wr_reg(0x20, y); |
wim | 3:2dccfa0121de | 1934 | _wr_reg(0x21, x); |
wim | 0:a8090b59eb05 | 1935 | } |
wim | 0:a8090b59eb05 | 1936 | LCD_CS(0) |
wim | 3:2dccfa0121de | 1937 | _wr_cmd(0x22); |
wim | 3:2dccfa0121de | 1938 | _wr_dat_start(); |
wim | 0:a8090b59eb05 | 1939 | for (j = 0; j < h; j++) { |
wim | 0:a8090b59eb05 | 1940 | bitmap_ptr += w-1; |
wim | 0:a8090b59eb05 | 1941 | for (i = 0; i < w; i++) { |
wim | 3:2dccfa0121de | 1942 | _wr_dat_only(*bitmap_ptr--); |
wim | 0:a8090b59eb05 | 1943 | } |
wim | 0:a8090b59eb05 | 1944 | bitmap_ptr += w+1; |
wim | 0:a8090b59eb05 | 1945 | } |
wim | 3:2dccfa0121de | 1946 | _wr_dat_stop(); |
wim | 0:a8090b59eb05 | 1947 | } |
wim | 0:a8090b59eb05 | 1948 | |
wim | 0:a8090b59eb05 | 1949 | |
wim | 0:a8090b59eb05 | 1950 | /******************************************************************************* |
wim | 0:a8090b59eb05 | 1951 | * Display graphical bmp file image at position x horizontally and y vertically * |
wim | 0:a8090b59eb05 | 1952 | * (This function is optimized for 16 bits per pixel format, it has to be * |
wim | 0:a8090b59eb05 | 1953 | * adapted for any other bits per pixel format) * |
wim | 0:a8090b59eb05 | 1954 | * Parameter: x: horizontal position * |
wim | 0:a8090b59eb05 | 1955 | * y: vertical position * |
wim | 0:a8090b59eb05 | 1956 | * w: width of bitmap * |
wim | 0:a8090b59eb05 | 1957 | * h: height of bitmap * |
wim | 0:a8090b59eb05 | 1958 | * bmp: address at which the bmp data resides * |
wim | 0:a8090b59eb05 | 1959 | * Return: * |
wim | 0:a8090b59eb05 | 1960 | *******************************************************************************/ |
wim | 0:a8090b59eb05 | 1961 | |
wim | 3:2dccfa0121de | 1962 | void GLCD::Bmp (unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint8_t *bmp) { |
wim | 0:a8090b59eb05 | 1963 | unsigned int i, j; |
wim | 3:2dccfa0121de | 1964 | uint16_t *bitmap_ptr = (uint16_t *)bmp; |
wim | 0:a8090b59eb05 | 1965 | |
wim | 1:ea0f7b1c5daf | 1966 | //wh x = WIDTH-x-w; |
wim | 0:a8090b59eb05 | 1967 | |
wim | 2:43ede88fb5a3 | 1968 | if(_driverCode==SSD1289_ID) |
wim | 0:a8090b59eb05 | 1969 | { |
wim | 3:2dccfa0121de | 1970 | //wh _wr_reg(0x44, y); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1971 | _wr_reg(0x44, y |((y+h-1)<<8)); /* Horizontal GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1972 | _wr_reg(0x45, x); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1973 | _wr_reg(0x46, x+w-1); /* Vertical GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1974 | _wr_reg(0x4e, y); |
wim | 3:2dccfa0121de | 1975 | _wr_reg(0x4f, x); |
wim | 0:a8090b59eb05 | 1976 | } |
wim | 0:a8090b59eb05 | 1977 | else |
wim | 0:a8090b59eb05 | 1978 | { |
wim | 3:2dccfa0121de | 1979 | _wr_reg(0x50, y); /* Horizontal GRAM Start Address */ |
wim | 3:2dccfa0121de | 1980 | _wr_reg(0x51, y+h-1); /* Horizontal GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1981 | _wr_reg(0x52, x); /* Vertical GRAM Start Address */ |
wim | 3:2dccfa0121de | 1982 | _wr_reg(0x53, x+w-1); /* Vertical GRAM End Address (-1) */ |
wim | 3:2dccfa0121de | 1983 | _wr_reg(0x20, y); |
wim | 3:2dccfa0121de | 1984 | _wr_reg(0x21, x); |
wim | 0:a8090b59eb05 | 1985 | } |
wim | 0:a8090b59eb05 | 1986 | LCD_CS(0) |
wim | 3:2dccfa0121de | 1987 | _wr_cmd(0x22); |
wim | 3:2dccfa0121de | 1988 | _wr_dat_start(); |
wim | 1:ea0f7b1c5daf | 1989 | // bitmap_ptr += (h*w)-1; |
wim | 1:ea0f7b1c5daf | 1990 | // for (j = 0; j < h; j++) { |
wim | 1:ea0f7b1c5daf | 1991 | // for (i = 0; i < w; i++) { |
wim | 3:2dccfa0121de | 1992 | // _wr_dat_only(*bitmap_ptr--); |
wim | 1:ea0f7b1c5daf | 1993 | // } |
wim | 1:ea0f7b1c5daf | 1994 | // } |
wim | 1:ea0f7b1c5daf | 1995 | |
wim | 1:ea0f7b1c5daf | 1996 | |
wim | 0:a8090b59eb05 | 1997 | for (j = 0; j < h; j++) { |
wim | 0:a8090b59eb05 | 1998 | for (i = 0; i < w; i++) { |
wim | 3:2dccfa0121de | 1999 | _wr_dat_only(*bitmap_ptr++); |
wim | 0:a8090b59eb05 | 2000 | } |
wim | 0:a8090b59eb05 | 2001 | } |
wim | 1:ea0f7b1c5daf | 2002 | |
wim | 1:ea0f7b1c5daf | 2003 | |
wim | 3:2dccfa0121de | 2004 | _wr_dat_stop(); |
wim | 3:2dccfa0121de | 2005 | } |
wim | 3:2dccfa0121de | 2006 | |
wim | 3:2dccfa0121de | 2007 | |
wim | 3:2dccfa0121de | 2008 | |
wim | 3:2dccfa0121de | 2009 | |
wim | 3:2dccfa0121de | 2010 | |
wim | 3:2dccfa0121de | 2011 | #if(0) |
wim | 3:2dccfa0121de | 2012 | |
wim | 3:2dccfa0121de | 2013 | void LCD_PolyLine(pPoint Points, uint16_t PointCount) |
wim | 3:2dccfa0121de | 2014 | { |
wim | 3:2dccfa0121de | 2015 | int16_t X = 0, Y = 0; |
wim | 3:2dccfa0121de | 2016 | |
wim | 3:2dccfa0121de | 2017 | if(PointCount < 2) |
wim | 3:2dccfa0121de | 2018 | { |
wim | 3:2dccfa0121de | 2019 | return; |
wim | 3:2dccfa0121de | 2020 | } |
wim | 3:2dccfa0121de | 2021 | |
wim | 3:2dccfa0121de | 2022 | while(--PointCount) |
wim | 3:2dccfa0121de | 2023 | { |
wim | 3:2dccfa0121de | 2024 | X = Points->X; |
wim | 3:2dccfa0121de | 2025 | Y = Points->Y; |
wim | 3:2dccfa0121de | 2026 | Points++; |
wim | 3:2dccfa0121de | 2027 | LCD_DrawUniLine(X, Y, Points->X, Points->Y); |
wim | 3:2dccfa0121de | 2028 | } |
wim | 3:2dccfa0121de | 2029 | } |
wim | 3:2dccfa0121de | 2030 | |
wim | 3:2dccfa0121de | 2031 | static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed) |
wim | 3:2dccfa0121de | 2032 | { |
wim | 3:2dccfa0121de | 2033 | int16_t X = 0, Y = 0; |
wim | 3:2dccfa0121de | 2034 | pPoint First = Points; |
wim | 3:2dccfa0121de | 2035 | |
wim | 3:2dccfa0121de | 2036 | if(PointCount < 2) |
wim | 3:2dccfa0121de | 2037 | { |
wim | 3:2dccfa0121de | 2038 | return; |
wim | 3:2dccfa0121de | 2039 | } |
wim | 3:2dccfa0121de | 2040 | X = Points->X; |
wim | 3:2dccfa0121de | 2041 | Y = Points->Y; |
wim | 3:2dccfa0121de | 2042 | while(--PointCount) |
wim | 3:2dccfa0121de | 2043 | { |
wim | 3:2dccfa0121de | 2044 | Points++; |
wim | 3:2dccfa0121de | 2045 | LCD_DrawUniLine(X, Y, X + Points->X, Y + Points->Y); |
wim | 3:2dccfa0121de | 2046 | X = X + Points->X; |
wim | 3:2dccfa0121de | 2047 | Y = Y + Points->Y; |
wim | 3:2dccfa0121de | 2048 | } |
wim | 3:2dccfa0121de | 2049 | if(Closed) |
wim | 3:2dccfa0121de | 2050 | { |
wim | 3:2dccfa0121de | 2051 | LCD_DrawUniLine(First->X, First->Y, X, Y); |
wim | 3:2dccfa0121de | 2052 | } |
wim | 3:2dccfa0121de | 2053 | } |
wim | 3:2dccfa0121de | 2054 | |
wim | 3:2dccfa0121de | 2055 | void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount) |
wim | 3:2dccfa0121de | 2056 | { |
wim | 3:2dccfa0121de | 2057 | LCD_PolyLine(Points, PointCount); |
wim | 3:2dccfa0121de | 2058 | LCD_DrawUniLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y); |
wim | 3:2dccfa0121de | 2059 | } |
wim | 3:2dccfa0121de | 2060 | |
wim | 3:2dccfa0121de | 2061 | |
wim | 3:2dccfa0121de | 2062 | void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount) |
wim | 3:2dccfa0121de | 2063 | { |
wim | 3:2dccfa0121de | 2064 | LCD_PolyLineRelativeClosed(Points, PointCount, 0); |
wim | 3:2dccfa0121de | 2065 | } |
wim | 3:2dccfa0121de | 2066 | |
wim | 3:2dccfa0121de | 2067 | |
wim | 3:2dccfa0121de | 2068 | void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount) |
wim | 3:2dccfa0121de | 2069 | { |
wim | 3:2dccfa0121de | 2070 | LCD_PolyLineRelativeClosed(Points, PointCount, 1); |
wim | 0:a8090b59eb05 | 2071 | } |
wim | 0:a8090b59eb05 | 2072 | |
wim | 3:2dccfa0121de | 2073 | void LCD_FillPolyLine(pPoint Points, uint16_t PointCount) |
wim | 3:2dccfa0121de | 2074 | { |
wim | 3:2dccfa0121de | 2075 | /* public-domain code by Darel Rex Finley, 2007 */ |
wim | 3:2dccfa0121de | 2076 | uint16_t nodes = 0, nodeX[MAX_POLY_CORNERS], pixelX = 0, pixelY = 0, i = 0, |
wim | 3:2dccfa0121de | 2077 | j = 0, swap = 0; |
wim | 3:2dccfa0121de | 2078 | uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0; |
wim | 3:2dccfa0121de | 2079 | |
wim | 3:2dccfa0121de | 2080 | IMAGE_LEFT = IMAGE_RIGHT = Points->X; |
wim | 3:2dccfa0121de | 2081 | IMAGE_TOP= IMAGE_BOTTOM = Points->Y; |
wim | 3:2dccfa0121de | 2082 | |
wim | 3:2dccfa0121de | 2083 | for(i = 1; i < PointCount; i++) |
wim | 3:2dccfa0121de | 2084 | { |
wim | 3:2dccfa0121de | 2085 | pixelX = POLY_X(i); |
wim | 3:2dccfa0121de | 2086 | if(pixelX < IMAGE_LEFT) |
wim | 3:2dccfa0121de | 2087 | { |
wim | 3:2dccfa0121de | 2088 | IMAGE_LEFT = pixelX; |
wim | 3:2dccfa0121de | 2089 | } |
wim | 3:2dccfa0121de | 2090 | if(pixelX > IMAGE_RIGHT) |
wim | 3:2dccfa0121de | 2091 | { |
wim | 3:2dccfa0121de | 2092 | IMAGE_RIGHT = pixelX; |
wim | 3:2dccfa0121de | 2093 | } |
wim | 3:2dccfa0121de | 2094 | |
wim | 3:2dccfa0121de | 2095 | pixelY = POLY_Y(i); |
wim | 3:2dccfa0121de | 2096 | if(pixelY < IMAGE_TOP) |
wim | 3:2dccfa0121de | 2097 | { |
wim | 3:2dccfa0121de | 2098 | IMAGE_TOP = pixelY; |
wim | 3:2dccfa0121de | 2099 | } |
wim | 3:2dccfa0121de | 2100 | if(pixelY > IMAGE_BOTTOM) |
wim | 3:2dccfa0121de | 2101 | { |
wim | 3:2dccfa0121de | 2102 | IMAGE_BOTTOM = pixelY; |
wim | 3:2dccfa0121de | 2103 | } |
wim | 3:2dccfa0121de | 2104 | } |
wim | 3:2dccfa0121de | 2105 | |
wim | 3:2dccfa0121de | 2106 | LCD_SetTextColor(BackColor); |
wim | 3:2dccfa0121de | 2107 | |
wim | 3:2dccfa0121de | 2108 | /* Loop through the rows of the image. */ |
wim | 3:2dccfa0121de | 2109 | for (pixelY = IMAGE_TOP; pixelY < IMAGE_BOTTOM; pixelY++) |
wim | 3:2dccfa0121de | 2110 | { |
wim | 3:2dccfa0121de | 2111 | /* Build a list of nodes. */ |
wim | 3:2dccfa0121de | 2112 | nodes = 0; j = PointCount-1; |
wim | 3:2dccfa0121de | 2113 | |
wim | 3:2dccfa0121de | 2114 | for (i = 0; i < PointCount; i++) |
wim | 3:2dccfa0121de | 2115 | { |
wim | 3:2dccfa0121de | 2116 | if (((POLY_Y(i)<(double) pixelY) && (POLY_Y(j)>=(double) pixelY)) || \ |
wim | 3:2dccfa0121de | 2117 | ((POLY_Y(j)<(double) pixelY) && (POLY_Y(i)>=(double) pixelY))) |
wim | 3:2dccfa0121de | 2118 | { |
wim | 3:2dccfa0121de | 2119 | nodeX[nodes++]=(int) (POLY_X(i)+((pixelY-POLY_Y(i))*(POLY_X(j)-POLY_X(i)))/(POLY_Y(j)-POLY_Y(i))); |
wim | 3:2dccfa0121de | 2120 | } |
wim | 3:2dccfa0121de | 2121 | j = i; |
wim | 3:2dccfa0121de | 2122 | } |
wim | 3:2dccfa0121de | 2123 | |
wim | 3:2dccfa0121de | 2124 | /* Sort the nodes, via a simple "Bubble" sort. */ |
wim | 3:2dccfa0121de | 2125 | i = 0; |
wim | 3:2dccfa0121de | 2126 | while (i < nodes-1) |
wim | 3:2dccfa0121de | 2127 | { |
wim | 3:2dccfa0121de | 2128 | if (nodeX[i]>nodeX[i+1]) |
wim | 3:2dccfa0121de | 2129 | { |
wim | 3:2dccfa0121de | 2130 | swap = nodeX[i]; |
wim | 3:2dccfa0121de | 2131 | nodeX[i] = nodeX[i+1]; |
wim | 3:2dccfa0121de | 2132 | nodeX[i+1] = swap; |
wim | 3:2dccfa0121de | 2133 | if(i) |
wim | 3:2dccfa0121de | 2134 | { |
wim | 3:2dccfa0121de | 2135 | i--; |
wim | 3:2dccfa0121de | 2136 | } |
wim | 3:2dccfa0121de | 2137 | } |
wim | 3:2dccfa0121de | 2138 | else |
wim | 3:2dccfa0121de | 2139 | { |
wim | 3:2dccfa0121de | 2140 | i++; |
wim | 3:2dccfa0121de | 2141 | } |
wim | 3:2dccfa0121de | 2142 | } |
wim | 3:2dccfa0121de | 2143 | |
wim | 3:2dccfa0121de | 2144 | /* Fill the pixels between node pairs. */ |
wim | 3:2dccfa0121de | 2145 | for (i = 0; i < nodes; i+=2) |
wim | 3:2dccfa0121de | 2146 | { |
wim | 3:2dccfa0121de | 2147 | if(nodeX[i] >= IMAGE_RIGHT) |
wim | 3:2dccfa0121de | 2148 | { |
wim | 3:2dccfa0121de | 2149 | break; |
wim | 3:2dccfa0121de | 2150 | } |
wim | 3:2dccfa0121de | 2151 | if(nodeX[i+1] > IMAGE_LEFT) |
wim | 3:2dccfa0121de | 2152 | { |
wim | 3:2dccfa0121de | 2153 | if (nodeX[i] < IMAGE_LEFT) |
wim | 3:2dccfa0121de | 2154 | { |
wim | 3:2dccfa0121de | 2155 | nodeX[i]=IMAGE_LEFT; |
wim | 3:2dccfa0121de | 2156 | } |
wim | 3:2dccfa0121de | 2157 | if(nodeX[i+1] > IMAGE_RIGHT) |
wim | 3:2dccfa0121de | 2158 | { |
wim | 3:2dccfa0121de | 2159 | nodeX[i+1] = IMAGE_RIGHT; |
wim | 3:2dccfa0121de | 2160 | } |
wim | 3:2dccfa0121de | 2161 | LCD_SetTextColor(BackColor); |
wim | 3:2dccfa0121de | 2162 | LCD_DrawLine(pixelY, nodeX[i+1], nodeX[i+1] - nodeX[i], LCD_DIR_HORIZONTAL); |
wim | 3:2dccfa0121de | 2163 | LCD_SetTextColor(TextColor); |
wim | 3:2dccfa0121de | 2164 | PutPixel(pixelY, nodeX[i+1]); |
wim | 3:2dccfa0121de | 2165 | PutPixel(pixelY, nodeX[i]); |
wim | 3:2dccfa0121de | 2166 | /* for (j=nodeX[i]; j<nodeX[i+1]; j++) PutPixel(j,pixelY); */ |
wim | 3:2dccfa0121de | 2167 | } |
wim | 3:2dccfa0121de | 2168 | } |
wim | 3:2dccfa0121de | 2169 | } |
wim | 3:2dccfa0121de | 2170 | |
wim | 3:2dccfa0121de | 2171 | /* draw the edges */ |
wim | 3:2dccfa0121de | 2172 | LCD_SetTextColor(TextColor); |
wim | 3:2dccfa0121de | 2173 | } |
wim | 3:2dccfa0121de | 2174 | |
wim | 3:2dccfa0121de | 2175 | |
wim | 3:2dccfa0121de | 2176 | |
wim | 3:2dccfa0121de | 2177 | |
wim | 3:2dccfa0121de | 2178 | #endif |
wim | 0:a8090b59eb05 | 2179 | /******************************************************************************/ |