wdenk | 5a8c51c | 2004-04-15 21:16:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * |
| 4 | * Pantelis Antoniou <panto@intracom.gr> |
| 5 | * Intracom S.A. |
| 6 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 5a8c51c | 2004-04-15 21:16:42 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <watchdog.h> |
| 12 | |
| 13 | #include <sed156x.h> |
| 14 | |
wdenk | 5a8c51c | 2004-04-15 21:16:42 +0000 | [diff] [blame] | 15 | /* configure according to the selected display */ |
| 16 | #if defined(CONFIG_SED156X_PG12864Q) |
| 17 | #define LCD_WIDTH 128 |
| 18 | #define LCD_HEIGHT 64 |
| 19 | #define LCD_LINES 64 |
| 20 | #define LCD_PAGES 9 |
| 21 | #define LCD_COLUMNS 132 |
| 22 | #else |
| 23 | #error Unsupported SED156x configuration |
| 24 | #endif |
| 25 | |
| 26 | /* include the font data */ |
| 27 | #include <video_font.h> |
| 28 | |
| 29 | #if VIDEO_FONT_WIDTH != 8 || VIDEO_FONT_HEIGHT != 16 |
| 30 | #error Expecting VIDEO_FONT_WIDTH == 8 && VIDEO_FONT_HEIGHT == 16 |
| 31 | #endif |
| 32 | |
| 33 | #define LCD_BYTE_WIDTH (LCD_WIDTH / 8) |
| 34 | #define VIDEO_FONT_BYTE_WIDTH (VIDEO_FONT_WIDTH / 8) |
| 35 | |
| 36 | #define LCD_TEXT_WIDTH (LCD_WIDTH / VIDEO_FONT_WIDTH) |
| 37 | #define LCD_TEXT_HEIGHT (LCD_HEIGHT / VIDEO_FONT_HEIGHT) |
| 38 | |
| 39 | #define LCD_BYTE_LINESZ (LCD_BYTE_WIDTH * VIDEO_FONT_HEIGHT) |
| 40 | |
| 41 | const int sed156x_text_width = LCD_TEXT_WIDTH; |
| 42 | const int sed156x_text_height = LCD_TEXT_HEIGHT; |
| 43 | |
| 44 | /**************************************************************************************/ |
| 45 | |
| 46 | #define SED156X_SPI_RXD() (SED156X_SPI_RXD_PORT & SED156X_SPI_RXD_MASK) |
| 47 | |
| 48 | #define SED156X_SPI_TXD(x) \ |
| 49 | do { \ |
| 50 | if (x) \ |
| 51 | SED156X_SPI_TXD_PORT |= SED156X_SPI_TXD_MASK; \ |
| 52 | else \ |
| 53 | SED156X_SPI_TXD_PORT &= ~SED156X_SPI_TXD_MASK; \ |
| 54 | } while(0) |
| 55 | |
| 56 | #define SED156X_SPI_CLK(x) \ |
| 57 | do { \ |
| 58 | if (x) \ |
| 59 | SED156X_SPI_CLK_PORT |= SED156X_SPI_CLK_MASK; \ |
| 60 | else \ |
| 61 | SED156X_SPI_CLK_PORT &= ~SED156X_SPI_CLK_MASK; \ |
| 62 | } while(0) |
| 63 | |
| 64 | #define SED156X_SPI_CLK_TOGGLE() (SED156X_SPI_CLK_PORT ^= SED156X_SPI_CLK_MASK) |
| 65 | |
| 66 | #define SED156X_SPI_BIT_DELAY() /* no delay */ |
| 67 | |
| 68 | #define SED156X_CS(x) \ |
| 69 | do { \ |
| 70 | if (x) \ |
| 71 | SED156X_CS_PORT |= SED156X_CS_MASK; \ |
| 72 | else \ |
| 73 | SED156X_CS_PORT &= ~SED156X_CS_MASK; \ |
| 74 | } while(0) |
| 75 | |
| 76 | #define SED156X_A0(x) \ |
| 77 | do { \ |
| 78 | if (x) \ |
| 79 | SED156X_A0_PORT |= SED156X_A0_MASK; \ |
| 80 | else \ |
| 81 | SED156X_A0_PORT &= ~SED156X_A0_MASK; \ |
| 82 | } while(0) |
| 83 | |
| 84 | /**************************************************************************************/ |
| 85 | |
| 86 | /*** LCD Commands ***/ |
| 87 | |
| 88 | #define LCD_ON 0xAF /* Display ON */ |
| 89 | #define LCD_OFF 0xAE /* Display OFF */ |
| 90 | #define LCD_LADDR 0x40 /* Display start line set + (6-bit) address */ |
| 91 | #define LCD_PADDR 0xB0 /* Page address set + (4-bit) page */ |
| 92 | #define LCD_CADRH 0x10 /* Column address set upper + (4-bit) column hi */ |
| 93 | #define LCD_CADRL 0x00 /* Column address set lower + (4-bit) column lo */ |
| 94 | #define LCD_ADC_NRM 0xA0 /* ADC select Normal */ |
| 95 | #define LCD_ADC_REV 0xA1 /* ADC select Reverse */ |
| 96 | #define LCD_DSP_NRM 0xA6 /* LCD display Normal */ |
| 97 | #define LCD_DSP_REV 0xA7 /* LCD display Reverse */ |
| 98 | #define LCD_DPT_NRM 0xA4 /* Display all points Normal */ |
| 99 | #define LCD_DPT_ALL 0xA5 /* Display all points ON */ |
| 100 | #define LCD_BIAS9 0xA2 /* LCD bias set 1/9 */ |
| 101 | #define LCD_BIAS7 0xA3 /* LCD bias set 1/7 */ |
| 102 | #define LCD_CAINC 0xE0 /* Read/modify/write */ |
| 103 | #define LCD_CAEND 0xEE /* End */ |
| 104 | #define LCD_RESET 0xE2 /* Reset */ |
| 105 | #define LCD_C_NRM 0xC0 /* Common output mode select Normal direction */ |
| 106 | #define LCD_C_RVS 0xC8 /* Common output mode select Reverse direction */ |
| 107 | #define LCD_PWRMD 0x28 /* Power control set + (3-bit) mode */ |
| 108 | #define LCD_RESRT 0x20 /* V5 v. reg. int. resistor ratio set + (3-bit) ratio */ |
| 109 | #define LCD_EVSET 0x81 /* Electronic volume mode set + byte = (6-bit) volume */ |
| 110 | #define LCD_SIOFF 0xAC /* Static indicator OFF */ |
| 111 | #define LCD_SION 0xAD /* Static indicator ON + byte = (2-bit) mode */ |
| 112 | #define LCD_NOP 0xE3 /* NOP */ |
| 113 | #define LCD_TEST 0xF0 /* Test/Test mode reset (Note: *DO NOT USE*) */ |
| 114 | |
| 115 | /*------------------------------------------------------------------------------- |
| 116 | Compound commands |
| 117 | ------------------------------------------------------------------------------- |
| 118 | Command Description Commands |
| 119 | ---------- ------------------------ ------------------------------------- |
| 120 | POWS_ON POWER SAVER ON command LCD_OFF, LCD_D_ALL |
| 121 | POWS_OFF POWER SAVER OFF command LCD_D_NRM |
| 122 | SLEEPON SLEEP mode LCD_SIOFF, POWS_ON |
| 123 | SLEEPOFF SLEEP mode cancel LCD_D_NRM, LCD_SION, LCD_SIS_??? |
| 124 | STDBYON STAND BY mode LCD_SION, POWS_ON |
| 125 | STDBYOFF STAND BY mode cancel LCD_D_NRM |
| 126 | -------------------------------------------------------------------------------*/ |
| 127 | |
| 128 | /*** LCD various parameters ***/ |
| 129 | #define LCD_PPB 8 /* Pixels per byte (display is B/W, 1 bit per pixel) */ |
| 130 | |
| 131 | /*** LCD Status byte masks ***/ |
| 132 | #define LCD_S_BUSY 0x80 /* Status Read - BUSY mask */ |
| 133 | #define LCD_S_ADC 0x40 /* Status Read - ADC mask */ |
| 134 | #define LCD_S_ONOFF 0x20 /* Status Read - ON/OFF mask */ |
| 135 | #define LCD_S_RESET 0x10 /* Status Read - RESET mask */ |
| 136 | |
| 137 | /*** LCD commands parameter masks ***/ |
| 138 | #define LCD_M_LADDR 0x3F /* Display start line (6-bit) address mask */ |
| 139 | #define LCD_M_PADDR 0x0F /* Page address (4-bit) page mask */ |
| 140 | #define LCD_M_CADRH 0x0F /* Column address upper (4-bit) column hi mask */ |
| 141 | #define LCD_M_CADRL 0x0F /* Column address lower (4-bit) column lo mask */ |
| 142 | #define LCD_M_PWRMD 0x07 /* Power control (3-bit) mode mask */ |
| 143 | #define LCD_M_RESRT 0x07 /* V5 v. reg. int. resistor ratio (3-bit) ratio mask */ |
| 144 | #define LCD_M_EVSET 0x3F /* Electronic volume mode byte (6-bit) volume mask */ |
| 145 | #define LCD_M_SION 0x03 /* Static indicator ON (2-bit) mode mask */ |
| 146 | |
| 147 | /*** LCD Power control cirquits control masks ***/ |
| 148 | #define LCD_PWRBSTR 0x04 /* Power control mode - Booster cirquit ON */ |
| 149 | #define LCD_PWRVREG 0x02 /* Power control mode - Voltage regulator cirquit ON */ |
| 150 | #define LCD_PWRVFOL 0x01 /* Power control mode - Voltage follower cirquit ON */ |
| 151 | |
| 152 | /*** LCD Static indicator states ***/ |
| 153 | #define LCD_SIS_OFF 0x00 /* Static indicator register set - OFF state */ |
| 154 | #define LCD_SIS_BL 0x01 /* Static indicator register set - 1s blink state */ |
| 155 | #define LCD_SIS_RBL 0x02 /* Static indicator register set - .5s rapid blink state */ |
| 156 | #define LCD_SIS_ON 0x03 /* Static indicator register set - constantly on state */ |
| 157 | |
| 158 | /*** LCD functions special parameters (commands) ***/ |
| 159 | #define LCD_PREVP 0x80 /* Page number for moving to previous */ |
| 160 | #define LCD_NEXTP 0x81 /* or next page */ |
| 161 | #define LCD_ERR_P 0xFF /* Error in page number */ |
| 162 | |
| 163 | /*** LCD initialization settings ***/ |
| 164 | #define LCD_BIAS LCD_BIAS9 /* Bias: 1/9 */ |
| 165 | #define LCD_ADCMODE LCD_ADC_NRM /* ADC mode: normal */ |
| 166 | #define LCD_COMDIR LCD_C_NRM /* Common output mode: normal */ |
| 167 | #define LCD_RRATIO 0 /* Resistor ratio: 0 */ |
| 168 | #define LCD_CNTRST 0x1C /* electronic volume: 1Ch */ |
| 169 | #define LCD_POWERM (LCD_PWRBSTR | LCD_PWRVREG | LCD_PWRVFOL) /* Power mode: All on */ |
| 170 | |
| 171 | /**************************************************************************************/ |
| 172 | |
| 173 | static inline unsigned int sed156x_transfer(unsigned int val) |
| 174 | { |
| 175 | unsigned int rx; |
| 176 | int b; |
| 177 | |
| 178 | rx = 0; b = 8; |
| 179 | while (--b >= 0) { |
| 180 | SED156X_SPI_TXD(val & 0x80); |
| 181 | val <<= 1; |
| 182 | SED156X_SPI_CLK_TOGGLE(); |
| 183 | SED156X_SPI_BIT_DELAY(); |
| 184 | rx <<= 1; |
| 185 | if (SED156X_SPI_RXD()) |
| 186 | rx |= 1; |
| 187 | SED156X_SPI_CLK_TOGGLE(); |
| 188 | SED156X_SPI_BIT_DELAY(); |
| 189 | } |
| 190 | |
| 191 | return rx; |
| 192 | } |
| 193 | |
| 194 | unsigned int sed156x_data_transfer(unsigned int val) |
| 195 | { |
| 196 | unsigned int rx; |
| 197 | |
| 198 | SED156X_SPI_CLK(1); |
| 199 | SED156X_CS(0); |
| 200 | SED156X_A0(1); |
| 201 | |
| 202 | rx = sed156x_transfer(val); |
| 203 | |
| 204 | SED156X_CS(1); |
| 205 | |
| 206 | return rx; |
| 207 | } |
| 208 | |
| 209 | void sed156x_data_block_transfer(const u8 *p, int size) |
| 210 | { |
| 211 | SED156X_SPI_CLK(1); |
| 212 | SED156X_CS(0); |
| 213 | SED156X_A0(1); |
| 214 | |
| 215 | while (--size >= 0) |
| 216 | sed156x_transfer(*p++); |
| 217 | |
| 218 | SED156X_CS(1); |
| 219 | } |
| 220 | |
| 221 | unsigned int sed156x_cmd_transfer(unsigned int val) |
| 222 | { |
| 223 | unsigned int rx; |
| 224 | |
| 225 | SED156X_SPI_CLK(1); |
| 226 | SED156X_CS(0); |
| 227 | SED156X_A0(0); |
| 228 | |
| 229 | rx = sed156x_transfer(val); |
| 230 | |
| 231 | SED156X_CS(1); |
| 232 | SED156X_A0(1); |
| 233 | |
| 234 | return rx; |
| 235 | } |
| 236 | |
| 237 | /******************************************************************************/ |
| 238 | |
| 239 | static u8 hw_screen[LCD_PAGES][LCD_COLUMNS]; |
| 240 | static u8 last_hw_screen[LCD_PAGES][LCD_COLUMNS]; |
| 241 | static u8 sw_screen[LCD_BYTE_WIDTH * LCD_HEIGHT]; |
| 242 | |
| 243 | void sed156x_sync(void) |
| 244 | { |
| 245 | int i, j, last_page; |
| 246 | u8 *d; |
| 247 | const u8 *s, *e, *b, *r; |
| 248 | u8 v0, v1, v2, v3, v4, v5, v6, v7; |
| 249 | |
| 250 | /* copy and rotate sw_screen to hw_screen */ |
| 251 | for (i = 0; i < LCD_HEIGHT / 8; i++) { |
| 252 | |
| 253 | d = &hw_screen[i][0]; |
| 254 | s = &sw_screen[LCD_BYTE_WIDTH * 8 * i + LCD_BYTE_WIDTH - 1]; |
| 255 | |
| 256 | for (j = 0; j < LCD_WIDTH / 8; j++) { |
| 257 | |
| 258 | v0 = s[0 * LCD_BYTE_WIDTH]; |
| 259 | v1 = s[1 * LCD_BYTE_WIDTH]; |
| 260 | v2 = s[2 * LCD_BYTE_WIDTH]; |
| 261 | v3 = s[3 * LCD_BYTE_WIDTH]; |
| 262 | v4 = s[4 * LCD_BYTE_WIDTH]; |
| 263 | v5 = s[5 * LCD_BYTE_WIDTH]; |
| 264 | v6 = s[6 * LCD_BYTE_WIDTH]; |
| 265 | v7 = s[7 * LCD_BYTE_WIDTH]; |
| 266 | |
| 267 | d[0] = ((v7 & 0x01) << 7) | |
| 268 | ((v6 & 0x01) << 6) | |
| 269 | ((v5 & 0x01) << 5) | |
| 270 | ((v4 & 0x01) << 4) | |
| 271 | ((v3 & 0x01) << 3) | |
| 272 | ((v2 & 0x01) << 2) | |
| 273 | ((v1 & 0x01) << 1) | |
| 274 | (v0 & 0x01) ; |
| 275 | |
| 276 | d[1] = ((v7 & 0x02) << 6) | |
| 277 | ((v6 & 0x02) << 5) | |
| 278 | ((v5 & 0x02) << 4) | |
| 279 | ((v4 & 0x02) << 3) | |
| 280 | ((v3 & 0x02) << 2) | |
| 281 | ((v2 & 0x02) << 1) | |
| 282 | ((v1 & 0x02) << 0) | |
| 283 | ((v0 & 0x02) >> 1) ; |
| 284 | |
| 285 | d[2] = ((v7 & 0x04) << 5) | |
| 286 | ((v6 & 0x04) << 4) | |
| 287 | ((v5 & 0x04) << 3) | |
| 288 | ((v4 & 0x04) << 2) | |
| 289 | ((v3 & 0x04) << 1) | |
| 290 | (v2 & 0x04) | |
| 291 | ((v1 & 0x04) >> 1) | |
| 292 | ((v0 & 0x04) >> 2) ; |
| 293 | |
| 294 | d[3] = ((v7 & 0x08) << 4) | |
| 295 | ((v6 & 0x08) << 3) | |
| 296 | ((v5 & 0x08) << 2) | |
| 297 | ((v4 & 0x08) << 1) | |
| 298 | (v3 & 0x08) | |
| 299 | ((v2 & 0x08) >> 1) | |
| 300 | ((v1 & 0x08) >> 2) | |
| 301 | ((v0 & 0x08) >> 3) ; |
| 302 | |
| 303 | d[4] = ((v7 & 0x10) << 3) | |
| 304 | ((v6 & 0x10) << 2) | |
| 305 | ((v5 & 0x10) << 1) | |
| 306 | (v4 & 0x10) | |
| 307 | ((v3 & 0x10) >> 1) | |
| 308 | ((v2 & 0x10) >> 2) | |
| 309 | ((v1 & 0x10) >> 3) | |
| 310 | ((v0 & 0x10) >> 4) ; |
| 311 | |
| 312 | d[5] = ((v7 & 0x20) << 2) | |
| 313 | ((v6 & 0x20) << 1) | |
| 314 | (v5 & 0x20) | |
| 315 | ((v4 & 0x20) >> 1) | |
| 316 | ((v3 & 0x20) >> 2) | |
| 317 | ((v2 & 0x20) >> 3) | |
| 318 | ((v1 & 0x20) >> 4) | |
| 319 | ((v0 & 0x20) >> 5) ; |
| 320 | |
| 321 | d[6] = ((v7 & 0x40) << 1) | |
| 322 | (v6 & 0x40) | |
| 323 | ((v5 & 0x40) >> 1) | |
| 324 | ((v4 & 0x40) >> 2) | |
| 325 | ((v3 & 0x40) >> 3) | |
| 326 | ((v2 & 0x40) >> 4) | |
| 327 | ((v1 & 0x40) >> 5) | |
| 328 | ((v0 & 0x40) >> 6) ; |
| 329 | |
| 330 | d[7] = (v7 & 0x80) | |
| 331 | ((v6 & 0x80) >> 1) | |
| 332 | ((v5 & 0x80) >> 2) | |
| 333 | ((v4 & 0x80) >> 3) | |
| 334 | ((v3 & 0x80) >> 4) | |
| 335 | ((v2 & 0x80) >> 5) | |
| 336 | ((v1 & 0x80) >> 6) | |
| 337 | ((v0 & 0x80) >> 7) ; |
| 338 | |
| 339 | d += 8; |
| 340 | s--; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* and now output only the differences */ |
| 345 | for (i = 0; i < LCD_PAGES; i++) { |
| 346 | |
| 347 | b = &hw_screen[i][0]; |
| 348 | e = &hw_screen[i][LCD_COLUMNS]; |
| 349 | |
| 350 | d = &last_hw_screen[i][0]; |
| 351 | s = b; |
| 352 | |
| 353 | last_page = -1; |
| 354 | |
| 355 | /* update only the differences */ |
| 356 | do { |
| 357 | while (s < e && *s == *d) { |
| 358 | s++; |
| 359 | d++; |
| 360 | } |
| 361 | if (s == e) |
| 362 | break; |
| 363 | r = s; |
| 364 | while (s < e && *s != *d) |
| 365 | *d++ = *s++; |
| 366 | |
| 367 | j = r - b; |
| 368 | |
| 369 | if (i != last_page) { |
| 370 | sed156x_cmd_transfer(LCD_PADDR | i); |
| 371 | last_page = i; |
| 372 | } |
| 373 | |
| 374 | sed156x_cmd_transfer(LCD_CADRH | ((j >> 4) & 0x0F)); |
| 375 | sed156x_cmd_transfer(LCD_CADRL | (j & 0x0F)); |
| 376 | sed156x_data_block_transfer(r, s - r); |
| 377 | |
| 378 | } while (s < e); |
| 379 | } |
| 380 | |
| 381 | /******** |
| 382 | for (i = 0; i < LCD_PAGES; i++) { |
| 383 | sed156x_cmd_transfer(LCD_PADDR | i); |
| 384 | sed156x_cmd_transfer(LCD_CADRH | 0); |
| 385 | sed156x_cmd_transfer(LCD_CADRL | 0); |
| 386 | sed156x_data_block_transfer(&hw_screen[i][0], LCD_COLUMNS); |
| 387 | } |
| 388 | memcpy(last_hw_screen, hw_screen, sizeof(last_hw_screen)); |
| 389 | ********/ |
| 390 | } |
| 391 | |
| 392 | void sed156x_clear(void) |
| 393 | { |
| 394 | memset(sw_screen, 0, sizeof(sw_screen)); |
| 395 | } |
| 396 | |
| 397 | void sed156x_output_at(int x, int y, const char *str, int size) |
| 398 | { |
| 399 | int i, j; |
| 400 | u8 *p; |
| 401 | const u8 *s; |
| 402 | |
| 403 | if ((unsigned int)y >= LCD_TEXT_HEIGHT || (unsigned int)x >= LCD_TEXT_WIDTH) |
| 404 | return; |
| 405 | |
| 406 | p = &sw_screen[y * VIDEO_FONT_HEIGHT * LCD_BYTE_WIDTH + x * VIDEO_FONT_BYTE_WIDTH]; |
| 407 | |
| 408 | while (--size >= 0) { |
| 409 | |
| 410 | s = &video_fontdata[((int)*str++ & 0xff) * VIDEO_FONT_BYTE_WIDTH * VIDEO_FONT_HEIGHT]; |
| 411 | for (i = 0; i < VIDEO_FONT_HEIGHT; i++) { |
| 412 | for (j = 0; j < VIDEO_FONT_BYTE_WIDTH; j++) |
| 413 | *p++ = *s++; |
| 414 | p += LCD_BYTE_WIDTH - VIDEO_FONT_BYTE_WIDTH; |
| 415 | } |
| 416 | p -= (LCD_BYTE_LINESZ - VIDEO_FONT_BYTE_WIDTH); |
| 417 | |
| 418 | if (x >= LCD_TEXT_WIDTH) |
| 419 | break; |
| 420 | x++; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | void sed156x_reverse_at(int x, int y, int size) |
| 425 | { |
| 426 | int i, j; |
| 427 | u8 *p; |
| 428 | |
| 429 | if ((unsigned int)y >= LCD_TEXT_HEIGHT || (unsigned int)x >= LCD_TEXT_WIDTH) |
| 430 | return; |
| 431 | |
| 432 | p = &sw_screen[y * VIDEO_FONT_HEIGHT * LCD_BYTE_WIDTH + x * VIDEO_FONT_BYTE_WIDTH]; |
| 433 | |
| 434 | while (--size >= 0) { |
| 435 | |
| 436 | for (i = 0; i < VIDEO_FONT_HEIGHT; i++) { |
| 437 | for (j = 0; j < VIDEO_FONT_BYTE_WIDTH; j++, p++) |
| 438 | *p = ~*p; |
| 439 | p += LCD_BYTE_WIDTH - VIDEO_FONT_BYTE_WIDTH; |
| 440 | } |
| 441 | p -= (LCD_BYTE_LINESZ - VIDEO_FONT_BYTE_WIDTH); |
| 442 | |
| 443 | if (x >= LCD_TEXT_WIDTH) |
| 444 | break; |
| 445 | x++; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | void sed156x_scroll_line(void) |
| 450 | { |
| 451 | memmove(&sw_screen[0], |
| 452 | &sw_screen[LCD_BYTE_LINESZ], |
| 453 | LCD_BYTE_WIDTH * (LCD_HEIGHT - VIDEO_FONT_HEIGHT)); |
| 454 | } |
| 455 | |
| 456 | void sed156x_scroll(int dx, int dy) |
| 457 | { |
| 458 | u8 *p1 = NULL, *p2 = NULL, *p3 = NULL; /* pacify gcc */ |
| 459 | int adx, ady, i, sz; |
| 460 | |
| 461 | adx = dx > 0 ? dx : -dx; |
| 462 | ady = dy > 0 ? dy : -dy; |
| 463 | |
| 464 | /* overscroll? erase everything */ |
| 465 | if (adx >= LCD_TEXT_WIDTH || ady >= LCD_TEXT_HEIGHT) { |
| 466 | memset(sw_screen, 0, sizeof(sw_screen)); |
| 467 | return; |
| 468 | } |
| 469 | |
| 470 | sz = LCD_BYTE_LINESZ * ady; |
| 471 | if (dy > 0) { |
| 472 | p1 = &sw_screen[0]; |
| 473 | p2 = &sw_screen[sz]; |
| 474 | p3 = &sw_screen[LCD_BYTE_WIDTH * LCD_HEIGHT - sz]; |
| 475 | } else if (dy < 0) { |
| 476 | p1 = &sw_screen[sz]; |
| 477 | p2 = &sw_screen[0]; |
| 478 | p3 = &sw_screen[0]; |
| 479 | } |
| 480 | |
| 481 | if (ady > 0) { |
| 482 | memmove(p1, p2, LCD_BYTE_WIDTH * LCD_HEIGHT - sz); |
| 483 | memset(p3, 0, sz); |
| 484 | } |
| 485 | |
| 486 | sz = VIDEO_FONT_BYTE_WIDTH * adx; |
| 487 | if (dx > 0) { |
| 488 | p1 = &sw_screen[0]; |
| 489 | p2 = &sw_screen[0] + sz; |
| 490 | p3 = &sw_screen[0] + LCD_BYTE_WIDTH - sz; |
| 491 | } else if (dx < 0) { |
| 492 | p1 = &sw_screen[0] + sz; |
| 493 | p2 = &sw_screen[0]; |
| 494 | p3 = &sw_screen[0]; |
| 495 | } |
| 496 | |
| 497 | /* xscroll */ |
| 498 | if (adx > 0) { |
| 499 | for (i = 0; i < LCD_HEIGHT; i++) { |
| 500 | memmove(p1, p2, LCD_BYTE_WIDTH - sz); |
| 501 | memset(p3, 0, sz); |
| 502 | p1 += LCD_BYTE_WIDTH; |
| 503 | p2 += LCD_BYTE_WIDTH; |
| 504 | p3 += LCD_BYTE_WIDTH; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | void sed156x_init(void) |
| 510 | { |
| 511 | int i; |
| 512 | |
| 513 | SED156X_CS(1); |
| 514 | SED156X_A0(1); |
| 515 | |
| 516 | /* Send initialization commands to the LCD */ |
| 517 | sed156x_cmd_transfer(LCD_OFF); /* Turn display OFF */ |
| 518 | sed156x_cmd_transfer(LCD_BIAS); /* set the LCD Bias, */ |
| 519 | sed156x_cmd_transfer(LCD_ADCMODE); /* ADC mode, */ |
| 520 | sed156x_cmd_transfer(LCD_COMDIR); /* common output mode, */ |
| 521 | sed156x_cmd_transfer(LCD_RESRT | LCD_RRATIO); /* resistor ratio, */ |
| 522 | sed156x_cmd_transfer(LCD_EVSET); /* electronic volume, */ |
| 523 | sed156x_cmd_transfer(LCD_CNTRST); |
| 524 | sed156x_cmd_transfer(LCD_PWRMD | LCD_POWERM); /* and power mode */ |
| 525 | sed156x_cmd_transfer(LCD_PADDR | 0); /* cursor home */ |
| 526 | sed156x_cmd_transfer(LCD_CADRH | 0); |
| 527 | sed156x_cmd_transfer(LCD_CADRL | 0); |
| 528 | sed156x_cmd_transfer(LCD_LADDR | 0); /* and display start line */ |
| 529 | sed156x_cmd_transfer(LCD_DSP_NRM); /* LCD display Normal */ |
| 530 | |
| 531 | /* clear everything */ |
| 532 | memset(sw_screen, 0, sizeof(sw_screen)); |
| 533 | memset(hw_screen, 0, sizeof(hw_screen)); |
| 534 | memset(last_hw_screen, 0, sizeof(last_hw_screen)); |
| 535 | |
| 536 | for (i = 0; i < LCD_PAGES; i++) { |
| 537 | sed156x_cmd_transfer(LCD_PADDR | i); |
| 538 | sed156x_cmd_transfer(LCD_CADRH | 0); |
| 539 | sed156x_cmd_transfer(LCD_CADRL | 0); |
| 540 | sed156x_data_block_transfer(&hw_screen[i][0], LCD_COLUMNS); |
| 541 | } |
| 542 | |
| 543 | sed156x_clear(); |
| 544 | sed156x_sync(); |
| 545 | sed156x_cmd_transfer(LCD_ON); /* Turn display ON */ |
| 546 | } |