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"
46 #ifdef HAVE_LCD_BITMAP
47 #include "scrollbar.h"
48 #include "peakmeter.h"
54 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
55 void *sim_plugin_load(char *plugin
, void **pd
);
56 void sim_plugin_close(void *pd
);
57 void sim_lcd_ex_init(int shades
, unsigned long (*getpixel
)(int, int));
58 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
60 #define sim_plugin_close(x)
61 extern unsigned char pluginbuf
[];
65 /* for actual plugins only, not for codecs */
66 static bool plugin_loaded
= false;
67 static int plugin_size
= 0;
68 static bool (*pfn_tsr_exit
)(bool reenter
) = NULL
; /* TSR exit callback */
69 static char current_plugin
[MAX_PATH
];
71 char *plugin_get_current_filename(void);
73 extern struct thread_entry threads
[MAXTHREADS
];
75 static const struct plugin_api rockbox_api
= {
86 #ifdef HAVE_LCD_CHARCELLS
88 lcd_get_locked_pattern
,
96 &lcd_framebuffer
[0][0],
107 lcd_mono_bitmap_part
,
120 lcd_bitmap_transparent_part
,
121 lcd_bitmap_transparent
,
123 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
124 || defined(IRIVER_H10) || defined(COWON_D2)
127 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
130 #endif /* LCD_DEPTH */
132 lcd_puts_scroll_style
,
133 #ifdef HAVE_LCD_INVERT
134 lcd_set_invert_display
,
135 #endif /* HAVE_LCD_INVERT */
136 #ifdef HAVE_LCD_ENABLE
152 backlight_set_timeout
,
153 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
154 backlight_set_brightness
,
155 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
158 backlight_set_timeout_plugged
,
164 #ifdef HAVE_REMOTE_LCD
166 lcd_remote_set_contrast
,
167 lcd_remote_clear_display
,
169 lcd_remote_puts_scroll
,
170 lcd_remote_stop_scroll
,
171 lcd_remote_set_drawmode
,
172 lcd_remote_get_drawmode
,
174 lcd_remote_getstringsize
,
175 lcd_remote_drawpixel
,
181 lcd_remote_mono_bitmap_part
,
182 lcd_remote_mono_bitmap
,
184 lcd_remote_puts_style
,
185 lcd_remote_puts_scroll_style
,
186 &lcd_remote_framebuffer
[0][0],
188 lcd_remote_update_rect
,
191 remote_backlight_off
,
192 remote_backlight_set_timeout
,
194 remote_backlight_set_timeout_plugged
,
196 #endif /* HAVE_REMOTE_LCD */
198 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
200 {&screens
[SCREEN_MAIN
]},
202 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
203 lcd_remote_set_foreground
,
204 lcd_remote_get_foreground
,
205 lcd_remote_set_background
,
206 lcd_remote_get_background
,
207 lcd_remote_bitmap_part
,
210 viewport_set_defaults
,
214 gui_synclist_set_nb_items
,
215 gui_synclist_set_icon_callback
,
216 gui_synclist_get_nb_items
,
217 gui_synclist_get_sel_pos
,
219 gui_synclist_select_item
,
220 gui_synclist_add_item
,
221 gui_synclist_del_item
,
222 gui_synclist_limit_scroll
,
223 gui_synclist_do_button
,
224 gui_synclist_set_title
,
226 simplelist_info_init
,
227 simplelist_show_list
,
233 #ifdef HAVE_BUTTON_DATA
238 #ifdef HAS_BUTTON_HOLD
241 #ifdef HAVE_TOUCHSCREEN
242 touchscreen_set_mode
,
245 #ifdef HAVE_BUTTON_LIGHT
246 buttonlight_set_timeout
,
249 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
250 buttonlight_set_brightness
,
251 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
252 #endif /* HAVE_BUTTON_LIGHT */
255 (open_func
)PREFIX(open
),
257 (read_func
)PREFIX(read
),
259 (creat_func
)PREFIX(creat
),
260 (write_func
)PREFIX(write
),
271 #if USING_ATA_CALLBACK
272 register_ata_idle_func
,
273 unregister_ata_idle_func
,
274 #endif /* USING_ATA_CALLBACK */
276 create_numbered_filename
,
291 default_event_handler
,
292 default_event_handler_ex
,
297 #if (CONFIG_CODEC == SWCODEC)
304 reset_poweroff_timer
,
309 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
310 #ifdef CPU_BOOST_LOGGING
315 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
316 #endif /* !SIMULATOR */
317 #ifdef HAVE_SCHEDULER_BOOSTCTRL
321 #ifdef CACHE_FUNCTIONS_AS_CALL
333 #if CONFIG_CODEC == SWCODEC
334 queue_enable_queue_send
,
344 __cyg_profile_func_enter
,
345 __cyg_profile_func_exit
,
349 /* special simulator hooks */
350 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
352 sim_lcd_ex_update_rect
,
356 /* strings and memory */
399 #if CONFIG_CODEC != SWCODEC
403 #if CONFIG_CODEC == SWCODEC
404 &audio_master_sampr_list
[0],
413 pcm_get_bytes_waiting
,
417 #ifdef HAVE_RECORDING
424 pcm_calculate_rec_peaks
,
425 audio_set_recording_gain
,
426 #endif /* HAVE_RECORDING */
427 #if INPUT_SRC_CAPS != 0
428 audio_set_output_source
,
429 audio_set_input_source
,
436 #endif /* CONFIG_CODEC == SWCODEC */
438 /* playback control */
451 audio_has_changed_track
,
453 audio_flush_and_reload_tracks
,
455 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
456 mpeg_get_last_header
,
458 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
459 (CONFIG_CODEC == SWCODEC)
463 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
464 /* MAS communication */
469 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
476 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
482 gui_syncstatusbar_draw
,
490 #ifdef HAVE_LCD_COLOR
494 /* action handling */
508 # if CONFIG_CHARGING == CHARGING_MONITOR
512 #ifdef HAVE_USB_POWER
527 plugin_get_audio_buffer
,
529 plugin_get_current_filename
,
530 #ifdef PLUGIN_USE_IRAM
533 #if defined(DEBUG) || defined(SIMULATOR)
536 #ifdef ROCKBOX_HAS_LOGF
542 #if CONFIG_CODEC == SWCODEC
551 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
552 peak_meter_scale_value
,
553 peak_meter_set_use_dbfs
,
554 peak_meter_get_use_dbfs
,
556 #ifdef HAVE_LCD_BITMAP
558 screen_dump_set_hook
,
565 #ifdef HAVE_WHEEL_POSITION
570 #ifdef IRIVER_H100_SERIES
571 /* Routines for the iriver_flash -plugin. */
572 detect_original_firmware
,
573 detect_flashed_ramimage
,
574 detect_flashed_romimage
,
577 #if (CONFIG_CODEC == SWCODEC)
590 buf_request_buffer_handle
,
597 tagcache_search_set_uniqbuf
,
598 tagcache_search_add_filter
,
601 tagcache_search_finish
,
602 tagcache_get_numeric
,
607 search_albumart_files
,
612 #ifdef HAVE_SEMAPHORE_OBJECTS
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
;