1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Will Robertson
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
27 #include "lcd-target.h"
28 #include "backlight-target.h"
30 #define MAIN_LCD_IDMAC_CHANNEL 14
31 #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
33 static volatile bool lcd_on
= true;
34 volatile bool lcd_poweroff
= false;
35 static unsigned lcd_yuv_options
= 0;
37 ** This is imported from lcd-16bit.c
39 extern struct viewport
* current_vp
;
41 /* Copies a rectangle from one framebuffer to another. Can be used in
42 single transfer mode with width = num pixels, and height = 1 which
43 allows a full-width rectangle to be copied more efficiently. */
44 extern void lcd_copy_buffer_rect(fb_data
*dst
, const fb_data
*src
,
45 int width
, int height
);
48 void lcd_init_device(void)
50 /* Move the framebuffer */
52 /* Only do this once to avoid flicker */
53 memset(FRAME
, 0x00, FRAME_SIZE
);
55 IPU_IDMAC_CHA_EN
&= ~(1ul << MAIN_LCD_IDMAC_CHANNEL
);
56 IPU_IMA_ADDR
= ((0x1 << 16) | (MAIN_LCD_IDMAC_CHANNEL
<< 4)) + (1 << 3);
57 IPU_IMA_DATA
= FRAME_PHYS_ADDR
;
58 IPU_IDMAC_CHA_EN
|= (1ul << MAIN_LCD_IDMAC_CHANNEL
);
61 /* Update a fraction of the display. */
62 void lcd_update_rect(int x
, int y
, int width
, int height
)
69 if (x
+ width
> LCD_WIDTH
)
70 width
= LCD_WIDTH
- x
; /* Clip right */
72 width
+= x
, x
= 0; /* Clip left */
74 return; /* nothing left to do */
76 if (y
+ height
> LCD_HEIGHT
)
77 height
= LCD_HEIGHT
- y
; /* Clip bottom */
79 height
+= y
, y
= 0; /* Clip top */
81 return; /* nothing left to do */
83 /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer
84 * and lcd_framebuffer */
85 dst
= (fb_data
*)FRAME
+ LCD_WIDTH
*y
+ x
;
86 src
= &lcd_framebuffer
[y
][x
];
88 /* Copy part of the Rockbox framebuffer to the second framebuffer */
89 if (width
< LCD_WIDTH
)
91 /* Not full width - do line-by-line */
92 lcd_copy_buffer_rect(dst
, src
, width
, height
);
96 /* Full width - copy as one line */
97 lcd_copy_buffer_rect(dst
, src
, LCD_WIDTH
*height
, 1);
101 #ifdef HAVE_LCD_SLEEP
104 _backlight_lcd_sleep();
106 #endif /* HAVE_LCD_SLEEP */
109 void lcd_enable(bool state
)
114 bool lcd_enabled(void)
120 /* Update the display.
121 This must be called after all other LCD functions that change the display. */
122 void lcd_update(void)
127 lcd_copy_buffer_rect((fb_data
*)FRAME
, &lcd_framebuffer
[0][0],
128 LCD_WIDTH
*LCD_HEIGHT
, 1);
131 void lcd_bitmap_transparent_part(const fb_data
*src
, int src_x
, int src_y
,
132 int stride
, int x
, int y
, int width
,
138 if (x
+ width
> current_vp
->width
)
139 width
= current_vp
->width
- x
; /* Clip right */
141 if (x
< 0) /* Clip left */
149 return; /* nothing left to do */
151 if (y
+ height
> current_vp
->height
)
152 height
= current_vp
->height
- y
; /* Clip bottom */
154 if (y
< 0) /* Clip top */
162 return; /* nothing left to do */
164 src
+= stride
* src_y
+ src_x
; /* move starting point */
165 dst
= &lcd_framebuffer
[current_vp
->y
+y
][current_vp
->x
+x
];
169 "mov %[w], %[width] \r\n" /* Load width for inner loop */
171 "ldrh %[px], [%[s]], #2 \r\n" /* Load src pixel */
172 "add %[d], %[d], #2 \r\n" /* Uncoditionally increment dst */
173 "cmp %[px], %[fgcolor] \r\n" /* Compare to foreground color */
174 "streqh %[fgpat], [%[d], #-2] \r\n" /* Store foregroud if match */
175 "cmpne %[px], %[transcolor] \r\n" /* Compare to transparent color */
176 "strneh %[px], [%[d], #-2] \r\n" /* Store dst if not transparent */
177 "subs %[w], %[w], #1 \r\n" /* Width counter has run down? */
178 "bgt .nextpixel \r\n" /* More in this row? */
179 "add %[s], %[s], %[sstp], lsl #1 \r\n" /* Skip over to start of next line */
180 "add %[d], %[d], %[dstp], lsl #1 \r\n"
181 "subs %[h], %[h], #1 \r\n" /* Height counter has run down? */
182 "bgt .rowstart \r\n" /* More rows? */
183 : [w
]"=&r"(w
), [h
]"+&r"(height
), [px
]"=&r"(px
),
184 [s
]"+&r"(src
), [d
]"+&r"(dst
)
186 [sstp
]"r"(stride
- width
),
187 [dstp
]"r"(LCD_WIDTH
- width
),
188 [transcolor
]"r"(TRANSPARENT_COLOR
),
189 [fgcolor
]"r"(REPLACEWITHFG_COLOR
),
190 [fgpat
]"r"(current_vp
->fg_pattern
)
194 void lcd_yuv_set_options(unsigned options
)
196 lcd_yuv_options
= options
;
199 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
200 extern void lcd_write_yuv420_lines(fb_data
*dst
,
201 unsigned char const * const src
[3],
204 extern void lcd_write_yuv420_lines_odither(fb_data
*dst
,
205 unsigned char const * const src
[3],
208 int x_screen
, /* To align dither pattern */
210 /* Performance function to blit a YUV bitmap directly to the LCD */
211 /* For the Gigabeat - show it rotated */
212 /* So the LCD_WIDTH is now the height */
213 void lcd_blit_yuv(unsigned char * const src
[3],
214 int src_x
, int src_y
, int stride
,
215 int x
, int y
, int width
, int height
)
217 /* Caches for chroma data so it only need be recaculated every other
219 unsigned char const * yuv_src
[3];
225 /* Sorry, but width and height must be >= 2 or else */
229 y
= LCD_WIDTH
- 1 - y
;
230 fb_data
*dst
= (fb_data
*)FRAME
+ x
* LCD_WIDTH
+ y
;
233 yuv_src
[0] = src
[0] + z
+ src_x
;
234 yuv_src
[1] = src
[1] + (z
>> 2) + (src_x
>> 1);
235 yuv_src
[2] = src
[2] + (yuv_src
[1] - src
[1]);
237 if (lcd_yuv_options
& LCD_YUV_DITHER
)
241 lcd_write_yuv420_lines_odither(dst
, yuv_src
, width
, stride
, y
, x
);
242 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
243 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
244 yuv_src
[2] += stride
>> 1;
248 while (--height
> 0);
254 lcd_write_yuv420_lines(dst
, yuv_src
, width
, stride
);
255 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
256 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
257 yuv_src
[2] += stride
>> 1;
260 while (--height
> 0);
264 void lcd_set_contrast(int val
) {
269 void lcd_set_invert_display(bool yesno
) {
274 void lcd_set_flip(bool yesno
) {