Minor quickscreen and pitchscreen fixes
[kugel-rb.git] / firmware / export / lcd.h
blobe435d174f2a4e47c20e97b81d3262cf577b52fbb
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 /* common functions */
96 extern void lcd_write_command(int byte);
97 extern void lcd_write_command_e(int cmd, int data);
98 extern void lcd_write_command_ex(int cmd, int data1, int data2);
99 extern void lcd_write_data(const fb_data* p_bytes, int count);
100 extern void lcd_init(void);
102 #ifdef SIMULATOR
103 /* Define a dummy device specific init for the sims */
104 #define lcd_init_device()
105 #else
106 extern void lcd_init_device(void);
107 #endif /* SIMULATOR */
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 #define LCD_YUV_DITHER 0x1
141 extern void lcd_yuv_set_options(unsigned options);
142 extern void lcd_blit_yuv(unsigned char * const src[3],
143 int src_x, int src_y, int stride,
144 int x, int y, int width, int height);
145 #else
146 extern void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
147 int bheight, int stride);
148 extern void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
149 int bx, int by, int bwidth, int bheight,
150 int stride);
151 #endif
154 /* update a fraction of the screen */
155 extern void lcd_update_rect(int x, int y, int width, int height);
156 extern void lcd_update_viewport_rect(int x, int y, int width, int height);
158 #ifdef HAVE_REMOTE_LCD
159 extern void lcd_remote_update(void);
160 /* update a fraction of the screen */
161 extern void lcd_remote_update_rect(int x, int y, int width, int height);
162 #endif /* HAVE_REMOTE_LCD */
163 #endif /* HAVE_LCD_BITMAP */
165 #ifdef HAVE_LCD_CHARCELLS
167 /* Icon definitions for lcd_icon() */
168 enum
170 ICON_BATTERY = 0,
171 ICON_BATTERY_1,
172 ICON_BATTERY_2,
173 ICON_BATTERY_3,
174 ICON_USB,
175 ICON_PLAY,
176 ICON_RECORD,
177 ICON_PAUSE,
178 ICON_AUDIO,
179 ICON_REPEAT,
180 ICON_1,
181 ICON_VOLUME,
182 ICON_VOLUME_1,
183 ICON_VOLUME_2,
184 ICON_VOLUME_3,
185 ICON_VOLUME_4,
186 ICON_VOLUME_5,
187 ICON_PARAM
190 void lcd_icon(int icon, bool enable);
191 void lcd_double_height(bool on);
192 void lcd_define_pattern(unsigned long ucs, const char *pattern);
193 unsigned long lcd_get_locked_pattern(void);
194 void lcd_unlock_pattern(unsigned long ucs);
195 void lcd_put_cursor(int x, int y, unsigned long cursor_ucs);
196 void lcd_remove_cursor(void);
197 #define JUMP_SCROLL_ALWAYS 5
198 extern void lcd_jump_scroll(int mode); /* 0=off, 1=once, ..., ALWAYS */
199 extern void lcd_jump_scroll_delay(int ms);
200 #endif /* HAVE_LCD_CHARCELLS */
202 /* Draw modes */
203 #define DRMODE_COMPLEMENT 0
204 #define DRMODE_BG 1
205 #define DRMODE_FG 2
206 #define DRMODE_SOLID 3
207 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
209 /* Low-level drawing function types */
210 typedef void lcd_pixelfunc_type(int x, int y);
211 typedef void lcd_blockfunc_type(fb_data *address, unsigned mask, unsigned bits);
212 #if LCD_DEPTH >= 8
213 typedef void lcd_fastpixelfunc_type(fb_data *address);
214 #endif
216 #ifdef HAVE_LCD_BITMAP
218 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
219 LCD_REMOTE_DEPTH > 1
220 /* Just return color for screens use */
221 static inline unsigned lcd_color_to_native(unsigned color)
222 { return color; }
223 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
224 #else
225 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
226 #endif
228 #ifdef HAVE_LCD_COLOR
229 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
230 #define LCD_MAX_RED 31
231 #define LCD_MAX_GREEN 63
232 #define LCD_MAX_BLUE 31
233 #define LCD_RED_BITS 5
234 #define LCD_GREEN_BITS 6
235 #define LCD_BLUE_BITS 5
237 /* pack/unpack native RGB values */
238 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
239 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
240 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
241 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
243 /* pack/unpack 24-bit RGB values */
244 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
245 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 13) & 0x07) )
246 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03) )
247 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) >> 2) & 0x07) )
249 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
250 /* RGB3553 */
251 #define _LCD_UNSWAP_COLOR(x) swap16(x)
252 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
253 (((g) >> 3) ) | \
254 (((g) & 0x07) << 13) | \
255 (((b) << 8) ) )
256 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
257 (((g) >> 5) ) | \
258 (((g) & 0x1c) << 11) | \
259 (((b) >> 3) << 8) )
260 /* swap color once - not currenly used in static inits */
261 #define _SWAPUNPACK(x, _unp_) \
262 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
263 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
264 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
265 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
266 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
267 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
268 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
269 #else /* LCD_PIXELFORMAT == RGB565 */
270 /* RGB565 */
271 #define _LCD_UNSWAP_COLOR(x) (x)
272 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
273 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
274 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
275 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
276 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
277 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
278 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
279 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
280 #endif /* RGB565* */
281 #else
282 /* other colour depths */
283 #endif
285 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
286 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
287 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
288 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
289 #define LCD_DEFAULT_FG LCD_WHITE
290 #define LCD_DEFAULT_BG LCD_BLACK
291 #define LCD_DEFAULT_LS LCD_WHITE
293 #elif LCD_DEPTH > 1 /* greyscale */
295 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
296 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
298 #define LCD_BLACK LCD_BRIGHTNESS(0)
299 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
300 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
301 #define LCD_WHITE LCD_BRIGHTNESS(255)
302 #define LCD_DEFAULT_FG LCD_BLACK
303 #define LCD_DEFAULT_BG LCD_WHITE
305 #endif /* HAVE_LCD_COLOR */
307 /* Frame buffer dimensions */
308 #if LCD_DEPTH == 1
309 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
310 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
311 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
312 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
313 #endif /* LCD_PIXELFORMAT */
314 #elif LCD_DEPTH == 2
315 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
316 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
317 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
318 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
319 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
320 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
321 #endif /* LCD_PIXELFORMAT */
322 #endif /* LCD_DEPTH */
323 /* Set defaults if not defined different yet. The defaults apply to both
324 * dimensions for LCD_DEPTH >= 8 */
325 #ifndef LCD_FBWIDTH
326 #define LCD_FBWIDTH LCD_WIDTH
327 #endif
328 #ifndef LCD_FBHEIGHT
329 #define LCD_FBHEIGHT LCD_HEIGHT
330 #endif
331 /* The actual framebuffer */
332 extern fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH];
334 /** Port-specific functions. Enable in port config file. **/
335 #ifdef HAVE_REMOTE_LCD_AS_MAIN
336 void lcd_on(void);
337 void lcd_off(void);
338 void lcd_poweroff(void);
339 #endif
341 #ifdef HAVE_LCD_ENABLE
342 /* Enable/disable the main display. */
343 extern void lcd_enable(bool on);
344 extern bool lcd_enabled(void);
346 #ifdef HAVE_LCD_COLOR
347 /* Register a hook that is called when the lcd is powered and after the
348 * framebuffer data is synchronized */
349 void lcd_set_enable_hook(void (*enable_hook)(void));
350 #endif /* HAVE_LCD_COLOR */
352 #endif /* HAVE_LCD_ENABLE */
353 void lcd_call_enable_hook(void);
355 #ifdef HAVE_LCD_SLEEP
356 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
357 extern void lcd_sleep(void);
358 #endif /* HAVE_LCD_SLEEP */
360 #ifdef HAVE_LCD_SHUTDOWN
361 void lcd_shutdown(void);
362 #endif
364 /* Bitmap formats */
365 enum
367 FORMAT_MONO,
368 FORMAT_NATIVE,
369 FORMAT_ANY /* For passing to read_bmp_file() */
372 #define FORMAT_TRANSPARENT 0x40000000
373 #define FORMAT_DITHER 0x20000000
374 #define FORMAT_REMOTE 0x10000000
375 #define FORMAT_RESIZE 0x08000000
376 #define FORMAT_KEEP_ASPECT 0x04000000
378 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
379 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
381 struct bitmap {
382 int width;
383 int height;
384 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
385 int format;
386 unsigned char *maskdata;
387 #endif
388 unsigned char *data;
391 extern void lcd_set_invert_display(bool yesno);
392 #ifdef HAVE_BACKLIGHT_INVERSION
393 extern void lcd_set_backlight_inversion(bool yesno);
394 #endif /* HAVE_BACKLIGHT_INVERSION */
395 extern void lcd_set_flip(bool yesno);
397 extern void lcd_set_drawmode(int mode);
398 extern int lcd_get_drawmode(void);
399 extern void lcd_setfont(int font);
400 extern int lcd_getfont(void);
402 extern void lcd_puts_style_offset(int x, int y, const unsigned char *str,
403 int style, int offset);
404 extern void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
405 int style, int offset);
407 /* low level drawing function pointer arrays */
408 #if LCD_DEPTH >= 8
409 extern lcd_fastpixelfunc_type* const *lcd_fastpixelfuncs;
410 #elif LCD_DEPTH > 1
411 extern lcd_pixelfunc_type* const *lcd_pixelfuncs;
412 extern lcd_blockfunc_type* const *lcd_blockfuncs;
413 #else /* LCD_DEPTH == 1*/
414 extern lcd_pixelfunc_type* const lcd_pixelfuncs[8];
415 extern lcd_blockfunc_type* const lcd_blockfuncs[8];
416 #endif /* LCD_DEPTH */
418 extern void lcd_drawpixel(int x, int y);
419 extern void lcd_drawline(int x1, int y1, int x2, int y2);
420 extern void lcd_hline(int x1, int x2, int y);
421 extern void lcd_vline(int x, int y1, int y2);
422 extern void lcd_drawrect(int x, int y, int width, int height);
423 extern void lcd_fillrect(int x, int y, int width, int height);
424 extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
425 int stride, int x, int y, int width, int height);
426 extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
427 int height);
429 extern void lcd_scroll_step(int pixels);
431 #if LCD_DEPTH > 1
432 extern void lcd_set_foreground(unsigned foreground);
433 extern unsigned lcd_get_foreground(void);
434 extern void lcd_set_background(unsigned background);
435 extern unsigned lcd_get_background(void);
436 #ifdef HAVE_LCD_COLOR
437 extern void lcd_set_selector_start(unsigned selector);
438 extern void lcd_set_selector_end(unsigned selector);
439 extern void lcd_set_selector_text(unsigned selector_text);
440 #endif
441 extern void lcd_set_drawinfo(int mode, unsigned foreground,
442 unsigned background);
443 void lcd_set_backdrop(fb_data* backdrop);
445 fb_data* lcd_get_backdrop(void);
447 extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
448 int stride, int x, int y, int width, int height);
449 extern void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width,
450 int height);
451 extern void lcd_bitmap_transparent_part(const fb_data *src,
452 int src_x, int src_y,
453 int stride, int x, int y, int width,
454 int height);
455 extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
456 int width, int height);
457 #else /* LCD_DEPTH == 1 */
458 #define lcd_mono_bitmap lcd_bitmap
459 #define lcd_mono_bitmap_part lcd_bitmap_part
460 #endif /* LCD_DEPTH */
462 #endif /* HAVE_LCD_BITMAP */
464 #endif /* __LCD_H__ */