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