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"
54 #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID)
55 #include "usbstack/usb_hid.h"
59 #define PREFIX(_x_) sim_ ## _x_
65 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
66 void *sim_plugin_load(char *plugin
, void **pd
);
67 void sim_plugin_close(void *pd
);
68 void sim_lcd_ex_init(unsigned long (*getpixel
)(int, int));
69 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
71 #define sim_plugin_close(x)
72 extern unsigned char pluginbuf
[];
76 /* for actual plugins only, not for codecs */
77 static bool plugin_loaded
= false;
78 static int plugin_size
= 0;
79 static bool (*pfn_tsr_exit
)(bool reenter
) = NULL
; /* TSR exit callback */
80 static char current_plugin
[MAX_PATH
];
82 char *plugin_get_current_filename(void);
84 static const struct plugin_api rockbox_api
= {
87 #ifdef HAVE_LCD_CONTRAST
97 #ifdef HAVE_LCD_CHARCELLS
99 lcd_get_locked_pattern
,
107 &lcd_framebuffer
[0][0],
118 lcd_mono_bitmap_part
,
131 lcd_bitmap_transparent_part
,
132 lcd_bitmap_transparent
,
135 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
136 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) \
137 || defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(TOSHIBA_GIGABEAT_S)
140 #endif /* MEMORYSIZE > 2 */
141 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
144 #endif /* LCD_DEPTH */
145 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
147 lcd_pal256_update_pal
,
150 lcd_puts_scroll_style
,
151 #ifdef HAVE_LCD_INVERT
152 lcd_set_invert_display
,
153 #endif /* HAVE_LCD_INVERT */
154 #if defined(HAVE_LCD_MODES)
157 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
158 lcd_activation_set_hook
,
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
,
233 viewportmanager_set_statusbar
,
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
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
,
373 __cyg_profile_func_enter
,
374 __cyg_profile_func_exit
,
378 /* special simulator hooks */
379 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
381 sim_lcd_ex_update_rect
,
385 /* strings and memory */
428 #if CONFIG_CODEC != SWCODEC
432 #if CONFIG_CODEC == SWCODEC
433 &audio_master_sampr_list
[0],
442 pcm_get_bytes_waiting
,
446 #ifdef HAVE_RECORDING
453 pcm_calculate_rec_peaks
,
454 audio_set_recording_gain
,
455 #endif /* HAVE_RECORDING */
456 #if INPUT_SRC_CAPS != 0
457 audio_set_output_source
,
458 audio_set_input_source
,
465 #endif /* CONFIG_CODEC == SWCODEC */
467 /* playback control */
473 playlist_remove_all_tracks
,
475 playlist_insert_track
,
476 playlist_insert_directory
,
488 audio_flush_and_reload_tracks
,
490 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
491 mpeg_get_last_header
,
493 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
494 (CONFIG_CODEC == SWCODEC)
498 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
499 /* MAS communication */
504 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
511 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
517 gui_syncstatusbar_draw
,
526 #ifdef HAVE_LCD_COLOR
530 /* action handling */
533 #ifdef HAVE_TOUCHSCREEN
534 action_get_touchscreen_press
,
547 # if CONFIG_CHARGING >= CHARGING_MONITOR
551 #ifdef HAVE_USB_POWER
566 plugin_get_audio_buffer
,
568 plugin_get_current_filename
,
569 #ifdef PLUGIN_USE_IRAM
572 #if defined(DEBUG) || defined(SIMULATOR)
575 #ifdef ROCKBOX_HAS_LOGF
581 #if CONFIG_CODEC == SWCODEC
582 codec_thread_do_callback
,
591 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
592 peak_meter_scale_value
,
593 peak_meter_set_use_dbfs
,
594 peak_meter_get_use_dbfs
,
596 #ifdef HAVE_LCD_BITMAP
603 screen_dump_set_hook
,
610 #ifdef HAVE_WHEEL_POSITION
615 #ifdef IRIVER_H100_SERIES
616 /* Routines for the iriver_flash -plugin. */
617 detect_original_firmware
,
618 detect_flashed_ramimage
,
619 detect_flashed_romimage
,
622 #if (CONFIG_CODEC == SWCODEC)
635 buf_request_buffer_handle
,
642 tagcache_search_set_uniqbuf
,
643 tagcache_search_add_filter
,
646 tagcache_search_finish
,
647 tagcache_get_numeric
,
648 #ifdef HAVE_TC_RAMCACHE
655 search_albumart_files
,
658 #ifdef HAVE_SEMAPHORE_OBJECTS
665 /* new stuff at the end, sort into place next time
666 the API gets incompatible */
668 #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID)
673 int plugin_load(const char* plugin
, const void* parameter
)
678 struct plugin_header
*hdr
;
681 #else /* !SIMULATOR */
687 #endif /* !SIMULATOR */
690 fb_data
* old_backdrop
;
693 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
695 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
697 /* not allowing another plugin to load */
701 plugin_loaded
= false;
704 splash(0, ID2P(LANG_WAIT
));
705 strcpy(current_plugin
, plugin
);
708 hdr
= sim_plugin_load((char *)plugin
, &pd
);
710 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
714 || hdr
->magic
!= PLUGIN_MAGIC
715 || hdr
->target_id
!= TARGET_ID
) {
716 sim_plugin_close(pd
);
717 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
720 if (hdr
->api_version
> PLUGIN_API_VERSION
721 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
722 sim_plugin_close(pd
);
723 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
727 fd
= open(plugin
, O_RDONLY
);
729 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
733 /* Make sure COP cache is flushed and invalidated before loading */
734 my_core
= switch_core(CURRENT_CORE
^ 1);
735 cpucache_invalidate();
736 switch_core(my_core
);
739 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
743 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
746 hdr
= (struct plugin_header
*)pluginbuf
;
748 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
749 || hdr
->magic
!= PLUGIN_MAGIC
750 || hdr
->target_id
!= TARGET_ID
751 || hdr
->load_addr
!= pluginbuf
752 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
753 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
756 if (hdr
->api_version
> PLUGIN_API_VERSION
757 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
758 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
761 plugin_size
= hdr
->end_addr
- pluginbuf
;
763 /* zero out bss area only, above guards end of pluginbuf */
764 if (plugin_size
> readsize
)
765 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
768 *(hdr
->api
) = &rockbox_api
;
769 plugin_loaded
= true;
772 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
773 old_backdrop
= lcd_get_backdrop();
778 #ifdef HAVE_REMOTE_LCD
779 lcd_remote_clear_display();
783 cpucache_invalidate();
784 oldbars
= viewportmanager_set_statusbar(VP_SB_HIDE_ALL
);
786 #ifdef HAVE_TOUCHSCREEN
787 enum touchscreen_mode old_mode
= touchscreen_get_mode();
789 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
792 rc
= hdr
->entry_point(parameter
);
794 #ifdef HAVE_TOUCHSCREEN
795 touchscreen_set_mode(old_mode
);
798 viewportmanager_set_statusbar(oldbars
);
800 button_clear_queue();
802 #ifdef HAVE_LCD_BITMAP
803 lcd_setfont(FONT_UI
);
805 lcd_set_backdrop(old_backdrop
);
806 #ifdef HAVE_LCD_COLOR
807 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
808 global_settings
.bg_color
);
810 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
812 #else /* LCD_DEPTH == 1 */
813 lcd_set_drawmode(DRMODE_SOLID
);
814 #endif /* LCD_DEPTH */
815 #endif /* HAVE_LCD_BITMAP */
818 #ifdef HAVE_REMOTE_LCD
819 #if LCD_REMOTE_DEPTH > 1
820 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
821 LCD_REMOTE_DEFAULT_BG
);
823 lcd_remote_set_drawmode(DRMODE_SOLID
);
827 if (rc
!= PLUGIN_GOTO_WPS
)
831 screens
[i
].clear_display();
836 viewportmanager_set_statusbar(oldbars
);
837 if (pfn_tsr_exit
== NULL
)
838 plugin_loaded
= false;
840 sim_plugin_close(pd
);
842 if (rc
== PLUGIN_ERROR
)
843 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
848 /* Returns a pointer to the portion of the plugin buffer that is not already
849 being used. If no plugin is loaded, returns the entire plugin buffer */
850 void* plugin_get_buffer(size_t *buffer_size
)
856 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
859 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
860 buffer_pos
= plugin_size
;
864 *buffer_size
= PLUGIN_BUFFER_SIZE
;
868 return &pluginbuf
[buffer_pos
];
871 /* Returns a pointer to the mp3 buffer.
872 Playback gets stopped, to avoid conflicts.
873 Talk buffer is stolen as well.
875 void* plugin_get_audio_buffer(size_t *buffer_size
)
877 #if CONFIG_CODEC == SWCODEC
878 return audio_get_buffer(true, buffer_size
);
881 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
882 *buffer_size
= audiobufend
- audiobuf
;
887 #ifdef PLUGIN_USE_IRAM
888 /* Initializes plugin IRAM */
889 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
890 char *iedata
, size_t iedata_size
)
892 /* We need to stop audio playback in order to use codec IRAM */
894 memcpy(iramstart
, iramcopy
, iram_size
);
895 memset(iedata
, 0, iedata_size
);
896 memset(iramcopy
, 0, iram_size
);
898 /* writeback cleared iedata and iramcopy areas */
902 #endif /* PLUGIN_USE_IRAM */
904 /* The plugin wants to stay resident after leaving its main function, e.g.
905 runs from timer or own thread. The callback is registered to later
906 instruct it to free its resources before a new plugin gets loaded. */
907 void plugin_tsr(bool (*exit_callback
)(bool))
909 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
912 char *plugin_get_current_filename(void)
914 return current_plugin
;