Remove the calls to backlight_lcd_sleep_countdown from target specific code and move...
[kugel-rb.git] / firmware / export / lcd.h
blobe52356b8bf9ef39310899383d25f8c6c91480638
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 #define FB_DATA_SZ 2
79 #else
80 typedef unsigned char fb_data;
81 #define FB_DATA_SZ 1
82 #endif
83 #elif LCD_DEPTH <= 16
84 typedef unsigned short fb_data;
85 #define FB_DATA_SZ 2
86 #else /* LCD_DEPTH > 16 */
87 typedef unsigned long fb_data;
88 #define FB_DATA_SZ 4
89 #endif /* LCD_DEPTH */
91 #else /* LCD_CHARCELLS */
92 typedef unsigned char fb_data;
93 #endif
95 #if defined(HAVE_LCD_MODES)
96 void lcd_set_mode(int mode);
97 #define LCD_MODE_RGB565 0x00000001
98 #define LCD_MODE_YUV 0x00000002
99 #define LCD_MODE_PAL256 0x00000004
101 #if HAVE_LCD_MODES & LCD_MODE_PAL256
102 void lcd_blit_pal256(unsigned char *src, int src_x, int src_y, int x, int y,
103 int width, int height);
104 void lcd_pal256_update_pal(fb_data *palette);
105 #endif
106 #endif
109 /* common functions */
110 extern void lcd_write_command(int byte);
111 extern void lcd_write_command_e(int cmd, int data);
112 extern void lcd_write_command_ex(int cmd, int data1, int data2);
113 extern void lcd_write_data(const fb_data* p_bytes, int count);
114 extern void lcd_init(void);
116 #ifdef SIMULATOR
117 /* Define a dummy device specific init for the sims */
118 #define lcd_init_device()
119 #else
120 extern void lcd_init_device(void);
121 #endif /* SIMULATOR */
123 extern void lcd_backlight(bool on);
124 extern int lcd_default_contrast(void);
125 extern void lcd_set_contrast(int val);
126 extern int lcd_getwidth(void);
127 extern int lcd_getheight(void);
128 extern int lcd_getstringsize(const unsigned char *str, int *w, int *h);
130 extern void lcd_set_viewport(struct viewport* vp);
131 extern void lcd_update(void);
132 extern void lcd_update_viewport(void);
133 extern void lcd_clear_viewport(void);
134 extern void lcd_clear_display(void);
135 extern void lcd_putsxy(int x, int y, const unsigned char *string);
136 extern void lcd_puts(int x, int y, const unsigned char *string);
137 extern void lcd_puts_style(int x, int y, const unsigned char *string, int style);
138 extern void lcd_puts_offset(int x, int y, const unsigned char *str, int offset);
139 extern void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
140 int offset);
141 extern void lcd_putc(int x, int y, unsigned long ucs);
142 extern void lcd_stop_scroll(void);
143 extern void lcd_bidir_scroll(int threshold);
144 extern void lcd_scroll_speed(int speed);
145 extern void lcd_scroll_delay(int ms);
146 extern void lcd_puts_scroll(int x, int y, const unsigned char* string);
147 extern void lcd_puts_scroll_style(int x, int y, const unsigned char* string,
148 int style);
150 #ifdef HAVE_LCD_BITMAP
152 /* performance function */
153 #if defined(HAVE_LCD_COLOR)
154 #define LCD_YUV_DITHER 0x1
155 extern void lcd_yuv_set_options(unsigned options);
156 extern void lcd_blit_yuv(unsigned char * const src[3],
157 int src_x, int src_y, int stride,
158 int x, int y, int width, int height);
159 #else
160 extern void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
161 int bheight, int stride);
162 extern void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
163 int bx, int by, int bwidth, int bheight,
164 int stride);
165 #endif
168 /* update a fraction of the screen */
169 extern void lcd_update_rect(int x, int y, int width, int height);
170 extern void lcd_update_viewport_rect(int x, int y, int width, int height);
172 #ifdef HAVE_REMOTE_LCD
173 extern void lcd_remote_update(void);
174 /* update a fraction of the screen */
175 extern void lcd_remote_update_rect(int x, int y, int width, int height);
176 #endif /* HAVE_REMOTE_LCD */
177 #endif /* HAVE_LCD_BITMAP */
179 #ifdef HAVE_LCD_CHARCELLS
181 /* Icon definitions for lcd_icon() */
182 enum
184 ICON_BATTERY = 0,
185 ICON_BATTERY_1,
186 ICON_BATTERY_2,
187 ICON_BATTERY_3,
188 ICON_USB,
189 ICON_PLAY,
190 ICON_RECORD,
191 ICON_PAUSE,
192 ICON_AUDIO,
193 ICON_REPEAT,
194 ICON_1,
195 ICON_VOLUME,
196 ICON_VOLUME_1,
197 ICON_VOLUME_2,
198 ICON_VOLUME_3,
199 ICON_VOLUME_4,
200 ICON_VOLUME_5,
201 ICON_PARAM
204 void lcd_icon(int icon, bool enable);
205 void lcd_double_height(bool on);
206 void lcd_define_pattern(unsigned long ucs, const char *pattern);
207 unsigned long lcd_get_locked_pattern(void);
208 void lcd_unlock_pattern(unsigned long ucs);
209 void lcd_put_cursor(int x, int y, unsigned long cursor_ucs);
210 void lcd_remove_cursor(void);
211 #define JUMP_SCROLL_ALWAYS 5
212 extern void lcd_jump_scroll(int mode); /* 0=off, 1=once, ..., ALWAYS */
213 extern void lcd_jump_scroll_delay(int ms);
214 #endif /* HAVE_LCD_CHARCELLS */
216 /* Draw modes */
217 #define DRMODE_COMPLEMENT 0
218 #define DRMODE_BG 1
219 #define DRMODE_FG 2
220 #define DRMODE_SOLID 3
221 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
223 /* Low-level drawing function types */
224 typedef void lcd_pixelfunc_type(int x, int y);
225 typedef void lcd_blockfunc_type(fb_data *address, unsigned mask, unsigned bits);
226 #if LCD_DEPTH >= 8
227 typedef void lcd_fastpixelfunc_type(fb_data *address);
228 #endif
230 #ifdef HAVE_LCD_BITMAP
232 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
233 LCD_REMOTE_DEPTH > 1
234 /* Just return color for screens use */
235 static inline unsigned lcd_color_to_native(unsigned color)
236 { return color; }
237 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
238 #else
239 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
240 #endif
242 #ifdef HAVE_LCD_COLOR
243 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
244 #define LCD_MAX_RED 31
245 #define LCD_MAX_GREEN 63
246 #define LCD_MAX_BLUE 31
247 #define LCD_RED_BITS 5
248 #define LCD_GREEN_BITS 6
249 #define LCD_BLUE_BITS 5
251 /* pack/unpack native RGB values */
252 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
253 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
254 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
255 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
257 /* pack/unpack 24-bit RGB values */
258 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
259 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 13) & 0x07) )
260 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03) )
261 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) >> 2) & 0x07) )
263 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
264 /* RGB3553 */
265 #define _LCD_UNSWAP_COLOR(x) swap16(x)
266 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
267 (((g) >> 3) ) | \
268 (((g) & 0x07) << 13) | \
269 (((b) << 8) ) )
270 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
271 (((g) >> 5) ) | \
272 (((g) & 0x1c) << 11) | \
273 (((b) >> 3) << 8) )
274 /* swap color once - not currenly used in static inits */
275 #define _SWAPUNPACK(x, _unp_) \
276 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
277 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
278 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
279 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
280 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
281 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
282 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
283 #else /* LCD_PIXELFORMAT == RGB565 */
284 /* RGB565 */
285 #define _LCD_UNSWAP_COLOR(x) (x)
286 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
287 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
288 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
289 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
290 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
291 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
292 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
293 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
294 #endif /* RGB565* */
295 #else
296 /* other colour depths */
297 #endif
299 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
300 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
301 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
302 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
303 #define LCD_DEFAULT_FG LCD_WHITE
304 #define LCD_DEFAULT_BG LCD_BLACK
305 #define LCD_DEFAULT_LS LCD_WHITE
307 #elif LCD_DEPTH > 1 /* greyscale */
309 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
310 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
312 #define LCD_BLACK LCD_BRIGHTNESS(0)
313 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
314 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
315 #define LCD_WHITE LCD_BRIGHTNESS(255)
316 #define LCD_DEFAULT_FG LCD_BLACK
317 #define LCD_DEFAULT_BG LCD_WHITE
319 #endif /* HAVE_LCD_COLOR */
321 /* Frame buffer dimensions */
322 #if LCD_DEPTH == 1
323 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
324 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
325 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
326 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
327 #endif /* LCD_PIXELFORMAT */
328 #elif LCD_DEPTH == 2
329 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
330 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
331 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
332 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
333 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
334 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
335 #endif /* LCD_PIXELFORMAT */
336 #endif /* LCD_DEPTH */
337 /* Set defaults if not defined different yet. The defaults apply to both
338 * dimensions for LCD_DEPTH >= 8 */
339 #ifndef LCD_FBWIDTH
340 #define LCD_FBWIDTH LCD_WIDTH
341 #endif
342 #ifndef LCD_FBHEIGHT
343 #define LCD_FBHEIGHT LCD_HEIGHT
344 #endif
345 /* The actual framebuffer */
346 extern fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH];
348 /** Port-specific functions. Enable in port config file. **/
349 #ifdef HAVE_REMOTE_LCD_AS_MAIN
350 void lcd_on(void);
351 void lcd_off(void);
352 void lcd_poweroff(void);
353 #endif
355 #ifdef HAVE_LCD_ENABLE
356 /* Enable/disable the main display. */
357 extern void lcd_enable(bool on);
358 #endif /* HAVE_LCD_ENABLE */
360 #ifdef HAVE_LCD_SLEEP
361 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
362 extern void lcd_sleep(void);
363 #endif /* HAVE_LCD_SLEEP */
364 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
365 /* Register a hook that is called when the lcd is powered and after the
366 * framebuffer data is synchronized */
367 /* Sansa Clip has these function in it's lcd driver, since it's the only
368 * 1-bit display featuring lcd_active, so far */
369 extern bool lcd_active(void);
370 extern void lcd_activation_set_hook(void (*enable_hook)(void));
371 extern void lcd_activation_call_hook(void);
372 #endif
374 #ifdef HAVE_LCD_SHUTDOWN
375 void lcd_shutdown(void);
376 #endif
378 /* Bitmap formats */
379 enum
381 FORMAT_MONO,
382 FORMAT_NATIVE,
383 FORMAT_ANY /* For passing to read_bmp_file() */
386 #define FORMAT_TRANSPARENT 0x40000000
387 #define FORMAT_DITHER 0x20000000
388 #define FORMAT_REMOTE 0x10000000
389 #define FORMAT_RESIZE 0x08000000
390 #define FORMAT_KEEP_ASPECT 0x04000000
392 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
393 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
395 struct bitmap {
396 int width;
397 int height;
398 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
399 int format;
400 unsigned char *maskdata;
401 #endif
402 unsigned char *data;
405 extern void lcd_set_invert_display(bool yesno);
406 #ifdef HAVE_BACKLIGHT_INVERSION
407 extern void lcd_set_backlight_inversion(bool yesno);
408 #endif /* HAVE_BACKLIGHT_INVERSION */
409 extern void lcd_set_flip(bool yesno);
411 extern void lcd_set_drawmode(int mode);
412 extern int lcd_get_drawmode(void);
413 extern void lcd_setfont(int font);
414 extern int lcd_getfont(void);
416 extern void lcd_puts_style_offset(int x, int y, const unsigned char *str,
417 int style, int offset);
418 extern void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
419 int style, int offset);
421 /* low level drawing function pointer arrays */
422 #if LCD_DEPTH >= 8
423 extern lcd_fastpixelfunc_type* const *lcd_fastpixelfuncs;
424 #elif LCD_DEPTH > 1
425 extern lcd_pixelfunc_type* const *lcd_pixelfuncs;
426 extern lcd_blockfunc_type* const *lcd_blockfuncs;
427 #else /* LCD_DEPTH == 1*/
428 extern lcd_pixelfunc_type* const lcd_pixelfuncs[8];
429 extern lcd_blockfunc_type* const lcd_blockfuncs[8];
430 #endif /* LCD_DEPTH */
432 extern void lcd_drawpixel(int x, int y);
433 extern void lcd_drawline(int x1, int y1, int x2, int y2);
434 extern void lcd_hline(int x1, int x2, int y);
435 extern void lcd_vline(int x, int y1, int y2);
436 extern void lcd_drawrect(int x, int y, int width, int height);
437 extern void lcd_fillrect(int x, int y, int width, int height);
438 extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
439 int stride, int x, int y, int width, int height);
440 extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
441 int height);
443 extern void lcd_scroll_step(int pixels);
445 #if LCD_DEPTH > 1
446 extern void lcd_set_foreground(unsigned foreground);
447 extern unsigned lcd_get_foreground(void);
448 extern void lcd_set_background(unsigned background);
449 extern unsigned lcd_get_background(void);
450 #ifdef HAVE_LCD_COLOR
451 extern void lcd_set_selector_start(unsigned selector);
452 extern void lcd_set_selector_end(unsigned selector);
453 extern void lcd_set_selector_text(unsigned selector_text);
454 #endif
455 extern void lcd_set_drawinfo(int mode, unsigned foreground,
456 unsigned background);
457 void lcd_set_backdrop(fb_data* backdrop);
459 fb_data* lcd_get_backdrop(void);
461 extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
462 int stride, int x, int y, int width, int height);
463 extern void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width,
464 int height);
465 extern void lcd_bitmap_transparent_part(const fb_data *src,
466 int src_x, int src_y,
467 int stride, int x, int y, int width,
468 int height);
469 extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
470 int width, int height);
471 #else /* LCD_DEPTH == 1 */
472 #define lcd_mono_bitmap lcd_bitmap
473 #define lcd_mono_bitmap_part lcd_bitmap_part
474 #endif /* LCD_DEPTH */
476 #endif /* HAVE_LCD_BITMAP */
478 #endif /* __LCD_H__ */