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
,
131 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
132 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) || defined(SANSA_FUZE) || defined(SANSA_E200V2)
135 #endif /* MEMORYSIZE > 2 */
136 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
139 #endif /* LCD_DEPTH */
140 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
142 lcd_pal256_update_pal
,
145 lcd_puts_scroll_style
,
146 #ifdef HAVE_LCD_INVERT
147 lcd_set_invert_display
,
148 #endif /* HAVE_LCD_INVERT */
149 #if defined(HAVE_LCD_MODES)
152 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
153 lcd_activation_set_hook
,
164 #endif /* HAVE_LCD_BITMAP */
169 backlight_set_timeout
,
170 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
171 backlight_set_brightness
,
172 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
175 backlight_set_timeout_plugged
,
181 #ifdef HAVE_REMOTE_LCD
183 lcd_remote_set_contrast
,
184 lcd_remote_clear_display
,
186 lcd_remote_puts_scroll
,
187 lcd_remote_stop_scroll
,
188 lcd_remote_set_drawmode
,
189 lcd_remote_get_drawmode
,
191 lcd_remote_getstringsize
,
192 lcd_remote_drawpixel
,
198 lcd_remote_mono_bitmap_part
,
199 lcd_remote_mono_bitmap
,
201 lcd_remote_puts_style
,
202 lcd_remote_puts_scroll_style
,
203 &lcd_remote_framebuffer
[0][0],
205 lcd_remote_update_rect
,
208 remote_backlight_off
,
209 remote_backlight_set_timeout
,
211 remote_backlight_set_timeout_plugged
,
213 #endif /* HAVE_REMOTE_LCD */
215 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
217 {&screens
[SCREEN_MAIN
]},
219 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
220 lcd_remote_set_foreground
,
221 lcd_remote_get_foreground
,
222 lcd_remote_set_background
,
223 lcd_remote_get_background
,
224 lcd_remote_bitmap_part
,
227 viewport_set_defaults
,
228 viewportmanager_set_statusbar
,
232 gui_synclist_set_nb_items
,
233 gui_synclist_set_icon_callback
,
234 gui_synclist_get_nb_items
,
235 gui_synclist_get_sel_pos
,
237 gui_synclist_select_item
,
238 gui_synclist_add_item
,
239 gui_synclist_del_item
,
240 gui_synclist_limit_scroll
,
241 gui_synclist_do_button
,
242 gui_synclist_set_title
,
244 simplelist_info_init
,
245 simplelist_show_list
,
251 #ifdef HAVE_BUTTON_DATA
256 #ifdef HAS_BUTTON_HOLD
259 #ifdef HAVE_TOUCHSCREEN
260 touchscreen_set_mode
,
263 #ifdef HAVE_BUTTON_LIGHT
264 buttonlight_set_timeout
,
267 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
268 buttonlight_set_brightness
,
269 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
270 #endif /* HAVE_BUTTON_LIGHT */
273 (open_func
)PREFIX(open
),
275 (read_func
)PREFIX(read
),
277 (creat_func
)PREFIX(creat
),
278 (write_func
)PREFIX(write
),
289 #if USING_STORAGE_CALLBACK
290 register_storage_idle_func
,
291 unregister_storage_idle_func
,
292 #endif /* USING_STORAGE_CALLBACK */
294 create_numbered_filename
,
313 default_event_handler
,
314 default_event_handler_ex
,
318 #if (CONFIG_CODEC == SWCODEC)
320 #ifdef HAVE_PRIORITY_SCHEDULING
328 reset_poweroff_timer
,
333 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
334 #ifdef CPU_BOOST_LOGGING
339 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
340 #endif /* !SIMULATOR */
341 #ifdef HAVE_SCHEDULER_BOOSTCTRL
357 #if CONFIG_CODEC == SWCODEC
358 queue_enable_queue_send
,
368 __cyg_profile_func_enter
,
369 __cyg_profile_func_exit
,
373 /* special simulator hooks */
374 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
376 sim_lcd_ex_update_rect
,
380 /* strings and memory */
423 #if CONFIG_CODEC != SWCODEC
427 #if CONFIG_CODEC == SWCODEC
428 &audio_master_sampr_list
[0],
437 pcm_get_bytes_waiting
,
441 #ifdef HAVE_RECORDING
448 pcm_calculate_rec_peaks
,
449 audio_set_recording_gain
,
450 #endif /* HAVE_RECORDING */
451 #if INPUT_SRC_CAPS != 0
452 audio_set_output_source
,
453 audio_set_input_source
,
460 #endif /* CONFIG_CODEC == SWCODEC */
462 /* playback control */
468 playlist_remove_all_tracks
,
470 playlist_insert_track
,
471 playlist_insert_directory
,
483 audio_flush_and_reload_tracks
,
485 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
486 mpeg_get_last_header
,
488 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
489 (CONFIG_CODEC == SWCODEC)
493 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
494 /* MAS communication */
499 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
506 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
512 gui_syncstatusbar_draw
,
521 #ifdef HAVE_LCD_COLOR
525 /* action handling */
528 #ifdef HAVE_TOUCHSCREEN
529 action_get_touchscreen_press
,
542 # if CONFIG_CHARGING >= CHARGING_MONITOR
546 #ifdef HAVE_USB_POWER
561 plugin_get_audio_buffer
,
563 plugin_get_current_filename
,
564 #ifdef PLUGIN_USE_IRAM
567 #if defined(DEBUG) || defined(SIMULATOR)
570 #ifdef ROCKBOX_HAS_LOGF
576 #if CONFIG_CODEC == SWCODEC
577 codec_thread_do_callback
,
586 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
587 peak_meter_scale_value
,
588 peak_meter_set_use_dbfs
,
589 peak_meter_get_use_dbfs
,
591 #ifdef HAVE_LCD_BITMAP
598 screen_dump_set_hook
,
605 #ifdef HAVE_WHEEL_POSITION
610 #ifdef IRIVER_H100_SERIES
611 /* Routines for the iriver_flash -plugin. */
612 detect_original_firmware
,
613 detect_flashed_ramimage
,
614 detect_flashed_romimage
,
617 #if (CONFIG_CODEC == SWCODEC)
630 buf_request_buffer_handle
,
637 tagcache_search_set_uniqbuf
,
638 tagcache_search_add_filter
,
641 tagcache_search_finish
,
642 tagcache_get_numeric
,
643 #ifdef HAVE_TC_RAMCACHE
650 search_albumart_files
,
653 #ifdef HAVE_SEMAPHORE_OBJECTS
660 /* new stuff at the end, sort into place next time
661 the API gets incompatible */
664 int plugin_load(const char* plugin
, const void* parameter
)
669 struct plugin_header
*hdr
;
672 #else /* !SIMULATOR */
678 #endif /* !SIMULATOR */
681 fb_data
* old_backdrop
;
684 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
686 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
688 /* not allowing another plugin to load */
692 plugin_loaded
= false;
695 splash(0, ID2P(LANG_WAIT
));
696 strcpy(current_plugin
, plugin
);
699 hdr
= sim_plugin_load((char *)plugin
, &pd
);
701 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
705 || hdr
->magic
!= PLUGIN_MAGIC
706 || hdr
->target_id
!= TARGET_ID
) {
707 sim_plugin_close(pd
);
708 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
711 if (hdr
->api_version
> PLUGIN_API_VERSION
712 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
713 sim_plugin_close(pd
);
714 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
718 fd
= open(plugin
, O_RDONLY
);
720 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
724 /* Make sure COP cache is flushed and invalidated before loading */
725 my_core
= switch_core(CURRENT_CORE
^ 1);
726 cpucache_invalidate();
727 switch_core(my_core
);
730 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
734 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
737 hdr
= (struct plugin_header
*)pluginbuf
;
739 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
740 || hdr
->magic
!= PLUGIN_MAGIC
741 || hdr
->target_id
!= TARGET_ID
742 || hdr
->load_addr
!= pluginbuf
743 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
744 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
747 if (hdr
->api_version
> PLUGIN_API_VERSION
748 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
749 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
752 plugin_size
= hdr
->end_addr
- pluginbuf
;
754 /* zero out bss area only, above guards end of pluginbuf */
755 if (plugin_size
> readsize
)
756 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
759 *(hdr
->api
) = &rockbox_api
;
760 plugin_loaded
= true;
763 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
764 old_backdrop
= lcd_get_backdrop();
769 #ifdef HAVE_REMOTE_LCD
770 lcd_remote_clear_display();
774 cpucache_invalidate();
775 oldbars
= viewportmanager_set_statusbar(VP_SB_HIDE_ALL
);
777 #ifdef HAVE_TOUCHSCREEN
778 enum touchscreen_mode old_mode
= touchscreen_get_mode();
780 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
783 rc
= hdr
->entry_point(parameter
);
785 #ifdef HAVE_TOUCHSCREEN
786 touchscreen_set_mode(old_mode
);
789 viewportmanager_set_statusbar(oldbars
);
791 button_clear_queue();
793 #ifdef HAVE_LCD_BITMAP
794 lcd_setfont(FONT_UI
);
796 lcd_set_backdrop(old_backdrop
);
797 #ifdef HAVE_LCD_COLOR
798 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
799 global_settings
.bg_color
);
801 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
803 #else /* LCD_DEPTH == 1 */
804 lcd_set_drawmode(DRMODE_SOLID
);
805 #endif /* LCD_DEPTH */
806 #endif /* HAVE_LCD_BITMAP */
809 #ifdef HAVE_REMOTE_LCD
810 #if LCD_REMOTE_DEPTH > 1
811 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
812 LCD_REMOTE_DEFAULT_BG
);
814 lcd_remote_set_drawmode(DRMODE_SOLID
);
818 if (rc
!= PLUGIN_GOTO_WPS
)
822 screens
[i
].clear_display();
827 viewportmanager_set_statusbar(oldbars
);
828 if (pfn_tsr_exit
== NULL
)
829 plugin_loaded
= false;
831 sim_plugin_close(pd
);
833 if (rc
== PLUGIN_ERROR
)
834 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
839 /* Returns a pointer to the portion of the plugin buffer that is not already
840 being used. If no plugin is loaded, returns the entire plugin buffer */
841 void* plugin_get_buffer(size_t *buffer_size
)
847 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
850 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
851 buffer_pos
= plugin_size
;
855 *buffer_size
= PLUGIN_BUFFER_SIZE
;
859 return &pluginbuf
[buffer_pos
];
862 /* Returns a pointer to the mp3 buffer.
863 Playback gets stopped, to avoid conflicts.
864 Talk buffer is stolen as well.
866 void* plugin_get_audio_buffer(size_t *buffer_size
)
868 #if CONFIG_CODEC == SWCODEC
869 return audio_get_buffer(true, buffer_size
);
872 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
873 *buffer_size
= audiobufend
- audiobuf
;
878 #ifdef PLUGIN_USE_IRAM
879 /* Initializes plugin IRAM */
880 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
881 char *iedata
, size_t iedata_size
)
883 /* We need to stop audio playback in order to use codec IRAM */
885 memcpy(iramstart
, iramcopy
, iram_size
);
886 memset(iedata
, 0, iedata_size
);
887 memset(iramcopy
, 0, iram_size
);
889 /* writeback cleared iedata and iramcopy areas */
893 #endif /* PLUGIN_USE_IRAM */
895 /* The plugin wants to stay resident after leaving its main function, e.g.
896 runs from timer or own thread. The callback is registered to later
897 instruct it to free its resources before a new plugin gets loaded. */
898 void plugin_tsr(bool (*exit_callback
)(bool))
900 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
903 char *plugin_get_current_filename(void)
905 return current_plugin
;