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)
134 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
137 #endif /* LCD_DEPTH */
139 lcd_puts_scroll_style
,
140 #ifdef HAVE_LCD_INVERT
141 lcd_set_invert_display
,
142 #endif /* HAVE_LCD_INVERT */
143 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
144 lcd_activation_set_hook
,
155 #endif /* HAVE_LCD_BITMAP */
160 backlight_set_timeout
,
161 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
162 backlight_set_brightness
,
163 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
166 backlight_set_timeout_plugged
,
172 #ifdef HAVE_REMOTE_LCD
174 lcd_remote_set_contrast
,
175 lcd_remote_clear_display
,
177 lcd_remote_puts_scroll
,
178 lcd_remote_stop_scroll
,
179 lcd_remote_set_drawmode
,
180 lcd_remote_get_drawmode
,
182 lcd_remote_getstringsize
,
183 lcd_remote_drawpixel
,
189 lcd_remote_mono_bitmap_part
,
190 lcd_remote_mono_bitmap
,
192 lcd_remote_puts_style
,
193 lcd_remote_puts_scroll_style
,
194 &lcd_remote_framebuffer
[0][0],
196 lcd_remote_update_rect
,
199 remote_backlight_off
,
200 remote_backlight_set_timeout
,
202 remote_backlight_set_timeout_plugged
,
204 #endif /* HAVE_REMOTE_LCD */
206 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
208 {&screens
[SCREEN_MAIN
]},
210 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
211 lcd_remote_set_foreground
,
212 lcd_remote_get_foreground
,
213 lcd_remote_set_background
,
214 lcd_remote_get_background
,
215 lcd_remote_bitmap_part
,
218 viewport_set_defaults
,
219 viewportmanager_set_statusbar
,
223 gui_synclist_set_nb_items
,
224 gui_synclist_set_icon_callback
,
225 gui_synclist_get_nb_items
,
226 gui_synclist_get_sel_pos
,
228 gui_synclist_select_item
,
229 gui_synclist_add_item
,
230 gui_synclist_del_item
,
231 gui_synclist_limit_scroll
,
232 gui_synclist_do_button
,
233 gui_synclist_set_title
,
235 simplelist_info_init
,
236 simplelist_show_list
,
242 #ifdef HAVE_BUTTON_DATA
247 #ifdef HAS_BUTTON_HOLD
250 #ifdef HAVE_TOUCHSCREEN
251 touchscreen_set_mode
,
254 #ifdef HAVE_BUTTON_LIGHT
255 buttonlight_set_timeout
,
258 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
259 buttonlight_set_brightness
,
260 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
261 #endif /* HAVE_BUTTON_LIGHT */
264 (open_func
)PREFIX(open
),
266 (read_func
)PREFIX(read
),
268 (creat_func
)PREFIX(creat
),
269 (write_func
)PREFIX(write
),
280 #if USING_STORAGE_CALLBACK
281 register_storage_idle_func
,
282 unregister_storage_idle_func
,
283 #endif /* USING_STORAGE_CALLBACK */
285 create_numbered_filename
,
304 default_event_handler
,
305 default_event_handler_ex
,
309 #if (CONFIG_CODEC == SWCODEC)
311 #ifdef HAVE_PRIORITY_SCHEDULING
319 reset_poweroff_timer
,
324 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
325 #ifdef CPU_BOOST_LOGGING
330 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
331 #endif /* !SIMULATOR */
332 #ifdef HAVE_SCHEDULER_BOOSTCTRL
348 #if CONFIG_CODEC == SWCODEC
349 queue_enable_queue_send
,
359 __cyg_profile_func_enter
,
360 __cyg_profile_func_exit
,
364 /* special simulator hooks */
365 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
367 sim_lcd_ex_update_rect
,
371 /* strings and memory */
414 #if CONFIG_CODEC != SWCODEC
418 #if CONFIG_CODEC == SWCODEC
419 &audio_master_sampr_list
[0],
428 pcm_get_bytes_waiting
,
432 #ifdef HAVE_RECORDING
439 pcm_calculate_rec_peaks
,
440 audio_set_recording_gain
,
441 #endif /* HAVE_RECORDING */
442 #if INPUT_SRC_CAPS != 0
443 audio_set_output_source
,
444 audio_set_input_source
,
451 #endif /* CONFIG_CODEC == SWCODEC */
453 /* playback control */
467 audio_flush_and_reload_tracks
,
469 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
470 mpeg_get_last_header
,
472 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
473 (CONFIG_CODEC == SWCODEC)
477 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
478 /* MAS communication */
483 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
490 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
496 gui_syncstatusbar_draw
,
505 #ifdef HAVE_LCD_COLOR
509 /* action handling */
523 # if CONFIG_CHARGING >= CHARGING_MONITOR
527 #ifdef HAVE_USB_POWER
542 plugin_get_audio_buffer
,
544 plugin_get_current_filename
,
545 #ifdef PLUGIN_USE_IRAM
548 #if defined(DEBUG) || defined(SIMULATOR)
551 #ifdef ROCKBOX_HAS_LOGF
557 #if CONFIG_CODEC == SWCODEC
558 codec_thread_do_callback
,
567 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
568 peak_meter_scale_value
,
569 peak_meter_set_use_dbfs
,
570 peak_meter_get_use_dbfs
,
572 #ifdef HAVE_LCD_BITMAP
574 screen_dump_set_hook
,
581 #ifdef HAVE_WHEEL_POSITION
586 #ifdef IRIVER_H100_SERIES
587 /* Routines for the iriver_flash -plugin. */
588 detect_original_firmware
,
589 detect_flashed_ramimage
,
590 detect_flashed_romimage
,
593 #if (CONFIG_CODEC == SWCODEC)
606 buf_request_buffer_handle
,
613 tagcache_search_set_uniqbuf
,
614 tagcache_search_add_filter
,
617 tagcache_search_finish
,
618 tagcache_get_numeric
,
623 search_albumart_files
,
626 #ifdef HAVE_SEMAPHORE_OBJECTS
633 /* new stuff at the end, sort into place next time
634 the API gets incompatible */
636 #if defined(HAVE_LCD_MODES)
641 int plugin_load(const char* plugin
, const void* parameter
)
645 struct plugin_header
*hdr
;
648 #else /* !SIMULATOR */
654 #endif /* !SIMULATOR */
657 fb_data
* old_backdrop
;
660 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
662 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
664 /* not allowing another plugin to load */
668 plugin_loaded
= false;
671 splash(0, ID2P(LANG_WAIT
));
672 strcpy(current_plugin
, plugin
);
675 hdr
= sim_plugin_load((char *)plugin
, &pd
);
677 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
681 || hdr
->magic
!= PLUGIN_MAGIC
682 || hdr
->target_id
!= TARGET_ID
) {
683 sim_plugin_close(pd
);
684 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
687 if (hdr
->api_version
> PLUGIN_API_VERSION
688 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
689 sim_plugin_close(pd
);
690 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
694 fd
= open(plugin
, O_RDONLY
);
696 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
700 /* Make sure COP cache is flushed and invalidated before loading */
701 my_core
= switch_core(CURRENT_CORE
^ 1);
702 cpucache_invalidate();
703 switch_core(my_core
);
706 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
710 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
713 hdr
= (struct plugin_header
*)pluginbuf
;
715 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
716 || hdr
->magic
!= PLUGIN_MAGIC
717 || hdr
->target_id
!= TARGET_ID
718 || hdr
->load_addr
!= pluginbuf
719 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
720 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
723 if (hdr
->api_version
> PLUGIN_API_VERSION
724 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
725 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
728 plugin_size
= hdr
->end_addr
- pluginbuf
;
730 /* zero out bss area only, above guards end of pluginbuf */
731 if (plugin_size
> readsize
)
732 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
735 *(hdr
->api
) = &rockbox_api
;
736 plugin_loaded
= true;
739 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
740 old_backdrop
= lcd_get_backdrop();
745 #ifdef HAVE_REMOTE_LCD
746 lcd_remote_clear_display();
750 cpucache_invalidate();
751 oldbars
= viewportmanager_set_statusbar(VP_SB_HIDE_ALL
);
753 rc
= hdr
->entry_point(parameter
);
755 viewportmanager_set_statusbar(oldbars
);
757 button_clear_queue();
759 #ifdef HAVE_LCD_BITMAP
761 lcd_set_backdrop(old_backdrop
);
762 #ifdef HAVE_LCD_COLOR
763 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
764 global_settings
.bg_color
);
766 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
768 #else /* LCD_DEPTH == 1 */
769 lcd_set_drawmode(DRMODE_SOLID
);
770 #endif /* LCD_DEPTH */
771 #endif /* HAVE_LCD_BITMAP */
776 #ifdef HAVE_REMOTE_LCD
777 #if LCD_REMOTE_DEPTH > 1
778 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
779 LCD_REMOTE_DEFAULT_BG
);
781 lcd_remote_set_drawmode(DRMODE_SOLID
);
783 lcd_remote_clear_display();
790 viewportmanager_set_statusbar(oldbars
);
791 if (pfn_tsr_exit
== NULL
)
792 plugin_loaded
= false;
794 sim_plugin_close(pd
);
800 case PLUGIN_USB_CONNECTED
:
801 return PLUGIN_USB_CONNECTED
;
804 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
811 /* Returns a pointer to the portion of the plugin buffer that is not already
812 being used. If no plugin is loaded, returns the entire plugin buffer */
813 void* plugin_get_buffer(size_t *buffer_size
)
819 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
822 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
823 buffer_pos
= plugin_size
;
827 *buffer_size
= PLUGIN_BUFFER_SIZE
;
831 return &pluginbuf
[buffer_pos
];
834 /* Returns a pointer to the mp3 buffer.
835 Playback gets stopped, to avoid conflicts.
836 Talk buffer is stolen as well.
838 void* plugin_get_audio_buffer(size_t *buffer_size
)
840 #if CONFIG_CODEC == SWCODEC
841 return audio_get_buffer(true, buffer_size
);
844 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
845 *buffer_size
= audiobufend
- audiobuf
;
850 #ifdef PLUGIN_USE_IRAM
851 /* Initializes plugin IRAM */
852 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
853 char *iedata
, size_t iedata_size
)
855 /* We need to stop audio playback in order to use codec IRAM */
857 memcpy(iramstart
, iramcopy
, iram_size
);
858 memset(iedata
, 0, iedata_size
);
859 memset(iramcopy
, 0, iram_size
);
861 /* writeback cleared iedata and iramcopy areas */
865 #endif /* PLUGIN_USE_IRAM */
867 /* The plugin wants to stay resident after leaving its main function, e.g.
868 runs from timer or own thread. The callback is registered to later
869 instruct it to free its resources before a new plugin gets loaded. */
870 void plugin_tsr(bool (*exit_callback
)(bool))
872 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
875 char *plugin_get_current_filename(void)
877 return current_plugin
;