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