1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
32 #include "backlight.h"
33 #include "sound_menu.h"
35 #include "powermgmt.h"
38 #include "option_select.h"
47 #ifdef HAVE_LCD_BITMAP
48 #include "scrollbar.h"
49 #include "peakmeter.h"
55 #define PREFIX(_x_) sim_ ## _x_
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(int shades
, unsigned long (*getpixel
)(int, int));
65 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
67 #define sim_plugin_close(x)
68 extern unsigned char pluginbuf
[];
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
= {
91 #ifdef HAVE_LCD_CHARCELLS
93 lcd_get_locked_pattern
,
101 &lcd_framebuffer
[0][0],
112 lcd_mono_bitmap_part
,
125 lcd_bitmap_transparent_part
,
126 lcd_bitmap_transparent
,
128 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
129 || defined(IRIVER_H10) || defined(COWON_D2)
132 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
135 #endif /* LCD_DEPTH */
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)
153 #endif /* HAVE_LCD_BITMAP */
158 backlight_set_timeout
,
159 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
160 backlight_set_brightness
,
161 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
164 backlight_set_timeout_plugged
,
170 #ifdef HAVE_REMOTE_LCD
172 lcd_remote_set_contrast
,
173 lcd_remote_clear_display
,
175 lcd_remote_puts_scroll
,
176 lcd_remote_stop_scroll
,
177 lcd_remote_set_drawmode
,
178 lcd_remote_get_drawmode
,
180 lcd_remote_getstringsize
,
181 lcd_remote_drawpixel
,
187 lcd_remote_mono_bitmap_part
,
188 lcd_remote_mono_bitmap
,
190 lcd_remote_puts_style
,
191 lcd_remote_puts_scroll_style
,
192 &lcd_remote_framebuffer
[0][0],
194 lcd_remote_update_rect
,
197 remote_backlight_off
,
198 remote_backlight_set_timeout
,
200 remote_backlight_set_timeout_plugged
,
202 #endif /* HAVE_REMOTE_LCD */
204 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
206 {&screens
[SCREEN_MAIN
]},
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
,
216 viewport_set_defaults
,
217 viewportmanager_set_statusbar
,
221 gui_synclist_set_nb_items
,
222 gui_synclist_set_icon_callback
,
223 gui_synclist_get_nb_items
,
224 gui_synclist_get_sel_pos
,
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
,
233 simplelist_info_init
,
234 simplelist_show_list
,
240 #ifdef HAVE_BUTTON_DATA
245 #ifdef HAS_BUTTON_HOLD
248 #ifdef HAVE_TOUCHSCREEN
249 touchscreen_set_mode
,
252 #ifdef HAVE_BUTTON_LIGHT
253 buttonlight_set_timeout
,
256 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
257 buttonlight_set_brightness
,
258 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
259 #endif /* HAVE_BUTTON_LIGHT */
262 (open_func
)PREFIX(open
),
264 (read_func
)PREFIX(read
),
266 (creat_func
)PREFIX(creat
),
267 (write_func
)PREFIX(write
),
278 #if USING_STORAGE_CALLBACK
279 register_storage_idle_func
,
280 unregister_storage_idle_func
,
281 #endif /* USING_STORAGE_CALLBACK */
283 create_numbered_filename
,
298 default_event_handler
,
299 default_event_handler_ex
,
303 #if (CONFIG_CODEC == SWCODEC)
305 #ifdef HAVE_PRIORITY_SCHEDULING
313 reset_poweroff_timer
,
318 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
319 #ifdef CPU_BOOST_LOGGING
324 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
325 #endif /* !SIMULATOR */
326 #ifdef HAVE_SCHEDULER_BOOSTCTRL
330 #ifdef CACHE_FUNCTIONS_AS_CALL
342 #if CONFIG_CODEC == SWCODEC
343 queue_enable_queue_send
,
353 __cyg_profile_func_enter
,
354 __cyg_profile_func_exit
,
358 /* special simulator hooks */
359 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
361 sim_lcd_ex_update_rect
,
365 /* strings and memory */
408 #if CONFIG_CODEC != SWCODEC
412 #if CONFIG_CODEC == SWCODEC
413 &audio_master_sampr_list
[0],
422 pcm_get_bytes_waiting
,
426 #ifdef HAVE_RECORDING
433 pcm_calculate_rec_peaks
,
434 audio_set_recording_gain
,
435 #endif /* HAVE_RECORDING */
436 #if INPUT_SRC_CAPS != 0
437 audio_set_output_source
,
438 audio_set_input_source
,
445 #endif /* CONFIG_CODEC == SWCODEC */
447 /* playback control */
460 audio_has_changed_track
,
462 audio_flush_and_reload_tracks
,
464 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
465 mpeg_get_last_header
,
467 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
468 (CONFIG_CODEC == SWCODEC)
472 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
473 /* MAS communication */
478 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
485 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
491 gui_syncstatusbar_draw
,
500 #ifdef HAVE_LCD_COLOR
504 /* action handling */
518 # if CONFIG_CHARGING == CHARGING_MONITOR
522 #ifdef HAVE_USB_POWER
537 plugin_get_audio_buffer
,
539 plugin_get_current_filename
,
540 #ifdef PLUGIN_USE_IRAM
543 #if defined(DEBUG) || defined(SIMULATOR)
546 #ifdef ROCKBOX_HAS_LOGF
552 #if CONFIG_CODEC == SWCODEC
553 codec_thread_do_callback
,
562 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
563 peak_meter_scale_value
,
564 peak_meter_set_use_dbfs
,
565 peak_meter_get_use_dbfs
,
567 #ifdef HAVE_LCD_BITMAP
569 screen_dump_set_hook
,
576 #ifdef HAVE_WHEEL_POSITION
581 #ifdef IRIVER_H100_SERIES
582 /* Routines for the iriver_flash -plugin. */
583 detect_original_firmware
,
584 detect_flashed_ramimage
,
585 detect_flashed_romimage
,
588 #if (CONFIG_CODEC == SWCODEC)
601 buf_request_buffer_handle
,
608 tagcache_search_set_uniqbuf
,
609 tagcache_search_add_filter
,
612 tagcache_search_finish
,
613 tagcache_get_numeric
,
618 search_albumart_files
,
621 #ifdef HAVE_SEMAPHORE_OBJECTS
628 /* new stuff at the end, sort into place next time
629 the API gets incompatible */
632 int plugin_load(const char* plugin
, const void* parameter
)
636 struct plugin_header
*hdr
;
639 #else /* !SIMULATOR */
645 #endif /* !SIMULATOR */
648 fb_data
* old_backdrop
;
651 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
653 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
655 /* not allowing another plugin to load */
659 plugin_loaded
= false;
662 splash(0, ID2P(LANG_WAIT
));
663 strcpy(current_plugin
, plugin
);
666 hdr
= sim_plugin_load((char *)plugin
, &pd
);
668 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
672 || hdr
->magic
!= PLUGIN_MAGIC
673 || hdr
->target_id
!= TARGET_ID
) {
674 sim_plugin_close(pd
);
675 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
678 if (hdr
->api_version
> PLUGIN_API_VERSION
679 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
680 sim_plugin_close(pd
);
681 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
685 fd
= open(plugin
, O_RDONLY
);
687 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
691 /* Make sure COP cache is flushed and invalidated before loading */
692 my_core
= switch_core(CURRENT_CORE
^ 1);
694 switch_core(my_core
);
697 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
701 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
704 hdr
= (struct plugin_header
*)pluginbuf
;
706 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
707 || hdr
->magic
!= PLUGIN_MAGIC
708 || hdr
->target_id
!= TARGET_ID
709 || hdr
->load_addr
!= pluginbuf
710 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
711 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
714 if (hdr
->api_version
> PLUGIN_API_VERSION
715 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
716 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
719 plugin_size
= hdr
->end_addr
- pluginbuf
;
721 /* zero out bss area only, above guards end of pluginbuf */
722 if (plugin_size
> readsize
)
723 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
726 *(hdr
->api
) = &rockbox_api
;
727 plugin_loaded
= true;
730 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
731 old_backdrop
= lcd_get_backdrop();
736 #ifdef HAVE_REMOTE_LCD
737 lcd_remote_clear_display();
742 oldbars
= viewportmanager_set_statusbar(false);
744 rc
= hdr
->entry_point(parameter
);
746 viewportmanager_set_statusbar(true);
748 button_clear_queue();
750 #ifdef HAVE_LCD_BITMAP
752 lcd_set_backdrop(old_backdrop
);
753 #ifdef HAVE_LCD_COLOR
754 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
755 global_settings
.bg_color
);
757 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
759 #else /* LCD_DEPTH == 1 */
760 lcd_set_drawmode(DRMODE_SOLID
);
761 #endif /* LCD_DEPTH */
762 #endif /* HAVE_LCD_BITMAP */
767 #ifdef HAVE_REMOTE_LCD
768 #if LCD_REMOTE_DEPTH > 1
769 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
770 LCD_REMOTE_DEFAULT_BG
);
772 lcd_remote_set_drawmode(DRMODE_SOLID
);
774 lcd_remote_clear_display();
781 viewportmanager_set_statusbar(oldbars
);
782 if (pfn_tsr_exit
== NULL
)
783 plugin_loaded
= false;
785 sim_plugin_close(pd
);
791 case PLUGIN_USB_CONNECTED
:
792 return PLUGIN_USB_CONNECTED
;
795 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
802 /* Returns a pointer to the portion of the plugin buffer that is not already
803 being used. If no plugin is loaded, returns the entire plugin buffer */
804 void* plugin_get_buffer(size_t *buffer_size
)
810 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
813 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
814 buffer_pos
= plugin_size
;
818 *buffer_size
= PLUGIN_BUFFER_SIZE
;
822 return &pluginbuf
[buffer_pos
];
825 /* Returns a pointer to the mp3 buffer.
826 Playback gets stopped, to avoid conflicts.
827 Talk buffer is stolen as well.
829 void* plugin_get_audio_buffer(size_t *buffer_size
)
831 #if CONFIG_CODEC == SWCODEC
832 return audio_get_buffer(true, buffer_size
);
835 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
836 *buffer_size
= audiobufend
- audiobuf
;
841 #ifdef PLUGIN_USE_IRAM
842 /* Initializes plugin IRAM */
843 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
844 char *iedata
, size_t iedata_size
)
846 /* We need to stop audio playback in order to use codec IRAM */
848 memcpy(iramstart
, iramcopy
, iram_size
);
849 memset(iedata
, 0, iedata_size
);
850 memset(iramcopy
, 0, iram_size
);
852 /* writeback cleared iedata and iramcopy areas */
856 #endif /* PLUGIN_USE_IRAM */
858 /* The plugin wants to stay resident after leaving its main function, e.g.
859 runs from timer or own thread. The callback is registered to later
860 instruct it to free its resources before a new plugin gets loaded. */
861 void plugin_tsr(bool (*exit_callback
)(bool))
863 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
866 char *plugin_get_current_filename(void)
868 return current_plugin
;