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