playback.c: Add the buffering thread
[Rockbox.git] / apps / plugin.h
blob448eed98ace1cf2a9766b4df272a8d963a849126
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
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 ****************************************************************************/
19 #ifndef _PLUGIN_H_
20 #define _PLUGIN_H_
22 /* instruct simulator code to not redefine any symbols when compiling plugins.
23 (the PLUGIN macro is defined in apps/plugins/Makefile) */
24 #ifdef PLUGIN
25 #define NO_REDEFINES_PLEASE
26 #endif
28 #ifndef MEM
29 #define MEM 2
30 #endif
32 #include <stdbool.h>
33 #include <sys/types.h>
34 #include <stdarg.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include "config.h"
38 #include "system.h"
39 #include "dir.h"
40 #include "kernel.h"
41 #include "thread.h"
42 #include "button.h"
43 #include "action.h"
44 #include "usb.h"
45 #include "font.h"
46 #include "lcd.h"
47 #include "id3.h"
48 #include "buffering.h"
49 #include "sound.h"
50 #include "mpeg.h"
51 #include "audio.h"
52 #include "mp3_playback.h"
53 #include "talk.h"
54 #ifdef RB_PROFILE
55 #include "profile.h"
56 #endif
57 #include "misc.h"
58 #if (CONFIG_CODEC == SWCODEC)
59 #include "dsp.h"
60 #include "codecs.h"
61 #include "playback.h"
62 #include "metadata.h"
63 #ifdef HAVE_RECORDING
64 #include "recording.h"
65 #endif
66 #else
67 #include "mas.h"
68 #endif /* CONFIG_CODEC == SWCODEC */
69 #include "settings.h"
70 #include "timer.h"
71 #include "playlist.h"
72 #ifdef HAVE_LCD_BITMAP
73 #include "scrollbar.h"
74 #endif
75 #include "statusbar.h"
76 #include "menu.h"
77 #include "rbunicode.h"
78 #include "list.h"
79 #include "tree.h"
80 #include "color_picker.h"
82 #ifdef HAVE_REMOTE_LCD
83 #include "lcd-remote.h"
84 #endif
86 #ifdef PLUGIN
88 #if defined(DEBUG) || defined(SIMULATOR)
89 #undef DEBUGF
90 #define DEBUGF rb->debugf
91 #undef LDEBUGF
92 #define LDEBUGF rb->debugf
93 #else
94 #define DEBUGF(...)
95 #define LDEBUGF(...)
96 #endif
98 #ifdef ROCKBOX_HAS_LOGF
99 #undef LOGF
100 #define LOGF rb->logf
101 #else
102 #define LOGF(...)
103 #endif
105 #endif
107 #ifdef SIMULATOR
108 #define PREFIX(_x_) sim_ ## _x_
109 #else
110 #define PREFIX(_x_) _x_
111 #endif
113 #define PLUGIN_MAGIC 0x526F634B /* RocK */
115 /* increase this every time the api struct changes */
116 #define PLUGIN_API_VERSION 86
118 /* update this to latest version if a change to the api struct breaks
119 backwards compatibility (and please take the opportunity to sort in any
120 new function which are "waiting" at the end of the function table) */
121 #define PLUGIN_MIN_API_VERSION 86
123 /* plugin return codes */
124 enum plugin_status {
125 PLUGIN_OK = 0,
126 PLUGIN_USB_CONNECTED,
127 PLUGIN_ERROR = -1,
130 /* NOTE: To support backwards compatibility, only add new functions at
131 the end of the structure. Every time you add a new function,
132 remember to increase PLUGIN_API_VERSION. If you make changes to the
133 existing APIs then also update PLUGIN_MIN_API_VERSION to current
134 version
136 struct plugin_api {
138 /* lcd */
139 void (*lcd_set_contrast)(int x);
140 void (*lcd_update)(void);
141 void (*lcd_clear_display)(void);
142 void (*lcd_setmargins)(int x, int y);
143 int (*lcd_getstringsize)(const unsigned char *str, int *w, int *h);
144 void (*lcd_putsxy)(int x, int y, const unsigned char *string);
145 void (*lcd_puts)(int x, int y, const unsigned char *string);
146 void (*lcd_puts_scroll)(int x, int y, const unsigned char* string);
147 void (*lcd_stop_scroll)(void);
148 #ifdef HAVE_LCD_CHARCELLS
149 void (*lcd_define_pattern)(unsigned long ucs, const char *pattern);
150 unsigned long (*lcd_get_locked_pattern)(void);
151 void (*lcd_unlock_pattern)(unsigned long ucs);
152 void (*lcd_putc)(int x, int y, unsigned long ucs);
153 void (*lcd_put_cursor)(int x, int y, unsigned long ucs);
154 void (*lcd_remove_cursor)(void);
155 void (*lcd_icon)(int icon, bool enable);
156 void (*lcd_double_height)(bool on);
157 #else
158 void (*lcd_set_drawmode)(int mode);
159 int (*lcd_get_drawmode)(void);
160 void (*lcd_setfont)(int font);
161 void (*lcd_drawpixel)(int x, int y);
162 void (*lcd_drawline)(int x1, int y1, int x2, int y2);
163 void (*lcd_hline)(int x1, int x2, int y);
164 void (*lcd_vline)(int x, int y1, int y2);
165 void (*lcd_drawrect)(int x, int y, int width, int height);
166 void (*lcd_fillrect)(int x, int y, int width, int height);
167 void (*lcd_mono_bitmap_part)(const unsigned char *src, int src_x, int src_y,
168 int stride, int x, int y, int width, int height);
169 void (*lcd_mono_bitmap)(const unsigned char *src, int x, int y,
170 int width, int height);
171 #if LCD_DEPTH > 1
172 void (*lcd_set_foreground)(unsigned foreground);
173 unsigned (*lcd_get_foreground)(void);
174 void (*lcd_set_background)(unsigned foreground);
175 unsigned (*lcd_get_background)(void);
176 void (*lcd_bitmap_part)(const fb_data *src, int src_x, int src_y,
177 int stride, int x, int y, int width, int height);
178 void (*lcd_bitmap)(const fb_data *src, int x, int y, int width,
179 int height);
180 fb_data* (*lcd_get_backdrop)(void);
181 void (*lcd_set_backdrop)(fb_data* backdrop);
182 #endif
183 #if LCD_DEPTH == 16
184 void (*lcd_bitmap_transparent_part)(const fb_data *src,
185 int src_x, int src_y, int stride,
186 int x, int y, int width, int height);
187 void (*lcd_bitmap_transparent)(const fb_data *src, int x, int y,
188 int width, int height);
189 #endif
190 unsigned short *(*bidi_l2v)( const unsigned char *str, int orientation );
191 const unsigned char *(*font_get_bits)( struct font *pf, unsigned short char_code );
192 struct font* (*font_load)(const char *path);
193 void (*lcd_puts_style)(int x, int y, const unsigned char *str, int style);
194 void (*lcd_puts_scroll_style)(int x, int y, const unsigned char* string,
195 int style);
196 fb_data* lcd_framebuffer;
197 void (*lcd_blit) (const fb_data* data, int x, int by, int width,
198 int bheight, int stride);
199 void (*lcd_update_rect)(int x, int y, int width, int height);
200 void (*gui_scrollbar_draw)(struct screen * screen, int x, int y,
201 int width, int height, int items,
202 int min_shown, int max_shown,
203 unsigned flags);
204 struct font* (*font_get)(int font);
205 int (*font_getstringsize)(const unsigned char *str, int *w, int *h,
206 int fontnumber);
207 int (*font_get_width)(struct font* pf, unsigned short char_code);
208 void (*screen_clear_area)(struct screen * display, int xstart, int ystart,
209 int width, int height);
210 #endif
211 void (*backlight_on)(void);
212 void (*backlight_off)(void);
213 void (*backlight_set_timeout)(int index);
214 #if CONFIG_CHARGING
215 void (*backlight_set_timeout_plugged)(int index);
216 #endif
217 void (*splash)(int ticks, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
219 #ifdef HAVE_REMOTE_LCD
220 /* remote lcd */
221 void (*lcd_remote_set_contrast)(int x);
222 void (*lcd_remote_clear_display)(void);
223 void (*lcd_remote_setmargins)(int x, int y);
224 void (*lcd_remote_puts)(int x, int y, const unsigned char *string);
225 void (*lcd_remote_lcd_puts_scroll)(int x, int y, const unsigned char* string);
226 void (*lcd_remote_lcd_stop_scroll)(void);
227 void (*lcd_remote_set_drawmode)(int mode);
228 int (*lcd_remote_get_drawmode)(void);
229 void (*lcd_remote_setfont)(int font);
230 int (*lcd_remote_getstringsize)(const unsigned char *str, int *w, int *h);
231 void (*lcd_remote_drawpixel)(int x, int y);
232 void (*lcd_remote_drawline)(int x1, int y1, int x2, int y2);
233 void (*lcd_remote_hline)(int x1, int x2, int y);
234 void (*lcd_remote_vline)(int x, int y1, int y2);
235 void (*lcd_remote_drawrect)(int x, int y, int nx, int ny);
236 void (*lcd_remote_fillrect)(int x, int y, int nx, int ny);
237 void (*lcd_remote_mono_bitmap_part)(const unsigned char *src, int src_x,
238 int src_y, int stride, int x, int y,
239 int width, int height);
240 void (*lcd_remote_mono_bitmap)(const unsigned char *src, int x, int y,
241 int width, int height);
242 void (*lcd_remote_putsxy)(int x, int y, const unsigned char *string);
243 void (*lcd_remote_puts_style)(int x, int y, const unsigned char *str, int style);
244 void (*lcd_remote_puts_scroll_style)(int x, int y, const unsigned char* string,
245 int style);
246 fb_remote_data* lcd_remote_framebuffer;
247 void (*lcd_remote_update)(void);
248 void (*lcd_remote_update_rect)(int x, int y, int width, int height);
250 void (*remote_backlight_on)(void);
251 void (*remote_backlight_off)(void);
252 #endif
253 struct screen* screens[NB_SCREENS];
254 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
255 void (*lcd_remote_set_foreground)(unsigned foreground);
256 unsigned (*lcd_remote_get_foreground)(void);
257 void (*lcd_remote_set_background)(unsigned background);
258 unsigned (*lcd_remote_get_background)(void);
259 void (*lcd_remote_bitmap_part)(const fb_remote_data *src, int src_x, int src_y,
260 int stride, int x, int y, int width, int height);
261 void (*lcd_remote_bitmap)(const fb_remote_data *src, int x, int y, int width,
262 int height);
263 #endif
264 #if defined(HAVE_LCD_COLOR)
265 void (*lcd_yuv_blit)(unsigned char * const src[3],
266 int src_x, int src_y, int stride,
267 int x, int y, int width, int height);
268 #endif
270 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200)
271 void (*lcd_yuv_set_options)(unsigned options);
272 #endif
274 /* list */
275 void (*gui_synclist_init)(struct gui_synclist * lists,
276 list_get_name callback_get_item_name,void * data,
277 bool scroll_all,int selected_size);
278 void (*gui_synclist_set_nb_items)(struct gui_synclist * lists, int nb_items);
279 void (*gui_synclist_set_icon_callback)(struct gui_synclist * lists, list_get_icon icon_callback);
280 int (*gui_synclist_get_nb_items)(struct gui_synclist * lists);
281 int (*gui_synclist_get_sel_pos)(struct gui_synclist * lists);
282 void (*gui_synclist_draw)(struct gui_synclist * lists);
283 void (*gui_synclist_select_item)(struct gui_synclist * lists,
284 int item_number);
285 void (*gui_synclist_add_item)(struct gui_synclist * lists);
286 void (*gui_synclist_del_item)(struct gui_synclist * lists);
287 void (*gui_synclist_limit_scroll)(struct gui_synclist * lists, bool scroll);
288 bool (*gui_synclist_do_button)(struct gui_synclist * lists,
289 unsigned *action, enum list_wrap wrap);
290 void (*gui_synclist_set_title)(struct gui_synclist *lists, char* title, int icon);
292 /* button */
293 long (*button_get)(bool block);
294 long (*button_get_w_tmo)(int ticks);
295 int (*button_status)(void);
296 void (*button_clear_queue)(void);
297 int (*button_queue_count)(void);
298 #ifdef HAS_BUTTON_HOLD
299 bool (*button_hold)(void);
300 #endif
302 /* file */
303 int (*PREFIX(open))(const char* pathname, int flags);
304 int (*PREFIX(close))(int fd);
305 ssize_t (*PREFIX(read))(int fd, void* buf, size_t count);
306 off_t (*PREFIX(lseek))(int fd, off_t offset, int whence);
307 int (*PREFIX(creat))(const char *pathname);
308 ssize_t (*PREFIX(write))(int fd, const void* buf, size_t count);
309 int (*PREFIX(remove))(const char* pathname);
310 int (*PREFIX(rename))(const char* path, const char* newname);
311 int (*PREFIX(ftruncate))(int fd, off_t length);
312 off_t (*PREFIX(filesize))(int fd);
313 int (*fdprintf)(int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
314 int (*read_line)(int fd, char* buffer, int buffer_size);
315 bool (*settings_parseline)(char* line, char** name, char** value);
316 #ifndef SIMULATOR
317 void (*ata_sleep)(void);
318 bool (*ata_disk_is_active)(void);
319 #endif
320 void (*ata_spindown)(int seconds);
321 void (*reload_directory)(void);
322 char *(*create_numbered_filename)(char *buffer, const char *path,
323 const char *prefix, const char *suffix,
324 int numberlen IF_CNFN_NUM_(, int *num));
326 /* dir */
327 DIR* (*opendir)(const char* name);
328 int (*closedir)(DIR* dir);
329 struct dirent* (*readdir)(DIR* dir);
330 int (*mkdir)(const char *name);
331 int (*rmdir)(const char *name);
333 /* kernel/ system */
334 void (*PREFIX(sleep))(int ticks);
335 void (*yield)(void);
336 #ifdef HAVE_PRIORITY_SCHEDULING
337 void (*priority_yield)(void);
338 #endif
339 volatile long* current_tick;
340 long (*default_event_handler)(long event);
341 long (*default_event_handler_ex)(long event, void (*callback)(void *), void *parameter);
342 struct thread_entry* threads;
343 struct thread_entry* (*create_thread)(void (*function)(void), void* stack,
344 int stack_size, unsigned flags,
345 const char *name
346 IF_PRIO(, int priority)
347 IF_COP(, unsigned int core));
348 void (*remove_thread)(struct thread_entry *thread);
349 void (*reset_poweroff_timer)(void);
350 #ifndef SIMULATOR
351 int (*system_memory_guard)(int newmode);
352 long *cpu_frequency;
353 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
354 #ifdef CPU_BOOST_LOGGING
355 void (*cpu_boost_)(bool on_off,char*location,int line);
356 #else
357 void (*cpu_boost)(bool on_off);
358 #endif
359 #endif
360 #endif
361 bool (*timer_register)(int reg_prio, void (*unregister_callback)(void),
362 long cycles, int int_prio,
363 void (*timer_callback)(void));
364 void (*timer_unregister)(void);
365 bool (*timer_set_period)(long count);
367 void (*queue_init)(struct event_queue *q, bool register_queue);
368 void (*queue_delete)(struct event_queue *q);
369 void (*queue_post)(struct event_queue *q, long id, intptr_t data);
370 void (*queue_wait_w_tmo)(struct event_queue *q, struct queue_event *ev,
371 int ticks);
372 void (*usb_acknowledge)(long id);
373 #ifdef RB_PROFILE
374 void (*profile_thread)(void);
375 void (*profstop)(void);
376 void (*profile_func_enter)(void *this_fn, void *call_site);
377 void (*profile_func_exit)(void *this_fn, void *call_site);
378 #endif
380 #ifdef SIMULATOR
381 /* special simulator hooks */
382 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
383 void (*sim_lcd_ex_init)(int shades, unsigned long (*getpixel)(int, int));
384 void (*sim_lcd_ex_update_rect)(int x, int y, int width, int height);
385 #endif
386 #endif
388 /* strings and memory */
389 int (*snprintf)(char *buf, size_t size, const char *fmt, ...)
390 ATTRIBUTE_PRINTF(3, 4);
391 int (*vsnprintf)(char *buf, int size, const char *fmt, va_list ap);
392 char* (*strcpy)(char *dst, const char *src);
393 char* (*strncpy)(char *dst, const char *src, size_t length);
394 size_t (*strlen)(const char *str);
395 char * (*strrchr)(const char *s, int c);
396 int (*strcmp)(const char *, const char *);
397 int (*strncmp)(const char *, const char *, size_t);
398 int (*strcasecmp)(const char *, const char *);
399 int (*strncasecmp)(const char *s1, const char *s2, size_t n);
400 void* (*memset)(void *dst, int c, size_t length);
401 void* (*memcpy)(void *out, const void *in, size_t n);
402 void* (*memmove)(void *out, const void *in, size_t n);
403 const unsigned char *_ctype_;
404 int (*atoi)(const char *str);
405 char *(*strchr)(const char *s, int c);
406 char *(*strcat)(char *s1, const char *s2);
407 void *(*memchr)(const void *s1, int c, size_t n);
408 int (*memcmp)(const void *s1, const void *s2, size_t n);
409 char *(*strcasestr) (const char* phaystack, const char* pneedle);
410 char* (*strtok_r)(char *ptr, const char *sep, char **end);
411 /* unicode stuff */
412 const unsigned char* (*utf8decode)(const unsigned char *utf8, unsigned short *ucs);
413 unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count);
414 unsigned char* (*utf16LEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
415 unsigned char* (*utf16BEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
416 unsigned char* (*utf8encode)(unsigned long ucs, unsigned char *utf8);
417 unsigned long (*utf8length)(const unsigned char *utf8);
418 int (*utf8seek)(const unsigned char* utf8, int offset);
420 /* sound */
421 #if CONFIG_CODEC == SWCODEC
422 int (*sound_default)(int setting);
423 #endif
424 void (*sound_set)(int setting, int value);
425 int (*sound_min)(int setting);
426 int (*sound_max)(int setting);
427 #ifndef SIMULATOR
428 void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, size_t* size));
429 void (*mp3_play_pause)(bool play);
430 void (*mp3_play_stop)(void);
431 bool (*mp3_is_playing)(void);
432 #if CONFIG_CODEC != SWCODEC
433 void (*bitswap)(unsigned char *data, int length);
434 #endif
435 #endif /* !SIMULATOR */
436 #if CONFIG_CODEC == SWCODEC
437 const unsigned long *audio_master_sampr_list;
438 const unsigned long *hw_freq_sampr;
439 void (*pcm_apply_settings)(void);
440 void (*pcm_play_data)(pcm_more_callback_type get_more,
441 unsigned char* start, size_t size);
442 void (*pcm_play_stop)(void);
443 void (*pcm_set_frequency)(unsigned int frequency);
444 bool (*pcm_is_playing)(void);
445 bool (*pcm_is_paused)(void);
446 void (*pcm_play_pause)(bool play);
447 size_t (*pcm_get_bytes_waiting)(void);
448 void (*pcm_calculate_peaks)(int *left, int *right);
449 #ifdef HAVE_RECORDING
450 const unsigned long *rec_freq_sampr;
451 void (*pcm_init_recording)(void);
452 void (*pcm_close_recording)(void);
453 void (*pcm_record_data)(pcm_more_callback_type2 more_ready,
454 void *start, size_t size);
455 void (*pcm_record_more)(void *start, size_t size);
456 void (*pcm_stop_recording)(void);
457 void (*pcm_calculate_rec_peaks)(int *left, int *right);
458 void (*audio_set_recording_gain)(int left, int right, int type);
459 #endif /* HAVE_RECORDING */
460 #if INPUT_SRC_CAPS != 0
461 void (*audio_set_output_source)(int monitor);
462 void (*audio_set_input_source)(int source, unsigned flags);
463 #endif
464 #endif /* CONFIG_CODEC == SWCODC */
466 /* playback control */
467 int (*playlist_amount)(void);
468 int (*playlist_resume)(void);
469 int (*playlist_start)(int start_index, int offset);
470 void (*PREFIX(audio_play))(long offset);
471 void (*audio_stop)(void);
472 void (*audio_pause)(void);
473 void (*audio_resume)(void);
474 void (*audio_next)(void);
475 void (*audio_prev)(void);
476 void (*audio_ff_rewind)(long newtime);
477 struct mp3entry* (*audio_next_track)(void);
478 int (*audio_status)(void);
479 bool (*audio_has_changed_track)(void);
480 struct mp3entry* (*audio_current_track)(void);
481 void (*audio_flush_and_reload_tracks)(void);
482 int (*audio_get_file_pos)(void);
483 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
484 unsigned long (*mpeg_get_last_header)(void);
485 #endif
486 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
487 (CONFIG_CODEC == SWCODEC)
488 void (*sound_set_pitch)(int pitch);
489 #endif
491 /* MAS communication */
492 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
493 int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len);
494 int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len);
495 int (*mas_readreg)(int reg);
496 int (*mas_writereg)(int reg, unsigned int val);
497 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
498 int (*mas_codec_writereg)(int reg, unsigned int val);
499 int (*mas_codec_readreg)(int reg);
500 void (*i2c_begin)(void);
501 void (*i2c_end)(void);
502 int (*i2c_write)(int address, unsigned char* buf, int count );
503 #endif
504 #endif
506 /* menu */
507 int (*do_menu)(const struct menu_item_ex *menu, int *start_selected);
509 /* scroll bar */
510 struct gui_syncstatusbar *statusbars;
511 void (*gui_syncstatusbar_draw)(struct gui_syncstatusbar * bars, bool force_redraw);
513 /* options */
514 const struct settings_list* (*find_setting)(void* variable, int *id);
515 bool (*option_screen)(struct settings_list *setting,
516 bool use_temp_var, unsigned char* option_title);
517 bool (*set_option)(const char* string, void* variable,
518 enum optiontype type, const struct opt_items* options,
519 int numoptions, void (*function)(int));
520 bool (*set_bool_options)(const char* string, bool* variable,
521 const char* yes_str, int yes_voice,
522 const char* no_str, int no_voice,
523 void (*function)(bool));
524 bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit,
525 int* variable, void (*function)(int), int step, int min,
526 int max, void (*formatter)(char*, size_t, int, const char*) );
527 bool (*set_bool)(const char* string, bool* variable );
529 #ifdef HAVE_LCD_COLOR
530 bool (*set_color)(struct screen *display, char *title, unsigned *color,
531 unsigned banned_color);
532 #endif
533 /* action handling */
534 int (*get_custom_action)(int context,int timeout,
535 const struct button_mapping* (*get_context_map)(int));
536 int (*get_action)(int context, int timeout);
537 bool (*action_userabort)(int timeout);
539 /* power */
540 int (*battery_level)(void);
541 bool (*battery_level_safe)(void);
542 int (*battery_time)(void);
543 #ifndef SIMULATOR
544 unsigned int (*battery_voltage)(void);
545 #endif
546 #if CONFIG_CHARGING
547 bool (*charger_inserted)(void);
548 # if CONFIG_CHARGING == CHARGING_MONITOR
549 bool (*charging_state)(void);
550 # endif
551 #endif
552 #ifdef HAVE_USB_POWER
553 bool (*usb_powered)(void);
554 #endif
556 /* misc */
557 void (*srand)(unsigned int seed);
558 int (*rand)(void);
559 void (*qsort)(void *base, size_t nmemb, size_t size,
560 int(*compar)(const void *, const void *));
561 int (*kbd_input)(char* buffer, int buflen);
562 struct tm* (*get_time)(void);
563 int (*set_time)(const struct tm *tm);
564 #if CONFIG_RTC
565 time_t (*mktime)(struct tm *t);
566 #endif
567 void* (*plugin_get_buffer)(size_t *buffer_size);
568 void* (*plugin_get_audio_buffer)(size_t *buffer_size);
569 void (*plugin_tsr)(bool (*exit_callback)(bool reenter));
570 char* (*plugin_get_current_filename)(void);
571 #ifdef IRAM_STEAL
572 void (*plugin_iram_init)(char *iramstart, char *iramcopy, size_t iram_size,
573 char *iedata, size_t iedata_size);
574 #endif
575 #if defined(DEBUG) || defined(SIMULATOR)
576 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
577 #endif
578 #ifdef ROCKBOX_HAS_LOGF
579 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
580 #endif
581 struct user_settings* global_settings;
582 struct system_status *global_status;
583 void (*talk_disable)(bool disable);
584 #if CONFIG_CODEC == SWCODEC
585 int (*codec_load_file)(const char* codec, struct codec_api *api);
586 const char *(*get_codec_filename)(int cod_spec);
587 bool (*get_metadata)(struct mp3entry* id3, int fd, const char* trackname);
588 #endif
589 bool (*mp3info)(struct mp3entry *entry, const char *filename);
590 int (*count_mp3_frames)(int fd, int startpos, int filesize,
591 void (*progressfunc)(int));
592 int (*create_xing_header)(int fd, long startpos, long filesize,
593 unsigned char *buf, unsigned long num_frames,
594 unsigned long rec_time, unsigned long header_template,
595 void (*progressfunc)(int), bool generate_toc);
596 unsigned long (*find_next_frame)(int fd, long *offset,
597 long max_offset, unsigned long last_header);
599 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
600 unsigned short (*peak_meter_scale_value)(unsigned short val,
601 int meterwidth);
602 void (*peak_meter_set_use_dbfs)(bool use);
603 bool (*peak_meter_get_use_dbfs)(void);
604 #endif
605 #ifdef HAVE_LCD_BITMAP
606 int (*read_bmp_file)(char* filename, struct bitmap *bm, int maxsize,
607 int format);
608 void (*screen_dump_set_hook)(void (*hook)(int fh));
609 #endif
610 int (*show_logo)(void);
611 struct tree_context* (*tree_get_context)(void);
612 void (*set_current_file)(char* path);
613 void (*set_dirfilter)(int l_dirfilter);
615 #ifdef HAVE_WHEEL_POSITION
616 int (*wheel_status)(void);
617 void (*wheel_send_events)(bool send);
618 #endif
620 #ifdef IRIVER_H100_SERIES
621 /* Routines for the iriver_flash -plugin. */
622 bool (*detect_original_firmware)(void);
623 bool (*detect_flashed_ramimage)(void);
624 bool (*detect_flashed_romimage)(void);
625 #endif
627 void (*led)(bool on);
629 #ifdef CACHE_FUNCTIONS_AS_CALL
630 void (*flush_icache)(void);
631 void (*invalidate_icache)(void);
632 #endif
634 /* new stuff at the end, sort into place next time
635 the API gets incompatible */
637 #if (CONFIG_CODEC == SWCODEC)
638 void (*mutex_init)(struct mutex *m);
639 void (*mutex_lock)(struct mutex *m);
640 void (*mutex_unlock)(struct mutex *m);
641 #endif
643 void (*thread_wait)(struct thread_entry *thread);
646 /* plugin header */
647 struct plugin_header {
648 unsigned long magic;
649 unsigned short target_id;
650 unsigned short api_version;
651 unsigned char *load_addr;
652 unsigned char *end_addr;
653 enum plugin_status(*entry_point)(struct plugin_api*, void*);
656 #ifdef PLUGIN
657 #ifndef SIMULATOR
658 extern unsigned char plugin_start_addr[];
659 extern unsigned char plugin_end_addr[];
660 #define PLUGIN_HEADER \
661 const struct plugin_header __header \
662 __attribute__ ((section (".header")))= { \
663 PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
664 plugin_start_addr, plugin_end_addr, plugin_start };
665 #else /* SIMULATOR */
666 #define PLUGIN_HEADER \
667 const struct plugin_header __header \
668 __attribute__((visibility("default"))) = { \
669 PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
670 NULL, NULL, plugin_start };
671 #endif /* SIMULATOR */
673 #ifdef USE_IRAM
674 /* Declare IRAM variables */
675 #define PLUGIN_IRAM_DECLARE \
676 extern char iramcopy[]; \
677 extern char iramstart[]; \
678 extern char iramend[]; \
679 extern char iedata[]; \
680 extern char iend[];
681 /* Initialize IRAM */
682 #define PLUGIN_IRAM_INIT(api) \
683 (api)->plugin_iram_init(iramstart, iramcopy, iramend-iramstart, \
684 iedata, iend-iedata);
685 #else
686 #define PLUGIN_IRAM_DECLARE
687 #define PLUGIN_IRAM_INIT(api)
688 #endif /* USE_IRAM */
689 #endif /* PLUGIN */
691 int plugin_load(const char* plugin, void* parameter);
692 void* plugin_get_buffer(size_t *buffer_size);
693 void* plugin_get_audio_buffer(size_t *buffer_size);
694 #ifdef IRAM_STEAL
695 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
696 char *iedata, size_t iedata_size);
697 #endif
699 /* plugin_tsr,
700 callback returns true to allow the new plugin to load,
701 reenter means the currently running plugin is being reloaded */
702 void plugin_tsr(bool (*exit_callback)(bool reenter));
704 /* defined by the plugin */
705 enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter)
706 NO_PROF_ATTR;
708 /* Use this macro in plugins where gcc tries to optimize by calling
709 * these functions directly */
710 #define MEM_FUNCTION_WRAPPERS(api) \
711 void *memcpy(void *dest, const void *src, size_t n) \
713 return (api)->memcpy(dest, src, n); \
715 void *memset(void *dest, int c, size_t n) \
717 return (api)->memset(dest, c, n); \
719 void *memmove(void *dest, const void *src, size_t n) \
721 return (api)->memmove(dest, src, n); \
723 int memcmp(const void *s1, const void *s2, size_t n) \
725 return (api)->memcmp(s1, s2, n); \
728 #ifndef CACHE_FUNCTION_WRAPPERS
730 #ifdef CACHE_FUNCTIONS_AS_CALL
731 #define CACHE_FUNCTION_WRAPPERS(api) \
732 void flush_icache(void) \
734 (api)->flush_icache(); \
736 void invalidate_icache(void) \
738 (api)->invalidate_icache(); \
740 #else
741 #define CACHE_FUNCTION_WRAPPERS(api)
742 #endif /* CACHE_FUNCTIONS_AS_CALL */
744 #endif /* CACHE_FUNCTION_WRAPPERS */
746 #endif