rbutil: fix voice download for some targets. (again naming issues)
[kugel-rb.git] / apps / plugin.c
blobc4e5a0bb0f62dc40506c520458556d7a00b6143f
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 playlist_add,
465 playlist_sync,
466 playlist_remove_all_tracks,
467 playlist_create,
468 playlist_insert_track,
469 playlist_shuffle,
470 PREFIX(audio_play),
471 audio_stop,
472 audio_pause,
473 audio_resume,
474 audio_next,
475 audio_prev,
476 audio_ff_rewind,
477 audio_next_track,
478 audio_status,
479 audio_current_track,
480 audio_flush_and_reload_tracks,
481 audio_get_file_pos,
482 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
483 mpeg_get_last_header,
484 #endif
485 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
486 (CONFIG_CODEC == SWCODEC)
487 sound_set_pitch,
488 #endif
490 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
491 /* MAS communication */
492 mas_readmem,
493 mas_writemem,
494 mas_readreg,
495 mas_writereg,
496 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
497 mas_codec_writereg,
498 mas_codec_readreg,
499 i2c_begin,
500 i2c_end,
501 i2c_write,
502 #endif
503 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
505 /* menu */
506 do_menu,
507 /* statusbars */
508 &statusbars,
509 gui_syncstatusbar_draw,
510 /* options */
511 get_settings_list,
512 find_setting,
513 option_screen,
514 set_option,
515 set_bool_options,
516 set_int,
517 set_bool,
518 #ifdef HAVE_LCD_COLOR
519 set_color,
520 #endif
522 /* action handling */
523 get_custom_action,
524 get_action,
525 #ifdef HAVE_TOUCHSCREEN
526 action_get_touchscreen_press,
527 #endif
528 action_userabort,
530 /* power */
531 battery_level,
532 battery_level_safe,
533 battery_time,
534 #ifndef SIMULATOR
535 battery_voltage,
536 #endif
537 #if CONFIG_CHARGING
538 charger_inserted,
539 # if CONFIG_CHARGING >= CHARGING_MONITOR
540 charging_state,
541 # endif
542 #endif
543 #ifdef HAVE_USB_POWER
544 usb_powered,
545 #endif
547 /* misc */
548 srand,
549 rand,
550 (qsort_func)qsort,
551 kbd_input,
552 get_time,
553 set_time,
554 #if CONFIG_RTC
555 mktime,
556 #endif
557 plugin_get_buffer,
558 plugin_get_audio_buffer,
559 plugin_tsr,
560 plugin_get_current_filename,
561 #ifdef PLUGIN_USE_IRAM
562 plugin_iram_init,
563 #endif
564 #if defined(DEBUG) || defined(SIMULATOR)
565 debugf,
566 #endif
567 #ifdef ROCKBOX_HAS_LOGF
568 _logf,
569 #endif
570 &global_settings,
571 &global_status,
572 talk_disable,
573 #if CONFIG_CODEC == SWCODEC
574 codec_thread_do_callback,
575 codec_load_file,
576 get_codec_filename,
577 #endif
578 get_metadata,
579 mp3info,
580 count_mp3_frames,
581 create_xing_header,
582 find_next_frame,
583 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
584 peak_meter_scale_value,
585 peak_meter_set_use_dbfs,
586 peak_meter_get_use_dbfs,
587 #endif
588 #ifdef HAVE_LCD_BITMAP
589 read_bmp_file,
590 read_bmp_fd,
591 #ifdef HAVE_JPEG
592 read_jpeg_file,
593 read_jpeg_fd,
594 #endif
595 screen_dump_set_hook,
596 #endif
597 show_logo,
598 tree_get_context,
599 set_current_file,
600 set_dirfilter,
602 #ifdef HAVE_WHEEL_POSITION
603 wheel_status,
604 wheel_send_events,
605 #endif
607 #ifdef IRIVER_H100_SERIES
608 /* Routines for the iriver_flash -plugin. */
609 detect_original_firmware,
610 detect_flashed_ramimage,
611 detect_flashed_romimage,
612 #endif
613 led,
614 #if (CONFIG_CODEC == SWCODEC)
615 bufopen,
616 bufalloc,
617 bufclose,
618 bufseek,
619 bufadvance,
620 bufread,
621 bufgetdata,
622 bufgettail,
623 bufcuttail,
625 buf_get_offset,
626 buf_handle_offset,
627 buf_request_buffer_handle,
628 buf_set_base_handle,
629 buf_used,
630 #endif
632 #ifdef HAVE_TAGCACHE
633 tagcache_search,
634 tagcache_search_set_uniqbuf,
635 tagcache_search_add_filter,
636 tagcache_get_next,
637 tagcache_retrieve,
638 tagcache_search_finish,
639 tagcache_get_numeric,
640 #ifdef HAVE_TC_RAMCACHE
641 tagcache_fill_tags,
642 #endif
643 #endif
645 #ifdef HAVE_ALBUMART
646 find_albumart,
647 search_albumart_files,
648 #endif
650 #ifdef HAVE_SEMAPHORE_OBJECTS
651 semaphore_init,
652 semaphore_wait,
653 semaphore_release,
654 #endif
656 appsversion,
657 /* new stuff at the end, sort into place next time
658 the API gets incompatible */
661 int plugin_load(const char* plugin, const void* parameter)
663 int rc;
664 int oldbars;
665 struct plugin_header *hdr;
666 #ifdef SIMULATOR
667 void *pd;
668 #else /* !SIMULATOR */
669 int fd;
670 ssize_t readsize;
671 #if NUM_CORES > 1
672 unsigned my_core;
673 #endif
674 #endif /* !SIMULATOR */
676 #if LCD_DEPTH > 1
677 fb_data* old_backdrop;
678 #endif
680 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
682 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
684 /* not allowing another plugin to load */
685 return PLUGIN_OK;
687 pfn_tsr_exit = NULL;
688 plugin_loaded = false;
691 splash(0, ID2P(LANG_WAIT));
692 strcpy(current_plugin, plugin);
694 #ifdef SIMULATOR
695 hdr = sim_plugin_load((char *)plugin, &pd);
696 if (pd == NULL) {
697 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
698 return -1;
700 if (hdr == NULL
701 || hdr->magic != PLUGIN_MAGIC
702 || hdr->target_id != TARGET_ID) {
703 sim_plugin_close(pd);
704 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
705 return -1;
707 if (hdr->api_version > PLUGIN_API_VERSION
708 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
709 sim_plugin_close(pd);
710 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
711 return -1;
713 #else
714 fd = open(plugin, O_RDONLY);
715 if (fd < 0) {
716 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
717 return fd;
719 #if NUM_CORES > 1
720 /* Make sure COP cache is flushed and invalidated before loading */
721 my_core = switch_core(CURRENT_CORE ^ 1);
722 cpucache_invalidate();
723 switch_core(my_core);
724 #endif
726 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
727 close(fd);
729 if (readsize < 0) {
730 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
731 return -1;
733 hdr = (struct plugin_header *)pluginbuf;
735 if ((unsigned)readsize <= sizeof(struct plugin_header)
736 || hdr->magic != PLUGIN_MAGIC
737 || hdr->target_id != TARGET_ID
738 || hdr->load_addr != pluginbuf
739 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
740 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
741 return -1;
743 if (hdr->api_version > PLUGIN_API_VERSION
744 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
745 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
746 return -1;
748 plugin_size = hdr->end_addr - pluginbuf;
750 /* zero out bss area only, above guards end of pluginbuf */
751 if (plugin_size > readsize)
752 memset(pluginbuf + readsize, 0, plugin_size - readsize);
753 #endif
755 *(hdr->api) = &rockbox_api;
756 plugin_loaded = true;
759 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
760 old_backdrop = lcd_get_backdrop();
761 #endif
762 lcd_clear_display();
763 lcd_update();
765 #ifdef HAVE_REMOTE_LCD
766 lcd_remote_clear_display();
767 lcd_remote_update();
768 #endif
770 cpucache_invalidate();
771 oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
773 #ifdef HAVE_TOUCHSCREEN
774 enum touchscreen_mode old_mode = touchscreen_get_mode();
776 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
777 #endif
779 rc = hdr->entry_point(parameter);
781 #ifdef HAVE_TOUCHSCREEN
782 touchscreen_set_mode(old_mode);
783 #endif
785 viewportmanager_set_statusbar(oldbars);
787 button_clear_queue();
789 #ifdef HAVE_LCD_BITMAP
790 lcd_setfont(FONT_UI);
791 #if LCD_DEPTH > 1
792 lcd_set_backdrop(old_backdrop);
793 #ifdef HAVE_LCD_COLOR
794 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
795 global_settings.bg_color);
796 #else
797 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
798 #endif
799 #else /* LCD_DEPTH == 1 */
800 lcd_set_drawmode(DRMODE_SOLID);
801 #endif /* LCD_DEPTH */
802 #endif /* HAVE_LCD_BITMAP */
804 lcd_clear_display();
805 lcd_update();
807 #ifdef HAVE_REMOTE_LCD
808 #if LCD_REMOTE_DEPTH > 1
809 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
810 LCD_REMOTE_DEFAULT_BG);
811 #else
812 lcd_remote_set_drawmode(DRMODE_SOLID);
813 #endif
814 lcd_remote_clear_display();
817 lcd_remote_update();
820 #endif
821 viewportmanager_set_statusbar(oldbars);
822 if (pfn_tsr_exit == NULL)
823 plugin_loaded = false;
825 sim_plugin_close(pd);
827 switch (rc) {
828 case PLUGIN_OK:
829 break;
831 case PLUGIN_USB_CONNECTED:
832 return PLUGIN_USB_CONNECTED;
834 default:
835 splash(HZ*2, str(LANG_PLUGIN_ERROR));
836 break;
839 return PLUGIN_OK;
842 /* Returns a pointer to the portion of the plugin buffer that is not already
843 being used. If no plugin is loaded, returns the entire plugin buffer */
844 void* plugin_get_buffer(size_t *buffer_size)
846 int buffer_pos;
848 if (plugin_loaded)
850 if (plugin_size >= PLUGIN_BUFFER_SIZE)
851 return NULL;
853 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
854 buffer_pos = plugin_size;
856 else
858 *buffer_size = PLUGIN_BUFFER_SIZE;
859 buffer_pos = 0;
862 return &pluginbuf[buffer_pos];
865 /* Returns a pointer to the mp3 buffer.
866 Playback gets stopped, to avoid conflicts.
867 Talk buffer is stolen as well.
869 void* plugin_get_audio_buffer(size_t *buffer_size)
871 #if CONFIG_CODEC == SWCODEC
872 return audio_get_buffer(true, buffer_size);
873 #else
874 audio_stop();
875 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
876 *buffer_size = audiobufend - audiobuf;
877 return audiobuf;
878 #endif
881 #ifdef PLUGIN_USE_IRAM
882 /* Initializes plugin IRAM */
883 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
884 char *iedata, size_t iedata_size)
886 /* We need to stop audio playback in order to use codec IRAM */
887 audio_hard_stop();
888 memcpy(iramstart, iramcopy, iram_size);
889 memset(iedata, 0, iedata_size);
890 memset(iramcopy, 0, iram_size);
891 #if NUM_CORES > 1
892 /* writeback cleared iedata and iramcopy areas */
893 cpucache_flush();
894 #endif
896 #endif /* PLUGIN_USE_IRAM */
898 /* The plugin wants to stay resident after leaving its main function, e.g.
899 runs from timer or own thread. The callback is registered to later
900 instruct it to free its resources before a new plugin gets loaded. */
901 void plugin_tsr(bool (*exit_callback)(bool))
903 pfn_tsr_exit = exit_callback; /* remember the callback for later */
906 char *plugin_get_current_filename(void)
908 return current_plugin;