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