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,
33 /* configure according to the selected display */
34 #if defined(CONFIG_SED156X_PG12864Q)
39 #define LCD_COLUMNS 132
41 #error Unsupported SED156x configuration
44 /* include the font data */
45 #include <video_font.h>
47 #if VIDEO_FONT_WIDTH != 8 || VIDEO_FONT_HEIGHT != 16
48 #error Expecting VIDEO_FONT_WIDTH == 8 && VIDEO_FONT_HEIGHT == 16
51 #define LCD_BYTE_WIDTH (LCD_WIDTH / 8)
52 #define VIDEO_FONT_BYTE_WIDTH (VIDEO_FONT_WIDTH / 8)
54 #define LCD_TEXT_WIDTH (LCD_WIDTH / VIDEO_FONT_WIDTH)
55 #define LCD_TEXT_HEIGHT (LCD_HEIGHT / VIDEO_FONT_HEIGHT)
57 #define LCD_BYTE_LINESZ (LCD_BYTE_WIDTH * VIDEO_FONT_HEIGHT)
59 const int sed156x_text_width
= LCD_TEXT_WIDTH
;
60 const int sed156x_text_height
= LCD_TEXT_HEIGHT
;
62 /**************************************************************************************/
64 #define SED156X_SPI_RXD() (SED156X_SPI_RXD_PORT & SED156X_SPI_RXD_MASK)
66 #define SED156X_SPI_TXD(x) \
69 SED156X_SPI_TXD_PORT |= SED156X_SPI_TXD_MASK; \
71 SED156X_SPI_TXD_PORT &= ~SED156X_SPI_TXD_MASK; \
74 #define SED156X_SPI_CLK(x) \
77 SED156X_SPI_CLK_PORT |= SED156X_SPI_CLK_MASK; \
79 SED156X_SPI_CLK_PORT &= ~SED156X_SPI_CLK_MASK; \
82 #define SED156X_SPI_CLK_TOGGLE() (SED156X_SPI_CLK_PORT ^= SED156X_SPI_CLK_MASK)
84 #define SED156X_SPI_BIT_DELAY() /* no delay */
86 #define SED156X_CS(x) \
89 SED156X_CS_PORT |= SED156X_CS_MASK; \
91 SED156X_CS_PORT &= ~SED156X_CS_MASK; \
94 #define SED156X_A0(x) \
97 SED156X_A0_PORT |= SED156X_A0_MASK; \
99 SED156X_A0_PORT &= ~SED156X_A0_MASK; \
102 /**************************************************************************************/
104 /*** LCD Commands ***/
106 #define LCD_ON 0xAF /* Display ON */
107 #define LCD_OFF 0xAE /* Display OFF */
108 #define LCD_LADDR 0x40 /* Display start line set + (6-bit) address */
109 #define LCD_PADDR 0xB0 /* Page address set + (4-bit) page */
110 #define LCD_CADRH 0x10 /* Column address set upper + (4-bit) column hi */
111 #define LCD_CADRL 0x00 /* Column address set lower + (4-bit) column lo */
112 #define LCD_ADC_NRM 0xA0 /* ADC select Normal */
113 #define LCD_ADC_REV 0xA1 /* ADC select Reverse */
114 #define LCD_DSP_NRM 0xA6 /* LCD display Normal */
115 #define LCD_DSP_REV 0xA7 /* LCD display Reverse */
116 #define LCD_DPT_NRM 0xA4 /* Display all points Normal */
117 #define LCD_DPT_ALL 0xA5 /* Display all points ON */
118 #define LCD_BIAS9 0xA2 /* LCD bias set 1/9 */
119 #define LCD_BIAS7 0xA3 /* LCD bias set 1/7 */
120 #define LCD_CAINC 0xE0 /* Read/modify/write */
121 #define LCD_CAEND 0xEE /* End */
122 #define LCD_RESET 0xE2 /* Reset */
123 #define LCD_C_NRM 0xC0 /* Common output mode select Normal direction */
124 #define LCD_C_RVS 0xC8 /* Common output mode select Reverse direction */
125 #define LCD_PWRMD 0x28 /* Power control set + (3-bit) mode */
126 #define LCD_RESRT 0x20 /* V5 v. reg. int. resistor ratio set + (3-bit) ratio */
127 #define LCD_EVSET 0x81 /* Electronic volume mode set + byte = (6-bit) volume */
128 #define LCD_SIOFF 0xAC /* Static indicator OFF */
129 #define LCD_SION 0xAD /* Static indicator ON + byte = (2-bit) mode */
130 #define LCD_NOP 0xE3 /* NOP */
131 #define LCD_TEST 0xF0 /* Test/Test mode reset (Note: *DO NOT USE*) */
133 /*-------------------------------------------------------------------------------
135 -------------------------------------------------------------------------------
136 Command Description Commands
137 ---------- ------------------------ -------------------------------------
138 POWS_ON POWER SAVER ON command LCD_OFF, LCD_D_ALL
139 POWS_OFF POWER SAVER OFF command LCD_D_NRM
140 SLEEPON SLEEP mode LCD_SIOFF, POWS_ON
141 SLEEPOFF SLEEP mode cancel LCD_D_NRM, LCD_SION, LCD_SIS_???
142 STDBYON STAND BY mode LCD_SION, POWS_ON
143 STDBYOFF STAND BY mode cancel LCD_D_NRM
144 -------------------------------------------------------------------------------*/
146 /*** LCD various parameters ***/
147 #define LCD_PPB 8 /* Pixels per byte (display is B/W, 1 bit per pixel) */
149 /*** LCD Status byte masks ***/
150 #define LCD_S_BUSY 0x80 /* Status Read - BUSY mask */
151 #define LCD_S_ADC 0x40 /* Status Read - ADC mask */
152 #define LCD_S_ONOFF 0x20 /* Status Read - ON/OFF mask */
153 #define LCD_S_RESET 0x10 /* Status Read - RESET mask */
155 /*** LCD commands parameter masks ***/
156 #define LCD_M_LADDR 0x3F /* Display start line (6-bit) address mask */
157 #define LCD_M_PADDR 0x0F /* Page address (4-bit) page mask */
158 #define LCD_M_CADRH 0x0F /* Column address upper (4-bit) column hi mask */
159 #define LCD_M_CADRL 0x0F /* Column address lower (4-bit) column lo mask */
160 #define LCD_M_PWRMD 0x07 /* Power control (3-bit) mode mask */
161 #define LCD_M_RESRT 0x07 /* V5 v. reg. int. resistor ratio (3-bit) ratio mask */
162 #define LCD_M_EVSET 0x3F /* Electronic volume mode byte (6-bit) volume mask */
163 #define LCD_M_SION 0x03 /* Static indicator ON (2-bit) mode mask */
165 /*** LCD Power control cirquits control masks ***/
166 #define LCD_PWRBSTR 0x04 /* Power control mode - Booster cirquit ON */
167 #define LCD_PWRVREG 0x02 /* Power control mode - Voltage regulator cirquit ON */
168 #define LCD_PWRVFOL 0x01 /* Power control mode - Voltage follower cirquit ON */
170 /*** LCD Static indicator states ***/
171 #define LCD_SIS_OFF 0x00 /* Static indicator register set - OFF state */
172 #define LCD_SIS_BL 0x01 /* Static indicator register set - 1s blink state */
173 #define LCD_SIS_RBL 0x02 /* Static indicator register set - .5s rapid blink state */
174 #define LCD_SIS_ON 0x03 /* Static indicator register set - constantly on state */
176 /*** LCD functions special parameters (commands) ***/
177 #define LCD_PREVP 0x80 /* Page number for moving to previous */
178 #define LCD_NEXTP 0x81 /* or next page */
179 #define LCD_ERR_P 0xFF /* Error in page number */
181 /*** LCD initialization settings ***/
182 #define LCD_BIAS LCD_BIAS9 /* Bias: 1/9 */
183 #define LCD_ADCMODE LCD_ADC_NRM /* ADC mode: normal */
184 #define LCD_COMDIR LCD_C_NRM /* Common output mode: normal */
185 #define LCD_RRATIO 0 /* Resistor ratio: 0 */
186 #define LCD_CNTRST 0x1C /* electronic volume: 1Ch */
187 #define LCD_POWERM (LCD_PWRBSTR | LCD_PWRVREG | LCD_PWRVFOL) /* Power mode: All on */
189 /**************************************************************************************/
191 static inline unsigned int sed156x_transfer(unsigned int val
)
198 SED156X_SPI_TXD(val
& 0x80);
200 SED156X_SPI_CLK_TOGGLE();
201 SED156X_SPI_BIT_DELAY();
203 if (SED156X_SPI_RXD())
205 SED156X_SPI_CLK_TOGGLE();
206 SED156X_SPI_BIT_DELAY();
212 unsigned int sed156x_data_transfer(unsigned int val
)
220 rx
= sed156x_transfer(val
);
227 void sed156x_data_block_transfer(const u8
*p
, int size
)
234 sed156x_transfer(*p
++);
239 unsigned int sed156x_cmd_transfer(unsigned int val
)
247 rx
= sed156x_transfer(val
);
255 /******************************************************************************/
257 static u8 hw_screen
[LCD_PAGES
][LCD_COLUMNS
];
258 static u8 last_hw_screen
[LCD_PAGES
][LCD_COLUMNS
];
259 static u8 sw_screen
[LCD_BYTE_WIDTH
* LCD_HEIGHT
];
261 void sed156x_sync(void)
265 const u8
*s
, *e
, *b
, *r
;
266 u8 v0
, v1
, v2
, v3
, v4
, v5
, v6
, v7
;
268 /* copy and rotate sw_screen to hw_screen */
269 for (i
= 0; i
< LCD_HEIGHT
/ 8; i
++) {
271 d
= &hw_screen
[i
][0];
272 s
= &sw_screen
[LCD_BYTE_WIDTH
* 8 * i
+ LCD_BYTE_WIDTH
- 1];
274 for (j
= 0; j
< LCD_WIDTH
/ 8; j
++) {
276 v0
= s
[0 * LCD_BYTE_WIDTH
];
277 v1
= s
[1 * LCD_BYTE_WIDTH
];
278 v2
= s
[2 * LCD_BYTE_WIDTH
];
279 v3
= s
[3 * LCD_BYTE_WIDTH
];
280 v4
= s
[4 * LCD_BYTE_WIDTH
];
281 v5
= s
[5 * LCD_BYTE_WIDTH
];
282 v6
= s
[6 * LCD_BYTE_WIDTH
];
283 v7
= s
[7 * LCD_BYTE_WIDTH
];
285 d
[0] = ((v7
& 0x01) << 7) |
294 d
[1] = ((v7
& 0x02) << 6) |
303 d
[2] = ((v7
& 0x04) << 5) |
312 d
[3] = ((v7
& 0x08) << 4) |
321 d
[4] = ((v7
& 0x10) << 3) |
330 d
[5] = ((v7
& 0x20) << 2) |
339 d
[6] = ((v7
& 0x40) << 1) |
362 /* and now output only the differences */
363 for (i
= 0; i
< LCD_PAGES
; i
++) {
365 b
= &hw_screen
[i
][0];
366 e
= &hw_screen
[i
][LCD_COLUMNS
];
368 d
= &last_hw_screen
[i
][0];
373 /* update only the differences */
375 while (s
< e
&& *s
== *d
) {
382 while (s
< e
&& *s
!= *d
)
387 if (i
!= last_page
) {
388 sed156x_cmd_transfer(LCD_PADDR
| i
);
392 sed156x_cmd_transfer(LCD_CADRH
| ((j
>> 4) & 0x0F));
393 sed156x_cmd_transfer(LCD_CADRL
| (j
& 0x0F));
394 sed156x_data_block_transfer(r
, s
- r
);
400 for (i = 0; i < LCD_PAGES; i++) {
401 sed156x_cmd_transfer(LCD_PADDR | i);
402 sed156x_cmd_transfer(LCD_CADRH | 0);
403 sed156x_cmd_transfer(LCD_CADRL | 0);
404 sed156x_data_block_transfer(&hw_screen[i][0], LCD_COLUMNS);
406 memcpy(last_hw_screen, hw_screen, sizeof(last_hw_screen));
410 void sed156x_clear(void)
412 memset(sw_screen
, 0, sizeof(sw_screen
));
415 void sed156x_output_at(int x
, int y
, const char *str
, int size
)
421 if ((unsigned int)y
>= LCD_TEXT_HEIGHT
|| (unsigned int)x
>= LCD_TEXT_WIDTH
)
424 p
= &sw_screen
[y
* VIDEO_FONT_HEIGHT
* LCD_BYTE_WIDTH
+ x
* VIDEO_FONT_BYTE_WIDTH
];
426 while (--size
>= 0) {
428 s
= &video_fontdata
[((int)*str
++ & 0xff) * VIDEO_FONT_BYTE_WIDTH
* VIDEO_FONT_HEIGHT
];
429 for (i
= 0; i
< VIDEO_FONT_HEIGHT
; i
++) {
430 for (j
= 0; j
< VIDEO_FONT_BYTE_WIDTH
; j
++)
432 p
+= LCD_BYTE_WIDTH
- VIDEO_FONT_BYTE_WIDTH
;
434 p
-= (LCD_BYTE_LINESZ
- VIDEO_FONT_BYTE_WIDTH
);
436 if (x
>= LCD_TEXT_WIDTH
)
442 void sed156x_reverse_at(int x
, int y
, int size
)
447 if ((unsigned int)y
>= LCD_TEXT_HEIGHT
|| (unsigned int)x
>= LCD_TEXT_WIDTH
)
450 p
= &sw_screen
[y
* VIDEO_FONT_HEIGHT
* LCD_BYTE_WIDTH
+ x
* VIDEO_FONT_BYTE_WIDTH
];
452 while (--size
>= 0) {
454 for (i
= 0; i
< VIDEO_FONT_HEIGHT
; i
++) {
455 for (j
= 0; j
< VIDEO_FONT_BYTE_WIDTH
; j
++, p
++)
457 p
+= LCD_BYTE_WIDTH
- VIDEO_FONT_BYTE_WIDTH
;
459 p
-= (LCD_BYTE_LINESZ
- VIDEO_FONT_BYTE_WIDTH
);
461 if (x
>= LCD_TEXT_WIDTH
)
467 void sed156x_scroll_line(void)
469 memmove(&sw_screen
[0],
470 &sw_screen
[LCD_BYTE_LINESZ
],
471 LCD_BYTE_WIDTH
* (LCD_HEIGHT
- VIDEO_FONT_HEIGHT
));
474 void sed156x_scroll(int dx
, int dy
)
476 u8
*p1
= NULL
, *p2
= NULL
, *p3
= NULL
; /* pacify gcc */
479 adx
= dx
> 0 ? dx
: -dx
;
480 ady
= dy
> 0 ? dy
: -dy
;
482 /* overscroll? erase everything */
483 if (adx
>= LCD_TEXT_WIDTH
|| ady
>= LCD_TEXT_HEIGHT
) {
484 memset(sw_screen
, 0, sizeof(sw_screen
));
488 sz
= LCD_BYTE_LINESZ
* ady
;
492 p3
= &sw_screen
[LCD_BYTE_WIDTH
* LCD_HEIGHT
- sz
];
500 memmove(p1
, p2
, LCD_BYTE_WIDTH
* LCD_HEIGHT
- sz
);
504 sz
= VIDEO_FONT_BYTE_WIDTH
* adx
;
507 p2
= &sw_screen
[0] + sz
;
508 p3
= &sw_screen
[0] + LCD_BYTE_WIDTH
- sz
;
510 p1
= &sw_screen
[0] + sz
;
517 for (i
= 0; i
< LCD_HEIGHT
; i
++) {
518 memmove(p1
, p2
, LCD_BYTE_WIDTH
- sz
);
520 p1
+= LCD_BYTE_WIDTH
;
521 p2
+= LCD_BYTE_WIDTH
;
522 p3
+= LCD_BYTE_WIDTH
;
527 void sed156x_init(void)
534 /* Send initialization commands to the LCD */
535 sed156x_cmd_transfer(LCD_OFF
); /* Turn display OFF */
536 sed156x_cmd_transfer(LCD_BIAS
); /* set the LCD Bias, */
537 sed156x_cmd_transfer(LCD_ADCMODE
); /* ADC mode, */
538 sed156x_cmd_transfer(LCD_COMDIR
); /* common output mode, */
539 sed156x_cmd_transfer(LCD_RESRT
| LCD_RRATIO
); /* resistor ratio, */
540 sed156x_cmd_transfer(LCD_EVSET
); /* electronic volume, */
541 sed156x_cmd_transfer(LCD_CNTRST
);
542 sed156x_cmd_transfer(LCD_PWRMD
| LCD_POWERM
); /* and power mode */
543 sed156x_cmd_transfer(LCD_PADDR
| 0); /* cursor home */
544 sed156x_cmd_transfer(LCD_CADRH
| 0);
545 sed156x_cmd_transfer(LCD_CADRL
| 0);
546 sed156x_cmd_transfer(LCD_LADDR
| 0); /* and display start line */
547 sed156x_cmd_transfer(LCD_DSP_NRM
); /* LCD display Normal */
549 /* clear everything */
550 memset(sw_screen
, 0, sizeof(sw_screen
));
551 memset(hw_screen
, 0, sizeof(hw_screen
));
552 memset(last_hw_screen
, 0, sizeof(last_hw_screen
));
554 for (i
= 0; i
< LCD_PAGES
; i
++) {
555 sed156x_cmd_transfer(LCD_PADDR
| i
);
556 sed156x_cmd_transfer(LCD_CADRH
| 0);
557 sed156x_cmd_transfer(LCD_CADRL
| 0);
558 sed156x_data_block_transfer(&hw_screen
[i
][0], LCD_COLUMNS
);
563 sed156x_cmd_transfer(LCD_ON
); /* Turn display ON */
566 #endif /* CONFIG_SED156X */