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"
49 #ifdef HAVE_LCD_BITMAP
50 #include "scrollbar.h"
51 #include "peakmeter.h"
57 #include "usbstack/usb_hid.h"
61 #define PREFIX(_x_) sim_ ## _x_
67 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
68 void *sim_plugin_load(char *plugin
, void **pd
);
69 void sim_plugin_close(void *pd
);
70 void sim_lcd_ex_init(unsigned long (*getpixel
)(int, int));
71 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
73 #define sim_plugin_close(x)
74 extern unsigned char pluginbuf
[];
78 /* for actual plugins only, not for codecs */
79 static bool plugin_loaded
= false;
80 static int plugin_size
= 0;
81 static bool (*pfn_tsr_exit
)(bool reenter
) = NULL
; /* TSR exit callback */
82 static char current_plugin
[MAX_PATH
];
84 char *plugin_get_current_filename(void);
86 static const struct plugin_api rockbox_api
= {
89 #ifdef HAVE_LCD_CONTRAST
99 #ifdef HAVE_LCD_CHARCELLS
101 lcd_get_locked_pattern
,
109 &lcd_framebuffer
[0][0],
120 lcd_mono_bitmap_part
,
133 lcd_bitmap_transparent_part
,
134 lcd_bitmap_transparent
,
137 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
138 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) \
139 || defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(TOSHIBA_GIGABEAT_S)
142 #endif /* MEMORYSIZE > 2 */
143 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
146 #endif /* LCD_DEPTH */
147 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
149 lcd_pal256_update_pal
,
152 lcd_puts_scroll_style
,
153 #ifdef HAVE_LCD_INVERT
154 lcd_set_invert_display
,
155 #endif /* HAVE_LCD_INVERT */
156 #if defined(HAVE_LCD_MODES)
159 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
170 #endif /* HAVE_LCD_BITMAP */
175 backlight_set_timeout
,
176 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
177 backlight_set_brightness
,
178 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
181 backlight_set_timeout_plugged
,
187 #ifdef HAVE_REMOTE_LCD
189 lcd_remote_set_contrast
,
190 lcd_remote_clear_display
,
192 lcd_remote_puts_scroll
,
193 lcd_remote_stop_scroll
,
194 lcd_remote_set_drawmode
,
195 lcd_remote_get_drawmode
,
197 lcd_remote_getstringsize
,
198 lcd_remote_drawpixel
,
204 lcd_remote_mono_bitmap_part
,
205 lcd_remote_mono_bitmap
,
207 lcd_remote_puts_style
,
208 lcd_remote_puts_scroll_style
,
209 &lcd_remote_framebuffer
[0][0],
211 lcd_remote_update_rect
,
214 remote_backlight_off
,
215 remote_backlight_set_timeout
,
217 remote_backlight_set_timeout_plugged
,
219 #endif /* HAVE_REMOTE_LCD */
221 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
223 {&screens
[SCREEN_MAIN
]},
225 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
226 lcd_remote_set_foreground
,
227 lcd_remote_get_foreground
,
228 lcd_remote_set_background
,
229 lcd_remote_get_background
,
230 lcd_remote_bitmap_part
,
233 viewport_set_defaults
,
237 gui_synclist_set_nb_items
,
238 gui_synclist_set_icon_callback
,
239 gui_synclist_get_nb_items
,
240 gui_synclist_get_sel_pos
,
242 gui_synclist_select_item
,
243 gui_synclist_add_item
,
244 gui_synclist_del_item
,
245 gui_synclist_limit_scroll
,
246 gui_synclist_do_button
,
247 gui_synclist_set_title
,
249 simplelist_info_init
,
250 simplelist_show_list
,
256 #ifdef HAVE_BUTTON_DATA
262 #ifdef HAS_BUTTON_HOLD
265 #ifdef HAVE_TOUCHSCREEN
266 touchscreen_set_mode
,
269 #ifdef HAVE_BUTTON_LIGHT
270 buttonlight_set_timeout
,
273 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
274 buttonlight_set_brightness
,
275 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
276 #endif /* HAVE_BUTTON_LIGHT */
279 (open_func
)PREFIX(open
),
281 (read_func
)PREFIX(read
),
283 (creat_func
)PREFIX(creat
),
284 (write_func
)PREFIX(write
),
295 #if USING_STORAGE_CALLBACK
296 register_storage_idle_func
,
297 unregister_storage_idle_func
,
298 #endif /* USING_STORAGE_CALLBACK */
300 create_numbered_filename
,
319 default_event_handler
,
320 default_event_handler_ex
,
324 #if (CONFIG_CODEC == SWCODEC)
326 #ifdef HAVE_PRIORITY_SCHEDULING
334 reset_poweroff_timer
,
339 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
340 #ifdef CPU_BOOST_LOGGING
345 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
346 #endif /* !SIMULATOR */
347 #ifdef HAVE_SCHEDULER_BOOSTCTRL
363 #if CONFIG_CODEC == SWCODEC
364 queue_enable_queue_send
,
371 #ifdef USB_ENABLE_HID
377 __cyg_profile_func_enter
,
378 __cyg_profile_func_exit
,
385 /* special simulator hooks */
386 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
388 sim_lcd_ex_update_rect
,
392 /* strings and memory */
435 #if CONFIG_CODEC != SWCODEC
439 #if CONFIG_CODEC == SWCODEC
440 &audio_master_sampr_list
[0],
449 pcm_get_bytes_waiting
,
453 #ifdef HAVE_RECORDING
460 pcm_calculate_rec_peaks
,
461 audio_set_recording_gain
,
462 #endif /* HAVE_RECORDING */
463 #if INPUT_SRC_CAPS != 0
464 audio_set_output_source
,
465 audio_set_input_source
,
474 #endif /* CONFIG_CODEC == SWCODEC */
476 /* playback control */
482 playlist_remove_all_tracks
,
484 playlist_insert_track
,
485 playlist_insert_directory
,
497 audio_flush_and_reload_tracks
,
499 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
500 mpeg_get_last_header
,
502 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
503 (CONFIG_CODEC == SWCODEC)
507 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
508 /* MAS communication */
513 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
520 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
526 gui_syncstatusbar_draw
,
535 #ifdef HAVE_LCD_COLOR
539 /* action handling */
542 #ifdef HAVE_TOUCHSCREEN
543 action_get_touchscreen_press
,
556 # if CONFIG_CHARGING >= CHARGING_MONITOR
560 #ifdef HAVE_USB_POWER
575 plugin_get_audio_buffer
,
577 plugin_get_current_filename
,
578 #ifdef PLUGIN_USE_IRAM
581 #if defined(DEBUG) || defined(SIMULATOR)
584 #ifdef ROCKBOX_HAS_LOGF
590 #if CONFIG_CODEC == SWCODEC
591 codec_thread_do_callback
,
600 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
601 peak_meter_scale_value
,
602 peak_meter_set_use_dbfs
,
603 peak_meter_get_use_dbfs
,
605 #ifdef HAVE_LCD_BITMAP
612 screen_dump_set_hook
,
619 #ifdef HAVE_WHEEL_POSITION
624 #ifdef IRIVER_H100_SERIES
625 /* Routines for the iriver_flash -plugin. */
626 detect_original_firmware
,
627 detect_flashed_ramimage
,
628 detect_flashed_romimage
,
631 #if (CONFIG_CODEC == SWCODEC)
644 buf_request_buffer_handle
,
651 tagcache_search_set_uniqbuf
,
652 tagcache_search_add_filter
,
655 tagcache_search_finish
,
656 tagcache_get_numeric
,
657 #ifdef HAVE_TC_RAMCACHE
663 search_albumart_files
,
666 #ifdef HAVE_SEMAPHORE_OBJECTS
673 /* new stuff at the end, sort into place next time
674 the API gets incompatible */
675 #if (CONFIG_CODEC == SWCODEC)
680 #ifdef HAVE_LCD_BITMAP
681 viewportmanager_theme_enable
,
682 viewportmanager_theme_undo
,
684 #if !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__)
690 int plugin_load(const char* plugin
, const void* parameter
)
693 struct plugin_header
*hdr
;
696 #else /* !SIMULATOR */
702 #endif /* !SIMULATOR */
705 fb_data
* old_backdrop
;
708 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
710 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
712 /* not allowing another plugin to load */
716 plugin_loaded
= false;
719 splash(0, ID2P(LANG_WAIT
));
720 strcpy(current_plugin
, plugin
);
723 hdr
= sim_plugin_load((char *)plugin
, &pd
);
725 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
729 || hdr
->magic
!= PLUGIN_MAGIC
730 || hdr
->target_id
!= TARGET_ID
) {
731 sim_plugin_close(pd
);
732 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
735 if (hdr
->api_version
> PLUGIN_API_VERSION
736 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
737 sim_plugin_close(pd
);
738 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
742 fd
= open(plugin
, O_RDONLY
);
744 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
748 /* Make sure COP cache is flushed and invalidated before loading */
749 my_core
= switch_core(CURRENT_CORE
^ 1);
750 cpucache_invalidate();
751 switch_core(my_core
);
754 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
758 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
761 hdr
= (struct plugin_header
*)pluginbuf
;
763 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
764 || hdr
->magic
!= PLUGIN_MAGIC
765 || hdr
->target_id
!= TARGET_ID
766 || hdr
->load_addr
!= pluginbuf
767 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
768 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
771 if (hdr
->api_version
> PLUGIN_API_VERSION
772 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
773 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
776 plugin_size
= hdr
->end_addr
- pluginbuf
;
778 /* zero out bss area only, above guards end of pluginbuf */
779 if (plugin_size
> readsize
)
780 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
783 *(hdr
->api
) = &rockbox_api
;
784 plugin_loaded
= true;
787 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
788 old_backdrop
= lcd_get_backdrop();
793 #ifdef HAVE_REMOTE_LCD
794 lcd_remote_clear_display();
799 viewportmanager_theme_enable(i
, false, NULL
);
801 cpucache_invalidate();
803 #ifdef HAVE_TOUCHSCREEN
804 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
807 rc
= hdr
->entry_point(parameter
);
809 /* Go back to the global setting in case the plugin changed it */
810 #ifdef HAVE_TOUCHSCREEN
811 touchscreen_set_mode(global_settings
.touch_mode
);
814 button_clear_queue();
816 #ifdef HAVE_LCD_BITMAP
817 lcd_setfont(FONT_UI
);
819 lcd_set_backdrop(old_backdrop
);
820 #ifdef HAVE_LCD_COLOR
821 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
822 global_settings
.bg_color
);
824 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
826 #else /* LCD_DEPTH == 1 */
827 lcd_set_drawmode(DRMODE_SOLID
);
828 #endif /* LCD_DEPTH */
829 #endif /* HAVE_LCD_BITMAP */
832 #ifdef HAVE_REMOTE_LCD
833 #if LCD_REMOTE_DEPTH > 1
834 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
835 LCD_REMOTE_DEFAULT_BG
);
837 lcd_remote_set_drawmode(DRMODE_SOLID
);
842 #ifdef HAVE_LCD_REMOTE
843 lcd_remote_clear_display();
847 viewportmanager_theme_undo(i
, false);
849 if (pfn_tsr_exit
== NULL
)
850 plugin_loaded
= false;
852 sim_plugin_close(pd
);
854 if (rc
== PLUGIN_ERROR
)
855 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
860 /* Returns a pointer to the portion of the plugin buffer that is not already
861 being used. If no plugin is loaded, returns the entire plugin buffer */
862 void* plugin_get_buffer(size_t *buffer_size
)
868 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
871 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
872 buffer_pos
= plugin_size
;
876 *buffer_size
= PLUGIN_BUFFER_SIZE
;
880 return &pluginbuf
[buffer_pos
];
883 /* Returns a pointer to the mp3 buffer.
884 Playback gets stopped, to avoid conflicts.
885 Talk buffer is stolen as well.
887 void* plugin_get_audio_buffer(size_t *buffer_size
)
889 #if CONFIG_CODEC == SWCODEC
890 return audio_get_buffer(true, buffer_size
);
893 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
894 *buffer_size
= audiobufend
- audiobuf
;
899 #ifdef PLUGIN_USE_IRAM
900 /* Initializes plugin IRAM */
901 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
902 char *iedata
, size_t iedata_size
)
904 /* We need to stop audio playback in order to use codec IRAM */
906 memcpy(iramstart
, iramcopy
, iram_size
);
907 memset(iedata
, 0, iedata_size
);
908 memset(iramcopy
, 0, iram_size
);
910 /* writeback cleared iedata and iramcopy areas */
914 #endif /* PLUGIN_USE_IRAM */
916 /* The plugin wants to stay resident after leaving its main function, e.g.
917 runs from timer or own thread. The callback is registered to later
918 instruct it to free its resources before a new plugin gets loaded. */
919 void plugin_tsr(bool (*exit_callback
)(bool))
921 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
924 char *plugin_get_current_filename(void)
926 return current_plugin
;