FS9795 - some playback cleanup.
[kugel-rb.git] / apps / plugin.c
blob17e9ac670b98ee93297216131f5e81c76817b6e7
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 #include "plugin.h"
22 #include <ctype.h>
23 #include <string.h>
24 #include <sprintf.h>
25 #include <stdlib.h>
26 #include "debug.h"
27 #include "i2c.h"
28 #include "lang.h"
29 #include "led.h"
30 #include "keyboard.h"
31 #include "buffer.h"
32 #include "backlight.h"
33 #include "sound_menu.h"
34 #include "mp3data.h"
35 #include "powermgmt.h"
36 #include "splash.h"
37 #include "logf.h"
38 #include "option_select.h"
39 #include "talk.h"
40 #include "version.h"
41 #include "storage.h"
43 #if CONFIG_CHARGING
44 #include "power.h"
45 #endif
47 #ifdef HAVE_LCD_BITMAP
48 #include "scrollbar.h"
49 #include "peakmeter.h"
50 #include "bmp.h"
51 #include "bidi.h"
52 #endif
54 #ifdef SIMULATOR
55 #define PREFIX(_x_) sim_ ## _x_
56 #else
57 #define PREFIX
58 #endif
60 #ifdef SIMULATOR
61 static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE];
62 void *sim_plugin_load(char *plugin, void **pd);
63 void sim_plugin_close(void *pd);
64 void sim_lcd_ex_init(unsigned long (*getpixel)(int, int));
65 void sim_lcd_ex_update_rect(int x, int y, int width, int height);
66 #else
67 #define sim_plugin_close(x)
68 extern unsigned char pluginbuf[];
69 #include "bitswap.h"
70 #endif
72 /* for actual plugins only, not for codecs */
73 static bool plugin_loaded = false;
74 static int plugin_size = 0;
75 static bool (*pfn_tsr_exit)(bool reenter) = NULL; /* TSR exit callback */
76 static char current_plugin[MAX_PATH];
78 char *plugin_get_current_filename(void);
80 static const struct plugin_api rockbox_api = {
82 /* lcd */
83 #ifdef HAVE_LCD_CONTRAST
84 lcd_set_contrast,
85 #endif
86 lcd_update,
87 lcd_clear_display,
88 lcd_getstringsize,
89 lcd_putsxy,
90 lcd_puts,
91 lcd_puts_scroll,
92 lcd_stop_scroll,
93 #ifdef HAVE_LCD_CHARCELLS
94 lcd_define_pattern,
95 lcd_get_locked_pattern,
96 lcd_unlock_pattern,
97 lcd_putc,
98 lcd_put_cursor,
99 lcd_remove_cursor,
100 lcd_icon,
101 lcd_double_height,
102 #else
103 &lcd_framebuffer[0][0],
104 lcd_update_rect,
105 lcd_set_drawmode,
106 lcd_get_drawmode,
107 lcd_setfont,
108 lcd_drawpixel,
109 lcd_drawline,
110 lcd_hline,
111 lcd_vline,
112 lcd_drawrect,
113 lcd_fillrect,
114 lcd_mono_bitmap_part,
115 lcd_mono_bitmap,
116 #if LCD_DEPTH > 1
117 lcd_set_foreground,
118 lcd_get_foreground,
119 lcd_set_background,
120 lcd_get_background,
121 lcd_bitmap_part,
122 lcd_bitmap,
123 lcd_get_backdrop,
124 lcd_set_backdrop,
125 #endif
126 #if LCD_DEPTH == 16
127 lcd_bitmap_transparent_part,
128 lcd_bitmap_transparent,
129 lcd_blit_yuv,
130 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
131 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630)
132 lcd_yuv_set_options,
133 #endif
134 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
135 lcd_blit_mono,
136 lcd_blit_grey_phase,
137 #endif /* LCD_DEPTH */
138 lcd_puts_style,
139 lcd_puts_scroll_style,
140 #ifdef HAVE_LCD_INVERT
141 lcd_set_invert_display,
142 #endif /* HAVE_LCD_INVERT */
143 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
144 lcd_activation_set_hook,
145 &button_queue,
146 #endif
147 bidi_l2v,
148 font_get_bits,
149 font_load,
150 font_get,
151 font_getstringsize,
152 font_get_width,
153 screen_clear_area,
154 gui_scrollbar_draw,
155 #endif /* HAVE_LCD_BITMAP */
156 get_codepage_name,
158 backlight_on,
159 backlight_off,
160 backlight_set_timeout,
161 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
162 backlight_set_brightness,
163 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
165 #if CONFIG_CHARGING
166 backlight_set_timeout_plugged,
167 #endif
168 is_backlight_on,
169 splash,
170 splashf,
172 #ifdef HAVE_REMOTE_LCD
173 /* remote lcd */
174 lcd_remote_set_contrast,
175 lcd_remote_clear_display,
176 lcd_remote_puts,
177 lcd_remote_puts_scroll,
178 lcd_remote_stop_scroll,
179 lcd_remote_set_drawmode,
180 lcd_remote_get_drawmode,
181 lcd_remote_setfont,
182 lcd_remote_getstringsize,
183 lcd_remote_drawpixel,
184 lcd_remote_drawline,
185 lcd_remote_hline,
186 lcd_remote_vline,
187 lcd_remote_drawrect,
188 lcd_remote_fillrect,
189 lcd_remote_mono_bitmap_part,
190 lcd_remote_mono_bitmap,
191 lcd_remote_putsxy,
192 lcd_remote_puts_style,
193 lcd_remote_puts_scroll_style,
194 &lcd_remote_framebuffer[0][0],
195 lcd_remote_update,
196 lcd_remote_update_rect,
198 remote_backlight_on,
199 remote_backlight_off,
200 remote_backlight_set_timeout,
201 #if CONFIG_CHARGING
202 remote_backlight_set_timeout_plugged,
203 #endif
204 #endif /* HAVE_REMOTE_LCD */
205 #if NB_SCREENS == 2
206 {&screens[SCREEN_MAIN], &screens[SCREEN_REMOTE]},
207 #else
208 {&screens[SCREEN_MAIN]},
209 #endif
210 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
211 lcd_remote_set_foreground,
212 lcd_remote_get_foreground,
213 lcd_remote_set_background,
214 lcd_remote_get_background,
215 lcd_remote_bitmap_part,
216 lcd_remote_bitmap,
217 #endif
218 viewport_set_defaults,
219 viewportmanager_set_statusbar,
221 /* list */
222 gui_synclist_init,
223 gui_synclist_set_nb_items,
224 gui_synclist_set_icon_callback,
225 gui_synclist_get_nb_items,
226 gui_synclist_get_sel_pos,
227 gui_synclist_draw,
228 gui_synclist_select_item,
229 gui_synclist_add_item,
230 gui_synclist_del_item,
231 gui_synclist_limit_scroll,
232 gui_synclist_do_button,
233 gui_synclist_set_title,
234 gui_syncyesno_run,
235 simplelist_info_init,
236 simplelist_show_list,
238 /* button */
239 button_get,
240 button_get_w_tmo,
241 button_status,
242 #ifdef HAVE_BUTTON_DATA
243 button_get_data,
244 #endif
245 button_clear_queue,
246 button_queue_count,
247 #ifdef HAS_BUTTON_HOLD
248 button_hold,
249 #endif
250 #ifdef HAVE_TOUCHSCREEN
251 touchscreen_set_mode,
252 #endif
254 #ifdef HAVE_BUTTON_LIGHT
255 buttonlight_set_timeout,
256 buttonlight_off,
257 buttonlight_on,
258 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
259 buttonlight_set_brightness,
260 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
261 #endif /* HAVE_BUTTON_LIGHT */
263 /* file */
264 (open_func)PREFIX(open),
265 PREFIX(close),
266 (read_func)PREFIX(read),
267 PREFIX(lseek),
268 (creat_func)PREFIX(creat),
269 (write_func)PREFIX(write),
270 PREFIX(remove),
271 PREFIX(rename),
272 PREFIX(ftruncate),
273 PREFIX(filesize),
274 fdprintf,
275 read_line,
276 settings_parseline,
277 storage_sleep,
278 storage_spin,
279 storage_spindown,
280 #if USING_STORAGE_CALLBACK
281 register_storage_idle_func,
282 unregister_storage_idle_func,
283 #endif /* USING_STORAGE_CALLBACK */
284 reload_directory,
285 create_numbered_filename,
286 file_exists,
287 strip_extension,
289 /* dir */
290 opendir,
291 closedir,
292 readdir,
293 mkdir,
294 rmdir,
295 dir_exists,
297 /* kernel/ system */
298 #ifdef CPU_ARM
299 __div0,
300 #endif
301 PREFIX(sleep),
302 yield,
303 &current_tick,
304 default_event_handler,
305 default_event_handler_ex,
306 create_thread,
307 thread_exit,
308 thread_wait,
309 #if (CONFIG_CODEC == SWCODEC)
310 thread_thaw,
311 #ifdef HAVE_PRIORITY_SCHEDULING
312 thread_set_priority,
313 #endif
314 mutex_init,
315 mutex_lock,
316 mutex_unlock,
317 #endif
319 reset_poweroff_timer,
320 #ifndef SIMULATOR
321 system_memory_guard,
322 &cpu_frequency,
324 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
325 #ifdef CPU_BOOST_LOGGING
326 cpu_boost_,
327 #else
328 cpu_boost,
329 #endif
330 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
331 #endif /* !SIMULATOR */
332 #ifdef HAVE_SCHEDULER_BOOSTCTRL
333 trigger_cpu_boost,
334 cancel_cpu_boost,
335 #endif
336 #if NUM_CORES > 1
337 cpucache_flush,
338 cpucache_invalidate,
339 #endif
340 timer_register,
341 timer_unregister,
342 timer_set_period,
344 queue_init,
345 queue_delete,
346 queue_post,
347 queue_wait_w_tmo,
348 #if CONFIG_CODEC == SWCODEC
349 queue_enable_queue_send,
350 queue_empty,
351 queue_wait,
352 queue_send,
353 queue_reply,
354 #endif
355 usb_acknowledge,
356 #ifdef RB_PROFILE
357 profile_thread,
358 profstop,
359 __cyg_profile_func_enter,
360 __cyg_profile_func_exit,
361 #endif
363 #ifdef SIMULATOR
364 /* special simulator hooks */
365 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
366 sim_lcd_ex_init,
367 sim_lcd_ex_update_rect,
368 #endif
369 #endif
371 /* strings and memory */
372 snprintf,
373 vsnprintf,
374 strcpy,
375 strncpy,
376 strlen,
377 strrchr,
378 strcmp,
379 strncmp,
380 strcasecmp,
381 strncasecmp,
382 memset,
383 memcpy,
384 memmove,
385 _ctype_,
386 atoi,
387 strchr,
388 strcat,
389 memchr,
390 memcmp,
391 strcasestr,
392 strtok_r,
393 /* unicode stuff */
394 utf8decode,
395 iso_decode,
396 utf16LEdecode,
397 utf16BEdecode,
398 utf8encode,
399 utf8length,
400 utf8seek,
402 /* sound */
403 sound_set,
404 sound_default,
405 sound_min,
406 sound_max,
407 sound_unit,
408 sound_val2phys,
409 #ifndef SIMULATOR
410 mp3_play_data,
411 mp3_play_pause,
412 mp3_play_stop,
413 mp3_is_playing,
414 #if CONFIG_CODEC != SWCODEC
415 bitswap,
416 #endif
417 #endif
418 #if CONFIG_CODEC == SWCODEC
419 &audio_master_sampr_list[0],
420 &hw_freq_sampr[0],
421 pcm_apply_settings,
422 pcm_play_data,
423 pcm_play_stop,
424 pcm_set_frequency,
425 pcm_is_playing,
426 pcm_is_paused,
427 pcm_play_pause,
428 pcm_get_bytes_waiting,
429 pcm_calculate_peaks,
430 pcm_play_lock,
431 pcm_play_unlock,
432 #ifdef HAVE_RECORDING
433 &rec_freq_sampr[0],
434 pcm_init_recording,
435 pcm_close_recording,
436 pcm_record_data,
437 pcm_record_more,
438 pcm_stop_recording,
439 pcm_calculate_rec_peaks,
440 audio_set_recording_gain,
441 #endif /* HAVE_RECORDING */
442 #if INPUT_SRC_CAPS != 0
443 audio_set_output_source,
444 audio_set_input_source,
445 #endif
446 dsp_set_crossfeed,
447 dsp_set_eq,
448 dsp_dither_enable,
449 dsp_configure,
450 dsp_process,
451 #endif /* CONFIG_CODEC == SWCODEC */
453 /* playback control */
454 playlist_amount,
455 playlist_resume,
456 playlist_start,
457 PREFIX(audio_play),
458 audio_stop,
459 audio_pause,
460 audio_resume,
461 audio_next,
462 audio_prev,
463 audio_ff_rewind,
464 audio_next_track,
465 audio_status,
466 audio_current_track,
467 audio_flush_and_reload_tracks,
468 audio_get_file_pos,
469 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
470 mpeg_get_last_header,
471 #endif
472 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
473 (CONFIG_CODEC == SWCODEC)
474 sound_set_pitch,
475 #endif
477 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
478 /* MAS communication */
479 mas_readmem,
480 mas_writemem,
481 mas_readreg,
482 mas_writereg,
483 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
484 mas_codec_writereg,
485 mas_codec_readreg,
486 i2c_begin,
487 i2c_end,
488 i2c_write,
489 #endif
490 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
492 /* menu */
493 do_menu,
494 /* statusbars */
495 &statusbars,
496 gui_syncstatusbar_draw,
497 /* options */
498 get_settings_list,
499 find_setting,
500 option_screen,
501 set_option,
502 set_bool_options,
503 set_int,
504 set_bool,
505 #ifdef HAVE_LCD_COLOR
506 set_color,
507 #endif
509 /* action handling */
510 get_custom_action,
511 get_action,
512 action_userabort,
514 /* power */
515 battery_level,
516 battery_level_safe,
517 battery_time,
518 #ifndef SIMULATOR
519 battery_voltage,
520 #endif
521 #if CONFIG_CHARGING
522 charger_inserted,
523 # if CONFIG_CHARGING >= CHARGING_MONITOR
524 charging_state,
525 # endif
526 #endif
527 #ifdef HAVE_USB_POWER
528 usb_powered,
529 #endif
531 /* misc */
532 srand,
533 rand,
534 (qsort_func)qsort,
535 kbd_input,
536 get_time,
537 set_time,
538 #if CONFIG_RTC
539 mktime,
540 #endif
541 plugin_get_buffer,
542 plugin_get_audio_buffer,
543 plugin_tsr,
544 plugin_get_current_filename,
545 #ifdef PLUGIN_USE_IRAM
546 plugin_iram_init,
547 #endif
548 #if defined(DEBUG) || defined(SIMULATOR)
549 debugf,
550 #endif
551 #ifdef ROCKBOX_HAS_LOGF
552 _logf,
553 #endif
554 &global_settings,
555 &global_status,
556 talk_disable,
557 #if CONFIG_CODEC == SWCODEC
558 codec_thread_do_callback,
559 codec_load_file,
560 get_codec_filename,
561 #endif
562 get_metadata,
563 mp3info,
564 count_mp3_frames,
565 create_xing_header,
566 find_next_frame,
567 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
568 peak_meter_scale_value,
569 peak_meter_set_use_dbfs,
570 peak_meter_get_use_dbfs,
571 #endif
572 #ifdef HAVE_LCD_BITMAP
573 read_bmp_file,
574 screen_dump_set_hook,
575 #endif
576 show_logo,
577 tree_get_context,
578 set_current_file,
579 set_dirfilter,
581 #ifdef HAVE_WHEEL_POSITION
582 wheel_status,
583 wheel_send_events,
584 #endif
586 #ifdef IRIVER_H100_SERIES
587 /* Routines for the iriver_flash -plugin. */
588 detect_original_firmware,
589 detect_flashed_ramimage,
590 detect_flashed_romimage,
591 #endif
592 led,
593 #if (CONFIG_CODEC == SWCODEC)
594 bufopen,
595 bufalloc,
596 bufclose,
597 bufseek,
598 bufadvance,
599 bufread,
600 bufgetdata,
601 bufgettail,
602 bufcuttail,
604 buf_get_offset,
605 buf_handle_offset,
606 buf_request_buffer_handle,
607 buf_set_base_handle,
608 buf_used,
609 #endif
611 #ifdef HAVE_TAGCACHE
612 tagcache_search,
613 tagcache_search_set_uniqbuf,
614 tagcache_search_add_filter,
615 tagcache_get_next,
616 tagcache_retrieve,
617 tagcache_search_finish,
618 tagcache_get_numeric,
619 #endif
621 #ifdef HAVE_ALBUMART
622 find_albumart,
623 search_albumart_files,
624 #endif
626 #ifdef HAVE_SEMAPHORE_OBJECTS
627 semaphore_init,
628 semaphore_wait,
629 semaphore_release,
630 #endif
632 appsversion,
633 /* new stuff at the end, sort into place next time
634 the API gets incompatible */
636 #if defined(HAVE_LCD_MODES)
637 lcd_set_mode,
638 #endif
641 int plugin_load(const char* plugin, const void* parameter)
643 int rc;
644 int oldbars;
645 struct plugin_header *hdr;
646 #ifdef SIMULATOR
647 void *pd;
648 #else /* !SIMULATOR */
649 int fd;
650 ssize_t readsize;
651 #if NUM_CORES > 1
652 unsigned my_core;
653 #endif
654 #endif /* !SIMULATOR */
656 #if LCD_DEPTH > 1
657 fb_data* old_backdrop;
658 #endif
660 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
662 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
664 /* not allowing another plugin to load */
665 return PLUGIN_OK;
667 pfn_tsr_exit = NULL;
668 plugin_loaded = false;
671 splash(0, ID2P(LANG_WAIT));
672 strcpy(current_plugin, plugin);
674 #ifdef SIMULATOR
675 hdr = sim_plugin_load((char *)plugin, &pd);
676 if (pd == NULL) {
677 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
678 return -1;
680 if (hdr == NULL
681 || hdr->magic != PLUGIN_MAGIC
682 || hdr->target_id != TARGET_ID) {
683 sim_plugin_close(pd);
684 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
685 return -1;
687 if (hdr->api_version > PLUGIN_API_VERSION
688 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
689 sim_plugin_close(pd);
690 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
691 return -1;
693 #else
694 fd = open(plugin, O_RDONLY);
695 if (fd < 0) {
696 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
697 return fd;
699 #if NUM_CORES > 1
700 /* Make sure COP cache is flushed and invalidated before loading */
701 my_core = switch_core(CURRENT_CORE ^ 1);
702 cpucache_invalidate();
703 switch_core(my_core);
704 #endif
706 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
707 close(fd);
709 if (readsize < 0) {
710 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
711 return -1;
713 hdr = (struct plugin_header *)pluginbuf;
715 if ((unsigned)readsize <= sizeof(struct plugin_header)
716 || hdr->magic != PLUGIN_MAGIC
717 || hdr->target_id != TARGET_ID
718 || hdr->load_addr != pluginbuf
719 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
720 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
721 return -1;
723 if (hdr->api_version > PLUGIN_API_VERSION
724 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
725 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
726 return -1;
728 plugin_size = hdr->end_addr - pluginbuf;
730 /* zero out bss area only, above guards end of pluginbuf */
731 if (plugin_size > readsize)
732 memset(pluginbuf + readsize, 0, plugin_size - readsize);
733 #endif
735 *(hdr->api) = &rockbox_api;
736 plugin_loaded = true;
739 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
740 old_backdrop = lcd_get_backdrop();
741 #endif
742 lcd_clear_display();
743 lcd_update();
745 #ifdef HAVE_REMOTE_LCD
746 lcd_remote_clear_display();
747 lcd_remote_update();
748 #endif
750 cpucache_invalidate();
751 oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
753 rc = hdr->entry_point(parameter);
755 viewportmanager_set_statusbar(oldbars);
757 button_clear_queue();
759 #ifdef HAVE_LCD_BITMAP
760 #if LCD_DEPTH > 1
761 lcd_set_backdrop(old_backdrop);
762 #ifdef HAVE_LCD_COLOR
763 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
764 global_settings.bg_color);
765 #else
766 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
767 #endif
768 #else /* LCD_DEPTH == 1 */
769 lcd_set_drawmode(DRMODE_SOLID);
770 #endif /* LCD_DEPTH */
771 #endif /* HAVE_LCD_BITMAP */
773 lcd_clear_display();
774 lcd_update();
776 #ifdef HAVE_REMOTE_LCD
777 #if LCD_REMOTE_DEPTH > 1
778 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
779 LCD_REMOTE_DEFAULT_BG);
780 #else
781 lcd_remote_set_drawmode(DRMODE_SOLID);
782 #endif
783 lcd_remote_clear_display();
786 lcd_remote_update();
789 #endif
790 viewportmanager_set_statusbar(oldbars);
791 if (pfn_tsr_exit == NULL)
792 plugin_loaded = false;
794 sim_plugin_close(pd);
796 switch (rc) {
797 case PLUGIN_OK:
798 break;
800 case PLUGIN_USB_CONNECTED:
801 return PLUGIN_USB_CONNECTED;
803 default:
804 splash(HZ*2, str(LANG_PLUGIN_ERROR));
805 break;
808 return PLUGIN_OK;
811 /* Returns a pointer to the portion of the plugin buffer that is not already
812 being used. If no plugin is loaded, returns the entire plugin buffer */
813 void* plugin_get_buffer(size_t *buffer_size)
815 int buffer_pos;
817 if (plugin_loaded)
819 if (plugin_size >= PLUGIN_BUFFER_SIZE)
820 return NULL;
822 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
823 buffer_pos = plugin_size;
825 else
827 *buffer_size = PLUGIN_BUFFER_SIZE;
828 buffer_pos = 0;
831 return &pluginbuf[buffer_pos];
834 /* Returns a pointer to the mp3 buffer.
835 Playback gets stopped, to avoid conflicts.
836 Talk buffer is stolen as well.
838 void* plugin_get_audio_buffer(size_t *buffer_size)
840 #if CONFIG_CODEC == SWCODEC
841 return audio_get_buffer(true, buffer_size);
842 #else
843 audio_stop();
844 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
845 *buffer_size = audiobufend - audiobuf;
846 return audiobuf;
847 #endif
850 #ifdef PLUGIN_USE_IRAM
851 /* Initializes plugin IRAM */
852 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
853 char *iedata, size_t iedata_size)
855 /* We need to stop audio playback in order to use codec IRAM */
856 audio_hard_stop();
857 memcpy(iramstart, iramcopy, iram_size);
858 memset(iedata, 0, iedata_size);
859 memset(iramcopy, 0, iram_size);
860 #if NUM_CORES > 1
861 /* writeback cleared iedata and iramcopy areas */
862 cpucache_flush();
863 #endif
865 #endif /* PLUGIN_USE_IRAM */
867 /* The plugin wants to stay resident after leaving its main function, e.g.
868 runs from timer or own thread. The callback is registered to later
869 instruct it to free its resources before a new plugin gets loaded. */
870 void plugin_tsr(bool (*exit_callback)(bool))
872 pfn_tsr_exit = exit_callback; /* remember the callback for later */
875 char *plugin_get_current_filename(void)
877 return current_plugin;