summaryrefslogtreecommitdiff
path: root/firmware/target/arm/tcc77x/lcd-ssd1815.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/tcc77x/lcd-ssd1815.c')
-rw-r--r--firmware/target/arm/tcc77x/lcd-ssd1815.c267
1 files changed, 267 insertions, 0 deletions
diff --git a/firmware/target/arm/tcc77x/lcd-ssd1815.c b/firmware/target/arm/tcc77x/lcd-ssd1815.c
new file mode 100644
index 0000000000..4101f6ab7d
--- /dev/null
+++ b/firmware/target/arm/tcc77x/lcd-ssd1815.c
@@ -0,0 +1,267 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20
21#include "hwcompat.h"
22#include "kernel.h"
23#include "lcd.h"
24#include "system.h"
25#include "cpu.h"
26
27/*** definitions ***/
28
29#define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00)
30#define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10)
31#define LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO ((char)0x20)
32#define LCD_SET_POWER_CONTROL_REGISTER ((char)0x28)
33#define LCD_SET_DISPLAY_START_LINE ((char)0x40)
34#define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81)
35#define LCD_SET_SEGMENT_REMAP ((char)0xA0)
36#define LCD_SET_LCD_BIAS ((char)0xA2)
37#define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4)
38#define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5)
39#define LCD_SET_NORMAL_DISPLAY ((char)0xA6)
40#define LCD_SET_REVERSE_DISPLAY ((char)0xA7)
41#define LCD_SET_MULTIPLEX_RATIO ((char)0xA8)
42#define LCD_SET_BIAS_TC_OSC ((char)0xA9)
43#define LCD_SET_1OVER4_BIAS_RATIO ((char)0xAA)
44#define LCD_SET_INDICATOR_OFF ((char)0xAC)
45#define LCD_SET_INDICATOR_ON ((char)0xAD)
46#define LCD_SET_DISPLAY_OFF ((char)0xAE)
47#define LCD_SET_DISPLAY_ON ((char)0xAF)
48#define LCD_SET_PAGE_ADDRESS ((char)0xB0)
49#define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0)
50#define LCD_SET_TOTAL_FRAME_PHASES ((char)0xD2)
51#define LCD_SET_DISPLAY_OFFSET ((char)0xD3)
52#define LCD_SET_READ_MODIFY_WRITE_MODE ((char)0xE0)
53#define LCD_SOFTWARE_RESET ((char)0xE2)
54#define LCD_NOP ((char)0xE3)
55#define LCD_SET_END_OF_READ_MODIFY_WRITE_MODE ((char)0xEE)
56
57/* LCD command codes */
58#define LCD_CNTL_RESET 0xe2 /* Software reset */
59#define LCD_CNTL_POWER 0x2f /* Power control */
60#define LCD_CNTL_CONTRAST 0x81 /* Contrast */
61#define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */
62#define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */
63#define LCD_CNTL_DISPON 0xaf /* Display on */
64
65#define LCD_CNTL_PAGE 0xb0 /* Page address */
66#define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */
67#define LCD_CNTL_LOWCOL 0x00 /* Lower column address */
68
69/* TCC77x specific defines */
70#define LCD_BASE 0x50000000
71#define LCD_CMD *(volatile unsigned char*)(LCD_BASE)
72#define LCD_DATA *(volatile unsigned char*)(LCD_BASE+1)
73
74void lcd_write_command(int byte)
75{
76 LCD_CMD = byte;
77
78 asm volatile (
79 "nop \n\t"
80 "nop \n\t"
81 "nop \n\t"
82 );
83}
84
85void lcd_write_data(const fb_data* p_bytes, int count)
86{
87 while (count--)
88 {
89 LCD_DATA = *(p_bytes++);
90
91 asm volatile (
92 "nop \n\t"
93 "nop \n\t"
94 "nop \n\t"
95 );
96 }
97}
98
99/* End of TCC77x specific defines */
100
101
102/** globals **/
103
104static int xoffset; /* needed for flip */
105
106/*** hardware configuration ***/
107
108int lcd_default_contrast(void)
109{
110 return 0x1f;
111}
112
113void lcd_set_contrast(int val)
114{
115 lcd_write_command(LCD_CNTL_CONTRAST);
116 lcd_write_command(val);
117}
118
119void lcd_set_invert_display(bool yesno)
120{
121 if (yesno)
122 lcd_write_command(LCD_SET_REVERSE_DISPLAY);
123 else
124 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
125}
126
127/* turn the display upside down (call lcd_update() afterwards) */
128void lcd_set_flip(bool yesno)
129{
130 /* TODO: flip mode isn't working. The commands in the else part of
131 this function are how the original firmware inits the LCD */
132
133 if (yesno)
134 {
135 lcd_write_command(LCD_SET_SEGMENT_REMAP | 0x01);
136 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION);
137 xoffset = 132 - LCD_WIDTH; /* 132 colums minus the 128 we have */
138 }
139 else
140 {
141 lcd_write_command(LCD_SET_SEGMENT_REMAP);
142 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION | 0x08);
143 xoffset = 0;
144 }
145}
146
147
148/* LCD init */
149void lcd_init_device(void)
150{
151 uint32_t bus_width;
152
153 /* Telechips init the same as the original firmware */
154 CSCFG1 &= 0xc3ffc000;
155 CSCFG1 |= 0x3400101a;
156 CSCFG1 |= (1 << 21);
157 CSCFG1 &= ~(1 << 21);
158
159 bus_width = ((MCFG >> 11) & 0x3) ^ 3;
160
161 CSCFG1 = (bus_width << 28) |
162 (3 << 26) | /* MTYPE = 3 */
163 ((LCD_BASE >> 28) << 22) | /* CSBASE = 0x5 */
164 (1 << 20) | /* Unknown */
165 (3 << 11) | /* Setup time = 3 cycles */
166 (3 << 3) | /* Pulse width = 3+1 cycles */
167 (1 << 0); /* Hold time = 1 cycle */
168
169 /* SSD1815 inits like the original firmware */
170 lcd_write_command(LCD_SET_DISPLAY_OFF);
171 lcd_set_flip(false);
172 lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO | 5);
173 lcd_set_contrast(lcd_default_contrast());
174 lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER | 7);
175 /* power control register: op-amp=1, regulator=1, booster=1 */
176 lcd_write_command(LCD_SET_BIAS_TC_OSC);
177
178 /* 0xc2 = 110 000 10: Osc. Freq 110 - ???
179 TC value 000 - "-0.01%/C (TC0, POR)"
180 Bias ratio 10 - "1/9, 1/7 (POR)"
181 */
182 lcd_write_command(0xc2);
183 lcd_write_command(LCD_SET_DISPLAY_ON);
184
185 lcd_clear_display();
186 lcd_update();
187}
188
189/*** Update functions ***/
190
191/* Performance function that works with an external buffer
192 note that by and bheight are in 8-pixel units! */
193void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
194 int bheight, int stride)
195{
196 /* Copy display bitmap to hardware */
197 while (bheight--)
198 {
199 lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf));
200 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset)>>4) & 0xf));
201 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
202
203 lcd_write_data(data, width);
204 data += stride;
205 }
206}
207
208
209/* Performance function that works with an external buffer
210 note that by and bheight are in 8-pixel units! */
211void lcd_blit_grey_phase_blit(unsigned char *values, unsigned char *phases,
212 int x, int by, int width, int bheight, int stride)
213{
214 (void)values;
215 (void)phases;
216 (void)x;
217 (void)by;
218 (void)width;
219 (void)bheight;
220 (void)stride;
221}
222
223/* Update the display.
224 This must be called after all other LCD functions that change the display. */
225void lcd_update(void) ICODE_ATTR;
226void lcd_update(void)
227{
228 int y;
229
230 /* Copy display bitmap to hardware */
231 for (y = 0; y < LCD_FBHEIGHT; y++)
232 {
233 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
234 lcd_write_command (LCD_CNTL_HIGHCOL | ((xoffset >> 4) & 0xf));
235 lcd_write_command (LCD_CNTL_LOWCOL | (xoffset & 0xf));
236
237 lcd_write_data (lcd_framebuffer[y], LCD_WIDTH);
238 }
239}
240
241/* Update a fraction of the display. */
242void lcd_update_rect(int, int, int, int) ICODE_ATTR;
243void lcd_update_rect(int x, int y, int width, int height)
244{
245 int ymax;
246
247 /* The Y coordinates have to work on even 8 pixel rows */
248 ymax = (y + height-1) >> 3;
249 y >>= 3;
250
251 if(x + width > LCD_WIDTH)
252 width = LCD_WIDTH - x;
253 if (width <= 0)
254 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
255 if(ymax >= LCD_FBHEIGHT)
256 ymax = LCD_FBHEIGHT-1;
257
258 /* Copy specified rectange bitmap to hardware */
259 for (; y <= ymax; y++)
260 {
261 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
262 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset) >> 4) & 0xf));
263 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
264
265 lcd_write_data (&lcd_framebuffer[y][x], width);
266 }
267}