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
= {
91 #ifdef HAVE_LCD_CHARCELLS
93 lcd_get_locked_pattern
,
101 &lcd_framebuffer
[0][0],
112 lcd_mono_bitmap_part
,
125 lcd_bitmap_transparent_part
,
126 lcd_bitmap_transparent
,
128 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
129 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630)
132 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
135 #endif /* LCD_DEPTH */
137 lcd_puts_scroll_style
,
138 #ifdef HAVE_LCD_INVERT
139 lcd_set_invert_display
,
140 #endif /* HAVE_LCD_INVERT */
141 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
142 lcd_activation_set_hook
,
153 #endif /* HAVE_LCD_BITMAP */
158 backlight_set_timeout
,
159 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
160 backlight_set_brightness
,
161 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
164 backlight_set_timeout_plugged
,
170 #ifdef HAVE_REMOTE_LCD
172 lcd_remote_set_contrast
,
173 lcd_remote_clear_display
,
175 lcd_remote_puts_scroll
,
176 lcd_remote_stop_scroll
,
177 lcd_remote_set_drawmode
,
178 lcd_remote_get_drawmode
,
180 lcd_remote_getstringsize
,
181 lcd_remote_drawpixel
,
187 lcd_remote_mono_bitmap_part
,
188 lcd_remote_mono_bitmap
,
190 lcd_remote_puts_style
,
191 lcd_remote_puts_scroll_style
,
192 &lcd_remote_framebuffer
[0][0],
194 lcd_remote_update_rect
,
197 remote_backlight_off
,
198 remote_backlight_set_timeout
,
200 remote_backlight_set_timeout_plugged
,
202 #endif /* HAVE_REMOTE_LCD */
204 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
206 {&screens
[SCREEN_MAIN
]},
208 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
209 lcd_remote_set_foreground
,
210 lcd_remote_get_foreground
,
211 lcd_remote_set_background
,
212 lcd_remote_get_background
,
213 lcd_remote_bitmap_part
,
216 viewport_set_defaults
,
217 viewportmanager_set_statusbar
,
221 gui_synclist_set_nb_items
,
222 gui_synclist_set_icon_callback
,
223 gui_synclist_get_nb_items
,
224 gui_synclist_get_sel_pos
,
226 gui_synclist_select_item
,
227 gui_synclist_add_item
,
228 gui_synclist_del_item
,
229 gui_synclist_limit_scroll
,
230 gui_synclist_do_button
,
231 gui_synclist_set_title
,
233 simplelist_info_init
,
234 simplelist_show_list
,
240 #ifdef HAVE_BUTTON_DATA
245 #ifdef HAS_BUTTON_HOLD
248 #ifdef HAVE_TOUCHSCREEN
249 touchscreen_set_mode
,
252 #ifdef HAVE_BUTTON_LIGHT
253 buttonlight_set_timeout
,
256 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
257 buttonlight_set_brightness
,
258 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
259 #endif /* HAVE_BUTTON_LIGHT */
262 (open_func
)PREFIX(open
),
264 (read_func
)PREFIX(read
),
266 (creat_func
)PREFIX(creat
),
267 (write_func
)PREFIX(write
),
278 #if USING_STORAGE_CALLBACK
279 register_storage_idle_func
,
280 unregister_storage_idle_func
,
281 #endif /* USING_STORAGE_CALLBACK */
283 create_numbered_filename
,
302 default_event_handler
,
303 default_event_handler_ex
,
307 #if (CONFIG_CODEC == SWCODEC)
309 #ifdef HAVE_PRIORITY_SCHEDULING
317 reset_poweroff_timer
,
322 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
323 #ifdef CPU_BOOST_LOGGING
328 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
329 #endif /* !SIMULATOR */
330 #ifdef HAVE_SCHEDULER_BOOSTCTRL
346 #if CONFIG_CODEC == SWCODEC
347 queue_enable_queue_send
,
357 __cyg_profile_func_enter
,
358 __cyg_profile_func_exit
,
362 /* special simulator hooks */
363 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
365 sim_lcd_ex_update_rect
,
369 /* strings and memory */
412 #if CONFIG_CODEC != SWCODEC
416 #if CONFIG_CODEC == SWCODEC
417 &audio_master_sampr_list
[0],
426 pcm_get_bytes_waiting
,
430 #ifdef HAVE_RECORDING
437 pcm_calculate_rec_peaks
,
438 audio_set_recording_gain
,
439 #endif /* HAVE_RECORDING */
440 #if INPUT_SRC_CAPS != 0
441 audio_set_output_source
,
442 audio_set_input_source
,
449 #endif /* CONFIG_CODEC == SWCODEC */
451 /* playback control */
464 audio_has_changed_track
,
466 audio_flush_and_reload_tracks
,
468 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
469 mpeg_get_last_header
,
471 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
472 (CONFIG_CODEC == SWCODEC)
476 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
477 /* MAS communication */
482 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
489 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
495 gui_syncstatusbar_draw
,
504 #ifdef HAVE_LCD_COLOR
508 /* action handling */
522 # if CONFIG_CHARGING == CHARGING_MONITOR
526 #ifdef HAVE_USB_POWER
541 plugin_get_audio_buffer
,
543 plugin_get_current_filename
,
544 #ifdef PLUGIN_USE_IRAM
547 #if defined(DEBUG) || defined(SIMULATOR)
550 #ifdef ROCKBOX_HAS_LOGF
556 #if CONFIG_CODEC == SWCODEC
557 codec_thread_do_callback
,
566 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
567 peak_meter_scale_value
,
568 peak_meter_set_use_dbfs
,
569 peak_meter_get_use_dbfs
,
571 #ifdef HAVE_LCD_BITMAP
573 screen_dump_set_hook
,
580 #ifdef HAVE_WHEEL_POSITION
585 #ifdef IRIVER_H100_SERIES
586 /* Routines for the iriver_flash -plugin. */
587 detect_original_firmware
,
588 detect_flashed_ramimage
,
589 detect_flashed_romimage
,
592 #if (CONFIG_CODEC == SWCODEC)
605 buf_request_buffer_handle
,
612 tagcache_search_set_uniqbuf
,
613 tagcache_search_add_filter
,
616 tagcache_search_finish
,
617 tagcache_get_numeric
,
622 search_albumart_files
,
625 #ifdef HAVE_SEMAPHORE_OBJECTS
632 /* new stuff at the end, sort into place next time
633 the API gets incompatible */
636 int plugin_load(const char* plugin
, const void* parameter
)
640 struct plugin_header
*hdr
;
643 #else /* !SIMULATOR */
649 #endif /* !SIMULATOR */
652 fb_data
* old_backdrop
;
655 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
657 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
659 /* not allowing another plugin to load */
663 plugin_loaded
= false;
666 splash(0, ID2P(LANG_WAIT
));
667 strcpy(current_plugin
, plugin
);
670 hdr
= sim_plugin_load((char *)plugin
, &pd
);
672 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
676 || hdr
->magic
!= PLUGIN_MAGIC
677 || hdr
->target_id
!= TARGET_ID
) {
678 sim_plugin_close(pd
);
679 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
682 if (hdr
->api_version
> PLUGIN_API_VERSION
683 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
684 sim_plugin_close(pd
);
685 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
689 fd
= open(plugin
, O_RDONLY
);
691 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
695 /* Make sure COP cache is flushed and invalidated before loading */
696 my_core
= switch_core(CURRENT_CORE
^ 1);
697 cpucache_invalidate();
698 switch_core(my_core
);
701 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
705 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
708 hdr
= (struct plugin_header
*)pluginbuf
;
710 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
711 || hdr
->magic
!= PLUGIN_MAGIC
712 || hdr
->target_id
!= TARGET_ID
713 || hdr
->load_addr
!= pluginbuf
714 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
715 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
718 if (hdr
->api_version
> PLUGIN_API_VERSION
719 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
720 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
723 plugin_size
= hdr
->end_addr
- pluginbuf
;
725 /* zero out bss area only, above guards end of pluginbuf */
726 if (plugin_size
> readsize
)
727 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
730 *(hdr
->api
) = &rockbox_api
;
731 plugin_loaded
= true;
734 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
735 old_backdrop
= lcd_get_backdrop();
740 #ifdef HAVE_REMOTE_LCD
741 lcd_remote_clear_display();
745 cpucache_invalidate();
746 oldbars
= viewportmanager_set_statusbar(VP_SB_HIDE_ALL
);
748 rc
= hdr
->entry_point(parameter
);
750 viewportmanager_set_statusbar(oldbars
);
752 button_clear_queue();
754 #ifdef HAVE_LCD_BITMAP
756 lcd_set_backdrop(old_backdrop
);
757 #ifdef HAVE_LCD_COLOR
758 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
759 global_settings
.bg_color
);
761 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
763 #else /* LCD_DEPTH == 1 */
764 lcd_set_drawmode(DRMODE_SOLID
);
765 #endif /* LCD_DEPTH */
766 #endif /* HAVE_LCD_BITMAP */
771 #ifdef HAVE_REMOTE_LCD
772 #if LCD_REMOTE_DEPTH > 1
773 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
774 LCD_REMOTE_DEFAULT_BG
);
776 lcd_remote_set_drawmode(DRMODE_SOLID
);
778 lcd_remote_clear_display();
785 viewportmanager_set_statusbar(oldbars
);
786 if (pfn_tsr_exit
== NULL
)
787 plugin_loaded
= false;
789 sim_plugin_close(pd
);
795 case PLUGIN_USB_CONNECTED
:
796 return PLUGIN_USB_CONNECTED
;
799 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
806 /* Returns a pointer to the portion of the plugin buffer that is not already
807 being used. If no plugin is loaded, returns the entire plugin buffer */
808 void* plugin_get_buffer(size_t *buffer_size
)
814 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
817 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
818 buffer_pos
= plugin_size
;
822 *buffer_size
= PLUGIN_BUFFER_SIZE
;
826 return &pluginbuf
[buffer_pos
];
829 /* Returns a pointer to the mp3 buffer.
830 Playback gets stopped, to avoid conflicts.
831 Talk buffer is stolen as well.
833 void* plugin_get_audio_buffer(size_t *buffer_size
)
835 #if CONFIG_CODEC == SWCODEC
836 return audio_get_buffer(true, buffer_size
);
839 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
840 *buffer_size
= audiobufend
- audiobuf
;
845 #ifdef PLUGIN_USE_IRAM
846 /* Initializes plugin IRAM */
847 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
848 char *iedata
, size_t iedata_size
)
850 /* We need to stop audio playback in order to use codec IRAM */
852 memcpy(iramstart
, iramcopy
, iram_size
);
853 memset(iedata
, 0, iedata_size
);
854 memset(iramcopy
, 0, iram_size
);
856 /* writeback cleared iedata and iramcopy areas */
860 #endif /* PLUGIN_USE_IRAM */
862 /* The plugin wants to stay resident after leaving its main function, e.g.
863 runs from timer or own thread. The callback is registered to later
864 instruct it to free its resources before a new plugin gets loaded. */
865 void plugin_tsr(bool (*exit_callback
)(bool))
867 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
870 char *plugin_get_current_filename(void)
872 return current_plugin
;