Fix FS#7044 - if the color RGB(0,255,255) is in a bmp it will be replaced with the...
[Rockbox.git] / firmware / export / lcd.h
blobd379dc36135b5002c235bb5e0c6650621b8c2021
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 #define STYLE_DEFAULT 0x00000000
28 #define STYLE_INVERT 0x20000000
29 #define STYLE_COLORED 0x10000000
30 #define STYLE_COLOR_MASK 0x0000FFFF
32 #ifdef SIMULATOR
33 #ifndef MAX_PATH
34 #define MAX_PATH 260
35 #endif
36 #else
37 #include "file.h" /* for MAX_PATH; FIXME: Why does this not work for sims? */
38 #endif
40 #if LCD_DEPTH <=8
41 typedef unsigned char fb_data;
42 #elif LCD_DEPTH <= 16
43 typedef unsigned short fb_data;
44 #else
45 typedef unsigned long fb_data;
46 #endif
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);
54 #ifdef SIMULATOR
55 /* Define a dummy device specific init for the sims */
56 #define lcd_init_device()
57 #else
58 extern void lcd_init_device(void);
59 #endif
60 extern void lcd_backlight(bool on);
61 extern int lcd_default_contrast(void);
62 extern void lcd_set_contrast(int val);
63 extern void lcd_setmargins(int xmargin, int ymargin);
64 extern int lcd_getxmargin(void);
65 extern int lcd_getymargin(void);
66 extern int lcd_getstringsize(const unsigned char *str, int *w, int *h);
68 extern void lcd_update(void);
69 extern void lcd_clear_display(void);
70 extern void lcd_putsxy(int x, int y, const unsigned char *string);
71 extern void lcd_puts(int x, int y, const unsigned char *string);
72 extern void lcd_puts_style(int x, int y, const unsigned char *string, int style);
73 extern void lcd_puts_offset(int x, int y, const unsigned char *str, int offset);
74 extern void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
75 int offset);
76 extern void lcd_putc(int x, int y, unsigned long ucs);
77 extern void lcd_stop_scroll(void);
78 extern void lcd_bidir_scroll(int threshold);
79 extern void lcd_scroll_speed(int speed);
80 extern void lcd_scroll_delay(int ms);
81 extern void lcd_puts_scroll(int x, int y, const unsigned char* string);
82 extern void lcd_puts_scroll_style(int x, int y, const unsigned char* string,
83 int style);
85 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
86 extern void lcd_yuv_blit(unsigned char * const src[3],
87 int src_x, int src_y, int stride,
88 int x, int y, int width, int height);
89 #endif
91 #ifdef HAVE_LCD_BITMAP
92 /* performance function */
93 extern void lcd_blit(const fb_data* data, int x, int by, int width,
94 int bheight, int stride);
96 /* update a fraction of the screen */
97 extern void lcd_update_rect(int x, int y, int width, int height);
99 #ifdef HAVE_REMOTE_LCD
100 extern void lcd_remote_update(void);
101 /* update a fraction of the screen */
102 extern void lcd_remote_update_rect(int x, int y, int width, int height);
103 #endif
104 #endif
106 #ifdef HAVE_LCD_CHARCELLS
108 /* Icon definitions for lcd_icon() */
109 enum
111 ICON_BATTERY = 0,
112 ICON_BATTERY_1,
113 ICON_BATTERY_2,
114 ICON_BATTERY_3,
115 ICON_USB,
116 ICON_PLAY,
117 ICON_RECORD,
118 ICON_PAUSE,
119 ICON_AUDIO,
120 ICON_REPEAT,
121 ICON_1,
122 ICON_VOLUME,
123 ICON_VOLUME_1,
124 ICON_VOLUME_2,
125 ICON_VOLUME_3,
126 ICON_VOLUME_4,
127 ICON_VOLUME_5,
128 ICON_PARAM
131 void lcd_icon(int icon, bool enable);
132 void lcd_double_height(bool on);
133 void lcd_define_pattern(unsigned long ucs, const char *pattern);
134 unsigned long lcd_get_locked_pattern(void);
135 void lcd_unlock_pattern(unsigned long ucs);
136 void lcd_put_cursor(int x, int y, unsigned long cursor_ucs);
137 void lcd_remove_cursor(void);
138 #define JUMP_SCROLL_ALWAYS 5
139 extern void lcd_jump_scroll(int mode); /* 0=off, 1=once, ..., ALWAYS */
140 extern void lcd_jump_scroll_delay(int ms);
141 #endif
143 /* Draw modes */
144 #define DRMODE_COMPLEMENT 0
145 #define DRMODE_BG 1
146 #define DRMODE_FG 2
147 #define DRMODE_SOLID 3
148 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
150 /* Low-level drawing function types */
151 typedef void lcd_pixelfunc_type(int x, int y);
152 typedef void lcd_blockfunc_type(fb_data *address, unsigned mask, unsigned bits);
153 #if LCD_DEPTH >= 8
154 typedef void lcd_fastpixelfunc_type(fb_data *address);
155 #endif
157 #ifdef HAVE_LCD_BITMAP
159 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
160 LCD_REMOTE_DEPTH > 1
161 /* Just return color for screens use */
162 static inline unsigned lcd_color_to_native(unsigned color)
163 { return color; }
164 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
165 #else
166 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
167 #endif
169 #ifdef HAVE_LCD_COLOR
170 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
171 #define LCD_MAX_RED 31
172 #define LCD_MAX_GREEN 63
173 #define LCD_MAX_BLUE 31
174 #define LCD_RED_BITS 5
175 #define LCD_GREEN_BITS 6
176 #define LCD_BLUE_BITS 5
178 /* pack/unpack native RGB values */
179 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
180 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
181 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
182 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
184 /* pack/unpack 24-bit RGB values */
185 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
186 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 11) & 0x07) )
187 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 5) & 0x03) )
188 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) ) & 0x07) )
190 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
191 /* RGB3553 */
192 #define _LCD_UNSWAP_COLOR(x) swap16(x)
193 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
194 (((g) >> 3) ) | \
195 (((g) & 0x07) << 13) | \
196 (((b) << 8) ) )
197 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
198 (((g) >> 5) ) | \
199 (((g) & 0x1c) << 11) | \
200 (((b) >> 3) << 8) )
201 /* swap color once - not currenly used in static inits */
202 #define _SWAPUNPACK(x, _unp_) \
203 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
204 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
205 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
206 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
207 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
208 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
209 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
210 #else
211 /* RGB565 */
212 #define _LCD_UNSWAP_COLOR(x) (x)
213 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
214 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
215 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
216 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
217 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
218 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
219 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
220 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
221 #endif
222 #else
223 /* other colour depths */
224 #endif
226 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
227 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
228 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
229 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
230 #define LCD_DEFAULT_FG LCD_BLACK
231 #define LCD_DEFAULT_BG LCD_RGBPACK(182, 198, 229) /* rockbox blue */
233 #elif LCD_DEPTH > 1 /* greyscale */
234 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
235 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
237 #define LCD_BLACK LCD_BRIGHTNESS(0)
238 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
239 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
240 #define LCD_WHITE LCD_BRIGHTNESS(255)
241 #define LCD_DEFAULT_FG LCD_BLACK
242 #define LCD_DEFAULT_BG LCD_WHITE
243 #endif
245 /* Frame buffer dimensions */
246 #if LCD_DEPTH == 1
247 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
248 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
249 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
250 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
251 #endif
252 #elif LCD_DEPTH == 2
253 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
254 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
255 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
256 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
257 #endif
258 #endif /* LCD_DEPTH */
259 /* Set defaults if not defined different yet. The defaults apply to both
260 * dimensions for LCD_DEPTH >= 8 */
261 #ifndef LCD_FBWIDTH
262 #define LCD_FBWIDTH LCD_WIDTH
263 #endif
264 #ifndef LCD_FBHEIGHT
265 #define LCD_FBHEIGHT LCD_HEIGHT
266 #endif
267 /* The actual framebuffer */
268 extern fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH];
270 /** Port-specific functions. Enable in port config file. **/
271 #ifdef HAVE_LCD_ENABLE
272 /* Enable/disable the main display. */
273 extern void lcd_enable(bool on);
274 #endif
276 #ifdef HAVE_LCD_SLEEP
277 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
278 extern void lcd_sleep(void);
279 #endif
281 /* Bitmap formats */
282 enum
284 FORMAT_MONO,
285 FORMAT_NATIVE,
286 FORMAT_ANY /* For passing to read_bmp_file() */
289 #define FORMAT_TRANSPARENT 0x40000000
290 #define FORMAT_DITHER 0x20000000
291 #define FORMAT_REMOTE 0x10000000
293 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
294 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
296 struct bitmap {
297 int width;
298 int height;
299 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
300 int format;
301 unsigned char *maskdata;
302 #endif
303 unsigned char *data;
306 extern void lcd_set_invert_display(bool yesno);
307 extern void lcd_set_flip(bool yesno);
309 extern void lcd_set_drawmode(int mode);
310 extern int lcd_get_drawmode(void);
311 extern void lcd_setfont(int font);
313 extern void lcd_puts_style_offset(int x, int y, const unsigned char *str,
314 int style, int offset);
315 extern void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
316 int style, int offset);
318 /* low level drawing function pointer arrays */
319 #if LCD_DEPTH >= 8
320 extern lcd_fastpixelfunc_type* const *lcd_fastpixelfuncs;
321 #elif LCD_DEPTH > 1
322 extern lcd_pixelfunc_type* const *lcd_pixelfuncs;
323 extern lcd_blockfunc_type* const *lcd_blockfuncs;
324 #else
325 extern lcd_pixelfunc_type* const lcd_pixelfuncs[8];
326 extern lcd_blockfunc_type* const lcd_blockfuncs[8];
327 #endif
329 extern void lcd_drawpixel(int x, int y);
330 extern void lcd_drawline(int x1, int y1, int x2, int y2);
331 extern void lcd_hline(int x1, int x2, int y);
332 extern void lcd_vline(int x, int y1, int y2);
333 extern void lcd_drawrect(int x, int y, int width, int height);
334 extern void lcd_fillrect(int x, int y, int width, int height);
335 extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
336 int stride, int x, int y, int width, int height);
337 extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
338 int height);
340 extern void lcd_invertscroll(int x, int y);
341 extern void lcd_scroll_step(int pixels);
343 #if LCD_DEPTH > 1
344 extern void lcd_set_foreground(unsigned foreground);
345 extern unsigned lcd_get_foreground(void);
346 extern void lcd_set_background(unsigned background);
347 extern unsigned lcd_get_background(void);
348 extern void lcd_set_drawinfo(int mode, unsigned foreground,
349 unsigned background);
350 void lcd_set_backdrop(fb_data* backdrop);
351 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
352 bool lcd_enabled(void);
353 #else
354 #define lcd_enabled() true
355 #endif
357 fb_data* lcd_get_backdrop(void);
359 extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
360 int stride, int x, int y, int width, int height);
361 extern void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width,
362 int height);
363 extern void lcd_bitmap_transparent_part(const fb_data *src,
364 int src_x, int src_y,
365 int stride, int x, int y, int width,
366 int height);
367 extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
368 int width, int height);
369 #else /* LCD_DEPTH == 1 */
370 #define lcd_mono_bitmap lcd_bitmap
371 #define lcd_mono_bitmap_part lcd_bitmap_part
372 #endif
374 #endif /* HAVE_LCD_BITMAP */
376 /* internal usage, but in multiple drivers */
377 #define SCROLL_SPACING 3
378 #ifdef HAVE_LCD_BITMAP
379 #define SCROLL_LINE_SIZE (MAX_PATH + SCROLL_SPACING + 3*LCD_WIDTH/2 + 2)
380 #else
381 #define SCROLL_LINE_SIZE (MAX_PATH + SCROLL_SPACING + 3*LCD_WIDTH + 2)
382 #endif
384 struct scrollinfo {
385 char line[SCROLL_LINE_SIZE];
386 int len; /* length of line in chars */
387 int offset;
388 int startx;
389 #ifdef HAVE_LCD_BITMAP
390 int width; /* length of line in pixels */
391 bool invert; /* invert the scrolled text */
392 #endif
393 bool backward; /* scroll presently forward or backward? */
394 bool bidir;
395 long start_tick;
396 #ifdef HAVE_LCD_COLOR
397 int line_colour;
398 #endif
401 #endif /* __LCD_H__ */