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 ****************************************************************************/
27 #define STYLE_DEFAULT 0x00000000
28 #define STYLE_INVERT 0x20000000
29 #define STYLE_COLORED 0x10000000
30 #define STYLE_COLOR_MASK 0x0000FFFF
37 #include "file.h" /* for MAX_PATH; FIXME: Why does this not work for sims? */
38 #endif /* SIMULATOR */
41 typedef unsigned char fb_data
;
43 typedef unsigned short fb_data
;
44 #else /* LCD_DEPTH > 16 */
45 typedef unsigned long fb_data
;
46 #endif /* LCD_DEPTH */
48 /* common functions */
49 extern void lcd_write_command(int byte
);
50 extern void lcd_write_command_e(int cmd
, int data
);
51 extern void lcd_write_command_ex(int cmd
, int data1
, int data2
);
52 extern void lcd_write_data(const fb_data
* p_bytes
, int count
);
53 extern void lcd_init(void);
56 /* Define a dummy device specific init for the sims */
57 #define lcd_init_device()
59 extern void lcd_init_device(void);
60 #endif /* SIMULATOR */
62 extern void lcd_backlight(bool on
);
63 extern int lcd_default_contrast(void);
64 extern void lcd_set_contrast(int val
);
65 extern void lcd_setmargins(int xmargin
, int ymargin
);
66 extern int lcd_getxmargin(void);
67 extern int lcd_getymargin(void);
68 extern int lcd_getstringsize(const unsigned char *str
, int *w
, int *h
);
70 extern void lcd_update(void);
71 extern void lcd_clear_display(void);
72 extern void lcd_putsxy(int x
, int y
, const unsigned char *string
);
73 extern void lcd_puts(int x
, int y
, const unsigned char *string
);
74 extern void lcd_puts_style(int x
, int y
, const unsigned char *string
, int style
);
75 extern void lcd_puts_offset(int x
, int y
, const unsigned char *str
, int offset
);
76 extern void lcd_puts_scroll_offset(int x
, int y
, const unsigned char *string
,
78 extern void lcd_putc(int x
, int y
, unsigned long ucs
);
79 extern void lcd_stop_scroll(void);
80 extern void lcd_bidir_scroll(int threshold
);
81 extern void lcd_scroll_speed(int speed
);
82 extern void lcd_scroll_delay(int ms
);
83 extern void lcd_puts_scroll(int x
, int y
, const unsigned char* string
);
84 extern void lcd_puts_scroll_style(int x
, int y
, const unsigned char* string
,
87 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
88 extern void lcd_yuv_blit(unsigned char * const src
[3],
89 int src_x
, int src_y
, int stride
,
90 int x
, int y
, int width
, int height
);
93 #ifdef HAVE_LCD_BITMAP
94 /* performance function */
95 extern void lcd_blit(const fb_data
* data
, int x
, int by
, int width
,
96 int bheight
, int stride
);
98 /* update a fraction of the screen */
99 extern void lcd_update_rect(int x
, int y
, int width
, int height
);
101 #ifdef HAVE_REMOTE_LCD
102 extern void lcd_remote_update(void);
103 /* update a fraction of the screen */
104 extern void lcd_remote_update_rect(int x
, int y
, int width
, int height
);
105 #endif /* HAVE_REMOTE_LCD */
106 #endif /* HAVE_LCD_BITMAP */
108 #ifdef HAVE_LCD_CHARCELLS
110 /* Icon definitions for lcd_icon() */
133 void lcd_icon(int icon
, bool enable
);
134 void lcd_double_height(bool on
);
135 void lcd_define_pattern(unsigned long ucs
, const char *pattern
);
136 unsigned long lcd_get_locked_pattern(void);
137 void lcd_unlock_pattern(unsigned long ucs
);
138 void lcd_put_cursor(int x
, int y
, unsigned long cursor_ucs
);
139 void lcd_remove_cursor(void);
140 #define JUMP_SCROLL_ALWAYS 5
141 extern void lcd_jump_scroll(int mode
); /* 0=off, 1=once, ..., ALWAYS */
142 extern void lcd_jump_scroll_delay(int ms
);
143 #endif /* HAVE_LCD_CHARCELLS */
146 #define DRMODE_COMPLEMENT 0
149 #define DRMODE_SOLID 3
150 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
152 /* Low-level drawing function types */
153 typedef void lcd_pixelfunc_type(int x
, int y
);
154 typedef void lcd_blockfunc_type(fb_data
*address
, unsigned mask
, unsigned bits
);
156 typedef void lcd_fastpixelfunc_type(fb_data
*address
);
159 #ifdef HAVE_LCD_BITMAP
161 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
163 /* Just return color for screens use */
164 static inline unsigned lcd_color_to_native(unsigned color
)
166 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
168 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
171 #ifdef HAVE_LCD_COLOR
172 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
173 #define LCD_MAX_RED 31
174 #define LCD_MAX_GREEN 63
175 #define LCD_MAX_BLUE 31
176 #define LCD_RED_BITS 5
177 #define LCD_GREEN_BITS 6
178 #define LCD_BLUE_BITS 5
180 /* pack/unpack native RGB values */
181 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
182 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
183 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
184 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
186 /* pack/unpack 24-bit RGB values */
187 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
188 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 11) & 0x07) )
189 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 5) & 0x03) )
190 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) ) & 0x07) )
192 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
194 #define _LCD_UNSWAP_COLOR(x) swap16(x)
195 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
197 (((g) & 0x07) << 13) | \
199 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
201 (((g) & 0x1c) << 11) | \
203 /* swap color once - not currenly used in static inits */
204 #define _SWAPUNPACK(x, _unp_) \
205 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
206 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
207 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
208 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
209 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
210 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
211 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
212 #else /* LCD_PIXELFORMAT == RGB565 */
214 #define _LCD_UNSWAP_COLOR(x) (x)
215 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
216 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
217 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
218 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
219 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
220 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
221 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
222 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
225 /* other colour depths */
228 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
229 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
230 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
231 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
232 #define LCD_DEFAULT_FG LCD_BLACK
233 #define LCD_DEFAULT_BG LCD_RGBPACK(182, 198, 229) /* rockbox blue */
235 #elif LCD_DEPTH > 1 /* greyscale */
237 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
238 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
240 #define LCD_BLACK LCD_BRIGHTNESS(0)
241 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
242 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
243 #define LCD_WHITE LCD_BRIGHTNESS(255)
244 #define LCD_DEFAULT_FG LCD_BLACK
245 #define LCD_DEFAULT_BG LCD_WHITE
247 #endif /* HAVE_LCD_COLOR */
249 /* Frame buffer dimensions */
251 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
252 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
253 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
254 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
255 #endif /* LCD_PIXELFORMAT */
257 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
258 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
259 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
260 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
261 #endif /* LCD_PIXELFORMAT */
262 #endif /* LCD_DEPTH */
263 /* Set defaults if not defined different yet. The defaults apply to both
264 * dimensions for LCD_DEPTH >= 8 */
266 #define LCD_FBWIDTH LCD_WIDTH
269 #define LCD_FBHEIGHT LCD_HEIGHT
271 /* The actual framebuffer */
272 extern fb_data lcd_framebuffer
[LCD_FBHEIGHT
][LCD_FBWIDTH
];
274 /** Port-specific functions. Enable in port config file. **/
275 #ifdef HAVE_LCD_ENABLE
276 /* Enable/disable the main display. */
277 extern void lcd_enable(bool on
);
278 extern bool lcd_enabled(void);
279 #endif /* HAVE_LCD_ENABLE */
281 #ifdef HAVE_LCD_SLEEP
282 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
283 extern void lcd_sleep(void);
284 #endif /* HAVE_LCD_SLEEP */
291 FORMAT_ANY
/* For passing to read_bmp_file() */
294 #define FORMAT_TRANSPARENT 0x40000000
295 #define FORMAT_DITHER 0x20000000
296 #define FORMAT_REMOTE 0x10000000
298 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
299 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
304 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
306 unsigned char *maskdata
;
311 extern void lcd_set_invert_display(bool yesno
);
312 #ifdef HAVE_BACKLIGHT_INVERSION
313 extern void lcd_set_backlight_inversion(bool yesno
);
314 #endif /* HAVE_BACKLIGHT_INVERSION */
315 extern void lcd_set_flip(bool yesno
);
317 extern void lcd_set_drawmode(int mode
);
318 extern int lcd_get_drawmode(void);
319 extern void lcd_setfont(int font
);
321 extern void lcd_puts_style_offset(int x
, int y
, const unsigned char *str
,
322 int style
, int offset
);
323 extern void lcd_puts_scroll_style_offset(int x
, int y
, const unsigned char *string
,
324 int style
, int offset
);
326 /* low level drawing function pointer arrays */
328 extern lcd_fastpixelfunc_type
* const *lcd_fastpixelfuncs
;
330 extern lcd_pixelfunc_type
* const *lcd_pixelfuncs
;
331 extern lcd_blockfunc_type
* const *lcd_blockfuncs
;
332 #else /* LCD_DEPTH == 1*/
333 extern lcd_pixelfunc_type
* const lcd_pixelfuncs
[8];
334 extern lcd_blockfunc_type
* const lcd_blockfuncs
[8];
335 #endif /* LCD_DEPTH */
337 extern void lcd_drawpixel(int x
, int y
);
338 extern void lcd_drawline(int x1
, int y1
, int x2
, int y2
);
339 extern void lcd_hline(int x1
, int x2
, int y
);
340 extern void lcd_vline(int x
, int y1
, int y2
);
341 extern void lcd_drawrect(int x
, int y
, int width
, int height
);
342 extern void lcd_fillrect(int x
, int y
, int width
, int height
);
343 extern void lcd_bitmap_part(const fb_data
*src
, int src_x
, int src_y
,
344 int stride
, int x
, int y
, int width
, int height
);
345 extern void lcd_bitmap(const fb_data
*src
, int x
, int y
, int width
,
348 extern void lcd_invertscroll(int x
, int y
);
349 extern void lcd_scroll_step(int pixels
);
352 extern void lcd_set_foreground(unsigned foreground
);
353 extern unsigned lcd_get_foreground(void);
354 extern void lcd_set_background(unsigned background
);
355 extern unsigned lcd_get_background(void);
356 extern void lcd_set_drawinfo(int mode
, unsigned foreground
,
357 unsigned background
);
358 void lcd_set_backdrop(fb_data
* backdrop
);
360 fb_data
* lcd_get_backdrop(void);
362 extern void lcd_mono_bitmap_part(const unsigned char *src
, int src_x
, int src_y
,
363 int stride
, int x
, int y
, int width
, int height
);
364 extern void lcd_mono_bitmap(const unsigned char *src
, int x
, int y
, int width
,
366 extern void lcd_bitmap_transparent_part(const fb_data
*src
,
367 int src_x
, int src_y
,
368 int stride
, int x
, int y
, int width
,
370 extern void lcd_bitmap_transparent(const fb_data
*src
, int x
, int y
,
371 int width
, int height
);
372 #else /* LCD_DEPTH == 1 */
373 #define lcd_mono_bitmap lcd_bitmap
374 #define lcd_mono_bitmap_part lcd_bitmap_part
375 #endif /* LCD_DEPTH */
377 #endif /* HAVE_LCD_BITMAP */
379 #endif /* __LCD_H__ */