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"
48 #ifdef HAVE_LCD_BITMAP
49 #include "scrollbar.h"
50 #include "peakmeter.h"
56 #include "usbstack/usb_hid.h"
60 #define PREFIX(_x_) sim_ ## _x_
66 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
67 void *sim_plugin_load(char *plugin
, void **pd
);
68 void sim_plugin_close(void *pd
);
69 void sim_lcd_ex_init(unsigned long (*getpixel
)(int, int));
70 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
72 #define sim_plugin_close(x)
73 extern unsigned char pluginbuf
[];
77 /* for actual plugins only, not for codecs */
78 static bool plugin_loaded
= false;
79 static int plugin_size
= 0;
80 static bool (*pfn_tsr_exit
)(bool reenter
) = NULL
; /* TSR exit callback */
81 static char current_plugin
[MAX_PATH
];
83 char *plugin_get_current_filename(void);
85 static const struct plugin_api rockbox_api
= {
88 #ifdef HAVE_LCD_CONTRAST
98 #ifdef HAVE_LCD_CHARCELLS
100 lcd_get_locked_pattern
,
108 &lcd_framebuffer
[0][0],
119 lcd_mono_bitmap_part
,
132 lcd_bitmap_transparent_part
,
133 lcd_bitmap_transparent
,
136 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
137 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) \
138 || defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(TOSHIBA_GIGABEAT_S)
141 #endif /* MEMORYSIZE > 2 */
142 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
145 #endif /* LCD_DEPTH */
146 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
148 lcd_pal256_update_pal
,
151 lcd_puts_scroll_style
,
152 #ifdef HAVE_LCD_INVERT
153 lcd_set_invert_display
,
154 #endif /* HAVE_LCD_INVERT */
155 #if defined(HAVE_LCD_MODES)
158 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
169 #endif /* HAVE_LCD_BITMAP */
174 backlight_set_timeout
,
175 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
176 backlight_set_brightness
,
177 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
180 backlight_set_timeout_plugged
,
186 #ifdef HAVE_REMOTE_LCD
188 lcd_remote_set_contrast
,
189 lcd_remote_clear_display
,
191 lcd_remote_puts_scroll
,
192 lcd_remote_stop_scroll
,
193 lcd_remote_set_drawmode
,
194 lcd_remote_get_drawmode
,
196 lcd_remote_getstringsize
,
197 lcd_remote_drawpixel
,
203 lcd_remote_mono_bitmap_part
,
204 lcd_remote_mono_bitmap
,
206 lcd_remote_puts_style
,
207 lcd_remote_puts_scroll_style
,
208 &lcd_remote_framebuffer
[0][0],
210 lcd_remote_update_rect
,
213 remote_backlight_off
,
214 remote_backlight_set_timeout
,
216 remote_backlight_set_timeout_plugged
,
218 #endif /* HAVE_REMOTE_LCD */
220 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
222 {&screens
[SCREEN_MAIN
]},
224 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
225 lcd_remote_set_foreground
,
226 lcd_remote_get_foreground
,
227 lcd_remote_set_background
,
228 lcd_remote_get_background
,
229 lcd_remote_bitmap_part
,
232 viewport_set_defaults
,
236 gui_synclist_set_nb_items
,
237 gui_synclist_set_icon_callback
,
238 gui_synclist_get_nb_items
,
239 gui_synclist_get_sel_pos
,
241 gui_synclist_select_item
,
242 gui_synclist_add_item
,
243 gui_synclist_del_item
,
244 gui_synclist_limit_scroll
,
245 gui_synclist_do_button
,
246 gui_synclist_set_title
,
248 simplelist_info_init
,
249 simplelist_show_list
,
255 #ifdef HAVE_BUTTON_DATA
261 #ifdef HAS_BUTTON_HOLD
264 #ifdef HAVE_TOUCHSCREEN
265 touchscreen_set_mode
,
268 #ifdef HAVE_BUTTON_LIGHT
269 buttonlight_set_timeout
,
272 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
273 buttonlight_set_brightness
,
274 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
275 #endif /* HAVE_BUTTON_LIGHT */
278 (open_func
)PREFIX(open
),
280 (read_func
)PREFIX(read
),
282 (creat_func
)PREFIX(creat
),
283 (write_func
)PREFIX(write
),
294 #if USING_STORAGE_CALLBACK
295 register_storage_idle_func
,
296 unregister_storage_idle_func
,
297 #endif /* USING_STORAGE_CALLBACK */
299 create_numbered_filename
,
318 default_event_handler
,
319 default_event_handler_ex
,
323 #if (CONFIG_CODEC == SWCODEC)
325 #ifdef HAVE_PRIORITY_SCHEDULING
333 reset_poweroff_timer
,
338 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
339 #ifdef CPU_BOOST_LOGGING
344 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
345 #endif /* !SIMULATOR */
346 #ifdef HAVE_SCHEDULER_BOOSTCTRL
362 #if CONFIG_CODEC == SWCODEC
363 queue_enable_queue_send
,
370 #ifdef USB_ENABLE_HID
376 __cyg_profile_func_enter
,
377 __cyg_profile_func_exit
,
384 /* special simulator hooks */
385 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
387 sim_lcd_ex_update_rect
,
391 /* strings and memory */
434 #if CONFIG_CODEC != SWCODEC
438 #if CONFIG_CODEC == SWCODEC
439 &audio_master_sampr_list
[0],
448 pcm_get_bytes_waiting
,
452 #ifdef HAVE_RECORDING
459 pcm_calculate_rec_peaks
,
460 audio_set_recording_gain
,
461 #endif /* HAVE_RECORDING */
462 #if INPUT_SRC_CAPS != 0
463 audio_set_output_source
,
464 audio_set_input_source
,
473 #endif /* CONFIG_CODEC == SWCODEC */
475 /* playback control */
481 playlist_remove_all_tracks
,
483 playlist_insert_track
,
484 playlist_insert_directory
,
496 audio_flush_and_reload_tracks
,
498 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
499 mpeg_get_last_header
,
501 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
502 (CONFIG_CODEC == SWCODEC)
506 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
507 /* MAS communication */
512 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
519 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
525 gui_syncstatusbar_draw
,
534 #ifdef HAVE_LCD_COLOR
538 /* action handling */
541 #ifdef HAVE_TOUCHSCREEN
542 action_get_touchscreen_press
,
555 # if CONFIG_CHARGING >= CHARGING_MONITOR
559 #ifdef HAVE_USB_POWER
574 plugin_get_audio_buffer
,
576 plugin_get_current_filename
,
577 #ifdef PLUGIN_USE_IRAM
580 #if defined(DEBUG) || defined(SIMULATOR)
583 #ifdef ROCKBOX_HAS_LOGF
589 #if CONFIG_CODEC == SWCODEC
590 codec_thread_do_callback
,
599 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
600 peak_meter_scale_value
,
601 peak_meter_set_use_dbfs
,
602 peak_meter_get_use_dbfs
,
604 #ifdef HAVE_LCD_BITMAP
611 screen_dump_set_hook
,
618 #ifdef HAVE_WHEEL_POSITION
623 #ifdef IRIVER_H100_SERIES
624 /* Routines for the iriver_flash -plugin. */
625 detect_original_firmware
,
626 detect_flashed_ramimage
,
627 detect_flashed_romimage
,
630 #if (CONFIG_CODEC == SWCODEC)
643 buf_request_buffer_handle
,
650 tagcache_search_set_uniqbuf
,
651 tagcache_search_add_filter
,
654 tagcache_search_finish
,
655 tagcache_get_numeric
,
656 #ifdef HAVE_TC_RAMCACHE
662 search_albumart_files
,
665 #ifdef HAVE_SEMAPHORE_OBJECTS
672 /* new stuff at the end, sort into place next time
673 the API gets incompatible */
674 #if (CONFIG_CODEC == SWCODEC)
680 int plugin_load(const char* plugin
, const void* parameter
)
683 struct plugin_header
*hdr
;
686 #else /* !SIMULATOR */
692 #endif /* !SIMULATOR */
695 fb_data
* old_backdrop
;
698 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
700 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
702 /* not allowing another plugin to load */
706 plugin_loaded
= false;
709 splash(0, ID2P(LANG_WAIT
));
710 strcpy(current_plugin
, plugin
);
713 hdr
= sim_plugin_load((char *)plugin
, &pd
);
715 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
719 || hdr
->magic
!= PLUGIN_MAGIC
720 || hdr
->target_id
!= TARGET_ID
) {
721 sim_plugin_close(pd
);
722 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
725 if (hdr
->api_version
> PLUGIN_API_VERSION
726 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
727 sim_plugin_close(pd
);
728 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
732 fd
= open(plugin
, O_RDONLY
);
734 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
738 /* Make sure COP cache is flushed and invalidated before loading */
739 my_core
= switch_core(CURRENT_CORE
^ 1);
740 cpucache_invalidate();
741 switch_core(my_core
);
744 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
748 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
751 hdr
= (struct plugin_header
*)pluginbuf
;
753 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
754 || hdr
->magic
!= PLUGIN_MAGIC
755 || hdr
->target_id
!= TARGET_ID
756 || hdr
->load_addr
!= pluginbuf
757 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
758 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
761 if (hdr
->api_version
> PLUGIN_API_VERSION
762 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
763 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
766 plugin_size
= hdr
->end_addr
- pluginbuf
;
768 /* zero out bss area only, above guards end of pluginbuf */
769 if (plugin_size
> readsize
)
770 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
773 *(hdr
->api
) = &rockbox_api
;
774 plugin_loaded
= true;
777 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
778 old_backdrop
= lcd_get_backdrop();
783 #ifdef HAVE_REMOTE_LCD
784 lcd_remote_clear_display();
789 viewportmanager_theme_enable(i
, false, NULL
);
791 cpucache_invalidate();
793 #ifdef HAVE_TOUCHSCREEN
794 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
797 rc
= hdr
->entry_point(parameter
);
799 /* Go back to the global setting in case the plugin changed it */
800 #ifdef HAVE_TOUCHSCREEN
801 touchscreen_set_mode(global_settings
.touch_mode
);
804 button_clear_queue();
806 #ifdef HAVE_LCD_BITMAP
807 lcd_setfont(FONT_UI
);
809 lcd_set_backdrop(old_backdrop
);
810 #ifdef HAVE_LCD_COLOR
811 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
812 global_settings
.bg_color
);
814 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
816 #else /* LCD_DEPTH == 1 */
817 lcd_set_drawmode(DRMODE_SOLID
);
818 #endif /* LCD_DEPTH */
819 #endif /* HAVE_LCD_BITMAP */
822 #ifdef HAVE_REMOTE_LCD
823 #if LCD_REMOTE_DEPTH > 1
824 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
825 LCD_REMOTE_DEFAULT_BG
);
827 lcd_remote_set_drawmode(DRMODE_SOLID
);
832 #ifdef HAVE_LCD_REMOTE
833 lcd_remote_clear_display();
837 viewportmanager_theme_undo(i
);
839 if (pfn_tsr_exit
== NULL
)
840 plugin_loaded
= false;
842 sim_plugin_close(pd
);
844 if (rc
== PLUGIN_ERROR
)
845 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
850 /* Returns a pointer to the portion of the plugin buffer that is not already
851 being used. If no plugin is loaded, returns the entire plugin buffer */
852 void* plugin_get_buffer(size_t *buffer_size
)
858 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
861 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
862 buffer_pos
= plugin_size
;
866 *buffer_size
= PLUGIN_BUFFER_SIZE
;
870 return &pluginbuf
[buffer_pos
];
873 /* Returns a pointer to the mp3 buffer.
874 Playback gets stopped, to avoid conflicts.
875 Talk buffer is stolen as well.
877 void* plugin_get_audio_buffer(size_t *buffer_size
)
879 #if CONFIG_CODEC == SWCODEC
880 return audio_get_buffer(true, buffer_size
);
883 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
884 *buffer_size
= audiobufend
- audiobuf
;
889 #ifdef PLUGIN_USE_IRAM
890 /* Initializes plugin IRAM */
891 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
892 char *iedata
, size_t iedata_size
)
894 /* We need to stop audio playback in order to use codec IRAM */
896 memcpy(iramstart
, iramcopy
, iram_size
);
897 memset(iedata
, 0, iedata_size
);
898 memset(iramcopy
, 0, iram_size
);
900 /* writeback cleared iedata and iramcopy areas */
904 #endif /* PLUGIN_USE_IRAM */
906 /* The plugin wants to stay resident after leaving its main function, e.g.
907 runs from timer or own thread. The callback is registered to later
908 instruct it to free its resources before a new plugin gets loaded. */
909 void plugin_tsr(bool (*exit_callback
)(bool))
911 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
914 char *plugin_get_current_filename(void)
916 return current_plugin
;