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(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
= {
83 #ifdef HAVE_LCD_CONTRAST
93 #ifdef HAVE_LCD_CHARCELLS
95 lcd_get_locked_pattern
,
103 &lcd_framebuffer
[0][0],
114 lcd_mono_bitmap_part
,
127 lcd_bitmap_transparent_part
,
128 lcd_bitmap_transparent
,
130 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
131 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) || defined(SANSA_FUZE) || defined(SANSA_E200V2)
134 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
137 #endif /* LCD_DEPTH */
138 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
140 lcd_pal256_update_pal
,
143 lcd_puts_scroll_style
,
144 #ifdef HAVE_LCD_INVERT
145 lcd_set_invert_display
,
146 #endif /* HAVE_LCD_INVERT */
147 #if defined(HAVE_LCD_MODES)
150 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
151 lcd_activation_set_hook
,
162 #endif /* HAVE_LCD_BITMAP */
167 backlight_set_timeout
,
168 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
169 backlight_set_brightness
,
170 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
173 backlight_set_timeout_plugged
,
179 #ifdef HAVE_REMOTE_LCD
181 lcd_remote_set_contrast
,
182 lcd_remote_clear_display
,
184 lcd_remote_puts_scroll
,
185 lcd_remote_stop_scroll
,
186 lcd_remote_set_drawmode
,
187 lcd_remote_get_drawmode
,
189 lcd_remote_getstringsize
,
190 lcd_remote_drawpixel
,
196 lcd_remote_mono_bitmap_part
,
197 lcd_remote_mono_bitmap
,
199 lcd_remote_puts_style
,
200 lcd_remote_puts_scroll_style
,
201 &lcd_remote_framebuffer
[0][0],
203 lcd_remote_update_rect
,
206 remote_backlight_off
,
207 remote_backlight_set_timeout
,
209 remote_backlight_set_timeout_plugged
,
211 #endif /* HAVE_REMOTE_LCD */
213 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
215 {&screens
[SCREEN_MAIN
]},
217 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
218 lcd_remote_set_foreground
,
219 lcd_remote_get_foreground
,
220 lcd_remote_set_background
,
221 lcd_remote_get_background
,
222 lcd_remote_bitmap_part
,
225 viewport_set_defaults
,
226 viewportmanager_set_statusbar
,
230 gui_synclist_set_nb_items
,
231 gui_synclist_set_icon_callback
,
232 gui_synclist_get_nb_items
,
233 gui_synclist_get_sel_pos
,
235 gui_synclist_select_item
,
236 gui_synclist_add_item
,
237 gui_synclist_del_item
,
238 gui_synclist_limit_scroll
,
239 gui_synclist_do_button
,
240 gui_synclist_set_title
,
242 simplelist_info_init
,
243 simplelist_show_list
,
249 #ifdef HAVE_BUTTON_DATA
254 #ifdef HAS_BUTTON_HOLD
257 #ifdef HAVE_TOUCHSCREEN
258 touchscreen_set_mode
,
261 #ifdef HAVE_BUTTON_LIGHT
262 buttonlight_set_timeout
,
265 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
266 buttonlight_set_brightness
,
267 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
268 #endif /* HAVE_BUTTON_LIGHT */
271 (open_func
)PREFIX(open
),
273 (read_func
)PREFIX(read
),
275 (creat_func
)PREFIX(creat
),
276 (write_func
)PREFIX(write
),
287 #if USING_STORAGE_CALLBACK
288 register_storage_idle_func
,
289 unregister_storage_idle_func
,
290 #endif /* USING_STORAGE_CALLBACK */
292 create_numbered_filename
,
311 default_event_handler
,
312 default_event_handler_ex
,
316 #if (CONFIG_CODEC == SWCODEC)
318 #ifdef HAVE_PRIORITY_SCHEDULING
326 reset_poweroff_timer
,
331 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
332 #ifdef CPU_BOOST_LOGGING
337 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
338 #endif /* !SIMULATOR */
339 #ifdef HAVE_SCHEDULER_BOOSTCTRL
355 #if CONFIG_CODEC == SWCODEC
356 queue_enable_queue_send
,
366 __cyg_profile_func_enter
,
367 __cyg_profile_func_exit
,
371 /* special simulator hooks */
372 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
374 sim_lcd_ex_update_rect
,
378 /* strings and memory */
421 #if CONFIG_CODEC != SWCODEC
425 #if CONFIG_CODEC == SWCODEC
426 &audio_master_sampr_list
[0],
435 pcm_get_bytes_waiting
,
439 #ifdef HAVE_RECORDING
446 pcm_calculate_rec_peaks
,
447 audio_set_recording_gain
,
448 #endif /* HAVE_RECORDING */
449 #if INPUT_SRC_CAPS != 0
450 audio_set_output_source
,
451 audio_set_input_source
,
458 #endif /* CONFIG_CODEC == SWCODEC */
460 /* playback control */
474 audio_flush_and_reload_tracks
,
476 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
477 mpeg_get_last_header
,
479 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
480 (CONFIG_CODEC == SWCODEC)
484 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
485 /* MAS communication */
490 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
497 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
503 gui_syncstatusbar_draw
,
512 #ifdef HAVE_LCD_COLOR
516 /* action handling */
530 # if CONFIG_CHARGING >= CHARGING_MONITOR
534 #ifdef HAVE_USB_POWER
549 plugin_get_audio_buffer
,
551 plugin_get_current_filename
,
552 #ifdef PLUGIN_USE_IRAM
555 #if defined(DEBUG) || defined(SIMULATOR)
558 #ifdef ROCKBOX_HAS_LOGF
564 #if CONFIG_CODEC == SWCODEC
565 codec_thread_do_callback
,
574 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
575 peak_meter_scale_value
,
576 peak_meter_set_use_dbfs
,
577 peak_meter_get_use_dbfs
,
579 #ifdef HAVE_LCD_BITMAP
586 screen_dump_set_hook
,
593 #ifdef HAVE_WHEEL_POSITION
598 #ifdef IRIVER_H100_SERIES
599 /* Routines for the iriver_flash -plugin. */
600 detect_original_firmware
,
601 detect_flashed_ramimage
,
602 detect_flashed_romimage
,
605 #if (CONFIG_CODEC == SWCODEC)
618 buf_request_buffer_handle
,
625 tagcache_search_set_uniqbuf
,
626 tagcache_search_add_filter
,
629 tagcache_search_finish
,
630 tagcache_get_numeric
,
635 search_albumart_files
,
638 #ifdef HAVE_SEMAPHORE_OBJECTS
645 /* new stuff at the end, sort into place next time
646 the API gets incompatible */
648 #ifdef HAVE_TOUCHSCREEN
649 action_get_touchscreen_press
,
651 #if defined(HAVE_TAGCACHE) && defined(HAVE_TC_RAMCACHE)
656 playlist_remove_all_tracks
,
658 playlist_insert_track
,
662 int plugin_load(const char* plugin
, const void* parameter
)
666 struct plugin_header
*hdr
;
669 #else /* !SIMULATOR */
675 #endif /* !SIMULATOR */
678 fb_data
* old_backdrop
;
681 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
683 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
685 /* not allowing another plugin to load */
689 plugin_loaded
= false;
692 splash(0, ID2P(LANG_WAIT
));
693 strcpy(current_plugin
, plugin
);
696 hdr
= sim_plugin_load((char *)plugin
, &pd
);
698 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
702 || hdr
->magic
!= PLUGIN_MAGIC
703 || hdr
->target_id
!= TARGET_ID
) {
704 sim_plugin_close(pd
);
705 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
708 if (hdr
->api_version
> PLUGIN_API_VERSION
709 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
710 sim_plugin_close(pd
);
711 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
715 fd
= open(plugin
, O_RDONLY
);
717 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
721 /* Make sure COP cache is flushed and invalidated before loading */
722 my_core
= switch_core(CURRENT_CORE
^ 1);
723 cpucache_invalidate();
724 switch_core(my_core
);
727 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
731 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
734 hdr
= (struct plugin_header
*)pluginbuf
;
736 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
737 || hdr
->magic
!= PLUGIN_MAGIC
738 || hdr
->target_id
!= TARGET_ID
739 || hdr
->load_addr
!= pluginbuf
740 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
741 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
744 if (hdr
->api_version
> PLUGIN_API_VERSION
745 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
746 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
749 plugin_size
= hdr
->end_addr
- pluginbuf
;
751 /* zero out bss area only, above guards end of pluginbuf */
752 if (plugin_size
> readsize
)
753 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
756 *(hdr
->api
) = &rockbox_api
;
757 plugin_loaded
= true;
760 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
761 old_backdrop
= lcd_get_backdrop();
766 #ifdef HAVE_REMOTE_LCD
767 lcd_remote_clear_display();
771 cpucache_invalidate();
772 oldbars
= viewportmanager_set_statusbar(VP_SB_HIDE_ALL
);
774 #ifdef HAVE_TOUCHSCREEN
775 enum touchscreen_mode old_mode
= touchscreen_get_mode();
777 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
780 rc
= hdr
->entry_point(parameter
);
782 #ifdef HAVE_TOUCHSCREEN
783 touchscreen_set_mode(old_mode
);
786 viewportmanager_set_statusbar(oldbars
);
788 button_clear_queue();
790 #ifdef HAVE_LCD_BITMAP
791 lcd_setfont(FONT_UI
);
793 lcd_set_backdrop(old_backdrop
);
794 #ifdef HAVE_LCD_COLOR
795 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
796 global_settings
.bg_color
);
798 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
800 #else /* LCD_DEPTH == 1 */
801 lcd_set_drawmode(DRMODE_SOLID
);
802 #endif /* LCD_DEPTH */
803 #endif /* HAVE_LCD_BITMAP */
808 #ifdef HAVE_REMOTE_LCD
809 #if LCD_REMOTE_DEPTH > 1
810 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
811 LCD_REMOTE_DEFAULT_BG
);
813 lcd_remote_set_drawmode(DRMODE_SOLID
);
815 lcd_remote_clear_display();
822 viewportmanager_set_statusbar(oldbars
);
823 if (pfn_tsr_exit
== NULL
)
824 plugin_loaded
= false;
826 sim_plugin_close(pd
);
832 case PLUGIN_USB_CONNECTED
:
833 return PLUGIN_USB_CONNECTED
;
836 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
843 /* Returns a pointer to the portion of the plugin buffer that is not already
844 being used. If no plugin is loaded, returns the entire plugin buffer */
845 void* plugin_get_buffer(size_t *buffer_size
)
851 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
854 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
855 buffer_pos
= plugin_size
;
859 *buffer_size
= PLUGIN_BUFFER_SIZE
;
863 return &pluginbuf
[buffer_pos
];
866 /* Returns a pointer to the mp3 buffer.
867 Playback gets stopped, to avoid conflicts.
868 Talk buffer is stolen as well.
870 void* plugin_get_audio_buffer(size_t *buffer_size
)
872 #if CONFIG_CODEC == SWCODEC
873 return audio_get_buffer(true, buffer_size
);
876 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
877 *buffer_size
= audiobufend
- audiobuf
;
882 #ifdef PLUGIN_USE_IRAM
883 /* Initializes plugin IRAM */
884 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
885 char *iedata
, size_t iedata_size
)
887 /* We need to stop audio playback in order to use codec IRAM */
889 memcpy(iramstart
, iramcopy
, iram_size
);
890 memset(iedata
, 0, iedata_size
);
891 memset(iramcopy
, 0, iram_size
);
893 /* writeback cleared iedata and iramcopy areas */
897 #endif /* PLUGIN_USE_IRAM */
899 /* The plugin wants to stay resident after leaving its main function, e.g.
900 runs from timer or own thread. The callback is registered to later
901 instruct it to free its resources before a new plugin gets loaded. */
902 void plugin_tsr(bool (*exit_callback
)(bool))
904 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
907 char *plugin_get_current_filename(void)
909 return current_plugin
;