Flyspray: FS#10326
[kugel-rb.git] / apps / plugin.c
blob35b4179949549727d0c924a6ed93de2d8200688b
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 #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID)
55 #include "usbstack/usb_hid.h"
56 #endif
58 #ifdef SIMULATOR
59 #define PREFIX(_x_) sim_ ## _x_
60 #else
61 #define PREFIX
62 #endif
64 #ifdef SIMULATOR
65 static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE];
66 void *sim_plugin_load(char *plugin, void **pd);
67 void sim_plugin_close(void *pd);
68 void sim_lcd_ex_init(unsigned long (*getpixel)(int, int));
69 void sim_lcd_ex_update_rect(int x, int y, int width, int height);
70 #else
71 #define sim_plugin_close(x)
72 extern unsigned char pluginbuf[];
73 #include "bitswap.h"
74 #endif
76 /* for actual plugins only, not for codecs */
77 static bool plugin_loaded = false;
78 static int plugin_size = 0;
79 static bool (*pfn_tsr_exit)(bool reenter) = NULL; /* TSR exit callback */
80 static char current_plugin[MAX_PATH];
82 char *plugin_get_current_filename(void);
84 static const struct plugin_api rockbox_api = {
86 /* lcd */
87 #ifdef HAVE_LCD_CONTRAST
88 lcd_set_contrast,
89 #endif
90 lcd_update,
91 lcd_clear_display,
92 lcd_getstringsize,
93 lcd_putsxy,
94 lcd_puts,
95 lcd_puts_scroll,
96 lcd_stop_scroll,
97 #ifdef HAVE_LCD_CHARCELLS
98 lcd_define_pattern,
99 lcd_get_locked_pattern,
100 lcd_unlock_pattern,
101 lcd_putc,
102 lcd_put_cursor,
103 lcd_remove_cursor,
104 lcd_icon,
105 lcd_double_height,
106 #else
107 &lcd_framebuffer[0][0],
108 lcd_update_rect,
109 lcd_set_drawmode,
110 lcd_get_drawmode,
111 lcd_setfont,
112 lcd_drawpixel,
113 lcd_drawline,
114 lcd_hline,
115 lcd_vline,
116 lcd_drawrect,
117 lcd_fillrect,
118 lcd_mono_bitmap_part,
119 lcd_mono_bitmap,
120 #if LCD_DEPTH > 1
121 lcd_set_foreground,
122 lcd_get_foreground,
123 lcd_set_background,
124 lcd_get_background,
125 lcd_bitmap_part,
126 lcd_bitmap,
127 lcd_get_backdrop,
128 lcd_set_backdrop,
129 #endif
130 #if LCD_DEPTH == 16
131 lcd_bitmap_transparent_part,
132 lcd_bitmap_transparent,
133 #if MEMORYSIZE > 2
134 lcd_blit_yuv,
135 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
136 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) \
137 || defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(TOSHIBA_GIGABEAT_S)
138 lcd_yuv_set_options,
139 #endif
140 #endif /* MEMORYSIZE > 2 */
141 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
142 lcd_blit_mono,
143 lcd_blit_grey_phase,
144 #endif /* LCD_DEPTH */
145 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
146 lcd_blit_pal256,
147 lcd_pal256_update_pal,
148 #endif
149 lcd_puts_style,
150 lcd_puts_scroll_style,
151 #ifdef HAVE_LCD_INVERT
152 lcd_set_invert_display,
153 #endif /* HAVE_LCD_INVERT */
154 #if defined(HAVE_LCD_MODES)
155 lcd_set_mode,
156 #endif
157 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
158 lcd_activation_set_hook,
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,
233 viewportmanager_set_statusbar,
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 #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 RB_PROFILE
371 profile_thread,
372 profstop,
373 __cyg_profile_func_enter,
374 __cyg_profile_func_exit,
375 #endif
377 #ifdef SIMULATOR
378 /* special simulator hooks */
379 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
380 sim_lcd_ex_init,
381 sim_lcd_ex_update_rect,
382 #endif
383 #endif
385 /* strings and memory */
386 snprintf,
387 vsnprintf,
388 strcpy,
389 strlcpy,
390 strlen,
391 strrchr,
392 strcmp,
393 strncmp,
394 strcasecmp,
395 strncasecmp,
396 memset,
397 memcpy,
398 memmove,
399 _ctype_,
400 atoi,
401 strchr,
402 strcat,
403 memchr,
404 memcmp,
405 strcasestr,
406 strtok_r,
407 /* unicode stuff */
408 utf8decode,
409 iso_decode,
410 utf16LEdecode,
411 utf16BEdecode,
412 utf8encode,
413 utf8length,
414 utf8seek,
416 /* sound */
417 sound_set,
418 sound_default,
419 sound_min,
420 sound_max,
421 sound_unit,
422 sound_val2phys,
423 #ifndef SIMULATOR
424 mp3_play_data,
425 mp3_play_pause,
426 mp3_play_stop,
427 mp3_is_playing,
428 #if CONFIG_CODEC != SWCODEC
429 bitswap,
430 #endif
431 #endif
432 #if CONFIG_CODEC == SWCODEC
433 &audio_master_sampr_list[0],
434 &hw_freq_sampr[0],
435 pcm_apply_settings,
436 pcm_play_data,
437 pcm_play_stop,
438 pcm_set_frequency,
439 pcm_is_playing,
440 pcm_is_paused,
441 pcm_play_pause,
442 pcm_get_bytes_waiting,
443 pcm_calculate_peaks,
444 pcm_play_lock,
445 pcm_play_unlock,
446 #ifdef HAVE_RECORDING
447 &rec_freq_sampr[0],
448 pcm_init_recording,
449 pcm_close_recording,
450 pcm_record_data,
451 pcm_record_more,
452 pcm_stop_recording,
453 pcm_calculate_rec_peaks,
454 audio_set_recording_gain,
455 #endif /* HAVE_RECORDING */
456 #if INPUT_SRC_CAPS != 0
457 audio_set_output_source,
458 audio_set_input_source,
459 #endif
460 dsp_set_crossfeed,
461 dsp_set_eq,
462 dsp_dither_enable,
463 dsp_configure,
464 dsp_process,
465 #endif /* CONFIG_CODEC == SWCODEC */
467 /* playback control */
468 playlist_amount,
469 playlist_resume,
470 playlist_start,
471 playlist_add,
472 playlist_sync,
473 playlist_remove_all_tracks,
474 playlist_create,
475 playlist_insert_track,
476 playlist_insert_directory,
477 playlist_shuffle,
478 PREFIX(audio_play),
479 audio_stop,
480 audio_pause,
481 audio_resume,
482 audio_next,
483 audio_prev,
484 audio_ff_rewind,
485 audio_next_track,
486 audio_status,
487 audio_current_track,
488 audio_flush_and_reload_tracks,
489 audio_get_file_pos,
490 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
491 mpeg_get_last_header,
492 #endif
493 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
494 (CONFIG_CODEC == SWCODEC)
495 sound_set_pitch,
496 #endif
498 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
499 /* MAS communication */
500 mas_readmem,
501 mas_writemem,
502 mas_readreg,
503 mas_writereg,
504 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
505 mas_codec_writereg,
506 mas_codec_readreg,
507 i2c_begin,
508 i2c_end,
509 i2c_write,
510 #endif
511 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
513 /* menu */
514 do_menu,
515 /* statusbars */
516 &statusbars,
517 gui_syncstatusbar_draw,
518 /* options */
519 get_settings_list,
520 find_setting,
521 option_screen,
522 set_option,
523 set_bool_options,
524 set_int,
525 set_bool,
526 #ifdef HAVE_LCD_COLOR
527 set_color,
528 #endif
530 /* action handling */
531 get_custom_action,
532 get_action,
533 #ifdef HAVE_TOUCHSCREEN
534 action_get_touchscreen_press,
535 #endif
536 action_userabort,
538 /* power */
539 battery_level,
540 battery_level_safe,
541 battery_time,
542 #ifndef SIMULATOR
543 battery_voltage,
544 #endif
545 #if CONFIG_CHARGING
546 charger_inserted,
547 # if CONFIG_CHARGING >= CHARGING_MONITOR
548 charging_state,
549 # endif
550 #endif
551 #ifdef HAVE_USB_POWER
552 usb_powered,
553 #endif
555 /* misc */
556 srand,
557 rand,
558 (qsort_func)qsort,
559 kbd_input,
560 get_time,
561 set_time,
562 #if CONFIG_RTC
563 mktime,
564 #endif
565 plugin_get_buffer,
566 plugin_get_audio_buffer,
567 plugin_tsr,
568 plugin_get_current_filename,
569 #ifdef PLUGIN_USE_IRAM
570 plugin_iram_init,
571 #endif
572 #if defined(DEBUG) || defined(SIMULATOR)
573 debugf,
574 #endif
575 #ifdef ROCKBOX_HAS_LOGF
576 _logf,
577 #endif
578 &global_settings,
579 &global_status,
580 talk_disable,
581 #if CONFIG_CODEC == SWCODEC
582 codec_thread_do_callback,
583 codec_load_file,
584 get_codec_filename,
585 #endif
586 get_metadata,
587 mp3info,
588 count_mp3_frames,
589 create_xing_header,
590 find_next_frame,
591 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
592 peak_meter_scale_value,
593 peak_meter_set_use_dbfs,
594 peak_meter_get_use_dbfs,
595 #endif
596 #ifdef HAVE_LCD_BITMAP
597 read_bmp_file,
598 read_bmp_fd,
599 #ifdef HAVE_JPEG
600 read_jpeg_file,
601 read_jpeg_fd,
602 #endif
603 screen_dump_set_hook,
604 #endif
605 show_logo,
606 tree_get_context,
607 set_current_file,
608 set_dirfilter,
610 #ifdef HAVE_WHEEL_POSITION
611 wheel_status,
612 wheel_send_events,
613 #endif
615 #ifdef IRIVER_H100_SERIES
616 /* Routines for the iriver_flash -plugin. */
617 detect_original_firmware,
618 detect_flashed_ramimage,
619 detect_flashed_romimage,
620 #endif
621 led,
622 #if (CONFIG_CODEC == SWCODEC)
623 bufopen,
624 bufalloc,
625 bufclose,
626 bufseek,
627 bufadvance,
628 bufread,
629 bufgetdata,
630 bufgettail,
631 bufcuttail,
633 buf_get_offset,
634 buf_handle_offset,
635 buf_request_buffer_handle,
636 buf_set_base_handle,
637 buf_used,
638 #endif
640 #ifdef HAVE_TAGCACHE
641 tagcache_search,
642 tagcache_search_set_uniqbuf,
643 tagcache_search_add_filter,
644 tagcache_get_next,
645 tagcache_retrieve,
646 tagcache_search_finish,
647 tagcache_get_numeric,
648 #ifdef HAVE_TC_RAMCACHE
649 tagcache_fill_tags,
650 #endif
651 #endif
653 #ifdef HAVE_ALBUMART
654 find_albumart,
655 search_albumart_files,
656 #endif
658 #ifdef HAVE_SEMAPHORE_OBJECTS
659 semaphore_init,
660 semaphore_wait,
661 semaphore_release,
662 #endif
664 appsversion,
665 /* new stuff at the end, sort into place next time
666 the API gets incompatible */
668 #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID)
669 usb_hid_send,
670 #endif
673 int plugin_load(const char* plugin, const void* parameter)
675 int rc;
676 int i;
677 int oldbars;
678 struct plugin_header *hdr;
679 #ifdef SIMULATOR
680 void *pd;
681 #else /* !SIMULATOR */
682 int fd;
683 ssize_t readsize;
684 #if NUM_CORES > 1
685 unsigned my_core;
686 #endif
687 #endif /* !SIMULATOR */
689 #if LCD_DEPTH > 1
690 fb_data* old_backdrop;
691 #endif
693 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
695 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
697 /* not allowing another plugin to load */
698 return PLUGIN_OK;
700 pfn_tsr_exit = NULL;
701 plugin_loaded = false;
704 splash(0, ID2P(LANG_WAIT));
705 strcpy(current_plugin, plugin);
707 #ifdef SIMULATOR
708 hdr = sim_plugin_load((char *)plugin, &pd);
709 if (pd == NULL) {
710 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
711 return -1;
713 if (hdr == NULL
714 || hdr->magic != PLUGIN_MAGIC
715 || hdr->target_id != TARGET_ID) {
716 sim_plugin_close(pd);
717 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
718 return -1;
720 if (hdr->api_version > PLUGIN_API_VERSION
721 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
722 sim_plugin_close(pd);
723 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
724 return -1;
726 #else
727 fd = open(plugin, O_RDONLY);
728 if (fd < 0) {
729 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
730 return fd;
732 #if NUM_CORES > 1
733 /* Make sure COP cache is flushed and invalidated before loading */
734 my_core = switch_core(CURRENT_CORE ^ 1);
735 cpucache_invalidate();
736 switch_core(my_core);
737 #endif
739 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
740 close(fd);
742 if (readsize < 0) {
743 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
744 return -1;
746 hdr = (struct plugin_header *)pluginbuf;
748 if ((unsigned)readsize <= sizeof(struct plugin_header)
749 || hdr->magic != PLUGIN_MAGIC
750 || hdr->target_id != TARGET_ID
751 || hdr->load_addr != pluginbuf
752 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
753 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
754 return -1;
756 if (hdr->api_version > PLUGIN_API_VERSION
757 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
758 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
759 return -1;
761 plugin_size = hdr->end_addr - pluginbuf;
763 /* zero out bss area only, above guards end of pluginbuf */
764 if (plugin_size > readsize)
765 memset(pluginbuf + readsize, 0, plugin_size - readsize);
766 #endif
768 *(hdr->api) = &rockbox_api;
769 plugin_loaded = true;
772 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
773 old_backdrop = lcd_get_backdrop();
774 #endif
775 lcd_clear_display();
776 lcd_update();
778 #ifdef HAVE_REMOTE_LCD
779 lcd_remote_clear_display();
780 lcd_remote_update();
781 #endif
783 cpucache_invalidate();
784 oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
786 #ifdef HAVE_TOUCHSCREEN
787 enum touchscreen_mode old_mode = touchscreen_get_mode();
789 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
790 #endif
792 rc = hdr->entry_point(parameter);
794 #ifdef HAVE_TOUCHSCREEN
795 touchscreen_set_mode(old_mode);
796 #endif
798 viewportmanager_set_statusbar(oldbars);
800 button_clear_queue();
802 #ifdef HAVE_LCD_BITMAP
803 lcd_setfont(FONT_UI);
804 #if LCD_DEPTH > 1
805 lcd_set_backdrop(old_backdrop);
806 #ifdef HAVE_LCD_COLOR
807 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
808 global_settings.bg_color);
809 #else
810 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
811 #endif
812 #else /* LCD_DEPTH == 1 */
813 lcd_set_drawmode(DRMODE_SOLID);
814 #endif /* LCD_DEPTH */
815 #endif /* HAVE_LCD_BITMAP */
818 #ifdef HAVE_REMOTE_LCD
819 #if LCD_REMOTE_DEPTH > 1
820 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
821 LCD_REMOTE_DEFAULT_BG);
822 #else
823 lcd_remote_set_drawmode(DRMODE_SOLID);
824 #endif
825 #endif
827 if (rc != PLUGIN_GOTO_WPS)
829 FOR_NB_SCREENS(i)
831 screens[i].clear_display();
832 screens[i].update();
836 viewportmanager_set_statusbar(oldbars);
837 if (pfn_tsr_exit == NULL)
838 plugin_loaded = false;
840 sim_plugin_close(pd);
842 if (rc == PLUGIN_ERROR)
843 splash(HZ*2, str(LANG_PLUGIN_ERROR));
845 return rc;
848 /* Returns a pointer to the portion of the plugin buffer that is not already
849 being used. If no plugin is loaded, returns the entire plugin buffer */
850 void* plugin_get_buffer(size_t *buffer_size)
852 int buffer_pos;
854 if (plugin_loaded)
856 if (plugin_size >= PLUGIN_BUFFER_SIZE)
857 return NULL;
859 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
860 buffer_pos = plugin_size;
862 else
864 *buffer_size = PLUGIN_BUFFER_SIZE;
865 buffer_pos = 0;
868 return &pluginbuf[buffer_pos];
871 /* Returns a pointer to the mp3 buffer.
872 Playback gets stopped, to avoid conflicts.
873 Talk buffer is stolen as well.
875 void* plugin_get_audio_buffer(size_t *buffer_size)
877 #if CONFIG_CODEC == SWCODEC
878 return audio_get_buffer(true, buffer_size);
879 #else
880 audio_stop();
881 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
882 *buffer_size = audiobufend - audiobuf;
883 return audiobuf;
884 #endif
887 #ifdef PLUGIN_USE_IRAM
888 /* Initializes plugin IRAM */
889 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
890 char *iedata, size_t iedata_size)
892 /* We need to stop audio playback in order to use codec IRAM */
893 audio_hard_stop();
894 memcpy(iramstart, iramcopy, iram_size);
895 memset(iedata, 0, iedata_size);
896 memset(iramcopy, 0, iram_size);
897 #if NUM_CORES > 1
898 /* writeback cleared iedata and iramcopy areas */
899 cpucache_flush();
900 #endif
902 #endif /* PLUGIN_USE_IRAM */
904 /* The plugin wants to stay resident after leaving its main function, e.g.
905 runs from timer or own thread. The callback is registered to later
906 instruct it to free its resources before a new plugin gets loaded. */
907 void plugin_tsr(bool (*exit_callback)(bool))
909 pfn_tsr_exit = exit_callback; /* remember the callback for later */
912 char *plugin_get_current_filename(void)
914 return current_plugin;