1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
32 #ifdef HAVE_LCD_BITMAP
36 int xmargin
; /* During the transition only - to be removed */
37 int ymargin
; /* During the transition only - to be removed */
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
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))
70 #include "file.h" /* for MAX_PATH; FIXME: Why does this not work for sims? */
71 #endif /* SIMULATOR */
73 #ifdef HAVE_LCD_BITMAP
75 #if (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED) \
76 || (LCD_PIXELFORMAT == HORIZONTAL_INTERLEAVED)
77 typedef unsigned short fb_data
;
79 typedef unsigned char fb_data
;
82 typedef unsigned short fb_data
;
83 #else /* LCD_DEPTH > 16 */
84 typedef unsigned long fb_data
;
85 #endif /* LCD_DEPTH */
87 #else /* LCD_CHARCELLS */
88 typedef unsigned char fb_data
;
91 /* common functions */
92 extern void lcd_write_command(int byte
);
93 extern void lcd_write_command_e(int cmd
, int data
);
94 extern void lcd_write_command_ex(int cmd
, int data1
, int data2
);
95 extern void lcd_write_data(const fb_data
* p_bytes
, int count
);
96 extern void lcd_init(void);
99 /* Define a dummy device specific init for the sims */
100 #define lcd_init_device()
102 extern void lcd_init_device(void);
103 #endif /* SIMULATOR */
105 extern void lcd_backlight(bool on
);
106 extern int lcd_default_contrast(void);
107 extern void lcd_set_contrast(int val
);
108 extern void lcd_setmargins(int xmargin
, int ymargin
);
109 extern int lcd_getxmargin(void);
110 extern int lcd_getymargin(void);
111 extern int lcd_getwidth(void);
112 extern int lcd_getheight(void);
113 extern int lcd_getstringsize(const unsigned char *str
, int *w
, int *h
);
115 extern void lcd_set_viewport(struct viewport
* vp
);
116 extern void lcd_update(void);
117 extern void lcd_update_viewport(void);
118 extern void lcd_clear_viewport(void);
119 extern void lcd_clear_display(void);
120 extern void lcd_putsxy(int x
, int y
, const unsigned char *string
);
121 extern void lcd_puts(int x
, int y
, const unsigned char *string
);
122 extern void lcd_puts_style(int x
, int y
, const unsigned char *string
, int style
);
123 extern void lcd_puts_offset(int x
, int y
, const unsigned char *str
, int offset
);
124 extern void lcd_puts_scroll_offset(int x
, int y
, const unsigned char *string
,
126 extern void lcd_putc(int x
, int y
, unsigned long ucs
);
127 extern void lcd_stop_scroll(void);
128 extern void lcd_bidir_scroll(int threshold
);
129 extern void lcd_scroll_speed(int speed
);
130 extern void lcd_scroll_delay(int ms
);
131 extern void lcd_puts_scroll(int x
, int y
, const unsigned char* string
);
132 extern void lcd_puts_scroll_style(int x
, int y
, const unsigned char* string
,
135 #ifdef HAVE_LCD_BITMAP
137 /* performance function */
138 #if defined(HAVE_LCD_COLOR)
139 #define LCD_YUV_DITHER 0x1
140 extern void lcd_yuv_set_options(unsigned options
);
141 extern void lcd_blit_yuv(unsigned char * const src
[3],
142 int src_x
, int src_y
, int stride
,
143 int x
, int y
, int width
, int height
);
145 extern void lcd_blit_mono(const unsigned char *data
, int x
, int by
, int width
,
146 int bheight
, int stride
);
147 extern void lcd_blit_grey_phase(unsigned char *values
, unsigned char *phases
,
148 int bx
, int by
, int bwidth
, int bheight
,
153 /* update a fraction of the screen */
154 extern void lcd_update_rect(int x
, int y
, int width
, int height
);
155 extern void lcd_update_viewport_rect(int x
, int y
, int width
, int height
);
157 #ifdef HAVE_REMOTE_LCD
158 extern void lcd_remote_update(void);
159 /* update a fraction of the screen */
160 extern void lcd_remote_update_rect(int x
, int y
, int width
, int height
);
161 #endif /* HAVE_REMOTE_LCD */
162 #endif /* HAVE_LCD_BITMAP */
164 #ifdef HAVE_LCD_CHARCELLS
166 /* Icon definitions for lcd_icon() */
189 void lcd_icon(int icon
, bool enable
);
190 void lcd_double_height(bool on
);
191 void lcd_define_pattern(unsigned long ucs
, const char *pattern
);
192 unsigned long lcd_get_locked_pattern(void);
193 void lcd_unlock_pattern(unsigned long ucs
);
194 void lcd_put_cursor(int x
, int y
, unsigned long cursor_ucs
);
195 void lcd_remove_cursor(void);
196 #define JUMP_SCROLL_ALWAYS 5
197 extern void lcd_jump_scroll(int mode
); /* 0=off, 1=once, ..., ALWAYS */
198 extern void lcd_jump_scroll_delay(int ms
);
199 #endif /* HAVE_LCD_CHARCELLS */
202 #define DRMODE_COMPLEMENT 0
205 #define DRMODE_SOLID 3
206 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
208 /* Low-level drawing function types */
209 typedef void lcd_pixelfunc_type(int x
, int y
);
210 typedef void lcd_blockfunc_type(fb_data
*address
, unsigned mask
, unsigned bits
);
212 typedef void lcd_fastpixelfunc_type(fb_data
*address
);
215 #ifdef HAVE_LCD_BITMAP
217 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
219 /* Just return color for screens use */
220 static inline unsigned lcd_color_to_native(unsigned color
)
222 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
224 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
227 #ifdef HAVE_LCD_COLOR
228 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
229 #define LCD_MAX_RED 31
230 #define LCD_MAX_GREEN 63
231 #define LCD_MAX_BLUE 31
232 #define LCD_RED_BITS 5
233 #define LCD_GREEN_BITS 6
234 #define LCD_BLUE_BITS 5
236 /* pack/unpack native RGB values */
237 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
238 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
239 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
240 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
242 /* pack/unpack 24-bit RGB values */
243 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
244 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 13) & 0x07) )
245 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03) )
246 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) >> 2) & 0x07) )
248 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
250 #define _LCD_UNSWAP_COLOR(x) swap16(x)
251 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
253 (((g) & 0x07) << 13) | \
255 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
257 (((g) & 0x1c) << 11) | \
259 /* swap color once - not currenly used in static inits */
260 #define _SWAPUNPACK(x, _unp_) \
261 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
262 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
263 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
264 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
265 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
266 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
267 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
268 #else /* LCD_PIXELFORMAT == RGB565 */
270 #define _LCD_UNSWAP_COLOR(x) (x)
271 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
272 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
273 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
274 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
275 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
276 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
277 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
278 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
281 /* other colour depths */
284 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
285 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
286 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
287 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
288 #define LCD_DEFAULT_FG LCD_BLACK
289 #define LCD_DEFAULT_BG LCD_RGBPACK(182, 198, 229) /* rockbox blue */
290 #define LCD_DEFAULT_LS LCD_WHITE
292 #elif LCD_DEPTH > 1 /* greyscale */
294 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
295 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
297 #define LCD_BLACK LCD_BRIGHTNESS(0)
298 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
299 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
300 #define LCD_WHITE LCD_BRIGHTNESS(255)
301 #define LCD_DEFAULT_FG LCD_BLACK
302 #define LCD_DEFAULT_BG LCD_WHITE
304 #endif /* HAVE_LCD_COLOR */
306 /* Frame buffer dimensions */
308 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
309 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
310 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
311 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
312 #endif /* LCD_PIXELFORMAT */
314 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
315 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
316 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
317 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
318 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
319 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
320 #endif /* LCD_PIXELFORMAT */
321 #endif /* LCD_DEPTH */
322 /* Set defaults if not defined different yet. The defaults apply to both
323 * dimensions for LCD_DEPTH >= 8 */
325 #define LCD_FBWIDTH LCD_WIDTH
328 #define LCD_FBHEIGHT LCD_HEIGHT
330 /* The actual framebuffer */
331 extern fb_data lcd_framebuffer
[LCD_FBHEIGHT
][LCD_FBWIDTH
];
333 /** Port-specific functions. Enable in port config file. **/
334 #ifdef HAVE_REMOTE_LCD_AS_MAIN
337 void lcd_poweroff(void);
340 #ifdef HAVE_LCD_ENABLE
341 /* Enable/disable the main display. */
342 extern void lcd_enable(bool on
);
343 extern bool lcd_enabled(void);
344 #endif /* HAVE_LCD_ENABLE */
346 #ifdef HAVE_LCD_SLEEP
347 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
348 extern void lcd_sleep(void);
349 #endif /* HAVE_LCD_SLEEP */
351 #ifdef HAVE_LCD_SHUTDOWN
352 void lcd_shutdown(void);
360 FORMAT_ANY
/* For passing to read_bmp_file() */
363 #define FORMAT_TRANSPARENT 0x40000000
364 #define FORMAT_DITHER 0x20000000
365 #define FORMAT_REMOTE 0x10000000
367 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
368 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
373 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
375 unsigned char *maskdata
;
380 extern void lcd_set_invert_display(bool yesno
);
381 #ifdef HAVE_BACKLIGHT_INVERSION
382 extern void lcd_set_backlight_inversion(bool yesno
);
383 #endif /* HAVE_BACKLIGHT_INVERSION */
384 extern void lcd_set_flip(bool yesno
);
386 extern void lcd_set_drawmode(int mode
);
387 extern int lcd_get_drawmode(void);
388 extern void lcd_setfont(int font
);
389 extern int lcd_getfont(void);
391 extern void lcd_puts_style_offset(int x
, int y
, const unsigned char *str
,
392 int style
, int offset
);
393 extern void lcd_puts_scroll_style_offset(int x
, int y
, const unsigned char *string
,
394 int style
, int offset
);
396 /* low level drawing function pointer arrays */
398 extern lcd_fastpixelfunc_type
* const *lcd_fastpixelfuncs
;
400 extern lcd_pixelfunc_type
* const *lcd_pixelfuncs
;
401 extern lcd_blockfunc_type
* const *lcd_blockfuncs
;
402 #else /* LCD_DEPTH == 1*/
403 extern lcd_pixelfunc_type
* const lcd_pixelfuncs
[8];
404 extern lcd_blockfunc_type
* const lcd_blockfuncs
[8];
405 #endif /* LCD_DEPTH */
407 extern void lcd_drawpixel(int x
, int y
);
408 extern void lcd_drawline(int x1
, int y1
, int x2
, int y2
);
409 extern void lcd_hline(int x1
, int x2
, int y
);
410 extern void lcd_vline(int x
, int y1
, int y2
);
411 extern void lcd_drawrect(int x
, int y
, int width
, int height
);
412 extern void lcd_fillrect(int x
, int y
, int width
, int height
);
413 extern void lcd_bitmap_part(const fb_data
*src
, int src_x
, int src_y
,
414 int stride
, int x
, int y
, int width
, int height
);
415 extern void lcd_bitmap(const fb_data
*src
, int x
, int y
, int width
,
418 extern void lcd_scroll_step(int pixels
);
421 extern void lcd_set_foreground(unsigned foreground
);
422 extern unsigned lcd_get_foreground(void);
423 extern void lcd_set_background(unsigned background
);
424 extern unsigned lcd_get_background(void);
425 #ifdef HAVE_LCD_COLOR
426 extern void lcd_set_selector_start(unsigned selector
);
427 extern void lcd_set_selector_end(unsigned selector
);
428 extern void lcd_set_selector_text(unsigned selector_text
);
430 extern void lcd_set_drawinfo(int mode
, unsigned foreground
,
431 unsigned background
);
432 void lcd_set_backdrop(fb_data
* backdrop
);
434 fb_data
* lcd_get_backdrop(void);
436 extern void lcd_mono_bitmap_part(const unsigned char *src
, int src_x
, int src_y
,
437 int stride
, int x
, int y
, int width
, int height
);
438 extern void lcd_mono_bitmap(const unsigned char *src
, int x
, int y
, int width
,
440 extern void lcd_bitmap_transparent_part(const fb_data
*src
,
441 int src_x
, int src_y
,
442 int stride
, int x
, int y
, int width
,
444 extern void lcd_bitmap_transparent(const fb_data
*src
, int x
, int y
,
445 int width
, int height
);
446 #else /* LCD_DEPTH == 1 */
447 #define lcd_mono_bitmap lcd_bitmap
448 #define lcd_mono_bitmap_part lcd_bitmap_part
449 #endif /* LCD_DEPTH */
451 #endif /* HAVE_LCD_BITMAP */
453 #endif /* __LCD_H__ */