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"
45 #ifdef HAVE_LCD_BITMAP
46 #include "scrollbar.h"
47 #include "peakmeter.h"
53 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
54 void *sim_plugin_load(char *plugin
, void **pd
);
55 void sim_plugin_close(void *pd
);
56 void sim_lcd_ex_init(int shades
, unsigned long (*getpixel
)(int, int));
57 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
59 #define sim_plugin_close(x)
60 extern unsigned char pluginbuf
[];
64 /* for actual plugins only, not for codecs */
65 static bool plugin_loaded
= false;
66 static int plugin_size
= 0;
67 static bool (*pfn_tsr_exit
)(bool reenter
) = NULL
; /* TSR exit callback */
68 static char current_plugin
[MAX_PATH
];
70 char *plugin_get_current_filename(void);
72 extern struct thread_entry threads
[MAXTHREADS
];
74 static const struct plugin_api rockbox_api
= {
85 #ifdef HAVE_LCD_CHARCELLS
87 lcd_get_locked_pattern
,
95 &lcd_framebuffer
[0][0],
106 lcd_mono_bitmap_part
,
119 lcd_bitmap_transparent_part
,
120 lcd_bitmap_transparent
,
122 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
123 || defined(IRIVER_H10) || defined(COWON_D2)
126 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
129 #endif /* LCD_DEPTH */
131 lcd_puts_scroll_style
,
132 #ifdef HAVE_LCD_INVERT
133 lcd_set_invert_display
,
134 #endif /* HAVE_LCD_INVERT */
135 #ifdef HAVE_LCD_ENABLE
151 backlight_set_timeout
,
152 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
153 backlight_set_brightness
,
154 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
157 backlight_set_timeout_plugged
,
162 #ifdef HAVE_REMOTE_LCD
164 lcd_remote_set_contrast
,
165 lcd_remote_clear_display
,
167 lcd_remote_puts_scroll
,
168 lcd_remote_stop_scroll
,
169 lcd_remote_set_drawmode
,
170 lcd_remote_get_drawmode
,
172 lcd_remote_getstringsize
,
173 lcd_remote_drawpixel
,
179 lcd_remote_mono_bitmap_part
,
180 lcd_remote_mono_bitmap
,
182 lcd_remote_puts_style
,
183 lcd_remote_puts_scroll_style
,
184 &lcd_remote_framebuffer
[0][0],
186 lcd_remote_update_rect
,
189 remote_backlight_off
,
190 remote_backlight_set_timeout
,
192 remote_backlight_set_timeout_plugged
,
194 #endif /* HAVE_REMOTE_LCD */
196 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
198 {&screens
[SCREEN_MAIN
]},
200 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
201 lcd_remote_set_foreground
,
202 lcd_remote_get_foreground
,
203 lcd_remote_set_background
,
204 lcd_remote_get_background
,
205 lcd_remote_bitmap_part
,
208 viewport_set_defaults
,
212 gui_synclist_set_nb_items
,
213 gui_synclist_set_icon_callback
,
214 gui_synclist_get_nb_items
,
215 gui_synclist_get_sel_pos
,
217 gui_synclist_select_item
,
218 gui_synclist_add_item
,
219 gui_synclist_del_item
,
220 gui_synclist_limit_scroll
,
221 gui_synclist_do_button
,
222 gui_synclist_set_title
,
223 simplelist_info_init
,
224 simplelist_show_list
,
230 #ifdef HAVE_BUTTON_DATA
235 #ifdef HAS_BUTTON_HOLD
242 #ifdef HAVE_BUTTON_LIGHT
243 buttonlight_set_timeout
,
246 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
247 buttonlight_set_brightness
,
248 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
249 #endif /* HAVE_BUTTON_LIGHT */
252 (open_func
)PREFIX(open
),
254 (read_func
)PREFIX(read
),
256 (creat_func
)PREFIX(creat
),
257 (write_func
)PREFIX(write
),
270 create_numbered_filename
,
285 default_event_handler
,
286 default_event_handler_ex
,
291 #if (CONFIG_CODEC == SWCODEC)
298 reset_poweroff_timer
,
303 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
304 #ifdef CPU_BOOST_LOGGING
309 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
310 #endif /* !SIMULATOR */
311 #ifdef HAVE_SCHEDULER_BOOSTCTRL
315 #ifdef CACHE_FUNCTIONS_AS_CALL
327 #if CONFIG_CODEC == SWCODEC
328 queue_enable_queue_send
,
338 __cyg_profile_func_enter
,
339 __cyg_profile_func_exit
,
343 /* special simulator hooks */
344 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
346 sim_lcd_ex_update_rect
,
350 /* strings and memory */
393 #if CONFIG_CODEC != SWCODEC
397 #if CONFIG_CODEC == SWCODEC
398 &audio_master_sampr_list
[0],
407 pcm_get_bytes_waiting
,
411 #ifdef HAVE_RECORDING
418 pcm_calculate_rec_peaks
,
419 audio_set_recording_gain
,
420 #endif /* HAVE_RECORDING */
421 #if INPUT_SRC_CAPS != 0
422 audio_set_output_source
,
423 audio_set_input_source
,
430 #endif /* CONFIG_CODEC == SWCODEC */
432 /* playback control */
445 audio_has_changed_track
,
447 audio_flush_and_reload_tracks
,
449 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
450 mpeg_get_last_header
,
452 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
453 (CONFIG_CODEC == SWCODEC)
457 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
458 /* MAS communication */
463 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
470 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
476 gui_syncstatusbar_draw
,
484 #ifdef HAVE_LCD_COLOR
488 /* action handling */
502 # if CONFIG_CHARGING == CHARGING_MONITOR
506 #ifdef HAVE_USB_POWER
521 plugin_get_audio_buffer
,
523 plugin_get_current_filename
,
524 #ifdef PLUGIN_USE_IRAM
527 #if defined(DEBUG) || defined(SIMULATOR)
530 #ifdef ROCKBOX_HAS_LOGF
536 #if CONFIG_CODEC == SWCODEC
545 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
546 peak_meter_scale_value
,
547 peak_meter_set_use_dbfs
,
548 peak_meter_get_use_dbfs
,
550 #ifdef HAVE_LCD_BITMAP
552 screen_dump_set_hook
,
559 #ifdef HAVE_WHEEL_POSITION
564 #ifdef IRIVER_H100_SERIES
565 /* Routines for the iriver_flash -plugin. */
566 detect_original_firmware
,
567 detect_flashed_ramimage
,
568 detect_flashed_romimage
,
571 #if (CONFIG_CODEC == SWCODEC)
584 buf_request_buffer_handle
,
591 tagcache_search_set_uniqbuf
,
592 tagcache_search_add_filter
,
595 tagcache_search_finish
,
600 search_albumart_files
,
603 /* new stuff at the end, sort into place next time
604 the API gets incompatible */
606 tagcache_get_numeric
,
612 int plugin_load(const char* plugin
, const void* parameter
)
615 struct plugin_header
*hdr
;
618 #else /* !SIMULATOR */
624 #endif /* !SIMULATOR */
627 fb_data
* old_backdrop
;
630 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
632 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
634 /* not allowing another plugin to load */
638 plugin_loaded
= false;
641 gui_syncsplash(0, ID2P(LANG_WAIT
));
642 strcpy(current_plugin
, plugin
);
645 hdr
= sim_plugin_load((char *)plugin
, &pd
);
647 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
651 || hdr
->magic
!= PLUGIN_MAGIC
652 || hdr
->target_id
!= TARGET_ID
) {
653 sim_plugin_close(pd
);
654 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
657 if (hdr
->api_version
> PLUGIN_API_VERSION
658 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
659 sim_plugin_close(pd
);
660 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
664 fd
= open(plugin
, O_RDONLY
);
666 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
670 /* Make sure COP cache is flushed and invalidated before loading */
671 my_core
= switch_core(CURRENT_CORE
^ 1);
673 switch_core(my_core
);
676 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
680 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
683 hdr
= (struct plugin_header
*)pluginbuf
;
685 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
686 || hdr
->magic
!= PLUGIN_MAGIC
687 || hdr
->target_id
!= TARGET_ID
688 || hdr
->load_addr
!= pluginbuf
689 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
690 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
693 if (hdr
->api_version
> PLUGIN_API_VERSION
694 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
695 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
698 plugin_size
= hdr
->end_addr
- pluginbuf
;
700 /* zero out bss area only, above guards end of pluginbuf */
701 if (plugin_size
> readsize
)
702 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
705 plugin_loaded
= true;
708 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
709 old_backdrop
= lcd_get_backdrop();
714 #ifdef HAVE_REMOTE_LCD
715 lcd_remote_clear_display();
721 rc
= hdr
->entry_point(&rockbox_api
, parameter
);
723 button_clear_queue();
725 #ifdef HAVE_LCD_BITMAP
727 lcd_set_backdrop(old_backdrop
);
728 #ifdef HAVE_LCD_COLOR
729 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
730 global_settings
.bg_color
);
732 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
734 #else /* LCD_DEPTH == 1 */
735 lcd_set_drawmode(DRMODE_SOLID
);
736 #endif /* LCD_DEPTH */
737 #endif /* HAVE_LCD_BITMAP */
742 #ifdef HAVE_REMOTE_LCD
743 #if LCD_REMOTE_DEPTH > 1
744 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
745 LCD_REMOTE_DEFAULT_BG
);
747 lcd_remote_set_drawmode(DRMODE_SOLID
);
749 lcd_remote_clear_display();
757 if (pfn_tsr_exit
== NULL
)
758 plugin_loaded
= false;
760 sim_plugin_close(pd
);
766 case PLUGIN_USB_CONNECTED
:
767 return PLUGIN_USB_CONNECTED
;
770 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
776 /* Returns a pointer to the portion of the plugin buffer that is not already
777 being used. If no plugin is loaded, returns the entire plugin buffer */
778 void* plugin_get_buffer(size_t *buffer_size
)
784 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
787 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
788 buffer_pos
= plugin_size
;
792 *buffer_size
= PLUGIN_BUFFER_SIZE
;
796 return &pluginbuf
[buffer_pos
];
799 /* Returns a pointer to the mp3 buffer.
800 Playback gets stopped, to avoid conflicts.
801 Talk buffer is stolen as well.
803 void* plugin_get_audio_buffer(size_t *buffer_size
)
805 #if CONFIG_CODEC == SWCODEC
806 return audio_get_buffer(true, buffer_size
);
809 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
810 *buffer_size
= audiobufend
- audiobuf
;
815 #ifdef PLUGIN_USE_IRAM
816 /* Initializes plugin IRAM */
817 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
818 char *iedata
, size_t iedata_size
)
820 /* We need to stop audio playback in order to use codec IRAM */
822 memcpy(iramstart
, iramcopy
, iram_size
);
823 memset(iedata
, 0, iedata_size
);
824 memset(iramcopy
, 0, iram_size
);
826 /* writeback cleared iedata and iramcopy areas */
830 #endif /* PLUGIN_USE_IRAM */
832 /* The plugin wants to stay resident after leaving its main function, e.g.
833 runs from timer or own thread. The callback is registered to later
834 instruct it to free its resources before a new plugin gets loaded. */
835 void plugin_tsr(bool (*exit_callback
)(bool))
837 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
840 char *plugin_get_current_filename(void)
842 return current_plugin
;