FS#10365 - Optional debug output for albumart.c
[kugel-rb.git] / apps / plugin.c
blob20c7a3733c98091aeb02101e69d7d9c74919e9b8
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 #if MEMORYSIZE > 2
130 lcd_blit_yuv,
131 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
132 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) || defined(SANSA_FUZE) || defined(SANSA_E200V2)
133 lcd_yuv_set_options,
134 #endif
135 #endif /* MEMORYSIZE > 2 */
136 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
137 lcd_blit_mono,
138 lcd_blit_grey_phase,
139 #endif /* LCD_DEPTH */
140 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
141 lcd_blit_pal256,
142 lcd_pal256_update_pal,
143 #endif
144 lcd_puts_style,
145 lcd_puts_scroll_style,
146 #ifdef HAVE_LCD_INVERT
147 lcd_set_invert_display,
148 #endif /* HAVE_LCD_INVERT */
149 #if defined(HAVE_LCD_MODES)
150 lcd_set_mode,
151 #endif
152 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
153 lcd_activation_set_hook,
154 &button_queue,
155 #endif
156 bidi_l2v,
157 font_get_bits,
158 font_load,
159 font_get,
160 font_getstringsize,
161 font_get_width,
162 screen_clear_area,
163 gui_scrollbar_draw,
164 #endif /* HAVE_LCD_BITMAP */
165 get_codepage_name,
167 backlight_on,
168 backlight_off,
169 backlight_set_timeout,
170 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
171 backlight_set_brightness,
172 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
174 #if CONFIG_CHARGING
175 backlight_set_timeout_plugged,
176 #endif
177 is_backlight_on,
178 splash,
179 splashf,
181 #ifdef HAVE_REMOTE_LCD
182 /* remote lcd */
183 lcd_remote_set_contrast,
184 lcd_remote_clear_display,
185 lcd_remote_puts,
186 lcd_remote_puts_scroll,
187 lcd_remote_stop_scroll,
188 lcd_remote_set_drawmode,
189 lcd_remote_get_drawmode,
190 lcd_remote_setfont,
191 lcd_remote_getstringsize,
192 lcd_remote_drawpixel,
193 lcd_remote_drawline,
194 lcd_remote_hline,
195 lcd_remote_vline,
196 lcd_remote_drawrect,
197 lcd_remote_fillrect,
198 lcd_remote_mono_bitmap_part,
199 lcd_remote_mono_bitmap,
200 lcd_remote_putsxy,
201 lcd_remote_puts_style,
202 lcd_remote_puts_scroll_style,
203 &lcd_remote_framebuffer[0][0],
204 lcd_remote_update,
205 lcd_remote_update_rect,
207 remote_backlight_on,
208 remote_backlight_off,
209 remote_backlight_set_timeout,
210 #if CONFIG_CHARGING
211 remote_backlight_set_timeout_plugged,
212 #endif
213 #endif /* HAVE_REMOTE_LCD */
214 #if NB_SCREENS == 2
215 {&screens[SCREEN_MAIN], &screens[SCREEN_REMOTE]},
216 #else
217 {&screens[SCREEN_MAIN]},
218 #endif
219 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
220 lcd_remote_set_foreground,
221 lcd_remote_get_foreground,
222 lcd_remote_set_background,
223 lcd_remote_get_background,
224 lcd_remote_bitmap_part,
225 lcd_remote_bitmap,
226 #endif
227 viewport_set_defaults,
228 viewportmanager_set_statusbar,
230 /* list */
231 gui_synclist_init,
232 gui_synclist_set_nb_items,
233 gui_synclist_set_icon_callback,
234 gui_synclist_get_nb_items,
235 gui_synclist_get_sel_pos,
236 gui_synclist_draw,
237 gui_synclist_select_item,
238 gui_synclist_add_item,
239 gui_synclist_del_item,
240 gui_synclist_limit_scroll,
241 gui_synclist_do_button,
242 gui_synclist_set_title,
243 gui_syncyesno_run,
244 simplelist_info_init,
245 simplelist_show_list,
247 /* button */
248 button_get,
249 button_get_w_tmo,
250 button_status,
251 #ifdef HAVE_BUTTON_DATA
252 button_get_data,
253 #endif
254 button_clear_queue,
255 button_queue_count,
256 #ifdef HAS_BUTTON_HOLD
257 button_hold,
258 #endif
259 #ifdef HAVE_TOUCHSCREEN
260 touchscreen_set_mode,
261 #endif
263 #ifdef HAVE_BUTTON_LIGHT
264 buttonlight_set_timeout,
265 buttonlight_off,
266 buttonlight_on,
267 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
268 buttonlight_set_brightness,
269 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
270 #endif /* HAVE_BUTTON_LIGHT */
272 /* file */
273 (open_func)PREFIX(open),
274 PREFIX(close),
275 (read_func)PREFIX(read),
276 PREFIX(lseek),
277 (creat_func)PREFIX(creat),
278 (write_func)PREFIX(write),
279 PREFIX(remove),
280 PREFIX(rename),
281 PREFIX(ftruncate),
282 PREFIX(filesize),
283 fdprintf,
284 read_line,
285 settings_parseline,
286 storage_sleep,
287 storage_spin,
288 storage_spindown,
289 #if USING_STORAGE_CALLBACK
290 register_storage_idle_func,
291 unregister_storage_idle_func,
292 #endif /* USING_STORAGE_CALLBACK */
293 reload_directory,
294 create_numbered_filename,
295 file_exists,
296 strip_extension,
298 /* dir */
299 opendir,
300 closedir,
301 readdir,
302 mkdir,
303 rmdir,
304 dir_exists,
306 /* kernel/ system */
307 #ifdef CPU_ARM
308 __div0,
309 #endif
310 PREFIX(sleep),
311 yield,
312 &current_tick,
313 default_event_handler,
314 default_event_handler_ex,
315 create_thread,
316 thread_exit,
317 thread_wait,
318 #if (CONFIG_CODEC == SWCODEC)
319 thread_thaw,
320 #ifdef HAVE_PRIORITY_SCHEDULING
321 thread_set_priority,
322 #endif
323 mutex_init,
324 mutex_lock,
325 mutex_unlock,
326 #endif
328 reset_poweroff_timer,
329 #ifndef SIMULATOR
330 system_memory_guard,
331 &cpu_frequency,
333 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
334 #ifdef CPU_BOOST_LOGGING
335 cpu_boost_,
336 #else
337 cpu_boost,
338 #endif
339 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
340 #endif /* !SIMULATOR */
341 #ifdef HAVE_SCHEDULER_BOOSTCTRL
342 trigger_cpu_boost,
343 cancel_cpu_boost,
344 #endif
345 #if NUM_CORES > 1
346 cpucache_flush,
347 cpucache_invalidate,
348 #endif
349 timer_register,
350 timer_unregister,
351 timer_set_period,
353 queue_init,
354 queue_delete,
355 queue_post,
356 queue_wait_w_tmo,
357 #if CONFIG_CODEC == SWCODEC
358 queue_enable_queue_send,
359 queue_empty,
360 queue_wait,
361 queue_send,
362 queue_reply,
363 #endif
364 usb_acknowledge,
365 #ifdef RB_PROFILE
366 profile_thread,
367 profstop,
368 __cyg_profile_func_enter,
369 __cyg_profile_func_exit,
370 #endif
372 #ifdef SIMULATOR
373 /* special simulator hooks */
374 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
375 sim_lcd_ex_init,
376 sim_lcd_ex_update_rect,
377 #endif
378 #endif
380 /* strings and memory */
381 snprintf,
382 vsnprintf,
383 strcpy,
384 strncpy,
385 strlen,
386 strrchr,
387 strcmp,
388 strncmp,
389 strcasecmp,
390 strncasecmp,
391 memset,
392 memcpy,
393 memmove,
394 _ctype_,
395 atoi,
396 strchr,
397 strcat,
398 memchr,
399 memcmp,
400 strcasestr,
401 strtok_r,
402 /* unicode stuff */
403 utf8decode,
404 iso_decode,
405 utf16LEdecode,
406 utf16BEdecode,
407 utf8encode,
408 utf8length,
409 utf8seek,
411 /* sound */
412 sound_set,
413 sound_default,
414 sound_min,
415 sound_max,
416 sound_unit,
417 sound_val2phys,
418 #ifndef SIMULATOR
419 mp3_play_data,
420 mp3_play_pause,
421 mp3_play_stop,
422 mp3_is_playing,
423 #if CONFIG_CODEC != SWCODEC
424 bitswap,
425 #endif
426 #endif
427 #if CONFIG_CODEC == SWCODEC
428 &audio_master_sampr_list[0],
429 &hw_freq_sampr[0],
430 pcm_apply_settings,
431 pcm_play_data,
432 pcm_play_stop,
433 pcm_set_frequency,
434 pcm_is_playing,
435 pcm_is_paused,
436 pcm_play_pause,
437 pcm_get_bytes_waiting,
438 pcm_calculate_peaks,
439 pcm_play_lock,
440 pcm_play_unlock,
441 #ifdef HAVE_RECORDING
442 &rec_freq_sampr[0],
443 pcm_init_recording,
444 pcm_close_recording,
445 pcm_record_data,
446 pcm_record_more,
447 pcm_stop_recording,
448 pcm_calculate_rec_peaks,
449 audio_set_recording_gain,
450 #endif /* HAVE_RECORDING */
451 #if INPUT_SRC_CAPS != 0
452 audio_set_output_source,
453 audio_set_input_source,
454 #endif
455 dsp_set_crossfeed,
456 dsp_set_eq,
457 dsp_dither_enable,
458 dsp_configure,
459 dsp_process,
460 #endif /* CONFIG_CODEC == SWCODEC */
462 /* playback control */
463 playlist_amount,
464 playlist_resume,
465 playlist_start,
466 playlist_add,
467 playlist_sync,
468 playlist_remove_all_tracks,
469 playlist_create,
470 playlist_insert_track,
471 playlist_shuffle,
472 PREFIX(audio_play),
473 audio_stop,
474 audio_pause,
475 audio_resume,
476 audio_next,
477 audio_prev,
478 audio_ff_rewind,
479 audio_next_track,
480 audio_status,
481 audio_current_track,
482 audio_flush_and_reload_tracks,
483 audio_get_file_pos,
484 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
485 mpeg_get_last_header,
486 #endif
487 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
488 (CONFIG_CODEC == SWCODEC)
489 sound_set_pitch,
490 #endif
492 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
493 /* MAS communication */
494 mas_readmem,
495 mas_writemem,
496 mas_readreg,
497 mas_writereg,
498 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
499 mas_codec_writereg,
500 mas_codec_readreg,
501 i2c_begin,
502 i2c_end,
503 i2c_write,
504 #endif
505 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
507 /* menu */
508 do_menu,
509 /* statusbars */
510 &statusbars,
511 gui_syncstatusbar_draw,
512 /* options */
513 get_settings_list,
514 find_setting,
515 option_screen,
516 set_option,
517 set_bool_options,
518 set_int,
519 set_bool,
520 #ifdef HAVE_LCD_COLOR
521 set_color,
522 #endif
524 /* action handling */
525 get_custom_action,
526 get_action,
527 #ifdef HAVE_TOUCHSCREEN
528 action_get_touchscreen_press,
529 #endif
530 action_userabort,
532 /* power */
533 battery_level,
534 battery_level_safe,
535 battery_time,
536 #ifndef SIMULATOR
537 battery_voltage,
538 #endif
539 #if CONFIG_CHARGING
540 charger_inserted,
541 # if CONFIG_CHARGING >= CHARGING_MONITOR
542 charging_state,
543 # endif
544 #endif
545 #ifdef HAVE_USB_POWER
546 usb_powered,
547 #endif
549 /* misc */
550 srand,
551 rand,
552 (qsort_func)qsort,
553 kbd_input,
554 get_time,
555 set_time,
556 #if CONFIG_RTC
557 mktime,
558 #endif
559 plugin_get_buffer,
560 plugin_get_audio_buffer,
561 plugin_tsr,
562 plugin_get_current_filename,
563 #ifdef PLUGIN_USE_IRAM
564 plugin_iram_init,
565 #endif
566 #if defined(DEBUG) || defined(SIMULATOR)
567 debugf,
568 #endif
569 #ifdef ROCKBOX_HAS_LOGF
570 _logf,
571 #endif
572 &global_settings,
573 &global_status,
574 talk_disable,
575 #if CONFIG_CODEC == SWCODEC
576 codec_thread_do_callback,
577 codec_load_file,
578 get_codec_filename,
579 #endif
580 get_metadata,
581 mp3info,
582 count_mp3_frames,
583 create_xing_header,
584 find_next_frame,
585 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
586 peak_meter_scale_value,
587 peak_meter_set_use_dbfs,
588 peak_meter_get_use_dbfs,
589 #endif
590 #ifdef HAVE_LCD_BITMAP
591 read_bmp_file,
592 read_bmp_fd,
593 #ifdef HAVE_JPEG
594 read_jpeg_file,
595 read_jpeg_fd,
596 #endif
597 screen_dump_set_hook,
598 #endif
599 show_logo,
600 tree_get_context,
601 set_current_file,
602 set_dirfilter,
604 #ifdef HAVE_WHEEL_POSITION
605 wheel_status,
606 wheel_send_events,
607 #endif
609 #ifdef IRIVER_H100_SERIES
610 /* Routines for the iriver_flash -plugin. */
611 detect_original_firmware,
612 detect_flashed_ramimage,
613 detect_flashed_romimage,
614 #endif
615 led,
616 #if (CONFIG_CODEC == SWCODEC)
617 bufopen,
618 bufalloc,
619 bufclose,
620 bufseek,
621 bufadvance,
622 bufread,
623 bufgetdata,
624 bufgettail,
625 bufcuttail,
627 buf_get_offset,
628 buf_handle_offset,
629 buf_request_buffer_handle,
630 buf_set_base_handle,
631 buf_used,
632 #endif
634 #ifdef HAVE_TAGCACHE
635 tagcache_search,
636 tagcache_search_set_uniqbuf,
637 tagcache_search_add_filter,
638 tagcache_get_next,
639 tagcache_retrieve,
640 tagcache_search_finish,
641 tagcache_get_numeric,
642 #ifdef HAVE_TC_RAMCACHE
643 tagcache_fill_tags,
644 #endif
645 #endif
647 #ifdef HAVE_ALBUMART
648 find_albumart,
649 search_albumart_files,
650 #endif
652 #ifdef HAVE_SEMAPHORE_OBJECTS
653 semaphore_init,
654 semaphore_wait,
655 semaphore_release,
656 #endif
658 appsversion,
659 /* new stuff at the end, sort into place next time
660 the API gets incompatible */
663 int plugin_load(const char* plugin, const void* parameter)
665 int rc;
666 int oldbars;
667 struct plugin_header *hdr;
668 #ifdef SIMULATOR
669 void *pd;
670 #else /* !SIMULATOR */
671 int fd;
672 ssize_t readsize;
673 #if NUM_CORES > 1
674 unsigned my_core;
675 #endif
676 #endif /* !SIMULATOR */
678 #if LCD_DEPTH > 1
679 fb_data* old_backdrop;
680 #endif
682 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
684 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
686 /* not allowing another plugin to load */
687 return PLUGIN_OK;
689 pfn_tsr_exit = NULL;
690 plugin_loaded = false;
693 splash(0, ID2P(LANG_WAIT));
694 strcpy(current_plugin, plugin);
696 #ifdef SIMULATOR
697 hdr = sim_plugin_load((char *)plugin, &pd);
698 if (pd == NULL) {
699 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
700 return -1;
702 if (hdr == NULL
703 || hdr->magic != PLUGIN_MAGIC
704 || hdr->target_id != TARGET_ID) {
705 sim_plugin_close(pd);
706 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
707 return -1;
709 if (hdr->api_version > PLUGIN_API_VERSION
710 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
711 sim_plugin_close(pd);
712 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
713 return -1;
715 #else
716 fd = open(plugin, O_RDONLY);
717 if (fd < 0) {
718 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
719 return fd;
721 #if NUM_CORES > 1
722 /* Make sure COP cache is flushed and invalidated before loading */
723 my_core = switch_core(CURRENT_CORE ^ 1);
724 cpucache_invalidate();
725 switch_core(my_core);
726 #endif
728 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
729 close(fd);
731 if (readsize < 0) {
732 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
733 return -1;
735 hdr = (struct plugin_header *)pluginbuf;
737 if ((unsigned)readsize <= sizeof(struct plugin_header)
738 || hdr->magic != PLUGIN_MAGIC
739 || hdr->target_id != TARGET_ID
740 || hdr->load_addr != pluginbuf
741 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
742 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
743 return -1;
745 if (hdr->api_version > PLUGIN_API_VERSION
746 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
747 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
748 return -1;
750 plugin_size = hdr->end_addr - pluginbuf;
752 /* zero out bss area only, above guards end of pluginbuf */
753 if (plugin_size > readsize)
754 memset(pluginbuf + readsize, 0, plugin_size - readsize);
755 #endif
757 *(hdr->api) = &rockbox_api;
758 plugin_loaded = true;
761 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
762 old_backdrop = lcd_get_backdrop();
763 #endif
764 lcd_clear_display();
765 lcd_update();
767 #ifdef HAVE_REMOTE_LCD
768 lcd_remote_clear_display();
769 lcd_remote_update();
770 #endif
772 cpucache_invalidate();
773 oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
775 #ifdef HAVE_TOUCHSCREEN
776 enum touchscreen_mode old_mode = touchscreen_get_mode();
778 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
779 #endif
781 rc = hdr->entry_point(parameter);
783 #ifdef HAVE_TOUCHSCREEN
784 touchscreen_set_mode(old_mode);
785 #endif
787 viewportmanager_set_statusbar(oldbars);
789 button_clear_queue();
791 #ifdef HAVE_LCD_BITMAP
792 lcd_setfont(FONT_UI);
793 #if LCD_DEPTH > 1
794 lcd_set_backdrop(old_backdrop);
795 #ifdef HAVE_LCD_COLOR
796 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
797 global_settings.bg_color);
798 #else
799 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
800 #endif
801 #else /* LCD_DEPTH == 1 */
802 lcd_set_drawmode(DRMODE_SOLID);
803 #endif /* LCD_DEPTH */
804 #endif /* HAVE_LCD_BITMAP */
806 lcd_clear_display();
807 lcd_update();
809 #ifdef HAVE_REMOTE_LCD
810 #if LCD_REMOTE_DEPTH > 1
811 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
812 LCD_REMOTE_DEFAULT_BG);
813 #else
814 lcd_remote_set_drawmode(DRMODE_SOLID);
815 #endif
816 lcd_remote_clear_display();
819 lcd_remote_update();
822 #endif
823 viewportmanager_set_statusbar(oldbars);
824 if (pfn_tsr_exit == NULL)
825 plugin_loaded = false;
827 sim_plugin_close(pd);
829 switch (rc) {
830 case PLUGIN_OK:
831 break;
833 case PLUGIN_USB_CONNECTED:
834 return PLUGIN_USB_CONNECTED;
836 default:
837 splash(HZ*2, str(LANG_PLUGIN_ERROR));
838 break;
841 return PLUGIN_OK;
844 /* Returns a pointer to the portion of the plugin buffer that is not already
845 being used. If no plugin is loaded, returns the entire plugin buffer */
846 void* plugin_get_buffer(size_t *buffer_size)
848 int buffer_pos;
850 if (plugin_loaded)
852 if (plugin_size >= PLUGIN_BUFFER_SIZE)
853 return NULL;
855 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
856 buffer_pos = plugin_size;
858 else
860 *buffer_size = PLUGIN_BUFFER_SIZE;
861 buffer_pos = 0;
864 return &pluginbuf[buffer_pos];
867 /* Returns a pointer to the mp3 buffer.
868 Playback gets stopped, to avoid conflicts.
869 Talk buffer is stolen as well.
871 void* plugin_get_audio_buffer(size_t *buffer_size)
873 #if CONFIG_CODEC == SWCODEC
874 return audio_get_buffer(true, buffer_size);
875 #else
876 audio_stop();
877 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
878 *buffer_size = audiobufend - audiobuf;
879 return audiobuf;
880 #endif
883 #ifdef PLUGIN_USE_IRAM
884 /* Initializes plugin IRAM */
885 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
886 char *iedata, size_t iedata_size)
888 /* We need to stop audio playback in order to use codec IRAM */
889 audio_hard_stop();
890 memcpy(iramstart, iramcopy, iram_size);
891 memset(iedata, 0, iedata_size);
892 memset(iramcopy, 0, iram_size);
893 #if NUM_CORES > 1
894 /* writeback cleared iedata and iramcopy areas */
895 cpucache_flush();
896 #endif
898 #endif /* PLUGIN_USE_IRAM */
900 /* The plugin wants to stay resident after leaving its main function, e.g.
901 runs from timer or own thread. The callback is registered to later
902 instruct it to free its resources before a new plugin gets loaded. */
903 void plugin_tsr(bool (*exit_callback)(bool))
905 pfn_tsr_exit = exit_callback; /* remember the callback for later */
908 char *plugin_get_current_filename(void)
910 return current_plugin;