4 * Pantelis Antoniou <panto@intracom.gr>
7 * See file CREDITS for list of people who contributed to this
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.
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.
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,
31 /* configure according to the selected display */
32 #if defined(CONFIG_SED156X_PG12864Q)
37 #define LCD_COLUMNS 132
39 #error Unsupported SED156x configuration
42 /* include the font data */
43 #include <video_font.h>
44 #include <video_font_data.h>
46 #if VIDEO_FONT_WIDTH != 8 || VIDEO_FONT_HEIGHT != 16
47 #error Expecting VIDEO_FONT_WIDTH == 8 && VIDEO_FONT_HEIGHT == 16
50 #define LCD_BYTE_WIDTH (LCD_WIDTH / 8)
51 #define VIDEO_FONT_BYTE_WIDTH (VIDEO_FONT_WIDTH / 8)
53 #define LCD_TEXT_WIDTH (LCD_WIDTH / VIDEO_FONT_WIDTH)
54 #define LCD_TEXT_HEIGHT (LCD_HEIGHT / VIDEO_FONT_HEIGHT)
56 #define LCD_BYTE_LINESZ (LCD_BYTE_WIDTH * VIDEO_FONT_HEIGHT)
58 const int sed156x_text_width = LCD_TEXT_WIDTH;
59 const int sed156x_text_height = LCD_TEXT_HEIGHT;
61 /**************************************************************************************/
63 #define SED156X_SPI_RXD() (SED156X_SPI_RXD_PORT & SED156X_SPI_RXD_MASK)
65 #define SED156X_SPI_TXD(x) \
68 SED156X_SPI_TXD_PORT |= SED156X_SPI_TXD_MASK; \
70 SED156X_SPI_TXD_PORT &= ~SED156X_SPI_TXD_MASK; \
73 #define SED156X_SPI_CLK(x) \
76 SED156X_SPI_CLK_PORT |= SED156X_SPI_CLK_MASK; \
78 SED156X_SPI_CLK_PORT &= ~SED156X_SPI_CLK_MASK; \
81 #define SED156X_SPI_CLK_TOGGLE() (SED156X_SPI_CLK_PORT ^= SED156X_SPI_CLK_MASK)
83 #define SED156X_SPI_BIT_DELAY() /* no delay */
85 #define SED156X_CS(x) \
88 SED156X_CS_PORT |= SED156X_CS_MASK; \
90 SED156X_CS_PORT &= ~SED156X_CS_MASK; \
93 #define SED156X_A0(x) \
96 SED156X_A0_PORT |= SED156X_A0_MASK; \
98 SED156X_A0_PORT &= ~SED156X_A0_MASK; \
101 /**************************************************************************************/
103 /*** LCD Commands ***/
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*) */
132 /*-------------------------------------------------------------------------------
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 -------------------------------------------------------------------------------*/
145 /*** LCD various parameters ***/
146 #define LCD_PPB 8 /* Pixels per byte (display is B/W, 1 bit per pixel) */
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 */
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 */
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 */
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 */
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 */
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 */
188 /**************************************************************************************/
190 static inline unsigned int sed156x_transfer(unsigned int val)
197 SED156X_SPI_TXD(val & 0x80);
199 SED156X_SPI_CLK_TOGGLE();
200 SED156X_SPI_BIT_DELAY();
202 if (SED156X_SPI_RXD())
204 SED156X_SPI_CLK_TOGGLE();
205 SED156X_SPI_BIT_DELAY();
211 unsigned int sed156x_data_transfer(unsigned int val)
219 rx = sed156x_transfer(val);
226 void sed156x_data_block_transfer(const u8 *p, int size)
233 sed156x_transfer(*p++);
238 unsigned int sed156x_cmd_transfer(unsigned int val)
246 rx = sed156x_transfer(val);
254 /******************************************************************************/
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];
260 void sed156x_sync(void)
264 const u8 *s, *e, *b, *r;
265 u8 v0, v1, v2, v3, v4, v5, v6, v7;
267 /* copy and rotate sw_screen to hw_screen */
268 for (i = 0; i < LCD_HEIGHT / 8; i++) {
270 d = &hw_screen[i][0];
271 s = &sw_screen[LCD_BYTE_WIDTH * 8 * i + LCD_BYTE_WIDTH - 1];
273 for (j = 0; j < LCD_WIDTH / 8; j++) {
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];
284 d[0] = ((v7 & 0x01) << 7) |
293 d[1] = ((v7 & 0x02) << 6) |
302 d[2] = ((v7 & 0x04) << 5) |
311 d[3] = ((v7 & 0x08) << 4) |
320 d[4] = ((v7 & 0x10) << 3) |
329 d[5] = ((v7 & 0x20) << 2) |
338 d[6] = ((v7 & 0x40) << 1) |
361 /* and now output only the differences */
362 for (i = 0; i < LCD_PAGES; i++) {
364 b = &hw_screen[i][0];
365 e = &hw_screen[i][LCD_COLUMNS];
367 d = &last_hw_screen[i][0];
372 /* update only the differences */
374 while (s < e && *s == *d) {
381 while (s < e && *s != *d)
386 if (i != last_page) {
387 sed156x_cmd_transfer(LCD_PADDR | i);
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);
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);
405 memcpy(last_hw_screen, hw_screen, sizeof(last_hw_screen));
409 void sed156x_clear(void)
411 memset(sw_screen, 0, sizeof(sw_screen));
414 void sed156x_output_at(int x, int y, const char *str, int size)
420 if ((unsigned int)y >= LCD_TEXT_HEIGHT || (unsigned int)x >= LCD_TEXT_WIDTH)
423 p = &sw_screen[y * VIDEO_FONT_HEIGHT * LCD_BYTE_WIDTH + x * VIDEO_FONT_BYTE_WIDTH];
425 while (--size >= 0) {
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++)
431 p += LCD_BYTE_WIDTH - VIDEO_FONT_BYTE_WIDTH;
433 p -= (LCD_BYTE_LINESZ - VIDEO_FONT_BYTE_WIDTH);
435 if (x >= LCD_TEXT_WIDTH)
441 void sed156x_reverse_at(int x, int y, int size)
446 if ((unsigned int)y >= LCD_TEXT_HEIGHT || (unsigned int)x >= LCD_TEXT_WIDTH)
449 p = &sw_screen[y * VIDEO_FONT_HEIGHT * LCD_BYTE_WIDTH + x * VIDEO_FONT_BYTE_WIDTH];
451 while (--size >= 0) {
453 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
454 for (j = 0; j < VIDEO_FONT_BYTE_WIDTH; j++, p++)
456 p += LCD_BYTE_WIDTH - VIDEO_FONT_BYTE_WIDTH;
458 p -= (LCD_BYTE_LINESZ - VIDEO_FONT_BYTE_WIDTH);
460 if (x >= LCD_TEXT_WIDTH)
466 void sed156x_scroll_line(void)
468 memmove(&sw_screen[0],
469 &sw_screen[LCD_BYTE_LINESZ],
470 LCD_BYTE_WIDTH * (LCD_HEIGHT - VIDEO_FONT_HEIGHT));
473 void sed156x_scroll(int dx, int dy)
475 u8 *p1 = NULL, *p2 = NULL, *p3 = NULL; /* pacify gcc */
478 adx = dx > 0 ? dx : -dx;
479 ady = dy > 0 ? dy : -dy;
481 /* overscroll? erase everything */
482 if (adx >= LCD_TEXT_WIDTH || ady >= LCD_TEXT_HEIGHT) {
483 memset(sw_screen, 0, sizeof(sw_screen));
487 sz = LCD_BYTE_LINESZ * ady;
491 p3 = &sw_screen[LCD_BYTE_WIDTH * LCD_HEIGHT - sz];
499 memmove(p1, p2, LCD_BYTE_WIDTH * LCD_HEIGHT - sz);
503 sz = VIDEO_FONT_BYTE_WIDTH * adx;
506 p2 = &sw_screen[0] + sz;
507 p3 = &sw_screen[0] + LCD_BYTE_WIDTH - sz;
509 p1 = &sw_screen[0] + sz;
516 for (i = 0; i < LCD_HEIGHT; i++) {
517 memmove(p1, p2, LCD_BYTE_WIDTH - sz);
519 p1 += LCD_BYTE_WIDTH;
520 p2 += LCD_BYTE_WIDTH;
521 p3 += LCD_BYTE_WIDTH;
526 void sed156x_init(void)
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 */
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));
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);
562 sed156x_cmd_transfer(LCD_ON); /* Turn display ON */