diff options
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s/lcd-gigabeat-s.c')
-rw-r--r-- | firmware/target/arm/imx31/gigabeat-s/lcd-gigabeat-s.c | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/lcd-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/lcd-gigabeat-s.c new file mode 100644 index 0000000000..71d8e4bef4 --- /dev/null +++ b/firmware/target/arm/imx31/gigabeat-s/lcd-gigabeat-s.c | |||
@@ -0,0 +1,229 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2007 by Will Robertson | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <sys/types.h> | ||
22 | |||
23 | #include "config.h" | ||
24 | #include "cpu.h" | ||
25 | #include "string.h" | ||
26 | #include "lcd.h" | ||
27 | #include "kernel.h" | ||
28 | #include "lcd-target.h" | ||
29 | #include "backlight-target.h" | ||
30 | |||
31 | #define MAIN_LCD_IDMAC_CHANNEL 14 | ||
32 | #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)]) | ||
33 | |||
34 | static bool lcd_on = true; | ||
35 | static bool lcd_powered = true; | ||
36 | static unsigned lcd_yuv_options = 0; | ||
37 | |||
38 | /* Copies a rectangle from one framebuffer to another. Can be used in | ||
39 | single transfer mode with width = num pixels, and height = 1 which | ||
40 | allows a full-width rectangle to be copied more efficiently. */ | ||
41 | extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src, | ||
42 | int width, int height); | ||
43 | |||
44 | /* LCD init */ | ||
45 | void lcd_init_device(void) | ||
46 | { | ||
47 | /* Move the framebuffer */ | ||
48 | #ifdef BOOTLOADER | ||
49 | /* Only do this once to avoid flicker */ | ||
50 | memset(FRAME, 0x00, FRAME_SIZE); | ||
51 | #endif | ||
52 | IPU_IDMAC_CHA_EN &= ~(1ul << MAIN_LCD_IDMAC_CHANNEL); | ||
53 | IPU_IMA_ADDR = ((0x1 << 16) | (MAIN_LCD_IDMAC_CHANNEL << 4)) + (1 << 3); | ||
54 | IPU_IMA_DATA = FRAME_PHYS_ADDR; | ||
55 | IPU_IDMAC_CHA_EN |= (1ul << MAIN_LCD_IDMAC_CHANNEL); | ||
56 | } | ||
57 | |||
58 | /* Update a fraction of the display. */ | ||
59 | void lcd_update_rect(int x, int y, int width, int height) | ||
60 | { | ||
61 | fb_data *dst, *src; | ||
62 | |||
63 | if (!lcd_on) | ||
64 | return; | ||
65 | |||
66 | if (x + width > LCD_WIDTH) | ||
67 | width = LCD_WIDTH - x; /* Clip right */ | ||
68 | if (x < 0) | ||
69 | width += x, x = 0; /* Clip left */ | ||
70 | if (width <= 0) | ||
71 | return; /* nothing left to do */ | ||
72 | |||
73 | if (y + height > LCD_HEIGHT) | ||
74 | height = LCD_HEIGHT - y; /* Clip bottom */ | ||
75 | if (y < 0) | ||
76 | height += y, y = 0; /* Clip top */ | ||
77 | if (height <= 0) | ||
78 | return; /* nothing left to do */ | ||
79 | |||
80 | /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer | ||
81 | * and lcd_framebuffer */ | ||
82 | dst = (fb_data *)FRAME + LCD_WIDTH*y + x; | ||
83 | src = &lcd_framebuffer[y][x]; | ||
84 | |||
85 | /* Copy part of the Rockbox framebuffer to the second framebuffer */ | ||
86 | if (width < LCD_WIDTH) | ||
87 | { | ||
88 | /* Not full width - do line-by-line */ | ||
89 | lcd_copy_buffer_rect(dst, src, width, height); | ||
90 | } | ||
91 | else | ||
92 | { | ||
93 | /* Full width - copy as one line */ | ||
94 | lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | void lcd_sleep(void) | ||
99 | { | ||
100 | if (lcd_powered) | ||
101 | { | ||
102 | lcd_enable(false); | ||
103 | lcd_powered = false; | ||
104 | IPU_IDMAC_CHA_EN &= ~(1ul << MAIN_LCD_IDMAC_CHANNEL); | ||
105 | _backlight_lcd_sleep(); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | void lcd_enable(bool state) | ||
110 | { | ||
111 | if (state == lcd_on) | ||
112 | return; | ||
113 | |||
114 | if (state) | ||
115 | { | ||
116 | IPU_IDMAC_CHA_EN |= 1ul << MAIN_LCD_IDMAC_CHANNEL; | ||
117 | sleep(HZ/50); | ||
118 | lcd_powered = true; | ||
119 | lcd_on = true; | ||
120 | lcd_update(); | ||
121 | send_event(LCD_EVENT_ACTIVATION, NULL); | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | lcd_on = false; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | bool lcd_active(void) | ||
130 | { | ||
131 | return lcd_on; | ||
132 | } | ||
133 | |||
134 | /* Update the display. | ||
135 | This must be called after all other LCD functions that change the display. */ | ||
136 | void lcd_update(void) | ||
137 | { | ||
138 | if (!lcd_on) | ||
139 | return; | ||
140 | |||
141 | lcd_copy_buffer_rect((fb_data *)FRAME, &lcd_framebuffer[0][0], | ||
142 | LCD_WIDTH*LCD_HEIGHT, 1); | ||
143 | } | ||
144 | |||
145 | void lcd_yuv_set_options(unsigned options) | ||
146 | { | ||
147 | lcd_yuv_options = options; | ||
148 | } | ||
149 | |||
150 | /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */ | ||
151 | extern void lcd_write_yuv420_lines(fb_data *dst, | ||
152 | unsigned char const * const src[3], | ||
153 | int width, | ||
154 | int stride); | ||
155 | extern void lcd_write_yuv420_lines_odither(fb_data *dst, | ||
156 | unsigned char const * const src[3], | ||
157 | int width, | ||
158 | int stride, | ||
159 | int x_screen, /* To align dither pattern */ | ||
160 | int y_screen); | ||
161 | /* Performance function to blit a YUV bitmap directly to the LCD */ | ||
162 | /* For the Gigabeat - show it rotated */ | ||
163 | /* So the LCD_WIDTH is now the height */ | ||
164 | void lcd_blit_yuv(unsigned char * const src[3], | ||
165 | int src_x, int src_y, int stride, | ||
166 | int x, int y, int width, int height) | ||
167 | { | ||
168 | /* Caches for chroma data so it only need be recaculated every other | ||
169 | line */ | ||
170 | unsigned char const * yuv_src[3]; | ||
171 | off_t z; | ||
172 | |||
173 | if (!lcd_on) | ||
174 | return; | ||
175 | |||
176 | /* Sorry, but width and height must be >= 2 or else */ | ||
177 | width &= ~1; | ||
178 | height >>= 1; | ||
179 | |||
180 | y = LCD_WIDTH - 1 - y; | ||
181 | fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + y; | ||
182 | |||
183 | z = stride*src_y; | ||
184 | yuv_src[0] = src[0] + z + src_x; | ||
185 | yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); | ||
186 | yuv_src[2] = src[2] + (yuv_src[1] - src[1]); | ||
187 | |||
188 | if (lcd_yuv_options & LCD_YUV_DITHER) | ||
189 | { | ||
190 | do | ||
191 | { | ||
192 | lcd_write_yuv420_lines_odither(dst, yuv_src, width, stride, y, x); | ||
193 | yuv_src[0] += stride << 1; /* Skip down two luma lines */ | ||
194 | yuv_src[1] += stride >> 1; /* Skip down one chroma line */ | ||
195 | yuv_src[2] += stride >> 1; | ||
196 | dst -= 2; | ||
197 | y -= 2; | ||
198 | } | ||
199 | while (--height > 0); | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | do | ||
204 | { | ||
205 | lcd_write_yuv420_lines(dst, yuv_src, width, stride); | ||
206 | yuv_src[0] += stride << 1; /* Skip down two luma lines */ | ||
207 | yuv_src[1] += stride >> 1; /* Skip down one chroma line */ | ||
208 | yuv_src[2] += stride >> 1; | ||
209 | dst -= 2; | ||
210 | } | ||
211 | while (--height > 0); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | void lcd_set_contrast(int val) { | ||
216 | (void) val; | ||
217 | // TODO: | ||
218 | } | ||
219 | |||
220 | void lcd_set_invert_display(bool yesno) { | ||
221 | (void) yesno; | ||
222 | // TODO: | ||
223 | } | ||
224 | |||
225 | void lcd_set_flip(bool yesno) { | ||
226 | (void) yesno; | ||
227 | // TODO: | ||
228 | } | ||
229 | |||