Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / firmware / target / arm / imx31 / gigabeat-s / lcd-gigabeat-s.c
blob5a0f81358def1ba43e4e84866f29207739d10b75
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 "inttypes.h"
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"
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);
44 /* LCD init */
45 void lcd_init_device(void)
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);
58 /* Update a fraction of the display. */
59 void lcd_update_rect(int x, int y, int width, int height)
61 fb_data *dst, *src;
63 if (!lcd_on)
64 return;
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 */
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 */
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);
91 else
93 /* Full width - copy as one line */
94 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
98 void lcd_sleep(void)
100 if (lcd_powered)
102 lcd_enable(false);
103 lcd_powered = false;
104 IPU_IDMAC_CHA_EN &= ~(1ul << MAIN_LCD_IDMAC_CHANNEL);
105 _backlight_lcd_sleep();
109 void lcd_enable(bool state)
111 if (state == lcd_on)
112 return;
114 if (state)
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);
123 else
125 lcd_on = false;
129 bool lcd_active(void)
131 return lcd_on;
134 /* Update the display.
135 This must be called after all other LCD functions that change the display. */
136 void lcd_update(void)
138 if (!lcd_on)
139 return;
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],
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)
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;
173 if (!lcd_on)
174 return;
176 /* Sorry, but width and height must be >= 2 or else */
177 width &= ~1;
178 height >>= 1;
180 y = LCD_WIDTH - 1 - y;
181 fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + y;
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]);
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;
196 dst -= 2;
197 y -= 2;
199 while (--height > 0);
201 else
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;
211 while (--height > 0);
215 void lcd_set_contrast(int val) {
216 (void) val;
217 // TODO:
220 void lcd_set_invert_display(bool yesno) {
221 (void) yesno;
222 // TODO:
225 void lcd_set_flip(bool yesno) {
226 (void) yesno;
227 // TODO: