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
617 #ifdef HAVE_EVENT_OBJECTS
623 /* new stuff at the end, sort into place next time
624 the API gets incompatible */
628 int plugin_load(const char* plugin
, const void* parameter
)
631 struct plugin_header
*hdr
;
634 #else /* !SIMULATOR */
640 #endif /* !SIMULATOR */
643 fb_data
* old_backdrop
;
646 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
648 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
650 /* not allowing another plugin to load */
654 plugin_loaded
= false;
657 splash(0, ID2P(LANG_WAIT
));
658 strcpy(current_plugin
, plugin
);
661 hdr
= sim_plugin_load((char *)plugin
, &pd
);
663 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
667 || hdr
->magic
!= PLUGIN_MAGIC
668 || hdr
->target_id
!= TARGET_ID
) {
669 sim_plugin_close(pd
);
670 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
673 if (hdr
->api_version
> PLUGIN_API_VERSION
674 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
675 sim_plugin_close(pd
);
676 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
680 fd
= open(plugin
, O_RDONLY
);
682 splashf(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
686 /* Make sure COP cache is flushed and invalidated before loading */
687 my_core
= switch_core(CURRENT_CORE
^ 1);
689 switch_core(my_core
);
692 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
696 splashf(HZ
*2, str(LANG_READ_FAILED
), plugin
);
699 hdr
= (struct plugin_header
*)pluginbuf
;
701 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
702 || hdr
->magic
!= PLUGIN_MAGIC
703 || hdr
->target_id
!= TARGET_ID
704 || hdr
->load_addr
!= pluginbuf
705 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
706 splash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
709 if (hdr
->api_version
> PLUGIN_API_VERSION
710 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
711 splash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
714 plugin_size
= hdr
->end_addr
- pluginbuf
;
716 /* zero out bss area only, above guards end of pluginbuf */
717 if (plugin_size
> readsize
)
718 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
721 plugin_loaded
= true;
724 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
725 old_backdrop
= lcd_get_backdrop();
730 #ifdef HAVE_REMOTE_LCD
731 lcd_remote_clear_display();
737 rc
= hdr
->entry_point(&rockbox_api
, parameter
);
739 button_clear_queue();
741 #ifdef HAVE_LCD_BITMAP
743 lcd_set_backdrop(old_backdrop
);
744 #ifdef HAVE_LCD_COLOR
745 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
746 global_settings
.bg_color
);
748 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
750 #else /* LCD_DEPTH == 1 */
751 lcd_set_drawmode(DRMODE_SOLID
);
752 #endif /* LCD_DEPTH */
753 #endif /* HAVE_LCD_BITMAP */
758 #ifdef HAVE_REMOTE_LCD
759 #if LCD_REMOTE_DEPTH > 1
760 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
761 LCD_REMOTE_DEFAULT_BG
);
763 lcd_remote_set_drawmode(DRMODE_SOLID
);
765 lcd_remote_clear_display();
773 if (pfn_tsr_exit
== NULL
)
774 plugin_loaded
= false;
776 sim_plugin_close(pd
);
782 case PLUGIN_USB_CONNECTED
:
783 return PLUGIN_USB_CONNECTED
;
786 splash(HZ
*2, str(LANG_PLUGIN_ERROR
));
792 /* Returns a pointer to the portion of the plugin buffer that is not already
793 being used. If no plugin is loaded, returns the entire plugin buffer */
794 void* plugin_get_buffer(size_t *buffer_size
)
800 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
803 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
804 buffer_pos
= plugin_size
;
808 *buffer_size
= PLUGIN_BUFFER_SIZE
;
812 return &pluginbuf
[buffer_pos
];
815 /* Returns a pointer to the mp3 buffer.
816 Playback gets stopped, to avoid conflicts.
817 Talk buffer is stolen as well.
819 void* plugin_get_audio_buffer(size_t *buffer_size
)
821 #if CONFIG_CODEC == SWCODEC
822 return audio_get_buffer(true, buffer_size
);
825 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
826 *buffer_size
= audiobufend
- audiobuf
;
831 #ifdef PLUGIN_USE_IRAM
832 /* Initializes plugin IRAM */
833 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
834 char *iedata
, size_t iedata_size
)
836 /* We need to stop audio playback in order to use codec IRAM */
838 memcpy(iramstart
, iramcopy
, iram_size
);
839 memset(iedata
, 0, iedata_size
);
840 memset(iramcopy
, 0, iram_size
);
842 /* writeback cleared iedata and iramcopy areas */
846 #endif /* PLUGIN_USE_IRAM */
848 /* The plugin wants to stay resident after leaving its main function, e.g.
849 runs from timer or own thread. The callback is registered to later
850 instruct it to free its resources before a new plugin gets loaded. */
851 void plugin_tsr(bool (*exit_callback
)(bool))
853 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
856 char *plugin_get_current_filename(void)
858 return current_plugin
;