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 ****************************************************************************/
23 #include <timefuncs.h>
41 #include "mp3_playback.h"
42 #include "backlight.h"
46 #include "powermgmt.h"
51 #if (CONFIG_CODEC == SWCODEC)
52 #include "pcm_playback.h"
55 #ifdef HAVE_LCD_BITMAP
56 #include "peakmeter.h"
61 #ifdef HAVE_REMOTE_LCD
62 #include "lcd-remote.h"
66 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
67 void *sim_plugin_load(char *plugin
, int *fd
);
68 void sim_plugin_close(int fd
);
70 #define sim_plugin_close(x)
71 extern unsigned char pluginbuf
[];
75 /* for actual plugins only, not for codecs */
76 static bool plugin_loaded
= false;
77 static int plugin_size
= 0;
78 static void (*pfn_tsr_exit
)(void) = NULL
; /* TSR exit callback */
80 static int plugin_test(int api_version
, int model
, int memsize
);
82 static const struct plugin_api rockbox_api
= {
93 #ifdef HAVE_LCD_CHARCELLS
95 lcd_get_locked_pattern
,
116 lcd_mono_bitmap_part
,
128 lcd_puts_scroll_style
,
129 &lcd_framebuffer
[0][0],
140 backlight_set_timeout
,
142 #ifdef HAVE_REMOTE_LCD
144 lcd_remote_set_contrast
,
145 lcd_remote_clear_display
,
147 lcd_remote_puts_scroll
,
148 lcd_remote_stop_scroll
,
152 lcd_remote_set_drawmode
,
153 lcd_remote_get_drawmode
,
155 lcd_remote_getstringsize
,
156 lcd_remote_drawpixel
,
162 lcd_remote_mono_bitmap_part
,
163 lcd_remote_mono_bitmap
,
165 lcd_remote_puts_style
,
166 lcd_remote_puts_scroll_style
,
167 &lcd_remote_framebuffer
[0][0],
169 lcd_remote_update_rect
,
171 lcd_remote_backlight_on
,
172 lcd_remote_backlight_off
,
179 #if CONFIG_KEYPAD == IRIVER_H100_PAD
184 (open_func
)PREFIX(open
),
188 (creat_func
)PREFIX(creat
),
211 default_event_handler
,
212 default_event_handler_ex
,
215 reset_poweroff_timer
,
219 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
227 /* strings and memory */
253 #if CONFIG_CODEC != SWCODEC
256 #if CONFIG_CODEC == SWCODEC
265 /* playback control */
276 audio_has_changed_track
,
278 audio_flush_and_reload_tracks
,
280 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
281 mpeg_get_last_header
,
283 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
287 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
288 /* MAS communication */
293 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
297 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
304 /* runtime database */
317 plugin_get_audio_buffer
,
319 #if defined(DEBUG) || defined(SIMULATOR)
322 #ifdef ROCKBOX_HAS_LOGF
332 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
333 peak_meter_scale_value
,
334 peak_meter_set_use_dbfs
,
335 peak_meter_get_use_dbfs
,
337 #ifdef HAVE_LCD_BITMAP
342 /* new stuff at the end, sort into place next time
343 the API gets incompatible */
359 #ifdef HAVE_LCD_BITMAP
360 screen_dump_set_hook
,
364 int plugin_load(const char* plugin
, void* parameter
)
366 enum plugin_status (*plugin_start
)(struct plugin_api
* api
, void* param
);
373 #ifdef HAVE_LCD_BITMAP
377 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
379 pfn_tsr_exit(); /* force it to exit now */
383 #ifdef HAVE_LCD_BITMAP
385 xm
= lcd_getxmargin();
386 ym
= lcd_getymargin();
393 plugin_start
= sim_plugin_load((char *)plugin
, &fd
);
397 fd
= open(plugin
, O_RDONLY
);
399 snprintf(buf
, sizeof buf
, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
400 splash(HZ
*2, true, buf
);
404 /* zero out plugin buffer to ensure a properly zeroed bss area */
405 memset(pluginbuf
, 0, PLUGIN_BUFFER_SIZE
);
407 plugin_start
= (void*)&pluginbuf
;
408 plugin_size
= read(fd
, plugin_start
, PLUGIN_BUFFER_SIZE
);
410 if (plugin_size
< 0) {
412 snprintf(buf
, sizeof buf
, str(LANG_READ_FAILED
), plugin
);
413 splash(HZ
*2, true, buf
);
416 if (plugin_size
== 0) {
417 /* loaded a 0-byte plugin, implying it's not for this model */
418 splash(HZ
*2, true, str(LANG_PLUGIN_WRONG_MODEL
));
423 plugin_loaded
= true;
427 rc
= plugin_start((struct plugin_api
*) &rockbox_api
, parameter
);
428 /* explicitly casting the pointer here to avoid touching every plugin. */
430 button_clear_queue();
431 #ifdef HAVE_LCD_BITMAP
433 lcd_set_drawinfo(DRMODE_SOLID
, LCD_BLACK
, LCD_WHITE
);
434 #else /* LCD_DEPTH == 1 */
435 lcd_set_drawmode(DRMODE_SOLID
);
436 #endif /* LCD_DEPTH */
437 #endif /* HAVE_LCD_BITMAP */
439 plugin_loaded
= false;
445 case PLUGIN_USB_CONNECTED
:
446 return PLUGIN_USB_CONNECTED
;
448 case PLUGIN_WRONG_API_VERSION
:
449 splash(HZ
*2, true, str(LANG_PLUGIN_WRONG_VERSION
));
452 case PLUGIN_WRONG_MODEL
:
453 splash(HZ
*2, true, str(LANG_PLUGIN_WRONG_MODEL
));
457 splash(HZ
*2, true, str(LANG_PLUGIN_ERROR
));
461 sim_plugin_close(fd
);
463 #ifdef HAVE_LCD_BITMAP
464 /* restore margins */
465 lcd_setmargins(xm
,ym
);
471 /* Returns a pointer to the portion of the plugin buffer that is not already
472 being used. If no plugin is loaded, returns the entire plugin buffer */
473 void* plugin_get_buffer(int* buffer_size
)
479 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
482 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
483 buffer_pos
= plugin_size
;
487 *buffer_size
= PLUGIN_BUFFER_SIZE
;
491 return &pluginbuf
[buffer_pos
];
494 /* Returns a pointer to the mp3 buffer.
495 Playback gets stopped, to avoid conflicts. */
496 void* plugin_get_audio_buffer(int* buffer_size
)
499 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
500 *buffer_size
= audiobufend
- audiobuf
;
504 /* The plugin wants to stay resident after leaving its main function, e.g.
505 runs from timer or own thread. The callback is registered to later
506 instruct it to free its resources before a new plugin gets loaded. */
507 void plugin_tsr(void (*exit_callback
)(void))
509 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
513 static int plugin_test(int api_version
, int model
, int memsize
)
515 if (api_version
< PLUGIN_MIN_API_VERSION
||
516 api_version
> PLUGIN_API_VERSION
)
517 return PLUGIN_WRONG_API_VERSION
;
520 return PLUGIN_WRONG_MODEL
;
523 return PLUGIN_WRONG_MODEL
;