Add the viewport functions to the screens API, including a new getfont() function...
[Rockbox.git] / firmware / export / lcd.h
blob57c9b1d3b82fbaff333f9c5647ebbcb3e82a8de1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Alan Korr
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #ifndef __LCD_H__
21 #define __LCD_H__
23 #include <stdbool.h>
24 #include "cpu.h"
25 #include "config.h"
27 struct viewport {
28 int x;
29 int y;
30 int width;
31 int height;
32 #ifdef HAVE_LCD_BITMAP
33 int font;
34 int drawmode;
35 #endif
36 int xmargin; /* During the transition only - to be removed */
37 int ymargin; /* During the transition only - to be removed */
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 #if LCD_DEPTH <=8
74 typedef unsigned char fb_data;
75 #elif LCD_DEPTH <= 16
76 typedef unsigned short fb_data;
77 #else /* LCD_DEPTH > 16 */
78 typedef unsigned long fb_data;
79 #endif /* LCD_DEPTH */
81 /* common functions */
82 extern void lcd_write_command(int byte);
83 extern void lcd_write_command_e(int cmd, int data);
84 extern void lcd_write_command_ex(int cmd, int data1, int data2);
85 extern void lcd_write_data(const fb_data* p_bytes, int count);
86 extern void lcd_init(void);
88 #ifdef SIMULATOR
89 /* Define a dummy device specific init for the sims */
90 #define lcd_init_device()
91 #else
92 extern void lcd_init_device(void);
93 #endif /* SIMULATOR */
95 extern void lcd_backlight(bool on);
96 extern int lcd_default_contrast(void);
97 extern void lcd_set_contrast(int val);
98 extern void lcd_setmargins(int xmargin, int ymargin);
99 extern int lcd_getxmargin(void);
100 extern int lcd_getymargin(void);
101 extern int lcd_getwidth(void);
102 extern int lcd_getheight(void);
103 extern int lcd_getstringsize(const unsigned char *str, int *w, int *h);
105 extern void lcd_set_viewport(struct viewport* vp);
106 extern void lcd_update(void);
107 extern void lcd_update_viewport(void);
108 extern void lcd_clear_viewport(void);
109 extern void lcd_clear_display(void);
110 extern void lcd_putsxy(int x, int y, const unsigned char *string);
111 extern void lcd_puts(int x, int y, const unsigned char *string);
112 extern void lcd_puts_style(int x, int y, const unsigned char *string, int style);
113 extern void lcd_puts_offset(int x, int y, const unsigned char *str, int offset);
114 extern void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
115 int offset);
116 extern void lcd_putc(int x, int y, unsigned long ucs);
117 extern void lcd_stop_scroll(void);
118 extern void lcd_bidir_scroll(int threshold);
119 extern void lcd_scroll_speed(int speed);
120 extern void lcd_scroll_delay(int ms);
121 extern void lcd_puts_scroll(int x, int y, const unsigned char* string);
122 extern void lcd_puts_scroll_style(int x, int y, const unsigned char* string,
123 int style);
125 #ifdef HAVE_LCD_BITMAP
127 #if defined(HAVE_LCD_COLOR)
128 #define LCD_YUV_DITHER 0x1
129 extern void lcd_yuv_set_options(unsigned options);
130 extern void lcd_yuv_blit(unsigned char * const src[3],
131 int src_x, int src_y, int stride,
132 int x, int y, int width, int height);
133 #else
134 struct grey_data {
135 unsigned char phase; /* SH1 uses it signed (doesn't matter for high level) */
136 unsigned char value; /* 0..128 are allowed */
137 } __attribute__((packed));
138 extern void lcd_grey_data(const struct grey_data *data, int count); /* private */
139 extern void lcd_grey_phase_blit(const struct grey_data *data, int bx, int by,
140 int bwidth, int bheight, int stride);
141 #endif
143 /* performance function */
144 extern void lcd_blit(const fb_data* data, int x, int by, int width,
145 int bheight, int stride);
147 /* update a fraction of the screen */
148 extern void lcd_update_rect(int x, int y, int width, int height);
149 extern void lcd_update_viewport_rect(int x, int y, int width, int height);
151 #ifdef HAVE_REMOTE_LCD
152 extern void lcd_remote_update(void);
153 /* update a fraction of the screen */
154 extern void lcd_remote_update_rect(int x, int y, int width, int height);
155 #endif /* HAVE_REMOTE_LCD */
156 #endif /* HAVE_LCD_BITMAP */
158 #ifdef HAVE_LCD_CHARCELLS
160 /* Icon definitions for lcd_icon() */
161 enum
163 ICON_BATTERY = 0,
164 ICON_BATTERY_1,
165 ICON_BATTERY_2,
166 ICON_BATTERY_3,
167 ICON_USB,
168 ICON_PLAY,
169 ICON_RECORD,
170 ICON_PAUSE,
171 ICON_AUDIO,
172 ICON_REPEAT,
173 ICON_1,
174 ICON_VOLUME,
175 ICON_VOLUME_1,
176 ICON_VOLUME_2,
177 ICON_VOLUME_3,
178 ICON_VOLUME_4,
179 ICON_VOLUME_5,
180 ICON_PARAM
183 void lcd_icon(int icon, bool enable);
184 void lcd_double_height(bool on);
185 void lcd_define_pattern(unsigned long ucs, const char *pattern);
186 unsigned long lcd_get_locked_pattern(void);
187 void lcd_unlock_pattern(unsigned long ucs);
188 void lcd_put_cursor(int x, int y, unsigned long cursor_ucs);
189 void lcd_remove_cursor(void);
190 #define JUMP_SCROLL_ALWAYS 5
191 extern void lcd_jump_scroll(int mode); /* 0=off, 1=once, ..., ALWAYS */
192 extern void lcd_jump_scroll_delay(int ms);
193 #endif /* HAVE_LCD_CHARCELLS */
195 /* Draw modes */
196 #define DRMODE_COMPLEMENT 0
197 #define DRMODE_BG 1
198 #define DRMODE_FG 2
199 #define DRMODE_SOLID 3
200 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
202 /* Low-level drawing function types */
203 typedef void lcd_pixelfunc_type(int x, int y);
204 typedef void lcd_blockfunc_type(fb_data *address, unsigned mask, unsigned bits);
205 #if LCD_DEPTH >= 8
206 typedef void lcd_fastpixelfunc_type(fb_data *address);
207 #endif
209 #ifdef HAVE_LCD_BITMAP
211 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
212 LCD_REMOTE_DEPTH > 1
213 /* Just return color for screens use */
214 static inline unsigned lcd_color_to_native(unsigned color)
215 { return color; }
216 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
217 #else
218 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
219 #endif
221 #ifdef HAVE_LCD_COLOR
222 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
223 #define LCD_MAX_RED 31
224 #define LCD_MAX_GREEN 63
225 #define LCD_MAX_BLUE 31
226 #define LCD_RED_BITS 5
227 #define LCD_GREEN_BITS 6
228 #define LCD_BLUE_BITS 5
230 /* pack/unpack native RGB values */
231 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
232 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
233 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
234 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
236 /* pack/unpack 24-bit RGB values */
237 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
238 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 13) & 0x07) )
239 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03) )
240 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) >> 2) & 0x07) )
242 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
243 /* RGB3553 */
244 #define _LCD_UNSWAP_COLOR(x) swap16(x)
245 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
246 (((g) >> 3) ) | \
247 (((g) & 0x07) << 13) | \
248 (((b) << 8) ) )
249 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
250 (((g) >> 5) ) | \
251 (((g) & 0x1c) << 11) | \
252 (((b) >> 3) << 8) )
253 /* swap color once - not currenly used in static inits */
254 #define _SWAPUNPACK(x, _unp_) \
255 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
256 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
257 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
258 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
259 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
260 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
261 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
262 #else /* LCD_PIXELFORMAT == RGB565 */
263 /* RGB565 */
264 #define _LCD_UNSWAP_COLOR(x) (x)
265 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
266 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
267 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
268 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
269 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
270 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
271 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
272 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
273 #endif /* RGB565* */
274 #else
275 /* other colour depths */
276 #endif
278 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
279 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
280 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
281 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
282 #define LCD_DEFAULT_FG LCD_BLACK
283 #define LCD_DEFAULT_BG LCD_RGBPACK(182, 198, 229) /* rockbox blue */
284 #define LCD_DEFAULT_LS LCD_WHITE
286 #elif LCD_DEPTH > 1 /* greyscale */
288 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
289 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
291 #define LCD_BLACK LCD_BRIGHTNESS(0)
292 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
293 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
294 #define LCD_WHITE LCD_BRIGHTNESS(255)
295 #define LCD_DEFAULT_FG LCD_BLACK
296 #define LCD_DEFAULT_BG LCD_WHITE
298 #endif /* HAVE_LCD_COLOR */
300 /* Frame buffer dimensions */
301 #if LCD_DEPTH == 1
302 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
303 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
304 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
305 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
306 #endif /* LCD_PIXELFORMAT */
307 #elif LCD_DEPTH == 2
308 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
309 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
310 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
311 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
312 #endif /* LCD_PIXELFORMAT */
313 #endif /* LCD_DEPTH */
314 /* Set defaults if not defined different yet. The defaults apply to both
315 * dimensions for LCD_DEPTH >= 8 */
316 #ifndef LCD_FBWIDTH
317 #define LCD_FBWIDTH LCD_WIDTH
318 #endif
319 #ifndef LCD_FBHEIGHT
320 #define LCD_FBHEIGHT LCD_HEIGHT
321 #endif
322 /* The actual framebuffer */
323 extern fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH];
325 /** Port-specific functions. Enable in port config file. **/
326 #ifdef HAVE_LCD_ENABLE
327 /* Enable/disable the main display. */
328 extern void lcd_enable(bool on);
329 extern bool lcd_enabled(void);
330 #endif /* HAVE_LCD_ENABLE */
332 #ifdef HAVE_LCD_SLEEP
333 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
334 extern void lcd_sleep(void);
335 #endif /* HAVE_LCD_SLEEP */
337 #ifdef HAVE_LCD_SHUTDOWN
338 void lcd_shutdown(void);
339 #endif
341 /* Bitmap formats */
342 enum
344 FORMAT_MONO,
345 FORMAT_NATIVE,
346 FORMAT_ANY /* For passing to read_bmp_file() */
349 #define FORMAT_TRANSPARENT 0x40000000
350 #define FORMAT_DITHER 0x20000000
351 #define FORMAT_REMOTE 0x10000000
353 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
354 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
356 struct bitmap {
357 int width;
358 int height;
359 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
360 int format;
361 unsigned char *maskdata;
362 #endif
363 unsigned char *data;
366 extern void lcd_set_invert_display(bool yesno);
367 #ifdef HAVE_BACKLIGHT_INVERSION
368 extern void lcd_set_backlight_inversion(bool yesno);
369 #endif /* HAVE_BACKLIGHT_INVERSION */
370 extern void lcd_set_flip(bool yesno);
372 extern void lcd_set_drawmode(int mode);
373 extern int lcd_get_drawmode(void);
374 extern void lcd_setfont(int font);
375 extern int lcd_getfont(void);
377 extern void lcd_puts_style_offset(int x, int y, const unsigned char *str,
378 int style, int offset);
379 extern void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
380 int style, int offset);
382 /* low level drawing function pointer arrays */
383 #if LCD_DEPTH >= 8
384 extern lcd_fastpixelfunc_type* const *lcd_fastpixelfuncs;
385 #elif LCD_DEPTH > 1
386 extern lcd_pixelfunc_type* const *lcd_pixelfuncs;
387 extern lcd_blockfunc_type* const *lcd_blockfuncs;
388 #else /* LCD_DEPTH == 1*/
389 extern lcd_pixelfunc_type* const lcd_pixelfuncs[8];
390 extern lcd_blockfunc_type* const lcd_blockfuncs[8];
391 #endif /* LCD_DEPTH */
393 extern void lcd_drawpixel(int x, int y);
394 extern void lcd_drawline(int x1, int y1, int x2, int y2);
395 extern void lcd_hline(int x1, int x2, int y);
396 extern void lcd_vline(int x, int y1, int y2);
397 extern void lcd_drawrect(int x, int y, int width, int height);
398 extern void lcd_fillrect(int x, int y, int width, int height);
399 extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
400 int stride, int x, int y, int width, int height);
401 extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
402 int height);
404 extern void lcd_scroll_step(int pixels);
406 #if LCD_DEPTH > 1
407 extern void lcd_set_foreground(unsigned foreground);
408 extern unsigned lcd_get_foreground(void);
409 extern void lcd_set_background(unsigned background);
410 extern unsigned lcd_get_background(void);
411 #ifdef HAVE_LCD_COLOR
412 extern void lcd_set_selector_start(unsigned selector);
413 extern void lcd_set_selector_end(unsigned selector);
414 extern void lcd_set_selector_text(unsigned selector_text);
415 #endif
416 extern void lcd_set_drawinfo(int mode, unsigned foreground,
417 unsigned background);
418 void lcd_set_backdrop(fb_data* backdrop);
420 fb_data* lcd_get_backdrop(void);
422 extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
423 int stride, int x, int y, int width, int height);
424 extern void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width,
425 int height);
426 extern void lcd_bitmap_transparent_part(const fb_data *src,
427 int src_x, int src_y,
428 int stride, int x, int y, int width,
429 int height);
430 extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
431 int width, int height);
432 #else /* LCD_DEPTH == 1 */
433 #define lcd_mono_bitmap lcd_bitmap
434 #define lcd_mono_bitmap_part lcd_bitmap_part
435 #endif /* LCD_DEPTH */
437 #endif /* HAVE_LCD_BITMAP */
439 #endif /* __LCD_H__ */