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