1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
30 #include "backlight.h"
31 #include "sound_menu.h"
33 #include "powermgmt.h"
36 #include "option_select.h"
43 #ifdef HAVE_LCD_BITMAP
44 #include "scrollbar.h"
45 #include "peakmeter.h"
51 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
52 void *sim_plugin_load(char *plugin
, void **pd
);
53 void sim_plugin_close(void *pd
);
54 void sim_lcd_ex_init(int shades
, unsigned long (*getpixel
)(int, int));
55 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
57 #define sim_plugin_close(x)
58 extern unsigned char pluginbuf
[];
62 /* for actual plugins only, not for codecs */
63 static bool plugin_loaded
= false;
64 static int plugin_size
= 0;
65 static bool (*pfn_tsr_exit
)(bool reenter
) = NULL
; /* TSR exit callback */
66 static char current_plugin
[MAX_PATH
];
68 char *plugin_get_current_filename(void);
70 extern struct thread_entry threads
[MAXTHREADS
];
72 static const struct plugin_api rockbox_api
= {
84 #ifdef HAVE_LCD_CHARCELLS
86 lcd_get_locked_pattern
,
103 lcd_mono_bitmap_part
,
116 lcd_bitmap_transparent_part
,
117 lcd_bitmap_transparent
,
123 lcd_puts_scroll_style
,
124 &lcd_framebuffer
[0][0],
135 backlight_set_timeout
,
137 backlight_set_timeout_plugged
,
140 #ifdef HAVE_REMOTE_LCD
142 lcd_remote_set_contrast
,
143 lcd_remote_clear_display
,
144 lcd_remote_setmargins
,
146 lcd_remote_puts_scroll
,
147 lcd_remote_stop_scroll
,
148 lcd_remote_set_drawmode
,
149 lcd_remote_get_drawmode
,
151 lcd_remote_getstringsize
,
152 lcd_remote_drawpixel
,
158 lcd_remote_mono_bitmap_part
,
159 lcd_remote_mono_bitmap
,
161 lcd_remote_puts_style
,
162 lcd_remote_puts_scroll_style
,
163 &lcd_remote_framebuffer
[0][0],
165 lcd_remote_update_rect
,
168 remote_backlight_off
,
171 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
173 {&screens
[SCREEN_MAIN
]},
175 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
176 lcd_remote_set_foreground
,
177 lcd_remote_get_foreground
,
178 lcd_remote_set_background
,
179 lcd_remote_get_background
,
180 lcd_remote_bitmap_part
,
184 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && !defined(SIMULATOR)
187 #if defined(HAVE_LCD_COLOR)
190 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
191 || defined (IRIVER_H10)
196 gui_synclist_set_nb_items
,
197 gui_synclist_set_icon_callback
,
198 gui_synclist_get_nb_items
,
199 gui_synclist_get_sel_pos
,
201 gui_synclist_select_item
,
202 gui_synclist_add_item
,
203 gui_synclist_del_item
,
204 gui_synclist_limit_scroll
,
205 gui_synclist_do_button
,
206 gui_synclist_set_title
,
214 #ifdef HAS_BUTTON_HOLD
219 (open_func
)PREFIX(open
),
221 (read_func
)PREFIX(read
),
223 (creat_func
)PREFIX(creat
),
224 (write_func
)PREFIX(write
),
238 create_numbered_filename
,
250 #ifdef HAVE_PRIORITY_SCHEDULING
254 default_event_handler
,
255 default_event_handler_ex
,
259 reset_poweroff_timer
,
264 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
265 #ifdef CPU_BOOST_LOGGING
289 /* special simulator hooks */
290 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
292 sim_lcd_ex_update_rect
,
296 /* strings and memory */
328 #if CONFIG_CODEC == SWCODEC
340 #if CONFIG_CODEC != SWCODEC
344 #if CONFIG_CODEC == SWCODEC
345 &audio_master_sampr_list
[0],
354 pcm_get_bytes_waiting
,
356 #ifdef HAVE_RECORDING
363 pcm_calculate_rec_peaks
,
364 audio_set_recording_gain
,
365 #endif /* HAVE_RECORDING */
366 #if INPUT_SRC_CAPS != 0
367 audio_set_output_source
,
368 audio_set_input_source
,
370 #endif /* CONFIG_CODEC == SWCODEC */
372 /* playback control */
385 audio_has_changed_track
,
387 audio_flush_and_reload_tracks
,
389 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
390 mpeg_get_last_header
,
392 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
393 (CONFIG_CODEC == SWCODEC)
397 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
398 /* MAS communication */
403 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
410 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
416 gui_syncstatusbar_draw
,
424 #ifdef HAVE_LCD_COLOR
428 /* action handling */
442 # if CONFIG_CHARGING == CHARGING_MONITOR
446 #ifdef HAVE_USB_POWER
461 plugin_get_audio_buffer
,
463 plugin_get_current_filename
,
464 #ifdef PLUGIN_USE_IRAM
467 #if defined(DEBUG) || defined(SIMULATOR)
470 #ifdef ROCKBOX_HAS_LOGF
476 #if CONFIG_CODEC == SWCODEC
485 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
486 peak_meter_scale_value
,
487 peak_meter_set_use_dbfs
,
488 peak_meter_get_use_dbfs
,
490 #ifdef HAVE_LCD_BITMAP
492 screen_dump_set_hook
,
499 #ifdef HAVE_WHEEL_POSITION
504 #ifdef IRIVER_H100_SERIES
505 /* Routines for the iriver_flash -plugin. */
506 detect_original_firmware
,
507 detect_flashed_ramimage
,
508 detect_flashed_romimage
,
511 #ifdef CACHE_FUNCTIONS_AS_CALL
515 /* new stuff at the end, sort into place next time
516 the API gets incompatible */
518 #if (CONFIG_CODEC == SWCODEC)
526 #if (CONFIG_CODEC == SWCODEC)
533 #ifdef HAVE_REMOTE_LCD
534 remote_backlight_set_timeout
,
536 remote_backlight_set_timeout_plugged
,
538 #endif /* HAVE_REMOTE_LCD */
540 #if (CONFIG_CODEC == SWCODEC)
553 buf_request_buffer_handle
,
560 tagcache_search_set_uniqbuf
,
561 tagcache_search_add_filter
,
564 tagcache_search_finish
,
569 search_albumart_files
,
572 #if CONFIG_CODEC == SWCODEC
575 queue_enable_queue_send
,
580 #ifndef HAVE_FLASH_STORAGE
583 #ifdef HAVE_SCHEDULER_BOOSTCTRL
594 #endif /* CONFIG_CODEC == SWCODEC */
597 int plugin_load(const char* plugin
, void* parameter
)
600 struct plugin_header
*hdr
;
608 #ifdef HAVE_REMOTE_LCD
613 fb_data
* old_backdrop
;
616 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
618 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
620 /* not allowing another plugin to load */
624 plugin_loaded
= false;
627 gui_syncsplash(0, ID2P(LANG_WAIT
));
628 strcpy(current_plugin
, plugin
);
631 hdr
= sim_plugin_load((char *)plugin
, &pd
);
633 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
637 || hdr
->magic
!= PLUGIN_MAGIC
638 || hdr
->target_id
!= TARGET_ID
) {
639 sim_plugin_close(pd
);
640 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
643 if (hdr
->api_version
> PLUGIN_API_VERSION
644 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
645 sim_plugin_close(pd
);
646 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
650 fd
= open(plugin
, O_RDONLY
);
652 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
656 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
660 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
663 hdr
= (struct plugin_header
*)pluginbuf
;
665 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
666 || hdr
->magic
!= PLUGIN_MAGIC
667 || hdr
->target_id
!= TARGET_ID
668 || hdr
->load_addr
!= pluginbuf
669 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
670 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
673 if (hdr
->api_version
> PLUGIN_API_VERSION
674 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
675 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
678 plugin_size
= hdr
->end_addr
- pluginbuf
;
680 /* zero out bss area only, above guards end of pluginbuf */
681 if (plugin_size
> readsize
)
682 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
685 plugin_loaded
= true;
687 xm
= lcd_getxmargin();
688 ym
= lcd_getymargin();
691 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
692 old_backdrop
= lcd_get_backdrop();
697 #ifdef HAVE_REMOTE_LCD
698 rxm
= lcd_remote_getxmargin();
699 rym
= lcd_remote_getymargin();
700 lcd_remote_setmargins(0, 0);
701 lcd_remote_clear_display();
707 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
708 /* explicitly casting the pointer here to avoid touching every plugin. */
710 button_clear_queue();
712 #ifdef HAVE_LCD_BITMAP
714 lcd_set_backdrop(old_backdrop
);
715 #ifdef HAVE_LCD_COLOR
716 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
717 global_settings
.bg_color
);
719 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
721 #else /* LCD_DEPTH == 1 */
722 lcd_set_drawmode(DRMODE_SOLID
);
723 #endif /* LCD_DEPTH */
724 #endif /* HAVE_LCD_BITMAP */
726 /* restore margins */
727 lcd_setmargins(xm
,ym
);
731 #ifdef HAVE_REMOTE_LCD
732 #if LCD_REMOTE_DEPTH > 1
733 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
734 LCD_REMOTE_DEFAULT_BG
);
736 lcd_remote_set_drawmode(DRMODE_SOLID
);
738 lcd_remote_setmargins(rxm
, rym
);
739 lcd_remote_clear_display();
747 if (pfn_tsr_exit
== NULL
)
748 plugin_loaded
= false;
750 sim_plugin_close(pd
);
756 case PLUGIN_USB_CONNECTED
:
757 return PLUGIN_USB_CONNECTED
;
760 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
766 /* Returns a pointer to the portion of the plugin buffer that is not already
767 being used. If no plugin is loaded, returns the entire plugin buffer */
768 void* plugin_get_buffer(size_t *buffer_size
)
774 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
777 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
778 buffer_pos
= plugin_size
;
782 *buffer_size
= PLUGIN_BUFFER_SIZE
;
786 return &pluginbuf
[buffer_pos
];
789 /* Returns a pointer to the mp3 buffer.
790 Playback gets stopped, to avoid conflicts.
791 Talk buffer is stolen as well.
793 void* plugin_get_audio_buffer(size_t *buffer_size
)
795 #if CONFIG_CODEC == SWCODEC
796 return audio_get_buffer(true, buffer_size
);
799 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
800 *buffer_size
= audiobufend
- audiobuf
;
805 #ifdef PLUGIN_USE_IRAM
806 /* Initializes plugin IRAM */
807 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
808 char *iedata
, size_t iedata_size
)
810 /* We need to stop audio playback in order to use codec IRAM */
812 memcpy(iramstart
, iramcopy
, iram_size
);
813 memset(iedata
, 0, iedata_size
);
814 memset(iramcopy
, 0, iram_size
);
816 /* writeback cleared iedata and iramcopy areas */
820 #endif /* PLUGIN_USE_IRAM */
822 /* The plugin wants to stay resident after leaving its main function, e.g.
823 runs from timer or own thread. The callback is registered to later
824 instruct it to free its resources before a new plugin gets loaded. */
825 void plugin_tsr(bool (*exit_callback
)(bool))
827 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
830 char *plugin_get_current_filename(void)
832 return current_plugin
;