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_HWCODEC == MASNONE)
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
,
115 lcd_mono_bitmap_part
,
127 lcd_puts_scroll_style
,
128 &lcd_framebuffer
[0][0],
139 backlight_set_timeout
,
141 #ifdef HAVE_REMOTE_LCD
143 lcd_remote_set_contrast
,
144 lcd_remote_clear_display
,
146 lcd_remote_puts_scroll
,
147 lcd_remote_stop_scroll
,
151 lcd_remote_set_drawmode
,
152 lcd_remote_get_drawmode
,
154 lcd_remote_getstringsize
,
155 lcd_remote_drawpixel
,
161 lcd_remote_mono_bitmap_part
,
162 lcd_remote_mono_bitmap
,
164 lcd_remote_puts_style
,
165 lcd_remote_puts_scroll_style
,
166 &lcd_remote_framebuffer
[0][0],
168 lcd_remote_update_rect
,
170 lcd_remote_backlight_on
,
171 lcd_remote_backlight_off
,
178 #if CONFIG_KEYPAD == IRIVER_H100_PAD
183 (open_func
)PREFIX(open
),
187 (creat_func
)PREFIX(creat
),
210 default_event_handler
,
211 default_event_handler_ex
,
214 reset_poweroff_timer
,
218 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
226 /* strings and memory */
252 #if CONFIG_HWCODEC != MASNONE
255 #if CONFIG_HWCODEC == MASNONE
264 /* playback control */
275 audio_has_changed_track
,
277 audio_flush_and_reload_tracks
,
279 #if !defined(SIMULATOR) && (CONFIG_HWCODEC != MASNONE)
280 mpeg_get_last_header
,
282 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
286 #if !defined(SIMULATOR) && (CONFIG_HWCODEC != MASNONE)
287 /* MAS communication */
292 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
296 #endif /* !simulator and HWCODEC != MASNONE */
303 /* runtime database */
316 plugin_get_audio_buffer
,
318 #if defined(DEBUG) || defined(SIMULATOR)
321 #ifdef ROCKBOX_HAS_LOGF
331 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
332 peak_meter_scale_value
,
333 peak_meter_set_use_dbfs
,
334 peak_meter_get_use_dbfs
,
336 #ifdef HAVE_LCD_BITMAP
340 /* new stuff at the end, sort into place next time
341 the API gets incompatible */
345 int plugin_load(const char* plugin
, void* parameter
)
347 enum plugin_status (*plugin_start
)(struct plugin_api
* api
, void* param
);
354 #ifdef HAVE_LCD_BITMAP
358 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
360 pfn_tsr_exit(); /* force it to exit now */
364 #ifdef HAVE_LCD_BITMAP
366 xm
= lcd_getxmargin();
367 ym
= lcd_getymargin();
374 plugin_start
= sim_plugin_load((char *)plugin
, &fd
);
378 fd
= open(plugin
, O_RDONLY
);
380 snprintf(buf
, sizeof buf
, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
381 splash(HZ
*2, true, buf
);
385 /* zero out plugin buffer to ensure a properly zeroed bss area */
386 memset(pluginbuf
, 0, PLUGIN_BUFFER_SIZE
);
388 plugin_start
= (void*)&pluginbuf
;
389 plugin_size
= read(fd
, plugin_start
, PLUGIN_BUFFER_SIZE
);
391 if (plugin_size
< 0) {
393 snprintf(buf
, sizeof buf
, str(LANG_READ_FAILED
), plugin
);
394 splash(HZ
*2, true, buf
);
397 if (plugin_size
== 0) {
398 /* loaded a 0-byte plugin, implying it's not for this model */
399 splash(HZ
*2, true, str(LANG_PLUGIN_WRONG_MODEL
));
404 plugin_loaded
= true;
408 rc
= plugin_start((struct plugin_api
*) &rockbox_api
, parameter
);
409 /* explicitly casting the pointer here to avoid touching every plugin. */
411 button_clear_queue();
412 #ifdef HAVE_LCD_BITMAP
414 lcd_set_drawinfo(DRMODE_SOLID
, LCD_BLACK
, LCD_WHITE
);
415 #else /* LCD_DEPTH == 1 */
416 lcd_set_drawmode(DRMODE_SOLID
);
417 #endif /* LCD_DEPTH */
418 #endif /* HAVE_LCD_BITMAP */
420 plugin_loaded
= false;
426 case PLUGIN_USB_CONNECTED
:
427 return PLUGIN_USB_CONNECTED
;
429 case PLUGIN_WRONG_API_VERSION
:
430 splash(HZ
*2, true, str(LANG_PLUGIN_WRONG_VERSION
));
433 case PLUGIN_WRONG_MODEL
:
434 splash(HZ
*2, true, str(LANG_PLUGIN_WRONG_MODEL
));
438 splash(HZ
*2, true, str(LANG_PLUGIN_ERROR
));
442 sim_plugin_close(fd
);
444 #ifdef HAVE_LCD_BITMAP
445 /* restore margins */
446 lcd_setmargins(xm
,ym
);
452 /* Returns a pointer to the portion of the plugin buffer that is not already
453 being used. If no plugin is loaded, returns the entire plugin buffer */
454 void* plugin_get_buffer(int* buffer_size
)
460 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
463 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
464 buffer_pos
= plugin_size
;
468 *buffer_size
= PLUGIN_BUFFER_SIZE
;
472 return &pluginbuf
[buffer_pos
];
475 /* Returns a pointer to the mp3 buffer.
476 Playback gets stopped, to avoid conflicts. */
477 void* plugin_get_audio_buffer(int* buffer_size
)
480 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
481 *buffer_size
= audiobufend
- audiobuf
;
485 /* The plugin wants to stay resident after leaving its main function, e.g.
486 runs from timer or own thread. The callback is registered to later
487 instruct it to free its resources before a new plugin gets loaded. */
488 void plugin_tsr(void (*exit_callback
)(void))
490 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
494 static int plugin_test(int api_version
, int model
, int memsize
)
496 if (api_version
< PLUGIN_MIN_API_VERSION
||
497 api_version
> PLUGIN_API_VERSION
)
498 return PLUGIN_WRONG_API_VERSION
;
501 return PLUGIN_WRONG_MODEL
;
504 return PLUGIN_WRONG_MODEL
;