Fix typo.
[Rockbox.git] / firmware / export / lcd.h
blobeb67a122119b1c72fa34875f0e60f50cb766885e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Alan Korr
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #ifndef __LCD_H__
21 #define __LCD_H__
23 #include <stdbool.h>
24 #include "cpu.h"
25 #include "config.h"
27 #define STYLE_DEFAULT 0x00000000
28 #define STYLE_INVERT 0x20000000
29 #define STYLE_COLORED 0x10000000
30 #define STYLE_COLORBAR 0x40000000
31 #define STYLE_GRADIENT 0x80000000
32 #define STYLE_COLOR_MASK 0x0000FFFF
34 #ifdef SIMULATOR
35 #ifndef MAX_PATH
36 #define MAX_PATH 260
37 #endif
38 #else
39 #include "file.h" /* for MAX_PATH; FIXME: Why does this not work for sims? */
40 #endif /* SIMULATOR */
42 #if LCD_DEPTH <=8
43 typedef unsigned char fb_data;
44 #elif LCD_DEPTH <= 16
45 typedef unsigned short fb_data;
46 #else /* LCD_DEPTH > 16 */
47 typedef unsigned long fb_data;
48 #endif /* LCD_DEPTH */
50 /* common functions */
51 extern void lcd_write_command(int byte);
52 extern void lcd_write_command_e(int cmd, int data);
53 extern void lcd_write_command_ex(int cmd, int data1, int data2);
54 extern void lcd_write_data(const fb_data* p_bytes, int count);
55 extern void lcd_init(void);
57 #ifdef SIMULATOR
58 /* Define a dummy device specific init for the sims */
59 #define lcd_init_device()
60 #else
61 extern void lcd_init_device(void);
62 #endif /* SIMULATOR */
64 extern void lcd_backlight(bool on);
65 extern int lcd_default_contrast(void);
66 extern void lcd_set_contrast(int val);
67 extern void lcd_setmargins(int xmargin, int ymargin);
68 extern int lcd_getxmargin(void);
69 extern int lcd_getymargin(void);
70 extern int lcd_getstringsize(const unsigned char *str, int *w, int *h);
72 extern void lcd_update(void);
73 extern void lcd_clear_display(void);
74 extern void lcd_putsxy(int x, int y, const unsigned char *string);
75 extern void lcd_puts(int x, int y, const unsigned char *string);
76 extern void lcd_puts_style(int x, int y, const unsigned char *string, int style);
77 extern void lcd_puts_offset(int x, int y, const unsigned char *str, int offset);
78 extern void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
79 int offset);
80 extern void lcd_putc(int x, int y, unsigned long ucs);
81 extern void lcd_stop_scroll(void);
82 extern void lcd_bidir_scroll(int threshold);
83 extern void lcd_scroll_speed(int speed);
84 extern void lcd_scroll_delay(int ms);
85 extern void lcd_puts_scroll(int x, int y, const unsigned char* string);
86 extern void lcd_puts_scroll_style(int x, int y, const unsigned char* string,
87 int style);
89 #if defined(HAVE_LCD_COLOR)
90 #define LCD_YUV_DITHER 0x1
91 extern void lcd_yuv_set_options(unsigned options);
92 extern void lcd_yuv_blit(unsigned char * const src[3],
93 int src_x, int src_y, int stride,
94 int x, int y, int width, int height);
95 #endif
97 #ifdef HAVE_LCD_BITMAP
98 /* performance function */
99 extern void lcd_blit(const fb_data* data, int x, int by, int width,
100 int bheight, int stride);
102 /* update a fraction of the screen */
103 extern void lcd_update_rect(int x, int y, int width, int height);
105 #ifdef HAVE_REMOTE_LCD
106 extern void lcd_remote_update(void);
107 /* update a fraction of the screen */
108 extern void lcd_remote_update_rect(int x, int y, int width, int height);
109 #endif /* HAVE_REMOTE_LCD */
110 #endif /* HAVE_LCD_BITMAP */
112 #ifdef HAVE_LCD_CHARCELLS
114 /* Icon definitions for lcd_icon() */
115 enum
117 ICON_BATTERY = 0,
118 ICON_BATTERY_1,
119 ICON_BATTERY_2,
120 ICON_BATTERY_3,
121 ICON_USB,
122 ICON_PLAY,
123 ICON_RECORD,
124 ICON_PAUSE,
125 ICON_AUDIO,
126 ICON_REPEAT,
127 ICON_1,
128 ICON_VOLUME,
129 ICON_VOLUME_1,
130 ICON_VOLUME_2,
131 ICON_VOLUME_3,
132 ICON_VOLUME_4,
133 ICON_VOLUME_5,
134 ICON_PARAM
137 void lcd_icon(int icon, bool enable);
138 void lcd_double_height(bool on);
139 void lcd_define_pattern(unsigned long ucs, const char *pattern);
140 unsigned long lcd_get_locked_pattern(void);
141 void lcd_unlock_pattern(unsigned long ucs);
142 void lcd_put_cursor(int x, int y, unsigned long cursor_ucs);
143 void lcd_remove_cursor(void);
144 #define JUMP_SCROLL_ALWAYS 5
145 extern void lcd_jump_scroll(int mode); /* 0=off, 1=once, ..., ALWAYS */
146 extern void lcd_jump_scroll_delay(int ms);
147 #endif /* HAVE_LCD_CHARCELLS */
149 /* Draw modes */
150 #define DRMODE_COMPLEMENT 0
151 #define DRMODE_BG 1
152 #define DRMODE_FG 2
153 #define DRMODE_SOLID 3
154 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
156 /* Low-level drawing function types */
157 typedef void lcd_pixelfunc_type(int x, int y);
158 typedef void lcd_blockfunc_type(fb_data *address, unsigned mask, unsigned bits);
159 #if LCD_DEPTH >= 8
160 typedef void lcd_fastpixelfunc_type(fb_data *address);
161 #endif
163 #ifdef HAVE_LCD_BITMAP
165 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
166 LCD_REMOTE_DEPTH > 1
167 /* Just return color for screens use */
168 static inline unsigned lcd_color_to_native(unsigned color)
169 { return color; }
170 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
171 #else
172 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
173 #endif
175 #ifdef HAVE_LCD_COLOR
176 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
177 #define LCD_MAX_RED 31
178 #define LCD_MAX_GREEN 63
179 #define LCD_MAX_BLUE 31
180 #define LCD_RED_BITS 5
181 #define LCD_GREEN_BITS 6
182 #define LCD_BLUE_BITS 5
184 /* pack/unpack native RGB values */
185 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
186 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
187 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
188 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
190 /* pack/unpack 24-bit RGB values */
191 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
192 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 11) & 0x07) )
193 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 5) & 0x03) )
194 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) ) & 0x07) )
196 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
197 /* RGB3553 */
198 #define _LCD_UNSWAP_COLOR(x) swap16(x)
199 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
200 (((g) >> 3) ) | \
201 (((g) & 0x07) << 13) | \
202 (((b) << 8) ) )
203 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
204 (((g) >> 5) ) | \
205 (((g) & 0x1c) << 11) | \
206 (((b) >> 3) << 8) )
207 /* swap color once - not currenly used in static inits */
208 #define _SWAPUNPACK(x, _unp_) \
209 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
210 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
211 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
212 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
213 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
214 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
215 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
216 #else /* LCD_PIXELFORMAT == RGB565 */
217 /* RGB565 */
218 #define _LCD_UNSWAP_COLOR(x) (x)
219 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
220 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
221 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
222 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
223 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
224 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
225 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
226 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
227 #endif /* RGB565* */
228 #else
229 /* other colour depths */
230 #endif
232 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
233 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
234 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
235 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
236 #define LCD_DEFAULT_FG LCD_BLACK
237 #define LCD_DEFAULT_BG LCD_RGBPACK(182, 198, 229) /* rockbox blue */
238 #define LCD_DEFAULT_LS LCD_WHITE
240 #elif LCD_DEPTH > 1 /* greyscale */
242 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
243 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
245 #define LCD_BLACK LCD_BRIGHTNESS(0)
246 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
247 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
248 #define LCD_WHITE LCD_BRIGHTNESS(255)
249 #define LCD_DEFAULT_FG LCD_BLACK
250 #define LCD_DEFAULT_BG LCD_WHITE
252 #endif /* HAVE_LCD_COLOR */
254 /* Frame buffer dimensions */
255 #if LCD_DEPTH == 1
256 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
257 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
258 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
259 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
260 #endif /* LCD_PIXELFORMAT */
261 #elif LCD_DEPTH == 2
262 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
263 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
264 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
265 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
266 #endif /* LCD_PIXELFORMAT */
267 #endif /* LCD_DEPTH */
268 /* Set defaults if not defined different yet. The defaults apply to both
269 * dimensions for LCD_DEPTH >= 8 */
270 #ifndef LCD_FBWIDTH
271 #define LCD_FBWIDTH LCD_WIDTH
272 #endif
273 #ifndef LCD_FBHEIGHT
274 #define LCD_FBHEIGHT LCD_HEIGHT
275 #endif
276 /* The actual framebuffer */
277 extern fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH];
279 /** Port-specific functions. Enable in port config file. **/
280 #ifdef HAVE_LCD_ENABLE
281 /* Enable/disable the main display. */
282 extern void lcd_enable(bool on);
283 extern bool lcd_enabled(void);
284 #endif /* HAVE_LCD_ENABLE */
286 #ifdef HAVE_LCD_SLEEP
287 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
288 extern void lcd_sleep(void);
289 #endif /* HAVE_LCD_SLEEP */
291 #ifdef HAVE_LCD_SHUTDOWN
292 void lcd_shutdown(void);
293 #endif
295 /* Bitmap formats */
296 enum
298 FORMAT_MONO,
299 FORMAT_NATIVE,
300 FORMAT_ANY /* For passing to read_bmp_file() */
303 #define FORMAT_TRANSPARENT 0x40000000
304 #define FORMAT_DITHER 0x20000000
305 #define FORMAT_REMOTE 0x10000000
307 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
308 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
310 struct bitmap {
311 int width;
312 int height;
313 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
314 int format;
315 unsigned char *maskdata;
316 #endif
317 unsigned char *data;
320 extern void lcd_set_invert_display(bool yesno);
321 #ifdef HAVE_BACKLIGHT_INVERSION
322 extern void lcd_set_backlight_inversion(bool yesno);
323 #endif /* HAVE_BACKLIGHT_INVERSION */
324 extern void lcd_set_flip(bool yesno);
326 extern void lcd_set_drawmode(int mode);
327 extern int lcd_get_drawmode(void);
328 extern void lcd_setfont(int font);
330 extern void lcd_puts_style_offset(int x, int y, const unsigned char *str,
331 int style, int offset);
332 extern void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
333 int style, int offset);
335 /* low level drawing function pointer arrays */
336 #if LCD_DEPTH >= 8
337 extern lcd_fastpixelfunc_type* const *lcd_fastpixelfuncs;
338 #elif LCD_DEPTH > 1
339 extern lcd_pixelfunc_type* const *lcd_pixelfuncs;
340 extern lcd_blockfunc_type* const *lcd_blockfuncs;
341 #else /* LCD_DEPTH == 1*/
342 extern lcd_pixelfunc_type* const lcd_pixelfuncs[8];
343 extern lcd_blockfunc_type* const lcd_blockfuncs[8];
344 #endif /* LCD_DEPTH */
346 extern void lcd_drawpixel(int x, int y);
347 extern void lcd_drawline(int x1, int y1, int x2, int y2);
348 extern void lcd_hline(int x1, int x2, int y);
349 extern void lcd_vline(int x, int y1, int y2);
350 extern void lcd_drawrect(int x, int y, int width, int height);
351 extern void lcd_fillrect(int x, int y, int width, int height);
352 extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
353 int stride, int x, int y, int width, int height);
354 extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
355 int height);
357 extern void lcd_invertscroll(int x, int y);
358 extern void lcd_scroll_step(int pixels);
360 #if LCD_DEPTH > 1
361 extern void lcd_set_foreground(unsigned foreground);
362 extern unsigned lcd_get_foreground(void);
363 extern void lcd_set_background(unsigned background);
364 extern unsigned lcd_get_background(void);
365 #ifdef HAVE_LCD_COLOR
366 extern void lcd_set_selector_start(unsigned selector);
367 extern void lcd_set_selector_end(unsigned selector);
368 extern void lcd_set_selector_text(unsigned selector_text);
369 #endif
370 extern void lcd_set_drawinfo(int mode, unsigned foreground,
371 unsigned background);
372 void lcd_set_backdrop(fb_data* backdrop);
374 fb_data* lcd_get_backdrop(void);
376 extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
377 int stride, int x, int y, int width, int height);
378 extern void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width,
379 int height);
380 extern void lcd_bitmap_transparent_part(const fb_data *src,
381 int src_x, int src_y,
382 int stride, int x, int y, int width,
383 int height);
384 extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
385 int width, int height);
386 #else /* LCD_DEPTH == 1 */
387 #define lcd_mono_bitmap lcd_bitmap
388 #define lcd_mono_bitmap_part lcd_bitmap_part
389 #endif /* LCD_DEPTH */
391 #endif /* HAVE_LCD_BITMAP */
393 #endif /* __LCD_H__ */