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)
195 gui_synclist_set_nb_items
,
196 gui_synclist_set_icon_callback
,
197 gui_synclist_get_nb_items
,
198 gui_synclist_get_sel_pos
,
200 gui_synclist_select_item
,
201 gui_synclist_add_item
,
202 gui_synclist_del_item
,
203 gui_synclist_limit_scroll
,
204 gui_synclist_do_button
,
205 gui_synclist_set_title
,
213 #ifdef HAS_BUTTON_HOLD
218 (open_func
)PREFIX(open
),
220 (read_func
)PREFIX(read
),
222 (creat_func
)PREFIX(creat
),
223 (write_func
)PREFIX(write
),
237 create_numbered_filename
,
249 #ifdef HAVE_PRIORITY_SCHEDULING
253 default_event_handler
,
254 default_event_handler_ex
,
258 reset_poweroff_timer
,
263 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
264 #ifdef CPU_BOOST_LOGGING
288 /* special simulator hooks */
289 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
291 sim_lcd_ex_update_rect
,
295 /* strings and memory */
327 #if CONFIG_CODEC == SWCODEC
339 #if CONFIG_CODEC != SWCODEC
343 #if CONFIG_CODEC == SWCODEC
344 &audio_master_sampr_list
[0],
353 pcm_get_bytes_waiting
,
355 #ifdef HAVE_RECORDING
362 pcm_calculate_rec_peaks
,
363 audio_set_recording_gain
,
364 #endif /* HAVE_RECORDING */
365 #if INPUT_SRC_CAPS != 0
366 audio_set_output_source
,
367 audio_set_input_source
,
369 #endif /* CONFIG_CODEC == SWCODEC */
371 /* playback control */
384 audio_has_changed_track
,
386 audio_flush_and_reload_tracks
,
388 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
389 mpeg_get_last_header
,
391 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
392 (CONFIG_CODEC == SWCODEC)
396 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
397 /* MAS communication */
402 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
409 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
415 gui_syncstatusbar_draw
,
423 #ifdef HAVE_LCD_COLOR
427 /* action handling */
441 # if CONFIG_CHARGING == CHARGING_MONITOR
445 #ifdef HAVE_USB_POWER
460 plugin_get_audio_buffer
,
462 plugin_get_current_filename
,
463 #ifdef PLUGIN_USE_IRAM
466 #if defined(DEBUG) || defined(SIMULATOR)
469 #ifdef ROCKBOX_HAS_LOGF
475 #if CONFIG_CODEC == SWCODEC
484 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
485 peak_meter_scale_value
,
486 peak_meter_set_use_dbfs
,
487 peak_meter_get_use_dbfs
,
489 #ifdef HAVE_LCD_BITMAP
491 screen_dump_set_hook
,
498 #ifdef HAVE_WHEEL_POSITION
503 #ifdef IRIVER_H100_SERIES
504 /* Routines for the iriver_flash -plugin. */
505 detect_original_firmware
,
506 detect_flashed_ramimage
,
507 detect_flashed_romimage
,
510 #ifdef CACHE_FUNCTIONS_AS_CALL
514 /* new stuff at the end, sort into place next time
515 the API gets incompatible */
517 #if (CONFIG_CODEC == SWCODEC)
525 #if (CONFIG_CODEC == SWCODEC)
532 #ifdef HAVE_REMOTE_LCD
533 remote_backlight_set_timeout
,
535 remote_backlight_set_timeout_plugged
,
537 #endif /* HAVE_REMOTE_LCD */
539 #if (CONFIG_CODEC == SWCODEC)
552 buf_request_buffer_handle
,
559 tagcache_search_set_uniqbuf
,
560 tagcache_search_add_filter
,
563 tagcache_search_finish
,
568 search_albumart_files
,
571 #if CONFIG_CODEC == SWCODEC
574 queue_enable_queue_send
,
579 #ifndef HAVE_FLASH_STORAGE
582 #ifdef HAVE_SCHEDULER_BOOSTCTRL
588 #endif /* CONFIG_CODEC == SWCODEC */
591 int plugin_load(const char* plugin
, void* parameter
)
594 struct plugin_header
*hdr
;
602 #ifdef HAVE_REMOTE_LCD
607 fb_data
* old_backdrop
;
610 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
612 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
614 /* not allowing another plugin to load */
618 plugin_loaded
= false;
621 gui_syncsplash(0, ID2P(LANG_WAIT
));
622 strcpy(current_plugin
, plugin
);
625 hdr
= sim_plugin_load((char *)plugin
, &pd
);
627 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
631 || hdr
->magic
!= PLUGIN_MAGIC
632 || hdr
->target_id
!= TARGET_ID
) {
633 sim_plugin_close(pd
);
634 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
637 if (hdr
->api_version
> PLUGIN_API_VERSION
638 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
639 sim_plugin_close(pd
);
640 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
644 fd
= open(plugin
, O_RDONLY
);
646 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
650 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
654 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
657 hdr
= (struct plugin_header
*)pluginbuf
;
659 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
660 || hdr
->magic
!= PLUGIN_MAGIC
661 || hdr
->target_id
!= TARGET_ID
662 || hdr
->load_addr
!= pluginbuf
663 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
664 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
667 if (hdr
->api_version
> PLUGIN_API_VERSION
668 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
669 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
672 plugin_size
= hdr
->end_addr
- pluginbuf
;
674 /* zero out bss area only, above guards end of pluginbuf */
675 if (plugin_size
> readsize
)
676 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
679 plugin_loaded
= true;
681 xm
= lcd_getxmargin();
682 ym
= lcd_getymargin();
685 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
686 old_backdrop
= lcd_get_backdrop();
691 #ifdef HAVE_REMOTE_LCD
692 rxm
= lcd_remote_getxmargin();
693 rym
= lcd_remote_getymargin();
694 lcd_remote_setmargins(0, 0);
695 lcd_remote_clear_display();
701 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
702 /* explicitly casting the pointer here to avoid touching every plugin. */
704 button_clear_queue();
706 #ifdef HAVE_LCD_BITMAP
708 lcd_set_backdrop(old_backdrop
);
709 #ifdef HAVE_LCD_COLOR
710 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
711 global_settings
.bg_color
);
713 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
715 #else /* LCD_DEPTH == 1 */
716 lcd_set_drawmode(DRMODE_SOLID
);
717 #endif /* LCD_DEPTH */
718 #endif /* HAVE_LCD_BITMAP */
720 /* restore margins */
721 lcd_setmargins(xm
,ym
);
725 #ifdef HAVE_REMOTE_LCD
726 #if LCD_REMOTE_DEPTH > 1
727 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
728 LCD_REMOTE_DEFAULT_BG
);
730 lcd_remote_set_drawmode(DRMODE_SOLID
);
732 lcd_remote_setmargins(rxm
, rym
);
733 lcd_remote_clear_display();
741 if (pfn_tsr_exit
== NULL
)
742 plugin_loaded
= false;
744 sim_plugin_close(pd
);
750 case PLUGIN_USB_CONNECTED
:
751 return PLUGIN_USB_CONNECTED
;
754 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
760 /* Returns a pointer to the portion of the plugin buffer that is not already
761 being used. If no plugin is loaded, returns the entire plugin buffer */
762 void* plugin_get_buffer(size_t *buffer_size
)
768 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
771 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
772 buffer_pos
= plugin_size
;
776 *buffer_size
= PLUGIN_BUFFER_SIZE
;
780 return &pluginbuf
[buffer_pos
];
783 /* Returns a pointer to the mp3 buffer.
784 Playback gets stopped, to avoid conflicts.
785 Talk buffer is stolen as well.
787 void* plugin_get_audio_buffer(size_t *buffer_size
)
789 #if CONFIG_CODEC == SWCODEC
790 return audio_get_buffer(true, buffer_size
);
793 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
794 *buffer_size
= audiobufend
- audiobuf
;
799 #ifdef PLUGIN_USE_IRAM
800 /* Initializes plugin IRAM */
801 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
802 char *iedata
, size_t iedata_size
)
804 /* We need to stop audio playback in order to use codec IRAM */
806 memcpy(iramstart
, iramcopy
, iram_size
);
807 memset(iedata
, 0, iedata_size
);
808 memset(iramcopy
, 0, iram_size
);
810 /* writeback cleared iedata and iramcopy areas */
814 #endif /* PLUGIN_USE_IRAM */
816 /* The plugin wants to stay resident after leaving its main function, e.g.
817 runs from timer or own thread. The callback is registered to later
818 instruct it to free its resources before a new plugin gets loaded. */
819 void plugin_tsr(bool (*exit_callback
)(bool))
821 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
824 char *plugin_get_current_filename(void)
826 return current_plugin
;