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
,
145 lcd_remote_puts_scroll
,
146 lcd_remote_stop_scroll
,
147 lcd_remote_set_drawmode
,
148 lcd_remote_get_drawmode
,
150 lcd_remote_getstringsize
,
151 lcd_remote_drawpixel
,
157 lcd_remote_mono_bitmap_part
,
158 lcd_remote_mono_bitmap
,
160 lcd_remote_puts_style
,
161 lcd_remote_puts_scroll_style
,
162 &lcd_remote_framebuffer
[0][0],
164 lcd_remote_update_rect
,
167 remote_backlight_off
,
170 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
172 {&screens
[SCREEN_MAIN
]},
174 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
175 lcd_remote_set_foreground
,
176 lcd_remote_get_foreground
,
177 lcd_remote_set_background
,
178 lcd_remote_get_background
,
179 lcd_remote_bitmap_part
,
183 #if defined(HAVE_LCD_COLOR)
188 gui_synclist_set_nb_items
,
189 gui_synclist_set_icon_callback
,
190 gui_synclist_get_nb_items
,
191 gui_synclist_get_sel_pos
,
193 gui_synclist_select_item
,
194 gui_synclist_add_item
,
195 gui_synclist_del_item
,
196 gui_synclist_limit_scroll
,
198 gui_synclist_do_button
,
199 gui_synclist_set_title
,
206 #ifdef HAS_BUTTON_HOLD
211 (open_func
)PREFIX(open
),
213 (read_func
)PREFIX(read
),
215 (creat_func
)PREFIX(creat
),
216 (write_func
)PREFIX(write
),
230 create_numbered_filename
,
242 #ifdef HAVE_PRIORITY_SCHEDULING
246 default_event_handler
,
247 default_event_handler_ex
,
251 reset_poweroff_timer
,
256 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
257 #ifdef CPU_BOOST_LOGGING
281 /* special simulator hooks */
282 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
284 sim_lcd_ex_update_rect
,
288 /* strings and memory */
320 #if CONFIG_CODEC == SWCODEC
332 #if CONFIG_CODEC != SWCODEC
336 #if CONFIG_CODEC == SWCODEC
337 &audio_master_sampr_list
[0],
346 pcm_get_bytes_waiting
,
348 #ifdef HAVE_RECORDING
355 pcm_calculate_rec_peaks
,
356 audio_set_recording_gain
,
357 #endif /* HAVE_RECORDING */
358 #if INPUT_SRC_CAPS != 0
359 audio_set_output_source
,
360 audio_set_input_source
,
362 #endif /* CONFIG_CODEC == SWCODEC */
364 /* playback control */
377 audio_has_changed_track
,
379 audio_flush_and_reload_tracks
,
381 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
382 mpeg_get_last_header
,
384 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
385 (CONFIG_CODEC == SWCODEC)
389 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
390 /* MAS communication */
395 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
402 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
408 gui_syncstatusbar_draw
,
416 #ifdef HAVE_LCD_COLOR
420 /* action handling */
434 # if CONFIG_CHARGING == CHARGING_MONITOR
438 #ifdef HAVE_USB_POWER
453 plugin_get_audio_buffer
,
455 plugin_get_current_filename
,
459 #if defined(DEBUG) || defined(SIMULATOR)
462 #ifdef ROCKBOX_HAS_LOGF
471 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
472 peak_meter_scale_value
,
473 peak_meter_set_use_dbfs
,
474 peak_meter_get_use_dbfs
,
476 #ifdef HAVE_LCD_BITMAP
478 screen_dump_set_hook
,
485 #ifdef HAVE_WHEEL_POSITION
490 #ifdef IRIVER_H100_SERIES
491 /* Routines for the iriver_flash -plugin. */
492 detect_original_firmware
,
493 detect_flashed_ramimage
,
494 detect_flashed_romimage
,
496 /* new stuff at the end, sort into place next time
497 the API gets incompatible */
499 #if (CONFIG_CODEC == SWCODEC)
510 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
514 #ifdef CACHE_FUNCTIONS_AS_CALL
525 int plugin_load(const char* plugin
, void* parameter
)
528 struct plugin_header
*hdr
;
536 #ifdef HAVE_REMOTE_LCD
541 fb_data
* old_backdrop
;
544 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
546 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
548 /* not allowing another plugin to load */
552 plugin_loaded
= false;
555 gui_syncsplash(0, ID2P(LANG_WAIT
));
556 strcpy(current_plugin
, plugin
);
559 hdr
= sim_plugin_load((char *)plugin
, &pd
);
561 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
565 || hdr
->magic
!= PLUGIN_MAGIC
566 || hdr
->target_id
!= TARGET_ID
) {
567 sim_plugin_close(pd
);
568 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
571 if (hdr
->api_version
> PLUGIN_API_VERSION
572 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
573 sim_plugin_close(pd
);
574 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
578 fd
= open(plugin
, O_RDONLY
);
580 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
584 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
588 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
591 hdr
= (struct plugin_header
*)pluginbuf
;
593 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
594 || hdr
->magic
!= PLUGIN_MAGIC
595 || hdr
->target_id
!= TARGET_ID
596 || hdr
->load_addr
!= pluginbuf
597 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
598 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
601 if (hdr
->api_version
> PLUGIN_API_VERSION
602 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
603 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
606 plugin_size
= hdr
->end_addr
- pluginbuf
;
608 /* zero out bss area only, above guards end of pluginbuf */
609 if (plugin_size
> readsize
)
610 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
613 plugin_loaded
= true;
615 xm
= lcd_getxmargin();
616 ym
= lcd_getymargin();
619 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
620 old_backdrop
= lcd_get_backdrop();
625 #ifdef HAVE_REMOTE_LCD
626 rxm
= lcd_remote_getxmargin();
627 rym
= lcd_remote_getymargin();
628 lcd_remote_setmargins(0, 0);
629 lcd_remote_clear_display();
635 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
636 /* explicitly casting the pointer here to avoid touching every plugin. */
638 button_clear_queue();
640 #ifdef HAVE_LCD_BITMAP
642 lcd_set_backdrop(old_backdrop
);
643 #ifdef HAVE_LCD_COLOR
644 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
645 global_settings
.bg_color
);
647 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
649 #else /* LCD_DEPTH == 1 */
650 lcd_set_drawmode(DRMODE_SOLID
);
651 #endif /* LCD_DEPTH */
652 #endif /* HAVE_LCD_BITMAP */
654 /* restore margins */
655 lcd_setmargins(xm
,ym
);
659 #ifdef HAVE_REMOTE_LCD
660 #if LCD_REMOTE_DEPTH > 1
661 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
662 LCD_REMOTE_DEFAULT_BG
);
664 lcd_remote_set_drawmode(DRMODE_SOLID
);
666 lcd_remote_setmargins(rxm
, rym
);
667 lcd_remote_clear_display();
671 if (pfn_tsr_exit
== NULL
)
672 plugin_loaded
= false;
674 sim_plugin_close(pd
);
680 case PLUGIN_USB_CONNECTED
:
681 return PLUGIN_USB_CONNECTED
;
684 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
690 /* Returns a pointer to the portion of the plugin buffer that is not already
691 being used. If no plugin is loaded, returns the entire plugin buffer */
692 void* plugin_get_buffer(size_t *buffer_size
)
698 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
701 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
702 buffer_pos
= plugin_size
;
706 *buffer_size
= PLUGIN_BUFFER_SIZE
;
710 return &pluginbuf
[buffer_pos
];
713 /* Returns a pointer to the mp3 buffer.
714 Playback gets stopped, to avoid conflicts.
715 Talk buffer is stolen as well.
717 void* plugin_get_audio_buffer(size_t *buffer_size
)
719 #if CONFIG_CODEC == SWCODEC
720 return audio_get_buffer(true, buffer_size
);
723 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
724 *buffer_size
= audiobufend
- audiobuf
;
730 /* Initializes plugin IRAM */
731 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
732 char *iedata
, size_t iedata_size
)
735 memcpy(iramstart
, iramcopy
, iram_size
);
736 memset(iedata
, 0, iedata_size
);
737 memset(iramcopy
, 0, iram_size
);
739 /* writeback cleared iedata and iramcopy areas */
743 #endif /* IRAM_STEAL */
745 /* The plugin wants to stay resident after leaving its main function, e.g.
746 runs from timer or own thread. The callback is registered to later
747 instruct it to free its resources before a new plugin gets loaded. */
748 void plugin_tsr(bool (*exit_callback
)(bool))
750 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
753 char *plugin_get_current_filename(void)
755 return current_plugin
;