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