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
59 /* Frame buffer stride
61 * Stride describes the amount that you need to increment to get to the next
62 * line. For screens that have the pixels in contiguous horizontal strips
63 * stride should be equal to the image width.
65 * For example, if the screen pixels are layed out as follows:
67 * width0 width1 width2 widthX-1
68 * ------ ------ ------ ------------------ --------
69 * height0 | pixel0 pixel1 pixel2 ----------------> pixelX-1
72 * then you need to add X pixels to get to the next line. (the next line
73 * in this case is height1).
75 * Similarly, if the screen has the pixels in contiguous vertical strips
76 * the stride would be equal to the image height.
78 * For example if the screen pixels are layed out as follows:
82 * height0 | pixel0 pixelY
87 * heightY-1 | pixelY-1
89 * then you would need to add Y pixels to get to the next line (the next
90 * line in this case is from width0 to width1).
92 * The remote might have a different stride than the main screen so the screen
93 * number needs to be passed to the STRIDE macro so that the appropriate height
94 * or width can be passed to the lcd_bitmap, or lcd_remote_bitmap calls.
96 * STRIDE_REMOTE and STRIDE_MAIN should never be used when it is not clear whether
97 * lcd_remote_bitmap calls or lcd_bitmap calls are being made (for example the
100 * Screen should always use the screen_type enum that is at the top of this
105 #ifdef HAVE_REMOTE_LCD
110 #if defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE
111 #define STRIDE_MAIN(w, h) (h)
113 #define STRIDE_MAIN(w, h) (w)
116 #define STRIDE_REMOTE(w, h) (w)
118 #define STRIDE(screen, w, h) (screen==SCREEN_MAIN?STRIDE_MAIN((w), \
119 (h)):STRIDE_REMOTE((w),(h)))
121 #define STYLE_DEFAULT 0x00000000
122 #define STYLE_COLORED 0x10000000
123 #define STYLE_INVERT 0x20000000
124 #define STYLE_COLORBAR 0x40000000
125 #define STYLE_GRADIENT 0x80000000
126 #define STYLE_MODE_MASK 0xF0000000
127 #define STYLE_COLOR_MASK 0x0000FFFF
128 #ifdef HAVE_LCD_COLOR
129 #define STYLE_CURLN_MASK 0x0000FF00
130 #define STYLE_MAXLN_MASK 0x000000FF
131 #define CURLN_PACK(x) (((x)<<8) & STYLE_CURLN_MASK)
132 #define CURLN_UNPACK(x) ((unsigned char)(((x)&STYLE_CURLN_MASK) >> 8))
133 #define NUMLN_PACK(x) ((x) & STYLE_MAXLN_MASK)
134 #define NUMLN_UNPACK(x) ((unsigned char)((x) & STYLE_MAXLN_MASK))
137 #ifdef HAVE_LCD_BITMAP
139 #if (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED) \
140 || (LCD_PIXELFORMAT == HORIZONTAL_INTERLEAVED)
141 typedef unsigned short fb_data
;
144 typedef unsigned char fb_data
;
147 #elif LCD_DEPTH <= 16
148 typedef unsigned short fb_data
;
150 #else /* LCD_DEPTH > 16 */
151 typedef unsigned long fb_data
;
153 #endif /* LCD_DEPTH */
155 #else /* LCD_CHARCELLS */
156 typedef unsigned char fb_data
;
159 #if defined(HAVE_LCD_MODES)
160 void lcd_set_mode(int mode
);
161 #define LCD_MODE_RGB565 0x00000001
162 #define LCD_MODE_YUV 0x00000002
163 #define LCD_MODE_PAL256 0x00000004
165 #if HAVE_LCD_MODES & LCD_MODE_PAL256
166 void lcd_blit_pal256(unsigned char *src
, int src_x
, int src_y
, int x
, int y
,
167 int width
, int height
);
168 void lcd_pal256_update_pal(fb_data
*palette
);
173 /* common functions */
174 extern void lcd_write_command(int byte
);
175 extern void lcd_write_command_e(int cmd
, int data
);
176 extern void lcd_write_command_ex(int cmd
, int data1
, int data2
);
177 extern void lcd_write_data(const fb_data
* p_bytes
, int count
);
178 extern void lcd_init(void);
179 extern void lcd_init_device(void);
181 extern void lcd_backlight(bool on
);
182 extern int lcd_default_contrast(void);
183 extern void lcd_set_contrast(int val
);
184 extern int lcd_getwidth(void);
185 extern int lcd_getheight(void);
186 extern int lcd_getstringsize(const unsigned char *str
, int *w
, int *h
);
188 extern void lcd_set_viewport(struct viewport
* vp
);
189 extern void lcd_update(void);
190 extern void lcd_update_viewport(void);
191 extern void lcd_clear_viewport(void);
192 extern void lcd_clear_display(void);
193 extern void lcd_putsxy(int x
, int y
, const unsigned char *string
);
194 extern void lcd_puts(int x
, int y
, const unsigned char *string
);
195 extern void lcd_putsf(int x
, int y
, const unsigned char *fmt
, ...);
196 extern void lcd_puts_style(int x
, int y
, const unsigned char *string
, int style
);
197 extern void lcd_puts_offset(int x
, int y
, const unsigned char *str
, int offset
);
198 extern void lcd_puts_scroll_offset(int x
, int y
, const unsigned char *string
,
200 extern void lcd_putc(int x
, int y
, unsigned long ucs
);
201 extern void lcd_stop_scroll(void);
202 extern void lcd_bidir_scroll(int threshold
);
203 extern void lcd_scroll_speed(int speed
);
204 extern void lcd_scroll_delay(int ms
);
205 extern void lcd_puts_scroll(int x
, int y
, const unsigned char* string
);
206 extern void lcd_puts_scroll_style(int x
, int y
, const unsigned char* string
,
209 #ifdef HAVE_LCD_BITMAP
211 /* performance function */
212 #if defined(HAVE_LCD_COLOR)
214 #define LCD_YUV_DITHER 0x1
215 extern void lcd_yuv_set_options(unsigned options
);
216 extern void lcd_blit_yuv(unsigned char * const src
[3],
217 int src_x
, int src_y
, int stride
,
218 int x
, int y
, int width
, int height
);
219 #endif /* MEMORYSIZE > 2 */
221 extern void lcd_blit_mono(const unsigned char *data
, int x
, int by
, int width
,
222 int bheight
, int stride
);
223 extern void lcd_blit_grey_phase(unsigned char *values
, unsigned char *phases
,
224 int bx
, int by
, int bwidth
, int bheight
,
229 /* update a fraction of the screen */
230 extern void lcd_update_rect(int x
, int y
, int width
, int height
);
231 extern void lcd_update_viewport_rect(int x
, int y
, int width
, int height
);
233 #ifdef HAVE_REMOTE_LCD
234 extern void lcd_remote_update(void);
235 /* update a fraction of the screen */
236 extern void lcd_remote_update_rect(int x
, int y
, int width
, int height
);
237 #endif /* HAVE_REMOTE_LCD */
238 #endif /* HAVE_LCD_BITMAP */
240 #ifdef HAVE_LCD_CHARCELLS
242 /* Icon definitions for lcd_icon() */
265 void lcd_icon(int icon
, bool enable
);
266 void lcd_double_height(bool on
);
267 void lcd_define_pattern(unsigned long ucs
, const char *pattern
);
268 unsigned long lcd_get_locked_pattern(void);
269 void lcd_unlock_pattern(unsigned long ucs
);
270 void lcd_put_cursor(int x
, int y
, unsigned long cursor_ucs
);
271 void lcd_remove_cursor(void);
272 #define JUMP_SCROLL_ALWAYS 5
273 extern void lcd_jump_scroll(int mode
); /* 0=off, 1=once, ..., ALWAYS */
274 extern void lcd_jump_scroll_delay(int ms
);
275 #endif /* HAVE_LCD_CHARCELLS */
278 #define DRMODE_COMPLEMENT 0
281 #define DRMODE_SOLID 3
282 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
284 /* Low-level drawing function types */
285 typedef void lcd_pixelfunc_type(int x
, int y
);
286 typedef void lcd_blockfunc_type(fb_data
*address
, unsigned mask
, unsigned bits
);
288 typedef void lcd_fastpixelfunc_type(fb_data
*address
);
291 #ifdef HAVE_LCD_BITMAP
293 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
295 /* Just return color for screens use */
296 static inline unsigned lcd_color_to_native(unsigned color
)
298 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
300 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
303 #ifdef HAVE_LCD_COLOR
304 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
305 #define LCD_MAX_RED 31
306 #define LCD_MAX_GREEN 63
307 #define LCD_MAX_BLUE 31
308 #define LCD_RED_BITS 5
309 #define LCD_GREEN_BITS 6
310 #define LCD_BLUE_BITS 5
312 /* pack/unpack native RGB values */
313 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
314 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
315 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
316 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
318 /* pack/unpack 24-bit RGB values */
319 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
320 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 13) & 0x07) )
321 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03) )
322 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) >> 2) & 0x07) )
324 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
326 #define _LCD_UNSWAP_COLOR(x) swap16(x)
327 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
329 (((g) & 0x07) << 13) | \
331 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
333 (((g) & 0x1c) << 11) | \
335 /* swap color once - not currenly used in static inits */
336 #define _SWAPUNPACK(x, _unp_) \
337 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
338 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
339 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
340 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
341 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
342 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
343 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
344 #else /* LCD_PIXELFORMAT == RGB565 */
346 #define _LCD_UNSWAP_COLOR(x) (x)
347 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
348 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
349 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
350 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
351 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
352 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
353 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
354 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
357 /* other colour depths */
360 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
361 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
362 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
363 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
364 #define LCD_DEFAULT_FG LCD_WHITE
365 #define LCD_DEFAULT_BG LCD_BLACK
366 #define LCD_DEFAULT_LS LCD_WHITE
368 #elif LCD_DEPTH > 1 /* greyscale */
370 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
371 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
373 #define LCD_BLACK LCD_BRIGHTNESS(0)
374 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
375 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
376 #define LCD_WHITE LCD_BRIGHTNESS(255)
377 #define LCD_DEFAULT_FG LCD_BLACK
378 #define LCD_DEFAULT_BG LCD_WHITE
380 #endif /* HAVE_LCD_COLOR */
382 /* Frame buffer dimensions */
384 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
385 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
386 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
387 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
388 #endif /* LCD_PIXELFORMAT */
390 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
391 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
392 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
393 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
394 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
395 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
396 #endif /* LCD_PIXELFORMAT */
397 #endif /* LCD_DEPTH */
398 /* Set defaults if not defined different yet. The defaults apply to both
399 * dimensions for LCD_DEPTH >= 8 */
401 #define LCD_FBWIDTH LCD_WIDTH
404 #define LCD_FBHEIGHT LCD_HEIGHT
406 /* The actual framebuffer */
407 extern fb_data lcd_framebuffer
[LCD_FBHEIGHT
][LCD_FBWIDTH
];
409 /** Port-specific functions. Enable in port config file. **/
410 #ifdef HAVE_REMOTE_LCD_AS_MAIN
413 void lcd_poweroff(void);
416 #ifdef HAVE_LCD_ENABLE
417 /* Enable/disable the main display. */
418 extern void lcd_enable(bool on
);
419 #endif /* HAVE_LCD_ENABLE */
421 #ifdef HAVE_LCD_SLEEP
422 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
423 extern void lcd_sleep(void);
424 #endif /* HAVE_LCD_SLEEP */
425 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
426 /* Register a hook that is called when the lcd is powered and after the
427 * framebuffer data is synchronized */
428 /* Sansa Clip has these function in it's lcd driver, since it's the only
429 * 1-bit display featuring lcd_active, so far */
432 LCD_EVENT_ACTIVATION
= (EVENT_CLASS_LCD
|1),
435 extern bool lcd_active(void);
438 #ifdef HAVE_LCD_SHUTDOWN
439 extern void lcd_shutdown(void);
447 FORMAT_ANY
/* For passing to read_bmp_file() */
450 #define FORMAT_TRANSPARENT 0x40000000
451 #define FORMAT_DITHER 0x20000000
452 #define FORMAT_REMOTE 0x10000000
453 #define FORMAT_RESIZE 0x08000000
454 #define FORMAT_KEEP_ASPECT 0x04000000
455 #define FORMAT_RETURN_SIZE 0x02000000
457 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
458 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
463 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
465 unsigned char *maskdata
;
470 extern void lcd_set_invert_display(bool yesno
);
471 #ifdef HAVE_BACKLIGHT_INVERSION
472 extern void lcd_set_backlight_inversion(bool yesno
);
473 #endif /* HAVE_BACKLIGHT_INVERSION */
474 extern void lcd_set_flip(bool yesno
);
476 extern void lcd_set_drawmode(int mode
);
477 extern int lcd_get_drawmode(void);
478 extern void lcd_setfont(int font
);
479 extern int lcd_getfont(void);
481 extern void lcd_puts_style_offset(int x
, int y
, const unsigned char *str
,
482 int style
, int offset
);
483 extern void lcd_puts_scroll_style_offset(int x
, int y
, const unsigned char *string
,
484 int style
, int offset
);
486 /* low level drawing function pointer arrays */
488 extern lcd_fastpixelfunc_type
* const *lcd_fastpixelfuncs
;
490 extern lcd_pixelfunc_type
* const *lcd_pixelfuncs
;
491 extern lcd_blockfunc_type
* const *lcd_blockfuncs
;
492 #else /* LCD_DEPTH == 1*/
493 extern lcd_pixelfunc_type
* const lcd_pixelfuncs
[8];
494 extern lcd_blockfunc_type
* const lcd_blockfuncs
[8];
495 #endif /* LCD_DEPTH */
497 extern void lcd_drawpixel(int x
, int y
);
498 extern void lcd_drawline(int x1
, int y1
, int x2
, int y2
);
499 extern void lcd_hline(int x1
, int x2
, int y
);
500 extern void lcd_vline(int x
, int y1
, int y2
);
501 extern void lcd_drawrect(int x
, int y
, int width
, int height
);
502 extern void lcd_fillrect(int x
, int y
, int width
, int height
);
503 extern void lcd_bitmap_part(const fb_data
*src
, int src_x
, int src_y
,
504 int stride
, int x
, int y
, int width
, int height
);
505 extern void lcd_bitmap(const fb_data
*src
, int x
, int y
, int width
,
508 extern void lcd_scroll_step(int pixels
);
511 extern void lcd_set_foreground(unsigned foreground
);
512 extern unsigned lcd_get_foreground(void);
513 extern void lcd_set_background(unsigned background
);
514 extern unsigned lcd_get_background(void);
515 #ifdef HAVE_LCD_COLOR
516 extern void lcd_set_selector_start(unsigned selector
);
517 extern void lcd_set_selector_end(unsigned selector
);
518 extern void lcd_set_selector_text(unsigned selector_text
);
520 extern void lcd_set_drawinfo(int mode
, unsigned foreground
,
521 unsigned background
);
522 void lcd_set_backdrop(fb_data
* backdrop
);
524 fb_data
* lcd_get_backdrop(void);
526 extern void lcd_mono_bitmap_part(const unsigned char *src
, int src_x
, int src_y
,
527 int stride
, int x
, int y
, int width
, int height
);
528 extern void lcd_mono_bitmap(const unsigned char *src
, int x
, int y
, int width
,
530 extern void lcd_bitmap_transparent_part(const fb_data
*src
,
531 int src_x
, int src_y
,
532 int stride
, int x
, int y
, int width
,
534 extern void lcd_bitmap_transparent(const fb_data
*src
, int x
, int y
,
535 int width
, int height
);
536 #else /* LCD_DEPTH == 1 */
537 #define lcd_mono_bitmap lcd_bitmap
538 #define lcd_mono_bitmap_part lcd_bitmap_part
539 #endif /* LCD_DEPTH */
541 #endif /* HAVE_LCD_BITMAP */
543 #endif /* __LCD_H__ */