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 ****************************************************************************/
28 #include "lcd-target.h"
29 #include "backlight-target.h"
31 #define MAIN_LCD_IDMAC_CHANNEL 14
32 #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
34 static bool lcd_on
= true;
35 static bool lcd_powered
= true;
36 static unsigned lcd_yuv_options
= 0;
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
);
45 void lcd_init_device(void)
47 /* Move the framebuffer */
49 /* Only do this once to avoid flicker */
50 memset(FRAME
, 0x00, FRAME_SIZE
);
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
);
58 /* Update a fraction of the display. */
59 void lcd_update_rect(int x
, int y
, int width
, int height
)
66 if (x
+ width
> LCD_WIDTH
)
67 width
= LCD_WIDTH
- x
; /* Clip right */
69 width
+= x
, x
= 0; /* Clip left */
71 return; /* nothing left to do */
73 if (y
+ height
> LCD_HEIGHT
)
74 height
= LCD_HEIGHT
- y
; /* Clip bottom */
76 height
+= y
, y
= 0; /* Clip top */
78 return; /* nothing left to do */
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
];
85 /* Copy part of the Rockbox framebuffer to the second framebuffer */
86 if (width
< LCD_WIDTH
)
88 /* Not full width - do line-by-line */
89 lcd_copy_buffer_rect(dst
, src
, width
, height
);
93 /* Full width - copy as one line */
94 lcd_copy_buffer_rect(dst
, src
, LCD_WIDTH
*height
, 1);
104 IPU_IDMAC_CHA_EN
&= ~(1ul << MAIN_LCD_IDMAC_CHANNEL
);
105 _backlight_lcd_sleep();
109 void lcd_enable(bool state
)
116 IPU_IDMAC_CHA_EN
|= 1ul << MAIN_LCD_IDMAC_CHANNEL
;
121 send_event(LCD_EVENT_ACTIVATION
, NULL
);
129 bool lcd_active(void)
134 /* Update the display.
135 This must be called after all other LCD functions that change the display. */
136 void lcd_update(void)
141 lcd_copy_buffer_rect((fb_data
*)FRAME
, &lcd_framebuffer
[0][0],
142 LCD_WIDTH
*LCD_HEIGHT
, 1);
145 void lcd_yuv_set_options(unsigned options
)
147 lcd_yuv_options
= options
;
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],
155 extern void lcd_write_yuv420_lines_odither(fb_data
*dst
,
156 unsigned char const * const src
[3],
159 int x_screen
, /* To align dither pattern */
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
)
168 /* Caches for chroma data so it only need be recaculated every other
170 unsigned char const * yuv_src
[3];
176 /* Sorry, but width and height must be >= 2 or else */
180 y
= LCD_WIDTH
- 1 - y
;
181 fb_data
*dst
= (fb_data
*)FRAME
+ x
* LCD_WIDTH
+ 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]);
188 if (lcd_yuv_options
& LCD_YUV_DITHER
)
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;
199 while (--height
> 0);
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;
211 while (--height
> 0);
215 void lcd_set_contrast(int val
) {
220 void lcd_set_invert_display(bool yesno
) {
225 void lcd_set_flip(bool yesno
) {