Fix red introduced with r20610.
[kugel-rb/myfork.git] / apps / plugin.c
blob2126641572735ceb6b7a09e0efc8f469ad65a9b0
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_has_changed_track,
467 audio_current_track,
468 audio_flush_and_reload_tracks,
469 audio_get_file_pos,
470 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
471 mpeg_get_last_header,
472 #endif
473 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
474 (CONFIG_CODEC == SWCODEC)
475 sound_set_pitch,
476 #endif
478 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
479 /* MAS communication */
480 mas_readmem,
481 mas_writemem,
482 mas_readreg,
483 mas_writereg,
484 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
485 mas_codec_writereg,
486 mas_codec_readreg,
487 i2c_begin,
488 i2c_end,
489 i2c_write,
490 #endif
491 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
493 /* menu */
494 do_menu,
495 /* statusbars */
496 &statusbars,
497 gui_syncstatusbar_draw,
498 /* options */
499 get_settings_list,
500 find_setting,
501 option_screen,
502 set_option,
503 set_bool_options,
504 set_int,
505 set_bool,
506 #ifdef HAVE_LCD_COLOR
507 set_color,
508 #endif
510 /* action handling */
511 get_custom_action,
512 get_action,
513 action_userabort,
515 /* power */
516 battery_level,
517 battery_level_safe,
518 battery_time,
519 #ifndef SIMULATOR
520 battery_voltage,
521 #endif
522 #if CONFIG_CHARGING
523 charger_inserted,
524 # if CONFIG_CHARGING >= CHARGING_MONITOR
525 charging_state,
526 # endif
527 #endif
528 #ifdef HAVE_USB_POWER
529 usb_powered,
530 #endif
532 /* misc */
533 srand,
534 rand,
535 (qsort_func)qsort,
536 kbd_input,
537 get_time,
538 set_time,
539 #if CONFIG_RTC
540 mktime,
541 #endif
542 plugin_get_buffer,
543 plugin_get_audio_buffer,
544 plugin_tsr,
545 plugin_get_current_filename,
546 #ifdef PLUGIN_USE_IRAM
547 plugin_iram_init,
548 #endif
549 #if defined(DEBUG) || defined(SIMULATOR)
550 debugf,
551 #endif
552 #ifdef ROCKBOX_HAS_LOGF
553 _logf,
554 #endif
555 &global_settings,
556 &global_status,
557 talk_disable,
558 #if CONFIG_CODEC == SWCODEC
559 codec_thread_do_callback,
560 codec_load_file,
561 get_codec_filename,
562 #endif
563 get_metadata,
564 mp3info,
565 count_mp3_frames,
566 create_xing_header,
567 find_next_frame,
568 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
569 peak_meter_scale_value,
570 peak_meter_set_use_dbfs,
571 peak_meter_get_use_dbfs,
572 #endif
573 #ifdef HAVE_LCD_BITMAP
574 read_bmp_file,
575 screen_dump_set_hook,
576 #endif
577 show_logo,
578 tree_get_context,
579 set_current_file,
580 set_dirfilter,
582 #ifdef HAVE_WHEEL_POSITION
583 wheel_status,
584 wheel_send_events,
585 #endif
587 #ifdef IRIVER_H100_SERIES
588 /* Routines for the iriver_flash -plugin. */
589 detect_original_firmware,
590 detect_flashed_ramimage,
591 detect_flashed_romimage,
592 #endif
593 led,
594 #if (CONFIG_CODEC == SWCODEC)
595 bufopen,
596 bufalloc,
597 bufclose,
598 bufseek,
599 bufadvance,
600 bufread,
601 bufgetdata,
602 bufgettail,
603 bufcuttail,
605 buf_get_offset,
606 buf_handle_offset,
607 buf_request_buffer_handle,
608 buf_set_base_handle,
609 buf_used,
610 #endif
612 #ifdef HAVE_TAGCACHE
613 tagcache_search,
614 tagcache_search_set_uniqbuf,
615 tagcache_search_add_filter,
616 tagcache_get_next,
617 tagcache_retrieve,
618 tagcache_search_finish,
619 tagcache_get_numeric,
620 #endif
622 #ifdef HAVE_ALBUMART
623 find_albumart,
624 search_albumart_files,
625 #endif
627 #ifdef HAVE_SEMAPHORE_OBJECTS
628 semaphore_init,
629 semaphore_wait,
630 semaphore_release,
631 #endif
633 appsversion,
634 /* new stuff at the end, sort into place next time
635 the API gets incompatible */
637 #if defined(HAVE_LCD_MODES)
638 lcd_set_mode,
639 #endif
642 int plugin_load(const char* plugin, const void* parameter)
644 int rc;
645 int oldbars;
646 struct plugin_header *hdr;
647 #ifdef SIMULATOR
648 void *pd;
649 #else /* !SIMULATOR */
650 int fd;
651 ssize_t readsize;
652 #if NUM_CORES > 1
653 unsigned my_core;
654 #endif
655 #endif /* !SIMULATOR */
657 #if LCD_DEPTH > 1
658 fb_data* old_backdrop;
659 #endif
661 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
663 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
665 /* not allowing another plugin to load */
666 return PLUGIN_OK;
668 pfn_tsr_exit = NULL;
669 plugin_loaded = false;
672 splash(0, ID2P(LANG_WAIT));
673 strcpy(current_plugin, plugin);
675 #ifdef SIMULATOR
676 hdr = sim_plugin_load((char *)plugin, &pd);
677 if (pd == NULL) {
678 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
679 return -1;
681 if (hdr == NULL
682 || hdr->magic != PLUGIN_MAGIC
683 || hdr->target_id != TARGET_ID) {
684 sim_plugin_close(pd);
685 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
686 return -1;
688 if (hdr->api_version > PLUGIN_API_VERSION
689 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
690 sim_plugin_close(pd);
691 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
692 return -1;
694 #else
695 fd = open(plugin, O_RDONLY);
696 if (fd < 0) {
697 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
698 return fd;
700 #if NUM_CORES > 1
701 /* Make sure COP cache is flushed and invalidated before loading */
702 my_core = switch_core(CURRENT_CORE ^ 1);
703 cpucache_invalidate();
704 switch_core(my_core);
705 #endif
707 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
708 close(fd);
710 if (readsize < 0) {
711 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
712 return -1;
714 hdr = (struct plugin_header *)pluginbuf;
716 if ((unsigned)readsize <= sizeof(struct plugin_header)
717 || hdr->magic != PLUGIN_MAGIC
718 || hdr->target_id != TARGET_ID
719 || hdr->load_addr != pluginbuf
720 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
721 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
722 return -1;
724 if (hdr->api_version > PLUGIN_API_VERSION
725 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
726 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
727 return -1;
729 plugin_size = hdr->end_addr - pluginbuf;
731 /* zero out bss area only, above guards end of pluginbuf */
732 if (plugin_size > readsize)
733 memset(pluginbuf + readsize, 0, plugin_size - readsize);
734 #endif
736 *(hdr->api) = &rockbox_api;
737 plugin_loaded = true;
740 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
741 old_backdrop = lcd_get_backdrop();
742 #endif
743 lcd_clear_display();
744 lcd_update();
746 #ifdef HAVE_REMOTE_LCD
747 lcd_remote_clear_display();
748 lcd_remote_update();
749 #endif
751 cpucache_invalidate();
752 oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
754 rc = hdr->entry_point(parameter);
756 viewportmanager_set_statusbar(oldbars);
758 button_clear_queue();
760 #ifdef HAVE_LCD_BITMAP
761 #if LCD_DEPTH > 1
762 lcd_set_backdrop(old_backdrop);
763 #ifdef HAVE_LCD_COLOR
764 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
765 global_settings.bg_color);
766 #else
767 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
768 #endif
769 #else /* LCD_DEPTH == 1 */
770 lcd_set_drawmode(DRMODE_SOLID);
771 #endif /* LCD_DEPTH */
772 #endif /* HAVE_LCD_BITMAP */
774 lcd_clear_display();
775 lcd_update();
777 #ifdef HAVE_REMOTE_LCD
778 #if LCD_REMOTE_DEPTH > 1
779 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
780 LCD_REMOTE_DEFAULT_BG);
781 #else
782 lcd_remote_set_drawmode(DRMODE_SOLID);
783 #endif
784 lcd_remote_clear_display();
787 lcd_remote_update();
790 #endif
791 viewportmanager_set_statusbar(oldbars);
792 if (pfn_tsr_exit == NULL)
793 plugin_loaded = false;
795 sim_plugin_close(pd);
797 switch (rc) {
798 case PLUGIN_OK:
799 break;
801 case PLUGIN_USB_CONNECTED:
802 return PLUGIN_USB_CONNECTED;
804 default:
805 splash(HZ*2, str(LANG_PLUGIN_ERROR));
806 break;
809 return PLUGIN_OK;
812 /* Returns a pointer to the portion of the plugin buffer that is not already
813 being used. If no plugin is loaded, returns the entire plugin buffer */
814 void* plugin_get_buffer(size_t *buffer_size)
816 int buffer_pos;
818 if (plugin_loaded)
820 if (plugin_size >= PLUGIN_BUFFER_SIZE)
821 return NULL;
823 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
824 buffer_pos = plugin_size;
826 else
828 *buffer_size = PLUGIN_BUFFER_SIZE;
829 buffer_pos = 0;
832 return &pluginbuf[buffer_pos];
835 /* Returns a pointer to the mp3 buffer.
836 Playback gets stopped, to avoid conflicts.
837 Talk buffer is stolen as well.
839 void* plugin_get_audio_buffer(size_t *buffer_size)
841 #if CONFIG_CODEC == SWCODEC
842 return audio_get_buffer(true, buffer_size);
843 #else
844 audio_stop();
845 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
846 *buffer_size = audiobufend - audiobuf;
847 return audiobuf;
848 #endif
851 #ifdef PLUGIN_USE_IRAM
852 /* Initializes plugin IRAM */
853 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
854 char *iedata, size_t iedata_size)
856 /* We need to stop audio playback in order to use codec IRAM */
857 audio_hard_stop();
858 memcpy(iramstart, iramcopy, iram_size);
859 memset(iedata, 0, iedata_size);
860 memset(iramcopy, 0, iram_size);
861 #if NUM_CORES > 1
862 /* writeback cleared iedata and iramcopy areas */
863 cpucache_flush();
864 #endif
866 #endif /* PLUGIN_USE_IRAM */
868 /* The plugin wants to stay resident after leaving its main function, e.g.
869 runs from timer or own thread. The callback is registered to later
870 instruct it to free its resources before a new plugin gets loaded. */
871 void plugin_tsr(bool (*exit_callback)(bool))
873 pfn_tsr_exit = exit_callback; /* remember the callback for later */
876 char *plugin_get_current_filename(void)
878 return current_plugin;