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
,
131 #ifdef HAVE_LCD_INVERT
132 lcd_set_invert_display
,
133 #endif /* HAVE_LCD_INVERT */
146 backlight_set_timeout
,
147 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
148 backlight_set_brightness
,
149 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
152 backlight_set_timeout_plugged
,
157 #ifdef HAVE_REMOTE_LCD
159 lcd_remote_set_contrast
,
160 lcd_remote_clear_display
,
161 lcd_remote_setmargins
,
163 lcd_remote_puts_scroll
,
164 lcd_remote_stop_scroll
,
165 lcd_remote_set_drawmode
,
166 lcd_remote_get_drawmode
,
168 lcd_remote_getstringsize
,
169 lcd_remote_drawpixel
,
175 lcd_remote_mono_bitmap_part
,
176 lcd_remote_mono_bitmap
,
178 lcd_remote_puts_style
,
179 lcd_remote_puts_scroll_style
,
180 &lcd_remote_framebuffer
[0][0],
182 lcd_remote_update_rect
,
185 remote_backlight_off
,
186 remote_backlight_set_timeout
,
188 remote_backlight_set_timeout_plugged
,
190 #endif /* HAVE_REMOTE_LCD */
192 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
194 {&screens
[SCREEN_MAIN
]},
196 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
197 lcd_remote_set_foreground
,
198 lcd_remote_get_foreground
,
199 lcd_remote_set_background
,
200 lcd_remote_get_background
,
201 lcd_remote_bitmap_part
,
204 viewport_set_defaults
,
208 gui_synclist_set_nb_items
,
209 gui_synclist_set_icon_callback
,
210 gui_synclist_get_nb_items
,
211 gui_synclist_get_sel_pos
,
213 gui_synclist_select_item
,
214 gui_synclist_add_item
,
215 gui_synclist_del_item
,
216 gui_synclist_limit_scroll
,
217 gui_synclist_do_button
,
218 gui_synclist_set_title
,
224 #ifdef HAVE_BUTTON_DATA
229 #ifdef HAS_BUTTON_HOLD
236 #ifdef HAVE_BUTTON_LIGHT
237 buttonlight_set_timeout
,
240 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
241 buttonlight_set_brightness
,
242 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
243 #endif /* HAVE_BUTTON_LIGHT */
246 (open_func
)PREFIX(open
),
248 (read_func
)PREFIX(read
),
250 (creat_func
)PREFIX(creat
),
251 (write_func
)PREFIX(write
),
266 create_numbered_filename
,
281 default_event_handler
,
282 default_event_handler_ex
,
287 #if (CONFIG_CODEC == SWCODEC)
294 reset_poweroff_timer
,
299 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
300 #ifdef CPU_BOOST_LOGGING
305 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
306 #endif /* !SIMULATOR */
307 #ifdef HAVE_SCHEDULER_BOOSTCTRL
311 #ifdef CACHE_FUNCTIONS_AS_CALL
323 #if CONFIG_CODEC == SWCODEC
324 queue_enable_queue_send
,
339 /* special simulator hooks */
340 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
342 sim_lcd_ex_update_rect
,
346 /* strings and memory */
389 #if CONFIG_CODEC != SWCODEC
393 #if CONFIG_CODEC == SWCODEC
394 &audio_master_sampr_list
[0],
403 pcm_get_bytes_waiting
,
407 #ifdef HAVE_RECORDING
414 pcm_calculate_rec_peaks
,
415 audio_set_recording_gain
,
416 #endif /* HAVE_RECORDING */
417 #if INPUT_SRC_CAPS != 0
418 audio_set_output_source
,
419 audio_set_input_source
,
426 #endif /* CONFIG_CODEC == SWCODEC */
428 /* playback control */
441 audio_has_changed_track
,
443 audio_flush_and_reload_tracks
,
445 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
446 mpeg_get_last_header
,
448 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
449 (CONFIG_CODEC == SWCODEC)
453 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
454 /* MAS communication */
459 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
466 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
472 gui_syncstatusbar_draw
,
480 #ifdef HAVE_LCD_COLOR
484 /* action handling */
498 # if CONFIG_CHARGING == CHARGING_MONITOR
502 #ifdef HAVE_USB_POWER
517 plugin_get_audio_buffer
,
519 plugin_get_current_filename
,
520 #ifdef PLUGIN_USE_IRAM
523 #if defined(DEBUG) || defined(SIMULATOR)
526 #ifdef ROCKBOX_HAS_LOGF
532 #if CONFIG_CODEC == SWCODEC
541 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
542 peak_meter_scale_value
,
543 peak_meter_set_use_dbfs
,
544 peak_meter_get_use_dbfs
,
546 #ifdef HAVE_LCD_BITMAP
548 screen_dump_set_hook
,
555 #ifdef HAVE_WHEEL_POSITION
560 #ifdef IRIVER_H100_SERIES
561 /* Routines for the iriver_flash -plugin. */
562 detect_original_firmware
,
563 detect_flashed_ramimage
,
564 detect_flashed_romimage
,
567 #if (CONFIG_CODEC == SWCODEC)
580 buf_request_buffer_handle
,
587 tagcache_search_set_uniqbuf
,
588 tagcache_search_add_filter
,
591 tagcache_search_finish
,
596 search_albumart_files
,
599 /* new stuff at the end, sort into place next time
600 the API gets incompatible */
601 simplelist_info_init
,
602 simplelist_show_list
,
604 #ifdef HAVE_LCD_ENABLE
610 int plugin_load(const char* plugin
, const void* parameter
)
613 struct plugin_header
*hdr
;
616 #else /* !SIMULATOR */
622 #endif /* !SIMULATOR */
624 #ifdef HAVE_REMOTE_LCD
629 fb_data
* old_backdrop
;
632 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
634 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
636 /* not allowing another plugin to load */
640 plugin_loaded
= false;
643 gui_syncsplash(0, ID2P(LANG_WAIT
));
644 strcpy(current_plugin
, plugin
);
647 hdr
= sim_plugin_load((char *)plugin
, &pd
);
649 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
653 || hdr
->magic
!= PLUGIN_MAGIC
654 || hdr
->target_id
!= TARGET_ID
) {
655 sim_plugin_close(pd
);
656 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
659 if (hdr
->api_version
> PLUGIN_API_VERSION
660 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
661 sim_plugin_close(pd
);
662 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
666 fd
= open(plugin
, O_RDONLY
);
668 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
672 /* Make sure COP cache is flushed and invalidated before loading */
673 my_core
= switch_core(CURRENT_CORE
^ 1);
675 switch_core(my_core
);
678 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
682 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
685 hdr
= (struct plugin_header
*)pluginbuf
;
687 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
688 || hdr
->magic
!= PLUGIN_MAGIC
689 || hdr
->target_id
!= TARGET_ID
690 || hdr
->load_addr
!= pluginbuf
691 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
692 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
695 if (hdr
->api_version
> PLUGIN_API_VERSION
696 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
697 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
700 plugin_size
= hdr
->end_addr
- pluginbuf
;
702 /* zero out bss area only, above guards end of pluginbuf */
703 if (plugin_size
> readsize
)
704 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
707 plugin_loaded
= true;
709 xm
= lcd_getxmargin();
710 ym
= lcd_getymargin();
713 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
714 old_backdrop
= lcd_get_backdrop();
719 #ifdef HAVE_REMOTE_LCD
720 rxm
= lcd_remote_getxmargin();
721 rym
= lcd_remote_getymargin();
722 lcd_remote_setmargins(0, 0);
723 lcd_remote_clear_display();
729 rc
= hdr
->entry_point(&rockbox_api
, parameter
);
731 button_clear_queue();
733 #ifdef HAVE_LCD_BITMAP
735 lcd_set_backdrop(old_backdrop
);
736 #ifdef HAVE_LCD_COLOR
737 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
738 global_settings
.bg_color
);
740 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
742 #else /* LCD_DEPTH == 1 */
743 lcd_set_drawmode(DRMODE_SOLID
);
744 #endif /* LCD_DEPTH */
745 #endif /* HAVE_LCD_BITMAP */
747 /* restore margins */
748 lcd_setmargins(xm
,ym
);
752 #ifdef HAVE_REMOTE_LCD
753 #if LCD_REMOTE_DEPTH > 1
754 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
755 LCD_REMOTE_DEFAULT_BG
);
757 lcd_remote_set_drawmode(DRMODE_SOLID
);
759 lcd_remote_setmargins(rxm
, rym
);
760 lcd_remote_clear_display();
768 if (pfn_tsr_exit
== NULL
)
769 plugin_loaded
= false;
771 sim_plugin_close(pd
);
777 case PLUGIN_USB_CONNECTED
:
778 return PLUGIN_USB_CONNECTED
;
781 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
787 /* Returns a pointer to the portion of the plugin buffer that is not already
788 being used. If no plugin is loaded, returns the entire plugin buffer */
789 void* plugin_get_buffer(size_t *buffer_size
)
795 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
798 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
799 buffer_pos
= plugin_size
;
803 *buffer_size
= PLUGIN_BUFFER_SIZE
;
807 return &pluginbuf
[buffer_pos
];
810 /* Returns a pointer to the mp3 buffer.
811 Playback gets stopped, to avoid conflicts.
812 Talk buffer is stolen as well.
814 void* plugin_get_audio_buffer(size_t *buffer_size
)
816 #if CONFIG_CODEC == SWCODEC
817 return audio_get_buffer(true, buffer_size
);
820 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
821 *buffer_size
= audiobufend
- audiobuf
;
826 #ifdef PLUGIN_USE_IRAM
827 /* Initializes plugin IRAM */
828 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
829 char *iedata
, size_t iedata_size
)
831 /* We need to stop audio playback in order to use codec IRAM */
833 memcpy(iramstart
, iramcopy
, iram_size
);
834 memset(iedata
, 0, iedata_size
);
835 memset(iramcopy
, 0, iram_size
);
837 /* writeback cleared iedata and iramcopy areas */
841 #endif /* PLUGIN_USE_IRAM */
843 /* The plugin wants to stay resident after leaving its main function, e.g.
844 runs from timer or own thread. The callback is registered to later
845 instruct it to free its resources before a new plugin gets loaded. */
846 void plugin_tsr(bool (*exit_callback
)(bool))
848 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
851 char *plugin_get_current_filename(void)
853 return current_plugin
;