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 */
581 int plugin_load(const char* plugin
, void* parameter
)
584 struct plugin_header
*hdr
;
592 #ifdef HAVE_REMOTE_LCD
597 fb_data
* old_backdrop
;
600 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
602 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
604 /* not allowing another plugin to load */
608 plugin_loaded
= false;
611 gui_syncsplash(0, ID2P(LANG_WAIT
));
612 strcpy(current_plugin
, plugin
);
615 hdr
= sim_plugin_load((char *)plugin
, &pd
);
617 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
621 || hdr
->magic
!= PLUGIN_MAGIC
622 || hdr
->target_id
!= TARGET_ID
) {
623 sim_plugin_close(pd
);
624 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
627 if (hdr
->api_version
> PLUGIN_API_VERSION
628 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
629 sim_plugin_close(pd
);
630 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
634 fd
= open(plugin
, O_RDONLY
);
636 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
640 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
644 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
647 hdr
= (struct plugin_header
*)pluginbuf
;
649 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
650 || hdr
->magic
!= PLUGIN_MAGIC
651 || hdr
->target_id
!= TARGET_ID
652 || hdr
->load_addr
!= pluginbuf
653 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
654 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
657 if (hdr
->api_version
> PLUGIN_API_VERSION
658 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
659 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
662 plugin_size
= hdr
->end_addr
- pluginbuf
;
664 /* zero out bss area only, above guards end of pluginbuf */
665 if (plugin_size
> readsize
)
666 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
669 plugin_loaded
= true;
671 xm
= lcd_getxmargin();
672 ym
= lcd_getymargin();
675 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
676 old_backdrop
= lcd_get_backdrop();
681 #ifdef HAVE_REMOTE_LCD
682 rxm
= lcd_remote_getxmargin();
683 rym
= lcd_remote_getymargin();
684 lcd_remote_setmargins(0, 0);
685 lcd_remote_clear_display();
691 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
692 /* explicitly casting the pointer here to avoid touching every plugin. */
694 button_clear_queue();
696 #ifdef HAVE_LCD_BITMAP
698 lcd_set_backdrop(old_backdrop
);
699 #ifdef HAVE_LCD_COLOR
700 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
701 global_settings
.bg_color
);
703 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
705 #else /* LCD_DEPTH == 1 */
706 lcd_set_drawmode(DRMODE_SOLID
);
707 #endif /* LCD_DEPTH */
708 #endif /* HAVE_LCD_BITMAP */
710 /* restore margins */
711 lcd_setmargins(xm
,ym
);
715 #ifdef HAVE_REMOTE_LCD
716 #if LCD_REMOTE_DEPTH > 1
717 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
718 LCD_REMOTE_DEFAULT_BG
);
720 lcd_remote_set_drawmode(DRMODE_SOLID
);
722 lcd_remote_setmargins(rxm
, rym
);
723 lcd_remote_clear_display();
731 if (pfn_tsr_exit
== NULL
)
732 plugin_loaded
= false;
734 sim_plugin_close(pd
);
740 case PLUGIN_USB_CONNECTED
:
741 return PLUGIN_USB_CONNECTED
;
744 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
750 /* Returns a pointer to the portion of the plugin buffer that is not already
751 being used. If no plugin is loaded, returns the entire plugin buffer */
752 void* plugin_get_buffer(size_t *buffer_size
)
758 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
761 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
762 buffer_pos
= plugin_size
;
766 *buffer_size
= PLUGIN_BUFFER_SIZE
;
770 return &pluginbuf
[buffer_pos
];
773 /* Returns a pointer to the mp3 buffer.
774 Playback gets stopped, to avoid conflicts.
775 Talk buffer is stolen as well.
777 void* plugin_get_audio_buffer(size_t *buffer_size
)
779 #if CONFIG_CODEC == SWCODEC
780 return audio_get_buffer(true, buffer_size
);
783 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
784 *buffer_size
= audiobufend
- audiobuf
;
789 #ifdef PLUGIN_USE_IRAM
790 /* Initializes plugin IRAM */
791 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
792 char *iedata
, size_t iedata_size
)
794 /* We need to stop audio playback in order to use codec IRAM */
796 memcpy(iramstart
, iramcopy
, iram_size
);
797 memset(iedata
, 0, iedata_size
);
798 memset(iramcopy
, 0, iram_size
);
800 /* writeback cleared iedata and iramcopy areas */
804 #endif /* PLUGIN_USE_IRAM */
806 /* The plugin wants to stay resident after leaving its main function, e.g.
807 runs from timer or own thread. The callback is registered to later
808 instruct it to free its resources before a new plugin gets loaded. */
809 void plugin_tsr(bool (*exit_callback
)(bool))
811 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
814 char *plugin_get_current_filename(void)
816 return current_plugin
;