Updated our source code header to explicitly mention that we are GPL v2 or
[Rockbox.git] / firmware / export / lcd.h
blob0aec5d0cbf6fcba9fb8ee1d5fbcedc7ecb459eb7
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Alan Korr
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 ****************************************************************************/
22 #ifndef __LCD_H__
23 #define __LCD_H__
25 #include <stdbool.h>
26 #include "cpu.h"
27 #include "config.h"
29 struct viewport {
30 int x;
31 int y;
32 int width;
33 int height;
34 #ifdef HAVE_LCD_BITMAP
35 int font;
36 int drawmode;
37 #endif
38 #if LCD_DEPTH > 1
39 unsigned fg_pattern;
40 unsigned bg_pattern;
41 #ifdef HAVE_LCD_COLOR
42 unsigned lss_pattern;
43 unsigned lse_pattern;
44 unsigned lst_pattern;
45 #endif
46 #endif
49 #define STYLE_DEFAULT 0x00000000
50 #define STYLE_COLORED 0x10000000
51 #define STYLE_INVERT 0x20000000
52 #define STYLE_COLORBAR 0x40000000
53 #define STYLE_GRADIENT 0x80000000
54 #define STYLE_MODE_MASK 0xF0000000
55 #define STYLE_COLOR_MASK 0x0000FFFF
56 #ifdef HAVE_LCD_COLOR
57 #define STYLE_CURLN_MASK 0x0000FF00
58 #define STYLE_MAXLN_MASK 0x000000FF
59 #define CURLN_PACK(x) (((x)<<8) & STYLE_CURLN_MASK)
60 #define CURLN_UNPACK(x) ((unsigned char)(((x)&STYLE_CURLN_MASK) >> 8))
61 #define NUMLN_PACK(x) ((x) & STYLE_MAXLN_MASK)
62 #define NUMLN_UNPACK(x) ((unsigned char)((x) & STYLE_MAXLN_MASK))
63 #endif
65 #ifdef SIMULATOR
66 #ifndef MAX_PATH
67 #define MAX_PATH 260
68 #endif
69 #else
70 #include "file.h" /* for MAX_PATH; FIXME: Why does this not work for sims? */
71 #endif /* SIMULATOR */
73 #ifdef HAVE_LCD_BITMAP
74 #if LCD_DEPTH <=8
75 #if (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED) \
76 || (LCD_PIXELFORMAT == HORIZONTAL_INTERLEAVED)
77 typedef unsigned short fb_data;
78 #else
79 typedef unsigned char fb_data;
80 #endif
81 #elif LCD_DEPTH <= 16
82 typedef unsigned short fb_data;
83 #else /* LCD_DEPTH > 16 */
84 typedef unsigned long fb_data;
85 #endif /* LCD_DEPTH */
87 #else /* LCD_CHARCELLS */
88 typedef unsigned char fb_data;
89 #endif
91 /* common functions */
92 extern void lcd_write_command(int byte);
93 extern void lcd_write_command_e(int cmd, int data);
94 extern void lcd_write_command_ex(int cmd, int data1, int data2);
95 extern void lcd_write_data(const fb_data* p_bytes, int count);
96 extern void lcd_init(void);
98 #ifdef SIMULATOR
99 /* Define a dummy device specific init for the sims */
100 #define lcd_init_device()
101 #else
102 extern void lcd_init_device(void);
103 #endif /* SIMULATOR */
105 extern void lcd_backlight(bool on);
106 extern int lcd_default_contrast(void);
107 extern void lcd_set_contrast(int val);
108 extern int lcd_getwidth(void);
109 extern int lcd_getheight(void);
110 extern int lcd_getstringsize(const unsigned char *str, int *w, int *h);
112 extern void lcd_set_viewport(struct viewport* vp);
113 extern void lcd_update(void);
114 extern void lcd_update_viewport(void);
115 extern void lcd_clear_viewport(void);
116 extern void lcd_clear_display(void);
117 extern void lcd_putsxy(int x, int y, const unsigned char *string);
118 extern void lcd_puts(int x, int y, const unsigned char *string);
119 extern void lcd_puts_style(int x, int y, const unsigned char *string, int style);
120 extern void lcd_puts_offset(int x, int y, const unsigned char *str, int offset);
121 extern void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
122 int offset);
123 extern void lcd_putc(int x, int y, unsigned long ucs);
124 extern void lcd_stop_scroll(void);
125 extern void lcd_bidir_scroll(int threshold);
126 extern void lcd_scroll_speed(int speed);
127 extern void lcd_scroll_delay(int ms);
128 extern void lcd_puts_scroll(int x, int y, const unsigned char* string);
129 extern void lcd_puts_scroll_style(int x, int y, const unsigned char* string,
130 int style);
132 #ifdef HAVE_LCD_BITMAP
134 /* performance function */
135 #if defined(HAVE_LCD_COLOR)
136 #define LCD_YUV_DITHER 0x1
137 extern void lcd_yuv_set_options(unsigned options);
138 extern void lcd_blit_yuv(unsigned char * const src[3],
139 int src_x, int src_y, int stride,
140 int x, int y, int width, int height);
141 #else
142 extern void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
143 int bheight, int stride);
144 extern void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
145 int bx, int by, int bwidth, int bheight,
146 int stride);
147 #endif
150 /* update a fraction of the screen */
151 extern void lcd_update_rect(int x, int y, int width, int height);
152 extern void lcd_update_viewport_rect(int x, int y, int width, int height);
154 #ifdef HAVE_REMOTE_LCD
155 extern void lcd_remote_update(void);
156 /* update a fraction of the screen */
157 extern void lcd_remote_update_rect(int x, int y, int width, int height);
158 #endif /* HAVE_REMOTE_LCD */
159 #endif /* HAVE_LCD_BITMAP */
161 #ifdef HAVE_LCD_CHARCELLS
163 /* Icon definitions for lcd_icon() */
164 enum
166 ICON_BATTERY = 0,
167 ICON_BATTERY_1,
168 ICON_BATTERY_2,
169 ICON_BATTERY_3,
170 ICON_USB,
171 ICON_PLAY,
172 ICON_RECORD,
173 ICON_PAUSE,
174 ICON_AUDIO,
175 ICON_REPEAT,
176 ICON_1,
177 ICON_VOLUME,
178 ICON_VOLUME_1,
179 ICON_VOLUME_2,
180 ICON_VOLUME_3,
181 ICON_VOLUME_4,
182 ICON_VOLUME_5,
183 ICON_PARAM
186 void lcd_icon(int icon, bool enable);
187 void lcd_double_height(bool on);
188 void lcd_define_pattern(unsigned long ucs, const char *pattern);
189 unsigned long lcd_get_locked_pattern(void);
190 void lcd_unlock_pattern(unsigned long ucs);
191 void lcd_put_cursor(int x, int y, unsigned long cursor_ucs);
192 void lcd_remove_cursor(void);
193 #define JUMP_SCROLL_ALWAYS 5
194 extern void lcd_jump_scroll(int mode); /* 0=off, 1=once, ..., ALWAYS */
195 extern void lcd_jump_scroll_delay(int ms);
196 #endif /* HAVE_LCD_CHARCELLS */
198 /* Draw modes */
199 #define DRMODE_COMPLEMENT 0
200 #define DRMODE_BG 1
201 #define DRMODE_FG 2
202 #define DRMODE_SOLID 3
203 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
205 /* Low-level drawing function types */
206 typedef void lcd_pixelfunc_type(int x, int y);
207 typedef void lcd_blockfunc_type(fb_data *address, unsigned mask, unsigned bits);
208 #if LCD_DEPTH >= 8
209 typedef void lcd_fastpixelfunc_type(fb_data *address);
210 #endif
212 #ifdef HAVE_LCD_BITMAP
214 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
215 LCD_REMOTE_DEPTH > 1
216 /* Just return color for screens use */
217 static inline unsigned lcd_color_to_native(unsigned color)
218 { return color; }
219 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
220 #else
221 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
222 #endif
224 #ifdef HAVE_LCD_COLOR
225 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
226 #define LCD_MAX_RED 31
227 #define LCD_MAX_GREEN 63
228 #define LCD_MAX_BLUE 31
229 #define LCD_RED_BITS 5
230 #define LCD_GREEN_BITS 6
231 #define LCD_BLUE_BITS 5
233 /* pack/unpack native RGB values */
234 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
235 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
236 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
237 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
239 /* pack/unpack 24-bit RGB values */
240 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
241 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 13) & 0x07) )
242 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03) )
243 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) >> 2) & 0x07) )
245 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
246 /* RGB3553 */
247 #define _LCD_UNSWAP_COLOR(x) swap16(x)
248 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
249 (((g) >> 3) ) | \
250 (((g) & 0x07) << 13) | \
251 (((b) << 8) ) )
252 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
253 (((g) >> 5) ) | \
254 (((g) & 0x1c) << 11) | \
255 (((b) >> 3) << 8) )
256 /* swap color once - not currenly used in static inits */
257 #define _SWAPUNPACK(x, _unp_) \
258 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
259 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
260 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
261 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
262 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
263 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
264 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
265 #else /* LCD_PIXELFORMAT == RGB565 */
266 /* RGB565 */
267 #define _LCD_UNSWAP_COLOR(x) (x)
268 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
269 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
270 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
271 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
272 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
273 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
274 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
275 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
276 #endif /* RGB565* */
277 #else
278 /* other colour depths */
279 #endif
281 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
282 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
283 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
284 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
285 #define LCD_DEFAULT_FG LCD_WHITE
286 #define LCD_DEFAULT_BG LCD_BLACK
287 #define LCD_DEFAULT_LS LCD_WHITE
289 #elif LCD_DEPTH > 1 /* greyscale */
291 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
292 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
294 #define LCD_BLACK LCD_BRIGHTNESS(0)
295 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
296 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
297 #define LCD_WHITE LCD_BRIGHTNESS(255)
298 #define LCD_DEFAULT_FG LCD_BLACK
299 #define LCD_DEFAULT_BG LCD_WHITE
301 #endif /* HAVE_LCD_COLOR */
303 /* Frame buffer dimensions */
304 #if LCD_DEPTH == 1
305 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
306 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
307 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
308 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
309 #endif /* LCD_PIXELFORMAT */
310 #elif LCD_DEPTH == 2
311 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
312 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
313 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
314 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
315 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
316 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
317 #endif /* LCD_PIXELFORMAT */
318 #endif /* LCD_DEPTH */
319 /* Set defaults if not defined different yet. The defaults apply to both
320 * dimensions for LCD_DEPTH >= 8 */
321 #ifndef LCD_FBWIDTH
322 #define LCD_FBWIDTH LCD_WIDTH
323 #endif
324 #ifndef LCD_FBHEIGHT
325 #define LCD_FBHEIGHT LCD_HEIGHT
326 #endif
327 /* The actual framebuffer */
328 extern fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH];
330 /** Port-specific functions. Enable in port config file. **/
331 #ifdef HAVE_REMOTE_LCD_AS_MAIN
332 void lcd_on(void);
333 void lcd_off(void);
334 void lcd_poweroff(void);
335 #endif
337 #ifdef HAVE_LCD_ENABLE
338 /* Enable/disable the main display. */
339 extern void lcd_enable(bool on);
340 extern bool lcd_enabled(void);
341 /* Register a hook that is called when the lcd is powered and after the
342 * framebuffer data is synchronized */
343 void lcd_set_enable_hook(void (*enable_hook)(void));
344 #endif /* HAVE_LCD_ENABLE */
345 void lcd_call_enable_hook(void);
347 #ifdef HAVE_LCD_SLEEP
348 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
349 extern void lcd_sleep(void);
350 #endif /* HAVE_LCD_SLEEP */
352 #ifdef HAVE_LCD_SHUTDOWN
353 void lcd_shutdown(void);
354 #endif
356 /* Bitmap formats */
357 enum
359 FORMAT_MONO,
360 FORMAT_NATIVE,
361 FORMAT_ANY /* For passing to read_bmp_file() */
364 #define FORMAT_TRANSPARENT 0x40000000
365 #define FORMAT_DITHER 0x20000000
366 #define FORMAT_REMOTE 0x10000000
368 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
369 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
371 struct bitmap {
372 int width;
373 int height;
374 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
375 int format;
376 unsigned char *maskdata;
377 #endif
378 unsigned char *data;
381 extern void lcd_set_invert_display(bool yesno);
382 #ifdef HAVE_BACKLIGHT_INVERSION
383 extern void lcd_set_backlight_inversion(bool yesno);
384 #endif /* HAVE_BACKLIGHT_INVERSION */
385 extern void lcd_set_flip(bool yesno);
387 extern void lcd_set_drawmode(int mode);
388 extern int lcd_get_drawmode(void);
389 extern void lcd_setfont(int font);
390 extern int lcd_getfont(void);
392 extern void lcd_puts_style_offset(int x, int y, const unsigned char *str,
393 int style, int offset);
394 extern void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
395 int style, int offset);
397 /* low level drawing function pointer arrays */
398 #if LCD_DEPTH >= 8
399 extern lcd_fastpixelfunc_type* const *lcd_fastpixelfuncs;
400 #elif LCD_DEPTH > 1
401 extern lcd_pixelfunc_type* const *lcd_pixelfuncs;
402 extern lcd_blockfunc_type* const *lcd_blockfuncs;
403 #else /* LCD_DEPTH == 1*/
404 extern lcd_pixelfunc_type* const lcd_pixelfuncs[8];
405 extern lcd_blockfunc_type* const lcd_blockfuncs[8];
406 #endif /* LCD_DEPTH */
408 extern void lcd_drawpixel(int x, int y);
409 extern void lcd_drawline(int x1, int y1, int x2, int y2);
410 extern void lcd_hline(int x1, int x2, int y);
411 extern void lcd_vline(int x, int y1, int y2);
412 extern void lcd_drawrect(int x, int y, int width, int height);
413 extern void lcd_fillrect(int x, int y, int width, int height);
414 extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
415 int stride, int x, int y, int width, int height);
416 extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
417 int height);
419 extern void lcd_scroll_step(int pixels);
421 #if LCD_DEPTH > 1
422 extern void lcd_set_foreground(unsigned foreground);
423 extern unsigned lcd_get_foreground(void);
424 extern void lcd_set_background(unsigned background);
425 extern unsigned lcd_get_background(void);
426 #ifdef HAVE_LCD_COLOR
427 extern void lcd_set_selector_start(unsigned selector);
428 extern void lcd_set_selector_end(unsigned selector);
429 extern void lcd_set_selector_text(unsigned selector_text);
430 #endif
431 extern void lcd_set_drawinfo(int mode, unsigned foreground,
432 unsigned background);
433 void lcd_set_backdrop(fb_data* backdrop);
435 fb_data* lcd_get_backdrop(void);
437 extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
438 int stride, int x, int y, int width, int height);
439 extern void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width,
440 int height);
441 extern void lcd_bitmap_transparent_part(const fb_data *src,
442 int src_x, int src_y,
443 int stride, int x, int y, int width,
444 int height);
445 extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
446 int width, int height);
447 #else /* LCD_DEPTH == 1 */
448 #define lcd_mono_bitmap lcd_bitmap
449 #define lcd_mono_bitmap_part lcd_bitmap_part
450 #endif /* LCD_DEPTH */
452 #endif /* HAVE_LCD_BITMAP */
454 #endif /* __LCD_H__ */