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
,
163 #ifdef HAVE_REMOTE_LCD
165 lcd_remote_set_contrast
,
166 lcd_remote_clear_display
,
168 lcd_remote_puts_scroll
,
169 lcd_remote_stop_scroll
,
170 lcd_remote_set_drawmode
,
171 lcd_remote_get_drawmode
,
173 lcd_remote_getstringsize
,
174 lcd_remote_drawpixel
,
180 lcd_remote_mono_bitmap_part
,
181 lcd_remote_mono_bitmap
,
183 lcd_remote_puts_style
,
184 lcd_remote_puts_scroll_style
,
185 &lcd_remote_framebuffer
[0][0],
187 lcd_remote_update_rect
,
190 remote_backlight_off
,
191 remote_backlight_set_timeout
,
193 remote_backlight_set_timeout_plugged
,
195 #endif /* HAVE_REMOTE_LCD */
197 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
199 {&screens
[SCREEN_MAIN
]},
201 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
202 lcd_remote_set_foreground
,
203 lcd_remote_get_foreground
,
204 lcd_remote_set_background
,
205 lcd_remote_get_background
,
206 lcd_remote_bitmap_part
,
209 viewport_set_defaults
,
213 gui_synclist_set_nb_items
,
214 gui_synclist_set_icon_callback
,
215 gui_synclist_get_nb_items
,
216 gui_synclist_get_sel_pos
,
218 gui_synclist_select_item
,
219 gui_synclist_add_item
,
220 gui_synclist_del_item
,
221 gui_synclist_limit_scroll
,
222 gui_synclist_do_button
,
223 gui_synclist_set_title
,
225 simplelist_info_init
,
226 simplelist_show_list
,
232 #ifdef HAVE_BUTTON_DATA
237 #ifdef HAS_BUTTON_HOLD
240 #ifdef HAVE_TOUCHSCREEN
241 touchscreen_set_mode
,
244 #ifdef HAVE_BUTTON_LIGHT
245 buttonlight_set_timeout
,
248 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
249 buttonlight_set_brightness
,
250 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
251 #endif /* HAVE_BUTTON_LIGHT */
254 (open_func
)PREFIX(open
),
256 (read_func
)PREFIX(read
),
258 (creat_func
)PREFIX(creat
),
259 (write_func
)PREFIX(write
),
270 #if USING_ATA_CALLBACK
271 register_ata_idle_func
,
272 unregister_ata_idle_func
,
273 #endif /* USING_ATA_CALLBACK */
275 create_numbered_filename
,
290 default_event_handler
,
291 default_event_handler_ex
,
296 #if (CONFIG_CODEC == SWCODEC)
303 reset_poweroff_timer
,
308 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
309 #ifdef CPU_BOOST_LOGGING
314 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
315 #endif /* !SIMULATOR */
316 #ifdef HAVE_SCHEDULER_BOOSTCTRL
320 #ifdef CACHE_FUNCTIONS_AS_CALL
332 #if CONFIG_CODEC == SWCODEC
333 queue_enable_queue_send
,
343 __cyg_profile_func_enter
,
344 __cyg_profile_func_exit
,
348 /* special simulator hooks */
349 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
351 sim_lcd_ex_update_rect
,
355 /* strings and memory */
398 #if CONFIG_CODEC != SWCODEC
402 #if CONFIG_CODEC == SWCODEC
403 &audio_master_sampr_list
[0],
412 pcm_get_bytes_waiting
,
416 #ifdef HAVE_RECORDING
423 pcm_calculate_rec_peaks
,
424 audio_set_recording_gain
,
425 #endif /* HAVE_RECORDING */
426 #if INPUT_SRC_CAPS != 0
427 audio_set_output_source
,
428 audio_set_input_source
,
435 #endif /* CONFIG_CODEC == SWCODEC */
437 /* playback control */
450 audio_has_changed_track
,
452 audio_flush_and_reload_tracks
,
454 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
455 mpeg_get_last_header
,
457 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
458 (CONFIG_CODEC == SWCODEC)
462 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
463 /* MAS communication */
468 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
475 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
481 gui_syncstatusbar_draw
,
489 #ifdef HAVE_LCD_COLOR
493 /* action handling */
507 # if CONFIG_CHARGING == CHARGING_MONITOR
511 #ifdef HAVE_USB_POWER
526 plugin_get_audio_buffer
,
528 plugin_get_current_filename
,
529 #ifdef PLUGIN_USE_IRAM
532 #if defined(DEBUG) || defined(SIMULATOR)
535 #ifdef ROCKBOX_HAS_LOGF
541 #if CONFIG_CODEC == SWCODEC
550 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
551 peak_meter_scale_value
,
552 peak_meter_set_use_dbfs
,
553 peak_meter_get_use_dbfs
,
555 #ifdef HAVE_LCD_BITMAP
557 screen_dump_set_hook
,
564 #ifdef HAVE_WHEEL_POSITION
569 #ifdef IRIVER_H100_SERIES
570 /* Routines for the iriver_flash -plugin. */
571 detect_original_firmware
,
572 detect_flashed_ramimage
,
573 detect_flashed_romimage
,
576 #if (CONFIG_CODEC == SWCODEC)
589 buf_request_buffer_handle
,
596 tagcache_search_set_uniqbuf
,
597 tagcache_search_add_filter
,
600 tagcache_search_finish
,
601 tagcache_get_numeric
,
606 search_albumart_files
,
611 #if (CONFIG_CODEC == SWCODEC)
619 /* new stuff at the end, sort into place next time
620 the API gets incompatible */
624 int plugin_load(const char* plugin
, const void* parameter
)
627 struct plugin_header
*hdr
;
630 #else /* !SIMULATOR */
636 #endif /* !SIMULATOR */
639 fb_data
* old_backdrop
;
642 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
644 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
646 /* not allowing another plugin to load */
650 plugin_loaded
= false;
653 splash(0, ID2P(LANG_WAIT
));
654 strcpy(current_plugin
, plugin
);
657 hdr
= sim_plugin_load((char *)plugin
, &pd
);
659 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
663 || hdr
->magic
!= PLUGIN_MAGIC
664 || hdr
->target_id
!= TARGET_ID
) {
665 sim_plugin_close(pd
);
666 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
669 if (hdr
->api_version
> PLUGIN_API_VERSION
670 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
671 sim_plugin_close(pd
);
672 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
676 fd
= open(plugin
, O_RDONLY
);
678 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
682 /* Make sure COP cache is flushed and invalidated before loading */
683 my_core
= switch_core(CURRENT_CORE
^ 1);
685 switch_core(my_core
);
688 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
692 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
695 hdr
= (struct plugin_header
*)pluginbuf
;
697 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
698 || hdr
->magic
!= PLUGIN_MAGIC
699 || hdr
->target_id
!= TARGET_ID
700 || hdr
->load_addr
!= pluginbuf
701 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
702 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
705 if (hdr
->api_version
> PLUGIN_API_VERSION
706 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
707 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
710 plugin_size
= hdr
->end_addr
- pluginbuf
;
712 /* zero out bss area only, above guards end of pluginbuf */
713 if (plugin_size
> readsize
)
714 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
717 plugin_loaded
= true;
720 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
721 old_backdrop
= lcd_get_backdrop();
726 #ifdef HAVE_REMOTE_LCD
727 lcd_remote_clear_display();
733 rc
= hdr
->entry_point(&rockbox_api
, parameter
);
735 button_clear_queue();
737 #ifdef HAVE_LCD_BITMAP
739 lcd_set_backdrop(old_backdrop
);
740 #ifdef HAVE_LCD_COLOR
741 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
742 global_settings
.bg_color
);
744 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
746 #else /* LCD_DEPTH == 1 */
747 lcd_set_drawmode(DRMODE_SOLID
);
748 #endif /* LCD_DEPTH */
749 #endif /* HAVE_LCD_BITMAP */
754 #ifdef HAVE_REMOTE_LCD
755 #if LCD_REMOTE_DEPTH > 1
756 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
757 LCD_REMOTE_DEFAULT_BG
);
759 lcd_remote_set_drawmode(DRMODE_SOLID
);
761 lcd_remote_clear_display();
769 if (pfn_tsr_exit
== NULL
)
770 plugin_loaded
= false;
772 sim_plugin_close(pd
);
778 case PLUGIN_USB_CONNECTED
:
779 return PLUGIN_USB_CONNECTED
;
782 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
788 /* Returns a pointer to the portion of the plugin buffer that is not already
789 being used. If no plugin is loaded, returns the entire plugin buffer */
790 void* plugin_get_buffer(size_t *buffer_size
)
796 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
799 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
800 buffer_pos
= plugin_size
;
804 *buffer_size
= PLUGIN_BUFFER_SIZE
;
808 return &pluginbuf
[buffer_pos
];
811 /* Returns a pointer to the mp3 buffer.
812 Playback gets stopped, to avoid conflicts.
813 Talk buffer is stolen as well.
815 void* plugin_get_audio_buffer(size_t *buffer_size
)
817 #if CONFIG_CODEC == SWCODEC
818 return audio_get_buffer(true, buffer_size
);
821 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
822 *buffer_size
= audiobufend
- audiobuf
;
827 #ifdef PLUGIN_USE_IRAM
828 /* Initializes plugin IRAM */
829 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
830 char *iedata
, size_t iedata_size
)
832 /* We need to stop audio playback in order to use codec IRAM */
834 memcpy(iramstart
, iramcopy
, iram_size
);
835 memset(iedata
, 0, iedata_size
);
836 memset(iramcopy
, 0, iram_size
);
838 /* writeback cleared iedata and iramcopy areas */
842 #endif /* PLUGIN_USE_IRAM */
844 /* The plugin wants to stay resident after leaving its main function, e.g.
845 runs from timer or own thread. The callback is registered to later
846 instruct it to free its resources before a new plugin gets loaded. */
847 void plugin_tsr(bool (*exit_callback
)(bool))
849 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
852 char *plugin_get_current_filename(void)
854 return current_plugin
;