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