merge 19488 back from the 3.1 branch
[kugel-rb.git] / firmware / export / lcd.h
blobea5851e7360d799995f55eb529ac0ca7804df535
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);
342 #ifdef HAVE_LCD_COLOR
343 /* Register a hook that is called when the lcd is powered and after the
344 * framebuffer data is synchronized */
345 void lcd_set_enable_hook(void (*enable_hook)(void));
346 #endif /* HAVE_LCD_COLOR */
348 #endif /* HAVE_LCD_ENABLE */
349 void lcd_call_enable_hook(void);
351 #ifdef HAVE_LCD_SLEEP
352 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
353 extern void lcd_sleep(void);
354 #endif /* HAVE_LCD_SLEEP */
356 #ifdef HAVE_LCD_SHUTDOWN
357 void lcd_shutdown(void);
358 #endif
360 /* Bitmap formats */
361 enum
363 FORMAT_MONO,
364 FORMAT_NATIVE,
365 FORMAT_ANY /* For passing to read_bmp_file() */
368 #define FORMAT_TRANSPARENT 0x40000000
369 #define FORMAT_DITHER 0x20000000
370 #define FORMAT_REMOTE 0x10000000
371 #define FORMAT_RESIZE 0x08000000
372 #define FORMAT_KEEP_ASPECT 0x04000000
374 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
375 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
377 struct bitmap {
378 int width;
379 int height;
380 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
381 int format;
382 unsigned char *maskdata;
383 #endif
384 unsigned char *data;
387 extern void lcd_set_invert_display(bool yesno);
388 #ifdef HAVE_BACKLIGHT_INVERSION
389 extern void lcd_set_backlight_inversion(bool yesno);
390 #endif /* HAVE_BACKLIGHT_INVERSION */
391 extern void lcd_set_flip(bool yesno);
393 extern void lcd_set_drawmode(int mode);
394 extern int lcd_get_drawmode(void);
395 extern void lcd_setfont(int font);
396 extern int lcd_getfont(void);
398 extern void lcd_puts_style_offset(int x, int y, const unsigned char *str,
399 int style, int offset);
400 extern void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
401 int style, int offset);
403 /* low level drawing function pointer arrays */
404 #if LCD_DEPTH >= 8
405 extern lcd_fastpixelfunc_type* const *lcd_fastpixelfuncs;
406 #elif LCD_DEPTH > 1
407 extern lcd_pixelfunc_type* const *lcd_pixelfuncs;
408 extern lcd_blockfunc_type* const *lcd_blockfuncs;
409 #else /* LCD_DEPTH == 1*/
410 extern lcd_pixelfunc_type* const lcd_pixelfuncs[8];
411 extern lcd_blockfunc_type* const lcd_blockfuncs[8];
412 #endif /* LCD_DEPTH */
414 extern void lcd_drawpixel(int x, int y);
415 extern void lcd_drawline(int x1, int y1, int x2, int y2);
416 extern void lcd_hline(int x1, int x2, int y);
417 extern void lcd_vline(int x, int y1, int y2);
418 extern void lcd_drawrect(int x, int y, int width, int height);
419 extern void lcd_fillrect(int x, int y, int width, int height);
420 extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
421 int stride, int x, int y, int width, int height);
422 extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
423 int height);
425 extern void lcd_scroll_step(int pixels);
427 #if LCD_DEPTH > 1
428 extern void lcd_set_foreground(unsigned foreground);
429 extern unsigned lcd_get_foreground(void);
430 extern void lcd_set_background(unsigned background);
431 extern unsigned lcd_get_background(void);
432 #ifdef HAVE_LCD_COLOR
433 extern void lcd_set_selector_start(unsigned selector);
434 extern void lcd_set_selector_end(unsigned selector);
435 extern void lcd_set_selector_text(unsigned selector_text);
436 #endif
437 extern void lcd_set_drawinfo(int mode, unsigned foreground,
438 unsigned background);
439 void lcd_set_backdrop(fb_data* backdrop);
441 fb_data* lcd_get_backdrop(void);
443 extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
444 int stride, int x, int y, int width, int height);
445 extern void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width,
446 int height);
447 extern void lcd_bitmap_transparent_part(const fb_data *src,
448 int src_x, int src_y,
449 int stride, int x, int y, int width,
450 int height);
451 extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
452 int width, int height);
453 #else /* LCD_DEPTH == 1 */
454 #define lcd_mono_bitmap lcd_bitmap
455 #define lcd_mono_bitmap_part lcd_bitmap_part
456 #endif /* LCD_DEPTH */
458 #endif /* HAVE_LCD_BITMAP */
460 #endif /* __LCD_H__ */