diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2006-02-23 15:22:08 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2006-02-23 15:22:08 +0000 |
commit | b528d0a87990a7c3c9e97c0d597a7868b193d843 (patch) | |
tree | 8da18aa09e0a01c4d76bf977211c7787f41de8ad /firmware/target/coldfire | |
parent | 563012c50318eab7a3a6026d430165c787982e99 (diff) | |
download | rockbox-b528d0a87990a7c3c9e97c0d597a7868b193d843.tar.gz rockbox-b528d0a87990a7c3c9e97c0d597a7868b193d843.zip |
LCD driver for iAudio X5
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8807 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/coldfire')
-rwxr-xr-x | firmware/target/coldfire/iaudio/x5/lcd-x5.c | 299 |
1 files changed, 299 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iaudio/x5/lcd-x5.c b/firmware/target/coldfire/iaudio/x5/lcd-x5.c new file mode 100755 index 0000000000..81ceee67e9 --- /dev/null +++ b/firmware/target/coldfire/iaudio/x5/lcd-x5.c | |||
@@ -0,0 +1,299 @@ | |||
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 | |||
33 | static bool display_on=false; /* is the display turned on? */ | ||
34 | |||
35 | /* register defines for the Renesas HD66773R */ | ||
36 | #define R_HORIZ_RAM_ADDR_POS 0x16 | ||
37 | #define R_VERT_RAM_ADDR_POS 0x17 | ||
38 | #define R_RAM_ADDR_SET 0x21 | ||
39 | #define R_WRITE_DATA_2_GRAM 0x22 | ||
40 | |||
41 | /* Lookup tables for 16->18bit conversion */ | ||
42 | short low8to9[] = { | ||
43 | 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007, 0x010, 0x011, 0x012, | ||
44 | 0x013, 0x014, 0x015, 0x016, 0x017, 0x020, 0x021, 0x022, 0x023, 0x024, 0x025, | ||
45 | 0x026, 0x027, 0x030, 0x031, 0x032, 0x033, 0x034, 0x035, 0x036, 0x037, 0x040, | ||
46 | 0x041, 0x042, 0x043, 0x044, 0x045, 0x046, 0x047, 0x050, 0x051, 0x052, 0x053, | ||
47 | 0x054, 0x055, 0x056, 0x057, 0x060, 0x061, 0x062, 0x063, 0x064, 0x065, 0x066, | ||
48 | 0x067, 0x070, 0x071, 0x072, 0x073, 0x074, 0x075, 0x076, 0x077, 0x080, 0x081, | ||
49 | 0x082, 0x083, 0x084, 0x085, 0x086, 0x087, 0x090, 0x091, 0x092, 0x093, 0x094, | ||
50 | 0x095, 0x096, 0x097, 0x0a0, 0x0a1, 0x0a2, 0x0a3, 0x0a4, 0x0a5, 0x0a6, 0x0a7, | ||
51 | 0x0b0, 0x0b1, 0x0b2, 0x0b3, 0x0b4, 0x0b5, 0x0b6, 0x0b7, 0x0c0, 0x0c1, 0x0c2, | ||
52 | 0x0c3, 0x0c4, 0x0c5, 0x0c6, 0x0c7, 0x0d0, 0x0d1, 0x0d2, 0x0d3, 0x0d4, 0x0d5, | ||
53 | 0x0d6, 0x0d7, 0x0e0, 0x0e1, 0x0e2, 0x0e3, 0x0e4, 0x0e5, 0x0e6, 0x0e7, 0x0f0, | ||
54 | 0x0f1, 0x0f2, 0x0f3, 0x0f4, 0x0f5, 0x0f6, 0x0f7, 0x100, 0x101, 0x102, 0x103, | ||
55 | 0x104, 0x105, 0x106, 0x107, 0x110, 0x111, 0x112, 0x113, 0x114, 0x115, 0x116, | ||
56 | 0x117, 0x120, 0x121, 0x122, 0x123, 0x124, 0x125, 0x126, 0x127, 0x130, 0x131, | ||
57 | 0x132, 0x133, 0x134, 0x135, 0x136, 0x137, 0x140, 0x141, 0x142, 0x143, 0x144, | ||
58 | 0x145, 0x146, 0x147, 0x150, 0x151, 0x152, 0x153, 0x154, 0x155, 0x156, 0x157, | ||
59 | 0x160, 0x161, 0x162, 0x163, 0x164, 0x165, 0x166, 0x167, 0x170, 0x171, 0x172, | ||
60 | 0x173, 0x174, 0x175, 0x176, 0x177, 0x180, 0x181, 0x182, 0x183, 0x184, 0x185, | ||
61 | 0x186, 0x187, 0x190, 0x191, 0x192, 0x193, 0x194, 0x195, 0x196, 0x197, 0x1a0, | ||
62 | 0x1a1, 0x1a2, 0x1a3, 0x1a4, 0x1a5, 0x1a6, 0x1a7, 0x1b0, 0x1b1, 0x1b2, 0x1b3, | ||
63 | 0x1b4, 0x1b5, 0x1b6, 0x1b7, 0x1c0, 0x1c1, 0x1c2, 0x1c3, 0x1c4, 0x1c5, 0x1c6, | ||
64 | 0x1c7, 0x1d0, 0x1d1, 0x1d2, 0x1d3, 0x1d4, 0x1d5, 0x1d6, 0x1d7, 0x1e0, 0x1e1, | ||
65 | 0x1e2, 0x1e3, 0x1e4, 0x1e5, 0x1e6, 0x1e7, 0x1f0, 0x1f1, 0x1f2, 0x1f3, 0x1f4, | ||
66 | 0x1f5, 0x1f6, 0x1f7, | ||
67 | }; | ||
68 | short high8to9[] = { | ||
69 | 0x000, 0x002, 0x004, 0x006, 0x008, 0x00a, 0x00c, 0x00e, 0x010, 0x012, 0x014, | ||
70 | 0x016, 0x018, 0x01a, 0x01c, 0x01e, 0x020, 0x022, 0x024, 0x026, 0x028, 0x02a, | ||
71 | 0x02c, 0x02e, 0x030, 0x032, 0x034, 0x036, 0x038, 0x03a, 0x03c, 0x03e, 0x040, | ||
72 | 0x042, 0x044, 0x046, 0x048, 0x04a, 0x04c, 0x04e, 0x050, 0x052, 0x054, 0x056, | ||
73 | 0x058, 0x05a, 0x05c, 0x05e, 0x060, 0x062, 0x064, 0x066, 0x068, 0x06a, 0x06c, | ||
74 | 0x06e, 0x070, 0x072, 0x074, 0x076, 0x078, 0x07a, 0x07c, 0x07e, 0x080, 0x082, | ||
75 | 0x084, 0x086, 0x088, 0x08a, 0x08c, 0x08e, 0x090, 0x092, 0x094, 0x096, 0x098, | ||
76 | 0x09a, 0x09c, 0x09e, 0x0a0, 0x0a2, 0x0a4, 0x0a6, 0x0a8, 0x0aa, 0x0ac, 0x0ae, | ||
77 | 0x0b0, 0x0b2, 0x0b4, 0x0b6, 0x0b8, 0x0ba, 0x0bc, 0x0be, 0x0c0, 0x0c2, 0x0c4, | ||
78 | 0x0c6, 0x0c8, 0x0ca, 0x0cc, 0x0ce, 0x0d0, 0x0d2, 0x0d4, 0x0d6, 0x0d8, 0x0da, | ||
79 | 0x0dc, 0x0de, 0x0e0, 0x0e2, 0x0e4, 0x0e6, 0x0e8, 0x0ea, 0x0ec, 0x0ee, 0x0f0, | ||
80 | 0x0f2, 0x0f4, 0x0f6, 0x0f8, 0x0fa, 0x0fc, 0x0fe, 0x100, 0x102, 0x104, 0x106, | ||
81 | 0x108, 0x10a, 0x10c, 0x10e, 0x110, 0x112, 0x114, 0x116, 0x118, 0x11a, 0x11c, | ||
82 | 0x11e, 0x120, 0x122, 0x124, 0x126, 0x128, 0x12a, 0x12c, 0x12e, 0x130, 0x132, | ||
83 | 0x134, 0x136, 0x138, 0x13a, 0x13c, 0x13e, 0x140, 0x142, 0x144, 0x146, 0x148, | ||
84 | 0x14a, 0x14c, 0x14e, 0x150, 0x152, 0x154, 0x156, 0x158, 0x15a, 0x15c, 0x15e, | ||
85 | 0x160, 0x162, 0x164, 0x166, 0x168, 0x16a, 0x16c, 0x16e, 0x170, 0x172, 0x174, | ||
86 | 0x176, 0x178, 0x17a, 0x17c, 0x17e, 0x180, 0x182, 0x184, 0x186, 0x188, 0x18a, | ||
87 | 0x18c, 0x18e, 0x190, 0x192, 0x194, 0x196, 0x198, 0x19a, 0x19c, 0x19e, 0x1a0, | ||
88 | 0x1a2, 0x1a4, 0x1a6, 0x1a8, 0x1aa, 0x1ac, 0x1ae, 0x1b0, 0x1b2, 0x1b4, 0x1b6, | ||
89 | 0x1b8, 0x1ba, 0x1bc, 0x1be, 0x1c0, 0x1c2, 0x1c4, 0x1c6, 0x1c8, 0x1ca, 0x1cc, | ||
90 | 0x1ce, 0x1d0, 0x1d2, 0x1d4, 0x1d6, 0x1d8, 0x1da, 0x1dc, 0x1de, 0x1e0, 0x1e2, | ||
91 | 0x1e4, 0x1e6, 0x1e8, 0x1ea, 0x1ec, 0x1ee, 0x1f0, 0x1f2, 0x1f4, 0x1f6, 0x1f8, | ||
92 | 0x1fa, 0x1fc, 0x1fe, | ||
93 | }; | ||
94 | |||
95 | /* called very frequently - inline! */ | ||
96 | inline void lcd_write_reg(int reg, int val) | ||
97 | { | ||
98 | *(volatile unsigned short *)0xf0008000 = (reg >> 8) << 1; | ||
99 | *(volatile unsigned short *)0xf0008000 = (reg & 0xff) << 1; | ||
100 | *(volatile unsigned short *)0xf0008002 = (val >> 8) << 1; | ||
101 | *(volatile unsigned short *)0xf0008002 = (val & 0xff) << 1; | ||
102 | } | ||
103 | |||
104 | /* called very frequently - inline! */ | ||
105 | inline void lcd_begin_write_gram(void) | ||
106 | { | ||
107 | *(volatile unsigned short *)0xf0008000 = (R_WRITE_DATA_2_GRAM >> 8) << 1; | ||
108 | *(volatile unsigned short *)0xf0008000 = (R_WRITE_DATA_2_GRAM & 0xff) << 1; | ||
109 | } | ||
110 | |||
111 | /* called very frequently - inline! */ | ||
112 | inline void lcd_write_data(const unsigned short* p_bytes, int count) ICODE_ATTR; | ||
113 | inline void lcd_write_data(const unsigned short* p_bytes, int count) | ||
114 | { | ||
115 | unsigned short tmp; | ||
116 | while(count--) { | ||
117 | tmp = *p_bytes++; | ||
118 | *(volatile unsigned short *)0xf0008002 = high8to9[tmp >> 8]; | ||
119 | *(volatile unsigned short *)0xf0008002 = low8to9[tmp&255]; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | /*** hardware configuration ***/ | ||
124 | |||
125 | void lcd_set_contrast(int val) | ||
126 | { | ||
127 | (void)val; | ||
128 | } | ||
129 | |||
130 | void lcd_set_invert_display(bool yesno) | ||
131 | { | ||
132 | (void)yesno; | ||
133 | } | ||
134 | |||
135 | /* turn the display upside down (call lcd_update() afterwards) */ | ||
136 | void lcd_set_flip(bool yesno) | ||
137 | { | ||
138 | (void)yesno; | ||
139 | } | ||
140 | |||
141 | /* Rolls up the lcd display by the specified amount of lines. | ||
142 | * Lines that are rolled out over the top of the screen are | ||
143 | * rolled in from the bottom again. This is a hardware | ||
144 | * remapping only and all operations on the lcd are affected. | ||
145 | * -> | ||
146 | * @param int lines - The number of lines that are rolled. | ||
147 | * The value must be 0 <= pixels < LCD_HEIGHT. */ | ||
148 | void lcd_roll(int lines) | ||
149 | { | ||
150 | (void)lines; | ||
151 | } | ||
152 | |||
153 | /* LCD init | ||
154 | * These settings are taken from the original X5 firmware | ||
155 | */ | ||
156 | void lcd_init_device(void) | ||
157 | { | ||
158 | display_on=true; | ||
159 | |||
160 | /* LCD Reset */ | ||
161 | and_l(~0x00000010, &GPIO1_OUT); | ||
162 | or_l(0x00000010, &GPIO1_ENABLE); | ||
163 | or_l(0x00000010, &GPIO1_FUNCTION); | ||
164 | sleep(HZ/100); | ||
165 | or_l(0x00000010, &GPIO1_OUT); | ||
166 | |||
167 | sleep(HZ/100); | ||
168 | |||
169 | lcd_write_reg(0, 0x0001); | ||
170 | |||
171 | sleep(HZ/50); | ||
172 | |||
173 | lcd_write_reg(0x0d, 0x0401); | ||
174 | lcd_write_reg(0x0e, 0x321e); | ||
175 | lcd_write_reg(0x01, 0x0113); | ||
176 | lcd_write_reg(0x02, 0x0700); | ||
177 | lcd_write_reg(0x05, 0x9018); | ||
178 | lcd_write_reg(0x06, 0x0000); | ||
179 | lcd_write_reg(0x0b, 0x4000); | ||
180 | |||
181 | sleep(HZ/100); | ||
182 | |||
183 | lcd_write_reg(0x21,0x0000); | ||
184 | lcd_write_reg(0x30,0x0003); | ||
185 | lcd_write_reg(0x31,0x0400); | ||
186 | lcd_write_reg(0x32,0x0407); | ||
187 | lcd_write_reg(0x33,0x0305); | ||
188 | lcd_write_reg(0x34,0x0003); | ||
189 | lcd_write_reg(0x35,0x0704); | ||
190 | lcd_write_reg(0x36,0x0407); | ||
191 | lcd_write_reg(0x37,0x0503); | ||
192 | lcd_write_reg(0x0f,0x0000); | ||
193 | lcd_write_reg(0x11,0x0000); | ||
194 | lcd_write_reg(0x14,0x9f00); | ||
195 | lcd_write_reg(0x15,0x5c00); | ||
196 | lcd_write_reg(0x16,0x7f00); | ||
197 | lcd_write_reg(0x17,0x9f00); | ||
198 | lcd_write_reg(0x3a,0x1409); | ||
199 | lcd_write_reg(0x3b,0x0602); | ||
200 | |||
201 | lcd_write_reg(0x0c,0x0001); | ||
202 | |||
203 | sleep(HZ/25); | ||
204 | |||
205 | lcd_write_reg(0x03,0x002c); | ||
206 | lcd_write_reg(0x04,0x8000); | ||
207 | |||
208 | sleep(HZ/25); | ||
209 | |||
210 | lcd_write_reg(0x0e,0x3318); | ||
211 | |||
212 | sleep(HZ/25); | ||
213 | |||
214 | lcd_write_reg(0x0d,0x0411); | ||
215 | |||
216 | sleep(HZ/100); | ||
217 | |||
218 | lcd_write_reg(0x07,0x0006); | ||
219 | lcd_write_reg(0x07,0x036); | ||
220 | lcd_write_reg(0x07,0x037); | ||
221 | lcd_write_reg(0x07,0x0037); | ||
222 | return; | ||
223 | } | ||
224 | |||
225 | void lcd_enable(bool on) | ||
226 | { | ||
227 | display_on = on; | ||
228 | } | ||
229 | |||
230 | /*** update functions ***/ | ||
231 | |||
232 | /* Performance function that works with an external buffer | ||
233 | note that by and bheight are in 8-pixel units! */ | ||
234 | void lcd_blit(const fb_data* data, int x, int by, int width, | ||
235 | int bheight, int stride) | ||
236 | { | ||
237 | /* TODO: Implement lcd_blit() */ | ||
238 | (void)data; | ||
239 | (void)x; | ||
240 | (void)by; | ||
241 | (void)width; | ||
242 | (void)bheight; | ||
243 | (void)stride; | ||
244 | /*if(display_on)*/ | ||
245 | } | ||
246 | |||
247 | |||
248 | /* Update the display. | ||
249 | This must be called after all other LCD functions that change the display. */ | ||
250 | void lcd_update(void) ICODE_ATTR; | ||
251 | void lcd_update(void) | ||
252 | { | ||
253 | if(display_on){ | ||
254 | |||
255 | /* Copy display bitmap to hardware */ | ||
256 | lcd_write_reg(R_RAM_ADDR_SET, 0x0000); | ||
257 | lcd_begin_write_gram(); | ||
258 | lcd_write_data((unsigned short *)lcd_framebuffer, LCD_WIDTH*LCD_HEIGHT); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | /* Update a fraction of the display. */ | ||
263 | void lcd_update_rect(int, int, int, int) ICODE_ATTR; | ||
264 | void lcd_update_rect(int x, int y, int width, int height) | ||
265 | { | ||
266 | if(display_on) { | ||
267 | int ymax = y + height; | ||
268 | |||
269 | if(x + width > LCD_WIDTH) | ||
270 | width = LCD_WIDTH - x; | ||
271 | if (width <= 0) | ||
272 | return; /* nothing left to do, 0 is harmful to lcd_write_data() */ | ||
273 | if(ymax >= LCD_HEIGHT) | ||
274 | ymax = LCD_HEIGHT-1; | ||
275 | |||
276 | /* set update window */ | ||
277 | |||
278 | /* horiz ram addr */ | ||
279 | lcd_write_reg(R_HORIZ_RAM_ADDR_POS, (ymax<<8) | y); | ||
280 | |||
281 | /* vert ram addr */ | ||
282 | lcd_write_reg(R_VERT_RAM_ADDR_POS,((x+width-1)<<8) | x); | ||
283 | lcd_write_reg(R_RAM_ADDR_SET, (x<<8) | y); | ||
284 | lcd_begin_write_gram(); | ||
285 | |||
286 | /* Copy specified rectangle bitmap to hardware */ | ||
287 | for (; y <= ymax; y++) | ||
288 | { | ||
289 | lcd_write_data ((unsigned short *)&lcd_framebuffer[y][x], width); | ||
290 | } | ||
291 | |||
292 | /* reset update window */ | ||
293 | /* horiz ram addr: 0 - 175 */ | ||
294 | lcd_write_reg(R_HORIZ_RAM_ADDR_POS, 0xaf00); | ||
295 | |||
296 | /* vert ram addr: 0 - 219 */ | ||
297 | lcd_write_reg(R_VERT_RAM_ADDR_POS, 0xdb00); | ||
298 | } | ||
299 | } | ||