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_COLOR)
187 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200)
192 gui_synclist_set_nb_items
,
193 gui_synclist_set_icon_callback
,
194 gui_synclist_get_nb_items
,
195 gui_synclist_get_sel_pos
,
197 gui_synclist_select_item
,
198 gui_synclist_add_item
,
199 gui_synclist_del_item
,
200 gui_synclist_limit_scroll
,
201 gui_synclist_do_button
,
202 gui_synclist_set_title
,
210 #ifdef HAS_BUTTON_HOLD
215 (open_func
)PREFIX(open
),
217 (read_func
)PREFIX(read
),
219 (creat_func
)PREFIX(creat
),
220 (write_func
)PREFIX(write
),
234 create_numbered_filename
,
246 #ifdef HAVE_PRIORITY_SCHEDULING
250 default_event_handler
,
251 default_event_handler_ex
,
255 reset_poweroff_timer
,
260 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
261 #ifdef CPU_BOOST_LOGGING
285 /* special simulator hooks */
286 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
288 sim_lcd_ex_update_rect
,
292 /* strings and memory */
324 #if CONFIG_CODEC == SWCODEC
336 #if CONFIG_CODEC != SWCODEC
340 #if CONFIG_CODEC == SWCODEC
341 &audio_master_sampr_list
[0],
350 pcm_get_bytes_waiting
,
352 #ifdef HAVE_RECORDING
359 pcm_calculate_rec_peaks
,
360 audio_set_recording_gain
,
361 #endif /* HAVE_RECORDING */
362 #if INPUT_SRC_CAPS != 0
363 audio_set_output_source
,
364 audio_set_input_source
,
366 #endif /* CONFIG_CODEC == SWCODEC */
368 /* playback control */
381 audio_has_changed_track
,
383 audio_flush_and_reload_tracks
,
385 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
386 mpeg_get_last_header
,
388 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
389 (CONFIG_CODEC == SWCODEC)
393 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
394 /* MAS communication */
399 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
406 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
412 gui_syncstatusbar_draw
,
420 #ifdef HAVE_LCD_COLOR
424 /* action handling */
438 # if CONFIG_CHARGING == CHARGING_MONITOR
442 #ifdef HAVE_USB_POWER
457 plugin_get_audio_buffer
,
459 plugin_get_current_filename
,
460 #ifdef PLUGIN_USE_IRAM
463 #if defined(DEBUG) || defined(SIMULATOR)
466 #ifdef ROCKBOX_HAS_LOGF
472 #if CONFIG_CODEC == SWCODEC
481 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
482 peak_meter_scale_value
,
483 peak_meter_set_use_dbfs
,
484 peak_meter_get_use_dbfs
,
486 #ifdef HAVE_LCD_BITMAP
488 screen_dump_set_hook
,
495 #ifdef HAVE_WHEEL_POSITION
500 #ifdef IRIVER_H100_SERIES
501 /* Routines for the iriver_flash -plugin. */
502 detect_original_firmware
,
503 detect_flashed_ramimage
,
504 detect_flashed_romimage
,
507 #ifdef CACHE_FUNCTIONS_AS_CALL
511 /* new stuff at the end, sort into place next time
512 the API gets incompatible */
514 #if (CONFIG_CODEC == SWCODEC)
522 #ifdef PROC_NEEDS_CACHEALIGN
529 #ifdef HAVE_REMOTE_LCD
530 remote_backlight_set_timeout
,
532 remote_backlight_set_timeout_plugged
,
534 #endif /* HAVE_REMOTE_LCD */
537 int plugin_load(const char* plugin
, void* parameter
)
540 struct plugin_header
*hdr
;
548 #ifdef HAVE_REMOTE_LCD
553 fb_data
* old_backdrop
;
556 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
558 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
560 /* not allowing another plugin to load */
564 plugin_loaded
= false;
567 gui_syncsplash(0, ID2P(LANG_WAIT
));
568 strcpy(current_plugin
, plugin
);
571 hdr
= sim_plugin_load((char *)plugin
, &pd
);
573 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
577 || hdr
->magic
!= PLUGIN_MAGIC
578 || hdr
->target_id
!= TARGET_ID
) {
579 sim_plugin_close(pd
);
580 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
583 if (hdr
->api_version
> PLUGIN_API_VERSION
584 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
585 sim_plugin_close(pd
);
586 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
590 fd
= open(plugin
, O_RDONLY
);
592 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
596 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
600 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
603 hdr
= (struct plugin_header
*)pluginbuf
;
605 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
606 || hdr
->magic
!= PLUGIN_MAGIC
607 || hdr
->target_id
!= TARGET_ID
608 || hdr
->load_addr
!= pluginbuf
609 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
610 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
613 if (hdr
->api_version
> PLUGIN_API_VERSION
614 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
615 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
618 plugin_size
= hdr
->end_addr
- pluginbuf
;
620 /* zero out bss area only, above guards end of pluginbuf */
621 if (plugin_size
> readsize
)
622 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
625 plugin_loaded
= true;
627 xm
= lcd_getxmargin();
628 ym
= lcd_getymargin();
631 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
632 old_backdrop
= lcd_get_backdrop();
637 #ifdef HAVE_REMOTE_LCD
638 rxm
= lcd_remote_getxmargin();
639 rym
= lcd_remote_getymargin();
640 lcd_remote_setmargins(0, 0);
641 lcd_remote_clear_display();
647 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
648 /* explicitly casting the pointer here to avoid touching every plugin. */
650 button_clear_queue();
652 #ifdef HAVE_LCD_BITMAP
654 lcd_set_backdrop(old_backdrop
);
655 #ifdef HAVE_LCD_COLOR
656 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
657 global_settings
.bg_color
);
659 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
661 #else /* LCD_DEPTH == 1 */
662 lcd_set_drawmode(DRMODE_SOLID
);
663 #endif /* LCD_DEPTH */
664 #endif /* HAVE_LCD_BITMAP */
666 /* restore margins */
667 lcd_setmargins(xm
,ym
);
671 #ifdef HAVE_REMOTE_LCD
672 #if LCD_REMOTE_DEPTH > 1
673 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
674 LCD_REMOTE_DEFAULT_BG
);
676 lcd_remote_set_drawmode(DRMODE_SOLID
);
678 lcd_remote_setmargins(rxm
, rym
);
679 lcd_remote_clear_display();
687 if (pfn_tsr_exit
== NULL
)
688 plugin_loaded
= false;
690 sim_plugin_close(pd
);
696 case PLUGIN_USB_CONNECTED
:
697 return PLUGIN_USB_CONNECTED
;
700 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
706 /* Returns a pointer to the portion of the plugin buffer that is not already
707 being used. If no plugin is loaded, returns the entire plugin buffer */
708 void* plugin_get_buffer(size_t *buffer_size
)
714 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
717 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
718 buffer_pos
= plugin_size
;
722 *buffer_size
= PLUGIN_BUFFER_SIZE
;
726 return &pluginbuf
[buffer_pos
];
729 /* Returns a pointer to the mp3 buffer.
730 Playback gets stopped, to avoid conflicts.
731 Talk buffer is stolen as well.
733 void* plugin_get_audio_buffer(size_t *buffer_size
)
735 #if CONFIG_CODEC == SWCODEC
736 return audio_get_buffer(true, buffer_size
);
739 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
740 *buffer_size
= audiobufend
- audiobuf
;
745 #ifdef PLUGIN_USE_IRAM
746 /* Initializes plugin IRAM */
747 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
748 char *iedata
, size_t iedata_size
)
750 /* We need to stop audio playback in order to use codec IRAM */
752 memcpy(iramstart
, iramcopy
, iram_size
);
753 memset(iedata
, 0, iedata_size
);
754 memset(iramcopy
, 0, iram_size
);
756 /* writeback cleared iedata and iramcopy areas */
760 #endif /* PLUGIN_USE_IRAM */
762 /* The plugin wants to stay resident after leaving its main function, e.g.
763 runs from timer or own thread. The callback is registered to later
764 instruct it to free its resources before a new plugin gets loaded. */
765 void plugin_tsr(bool (*exit_callback
)(bool))
767 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
770 char *plugin_get_current_filename(void)
772 return current_plugin
;