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 ****************************************************************************/
29 #include "backlight.h"
30 #include "sound_menu.h"
32 #include "powermgmt.h"
35 #include "option_select.h"
41 #ifdef HAVE_LCD_BITMAP
42 #include "scrollbar.h"
43 #include "peakmeter.h"
49 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
50 void *sim_plugin_load(char *plugin
, void **pd
);
51 void sim_plugin_close(void *pd
);
52 void sim_lcd_ex_init(int shades
, unsigned long (*getpixel
)(int, int));
53 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
55 #define sim_plugin_close(x)
56 extern unsigned char pluginbuf
[];
60 /* for actual plugins only, not for codecs */
61 static bool plugin_loaded
= false;
62 static int plugin_size
= 0;
63 static bool (*pfn_tsr_exit
)(bool reenter
) = NULL
; /* TSR exit callback */
64 static char current_plugin
[MAX_PATH
];
66 extern struct thread_entry threads
[MAXTHREADS
];
68 static const struct plugin_api rockbox_api
= {
80 #ifdef HAVE_LCD_CHARCELLS
82 lcd_get_locked_pattern
,
112 lcd_bitmap_transparent_part
,
113 lcd_bitmap_transparent
,
119 lcd_puts_scroll_style
,
120 &lcd_framebuffer
[0][0],
130 backlight_set_timeout
,
132 #ifdef HAVE_REMOTE_LCD
134 lcd_remote_set_contrast
,
135 lcd_remote_clear_display
,
137 lcd_remote_puts_scroll
,
138 lcd_remote_stop_scroll
,
139 lcd_remote_set_drawmode
,
140 lcd_remote_get_drawmode
,
142 lcd_remote_getstringsize
,
143 lcd_remote_drawpixel
,
149 lcd_remote_mono_bitmap_part
,
150 lcd_remote_mono_bitmap
,
152 lcd_remote_puts_style
,
153 lcd_remote_puts_scroll_style
,
154 &lcd_remote_framebuffer
[0][0],
156 lcd_remote_update_rect
,
159 remote_backlight_off
,
162 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
164 {&screens
[SCREEN_MAIN
]},
166 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
167 lcd_remote_set_foreground
,
168 lcd_remote_get_foreground
,
169 lcd_remote_set_background
,
170 lcd_remote_get_background
,
171 lcd_remote_bitmap_part
,
175 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
180 gui_synclist_set_nb_items
,
181 gui_synclist_set_icon_callback
,
182 gui_synclist_get_nb_items
,
183 gui_synclist_get_sel_pos
,
185 gui_synclist_select_item
,
186 gui_synclist_add_item
,
187 gui_synclist_del_item
,
188 gui_synclist_limit_scroll
,
190 gui_synclist_do_button
,
191 gui_synclist_set_title
,
198 #ifdef HAS_BUTTON_HOLD
203 (open_func
)PREFIX(open
),
207 (creat_func
)PREFIX(creat
),
222 create_numbered_filename
,
241 #ifdef HAVE_PRIORITY_SCHEDULING
245 default_event_handler
,
246 default_event_handler_ex
,
250 reset_poweroff_timer
,
255 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
256 #ifdef CPU_BOOST_LOGGING
279 /* special simulator hooks */
280 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
282 sim_lcd_ex_update_rect
,
286 /* strings and memory */
318 #if CONFIG_CODEC == SWCODEC
330 #if CONFIG_CODEC != SWCODEC
334 #if CONFIG_CODEC == SWCODEC
335 &audio_master_sampr_list
[0],
344 pcm_get_bytes_waiting
,
346 #ifdef HAVE_RECORDING
353 pcm_calculate_rec_peaks
,
354 audio_set_recording_gain
,
355 #endif /* HAVE_RECORDING */
356 #if INPUT_SRC_CAPS != 0
357 audio_set_output_source
,
358 audio_set_input_source
,
360 #endif /* CONFIG_CODEC == SWCODEC */
362 /* playback control */
375 audio_has_changed_track
,
377 audio_flush_and_reload_tracks
,
379 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
380 mpeg_get_last_header
,
382 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
383 (CONFIG_CODEC == SWCODEC)
387 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
388 /* MAS communication */
393 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
400 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
406 gui_syncstatusbar_draw
,
414 #ifdef HAVE_LCD_COLOR
418 /* action handling */
421 action_signalscreenchange
,
433 # if CONFIG_CHARGING == CHARGING_MONITOR
437 #ifdef HAVE_USB_POWER
449 plugin_get_audio_buffer
,
454 #if defined(DEBUG) || defined(SIMULATOR)
457 #ifdef ROCKBOX_HAS_LOGF
466 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
467 peak_meter_scale_value
,
468 peak_meter_set_use_dbfs
,
469 peak_meter_get_use_dbfs
,
471 #ifdef HAVE_LCD_BITMAP
473 screen_dump_set_hook
,
478 #ifdef HAVE_WHEEL_POSITION
483 #ifdef IRIVER_H100_SERIES
484 /* Routines for the iriver_flash -plugin. */
485 detect_original_firmware
,
486 detect_flashed_ramimage
,
487 detect_flashed_romimage
,
489 /* new stuff at the end, sort into place next time
490 the API gets incompatible */
497 #if (CONFIG_CODEC == SWCODEC)
504 int plugin_load(const char* plugin
, void* parameter
)
507 struct plugin_header
*hdr
;
508 const char *p
= strrchr(plugin
,'/');
516 #ifdef HAVE_REMOTE_LCD
521 fb_data
* old_backdrop
;
526 action_signalscreenchange();
528 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
530 if (pfn_tsr_exit(!strcmp(current_plugin
,p
)) == false )
532 /* not allowing another plugin to load */
536 plugin_loaded
= false;
539 gui_syncsplash(0, str(LANG_WAIT
));
540 strcpy(current_plugin
,p
);
543 hdr
= sim_plugin_load((char *)plugin
, &pd
);
545 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
549 || hdr
->magic
!= PLUGIN_MAGIC
550 || hdr
->target_id
!= TARGET_ID
) {
551 sim_plugin_close(pd
);
552 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
555 if (hdr
->api_version
> PLUGIN_API_VERSION
556 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
557 sim_plugin_close(pd
);
558 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
562 fd
= open(plugin
, O_RDONLY
);
564 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
568 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
572 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
575 hdr
= (struct plugin_header
*)pluginbuf
;
577 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
578 || hdr
->magic
!= PLUGIN_MAGIC
579 || hdr
->target_id
!= TARGET_ID
580 || hdr
->load_addr
!= pluginbuf
581 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
582 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
585 if (hdr
->api_version
> PLUGIN_API_VERSION
586 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
587 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
590 plugin_size
= hdr
->end_addr
- pluginbuf
;
592 /* zero out bss area only, above guards end of pluginbuf */
593 if (plugin_size
> readsize
)
594 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
597 plugin_loaded
= true;
599 xm
= lcd_getxmargin();
600 ym
= lcd_getymargin();
603 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
604 old_backdrop
= lcd_get_backdrop();
609 #ifdef HAVE_REMOTE_LCD
610 rxm
= lcd_remote_getxmargin();
611 rym
= lcd_remote_getymargin();
612 lcd_remote_setmargins(0, 0);
613 lcd_remote_clear_display();
619 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
620 /* explicitly casting the pointer here to avoid touching every plugin. */
622 action_signalscreenchange();
623 button_clear_queue();
625 #ifdef HAVE_LCD_BITMAP
627 lcd_set_backdrop(old_backdrop
);
628 #ifdef HAVE_LCD_COLOR
629 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
630 global_settings
.bg_color
);
632 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
634 #else /* LCD_DEPTH == 1 */
635 lcd_set_drawmode(DRMODE_SOLID
);
636 #endif /* LCD_DEPTH */
637 #endif /* HAVE_LCD_BITMAP */
639 /* restore margins */
640 lcd_setmargins(xm
,ym
);
644 #ifdef HAVE_REMOTE_LCD
645 #if LCD_REMOTE_DEPTH > 1
646 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
647 LCD_REMOTE_DEFAULT_BG
);
649 lcd_remote_set_drawmode(DRMODE_SOLID
);
651 lcd_remote_setmargins(rxm
, rym
);
652 lcd_remote_clear_display();
656 if (pfn_tsr_exit
== NULL
)
657 plugin_loaded
= false;
659 sim_plugin_close(pd
);
665 case PLUGIN_USB_CONNECTED
:
666 return PLUGIN_USB_CONNECTED
;
669 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
675 /* Returns a pointer to the portion of the plugin buffer that is not already
676 being used. If no plugin is loaded, returns the entire plugin buffer */
677 void* plugin_get_buffer(size_t *buffer_size
)
683 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
686 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
687 buffer_pos
= plugin_size
;
691 *buffer_size
= PLUGIN_BUFFER_SIZE
;
695 return &pluginbuf
[buffer_pos
];
698 /* Returns a pointer to the mp3 buffer.
699 Playback gets stopped, to avoid conflicts.
700 Talk buffer is stolen as well.
702 void* plugin_get_audio_buffer(size_t *buffer_size
)
704 #if CONFIG_CODEC == SWCODEC
705 return audio_get_buffer(true, buffer_size
);
708 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
709 *buffer_size
= audiobufend
- audiobuf
;
715 /* Initializes plugin IRAM */
716 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
717 char *iedata
, size_t iedata_size
)
720 memcpy(iramstart
, iramcopy
, iram_size
);
721 memset(iedata
, 0, iedata_size
);
722 memset(iramcopy
, 0, iram_size
);
724 #endif /* IRAM_STEAL */
726 /* The plugin wants to stay resident after leaving its main function, e.g.
727 runs from timer or own thread. The callback is registered to later
728 instruct it to free its resources before a new plugin gets loaded. */
729 void plugin_tsr(bool (*exit_callback
)(bool))
731 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */