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 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
56 void *sim_plugin_load(char *plugin
, void **pd
);
57 void sim_plugin_close(void *pd
);
58 void sim_lcd_ex_init(int shades
, unsigned long (*getpixel
)(int, int));
59 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
61 #define sim_plugin_close(x)
62 extern unsigned char pluginbuf
[];
66 /* for actual plugins only, not for codecs */
67 static bool plugin_loaded
= false;
68 static int plugin_size
= 0;
69 static bool (*pfn_tsr_exit
)(bool reenter
) = NULL
; /* TSR exit callback */
70 static char current_plugin
[MAX_PATH
];
72 char *plugin_get_current_filename(void);
74 extern struct thread_entry threads
[MAXTHREADS
];
76 static const struct plugin_api rockbox_api
= {
87 #ifdef HAVE_LCD_CHARCELLS
89 lcd_get_locked_pattern
,
97 &lcd_framebuffer
[0][0],
108 lcd_mono_bitmap_part
,
121 lcd_bitmap_transparent_part
,
122 lcd_bitmap_transparent
,
124 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
125 || defined(IRIVER_H10) || defined(COWON_D2)
128 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
131 #endif /* LCD_DEPTH */
133 lcd_puts_scroll_style
,
134 #ifdef HAVE_LCD_INVERT
135 lcd_set_invert_display
,
136 #endif /* HAVE_LCD_INVERT */
137 #if defined(HAVE_LCD_ENABLE) && defined(HAVE_LCD_COLOR)
153 backlight_set_timeout
,
154 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
155 backlight_set_brightness
,
156 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
159 backlight_set_timeout_plugged
,
165 #ifdef HAVE_REMOTE_LCD
167 lcd_remote_set_contrast
,
168 lcd_remote_clear_display
,
170 lcd_remote_puts_scroll
,
171 lcd_remote_stop_scroll
,
172 lcd_remote_set_drawmode
,
173 lcd_remote_get_drawmode
,
175 lcd_remote_getstringsize
,
176 lcd_remote_drawpixel
,
182 lcd_remote_mono_bitmap_part
,
183 lcd_remote_mono_bitmap
,
185 lcd_remote_puts_style
,
186 lcd_remote_puts_scroll_style
,
187 &lcd_remote_framebuffer
[0][0],
189 lcd_remote_update_rect
,
192 remote_backlight_off
,
193 remote_backlight_set_timeout
,
195 remote_backlight_set_timeout_plugged
,
197 #endif /* HAVE_REMOTE_LCD */
199 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
201 {&screens
[SCREEN_MAIN
]},
203 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
204 lcd_remote_set_foreground
,
205 lcd_remote_get_foreground
,
206 lcd_remote_set_background
,
207 lcd_remote_get_background
,
208 lcd_remote_bitmap_part
,
211 viewport_set_defaults
,
215 gui_synclist_set_nb_items
,
216 gui_synclist_set_icon_callback
,
217 gui_synclist_get_nb_items
,
218 gui_synclist_get_sel_pos
,
220 gui_synclist_select_item
,
221 gui_synclist_add_item
,
222 gui_synclist_del_item
,
223 gui_synclist_limit_scroll
,
224 gui_synclist_do_button
,
225 gui_synclist_set_title
,
227 simplelist_info_init
,
228 simplelist_show_list
,
234 #ifdef HAVE_BUTTON_DATA
239 #ifdef HAS_BUTTON_HOLD
242 #ifdef HAVE_TOUCHSCREEN
243 touchscreen_set_mode
,
246 #ifdef HAVE_BUTTON_LIGHT
247 buttonlight_set_timeout
,
250 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
251 buttonlight_set_brightness
,
252 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
253 #endif /* HAVE_BUTTON_LIGHT */
256 (open_func
)PREFIX(open
),
258 (read_func
)PREFIX(read
),
260 (creat_func
)PREFIX(creat
),
261 (write_func
)PREFIX(write
),
272 #if USING_STORAGE_CALLBACK
273 register_storage_idle_func
,
274 unregister_storage_idle_func
,
275 #endif /* USING_STORAGE_CALLBACK */
277 create_numbered_filename
,
292 default_event_handler
,
293 default_event_handler_ex
,
298 #if (CONFIG_CODEC == SWCODEC)
305 reset_poweroff_timer
,
310 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
311 #ifdef CPU_BOOST_LOGGING
316 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
317 #endif /* !SIMULATOR */
318 #ifdef HAVE_SCHEDULER_BOOSTCTRL
322 #ifdef CACHE_FUNCTIONS_AS_CALL
334 #if CONFIG_CODEC == SWCODEC
335 queue_enable_queue_send
,
345 __cyg_profile_func_enter
,
346 __cyg_profile_func_exit
,
350 /* special simulator hooks */
351 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
353 sim_lcd_ex_update_rect
,
357 /* strings and memory */
400 #if CONFIG_CODEC != SWCODEC
404 #if CONFIG_CODEC == SWCODEC
405 &audio_master_sampr_list
[0],
414 pcm_get_bytes_waiting
,
418 #ifdef HAVE_RECORDING
425 pcm_calculate_rec_peaks
,
426 audio_set_recording_gain
,
427 #endif /* HAVE_RECORDING */
428 #if INPUT_SRC_CAPS != 0
429 audio_set_output_source
,
430 audio_set_input_source
,
437 #endif /* CONFIG_CODEC == SWCODEC */
439 /* playback control */
452 audio_has_changed_track
,
454 audio_flush_and_reload_tracks
,
456 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
457 mpeg_get_last_header
,
459 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
460 (CONFIG_CODEC == SWCODEC)
464 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
465 /* MAS communication */
470 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
477 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
483 gui_syncstatusbar_draw
,
491 #ifdef HAVE_LCD_COLOR
495 /* action handling */
509 # if CONFIG_CHARGING == CHARGING_MONITOR
513 #ifdef HAVE_USB_POWER
528 plugin_get_audio_buffer
,
530 plugin_get_current_filename
,
531 #ifdef PLUGIN_USE_IRAM
534 #if defined(DEBUG) || defined(SIMULATOR)
537 #ifdef ROCKBOX_HAS_LOGF
543 #if CONFIG_CODEC == SWCODEC
552 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
553 peak_meter_scale_value
,
554 peak_meter_set_use_dbfs
,
555 peak_meter_get_use_dbfs
,
557 #ifdef HAVE_LCD_BITMAP
559 screen_dump_set_hook
,
566 #ifdef HAVE_WHEEL_POSITION
571 #ifdef IRIVER_H100_SERIES
572 /* Routines for the iriver_flash -plugin. */
573 detect_original_firmware
,
574 detect_flashed_ramimage
,
575 detect_flashed_romimage
,
578 #if (CONFIG_CODEC == SWCODEC)
591 buf_request_buffer_handle
,
598 tagcache_search_set_uniqbuf
,
599 tagcache_search_add_filter
,
602 tagcache_search_finish
,
603 tagcache_get_numeric
,
608 search_albumart_files
,
613 #ifdef HAVE_SEMAPHORE_OBJECTS
620 /* new stuff at the end, sort into place next time
621 the API gets incompatible */
625 int plugin_load(const char* plugin
, const void* parameter
)
628 struct plugin_header
*hdr
;
631 #else /* !SIMULATOR */
637 #endif /* !SIMULATOR */
640 fb_data
* old_backdrop
;
643 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
645 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
647 /* not allowing another plugin to load */
651 plugin_loaded
= false;
654 splash(0, ID2P(LANG_WAIT
));
655 strcpy(current_plugin
, plugin
);
658 hdr
= sim_plugin_load((char *)plugin
, &pd
);
660 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
664 || hdr
->magic
!= PLUGIN_MAGIC
665 || hdr
->target_id
!= TARGET_ID
) {
666 sim_plugin_close(pd
);
667 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
670 if (hdr
->api_version
> PLUGIN_API_VERSION
671 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
672 sim_plugin_close(pd
);
673 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
677 fd
= open(plugin
, O_RDONLY
);
679 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
683 /* Make sure COP cache is flushed and invalidated before loading */
684 my_core
= switch_core(CURRENT_CORE
^ 1);
686 switch_core(my_core
);
689 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
693 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
696 hdr
= (struct plugin_header
*)pluginbuf
;
698 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
699 || hdr
->magic
!= PLUGIN_MAGIC
700 || hdr
->target_id
!= TARGET_ID
701 || hdr
->load_addr
!= pluginbuf
702 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
703 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
706 if (hdr
->api_version
> PLUGIN_API_VERSION
707 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
708 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
711 plugin_size
= hdr
->end_addr
- pluginbuf
;
713 /* zero out bss area only, above guards end of pluginbuf */
714 if (plugin_size
> readsize
)
715 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
718 plugin_loaded
= true;
721 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
722 old_backdrop
= lcd_get_backdrop();
727 #ifdef HAVE_REMOTE_LCD
728 lcd_remote_clear_display();
734 rc
= hdr
->entry_point(&rockbox_api
, parameter
);
736 button_clear_queue();
738 #ifdef HAVE_LCD_BITMAP
740 lcd_set_backdrop(old_backdrop
);
741 #ifdef HAVE_LCD_COLOR
742 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
743 global_settings
.bg_color
);
745 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
747 #else /* LCD_DEPTH == 1 */
748 lcd_set_drawmode(DRMODE_SOLID
);
749 #endif /* LCD_DEPTH */
750 #endif /* HAVE_LCD_BITMAP */
755 #ifdef HAVE_REMOTE_LCD
756 #if LCD_REMOTE_DEPTH > 1
757 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
758 LCD_REMOTE_DEFAULT_BG
);
760 lcd_remote_set_drawmode(DRMODE_SOLID
);
762 lcd_remote_clear_display();
770 if (pfn_tsr_exit
== NULL
)
771 plugin_loaded
= false;
773 sim_plugin_close(pd
);
779 case PLUGIN_USB_CONNECTED
:
780 return PLUGIN_USB_CONNECTED
;
783 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
789 /* Returns a pointer to the portion of the plugin buffer that is not already
790 being used. If no plugin is loaded, returns the entire plugin buffer */
791 void* plugin_get_buffer(size_t *buffer_size
)
797 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
800 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
801 buffer_pos
= plugin_size
;
805 *buffer_size
= PLUGIN_BUFFER_SIZE
;
809 return &pluginbuf
[buffer_pos
];
812 /* Returns a pointer to the mp3 buffer.
813 Playback gets stopped, to avoid conflicts.
814 Talk buffer is stolen as well.
816 void* plugin_get_audio_buffer(size_t *buffer_size
)
818 #if CONFIG_CODEC == SWCODEC
819 return audio_get_buffer(true, buffer_size
);
822 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
823 *buffer_size
= audiobufend
- audiobuf
;
828 #ifdef PLUGIN_USE_IRAM
829 /* Initializes plugin IRAM */
830 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
831 char *iedata
, size_t iedata_size
)
833 /* We need to stop audio playback in order to use codec IRAM */
835 memcpy(iramstart
, iramcopy
, iram_size
);
836 memset(iedata
, 0, iedata_size
);
837 memset(iramcopy
, 0, iram_size
);
839 /* writeback cleared iedata and iramcopy areas */
843 #endif /* PLUGIN_USE_IRAM */
845 /* The plugin wants to stay resident after leaving its main function, e.g.
846 runs from timer or own thread. The callback is registered to later
847 instruct it to free its resources before a new plugin gets loaded. */
848 void plugin_tsr(bool (*exit_callback
)(bool))
850 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
853 char *plugin_get_current_filename(void)
855 return current_plugin
;