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