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
,
146 backlight_set_timeout_plugged
,
151 #ifdef HAVE_REMOTE_LCD
153 lcd_remote_set_contrast
,
154 lcd_remote_clear_display
,
155 lcd_remote_setmargins
,
157 lcd_remote_puts_scroll
,
158 lcd_remote_stop_scroll
,
159 lcd_remote_set_drawmode
,
160 lcd_remote_get_drawmode
,
162 lcd_remote_getstringsize
,
163 lcd_remote_drawpixel
,
169 lcd_remote_mono_bitmap_part
,
170 lcd_remote_mono_bitmap
,
172 lcd_remote_puts_style
,
173 lcd_remote_puts_scroll_style
,
174 &lcd_remote_framebuffer
[0][0],
176 lcd_remote_update_rect
,
179 remote_backlight_off
,
180 remote_backlight_set_timeout
,
182 remote_backlight_set_timeout_plugged
,
184 #endif /* HAVE_REMOTE_LCD */
186 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
188 {&screens
[SCREEN_MAIN
]},
190 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
191 lcd_remote_set_foreground
,
192 lcd_remote_get_foreground
,
193 lcd_remote_set_background
,
194 lcd_remote_get_background
,
195 lcd_remote_bitmap_part
,
198 viewport_set_defaults
,
202 gui_synclist_set_nb_items
,
203 gui_synclist_set_icon_callback
,
204 gui_synclist_get_nb_items
,
205 gui_synclist_get_sel_pos
,
207 gui_synclist_select_item
,
208 gui_synclist_add_item
,
209 gui_synclist_del_item
,
210 gui_synclist_limit_scroll
,
211 gui_synclist_do_button
,
212 gui_synclist_set_title
,
220 #ifdef HAS_BUTTON_HOLD
225 (open_func
)PREFIX(open
),
227 (read_func
)PREFIX(read
),
229 (creat_func
)PREFIX(creat
),
230 (write_func
)PREFIX(write
),
245 create_numbered_filename
,
260 default_event_handler
,
261 default_event_handler_ex
,
266 #if (CONFIG_CODEC == SWCODEC)
273 reset_poweroff_timer
,
278 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
279 #ifdef CPU_BOOST_LOGGING
284 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
285 #endif /* !SIMULATOR */
286 #ifdef HAVE_SCHEDULER_BOOSTCTRL
290 #ifdef CACHE_FUNCTIONS_AS_CALL
302 #if CONFIG_CODEC == SWCODEC
303 queue_enable_queue_send
,
318 /* special simulator hooks */
319 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
321 sim_lcd_ex_update_rect
,
325 /* strings and memory */
368 #if CONFIG_CODEC != SWCODEC
372 #if CONFIG_CODEC == SWCODEC
373 &audio_master_sampr_list
[0],
382 pcm_get_bytes_waiting
,
386 #ifdef HAVE_RECORDING
393 pcm_calculate_rec_peaks
,
394 audio_set_recording_gain
,
395 #endif /* HAVE_RECORDING */
396 #if INPUT_SRC_CAPS != 0
397 audio_set_output_source
,
398 audio_set_input_source
,
405 #endif /* CONFIG_CODEC == SWCODEC */
407 /* playback control */
420 audio_has_changed_track
,
422 audio_flush_and_reload_tracks
,
424 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
425 mpeg_get_last_header
,
427 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
428 (CONFIG_CODEC == SWCODEC)
432 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
433 /* MAS communication */
438 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
445 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
451 gui_syncstatusbar_draw
,
459 #ifdef HAVE_LCD_COLOR
463 /* action handling */
477 # if CONFIG_CHARGING == CHARGING_MONITOR
481 #ifdef HAVE_USB_POWER
496 plugin_get_audio_buffer
,
498 plugin_get_current_filename
,
499 #ifdef PLUGIN_USE_IRAM
502 #if defined(DEBUG) || defined(SIMULATOR)
505 #ifdef ROCKBOX_HAS_LOGF
511 #if CONFIG_CODEC == SWCODEC
520 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
521 peak_meter_scale_value
,
522 peak_meter_set_use_dbfs
,
523 peak_meter_get_use_dbfs
,
525 #ifdef HAVE_LCD_BITMAP
527 screen_dump_set_hook
,
534 #ifdef HAVE_WHEEL_POSITION
539 #ifdef IRIVER_H100_SERIES
540 /* Routines for the iriver_flash -plugin. */
541 detect_original_firmware
,
542 detect_flashed_ramimage
,
543 detect_flashed_romimage
,
546 #if (CONFIG_CODEC == SWCODEC)
559 buf_request_buffer_handle
,
566 tagcache_search_set_uniqbuf
,
567 tagcache_search_add_filter
,
570 tagcache_search_finish
,
575 search_albumart_files
,
578 /* new stuff at the end, sort into place next time
579 the API gets incompatible */
581 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
582 backlight_set_brightness
,
583 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
584 #ifdef HAVE_LCD_INVERT
585 lcd_set_invert_display
,
586 #endif /* HAVE_LCD_INVERT */
587 #ifdef HAVE_BUTTON_DATA
589 #endif /* HAVE_BUTTON_DATA */
592 #endif /* HAVE_TOUCHPAD */
593 #ifdef HAVE_BUTTON_LIGHT
594 buttonlight_set_timeout
,
597 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
598 buttonlight_set_brightness
,
599 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
600 #endif /* HAVE_BUTTON_LIGHT */
603 int plugin_load(const char* plugin
, void* parameter
)
606 struct plugin_header
*hdr
;
609 #else /* !SIMULATOR */
615 #endif /* !SIMULATOR */
617 #ifdef HAVE_REMOTE_LCD
622 fb_data
* old_backdrop
;
625 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
627 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
629 /* not allowing another plugin to load */
633 plugin_loaded
= false;
636 gui_syncsplash(0, ID2P(LANG_WAIT
));
637 strcpy(current_plugin
, plugin
);
640 hdr
= sim_plugin_load((char *)plugin
, &pd
);
642 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
646 || hdr
->magic
!= PLUGIN_MAGIC
647 || hdr
->target_id
!= TARGET_ID
) {
648 sim_plugin_close(pd
);
649 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
652 if (hdr
->api_version
> PLUGIN_API_VERSION
653 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
654 sim_plugin_close(pd
);
655 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
659 fd
= open(plugin
, O_RDONLY
);
661 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
665 /* Make sure COP cache is flushed and invalidated before loading */
666 my_core
= switch_core(CURRENT_CORE
^ 1);
668 switch_core(my_core
);
671 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
675 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
678 hdr
= (struct plugin_header
*)pluginbuf
;
680 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
681 || hdr
->magic
!= PLUGIN_MAGIC
682 || hdr
->target_id
!= TARGET_ID
683 || hdr
->load_addr
!= pluginbuf
684 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
685 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
688 if (hdr
->api_version
> PLUGIN_API_VERSION
689 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
690 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
693 plugin_size
= hdr
->end_addr
- pluginbuf
;
695 /* zero out bss area only, above guards end of pluginbuf */
696 if (plugin_size
> readsize
)
697 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
700 plugin_loaded
= true;
702 xm
= lcd_getxmargin();
703 ym
= lcd_getymargin();
706 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
707 old_backdrop
= lcd_get_backdrop();
712 #ifdef HAVE_REMOTE_LCD
713 rxm
= lcd_remote_getxmargin();
714 rym
= lcd_remote_getymargin();
715 lcd_remote_setmargins(0, 0);
716 lcd_remote_clear_display();
722 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
723 /* explicitly casting the pointer here to avoid touching every plugin. */
725 button_clear_queue();
727 #ifdef HAVE_LCD_BITMAP
729 lcd_set_backdrop(old_backdrop
);
730 #ifdef HAVE_LCD_COLOR
731 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
732 global_settings
.bg_color
);
734 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
736 #else /* LCD_DEPTH == 1 */
737 lcd_set_drawmode(DRMODE_SOLID
);
738 #endif /* LCD_DEPTH */
739 #endif /* HAVE_LCD_BITMAP */
741 /* restore margins */
742 lcd_setmargins(xm
,ym
);
746 #ifdef HAVE_REMOTE_LCD
747 #if LCD_REMOTE_DEPTH > 1
748 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
749 LCD_REMOTE_DEFAULT_BG
);
751 lcd_remote_set_drawmode(DRMODE_SOLID
);
753 lcd_remote_setmargins(rxm
, rym
);
754 lcd_remote_clear_display();
762 if (pfn_tsr_exit
== NULL
)
763 plugin_loaded
= false;
765 sim_plugin_close(pd
);
771 case PLUGIN_USB_CONNECTED
:
772 return PLUGIN_USB_CONNECTED
;
775 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
781 /* Returns a pointer to the portion of the plugin buffer that is not already
782 being used. If no plugin is loaded, returns the entire plugin buffer */
783 void* plugin_get_buffer(size_t *buffer_size
)
789 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
792 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
793 buffer_pos
= plugin_size
;
797 *buffer_size
= PLUGIN_BUFFER_SIZE
;
801 return &pluginbuf
[buffer_pos
];
804 /* Returns a pointer to the mp3 buffer.
805 Playback gets stopped, to avoid conflicts.
806 Talk buffer is stolen as well.
808 void* plugin_get_audio_buffer(size_t *buffer_size
)
810 #if CONFIG_CODEC == SWCODEC
811 return audio_get_buffer(true, buffer_size
);
814 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
815 *buffer_size
= audiobufend
- audiobuf
;
820 #ifdef PLUGIN_USE_IRAM
821 /* Initializes plugin IRAM */
822 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
823 char *iedata
, size_t iedata_size
)
825 /* We need to stop audio playback in order to use codec IRAM */
827 memcpy(iramstart
, iramcopy
, iram_size
);
828 memset(iedata
, 0, iedata_size
);
829 memset(iramcopy
, 0, iram_size
);
831 /* writeback cleared iedata and iramcopy areas */
835 #endif /* PLUGIN_USE_IRAM */
837 /* The plugin wants to stay resident after leaving its main function, e.g.
838 runs from timer or own thread. The callback is registered to later
839 instruct it to free its resources before a new plugin gets loaded. */
840 void plugin_tsr(bool (*exit_callback
)(bool))
842 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
845 char *plugin_get_current_filename(void)
847 return current_plugin
;