1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
22 /* instruct simulator code to not redefine any symbols when compiling plugins.
23 (the PLUGIN macro is defined in apps/plugins/Makefile) */
25 #define NO_REDEFINES_PLEASE
36 #include <sys/types.h>
48 #include "mp3_playback.h"
54 #if (CONFIG_CODEC == SWCODEC)
55 #include "pcm_playback.h"
64 #ifdef HAVE_LCD_BITMAP
69 #include "rbunicode.h"
72 #ifdef HAVE_REMOTE_LCD
73 #include "lcd-remote.h"
78 #if defined(DEBUG) || defined(SIMULATOR)
80 #define DEBUGF rb->debugf
82 #define LDEBUGF rb->debugf
88 #ifdef ROCKBOX_HAS_LOGF
98 #define PREFIX(_x_) sim_ ## _x_
100 #define PREFIX(_x_) _x_
103 #define PLUGIN_MAGIC 0x526F634B /* RocK */
105 /* increase this every time the api struct changes */
106 #define PLUGIN_API_VERSION 19
108 /* update this to latest version if a change to the api struct breaks
109 backwards compatibility (and please take the opportunity to sort in any
110 new function which are "waiting" at the end of the function table) */
111 #define PLUGIN_MIN_API_VERSION 14
113 /* plugin return codes */
116 PLUGIN_USB_CONNECTED
,
120 /* NOTE: To support backwards compatibility, only add new functions at
121 the end of the structure. Every time you add a new function,
122 remember to increase PLUGIN_API_VERSION. If you make changes to the
123 existing APIs then also update PLUGIN_MIN_API_VERSION to current
129 void (*lcd_set_contrast
)(int x
);
130 void (*lcd_clear_display
)(void);
131 void (*lcd_puts
)(int x
, int y
, const unsigned char *string
);
132 void (*lcd_puts_scroll
)(int x
, int y
, const unsigned char* string
);
133 void (*lcd_stop_scroll
)(void);
134 #ifdef HAVE_LCD_CHARCELLS
135 void (*lcd_define_pattern
)(int which
,const char *pattern
);
136 unsigned char (*lcd_get_locked_pattern
)(void);
137 void (*lcd_unlock_pattern
)(unsigned char pat
);
138 void (*lcd_putc
)(int x
, int y
, unsigned short ch
);
139 void (*lcd_put_cursor
)(int x
, int y
, char cursor_char
);
140 void (*lcd_remove_cursor
)(void);
141 void (*PREFIX(lcd_icon
))(int icon
, bool enable
);
142 void (*lcd_double_height
)(bool on
);
144 void (*lcd_set_drawmode
)(int mode
);
145 int (*lcd_get_drawmode
)(void);
146 void (*lcd_setfont
)(int font
);
147 int (*lcd_getstringsize
)(const unsigned char *str
, int *w
, int *h
);
148 void (*lcd_drawpixel
)(int x
, int y
);
149 void (*lcd_drawline
)(int x1
, int y1
, int x2
, int y2
);
150 void (*lcd_hline
)(int x1
, int x2
, int y
);
151 void (*lcd_vline
)(int x
, int y1
, int y2
);
152 void (*lcd_drawrect
)(int x
, int y
, int width
, int height
);
153 void (*lcd_fillrect
)(int x
, int y
, int width
, int height
);
154 void (*lcd_mono_bitmap_part
)(const unsigned char *src
, int src_x
, int src_y
,
155 int stride
, int x
, int y
, int width
, int height
);
156 void (*lcd_mono_bitmap
)(const unsigned char *src
, int x
, int y
,
157 int width
, int height
);
159 void (*lcd_set_foreground
)(unsigned foreground
);
160 unsigned (*lcd_get_foreground
)(void);
161 void (*lcd_set_background
)(unsigned foreground
);
162 unsigned (*lcd_get_background
)(void);
163 void (*lcd_bitmap_part
)(const fb_data
*src
, int src_x
, int src_y
,
164 int stride
, int x
, int y
, int width
, int height
);
165 void (*lcd_bitmap
)(const fb_data
*src
, int x
, int y
, int width
,
169 void (*lcd_bitmap_transparent_part
)(const fb_data
*src
,
170 int src_x
, int src_y
, int stride
,
171 int x
, int y
, int width
, int height
);
172 void (*lcd_bitmap_transparent
)(const fb_data
*src
, int x
, int y
,
173 int width
, int height
);
175 void (*lcd_putsxy
)(int x
, int y
, const unsigned char *string
);
176 void (*lcd_puts_style
)(int x
, int y
, const unsigned char *str
, int style
);
177 void (*lcd_puts_scroll_style
)(int x
, int y
, const unsigned char* string
,
179 fb_data
* lcd_framebuffer
;
180 void (*lcd_blit
) (const fb_data
* data
, int x
, int by
, int width
,
181 int bheight
, int stride
);
182 void (*lcd_update
)(void);
183 void (*lcd_update_rect
)(int x
, int y
, int width
, int height
);
184 void (*scrollbar
)(int x
, int y
, int width
, int height
, int items
,
185 int min_shown
, int max_shown
, int orientation
);
186 void (*checkbox
)(int x
, int y
, int width
, int height
, bool checked
);
187 struct font
* (*font_get
)(int font
);
188 int (*font_getstringsize
)(const unsigned char *str
, int *w
, int *h
,
190 int (*font_get_width
)(struct font
* pf
, unsigned short char_code
);
192 void (*backlight_on
)(void);
193 void (*backlight_off
)(void);
194 void (*backlight_set_timeout
)(int index
);
195 void (*splash
)(int ticks
, bool center
, const unsigned char *fmt
, ...);
197 #ifdef HAVE_REMOTE_LCD
199 void (*lcd_remote_set_contrast
)(int x
);
200 void (*lcd_remote_clear_display
)(void);
201 void (*lcd_remote_puts
)(int x
, int y
, const unsigned char *string
);
202 void (*lcd_remote_lcd_puts_scroll
)(int x
, int y
, const unsigned char* string
);
203 void (*lcd_remote_lcd_stop_scroll
)(void);
204 void (*lcd_remote_set_drawmode
)(int mode
);
205 int (*lcd_remote_get_drawmode
)(void);
206 void (*lcd_remote_setfont
)(int font
);
207 int (*lcd_remote_getstringsize
)(const unsigned char *str
, int *w
, int *h
);
208 void (*lcd_remote_drawpixel
)(int x
, int y
);
209 void (*lcd_remote_drawline
)(int x1
, int y1
, int x2
, int y2
);
210 void (*lcd_remote_hline
)(int x1
, int x2
, int y
);
211 void (*lcd_remote_vline
)(int x
, int y1
, int y2
);
212 void (*lcd_remote_drawrect
)(int x
, int y
, int nx
, int ny
);
213 void (*lcd_remote_fillrect
)(int x
, int y
, int nx
, int ny
);
214 void (*lcd_remote_mono_bitmap_part
)(const unsigned char *src
, int src_x
,
215 int src_y
, int stride
, int x
, int y
,
216 int width
, int height
);
217 void (*lcd_remote_mono_bitmap
)(const unsigned char *src
, int x
, int y
,
218 int width
, int height
);
219 void (*lcd_remote_putsxy
)(int x
, int y
, const unsigned char *string
);
220 void (*lcd_remote_puts_style
)(int x
, int y
, const unsigned char *str
, int style
);
221 void (*lcd_remote_puts_scroll_style
)(int x
, int y
, const unsigned char* string
,
223 unsigned char* lcd_remote_framebuffer
;
224 void (*lcd_remote_update
)(void);
225 void (*lcd_remote_update_rect
)(int x
, int y
, int width
, int height
);
227 void (*remote_backlight_on
)(void);
228 void (*remote_backlight_off
)(void);
232 long (*button_get
)(bool block
);
233 long (*button_get_w_tmo
)(int ticks
);
234 int (*button_status
)(void);
235 void (*button_clear_queue
)(void);
236 #ifdef HAS_BUTTON_HOLD
237 bool (*button_hold
)(void);
241 int (*PREFIX(open
))(const char* pathname
, int flags
);
242 int (*close
)(int fd
);
243 ssize_t (*read
)(int fd
, void* buf
, size_t count
);
244 off_t (*PREFIX(lseek
))(int fd
, off_t offset
, int whence
);
245 int (*PREFIX(creat
))(const char *pathname
, mode_t mode
);
246 ssize_t (*write
)(int fd
, const void* buf
, size_t count
);
247 int (*PREFIX(remove
))(const char* pathname
);
248 int (*PREFIX(rename
))(const char* path
, const char* newname
);
249 int (*PREFIX(ftruncate
))(int fd
, off_t length
);
250 off_t (*PREFIX(filesize
))(int fd
);
251 int (*fdprintf
)(int fd
, const char *fmt
, ...);
252 int (*read_line
)(int fd
, char* buffer
, int buffer_size
);
253 bool (*settings_parseline
)(char* line
, char** name
, char** value
);
255 void (*ata_sleep
)(void);
256 bool (*ata_disk_is_active
)(void);
260 DIR* (*PREFIX(opendir
))(const char* name
);
261 int (*PREFIX(closedir
))(DIR* dir
);
262 struct dirent
* (*PREFIX(readdir
))(DIR* dir
);
263 int (*PREFIX(mkdir
))(const char *name
, int mode
);
266 void (*PREFIX(sleep
))(int ticks
);
269 long (*default_event_handler
)(long event
);
270 long (*default_event_handler_ex
)(long event
, void (*callback
)(void *), void *parameter
);
271 int (*create_thread
)(void (*function
)(void), void* stack
, int stack_size
, const char *name
);
272 void (*remove_thread
)(int threadnum
);
273 void (*reset_poweroff_timer
)(void);
275 int (*system_memory_guard
)(int newmode
);
277 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
278 void (*cpu_boost
)(bool on_off
);
280 bool (*timer_register
)(int reg_prio
, void (*unregister_callback
)(void),
281 long cycles
, int int_prio
,
282 void (*timer_callback
)(void));
283 void (*timer_unregister
)(void);
284 bool (*timer_set_period
)(long count
);
286 void (*queue_init
)(struct event_queue
*q
);
287 void (*queue_delete
)(struct event_queue
*q
);
288 void (*queue_post
)(struct event_queue
*q
, long id
, void *data
);
289 void (*queue_wait_w_tmo
)(struct event_queue
*q
, struct event
*ev
,
291 void (*usb_acknowledge
)(long id
);
293 void (*profile_thread
)(void);
294 void (*profstop
)(void);
295 void (*profile_func_enter
)(void *this_fn
, void *call_site
);
296 void (*profile_func_exit
)(void *this_fn
, void *call_site
);
300 /* special simulator hooks */
301 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
302 void (*sim_lcd_ex_init
)(int shades
, unsigned long (*getpixel
)(int, int));
303 void (*sim_lcd_ex_update_rect
)(int x
, int y
, int width
, int height
);
307 /* strings and memory */
308 int (*snprintf
)(char *buf
, size_t size
, const char *fmt
, ...);
309 char* (*strcpy
)(char *dst
, const char *src
);
310 char* (*strncpy
)(char *dst
, const char *src
, size_t length
);
311 size_t (*strlen
)(const char *str
);
312 char * (*strrchr
)(const char *s
, int c
);
313 int (*strcmp
)(const char *, const char *);
314 int (*strncmp
)(const char *, const char *, size_t);
315 int (*strcasecmp
)(const char *, const char *);
316 int (*strncasecmp
)(const char *s1
, const char *s2
, size_t n
);
317 void* (*memset
)(void *dst
, int c
, size_t length
);
318 void* (*memcpy
)(void *out
, const void *in
, size_t n
);
319 void* (*memmove
)(void *out
, const void *in
, size_t n
);
320 const unsigned char *_ctype_
;
321 int (*atoi
)(const char *str
);
322 char *(*strchr
)(const char *s
, int c
);
323 char *(*strcat
)(char *s1
, const char *s2
);
324 int (*memcmp
)(const void *s1
, const void *s2
, size_t n
);
325 char *(*strcasestr
) (const char* phaystack
, const char* pneedle
);
327 const unsigned char* (*utf8decode
)(const unsigned char *utf8
, unsigned short *ucs
);
328 unsigned char* (*iso_decode
)(const unsigned char *iso
, unsigned char *utf8
, int cp
, int count
);
329 unsigned char* (*utf16LEdecode
)(const unsigned char *utf16
, unsigned char *utf8
, unsigned int count
);
330 unsigned char* (*utf16BEdecode
)(const unsigned char *utf16
, unsigned char *utf8
, unsigned int count
);
331 unsigned char* (*utf8encode
)(unsigned long ucs
, unsigned char *utf8
);
332 unsigned long (*utf8length
)(const unsigned char *utf8
);
335 void (*sound_set
)(int setting
, int value
);
336 int (*sound_min
)(int setting
);
337 int (*sound_max
)(int setting
);
339 void (*mp3_play_data
)(const unsigned char* start
, int size
, void (*get_more
)(unsigned char** start
, int* size
));
340 void (*mp3_play_pause
)(bool play
);
341 void (*mp3_play_stop
)(void);
342 bool (*mp3_is_playing
)(void);
343 #if CONFIG_CODEC != SWCODEC
344 void (*bitswap
)(unsigned char *data
, int length
);
346 #if CONFIG_CODEC == SWCODEC
347 void (*pcm_play_data
)(void (*get_more
)(unsigned char** start
, size_t*size
),
348 unsigned char* start
, size_t size
);
349 void (*pcm_play_stop
)(void);
350 void (*pcm_set_frequency
)(unsigned int frequency
);
351 bool (*pcm_is_playing
)(void);
352 void (*pcm_play_pause
)(bool play
);
354 #endif /* !SIMULATOR */
355 #if CONFIG_CODEC == SWCODEC
356 void (*pcm_calculate_peaks
)(int *left
, int *right
);
359 /* playback control */
360 void (*PREFIX(audio_play
))(long offset
);
361 void (*audio_stop
)(void);
362 void (*audio_pause
)(void);
363 void (*audio_resume
)(void);
364 void (*audio_next
)(void);
365 void (*audio_prev
)(void);
366 void (*audio_ff_rewind
)(long newtime
);
367 struct mp3entry
* (*audio_next_track
)(void);
368 int (*playlist_amount
)(void);
369 int (*audio_status
)(void);
370 bool (*audio_has_changed_track
)(void);
371 struct mp3entry
* (*audio_current_track
)(void);
372 void (*audio_flush_and_reload_tracks
)(void);
373 int (*audio_get_file_pos
)(void);
374 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
375 unsigned long (*mpeg_get_last_header
)(void);
377 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
378 (CONFIG_CODEC == SWCODEC)
379 void (*sound_set_pitch
)(int pitch
);
382 /* MAS communication */
383 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
384 int (*mas_readmem
)(int bank
, int addr
, unsigned long* dest
, int len
);
385 int (*mas_writemem
)(int bank
, int addr
, const unsigned long* src
, int len
);
386 int (*mas_readreg
)(int reg
);
387 int (*mas_writereg
)(int reg
, unsigned int val
);
388 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
389 int (*mas_codec_writereg
)(int reg
, unsigned int val
);
390 int (*mas_codec_readreg
)(int reg
);
395 int (*menu_init
)(const struct menu_item
* mitems
, int count
,
396 int (*callback
)(int, int),
397 const char *button1
, const char *button2
, const char *button3
);
398 void (*menu_exit
)(int menu
);
399 int (*menu_show
)(int m
);
400 bool (*menu_run
)(int menu
);
401 int (*menu_cursor
)(int menu
);
402 char* (*menu_description
)(int menu
, int position
);
403 void (*menu_delete
)(int menu
, int position
);
404 int (*menu_count
)(int menu
);
405 bool (*menu_moveup
)(int menu
);
406 bool (*menu_movedown
)(int menu
);
407 void (*menu_draw
)(int menu
);
408 void (*menu_insert
)(int menu
, int position
, char *desc
, bool (*function
) (void));
409 void (*menu_set_cursor
)(int menu
, int position
);
411 bool (*set_option
)(const char* string
, void* variable
,
412 enum optiontype type
, const struct opt_items
* options
,
413 int numoptions
, void (*function
)(int));
417 int (*battery_level
)(void);
418 bool (*battery_level_safe
)(void);
419 int (*battery_time
)(void);
421 unsigned int (*battery_voltage
)(void);
424 bool (*charger_inserted
)(void);
425 # ifdef HAVE_CHARGE_STATE
426 bool (*charging_state
)(void);
429 #ifdef HAVE_USB_POWER
430 bool (*usb_powered
)(void);
434 void (*srand
)(unsigned int seed
);
436 void (*qsort
)(void *base
, size_t nmemb
, size_t size
,
437 int(*compar
)(const void *, const void *));
438 int (*kbd_input
)(char* buffer
, int buflen
);
439 struct tm
* (*get_time
)(void);
440 int (*set_time
)(const struct tm
*tm
);
441 void* (*plugin_get_buffer
)(int* buffer_size
);
442 void* (*plugin_get_audio_buffer
)(int* buffer_size
);
443 void (*plugin_tsr
)(void (*exit_callback
)(void));
444 #if defined(DEBUG) || defined(SIMULATOR)
445 void (*debugf
)(const char *fmt
, ...);
447 #ifdef ROCKBOX_HAS_LOGF
448 void (*logf
)(const char *fmt
, ...);
450 struct user_settings
* global_settings
;
451 bool (*mp3info
)(struct mp3entry
*entry
, const char *filename
, bool v1first
);
452 int (*count_mp3_frames
)(int fd
, int startpos
, int filesize
,
453 void (*progressfunc
)(int));
454 int (*create_xing_header
)(int fd
, long startpos
, long filesize
,
455 unsigned char *buf
, unsigned long num_frames
,
456 unsigned long rec_time
, unsigned long header_template
,
457 void (*progressfunc
)(int), bool generate_toc
);
458 unsigned long (*find_next_frame
)(int fd
, long *offset
,
459 long max_offset
, unsigned long last_header
);
461 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
462 unsigned short (*peak_meter_scale_value
)(unsigned short val
,
464 void (*peak_meter_set_use_dbfs
)(bool use
);
465 bool (*peak_meter_get_use_dbfs
)(void);
467 #ifdef HAVE_LCD_BITMAP
468 int (*read_bmp_file
)(char* filename
, struct bitmap
*bm
, int maxsize
,
470 void (*screen_dump_set_hook
)(void (*hook
)(int fh
));
472 int (*show_logo
)(void);
473 struct tree_context
* (*tree_get_context
)(void);
475 /* new stuff at the end, sort into place next time
476 the API gets incompatible */
477 bool (*set_sound
)(const unsigned char * string
,
478 int* variable
, int setting
);
479 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)) && !defined(SIMULATOR)
480 void (*i2c_begin
)(void);
481 void (*i2c_end
)(void);
482 int (*i2c_write
)(int address
, unsigned char* buf
, int count
);
485 int (*vsnprintf
)(char *buf
, int size
, const char *fmt
, va_list ap
);
486 void *(*memchr
)(const void *s1
, int c
, size_t n
);
489 void (*gui_synclist_init
)(struct gui_synclist
* lists
,
490 list_get_name callback_get_item_name
,void * data
);
491 void (*gui_synclist_set_nb_items
)(struct gui_synclist
* lists
, int nb_items
);
492 void (*gui_synclist_set_icon_callback
)(struct gui_synclist
* lists
, list_get_icon icon_callback
);
493 int (*gui_synclist_get_nb_items
)(struct gui_synclist
* lists
);
494 int (*gui_synclist_get_sel_pos
)(struct gui_synclist
* lists
);
495 void (*gui_synclist_draw
)(struct gui_synclist
* lists
);
496 void (*gui_synclist_select_item
)(struct gui_synclist
* lists
,
498 void (*gui_synclist_select_next
)(struct gui_synclist
* lists
);
499 void (*gui_synclist_select_previous
)(struct gui_synclist
* lists
);
500 void (*gui_synclist_select_next_page
)(struct gui_synclist
* lists
,
501 enum screen_type screen
);
502 void (*gui_synclist_select_previous_page
)(struct gui_synclist
* lists
,
503 enum screen_type screen
);
504 void (*gui_synclist_add_item
)(struct gui_synclist
* lists
);
505 void (*gui_synclist_del_item
)(struct gui_synclist
* lists
);
506 void (*gui_synclist_limit_scroll
)(struct gui_synclist
* lists
, bool scroll
);
507 void (*gui_synclist_flash
)(struct gui_synclist
* lists
);
508 #ifdef HAVE_LCD_BITMAP
509 void (*gui_synclist_scroll_right
)(struct gui_synclist
* lists
);
510 void (*gui_synclist_scroll_left
)(struct gui_synclist
* lists
);
512 unsigned (*gui_synclist_do_button
)(struct gui_synclist
* lists
, unsigned button
);
514 #ifdef HAVE_LCD_BITMAP
515 void (*lcd_setmargins
)(int x
, int y
);
520 struct plugin_header
{
522 unsigned short target_id
;
523 unsigned short api_version
;
524 unsigned char *load_addr
;
525 unsigned char *end_addr
;
526 enum plugin_status(*entry_point
)(struct plugin_api
*, void*);
530 extern unsigned char plugin_start_addr
[];
531 extern unsigned char plugin_end_addr
[];
532 #define PLUGIN_HEADER \
533 const struct plugin_header __header \
534 __attribute__ ((section (".header")))= { \
535 PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
536 plugin_start_addr, plugin_end_addr, plugin_start };
537 #else /* SIMULATOR */
538 #define PLUGIN_HEADER \
539 const struct plugin_header __header = { \
540 PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
541 NULL, NULL, plugin_start };
545 int plugin_load(const char* plugin
, void* parameter
);
546 void* plugin_get_buffer(int *buffer_size
);
547 void* plugin_get_audio_buffer(int *buffer_size
);
548 void plugin_tsr(void (*exit_callback
)(void));
550 /* defined by the plugin */
551 enum plugin_status
plugin_start(struct plugin_api
* rockbox
, void* parameter
)