summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-h300.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd-h300.c')
-rw-r--r--firmware/drivers/lcd-h300.c219
1 files changed, 219 insertions, 0 deletions
diff --git a/firmware/drivers/lcd-h300.c b/firmware/drivers/lcd-h300.c
new file mode 100644
index 0000000000..1e71da59a8
--- /dev/null
+++ b/firmware/drivers/lcd-h300.c
@@ -0,0 +1,219 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2004 by Linus Nielsen Feltzing
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 "cpu.h"
22#include "lcd.h"
23#include "kernel.h"
24#include "thread.h"
25#include <string.h>
26#include <stdlib.h>
27#include "file.h"
28#include "debug.h"
29#include "system.h"
30#include "font.h"
31#include "bidi.h"
32
33void lcd_write_reg(int reg, int val)
34{
35 *(volatile unsigned short *)0xf0000000 = reg;
36 *(volatile unsigned short *)0xf0000002 = val;
37}
38
39void lcd_begin_write_gram(void)
40{
41 *(volatile unsigned short *)0xf0000000 = 0x22;
42}
43
44void lcd_write_data(const unsigned short* p_bytes, int count)
45{
46 while(count--)
47 *(volatile unsigned short *)0xf0000002 = *p_bytes++;
48}
49
50/*** hardware configuration ***/
51
52int lcd_default_contrast(void)
53{
54 return 28;
55}
56
57#ifndef SIMULATOR
58
59void lcd_set_contrast(int val)
60{
61 (void)val;
62}
63
64void lcd_set_invert_display(bool yesno)
65{
66 (void)yesno;
67}
68
69/* turn the display upside down (call lcd_update() afterwards) */
70void lcd_set_flip(bool yesno)
71{
72 (void)yesno;
73}
74
75/* Rolls up the lcd display by the specified amount of lines.
76 * Lines that are rolled out over the top of the screen are
77 * rolled in from the bottom again. This is a hardware
78 * remapping only and all operations on the lcd are affected.
79 * ->
80 * @param int lines - The number of lines that are rolled.
81 * The value must be 0 <= pixels < LCD_HEIGHT. */
82void lcd_roll(int lines)
83{
84 (void)lines;
85}
86
87#endif /* !SIMULATOR */
88
89/* LCD init */
90#ifndef SIMULATOR
91void lcd_init_device(void)
92{
93 /* GPO46 is LCD RESET */
94 or_l(0x00004000, &GPIO1_OUT);
95 or_l(0x00004000, &GPIO1_ENABLE);
96 or_l(0x00004000, &GPIO1_FUNCTION);
97
98 /* Reset LCD */
99 sleep(1);
100 and_l(~0x00004000, &GPIO1_OUT);
101 sleep(1);
102 or_l(0x00004000, &GPIO1_OUT);
103 sleep(1);
104
105 lcd_write_reg(0x00, 0x0001);
106 sleep(1);
107 lcd_write_reg(0x07, 0x0040);
108 lcd_write_reg(0x12, 0x0000);
109 lcd_write_reg(0x13, 0x0000);
110 sleep(1);
111 lcd_write_reg(0x11, 0x0003);
112 lcd_write_reg(0x12, 0x0008);
113 lcd_write_reg(0x13, 0x3617);
114 lcd_write_reg(0x12, 0x0008);
115 lcd_write_reg(0x10, 0x0004);
116 lcd_write_reg(0x10, 0x0004);
117 lcd_write_reg(0x11, 0x0002);
118 lcd_write_reg(0x12, 0x0018);
119 lcd_write_reg(0x10, 0x0044);
120 sleep(1);
121 lcd_write_reg(0x10, 0x0144);
122 lcd_write_reg(0x10, 0x0540);
123 lcd_write_reg(0x13, 0x3218);
124 lcd_write_reg(0x01, 0x001b);
125 lcd_write_reg(0x02, 0x0700);
126 lcd_write_reg(0x03, 0x7038);
127 lcd_write_reg(0x04, 0x7030);
128 lcd_write_reg(0x05, 0x0000);
129 lcd_write_reg(0x40, 0x0000);
130 lcd_write_reg(0x41, 0x0000);
131 lcd_write_reg(0x42, 0xdb00);
132 lcd_write_reg(0x43, 0x0000);
133 lcd_write_reg(0x44, 0xaf00);
134 lcd_write_reg(0x45, 0xdb00);
135
136 lcd_write_reg(0x0b, 0x0002);
137 lcd_write_reg(0x0c, 0x0003);
138 sleep(1);
139 lcd_write_reg(0x10, 0x4540);
140 lcd_write_reg(0x07, 0x0041);
141 sleep(1);
142 lcd_write_reg(0x08, 0x0808);
143 lcd_write_reg(0x09, 0x003f);
144 sleep(1);
145 lcd_write_reg(0x07, 0x0636);
146 sleep(1);
147 lcd_write_reg(0x07, 0x0626);
148 sleep(1);
149 lcd_write_reg(0x30, 0x0003);
150 lcd_write_reg(0x31, 0x0707);
151 lcd_write_reg(0x32, 0x0007);
152 lcd_write_reg(0x33, 0x0705);
153 lcd_write_reg(0x34, 0x0007);
154 lcd_write_reg(0x35, 0x0000);
155 lcd_write_reg(0x36, 0x0407);
156 lcd_write_reg(0x37, 0x0507);
157 lcd_write_reg(0x38, 0x1d09);
158 lcd_write_reg(0x39, 0x0303);
159
160 lcd_write_reg(0x13, 0x2610);
161
162 /* LCD ON */
163 lcd_write_reg(0x07, 0x0061);
164 sleep(1);
165 lcd_write_reg(0x07, 0x0067);
166 sleep(1);
167 lcd_write_reg(0x07, 0x0637);
168}
169
170/*** update functions ***/
171
172/* Performance function that works with an external buffer
173 note that by and bheight are in 8-pixel units! */
174void lcd_blit(const fb_data* data, int x, int by, int width,
175 int bheight, int stride)
176{
177 /* TODO: Implement lcd_blit() */
178 (void)data;
179 (void)x;
180 (void)by;
181 (void)width;
182 (void)bheight;
183 (void)stride;
184}
185
186
187/* Update the display.
188 This must be called after all other LCD functions that change the display. */
189void lcd_update(void) ICODE_ATTR;
190void lcd_update(void)
191{
192 /* Copy display bitmap to hardware */
193 lcd_write_reg(0x21, 0);
194 lcd_begin_write_gram();
195 lcd_write_data((unsigned short *)lcd_framebuffer, LCD_WIDTH*LCD_HEIGHT);
196}
197
198/* Update a fraction of the display. */
199void lcd_update_rect(int, int, int, int) ICODE_ATTR;
200void lcd_update_rect(int x, int y, int width, int height)
201{
202 int ymax = y + height;
203
204 if(x + width > LCD_WIDTH)
205 width = LCD_WIDTH - x;
206 if (width <= 0)
207 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
208 if(ymax >= LCD_HEIGHT)
209 ymax = LCD_HEIGHT-1;
210
211 /* Copy specified rectangle bitmap to hardware */
212 for (; y <= ymax; y++)
213 {
214 lcd_write_reg(0x21, (x << 8) + y);
215 lcd_begin_write_gram();
216 lcd_write_data ((unsigned short *)&lcd_framebuffer[y][x], width);
217 }
218}
219#endif /* !SIMULATOR */