diff options
author | Rafaël Carré <rafael.carre@gmail.com> | 2010-05-27 23:32:38 +0000 |
---|---|---|
committer | Rafaël Carré <rafael.carre@gmail.com> | 2010-05-27 23:32:38 +0000 |
commit | 6921a2b6b988e40fed1c2c3c5182381c26ef3d75 (patch) | |
tree | dd3ca9554ecf0a24d704d84b976b745955545b3e /firmware/target/arm/as3525/lcd-fuze.c | |
parent | 9d583f2b0b52919d961ed1853babebd6ec377c1d (diff) | |
download | rockbox-6921a2b6b988e40fed1c2c3c5182381c26ef3d75.tar.gz rockbox-6921a2b6b988e40fed1c2c3c5182381c26ef3d75.zip |
Merge common LCD code between fuzev1 & fuzev2
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26344 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/as3525/lcd-fuze.c')
-rw-r--r-- | firmware/target/arm/as3525/lcd-fuze.c | 338 |
1 files changed, 338 insertions, 0 deletions
diff --git a/firmware/target/arm/as3525/lcd-fuze.c b/firmware/target/arm/as3525/lcd-fuze.c new file mode 100644 index 0000000000..ef4791e6eb --- /dev/null +++ b/firmware/target/arm/as3525/lcd-fuze.c | |||
@@ -0,0 +1,338 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 by Dave Chapman | ||
11 | * | ||
12 | * LCD driver for the Sansa Fuze - controller unknown | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version 2 | ||
17 | * of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
20 | * KIND, either express or implied. | ||
21 | * | ||
22 | ****************************************************************************/ | ||
23 | #include "config.h" | ||
24 | |||
25 | #include "cpu.h" | ||
26 | #include "lcd.h" | ||
27 | #include "system.h" | ||
28 | #include "file.h" | ||
29 | #include "clock-target.h" | ||
30 | #include "dbop-as3525.h" | ||
31 | #include "lcd-fuze.h" | ||
32 | |||
33 | /* The controller is unknown, but some registers appear to be the same as the | ||
34 | HD66789R */ | ||
35 | static bool display_on = false; /* is the display turned on? */ | ||
36 | |||
37 | /* Flip Flag */ | ||
38 | static unsigned short r_entry_mode = R_ENTRY_MODE_HORZ_NORMAL; | ||
39 | |||
40 | /* Reverse Flag */ | ||
41 | static unsigned short r_disp_control_rev = R_DISP_CONTROL_NORMAL; | ||
42 | |||
43 | static const int xoffset = 20; | ||
44 | |||
45 | /*** hardware configuration ***/ | ||
46 | |||
47 | void lcd_set_contrast(int val) | ||
48 | { | ||
49 | (void)val; | ||
50 | } | ||
51 | |||
52 | void lcd_set_invert_display(bool yesno) | ||
53 | { | ||
54 | r_disp_control_rev = yesno ? R_DISP_CONTROL_REV : | ||
55 | R_DISP_CONTROL_NORMAL; | ||
56 | |||
57 | if (display_on) | ||
58 | { | ||
59 | lcd_write_reg(R_DISP_CONTROL1, 0x0013 | r_disp_control_rev); | ||
60 | } | ||
61 | |||
62 | } | ||
63 | |||
64 | #ifdef HAVE_LCD_FLIP | ||
65 | static bool display_flipped = false; | ||
66 | |||
67 | /* turn the display upside down */ | ||
68 | void lcd_set_flip(bool yesno) | ||
69 | { | ||
70 | display_flipped = yesno; | ||
71 | |||
72 | r_entry_mode = yesno ? R_ENTRY_MODE_HORZ_FLIPPED : | ||
73 | R_ENTRY_MODE_HORZ_NORMAL; | ||
74 | } | ||
75 | #endif | ||
76 | |||
77 | void fuze_display_on(void) | ||
78 | { | ||
79 | /* Initialise in the same way as the original firmare */ | ||
80 | |||
81 | lcd_write_reg(R_DISP_CONTROL1, 0); | ||
82 | lcd_write_reg(R_POWER_CONTROL4, 0); | ||
83 | |||
84 | lcd_write_reg(R_POWER_CONTROL2, 0x3704); | ||
85 | lcd_write_reg(0x14, 0x1a1b); | ||
86 | lcd_write_reg(R_POWER_CONTROL1, 0x3860); | ||
87 | lcd_write_reg(R_POWER_CONTROL4, 0x40); | ||
88 | |||
89 | lcd_write_reg(R_POWER_CONTROL4, 0x60); | ||
90 | |||
91 | lcd_write_reg(R_POWER_CONTROL4, 0x70); | ||
92 | lcd_write_reg(R_DRV_OUTPUT_CONTROL, 277); | ||
93 | lcd_write_reg(R_DRV_WAVEFORM_CONTROL, (7<<8)); | ||
94 | lcd_write_reg(R_ENTRY_MODE, r_entry_mode); | ||
95 | lcd_write_reg(R_DISP_CONTROL2, 0x01); | ||
96 | lcd_write_reg(R_FRAME_CYCLE_CONTROL, (1<<10)); | ||
97 | lcd_write_reg(R_EXT_DISP_IF_CONTROL, 0); | ||
98 | |||
99 | lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x40); | ||
100 | lcd_write_reg(R_GAMMA_FINE_ADJ_POS2, 0x0687); | ||
101 | lcd_write_reg(R_GAMMA_FINE_ADJ_POS3, 0x0306); | ||
102 | lcd_write_reg(R_GAMMA_GRAD_ADJ_POS, 0x104); | ||
103 | lcd_write_reg(R_GAMMA_FINE_ADJ_NEG1, 0x0585); | ||
104 | lcd_write_reg(R_GAMMA_FINE_ADJ_NEG2, 255+66); | ||
105 | lcd_write_reg(R_GAMMA_FINE_ADJ_NEG3, 0x0687+128); | ||
106 | lcd_write_reg(R_GAMMA_GRAD_ADJ_NEG, 259); | ||
107 | lcd_write_reg(R_GAMMA_AMP_ADJ_RES_POS, 0); | ||
108 | lcd_write_reg(R_GAMMA_AMP_AVG_ADJ_RES_NEG, 0); | ||
109 | |||
110 | lcd_write_reg(R_1ST_SCR_DRV_POS, (LCD_WIDTH - 1)); | ||
111 | lcd_write_reg(R_2ND_SCR_DRV_POS, 0); | ||
112 | lcd_write_reg(R_HORIZ_RAM_ADDR_POS, (LCD_WIDTH - 1)); | ||
113 | lcd_write_reg(R_VERT_RAM_ADDR_POS, 0); | ||
114 | lcd_write_reg(0x46, (((LCD_WIDTH - 1) + xoffset) << 8) | xoffset); | ||
115 | lcd_write_reg(0x47, (LCD_HEIGHT - 1)); | ||
116 | lcd_write_reg(0x48, 0x0); | ||
117 | |||
118 | lcd_write_reg(R_DISP_CONTROL1, 0x11); | ||
119 | lcd_write_reg(R_DISP_CONTROL1, 0x13 | r_disp_control_rev); | ||
120 | |||
121 | display_on = true; /* must be done before calling lcd_update() */ | ||
122 | lcd_update(); | ||
123 | } | ||
124 | |||
125 | #if defined(HAVE_LCD_ENABLE) | ||
126 | void lcd_enable(bool on) | ||
127 | { | ||
128 | if (display_on == on) | ||
129 | return; | ||
130 | |||
131 | if(on) | ||
132 | { | ||
133 | lcd_write_reg(R_START_OSC, 1); | ||
134 | lcd_write_reg(R_POWER_CONTROL1, 0); | ||
135 | lcd_write_reg(R_POWER_CONTROL2, 0x3704); | ||
136 | lcd_write_reg(0x14, 0x1a1b); | ||
137 | lcd_write_reg(R_POWER_CONTROL1, 0x3860); | ||
138 | lcd_write_reg(R_POWER_CONTROL4, 0x40); | ||
139 | lcd_write_reg(R_POWER_CONTROL4, 0x60); | ||
140 | lcd_write_reg(R_POWER_CONTROL4, 112); | ||
141 | lcd_write_reg(R_DISP_CONTROL1, 0x11); | ||
142 | lcd_write_reg(R_DISP_CONTROL1, 0x13 | r_disp_control_rev); | ||
143 | display_on = true; | ||
144 | lcd_update(); /* Resync display */ | ||
145 | send_event(LCD_EVENT_ACTIVATION, NULL); | ||
146 | sleep(0); | ||
147 | |||
148 | } | ||
149 | else | ||
150 | { | ||
151 | lcd_write_reg(R_DISP_CONTROL1, 0x22); | ||
152 | lcd_write_reg(R_DISP_CONTROL1, 0); | ||
153 | lcd_write_reg(R_POWER_CONTROL1, 1); | ||
154 | display_on = false; | ||
155 | } | ||
156 | } | ||
157 | #endif | ||
158 | |||
159 | #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP) | ||
160 | bool lcd_active(void) | ||
161 | { | ||
162 | return display_on; | ||
163 | } | ||
164 | #endif | ||
165 | |||
166 | /*** update functions ***/ | ||
167 | |||
168 | /* FIXME : find the datasheet for this RENESAS controller so we identify the | ||
169 | * registers used in windowing code (not present in HD66789R) */ | ||
170 | |||
171 | /* Set horizontal window addresses */ | ||
172 | static void lcd_window_x(int xmin, int xmax) | ||
173 | { | ||
174 | xmin += xoffset; | ||
175 | xmax += xoffset; | ||
176 | lcd_write_reg(R_HORIZ_RAM_ADDR_POS + 2, (xmax << 8) | xmin); | ||
177 | lcd_write_reg(R_RAM_ADDR_SET - 1, xmin); | ||
178 | } | ||
179 | |||
180 | /* Set vertical window addresses */ | ||
181 | static void lcd_window_y(int ymin, int ymax) | ||
182 | { | ||
183 | lcd_write_reg(R_VERT_RAM_ADDR_POS + 2, ymax); | ||
184 | lcd_write_reg(R_VERT_RAM_ADDR_POS + 3, ymin); | ||
185 | lcd_write_reg(R_RAM_ADDR_SET, ymin); | ||
186 | } | ||
187 | |||
188 | static unsigned lcd_yuv_options = 0; | ||
189 | |||
190 | void lcd_yuv_set_options(unsigned options) | ||
191 | { | ||
192 | lcd_yuv_options = options; | ||
193 | } | ||
194 | |||
195 | |||
196 | #ifndef BOOTLOADER | ||
197 | /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */ | ||
198 | extern void lcd_write_yuv420_lines(unsigned char const * const src[3], | ||
199 | int width, | ||
200 | int stride); | ||
201 | extern void lcd_write_yuv420_lines_odither(unsigned char const * const src[3], | ||
202 | int width, | ||
203 | int stride, | ||
204 | int x_screen, /* To align dither pattern */ | ||
205 | int y_screen); | ||
206 | |||
207 | /* Performance function to blit a YUV bitmap directly to the LCD | ||
208 | * src_x, src_y, width and height should be even | ||
209 | * x, y, width and height have to be within LCD bounds | ||
210 | */ | ||
211 | void lcd_blit_yuv(unsigned char * const src[3], | ||
212 | int src_x, int src_y, int stride, | ||
213 | int x, int y, int width, int height) | ||
214 | { | ||
215 | unsigned char const * yuv_src[3]; | ||
216 | off_t z; | ||
217 | |||
218 | /* Sorry, but width and height must be >= 2 or else */ | ||
219 | width &= ~1; | ||
220 | height >>= 1; | ||
221 | |||
222 | z = stride*src_y; | ||
223 | yuv_src[0] = src[0] + z + src_x; | ||
224 | yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); | ||
225 | yuv_src[2] = src[2] + (yuv_src[1] - src[1]); | ||
226 | |||
227 | #ifdef HAVE_LCD_FLIP | ||
228 | lcd_write_reg(R_ENTRY_MODE, | ||
229 | display_flipped ? R_ENTRY_MODE_VIDEO_FLIPPED : R_ENTRY_MODE_VIDEO_NORMAL | ||
230 | ); | ||
231 | #else | ||
232 | lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_VIDEO_NORMAL); | ||
233 | #endif | ||
234 | |||
235 | lcd_window_x(x, x + width - 1); | ||
236 | |||
237 | if (lcd_yuv_options & LCD_YUV_DITHER) | ||
238 | { | ||
239 | do | ||
240 | { | ||
241 | lcd_window_y(y, y + 1); | ||
242 | |||
243 | lcd_write_cmd(R_WRITE_DATA_2_GRAM); | ||
244 | |||
245 | lcd_write_yuv420_lines_odither(yuv_src, width, stride, x, y); | ||
246 | yuv_src[0] += stride << 1; /* Skip down two luma lines */ | ||
247 | yuv_src[1] += stride >> 1; /* Skip down one chroma line */ | ||
248 | yuv_src[2] += stride >> 1; | ||
249 | y += 2; | ||
250 | } | ||
251 | while (--height > 0); | ||
252 | } | ||
253 | else | ||
254 | { | ||
255 | do | ||
256 | { | ||
257 | lcd_window_y(y, y + 1); | ||
258 | |||
259 | lcd_write_cmd(R_WRITE_DATA_2_GRAM); | ||
260 | |||
261 | lcd_write_yuv420_lines(yuv_src, width, stride); | ||
262 | yuv_src[0] += stride << 1; /* Skip down two luma lines */ | ||
263 | yuv_src[1] += stride >> 1; /* Skip down one chroma line */ | ||
264 | yuv_src[2] += stride >> 1; | ||
265 | y += 2; | ||
266 | } | ||
267 | while (--height > 0); | ||
268 | } | ||
269 | } | ||
270 | |||
271 | #endif | ||
272 | |||
273 | |||
274 | /* Update the display. | ||
275 | This must be called after all other LCD functions that change the display. */ | ||
276 | void lcd_update(void) | ||
277 | { | ||
278 | if (!display_on) | ||
279 | return; | ||
280 | |||
281 | lcd_write_reg(R_ENTRY_MODE, r_entry_mode); | ||
282 | |||
283 | lcd_window_x(0, LCD_WIDTH - 1); | ||
284 | lcd_window_y(0, LCD_HEIGHT - 1); | ||
285 | |||
286 | lcd_write_cmd(R_WRITE_DATA_2_GRAM); | ||
287 | |||
288 | dbop_write_data((fb_data*)lcd_framebuffer, LCD_WIDTH*LCD_HEIGHT); | ||
289 | } | ||
290 | |||
291 | /* Update a fraction of the display. */ | ||
292 | void lcd_update_rect(int x, int y, int width, int height) | ||
293 | { | ||
294 | const fb_data *ptr; | ||
295 | |||
296 | if (!display_on) | ||
297 | return; | ||
298 | |||
299 | /* nothing to draw? */ | ||
300 | if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || | ||
301 | (y >= LCD_HEIGHT) || (x + width <= 0) || (y + height <= 0)) | ||
302 | return; | ||
303 | |||
304 | if (x < 0) | ||
305 | { /* clip left */ | ||
306 | width += x; | ||
307 | x = 0; | ||
308 | } | ||
309 | if (y < 0) | ||
310 | { /* clip top */ | ||
311 | height += y; | ||
312 | y = 0; | ||
313 | } | ||
314 | if (x + width > LCD_WIDTH) | ||
315 | width = LCD_WIDTH - x; /* clip right */ | ||
316 | if (y + height > LCD_HEIGHT) | ||
317 | height = LCD_HEIGHT - y; /* clip bottom */ | ||
318 | |||
319 | lcd_write_reg(R_ENTRY_MODE, r_entry_mode); | ||
320 | |||
321 | /* we need to make x and width even to enable 32bit transfers */ | ||
322 | width = (width + (x & 1) + 1) & ~1; | ||
323 | x &= ~1; | ||
324 | |||
325 | lcd_window_x(x, x + width - 1); | ||
326 | lcd_window_y(y, y + height -1); | ||
327 | |||
328 | lcd_write_cmd(R_WRITE_DATA_2_GRAM); | ||
329 | |||
330 | ptr = &lcd_framebuffer[y][x]; | ||
331 | |||
332 | do | ||
333 | { | ||
334 | dbop_write_data(ptr, width); | ||
335 | ptr += LCD_WIDTH; | ||
336 | } | ||
337 | while (--height > 0); | ||
338 | } | ||