Commit the first part of FS#10263: Starting playback from within pictureflow, by...
[kugel-rb/myfork.git] / apps / plugin.c
blob31990a9b0037b709b6d9ef9193cda84ce3ed8666
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 */
648 #ifdef HAVE_TOUCHSCREEN
649 action_get_touchscreen_press,
650 #endif
651 #if defined(HAVE_TAGCACHE) && defined(HAVE_TC_RAMCACHE)
652 tagcache_fill_tags,
653 #endif
654 playlist_add,
655 playlist_sync,
656 playlist_remove_all_tracks,
657 playlist_create,
660 int plugin_load(const char* plugin, const void* parameter)
662 int rc;
663 int oldbars;
664 struct plugin_header *hdr;
665 #ifdef SIMULATOR
666 void *pd;
667 #else /* !SIMULATOR */
668 int fd;
669 ssize_t readsize;
670 #if NUM_CORES > 1
671 unsigned my_core;
672 #endif
673 #endif /* !SIMULATOR */
675 #if LCD_DEPTH > 1
676 fb_data* old_backdrop;
677 #endif
679 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
681 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
683 /* not allowing another plugin to load */
684 return PLUGIN_OK;
686 pfn_tsr_exit = NULL;
687 plugin_loaded = false;
690 splash(0, ID2P(LANG_WAIT));
691 strcpy(current_plugin, plugin);
693 #ifdef SIMULATOR
694 hdr = sim_plugin_load((char *)plugin, &pd);
695 if (pd == NULL) {
696 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
697 return -1;
699 if (hdr == NULL
700 || hdr->magic != PLUGIN_MAGIC
701 || hdr->target_id != TARGET_ID) {
702 sim_plugin_close(pd);
703 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
704 return -1;
706 if (hdr->api_version > PLUGIN_API_VERSION
707 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
708 sim_plugin_close(pd);
709 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
710 return -1;
712 #else
713 fd = open(plugin, O_RDONLY);
714 if (fd < 0) {
715 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
716 return fd;
718 #if NUM_CORES > 1
719 /* Make sure COP cache is flushed and invalidated before loading */
720 my_core = switch_core(CURRENT_CORE ^ 1);
721 cpucache_invalidate();
722 switch_core(my_core);
723 #endif
725 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
726 close(fd);
728 if (readsize < 0) {
729 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
730 return -1;
732 hdr = (struct plugin_header *)pluginbuf;
734 if ((unsigned)readsize <= sizeof(struct plugin_header)
735 || hdr->magic != PLUGIN_MAGIC
736 || hdr->target_id != TARGET_ID
737 || hdr->load_addr != pluginbuf
738 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
739 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
740 return -1;
742 if (hdr->api_version > PLUGIN_API_VERSION
743 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
744 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
745 return -1;
747 plugin_size = hdr->end_addr - pluginbuf;
749 /* zero out bss area only, above guards end of pluginbuf */
750 if (plugin_size > readsize)
751 memset(pluginbuf + readsize, 0, plugin_size - readsize);
752 #endif
754 *(hdr->api) = &rockbox_api;
755 plugin_loaded = true;
758 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
759 old_backdrop = lcd_get_backdrop();
760 #endif
761 lcd_clear_display();
762 lcd_update();
764 #ifdef HAVE_REMOTE_LCD
765 lcd_remote_clear_display();
766 lcd_remote_update();
767 #endif
769 cpucache_invalidate();
770 oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
772 #ifdef HAVE_TOUCHSCREEN
773 enum touchscreen_mode old_mode = touchscreen_get_mode();
775 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
776 #endif
778 rc = hdr->entry_point(parameter);
780 #ifdef HAVE_TOUCHSCREEN
781 touchscreen_set_mode(old_mode);
782 #endif
784 viewportmanager_set_statusbar(oldbars);
786 button_clear_queue();
788 #ifdef HAVE_LCD_BITMAP
789 lcd_setfont(FONT_UI);
790 #if LCD_DEPTH > 1
791 lcd_set_backdrop(old_backdrop);
792 #ifdef HAVE_LCD_COLOR
793 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
794 global_settings.bg_color);
795 #else
796 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
797 #endif
798 #else /* LCD_DEPTH == 1 */
799 lcd_set_drawmode(DRMODE_SOLID);
800 #endif /* LCD_DEPTH */
801 #endif /* HAVE_LCD_BITMAP */
803 lcd_clear_display();
804 lcd_update();
806 #ifdef HAVE_REMOTE_LCD
807 #if LCD_REMOTE_DEPTH > 1
808 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
809 LCD_REMOTE_DEFAULT_BG);
810 #else
811 lcd_remote_set_drawmode(DRMODE_SOLID);
812 #endif
813 lcd_remote_clear_display();
816 lcd_remote_update();
819 #endif
820 viewportmanager_set_statusbar(oldbars);
821 if (pfn_tsr_exit == NULL)
822 plugin_loaded = false;
824 sim_plugin_close(pd);
826 switch (rc) {
827 case PLUGIN_OK:
828 break;
830 case PLUGIN_USB_CONNECTED:
831 return PLUGIN_USB_CONNECTED;
833 default:
834 splash(HZ*2, str(LANG_PLUGIN_ERROR));
835 break;
838 return PLUGIN_OK;
841 /* Returns a pointer to the portion of the plugin buffer that is not already
842 being used. If no plugin is loaded, returns the entire plugin buffer */
843 void* plugin_get_buffer(size_t *buffer_size)
845 int buffer_pos;
847 if (plugin_loaded)
849 if (plugin_size >= PLUGIN_BUFFER_SIZE)
850 return NULL;
852 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
853 buffer_pos = plugin_size;
855 else
857 *buffer_size = PLUGIN_BUFFER_SIZE;
858 buffer_pos = 0;
861 return &pluginbuf[buffer_pos];
864 /* Returns a pointer to the mp3 buffer.
865 Playback gets stopped, to avoid conflicts.
866 Talk buffer is stolen as well.
868 void* plugin_get_audio_buffer(size_t *buffer_size)
870 #if CONFIG_CODEC == SWCODEC
871 return audio_get_buffer(true, buffer_size);
872 #else
873 audio_stop();
874 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
875 *buffer_size = audiobufend - audiobuf;
876 return audiobuf;
877 #endif
880 #ifdef PLUGIN_USE_IRAM
881 /* Initializes plugin IRAM */
882 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
883 char *iedata, size_t iedata_size)
885 /* We need to stop audio playback in order to use codec IRAM */
886 audio_hard_stop();
887 memcpy(iramstart, iramcopy, iram_size);
888 memset(iedata, 0, iedata_size);
889 memset(iramcopy, 0, iram_size);
890 #if NUM_CORES > 1
891 /* writeback cleared iedata and iramcopy areas */
892 cpucache_flush();
893 #endif
895 #endif /* PLUGIN_USE_IRAM */
897 /* The plugin wants to stay resident after leaving its main function, e.g.
898 runs from timer or own thread. The callback is registered to later
899 instruct it to free its resources before a new plugin gets loaded. */
900 void plugin_tsr(bool (*exit_callback)(bool))
902 pfn_tsr_exit = exit_callback; /* remember the callback for later */
905 char *plugin_get_current_filename(void)
907 return current_plugin;