9fd3b2f33637ab8ea76d6e9c68250dc606a843dd
[kugel-rb.git] / firmware / target / arm / imx31 / gigabeat-s / lcd-gigabeat-s.c
blob9fd3b2f33637ab8ea76d6e9c68250dc606a843dd
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include <sys/types.h>
22 #include "inttypes.h"
24 #include "config.h"
25 #include "cpu.h"
26 #include "string.h"
27 #include "lcd.h"
28 #include "kernel.h"
29 #include "lcd-target.h"
30 #include "backlight-target.h"
32 #define MAIN_LCD_IDMAC_CHANNEL 14
33 #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
35 static bool lcd_on = true;
36 static bool lcd_powered = true;
37 static unsigned lcd_yuv_options = 0;
39 /* Copies a rectangle from one framebuffer to another. Can be used in
40 single transfer mode with width = num pixels, and height = 1 which
41 allows a full-width rectangle to be copied more efficiently. */
42 extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
43 int width, int height);
45 /* LCD init */
46 void lcd_init_device(void)
48 /* Move the framebuffer */
49 #ifdef BOOTLOADER
50 /* Only do this once to avoid flicker */
51 memset(FRAME, 0x00, FRAME_SIZE);
52 #endif
53 IPU_IDMAC_CHA_EN &= ~(1ul << MAIN_LCD_IDMAC_CHANNEL);
54 IPU_IMA_ADDR = ((0x1 << 16) | (MAIN_LCD_IDMAC_CHANNEL << 4)) + (1 << 3);
55 IPU_IMA_DATA = FRAME_PHYS_ADDR;
56 IPU_IDMAC_CHA_EN |= (1ul << MAIN_LCD_IDMAC_CHANNEL);
59 /* Update a fraction of the display. */
60 void lcd_update_rect(int x, int y, int width, int height)
62 fb_data *dst, *src;
64 if (!lcd_on)
65 return;
67 if (x + width > LCD_WIDTH)
68 width = LCD_WIDTH - x; /* Clip right */
69 if (x < 0)
70 width += x, x = 0; /* Clip left */
71 if (width <= 0)
72 return; /* nothing left to do */
74 if (y + height > LCD_HEIGHT)
75 height = LCD_HEIGHT - y; /* Clip bottom */
76 if (y < 0)
77 height += y, y = 0; /* Clip top */
78 if (height <= 0)
79 return; /* nothing left to do */
81 /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer
82 * and lcd_framebuffer */
83 dst = (fb_data *)FRAME + LCD_WIDTH*y + x;
84 src = &lcd_framebuffer[y][x];
86 /* Copy part of the Rockbox framebuffer to the second framebuffer */
87 if (width < LCD_WIDTH)
89 /* Not full width - do line-by-line */
90 lcd_copy_buffer_rect(dst, src, width, height);
92 else
94 /* Full width - copy as one line */
95 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
99 void lcd_sleep(void)
101 if (lcd_powered)
103 lcd_enable(false);
104 lcd_powered = false;
105 IPU_IDMAC_CHA_EN &= ~(1ul << MAIN_LCD_IDMAC_CHANNEL);
106 _backlight_lcd_sleep();
110 void lcd_enable(bool state)
112 if (state == lcd_on)
113 return;
115 if (state)
117 IPU_IDMAC_CHA_EN |= 1ul << MAIN_LCD_IDMAC_CHANNEL;
118 sleep(HZ/50);
119 lcd_powered = true;
120 lcd_on = true;
121 lcd_update();
122 send_event(LCD_EVENT_ACTIVATION, NULL);
124 else
126 lcd_on = false;
130 bool lcd_active(void)
132 return lcd_on;
135 /* Update the display.
136 This must be called after all other LCD functions that change the display. */
137 void lcd_update(void)
139 if (!lcd_on)
140 return;
142 lcd_copy_buffer_rect((fb_data *)FRAME, &lcd_framebuffer[0][0],
143 LCD_WIDTH*LCD_HEIGHT, 1);
146 void lcd_yuv_set_options(unsigned options)
148 lcd_yuv_options = options;
151 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
152 extern void lcd_write_yuv420_lines(fb_data *dst,
153 unsigned char const * const src[3],
154 int width,
155 int stride);
156 extern void lcd_write_yuv420_lines_odither(fb_data *dst,
157 unsigned char const * const src[3],
158 int width,
159 int stride,
160 int x_screen, /* To align dither pattern */
161 int y_screen);
162 /* Performance function to blit a YUV bitmap directly to the LCD */
163 /* For the Gigabeat - show it rotated */
164 /* So the LCD_WIDTH is now the height */
165 void lcd_blit_yuv(unsigned char * const src[3],
166 int src_x, int src_y, int stride,
167 int x, int y, int width, int height)
169 /* Caches for chroma data so it only need be recaculated every other
170 line */
171 unsigned char const * yuv_src[3];
172 off_t z;
174 if (!lcd_on)
175 return;
177 /* Sorry, but width and height must be >= 2 or else */
178 width &= ~1;
179 height >>= 1;
181 y = LCD_WIDTH - 1 - y;
182 fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + y;
184 z = stride*src_y;
185 yuv_src[0] = src[0] + z + src_x;
186 yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
187 yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
189 if (lcd_yuv_options & LCD_YUV_DITHER)
193 lcd_write_yuv420_lines_odither(dst, yuv_src, width, stride, y, x);
194 yuv_src[0] += stride << 1; /* Skip down two luma lines */
195 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
196 yuv_src[2] += stride >> 1;
197 dst -= 2;
198 y -= 2;
200 while (--height > 0);
202 else
206 lcd_write_yuv420_lines(dst, yuv_src, width, stride);
207 yuv_src[0] += stride << 1; /* Skip down two luma lines */
208 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
209 yuv_src[2] += stride >> 1;
210 dst -= 2;
212 while (--height > 0);
216 void lcd_set_contrast(int val) {
217 (void) val;
218 // TODO:
221 void lcd_set_invert_display(bool yesno) {
222 (void) yesno;
223 // TODO:
226 void lcd_set_flip(bool yesno) {
227 (void) yesno;
228 // TODO: