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