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
,
94 &lcd_framebuffer
[0][0],
105 lcd_mono_bitmap_part
,
118 lcd_bitmap_transparent_part
,
119 lcd_bitmap_transparent
,
121 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
122 || defined (IRIVER_H10)
125 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
128 #endif /* LCD_DEPTH */
130 lcd_puts_scroll_style
,
143 backlight_set_timeout
,
145 backlight_set_timeout_plugged
,
149 #ifdef HAVE_REMOTE_LCD
151 lcd_remote_set_contrast
,
152 lcd_remote_clear_display
,
153 lcd_remote_setmargins
,
155 lcd_remote_puts_scroll
,
156 lcd_remote_stop_scroll
,
157 lcd_remote_set_drawmode
,
158 lcd_remote_get_drawmode
,
160 lcd_remote_getstringsize
,
161 lcd_remote_drawpixel
,
167 lcd_remote_mono_bitmap_part
,
168 lcd_remote_mono_bitmap
,
170 lcd_remote_puts_style
,
171 lcd_remote_puts_scroll_style
,
172 &lcd_remote_framebuffer
[0][0],
174 lcd_remote_update_rect
,
177 remote_backlight_off
,
178 remote_backlight_set_timeout
,
180 remote_backlight_set_timeout_plugged
,
182 #endif /* HAVE_REMOTE_LCD */
184 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
186 {&screens
[SCREEN_MAIN
]},
188 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
189 lcd_remote_set_foreground
,
190 lcd_remote_get_foreground
,
191 lcd_remote_set_background
,
192 lcd_remote_get_background
,
193 lcd_remote_bitmap_part
,
196 viewport_set_defaults
,
200 gui_synclist_set_nb_items
,
201 gui_synclist_set_icon_callback
,
202 gui_synclist_get_nb_items
,
203 gui_synclist_get_sel_pos
,
205 gui_synclist_select_item
,
206 gui_synclist_add_item
,
207 gui_synclist_del_item
,
208 gui_synclist_limit_scroll
,
209 gui_synclist_do_button
,
210 gui_synclist_set_title
,
218 #ifdef HAS_BUTTON_HOLD
223 (open_func
)PREFIX(open
),
225 (read_func
)PREFIX(read
),
227 (creat_func
)PREFIX(creat
),
228 (write_func
)PREFIX(write
),
243 create_numbered_filename
,
258 default_event_handler
,
259 default_event_handler_ex
,
264 #if (CONFIG_CODEC == SWCODEC)
271 reset_poweroff_timer
,
276 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
277 #ifdef CPU_BOOST_LOGGING
282 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
283 #endif /* !SIMULATOR */
284 #ifdef HAVE_SCHEDULER_BOOSTCTRL
288 #ifdef CACHE_FUNCTIONS_AS_CALL
300 #if CONFIG_CODEC == SWCODEC
301 queue_enable_queue_send
,
316 /* special simulator hooks */
317 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
319 sim_lcd_ex_update_rect
,
323 /* strings and memory */
366 #if CONFIG_CODEC != SWCODEC
370 #if CONFIG_CODEC == SWCODEC
371 &audio_master_sampr_list
[0],
380 pcm_get_bytes_waiting
,
384 #ifdef HAVE_RECORDING
391 pcm_calculate_rec_peaks
,
392 audio_set_recording_gain
,
393 #endif /* HAVE_RECORDING */
394 #if INPUT_SRC_CAPS != 0
395 audio_set_output_source
,
396 audio_set_input_source
,
403 #endif /* CONFIG_CODEC == SWCODEC */
405 /* playback control */
418 audio_has_changed_track
,
420 audio_flush_and_reload_tracks
,
422 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
423 mpeg_get_last_header
,
425 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
426 (CONFIG_CODEC == SWCODEC)
430 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
431 /* MAS communication */
436 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
443 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
449 gui_syncstatusbar_draw
,
457 #ifdef HAVE_LCD_COLOR
461 /* action handling */
475 # if CONFIG_CHARGING == CHARGING_MONITOR
479 #ifdef HAVE_USB_POWER
494 plugin_get_audio_buffer
,
496 plugin_get_current_filename
,
497 #ifdef PLUGIN_USE_IRAM
500 #if defined(DEBUG) || defined(SIMULATOR)
503 #ifdef ROCKBOX_HAS_LOGF
509 #if CONFIG_CODEC == SWCODEC
518 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
519 peak_meter_scale_value
,
520 peak_meter_set_use_dbfs
,
521 peak_meter_get_use_dbfs
,
523 #ifdef HAVE_LCD_BITMAP
525 screen_dump_set_hook
,
532 #ifdef HAVE_WHEEL_POSITION
537 #ifdef IRIVER_H100_SERIES
538 /* Routines for the iriver_flash -plugin. */
539 detect_original_firmware
,
540 detect_flashed_ramimage
,
541 detect_flashed_romimage
,
544 #if (CONFIG_CODEC == SWCODEC)
557 buf_request_buffer_handle
,
564 tagcache_search_set_uniqbuf
,
565 tagcache_search_add_filter
,
568 tagcache_search_finish
,
573 search_albumart_files
,
576 /* new stuff at the end, sort into place next time
577 the API gets incompatible */
582 int plugin_load(const char* plugin
, void* parameter
)
585 struct plugin_header
*hdr
;
593 #ifdef HAVE_REMOTE_LCD
598 fb_data
* old_backdrop
;
601 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
603 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
605 /* not allowing another plugin to load */
609 plugin_loaded
= false;
612 gui_syncsplash(0, ID2P(LANG_WAIT
));
613 strcpy(current_plugin
, plugin
);
616 hdr
= sim_plugin_load((char *)plugin
, &pd
);
618 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
622 || hdr
->magic
!= PLUGIN_MAGIC
623 || hdr
->target_id
!= TARGET_ID
) {
624 sim_plugin_close(pd
);
625 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
628 if (hdr
->api_version
> PLUGIN_API_VERSION
629 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
630 sim_plugin_close(pd
);
631 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
635 fd
= open(plugin
, O_RDONLY
);
637 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
641 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
645 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
648 hdr
= (struct plugin_header
*)pluginbuf
;
650 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
651 || hdr
->magic
!= PLUGIN_MAGIC
652 || hdr
->target_id
!= TARGET_ID
653 || hdr
->load_addr
!= pluginbuf
654 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
655 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
658 if (hdr
->api_version
> PLUGIN_API_VERSION
659 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
660 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
663 plugin_size
= hdr
->end_addr
- pluginbuf
;
665 /* zero out bss area only, above guards end of pluginbuf */
666 if (plugin_size
> readsize
)
667 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
670 plugin_loaded
= true;
672 xm
= lcd_getxmargin();
673 ym
= lcd_getymargin();
676 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
677 old_backdrop
= lcd_get_backdrop();
682 #ifdef HAVE_REMOTE_LCD
683 rxm
= lcd_remote_getxmargin();
684 rym
= lcd_remote_getymargin();
685 lcd_remote_setmargins(0, 0);
686 lcd_remote_clear_display();
692 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
693 /* explicitly casting the pointer here to avoid touching every plugin. */
695 button_clear_queue();
697 #ifdef HAVE_LCD_BITMAP
699 lcd_set_backdrop(old_backdrop
);
700 #ifdef HAVE_LCD_COLOR
701 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
702 global_settings
.bg_color
);
704 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
706 #else /* LCD_DEPTH == 1 */
707 lcd_set_drawmode(DRMODE_SOLID
);
708 #endif /* LCD_DEPTH */
709 #endif /* HAVE_LCD_BITMAP */
711 /* restore margins */
712 lcd_setmargins(xm
,ym
);
716 #ifdef HAVE_REMOTE_LCD
717 #if LCD_REMOTE_DEPTH > 1
718 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
719 LCD_REMOTE_DEFAULT_BG
);
721 lcd_remote_set_drawmode(DRMODE_SOLID
);
723 lcd_remote_setmargins(rxm
, rym
);
724 lcd_remote_clear_display();
732 if (pfn_tsr_exit
== NULL
)
733 plugin_loaded
= false;
735 sim_plugin_close(pd
);
741 case PLUGIN_USB_CONNECTED
:
742 return PLUGIN_USB_CONNECTED
;
745 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
751 /* Returns a pointer to the portion of the plugin buffer that is not already
752 being used. If no plugin is loaded, returns the entire plugin buffer */
753 void* plugin_get_buffer(size_t *buffer_size
)
759 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
762 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
763 buffer_pos
= plugin_size
;
767 *buffer_size
= PLUGIN_BUFFER_SIZE
;
771 return &pluginbuf
[buffer_pos
];
774 /* Returns a pointer to the mp3 buffer.
775 Playback gets stopped, to avoid conflicts.
776 Talk buffer is stolen as well.
778 void* plugin_get_audio_buffer(size_t *buffer_size
)
780 #if CONFIG_CODEC == SWCODEC
781 return audio_get_buffer(true, buffer_size
);
784 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
785 *buffer_size
= audiobufend
- audiobuf
;
790 #ifdef PLUGIN_USE_IRAM
791 /* Initializes plugin IRAM */
792 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
793 char *iedata
, size_t iedata_size
)
795 /* We need to stop audio playback in order to use codec IRAM */
797 memcpy(iramstart
, iramcopy
, iram_size
);
798 memset(iedata
, 0, iedata_size
);
799 memset(iramcopy
, 0, iram_size
);
801 /* writeback cleared iedata and iramcopy areas */
805 #endif /* PLUGIN_USE_IRAM */
807 /* The plugin wants to stay resident after leaving its main function, e.g.
808 runs from timer or own thread. The callback is registered to later
809 instruct it to free its resources before a new plugin gets loaded. */
810 void plugin_tsr(bool (*exit_callback
)(bool))
812 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
815 char *plugin_get_current_filename(void)
817 return current_plugin
;