1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
30 #define VP_FLAG_ALIGN_RIGHT 0x01
31 #define VP_FLAG_ALIGN_CENTER 0x02
33 #define VP_FLAG_ALIGNMENT_MASK \
34 (VP_FLAG_ALIGN_RIGHT|VP_FLAG_ALIGN_CENTER)
36 #define VP_IS_RTL(vp) (((vp)->flags & VP_FLAG_ALIGNMENT_MASK) == VP_FLAG_ALIGN_RIGHT)
43 #ifdef HAVE_LCD_BITMAP
46 int line_height
; /* 0 for using font height */
60 /* Frame buffer stride
62 * Stride describes the amount that you need to increment to get to the next
63 * line. For screens that have the pixels in contiguous horizontal strips
64 * stride should be equal to the image width.
66 * For example, if the screen pixels are layed out as follows:
68 * width0 width1 width2 widthX-1
69 * ------ ------ ------ ------------------ --------
70 * height0 | pixel0 pixel1 pixel2 ----------------> pixelX-1
73 * then you need to add X pixels to get to the next line. (the next line
74 * in this case is height1).
76 * Similarly, if the screen has the pixels in contiguous vertical strips
77 * the stride would be equal to the image height.
79 * For example if the screen pixels are layed out as follows:
83 * height0 | pixel0 pixelY
88 * heightY-1 | pixelY-1
90 * then you would need to add Y pixels to get to the next line (the next
91 * line in this case is from width0 to width1).
93 * The remote might have a different stride than the main screen so the screen
94 * number needs to be passed to the STRIDE macro so that the appropriate height
95 * or width can be passed to the lcd_bitmap, or lcd_remote_bitmap calls.
97 * STRIDE_REMOTE and STRIDE_MAIN should never be used when it is not clear whether
98 * lcd_remote_bitmap calls or lcd_bitmap calls are being made (for example the
101 * Screen should always use the screen_type enum that is at the top of this
106 #ifdef HAVE_REMOTE_LCD
111 #if defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE
112 #define STRIDE_MAIN(w, h) (h)
114 #define STRIDE_MAIN(w, h) (w)
117 #define STRIDE_REMOTE(w, h) (w)
119 #define STRIDE(screen, w, h) (screen==SCREEN_MAIN?STRIDE_MAIN((w), \
120 (h)):STRIDE_REMOTE((w),(h)))
122 #define STYLE_DEFAULT 0x00000000
123 #define STYLE_COLORED 0x10000000
124 #define STYLE_INVERT 0x20000000
125 #define STYLE_COLORBAR 0x40000000
126 #define STYLE_GRADIENT 0x80000000
127 #define STYLE_MODE_MASK 0xF0000000
128 /* HACK: This isnt really a style, We need to be able to tell some of
129 * the lcd API that we want to draw text to a specific pixel instead
130 * of a char. Remove this hack when the whole LCD api goes to fully
131 * pixel based positioning - jdgordon */
132 #define STYLE_XY_PIXELS 0x00010000
133 #define STYLE_COLOR_MASK 0x0000FFFF
134 #ifdef HAVE_LCD_COLOR
135 #define STYLE_CURLN_MASK 0x0000FF00
136 #define STYLE_MAXLN_MASK 0x000000FF
137 #define CURLN_PACK(x) (((x)<<8) & STYLE_CURLN_MASK)
138 #define CURLN_UNPACK(x) ((unsigned char)(((x)&STYLE_CURLN_MASK) >> 8))
139 #define NUMLN_PACK(x) ((x) & STYLE_MAXLN_MASK)
140 #define NUMLN_UNPACK(x) ((unsigned char)((x) & STYLE_MAXLN_MASK))
143 #ifdef HAVE_LCD_BITMAP
145 #if (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED) \
146 || (LCD_PIXELFORMAT == HORIZONTAL_INTERLEAVED)
147 typedef unsigned short fb_data
;
150 typedef unsigned char fb_data
;
153 #elif LCD_DEPTH <= 16
154 typedef unsigned short fb_data
;
156 #else /* LCD_DEPTH > 16 */
157 typedef unsigned long fb_data
;
159 #endif /* LCD_DEPTH */
161 #else /* LCD_CHARCELLS */
162 typedef unsigned char fb_data
;
165 #if defined(HAVE_LCD_MODES)
166 void lcd_set_mode(int mode
);
167 #define LCD_MODE_RGB565 0x00000001
168 #define LCD_MODE_YUV 0x00000002
169 #define LCD_MODE_PAL256 0x00000004
171 #if HAVE_LCD_MODES & LCD_MODE_PAL256
172 void lcd_blit_pal256(unsigned char *src
, int src_x
, int src_y
, int x
, int y
,
173 int width
, int height
);
174 void lcd_pal256_update_pal(fb_data
*palette
);
179 /* common functions */
180 extern void lcd_write_command(int byte
);
181 extern void lcd_write_command_e(int cmd
, int data
);
182 extern void lcd_write_command_ex(int cmd
, int data1
, int data2
);
183 extern void lcd_write_data(const fb_data
* p_bytes
, int count
);
184 extern void lcd_init(void) INIT_ATTR
;
185 extern void lcd_init_device(void) INIT_ATTR
;
187 extern void lcd_backlight(bool on
);
188 extern int lcd_default_contrast(void);
189 extern void lcd_set_contrast(int val
);
190 extern int lcd_getwidth(void);
191 extern int lcd_getheight(void);
192 extern int lcd_getstringsize(const unsigned char *str
, int *w
, int *h
);
194 extern void lcd_set_viewport(struct viewport
* vp
);
195 extern void lcd_update(void);
196 extern void lcd_update_viewport(void);
197 extern void lcd_clear_viewport(void);
198 extern void lcd_clear_display(void);
199 extern void lcd_putsxy(int x
, int y
, const unsigned char *string
);
200 extern void lcd_putsxyf(int x
, int y
, const unsigned char *fmt
, ...);
201 extern void lcd_putsxy_style_offset(int x
, int y
, const unsigned char *str
,
202 int style
, int offset
);
203 extern void lcd_puts(int x
, int y
, const unsigned char *string
);
204 extern void lcd_putsf(int x
, int y
, const unsigned char *fmt
, ...);
205 extern void lcd_puts_style(int x
, int y
, const unsigned char *string
, int style
);
206 extern void lcd_puts_offset(int x
, int y
, const unsigned char *str
, int offset
);
207 extern void lcd_puts_scroll_offset(int x
, int y
, const unsigned char *string
,
209 extern void lcd_putc(int x
, int y
, unsigned long ucs
);
210 extern void lcd_stop_scroll(void);
211 extern void lcd_bidir_scroll(int threshold
);
212 extern void lcd_scroll_speed(int speed
);
213 extern void lcd_scroll_delay(int ms
);
214 extern void lcd_puts_scroll(int x
, int y
, const unsigned char* string
);
215 extern void lcd_puts_scroll_style(int x
, int y
, const unsigned char* string
,
218 #ifdef HAVE_LCD_BITMAP
220 /* performance function */
221 #if defined(HAVE_LCD_COLOR)
223 #define LCD_YUV_DITHER 0x1
224 extern void lcd_yuv_set_options(unsigned options
);
225 extern void lcd_blit_yuv(unsigned char * const src
[3],
226 int src_x
, int src_y
, int stride
,
227 int x
, int y
, int width
, int height
);
228 #endif /* MEMORYSIZE > 2 */
230 extern void lcd_blit_mono(const unsigned char *data
, int x
, int by
, int width
,
231 int bheight
, int stride
);
232 extern void lcd_blit_grey_phase(unsigned char *values
, unsigned char *phases
,
233 int bx
, int by
, int bwidth
, int bheight
,
238 /* update a fraction of the screen */
239 extern void lcd_update_rect(int x
, int y
, int width
, int height
);
240 extern void lcd_update_viewport_rect(int x
, int y
, int width
, int height
);
242 #ifdef HAVE_REMOTE_LCD
243 extern void lcd_remote_update(void);
244 /* update a fraction of the screen */
245 extern void lcd_remote_update_rect(int x
, int y
, int width
, int height
);
246 #endif /* HAVE_REMOTE_LCD */
247 #endif /* HAVE_LCD_BITMAP */
249 #ifdef HAVE_LCD_CHARCELLS
251 /* Icon definitions for lcd_icon() */
274 void lcd_icon(int icon
, bool enable
);
275 void lcd_double_height(bool on
);
276 void lcd_define_pattern(unsigned long ucs
, const char *pattern
);
277 unsigned long lcd_get_locked_pattern(void);
278 void lcd_unlock_pattern(unsigned long ucs
);
279 void lcd_put_cursor(int x
, int y
, unsigned long cursor_ucs
);
280 void lcd_remove_cursor(void);
281 #define JUMP_SCROLL_ALWAYS 5
282 extern void lcd_jump_scroll(int mode
); /* 0=off, 1=once, ..., ALWAYS */
283 extern void lcd_jump_scroll_delay(int ms
);
284 #endif /* HAVE_LCD_CHARCELLS */
287 #define DRMODE_COMPLEMENT 0
290 #define DRMODE_SOLID 3
291 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
292 /* Internal drawmode modifiers. DO NOT use with set_drawmode() */
293 #define DRMODE_INT_MOD 8
295 /* Low-level drawing function types */
296 typedef void lcd_pixelfunc_type(int x
, int y
);
297 typedef void lcd_blockfunc_type(fb_data
*address
, unsigned mask
, unsigned bits
);
299 typedef void lcd_fastpixelfunc_type(fb_data
*address
);
302 #ifdef HAVE_LCD_BITMAP
304 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
306 /* Just return color for screens use */
307 static inline unsigned lcd_color_to_native(unsigned color
)
309 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
311 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
314 #ifdef HAVE_LCD_COLOR
315 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
316 #define LCD_MAX_RED 31
317 #define LCD_MAX_GREEN 63
318 #define LCD_MAX_BLUE 31
319 #define LCD_RED_BITS 5
320 #define LCD_GREEN_BITS 6
321 #define LCD_BLUE_BITS 5
323 /* pack/unpack native RGB values */
324 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
325 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
326 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
327 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
329 /* pack/unpack 24-bit RGB values */
330 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
331 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 13) & 0x07) )
332 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03) )
333 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) >> 2) & 0x07) )
335 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
337 #define _LCD_UNSWAP_COLOR(x) swap16(x)
338 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
340 (((g) & 0x07) << 13) | \
342 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
344 (((g) & 0x1c) << 11) | \
346 /* swap color once - not currenly used in static inits */
347 #define _SWAPUNPACK(x, _unp_) \
348 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
349 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
350 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
351 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
352 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
353 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
354 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
355 #else /* LCD_PIXELFORMAT == RGB565 */
357 #define _LCD_UNSWAP_COLOR(x) (x)
358 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
359 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
360 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
361 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
362 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
363 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
364 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
365 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
368 /* other colour depths */
371 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
372 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
373 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
374 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
375 #define LCD_DEFAULT_FG LCD_WHITE
376 #define LCD_DEFAULT_BG LCD_BLACK
377 #define LCD_DEFAULT_LS LCD_WHITE
379 #elif LCD_DEPTH > 1 /* greyscale */
381 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
382 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
384 #define LCD_BLACK LCD_BRIGHTNESS(0)
385 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
386 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
387 #define LCD_WHITE LCD_BRIGHTNESS(255)
388 #define LCD_DEFAULT_FG LCD_BLACK
389 #define LCD_DEFAULT_BG LCD_WHITE
391 #endif /* HAVE_LCD_COLOR */
393 /* Frame buffer dimensions */
395 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
396 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
397 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
398 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
399 #endif /* LCD_PIXELFORMAT */
401 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
402 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
403 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
404 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
405 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
406 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
407 #endif /* LCD_PIXELFORMAT */
408 #endif /* LCD_DEPTH */
409 /* Set defaults if not defined different yet. The defaults apply to both
410 * dimensions for LCD_DEPTH >= 8 */
412 #define LCD_FBWIDTH LCD_WIDTH
415 #define LCD_FBHEIGHT LCD_HEIGHT
417 /* The actual framebuffer */
418 extern fb_data
*lcd_framebuffer
;
419 extern fb_data lcd_static_framebuffer
[LCD_FBHEIGHT
][LCD_FBWIDTH
];
420 #if defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE
421 #define FBADDR(x, y) (lcd_framebuffer + ((x) * LCD_FBHEIGHT) + (y))
423 #define FBADDR(x, y) (lcd_framebuffer + ((y) * LCD_FBWIDTH) + (x))
425 #define FRAMEBUFFER_SIZE (sizeof(lcd_static_framebuffer))
427 /** Port-specific functions. Enable in port config file. **/
428 #ifdef HAVE_REMOTE_LCD_AS_MAIN
431 void lcd_poweroff(void);
434 #ifdef HAVE_LCD_ENABLE
435 /* Enable/disable the main display. */
436 extern void lcd_enable(bool on
);
437 #endif /* HAVE_LCD_ENABLE */
439 #ifdef HAVE_LCD_SLEEP
440 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
441 extern void lcd_sleep(void);
442 #endif /* HAVE_LCD_SLEEP */
443 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
444 /* Register a hook that is called when the lcd is powered and after the
445 * framebuffer data is synchronized */
446 /* Sansa Clip has these function in it's lcd driver, since it's the only
447 * 1-bit display featuring lcd_active, so far */
450 LCD_EVENT_ACTIVATION
= (EVENT_CLASS_LCD
|1),
453 extern bool lcd_active(void);
456 #ifdef HAVE_LCD_SHUTDOWN
457 extern void lcd_shutdown(void);
465 FORMAT_ANY
/* For passing to read_bmp_file() */
468 #define FORMAT_TRANSPARENT 0x40000000
469 #define FORMAT_DITHER 0x20000000
470 #define FORMAT_REMOTE 0x10000000
471 #define FORMAT_RESIZE 0x08000000
472 #define FORMAT_KEEP_ASPECT 0x04000000
473 #define FORMAT_RETURN_SIZE 0x02000000
475 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
476 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
481 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
483 unsigned char *maskdata
;
485 #ifdef HAVE_LCD_COLOR
486 int alpha_offset
; /* byte-offset of alpha channel in data */
491 extern void lcd_set_invert_display(bool yesno
);
492 #ifdef HAVE_BACKLIGHT_INVERSION
493 extern void lcd_set_backlight_inversion(bool yesno
);
494 #endif /* HAVE_BACKLIGHT_INVERSION */
495 extern void lcd_set_flip(bool yesno
);
497 extern void lcd_set_drawmode(int mode
);
498 extern int lcd_get_drawmode(void);
499 extern void lcd_setfont(int font
);
500 extern int lcd_getfont(void);
502 extern void lcd_puts_style_offset(int x
, int y
, const unsigned char *str
,
503 int style
, int x_offset
);
504 extern void lcd_puts_style_xyoffset(int x
, int y
, const unsigned char *str
,
505 int style
, int x_offset
, int y_offset
);
506 extern void lcd_puts_scroll_style_offset(int x
, int y
, const unsigned char *string
,
507 int style
, int x_offset
);
508 extern void lcd_puts_scroll_style_xyoffset(int x
, int y
, const unsigned char *string
,
509 int style
, int x_offset
, int y_offset
);
511 /* low level drawing function pointer arrays */
513 extern lcd_fastpixelfunc_type
* const *lcd_fastpixelfuncs
;
515 extern lcd_pixelfunc_type
* const *lcd_pixelfuncs
;
516 extern lcd_blockfunc_type
* const *lcd_blockfuncs
;
517 #else /* LCD_DEPTH == 1*/
518 extern lcd_pixelfunc_type
* const lcd_pixelfuncs
[8];
519 extern lcd_blockfunc_type
* const lcd_blockfuncs
[8];
520 #endif /* LCD_DEPTH */
522 extern void lcd_drawpixel(int x
, int y
);
523 extern void lcd_drawline(int x1
, int y1
, int x2
, int y2
);
524 extern void lcd_hline(int x1
, int x2
, int y
);
525 extern void lcd_vline(int x
, int y1
, int y2
);
526 extern void lcd_drawrect(int x
, int y
, int width
, int height
);
527 extern void lcd_fillrect(int x
, int y
, int width
, int height
);
528 extern void lcd_gradient_fillrect(int x
, int y
, int width
, int height
,
529 unsigned start_rgb
, unsigned end_rgb
);
530 extern void lcd_draw_border_viewport(void);
531 extern void lcd_fill_viewport(void);
532 extern void lcd_bitmap_part(const fb_data
*src
, int src_x
, int src_y
,
533 int stride
, int x
, int y
, int width
, int height
);
534 extern void lcd_bitmap(const fb_data
*src
, int x
, int y
, int width
,
536 extern void lcd_set_framebuffer(fb_data
*fb
);
538 extern void lcd_scroll_step(int pixels
);
541 extern void lcd_set_foreground(unsigned foreground
);
542 extern unsigned lcd_get_foreground(void);
543 extern void lcd_set_background(unsigned background
);
544 extern unsigned lcd_get_background(void);
545 #ifdef HAVE_LCD_COLOR
546 extern void lcd_set_selector_start(unsigned selector
);
547 extern void lcd_set_selector_end(unsigned selector
);
548 extern void lcd_set_selector_text(unsigned selector_text
);
550 extern void lcd_set_drawinfo(int mode
, unsigned foreground
,
551 unsigned background
);
552 void lcd_set_backdrop(fb_data
* backdrop
);
554 fb_data
* lcd_get_backdrop(void);
556 extern void lcd_mono_bitmap_part(const unsigned char *src
, int src_x
, int src_y
,
557 int stride
, int x
, int y
, int width
, int height
);
558 extern void lcd_mono_bitmap(const unsigned char *src
, int x
, int y
, int width
,
560 extern void lcd_bitmap_transparent_part(const fb_data
*src
,
561 int src_x
, int src_y
,
562 int stride
, int x
, int y
, int width
,
564 extern void lcd_bitmap_transparent(const fb_data
*src
, int x
, int y
,
565 int width
, int height
);
566 #else /* LCD_DEPTH == 1 */
567 #define lcd_mono_bitmap lcd_bitmap
568 #define lcd_mono_bitmap_part lcd_bitmap_part
569 #endif /* LCD_DEPTH */
570 extern void lcd_bmp_part(const struct bitmap
* bm
, int src_x
, int src_y
,
571 int x
, int y
, int width
, int height
);
572 extern void lcd_bmp(const struct bitmap
* bm
, int x
, int y
);
573 extern void lcd_nine_segment_bmp(const struct bitmap
* bm
, int x
, int y
,
574 int width
, int height
);
575 #endif /* HAVE_LCD_BITMAP */
578 #ifdef HAVE_TOUCHSCREEN
579 /* only needed for touchscreen for now, feel free to implement it for others
583 #if defined(LCD_DPI) && (LCD_DPI > 0)
584 /* returns the pixel density of the display */
585 static inline int lcd_get_dpi(void) { return LCD_DPI
; }
587 extern int lcd_get_dpi(void);
589 #endif /* HAVE_TOUCHSCREEN */
591 #endif /* __LCD_H__ */