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
,
609 /* new stuff at the end, sort into place next time
610 the API gets incompatible */
614 int plugin_load(const char* plugin
, const void* parameter
)
617 struct plugin_header
*hdr
;
620 #else /* !SIMULATOR */
626 #endif /* !SIMULATOR */
629 fb_data
* old_backdrop
;
632 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
634 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
636 /* not allowing another plugin to load */
640 plugin_loaded
= false;
643 splash(0, ID2P(LANG_WAIT
));
644 strcpy(current_plugin
, plugin
);
647 hdr
= sim_plugin_load((char *)plugin
, &pd
);
649 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
653 || hdr
->magic
!= PLUGIN_MAGIC
654 || hdr
->target_id
!= TARGET_ID
) {
655 sim_plugin_close(pd
);
656 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
659 if (hdr
->api_version
> PLUGIN_API_VERSION
660 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
661 sim_plugin_close(pd
);
662 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
666 fd
= open(plugin
, O_RDONLY
);
668 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
672 /* Make sure COP cache is flushed and invalidated before loading */
673 my_core
= switch_core(CURRENT_CORE
^ 1);
675 switch_core(my_core
);
678 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
682 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
685 hdr
= (struct plugin_header
*)pluginbuf
;
687 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
688 || hdr
->magic
!= PLUGIN_MAGIC
689 || hdr
->target_id
!= TARGET_ID
690 || hdr
->load_addr
!= pluginbuf
691 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
692 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
695 if (hdr
->api_version
> PLUGIN_API_VERSION
696 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
697 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
700 plugin_size
= hdr
->end_addr
- pluginbuf
;
702 /* zero out bss area only, above guards end of pluginbuf */
703 if (plugin_size
> readsize
)
704 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
707 plugin_loaded
= true;
710 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
711 old_backdrop
= lcd_get_backdrop();
716 #ifdef HAVE_REMOTE_LCD
717 lcd_remote_clear_display();
723 rc
= hdr
->entry_point(&rockbox_api
, parameter
);
725 button_clear_queue();
727 #ifdef HAVE_LCD_BITMAP
729 lcd_set_backdrop(old_backdrop
);
730 #ifdef HAVE_LCD_COLOR
731 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
732 global_settings
.bg_color
);
734 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
736 #else /* LCD_DEPTH == 1 */
737 lcd_set_drawmode(DRMODE_SOLID
);
738 #endif /* LCD_DEPTH */
739 #endif /* HAVE_LCD_BITMAP */
744 #ifdef HAVE_REMOTE_LCD
745 #if LCD_REMOTE_DEPTH > 1
746 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
747 LCD_REMOTE_DEFAULT_BG
);
749 lcd_remote_set_drawmode(DRMODE_SOLID
);
751 lcd_remote_clear_display();
759 if (pfn_tsr_exit
== NULL
)
760 plugin_loaded
= false;
762 sim_plugin_close(pd
);
768 case PLUGIN_USB_CONNECTED
:
769 return PLUGIN_USB_CONNECTED
;
772 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
778 /* Returns a pointer to the portion of the plugin buffer that is not already
779 being used. If no plugin is loaded, returns the entire plugin buffer */
780 void* plugin_get_buffer(size_t *buffer_size
)
786 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
789 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
790 buffer_pos
= plugin_size
;
794 *buffer_size
= PLUGIN_BUFFER_SIZE
;
798 return &pluginbuf
[buffer_pos
];
801 /* Returns a pointer to the mp3 buffer.
802 Playback gets stopped, to avoid conflicts.
803 Talk buffer is stolen as well.
805 void* plugin_get_audio_buffer(size_t *buffer_size
)
807 #if CONFIG_CODEC == SWCODEC
808 return audio_get_buffer(true, buffer_size
);
811 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
812 *buffer_size
= audiobufend
- audiobuf
;
817 #ifdef PLUGIN_USE_IRAM
818 /* Initializes plugin IRAM */
819 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
820 char *iedata
, size_t iedata_size
)
822 /* We need to stop audio playback in order to use codec IRAM */
824 memcpy(iramstart
, iramcopy
, iram_size
);
825 memset(iedata
, 0, iedata_size
);
826 memset(iramcopy
, 0, iram_size
);
828 /* writeback cleared iedata and iramcopy areas */
832 #endif /* PLUGIN_USE_IRAM */
834 /* The plugin wants to stay resident after leaving its main function, e.g.
835 runs from timer or own thread. The callback is registered to later
836 instruct it to free its resources before a new plugin gets loaded. */
837 void plugin_tsr(bool (*exit_callback
)(bool))
839 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
842 char *plugin_get_current_filename(void)
844 return current_plugin
;