Make the greylib text output functions handle unicode. Fixes non-working umlauts...
[kugel-rb.git] / apps / plugin.h
blob81c069666ac98006180ccc4e01dafa191c235bf5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
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 ****************************************************************************/
21 #ifndef _PLUGIN_H_
22 #define _PLUGIN_H_
24 /* instruct simulator code to not redefine any symbols when compiling plugins.
25 (the PLUGIN macro is defined in apps/plugins/Makefile) */
26 #ifdef PLUGIN
27 #define NO_REDEFINES_PLEASE
28 #endif
30 #ifndef MEM
31 #define MEM 2
32 #endif
34 #include <stdbool.h>
35 #include <sys/types.h>
36 #include <stdarg.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
41 void* plugin_get_buffer(size_t *buffer_size);
43 #ifndef __PCTOOL__
44 #include "config.h"
45 #include "system.h"
46 #include "dir.h"
47 #include "general.h"
48 #include "kernel.h"
49 #include "thread.h"
50 #include "button.h"
51 #include "action.h"
52 #include "usb.h"
53 #include "font.h"
54 #include "lcd.h"
55 #include "metadata.h"
56 #include "sound.h"
57 #include "mpeg.h"
58 #include "audio.h"
59 #include "mp3_playback.h"
60 #include "talk.h"
61 #ifdef RB_PROFILE
62 #include "profile.h"
63 #endif
64 #include "misc.h"
65 #if (CONFIG_CODEC == SWCODEC)
66 #include "dsp.h"
67 #include "codecs.h"
68 #include "playback.h"
69 #include "metadata.h"
70 #ifdef HAVE_RECORDING
71 #include "recording.h"
72 #endif
73 #else
74 #include "mas.h"
75 #endif /* CONFIG_CODEC == SWCODEC */
76 #include "settings.h"
77 #include "timer.h"
78 #include "playlist.h"
79 #ifdef HAVE_LCD_BITMAP
80 #include "scrollbar.h"
81 #include "../recorder/bmp.h"
82 #endif
83 #include "statusbar.h"
84 #include "menu.h"
85 #include "rbunicode.h"
86 #include "list.h"
87 #include "tree.h"
88 #include "color_picker.h"
89 #include "buffering.h"
90 #include "tagcache.h"
91 #include "viewport.h"
92 #include "ata_idle_notify.h"
93 #include "settings_list.h"
95 #ifdef HAVE_ALBUMART
96 #include "albumart.h"
97 #endif
99 #ifdef HAVE_REMOTE_LCD
100 #include "lcd-remote.h"
101 #endif
103 #include "yesno.h"
105 #ifdef PLUGIN
107 #if defined(DEBUG) || defined(SIMULATOR)
108 #undef DEBUGF
109 #define DEBUGF rb->debugf
110 #undef LDEBUGF
111 #define LDEBUGF rb->debugf
112 #else
113 #define DEBUGF(...)
114 #define LDEBUGF(...)
115 #endif
117 #ifdef ROCKBOX_HAS_LOGF
118 #undef LOGF
119 #define LOGF rb->logf
120 #else
121 #define LOGF(...)
122 #endif
124 #endif
126 #ifdef SIMULATOR
127 #define PREFIX(_x_) sim_ ## _x_
128 #else
129 #define PREFIX(_x_) _x_
130 #endif
132 #define PLUGIN_MAGIC 0x526F634B /* RocK */
134 /* increase this every time the api struct changes */
135 #define PLUGIN_API_VERSION 131
137 /* update this to latest version if a change to the api struct breaks
138 backwards compatibility (and please take the opportunity to sort in any
139 new function which are "waiting" at the end of the function table) */
140 #define PLUGIN_MIN_API_VERSION 131
142 /* plugin return codes */
143 enum plugin_status {
144 PLUGIN_OK = 0,
145 PLUGIN_USB_CONNECTED,
146 PLUGIN_ERROR = -1,
149 /* NOTE: To support backwards compatibility, only add new functions at
150 the end of the structure. Every time you add a new function,
151 remember to increase PLUGIN_API_VERSION. If you make changes to the
152 existing APIs then also update PLUGIN_MIN_API_VERSION to current
153 version
155 struct plugin_api {
157 /* lcd */
158 void (*lcd_set_contrast)(int x);
159 void (*lcd_update)(void);
160 void (*lcd_clear_display)(void);
161 int (*lcd_getstringsize)(const unsigned char *str, int *w, int *h);
162 void (*lcd_putsxy)(int x, int y, const unsigned char *string);
163 void (*lcd_puts)(int x, int y, const unsigned char *string);
164 void (*lcd_puts_scroll)(int x, int y, const unsigned char* string);
165 void (*lcd_stop_scroll)(void);
166 #ifdef HAVE_LCD_CHARCELLS
167 void (*lcd_define_pattern)(unsigned long ucs, const char *pattern);
168 unsigned long (*lcd_get_locked_pattern)(void);
169 void (*lcd_unlock_pattern)(unsigned long ucs);
170 void (*lcd_putc)(int x, int y, unsigned long ucs);
171 void (*lcd_put_cursor)(int x, int y, unsigned long ucs);
172 void (*lcd_remove_cursor)(void);
173 void (*lcd_icon)(int icon, bool enable);
174 void (*lcd_double_height)(bool on);
175 #else /* HAVE_LCD_BITMAP */
176 fb_data* lcd_framebuffer;
177 void (*lcd_update_rect)(int x, int y, int width, int height);
178 void (*lcd_set_drawmode)(int mode);
179 int (*lcd_get_drawmode)(void);
180 void (*lcd_setfont)(int font);
181 void (*lcd_drawpixel)(int x, int y);
182 void (*lcd_drawline)(int x1, int y1, int x2, int y2);
183 void (*lcd_hline)(int x1, int x2, int y);
184 void (*lcd_vline)(int x, int y1, int y2);
185 void (*lcd_drawrect)(int x, int y, int width, int height);
186 void (*lcd_fillrect)(int x, int y, int width, int height);
187 void (*lcd_mono_bitmap_part)(const unsigned char *src, int src_x, int src_y,
188 int stride, int x, int y, int width, int height);
189 void (*lcd_mono_bitmap)(const unsigned char *src, int x, int y,
190 int width, int height);
191 #if LCD_DEPTH > 1
192 void (*lcd_set_foreground)(unsigned foreground);
193 unsigned (*lcd_get_foreground)(void);
194 void (*lcd_set_background)(unsigned foreground);
195 unsigned (*lcd_get_background)(void);
196 void (*lcd_bitmap_part)(const fb_data *src, int src_x, int src_y,
197 int stride, int x, int y, int width, int height);
198 void (*lcd_bitmap)(const fb_data *src, int x, int y, int width,
199 int height);
200 fb_data* (*lcd_get_backdrop)(void);
201 void (*lcd_set_backdrop)(fb_data* backdrop);
202 #endif
203 #if LCD_DEPTH == 16
204 void (*lcd_bitmap_transparent_part)(const fb_data *src,
205 int src_x, int src_y, int stride,
206 int x, int y, int width, int height);
207 void (*lcd_bitmap_transparent)(const fb_data *src, int x, int y,
208 int width, int height);
209 void (*lcd_blit_yuv)(unsigned char * const src[3],
210 int src_x, int src_y, int stride,
211 int x, int y, int width, int height);
212 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
213 || defined(IRIVER_H10) || defined(COWON_D2)
214 void (*lcd_yuv_set_options)(unsigned options);
215 #endif
216 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
217 void (*lcd_blit_mono)(const unsigned char *data, int x, int by, int width,
218 int bheight, int stride);
219 void (*lcd_blit_grey_phase)(unsigned char *values, unsigned char *phases,
220 int bx, int by, int bwidth, int bheight,
221 int stride);
222 #endif /* LCD_DEPTH */
223 void (*lcd_puts_style)(int x, int y, const unsigned char *str, int style);
224 void (*lcd_puts_scroll_style)(int x, int y, const unsigned char* string,
225 int style);
226 #ifdef HAVE_LCD_INVERT
227 void (*lcd_set_invert_display)(bool yesno);
228 #endif /* HAVE_LCD_INVERT */
230 #if defined(HAVE_LCD_ENABLE) && defined(HAVE_LCD_COLOR)
231 void (*lcd_set_enable_hook)(void (*enable_hook)(void));
232 struct event_queue *button_queue;
233 #endif
234 unsigned short *(*bidi_l2v)( const unsigned char *str, int orientation );
235 const unsigned char *(*font_get_bits)( struct font *pf, unsigned short char_code );
236 struct font* (*font_load)(const char *path);
237 struct font* (*font_get)(int font);
238 int (*font_getstringsize)(const unsigned char *str, int *w, int *h,
239 int fontnumber);
240 int (*font_get_width)(struct font* pf, unsigned short char_code);
241 void (*screen_clear_area)(struct screen * display, int xstart, int ystart,
242 int width, int height);
243 void (*gui_scrollbar_draw)(struct screen * screen, int x, int y,
244 int width, int height, int items,
245 int min_shown, int max_shown,
246 unsigned flags);
247 #endif /* HAVE_LCD_BITMAP */
248 const char* (*get_codepage_name)(int cp);
250 /* backlight */
251 /* The backlight_* functions must be present in the API regardless whether
252 * HAVE_BACKLIGHT is defined or not. The reason is that the stock Ondio has
253 * no backlight but can be modded to have backlight (it's prepared on the
254 * PCB). This makes backlight an all-target feature API wise, and keeps API
255 * compatible between stock and modded Ondio.
256 * For OLED targets like the Sansa Clip, the backlight_* functions control
257 * the display enable, which has essentially the same effect. */
258 void (*backlight_on)(void);
259 void (*backlight_off)(void);
260 void (*backlight_set_timeout)(int index);
261 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
262 void (*backlight_set_brightness)(int val);
263 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
265 #if CONFIG_CHARGING
266 void (*backlight_set_timeout_plugged)(int index);
267 #endif
268 bool (*is_backlight_on)(bool ignore_always_off);
269 void (*splash)(int ticks, const char *str);
270 void (*splashf)(int ticks, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
272 #ifdef HAVE_REMOTE_LCD
273 /* remote lcd */
274 void (*lcd_remote_set_contrast)(int x);
275 void (*lcd_remote_clear_display)(void);
276 void (*lcd_remote_puts)(int x, int y, const unsigned char *string);
277 void (*lcd_remote_puts_scroll)(int x, int y, const unsigned char* string);
278 void (*lcd_remote_stop_scroll)(void);
279 void (*lcd_remote_set_drawmode)(int mode);
280 int (*lcd_remote_get_drawmode)(void);
281 void (*lcd_remote_setfont)(int font);
282 int (*lcd_remote_getstringsize)(const unsigned char *str, int *w, int *h);
283 void (*lcd_remote_drawpixel)(int x, int y);
284 void (*lcd_remote_drawline)(int x1, int y1, int x2, int y2);
285 void (*lcd_remote_hline)(int x1, int x2, int y);
286 void (*lcd_remote_vline)(int x, int y1, int y2);
287 void (*lcd_remote_drawrect)(int x, int y, int nx, int ny);
288 void (*lcd_remote_fillrect)(int x, int y, int nx, int ny);
289 void (*lcd_remote_mono_bitmap_part)(const unsigned char *src, int src_x,
290 int src_y, int stride, int x, int y,
291 int width, int height);
292 void (*lcd_remote_mono_bitmap)(const unsigned char *src, int x, int y,
293 int width, int height);
294 void (*lcd_remote_putsxy)(int x, int y, const unsigned char *string);
295 void (*lcd_remote_puts_style)(int x, int y, const unsigned char *str, int style);
296 void (*lcd_remote_puts_scroll_style)(int x, int y, const unsigned char* string,
297 int style);
298 fb_remote_data* lcd_remote_framebuffer;
299 void (*lcd_remote_update)(void);
300 void (*lcd_remote_update_rect)(int x, int y, int width, int height);
302 void (*remote_backlight_on)(void);
303 void (*remote_backlight_off)(void);
304 void (*remote_backlight_set_timeout)(int index);
305 #if CONFIG_CHARGING
306 void (*remote_backlight_set_timeout_plugged)(int index);
307 #endif
308 #endif /* HAVE_REMOTE_LCD */
309 struct screen* screens[NB_SCREENS];
310 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
311 void (*lcd_remote_set_foreground)(unsigned foreground);
312 unsigned (*lcd_remote_get_foreground)(void);
313 void (*lcd_remote_set_background)(unsigned background);
314 unsigned (*lcd_remote_get_background)(void);
315 void (*lcd_remote_bitmap_part)(const fb_remote_data *src, int src_x, int src_y,
316 int stride, int x, int y, int width, int height);
317 void (*lcd_remote_bitmap)(const fb_remote_data *src, int x, int y, int width,
318 int height);
319 #endif
320 void (*viewport_set_defaults)(struct viewport *vp, enum screen_type screen);
321 /* list */
322 void (*gui_synclist_init)(struct gui_synclist * lists,
323 list_get_name callback_get_item_name, void * data,
324 bool scroll_all,int selected_size,
325 struct viewport parent[NB_SCREENS]);
326 void (*gui_synclist_set_nb_items)(struct gui_synclist * lists, int nb_items);
327 void (*gui_synclist_set_icon_callback)(struct gui_synclist * lists, list_get_icon icon_callback);
328 int (*gui_synclist_get_nb_items)(struct gui_synclist * lists);
329 int (*gui_synclist_get_sel_pos)(struct gui_synclist * lists);
330 void (*gui_synclist_draw)(struct gui_synclist * lists);
331 void (*gui_synclist_select_item)(struct gui_synclist * lists,
332 int item_number);
333 void (*gui_synclist_add_item)(struct gui_synclist * lists);
334 void (*gui_synclist_del_item)(struct gui_synclist * lists);
335 void (*gui_synclist_limit_scroll)(struct gui_synclist * lists, bool scroll);
336 bool (*gui_synclist_do_button)(struct gui_synclist * lists,
337 unsigned *action, enum list_wrap wrap);
338 void (*gui_synclist_set_title)(struct gui_synclist *lists, char* title, int icon);
339 enum yesno_res (*gui_syncyesno_run)(const struct text_message * main_message,
340 const struct text_message * yes_message,
341 const struct text_message * no_message);
342 void (*simplelist_info_init)(struct simplelist_info *info, char* title,
343 int count, void* data);
344 bool (*simplelist_show_list)(struct simplelist_info *info);
346 /* button */
347 long (*button_get)(bool block);
348 long (*button_get_w_tmo)(int ticks);
349 int (*button_status)(void);
350 #ifdef HAVE_BUTTON_DATA
351 intptr_t (*button_get_data)(void);
352 #endif
353 void (*button_clear_queue)(void);
354 int (*button_queue_count)(void);
355 #ifdef HAS_BUTTON_HOLD
356 bool (*button_hold)(void);
357 #endif
358 #ifdef HAVE_TOUCHSCREEN
359 void (*touchscreen_set_mode)(enum touchscreen_mode);
360 #endif
361 #ifdef HAVE_BUTTON_LIGHT
362 void (*buttonlight_set_timeout)(int value);
363 void (*buttonlight_off)(void);
364 void (*buttonlight_on)(void);
365 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
366 void (*buttonlight_set_brightness)(int val);
367 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
368 #endif /* HAVE_BUTTON_LIGHT */
370 /* file */
371 int (*PREFIX(open))(const char* pathname, int flags);
372 int (*PREFIX(close))(int fd);
373 ssize_t (*PREFIX(read))(int fd, void* buf, size_t count);
374 off_t (*PREFIX(lseek))(int fd, off_t offset, int whence);
375 int (*PREFIX(creat))(const char *pathname);
376 ssize_t (*PREFIX(write))(int fd, const void* buf, size_t count);
377 int (*PREFIX(remove))(const char* pathname);
378 int (*PREFIX(rename))(const char* path, const char* newname);
379 int (*PREFIX(ftruncate))(int fd, off_t length);
380 off_t (*PREFIX(filesize))(int fd);
381 int (*fdprintf)(int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
382 int (*read_line)(int fd, char* buffer, int buffer_size);
383 bool (*settings_parseline)(char* line, char** name, char** value);
384 void (*storage_sleep)(void);
385 void (*storage_spin)(void);
386 void (*storage_spindown)(int seconds);
387 #if USING_STORAGE_CALLBACK
388 void (*register_storage_idle_func)(storage_idle_notify function);
389 void (*unregister_storage_idle_func)(storage_idle_notify function, bool run);
390 #endif /* USING_STORAGE_CALLBACK */
391 void (*reload_directory)(void);
392 char *(*create_numbered_filename)(char *buffer, const char *path,
393 const char *prefix, const char *suffix,
394 int numberlen IF_CNFN_NUM_(, int *num));
395 bool (*file_exists)(const char *file);
398 /* dir */
399 DIR* (*opendir)(const char* name);
400 int (*closedir)(DIR* dir);
401 struct dirent* (*readdir)(DIR* dir);
402 int (*mkdir)(const char *name);
403 int (*rmdir)(const char *name);
404 bool (*dir_exists)(const char *path);
406 /* kernel/ system */
407 void (*PREFIX(sleep))(int ticks);
408 void (*yield)(void);
409 volatile long* current_tick;
410 long (*default_event_handler)(long event);
411 long (*default_event_handler_ex)(long event, void (*callback)(void *), void *parameter);
412 struct thread_entry* threads;
413 unsigned int (*create_thread)(void (*function)(void), void* stack,
414 size_t stack_size, unsigned flags,
415 const char *name
416 IF_PRIO(, int priority)
417 IF_COP(, unsigned int core));
418 void (*thread_exit)(void);
419 void (*thread_wait)(unsigned int thread_id);
420 #if CONFIG_CODEC == SWCODEC
421 void (*mutex_init)(struct mutex *m);
422 void (*mutex_lock)(struct mutex *m);
423 void (*mutex_unlock)(struct mutex *m);
424 size_t (*align_buffer)(void **start, size_t size, size_t align);
425 #endif
427 void (*reset_poweroff_timer)(void);
428 #ifndef SIMULATOR
429 int (*system_memory_guard)(int newmode);
430 long *cpu_frequency;
431 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
432 #ifdef CPU_BOOST_LOGGING
433 void (*cpu_boost_)(bool on_off,char*location,int line);
434 #else
435 void (*cpu_boost)(bool on_off);
436 #endif
437 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
438 #endif /* !SIMULATOR */
439 #ifdef HAVE_SCHEDULER_BOOSTCTRL
440 void (*trigger_cpu_boost)(void);
441 void (*cancel_cpu_boost)(void);
442 #endif
443 #ifdef CACHE_FUNCTIONS_AS_CALL
444 void (*flush_icache)(void);
445 void (*invalidate_icache)(void);
446 #endif
447 bool (*timer_register)(int reg_prio, void (*unregister_callback)(void),
448 long cycles, int int_prio,
449 void (*timer_callback)(void) IF_COP(, int core));
450 void (*timer_unregister)(void);
451 bool (*timer_set_period)(long count);
453 void (*queue_init)(struct event_queue *q, bool register_queue);
454 void (*queue_delete)(struct event_queue *q);
455 void (*queue_post)(struct event_queue *q, long id, intptr_t data);
456 void (*queue_wait_w_tmo)(struct event_queue *q, struct queue_event *ev,
457 int ticks);
458 #if CONFIG_CODEC == SWCODEC
459 void (*queue_enable_queue_send)(struct event_queue *q,
460 struct queue_sender_list *send,
461 unsigned int thread_id);
462 bool (*queue_empty)(const struct event_queue *q);
463 void (*queue_wait)(struct event_queue *q, struct queue_event *ev);
464 intptr_t (*queue_send)(struct event_queue *q, long id,
465 intptr_t data);
466 void (*queue_reply)(struct event_queue *q, intptr_t retval);
467 #endif /* CONFIG_CODEC == SWCODEC */
469 void (*usb_acknowledge)(long id);
470 #ifdef RB_PROFILE
471 void (*profile_thread)(void);
472 void (*profstop)(void);
473 void (*profile_func_enter)(void *this_fn, void *call_site);
474 void (*profile_func_exit)(void *this_fn, void *call_site);
475 #endif
477 #ifdef SIMULATOR
478 /* special simulator hooks */
479 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
480 void (*sim_lcd_ex_init)(int shades, unsigned long (*getpixel)(int, int));
481 void (*sim_lcd_ex_update_rect)(int x, int y, int width, int height);
482 #endif
483 #endif
485 /* strings and memory */
486 int (*snprintf)(char *buf, size_t size, const char *fmt, ...)
487 ATTRIBUTE_PRINTF(3, 4);
488 int (*vsnprintf)(char *buf, int size, const char *fmt, va_list ap);
489 char* (*strcpy)(char *dst, const char *src);
490 char* (*strncpy)(char *dst, const char *src, size_t length);
491 size_t (*strlen)(const char *str);
492 char * (*strrchr)(const char *s, int c);
493 int (*strcmp)(const char *, const char *);
494 int (*strncmp)(const char *, const char *, size_t);
495 int (*strcasecmp)(const char *, const char *);
496 int (*strncasecmp)(const char *s1, const char *s2, size_t n);
497 void* (*memset)(void *dst, int c, size_t length);
498 void* (*memcpy)(void *out, const void *in, size_t n);
499 void* (*memmove)(void *out, const void *in, size_t n);
500 const unsigned char *_ctype_;
501 int (*atoi)(const char *str);
502 char *(*strchr)(const char *s, int c);
503 char *(*strcat)(char *s1, const char *s2);
504 void *(*memchr)(const void *s1, int c, size_t n);
505 int (*memcmp)(const void *s1, const void *s2, size_t n);
506 char *(*strcasestr) (const char* phaystack, const char* pneedle);
507 char* (*strtok_r)(char *ptr, const char *sep, char **end);
508 /* unicode stuff */
509 const unsigned char* (*utf8decode)(const unsigned char *utf8, unsigned short *ucs);
510 unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count);
511 unsigned char* (*utf16LEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
512 unsigned char* (*utf16BEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
513 unsigned char* (*utf8encode)(unsigned long ucs, unsigned char *utf8);
514 unsigned long (*utf8length)(const unsigned char *utf8);
515 int (*utf8seek)(const unsigned char* utf8, int offset);
517 /* sound */
518 void (*sound_set)(int setting, int value);
519 int (*sound_default)(int setting);
520 int (*sound_min)(int setting);
521 int (*sound_max)(int setting);
522 const char * (*sound_unit)(int setting);
523 int (*sound_val2phys)(int setting, int value);
524 #ifndef SIMULATOR
525 void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, size_t* size));
526 void (*mp3_play_pause)(bool play);
527 void (*mp3_play_stop)(void);
528 bool (*mp3_is_playing)(void);
529 #if CONFIG_CODEC != SWCODEC
530 void (*bitswap)(unsigned char *data, int length);
531 #endif
532 #endif /* !SIMULATOR */
533 #if CONFIG_CODEC == SWCODEC
534 const unsigned long *audio_master_sampr_list;
535 const unsigned long *hw_freq_sampr;
536 void (*pcm_apply_settings)(void);
537 void (*pcm_play_data)(pcm_more_callback_type get_more,
538 unsigned char* start, size_t size);
539 void (*pcm_play_stop)(void);
540 void (*pcm_set_frequency)(unsigned int frequency);
541 bool (*pcm_is_playing)(void);
542 bool (*pcm_is_paused)(void);
543 void (*pcm_play_pause)(bool play);
544 size_t (*pcm_get_bytes_waiting)(void);
545 void (*pcm_calculate_peaks)(int *left, int *right);
546 void (*pcm_play_lock)(void);
547 void (*pcm_play_unlock)(void);
548 #ifdef HAVE_RECORDING
549 const unsigned long *rec_freq_sampr;
550 void (*pcm_init_recording)(void);
551 void (*pcm_close_recording)(void);
552 void (*pcm_record_data)(pcm_more_callback_type2 more_ready,
553 void *start, size_t size);
554 void (*pcm_record_more)(void *start, size_t size);
555 void (*pcm_stop_recording)(void);
556 void (*pcm_calculate_rec_peaks)(int *left, int *right);
557 void (*audio_set_recording_gain)(int left, int right, int type);
558 #endif /* HAVE_RECORDING */
559 #if INPUT_SRC_CAPS != 0
560 void (*audio_set_output_source)(int monitor);
561 void (*audio_set_input_source)(int source, unsigned flags);
562 #endif
563 void (*dsp_set_crossfeed)(bool enable);
564 void (*dsp_set_eq)(bool enable);
565 void (*dsp_dither_enable)(bool enable);
566 intptr_t (*dsp_configure)(struct dsp_config *dsp, int setting,
567 intptr_t value);
568 int (*dsp_process)(struct dsp_config *dsp, char *dest,
569 const char *src[], int count);
570 #endif /* CONFIG_CODEC == SWCODC */
572 /* playback control */
573 int (*playlist_amount)(void);
574 int (*playlist_resume)(void);
575 int (*playlist_start)(int start_index, int offset);
576 void (*PREFIX(audio_play))(long offset);
577 void (*audio_stop)(void);
578 void (*audio_pause)(void);
579 void (*audio_resume)(void);
580 void (*audio_next)(void);
581 void (*audio_prev)(void);
582 void (*audio_ff_rewind)(long newtime);
583 struct mp3entry* (*audio_next_track)(void);
584 int (*audio_status)(void);
585 bool (*audio_has_changed_track)(void);
586 struct mp3entry* (*audio_current_track)(void);
587 void (*audio_flush_and_reload_tracks)(void);
588 int (*audio_get_file_pos)(void);
589 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
590 unsigned long (*mpeg_get_last_header)(void);
591 #endif
592 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
593 (CONFIG_CODEC == SWCODEC)
594 void (*sound_set_pitch)(int pitch);
595 #endif
597 /* MAS communication */
598 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
599 int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len);
600 int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len);
601 int (*mas_readreg)(int reg);
602 int (*mas_writereg)(int reg, unsigned int val);
603 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
604 int (*mas_codec_writereg)(int reg, unsigned int val);
605 int (*mas_codec_readreg)(int reg);
606 void (*i2c_begin)(void);
607 void (*i2c_end)(void);
608 int (*i2c_write)(int address, const unsigned char* buf, int count );
609 #endif
610 #endif
612 /* menu */
613 int (*do_menu)(const struct menu_item_ex *menu, int *start_selected,
614 struct viewport parent[NB_SCREENS], bool hide_bars);
616 /* scroll bar */
617 struct gui_syncstatusbar *statusbars;
618 void (*gui_syncstatusbar_draw)(struct gui_syncstatusbar * bars, bool force_redraw);
620 /* options */
621 const struct settings_list* (*get_settings_list)(int*count);
622 const struct settings_list* (*find_setting)(const void* variable, int *id);
623 bool (*option_screen)(const struct settings_list *setting,
624 struct viewport parent[NB_SCREENS],
625 bool use_temp_var, unsigned char* option_title);
626 bool (*set_option)(const char* string, const void* variable,
627 enum optiontype type, const struct opt_items* options,
628 int numoptions, void (*function)(int));
629 bool (*set_bool_options)(const char* string, const bool* variable,
630 const char* yes_str, int yes_voice,
631 const char* no_str, int no_voice,
632 void (*function)(bool));
633 bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit,
634 const int* variable, void (*function)(int), int step,
635 int min, int max,
636 void (*formatter)(char*, size_t, int, const char*) );
637 bool (*set_bool)(const char* string, const bool* variable );
639 #ifdef HAVE_LCD_COLOR
640 bool (*set_color)(struct screen *display, char *title, unsigned *color,
641 unsigned banned_color);
642 #endif
643 /* action handling */
644 int (*get_custom_action)(int context,int timeout,
645 const struct button_mapping* (*get_context_map)(int));
646 int (*get_action)(int context, int timeout);
647 bool (*action_userabort)(int timeout);
649 /* power */
650 int (*battery_level)(void);
651 bool (*battery_level_safe)(void);
652 int (*battery_time)(void);
653 #ifndef SIMULATOR
654 unsigned int (*battery_voltage)(void);
655 #endif
656 #if CONFIG_CHARGING
657 bool (*charger_inserted)(void);
658 # if CONFIG_CHARGING == CHARGING_MONITOR
659 bool (*charging_state)(void);
660 # endif
661 #endif
662 #ifdef HAVE_USB_POWER
663 bool (*usb_powered)(void);
664 #endif
666 /* misc */
667 void (*srand)(unsigned int seed);
668 int (*rand)(void);
669 void (*qsort)(void *base, size_t nmemb, size_t size,
670 int(*compar)(const void *, const void *));
671 int (*kbd_input)(char* buffer, int buflen);
672 struct tm* (*get_time)(void);
673 int (*set_time)(const struct tm *tm);
674 #if CONFIG_RTC
675 time_t (*mktime)(struct tm *t);
676 #endif
677 void* (*plugin_get_buffer)(size_t *buffer_size);
678 void* (*plugin_get_audio_buffer)(size_t *buffer_size);
679 void (*plugin_tsr)(bool (*exit_callback)(bool reenter));
680 char* (*plugin_get_current_filename)(void);
681 #ifdef PLUGIN_USE_IRAM
682 void (*plugin_iram_init)(char *iramstart, char *iramcopy, size_t iram_size,
683 char *iedata, size_t iedata_size);
684 #endif
685 #if defined(DEBUG) || defined(SIMULATOR)
686 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
687 #endif
688 #ifdef ROCKBOX_HAS_LOGF
689 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
690 #endif
691 struct user_settings* global_settings;
692 struct system_status *global_status;
693 void (*talk_disable)(bool disable);
694 #if CONFIG_CODEC == SWCODEC
695 int (*codec_load_file)(const char* codec, struct codec_api *api);
696 const char *(*get_codec_filename)(int cod_spec);
697 bool (*get_metadata)(struct mp3entry* id3, int fd, const char* trackname);
698 #endif
699 bool (*mp3info)(struct mp3entry *entry, const char *filename);
700 int (*count_mp3_frames)(int fd, int startpos, int filesize,
701 void (*progressfunc)(int));
702 int (*create_xing_header)(int fd, long startpos, long filesize,
703 unsigned char *buf, unsigned long num_frames,
704 unsigned long rec_time, unsigned long header_template,
705 void (*progressfunc)(int), bool generate_toc);
706 unsigned long (*find_next_frame)(int fd, long *offset,
707 long max_offset, unsigned long last_header);
709 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
710 unsigned short (*peak_meter_scale_value)(unsigned short val,
711 int meterwidth);
712 void (*peak_meter_set_use_dbfs)(bool use);
713 bool (*peak_meter_get_use_dbfs)(void);
714 #endif
715 #ifdef HAVE_LCD_BITMAP
716 int (*read_bmp_file)(const char* filename, struct bitmap *bm, int maxsize,
717 int format, const struct custom_format *cformat);
718 void (*screen_dump_set_hook)(void (*hook)(int fh));
719 #endif
720 int (*show_logo)(void);
721 struct tree_context* (*tree_get_context)(void);
722 void (*set_current_file)(char* path);
723 void (*set_dirfilter)(int l_dirfilter);
725 #ifdef HAVE_WHEEL_POSITION
726 int (*wheel_status)(void);
727 void (*wheel_send_events)(bool send);
728 #endif
730 #ifdef IRIVER_H100_SERIES
731 /* Routines for the iriver_flash -plugin. */
732 bool (*detect_original_firmware)(void);
733 bool (*detect_flashed_ramimage)(void);
734 bool (*detect_flashed_romimage)(void);
735 #endif
737 void (*led)(bool on);
739 #if (CONFIG_CODEC == SWCODEC)
740 /* buffering API */
741 int (*bufopen)(const char *file, size_t offset, enum data_type type);
742 int (*bufalloc)(const void *src, size_t size, enum data_type type);
743 bool (*bufclose)(int handle_id);
744 int (*bufseek)(int handle_id, size_t newpos);
745 int (*bufadvance)(int handle_id, off_t offset);
746 ssize_t (*bufread)(int handle_id, size_t size, void *dest);
747 ssize_t (*bufgetdata)(int handle_id, size_t size, void **data);
748 ssize_t (*bufgettail)(int handle_id, size_t size, void **data);
749 ssize_t (*bufcuttail)(int handle_id, size_t size);
751 ssize_t (*buf_get_offset)(int handle_id, void *ptr);
752 ssize_t (*buf_handle_offset)(int handle_id);
753 void (*buf_request_buffer_handle)(int handle_id);
754 void (*buf_set_base_handle)(int handle_id);
755 size_t (*buf_used)(void);
756 #endif
758 #ifdef HAVE_TAGCACHE
759 bool (*tagcache_search)(struct tagcache_search *tcs, int tag);
760 void (*tagcache_search_set_uniqbuf)(struct tagcache_search *tcs,
761 void *buffer, long length);
762 bool (*tagcache_search_add_filter)(struct tagcache_search *tcs,
763 int tag, int seek);
764 bool (*tagcache_get_next)(struct tagcache_search *tcs);
765 bool (*tagcache_retrieve)(struct tagcache_search *tcs, int idxid,
766 int tag, char *buf, long size);
767 void (*tagcache_search_finish)(struct tagcache_search *tcs);
768 long (*tagcache_get_numeric)(const struct tagcache_search *tcs, int tag);
769 #endif
771 #ifdef HAVE_ALBUMART
772 bool (*find_albumart)(const struct mp3entry *id3, char *buf, int buflen);
773 bool (*search_albumart_files)(const struct mp3entry *id3, const char *size_string,
774 char *buf, int buflen);
775 #endif
777 void (*thread_thaw)(unsigned int thread_id);
779 #ifdef HAVE_SEMAPHORE_OBJECTS
780 void (*semaphore_init)(struct semaphore *s, int max, int start);
781 void (*semaphore_wait)(struct semaphore *s);
782 void (*semaphore_release)(struct semaphore *s);
783 #endif
785 const char *appsversion;
786 /* new stuff at the end, sort into place next time
787 the API gets incompatible */
790 /* plugin header */
791 struct plugin_header {
792 unsigned long magic;
793 unsigned short target_id;
794 unsigned short api_version;
795 unsigned char *load_addr;
796 unsigned char *end_addr;
797 enum plugin_status(*entry_point)(const struct plugin_api*, const void*);
800 #ifdef PLUGIN
801 #ifndef SIMULATOR
802 extern unsigned char plugin_start_addr[];
803 extern unsigned char plugin_end_addr[];
804 #define PLUGIN_HEADER \
805 const struct plugin_header __header \
806 __attribute__ ((section (".header")))= { \
807 PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
808 plugin_start_addr, plugin_end_addr, plugin_start };
809 #else /* SIMULATOR */
810 #define PLUGIN_HEADER \
811 const struct plugin_header __header \
812 __attribute__((visibility("default"))) = { \
813 PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
814 NULL, NULL, plugin_start };
815 #endif /* SIMULATOR */
817 #ifdef PLUGIN_USE_IRAM
818 /* Declare IRAM variables */
819 #define PLUGIN_IRAM_DECLARE \
820 extern char iramcopy[]; \
821 extern char iramstart[]; \
822 extern char iramend[]; \
823 extern char iedata[]; \
824 extern char iend[];
825 /* Initialize IRAM */
826 #define PLUGIN_IRAM_INIT(api) \
827 (api)->plugin_iram_init(iramstart, iramcopy, iramend-iramstart, \
828 iedata, iend-iedata);
829 #else
830 #define PLUGIN_IRAM_DECLARE
831 #define PLUGIN_IRAM_INIT(api)
832 #endif /* PLUGIN_USE_IRAM */
833 #endif /* PLUGIN */
835 int plugin_load(const char* plugin, const void* parameter);
836 void* plugin_get_audio_buffer(size_t *buffer_size);
837 #ifdef PLUGIN_USE_IRAM
838 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
839 char *iedata, size_t iedata_size);
840 #endif
842 /* plugin_tsr,
843 callback returns true to allow the new plugin to load,
844 reenter means the currently running plugin is being reloaded */
845 void plugin_tsr(bool (*exit_callback)(bool reenter));
847 /* defined by the plugin */
848 enum plugin_status plugin_start(const struct plugin_api* rockbox, const void* parameter)
849 NO_PROF_ATTR;
851 /* Use this macro in plugins where gcc tries to optimize by calling
852 * these functions directly */
853 #define MEM_FUNCTION_WRAPPERS(api) \
854 void *memcpy(void *dest, const void *src, size_t n) \
856 return (api)->memcpy(dest, src, n); \
858 void *memset(void *dest, int c, size_t n) \
860 return (api)->memset(dest, c, n); \
862 void *memmove(void *dest, const void *src, size_t n) \
864 return (api)->memmove(dest, src, n); \
866 int memcmp(const void *s1, const void *s2, size_t n) \
868 return (api)->memcmp(s1, s2, n); \
871 #ifndef CACHE_FUNCTION_WRAPPERS
873 #ifdef CACHE_FUNCTIONS_AS_CALL
874 #define CACHE_FUNCTION_WRAPPERS(api) \
875 void flush_icache(void) \
877 (api)->flush_icache(); \
879 void invalidate_icache(void) \
881 (api)->invalidate_icache(); \
883 #else
884 #define CACHE_FUNCTION_WRAPPERS(api)
885 #endif /* CACHE_FUNCTIONS_AS_CALL */
887 #endif /* CACHE_FUNCTION_WRAPPERS */
889 #ifndef ALIGN_BUFFER_WRAPPER
890 #define ALIGN_BUFFER_WRAPPER(api) \
891 size_t align_buffer(void **start, size_t size, size_t align) \
893 return (api)->align_buffer(start, size, align); \
895 #endif /* ALIGN_BUFFER_WRAPPER */
897 #endif /* __PCTOOL__ */
898 #endif