apps/plugin.c : do not declare backlight_* part of rockbox api
[kugel-rb.git] / apps / plugin.c
blob9a7e9b578cce83ce64be0bd4dc2ec3e1bb59da51
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 #ifdef HAVE_BACKLIGHT
151 backlight_on,
152 backlight_off,
153 backlight_set_timeout,
154 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
155 backlight_set_brightness,
156 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
158 #if CONFIG_CHARGING
159 backlight_set_timeout_plugged,
160 #endif
161 is_backlight_on,
162 #endif /* HAVE_BACKLIGHT */
163 splash,
164 splashf,
166 #ifdef HAVE_REMOTE_LCD
167 /* remote lcd */
168 lcd_remote_set_contrast,
169 lcd_remote_clear_display,
170 lcd_remote_puts,
171 lcd_remote_puts_scroll,
172 lcd_remote_stop_scroll,
173 lcd_remote_set_drawmode,
174 lcd_remote_get_drawmode,
175 lcd_remote_setfont,
176 lcd_remote_getstringsize,
177 lcd_remote_drawpixel,
178 lcd_remote_drawline,
179 lcd_remote_hline,
180 lcd_remote_vline,
181 lcd_remote_drawrect,
182 lcd_remote_fillrect,
183 lcd_remote_mono_bitmap_part,
184 lcd_remote_mono_bitmap,
185 lcd_remote_putsxy,
186 lcd_remote_puts_style,
187 lcd_remote_puts_scroll_style,
188 &lcd_remote_framebuffer[0][0],
189 lcd_remote_update,
190 lcd_remote_update_rect,
192 remote_backlight_on,
193 remote_backlight_off,
194 remote_backlight_set_timeout,
195 #if CONFIG_CHARGING
196 remote_backlight_set_timeout_plugged,
197 #endif
198 #endif /* HAVE_REMOTE_LCD */
199 #if NB_SCREENS == 2
200 {&screens[SCREEN_MAIN], &screens[SCREEN_REMOTE]},
201 #else
202 {&screens[SCREEN_MAIN]},
203 #endif
204 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
205 lcd_remote_set_foreground,
206 lcd_remote_get_foreground,
207 lcd_remote_set_background,
208 lcd_remote_get_background,
209 lcd_remote_bitmap_part,
210 lcd_remote_bitmap,
211 #endif
212 viewport_set_defaults,
214 /* list */
215 gui_synclist_init,
216 gui_synclist_set_nb_items,
217 gui_synclist_set_icon_callback,
218 gui_synclist_get_nb_items,
219 gui_synclist_get_sel_pos,
220 gui_synclist_draw,
221 gui_synclist_select_item,
222 gui_synclist_add_item,
223 gui_synclist_del_item,
224 gui_synclist_limit_scroll,
225 gui_synclist_do_button,
226 gui_synclist_set_title,
227 gui_syncyesno_run,
228 simplelist_info_init,
229 simplelist_show_list,
231 /* button */
232 button_get,
233 button_get_w_tmo,
234 button_status,
235 #ifdef HAVE_BUTTON_DATA
236 button_get_data,
237 #endif
238 button_clear_queue,
239 button_queue_count,
240 #ifdef HAS_BUTTON_HOLD
241 button_hold,
242 #endif
243 #ifdef HAVE_TOUCHSCREEN
244 touchscreen_set_mode,
245 #endif
247 #ifdef HAVE_BUTTON_LIGHT
248 buttonlight_set_timeout,
249 buttonlight_off,
250 buttonlight_on,
251 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
252 buttonlight_set_brightness,
253 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
254 #endif /* HAVE_BUTTON_LIGHT */
256 /* file */
257 (open_func)PREFIX(open),
258 PREFIX(close),
259 (read_func)PREFIX(read),
260 PREFIX(lseek),
261 (creat_func)PREFIX(creat),
262 (write_func)PREFIX(write),
263 PREFIX(remove),
264 PREFIX(rename),
265 PREFIX(ftruncate),
266 PREFIX(filesize),
267 fdprintf,
268 read_line,
269 settings_parseline,
270 ata_sleep,
271 ata_spin,
272 ata_spindown,
273 #if USING_ATA_CALLBACK
274 register_ata_idle_func,
275 unregister_ata_idle_func,
276 #endif /* USING_ATA_CALLBACK */
277 reload_directory,
278 create_numbered_filename,
279 file_exists,
281 /* dir */
282 opendir,
283 closedir,
284 readdir,
285 mkdir,
286 rmdir,
287 dir_exists,
289 /* kernel/ system */
290 PREFIX(sleep),
291 yield,
292 &current_tick,
293 default_event_handler,
294 default_event_handler_ex,
295 threads,
296 create_thread,
297 thread_exit,
298 thread_wait,
299 #if (CONFIG_CODEC == SWCODEC)
300 mutex_init,
301 mutex_lock,
302 mutex_unlock,
303 align_buffer,
304 #endif
306 reset_poweroff_timer,
307 #ifndef SIMULATOR
308 system_memory_guard,
309 &cpu_frequency,
311 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
312 #ifdef CPU_BOOST_LOGGING
313 cpu_boost_,
314 #else
315 cpu_boost,
316 #endif
317 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
318 #endif /* !SIMULATOR */
319 #ifdef HAVE_SCHEDULER_BOOSTCTRL
320 trigger_cpu_boost,
321 cancel_cpu_boost,
322 #endif
323 #ifdef CACHE_FUNCTIONS_AS_CALL
324 flush_icache,
325 invalidate_icache,
326 #endif
327 timer_register,
328 timer_unregister,
329 timer_set_period,
331 queue_init,
332 queue_delete,
333 queue_post,
334 queue_wait_w_tmo,
335 #if CONFIG_CODEC == SWCODEC
336 queue_enable_queue_send,
337 queue_empty,
338 queue_wait,
339 queue_send,
340 queue_reply,
341 #endif
342 usb_acknowledge,
343 #ifdef RB_PROFILE
344 profile_thread,
345 profstop,
346 __cyg_profile_func_enter,
347 __cyg_profile_func_exit,
348 #endif
350 #ifdef SIMULATOR
351 /* special simulator hooks */
352 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
353 sim_lcd_ex_init,
354 sim_lcd_ex_update_rect,
355 #endif
356 #endif
358 /* strings and memory */
359 snprintf,
360 vsnprintf,
361 strcpy,
362 strncpy,
363 strlen,
364 strrchr,
365 strcmp,
366 strncmp,
367 strcasecmp,
368 strncasecmp,
369 memset,
370 memcpy,
371 memmove,
372 _ctype_,
373 atoi,
374 strchr,
375 strcat,
376 memchr,
377 memcmp,
378 strcasestr,
379 strtok_r,
380 /* unicode stuff */
381 utf8decode,
382 iso_decode,
383 utf16LEdecode,
384 utf16BEdecode,
385 utf8encode,
386 utf8length,
387 utf8seek,
389 /* sound */
390 sound_set,
391 sound_default,
392 sound_min,
393 sound_max,
394 sound_unit,
395 sound_val2phys,
396 #ifndef SIMULATOR
397 mp3_play_data,
398 mp3_play_pause,
399 mp3_play_stop,
400 mp3_is_playing,
401 #if CONFIG_CODEC != SWCODEC
402 bitswap,
403 #endif
404 #endif
405 #if CONFIG_CODEC == SWCODEC
406 &audio_master_sampr_list[0],
407 &hw_freq_sampr[0],
408 pcm_apply_settings,
409 pcm_play_data,
410 pcm_play_stop,
411 pcm_set_frequency,
412 pcm_is_playing,
413 pcm_is_paused,
414 pcm_play_pause,
415 pcm_get_bytes_waiting,
416 pcm_calculate_peaks,
417 pcm_play_lock,
418 pcm_play_unlock,
419 #ifdef HAVE_RECORDING
420 &rec_freq_sampr[0],
421 pcm_init_recording,
422 pcm_close_recording,
423 pcm_record_data,
424 pcm_record_more,
425 pcm_stop_recording,
426 pcm_calculate_rec_peaks,
427 audio_set_recording_gain,
428 #endif /* HAVE_RECORDING */
429 #if INPUT_SRC_CAPS != 0
430 audio_set_output_source,
431 audio_set_input_source,
432 #endif
433 dsp_set_crossfeed,
434 dsp_set_eq,
435 dsp_dither_enable,
436 dsp_configure,
437 dsp_process,
438 #endif /* CONFIG_CODEC == SWCODEC */
440 /* playback control */
441 playlist_amount,
442 playlist_resume,
443 playlist_start,
444 PREFIX(audio_play),
445 audio_stop,
446 audio_pause,
447 audio_resume,
448 audio_next,
449 audio_prev,
450 audio_ff_rewind,
451 audio_next_track,
452 audio_status,
453 audio_has_changed_track,
454 audio_current_track,
455 audio_flush_and_reload_tracks,
456 audio_get_file_pos,
457 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
458 mpeg_get_last_header,
459 #endif
460 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
461 (CONFIG_CODEC == SWCODEC)
462 sound_set_pitch,
463 #endif
465 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
466 /* MAS communication */
467 mas_readmem,
468 mas_writemem,
469 mas_readreg,
470 mas_writereg,
471 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
472 mas_codec_writereg,
473 mas_codec_readreg,
474 i2c_begin,
475 i2c_end,
476 i2c_write,
477 #endif
478 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
480 /* menu */
481 do_menu,
482 /* statusbars */
483 &statusbars,
484 gui_syncstatusbar_draw,
485 /* options */
486 find_setting,
487 option_screen,
488 set_option,
489 set_bool_options,
490 set_int,
491 set_bool,
492 #ifdef HAVE_LCD_COLOR
493 set_color,
494 #endif
496 /* action handling */
497 get_custom_action,
498 get_action,
499 action_userabort,
501 /* power */
502 battery_level,
503 battery_level_safe,
504 battery_time,
505 #ifndef SIMULATOR
506 battery_voltage,
507 #endif
508 #if CONFIG_CHARGING
509 charger_inserted,
510 # if CONFIG_CHARGING == CHARGING_MONITOR
511 charging_state,
512 # endif
513 #endif
514 #ifdef HAVE_USB_POWER
515 usb_powered,
516 #endif
518 /* misc */
519 srand,
520 rand,
521 (qsort_func)qsort,
522 kbd_input,
523 get_time,
524 set_time,
525 #if CONFIG_RTC
526 mktime,
527 #endif
528 plugin_get_buffer,
529 plugin_get_audio_buffer,
530 plugin_tsr,
531 plugin_get_current_filename,
532 #ifdef PLUGIN_USE_IRAM
533 plugin_iram_init,
534 #endif
535 #if defined(DEBUG) || defined(SIMULATOR)
536 debugf,
537 #endif
538 #ifdef ROCKBOX_HAS_LOGF
539 _logf,
540 #endif
541 &global_settings,
542 &global_status,
543 talk_disable,
544 #if CONFIG_CODEC == SWCODEC
545 codec_load_file,
546 get_codec_filename,
547 get_metadata,
548 #endif
549 mp3info,
550 count_mp3_frames,
551 create_xing_header,
552 find_next_frame,
553 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
554 peak_meter_scale_value,
555 peak_meter_set_use_dbfs,
556 peak_meter_get_use_dbfs,
557 #endif
558 #ifdef HAVE_LCD_BITMAP
559 read_bmp_file,
560 screen_dump_set_hook,
561 #endif
562 show_logo,
563 tree_get_context,
564 set_current_file,
565 set_dirfilter,
567 #ifdef HAVE_WHEEL_POSITION
568 wheel_status,
569 wheel_send_events,
570 #endif
572 #ifdef IRIVER_H100_SERIES
573 /* Routines for the iriver_flash -plugin. */
574 detect_original_firmware,
575 detect_flashed_ramimage,
576 detect_flashed_romimage,
577 #endif
578 led,
579 #if (CONFIG_CODEC == SWCODEC)
580 bufopen,
581 bufalloc,
582 bufclose,
583 bufseek,
584 bufadvance,
585 bufread,
586 bufgetdata,
587 bufgettail,
588 bufcuttail,
590 buf_get_offset,
591 buf_handle_offset,
592 buf_request_buffer_handle,
593 buf_set_base_handle,
594 buf_used,
595 #endif
597 #ifdef HAVE_TAGCACHE
598 tagcache_search,
599 tagcache_search_set_uniqbuf,
600 tagcache_search_add_filter,
601 tagcache_get_next,
602 tagcache_retrieve,
603 tagcache_search_finish,
604 tagcache_get_numeric,
605 #endif
607 #ifdef HAVE_ALBUMART
608 find_albumart,
609 search_albumart_files,
610 #endif
612 thread_thaw,
614 #ifdef HAVE_SEMAPHORE_OBJECTS
615 semaphore_init,
616 semaphore_wait,
617 semaphore_release,
618 #endif
620 appsversion,
621 /* new stuff at the end, sort into place next time
622 the API gets incompatible */
623 get_settings_list,
626 int plugin_load(const char* plugin, const void* parameter)
628 int rc;
629 struct plugin_header *hdr;
630 #ifdef SIMULATOR
631 void *pd;
632 #else /* !SIMULATOR */
633 int fd;
634 ssize_t readsize;
635 #if NUM_CORES > 1
636 unsigned my_core;
637 #endif
638 #endif /* !SIMULATOR */
640 #if LCD_DEPTH > 1
641 fb_data* old_backdrop;
642 #endif
644 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
646 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
648 /* not allowing another plugin to load */
649 return PLUGIN_OK;
651 pfn_tsr_exit = NULL;
652 plugin_loaded = false;
655 splash(0, ID2P(LANG_WAIT));
656 strcpy(current_plugin, plugin);
658 #ifdef SIMULATOR
659 hdr = sim_plugin_load((char *)plugin, &pd);
660 if (pd == NULL) {
661 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
662 return -1;
664 if (hdr == NULL
665 || hdr->magic != PLUGIN_MAGIC
666 || hdr->target_id != TARGET_ID) {
667 sim_plugin_close(pd);
668 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
669 return -1;
671 if (hdr->api_version > PLUGIN_API_VERSION
672 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
673 sim_plugin_close(pd);
674 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
675 return -1;
677 #else
678 fd = open(plugin, O_RDONLY);
679 if (fd < 0) {
680 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
681 return fd;
683 #if NUM_CORES > 1
684 /* Make sure COP cache is flushed and invalidated before loading */
685 my_core = switch_core(CURRENT_CORE ^ 1);
686 invalidate_icache();
687 switch_core(my_core);
688 #endif
690 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
691 close(fd);
693 if (readsize < 0) {
694 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
695 return -1;
697 hdr = (struct plugin_header *)pluginbuf;
699 if ((unsigned)readsize <= sizeof(struct plugin_header)
700 || hdr->magic != PLUGIN_MAGIC
701 || hdr->target_id != TARGET_ID
702 || hdr->load_addr != pluginbuf
703 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
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 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
710 return -1;
712 plugin_size = hdr->end_addr - pluginbuf;
714 /* zero out bss area only, above guards end of pluginbuf */
715 if (plugin_size > readsize)
716 memset(pluginbuf + readsize, 0, plugin_size - readsize);
717 #endif
719 plugin_loaded = true;
722 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
723 old_backdrop = lcd_get_backdrop();
724 #endif
725 lcd_clear_display();
726 lcd_update();
728 #ifdef HAVE_REMOTE_LCD
729 lcd_remote_clear_display();
730 lcd_remote_update();
731 #endif
733 invalidate_icache();
735 rc = hdr->entry_point(&rockbox_api, parameter);
737 button_clear_queue();
739 #ifdef HAVE_LCD_BITMAP
740 #if LCD_DEPTH > 1
741 lcd_set_backdrop(old_backdrop);
742 #ifdef HAVE_LCD_COLOR
743 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
744 global_settings.bg_color);
745 #else
746 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
747 #endif
748 #else /* LCD_DEPTH == 1 */
749 lcd_set_drawmode(DRMODE_SOLID);
750 #endif /* LCD_DEPTH */
751 #endif /* HAVE_LCD_BITMAP */
753 lcd_clear_display();
754 lcd_update();
756 #ifdef HAVE_REMOTE_LCD
757 #if LCD_REMOTE_DEPTH > 1
758 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
759 LCD_REMOTE_DEFAULT_BG);
760 #else
761 lcd_remote_set_drawmode(DRMODE_SOLID);
762 #endif
763 lcd_remote_clear_display();
766 lcd_remote_update();
769 #endif
771 if (pfn_tsr_exit == NULL)
772 plugin_loaded = false;
774 sim_plugin_close(pd);
776 switch (rc) {
777 case PLUGIN_OK:
778 break;
780 case PLUGIN_USB_CONNECTED:
781 return PLUGIN_USB_CONNECTED;
783 default:
784 splash(HZ*2, str(LANG_PLUGIN_ERROR));
785 break;
787 return PLUGIN_OK;
790 /* Returns a pointer to the portion of the plugin buffer that is not already
791 being used. If no plugin is loaded, returns the entire plugin buffer */
792 void* plugin_get_buffer(size_t *buffer_size)
794 int buffer_pos;
796 if (plugin_loaded)
798 if (plugin_size >= PLUGIN_BUFFER_SIZE)
799 return NULL;
801 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
802 buffer_pos = plugin_size;
804 else
806 *buffer_size = PLUGIN_BUFFER_SIZE;
807 buffer_pos = 0;
810 return &pluginbuf[buffer_pos];
813 /* Returns a pointer to the mp3 buffer.
814 Playback gets stopped, to avoid conflicts.
815 Talk buffer is stolen as well.
817 void* plugin_get_audio_buffer(size_t *buffer_size)
819 #if CONFIG_CODEC == SWCODEC
820 return audio_get_buffer(true, buffer_size);
821 #else
822 audio_stop();
823 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
824 *buffer_size = audiobufend - audiobuf;
825 return audiobuf;
826 #endif
829 #ifdef PLUGIN_USE_IRAM
830 /* Initializes plugin IRAM */
831 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
832 char *iedata, size_t iedata_size)
834 /* We need to stop audio playback in order to use codec IRAM */
835 audio_hard_stop();
836 memcpy(iramstart, iramcopy, iram_size);
837 memset(iedata, 0, iedata_size);
838 memset(iramcopy, 0, iram_size);
839 #if NUM_CORES > 1
840 /* writeback cleared iedata and iramcopy areas */
841 flush_icache();
842 #endif
844 #endif /* PLUGIN_USE_IRAM */
846 /* The plugin wants to stay resident after leaving its main function, e.g.
847 runs from timer or own thread. The callback is registered to later
848 instruct it to free its resources before a new plugin gets loaded. */
849 void plugin_tsr(bool (*exit_callback)(bool))
851 pfn_tsr_exit = exit_callback; /* remember the callback for later */
854 char *plugin_get_current_filename(void)
856 return current_plugin;