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"
40 #ifdef HAVE_LCD_BITMAP
41 #include "scrollbar.h"
42 #include "peakmeter.h"
48 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
49 void *sim_plugin_load(char *plugin
, void **pd
);
50 void sim_plugin_close(void *pd
);
51 void sim_lcd_ex_init(int shades
, unsigned long (*getpixel
)(int, int));
52 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
54 #define sim_plugin_close(x)
55 extern unsigned char pluginbuf
[];
59 /* for actual plugins only, not for codecs */
60 static bool plugin_loaded
= false;
61 static int plugin_size
= 0;
62 static bool (*pfn_tsr_exit
)(bool reenter
) = NULL
; /* TSR exit callback */
63 static char current_plugin
[MAX_PATH
];
65 extern struct thread_entry threads
[MAXTHREADS
];
67 static const struct plugin_api rockbox_api
= {
79 #ifdef HAVE_LCD_CHARCELLS
81 lcd_get_locked_pattern
,
110 lcd_bitmap_transparent_part
,
111 lcd_bitmap_transparent
,
117 lcd_puts_scroll_style
,
118 &lcd_framebuffer
[0][0],
128 backlight_set_timeout
,
130 #ifdef HAVE_REMOTE_LCD
132 lcd_remote_set_contrast
,
133 lcd_remote_clear_display
,
135 lcd_remote_puts_scroll
,
136 lcd_remote_stop_scroll
,
137 lcd_remote_set_drawmode
,
138 lcd_remote_get_drawmode
,
140 lcd_remote_getstringsize
,
141 lcd_remote_drawpixel
,
147 lcd_remote_mono_bitmap_part
,
148 lcd_remote_mono_bitmap
,
150 lcd_remote_puts_style
,
151 lcd_remote_puts_scroll_style
,
152 &lcd_remote_framebuffer
[0][0],
154 lcd_remote_update_rect
,
157 remote_backlight_off
,
160 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
162 {&screens
[SCREEN_MAIN
]},
164 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
165 lcd_remote_set_foreground
,
166 lcd_remote_get_foreground
,
167 lcd_remote_set_background
,
168 lcd_remote_get_background
,
169 lcd_remote_bitmap_part
,
173 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
178 gui_synclist_set_nb_items
,
179 gui_synclist_set_icon_callback
,
180 gui_synclist_get_nb_items
,
181 gui_synclist_get_sel_pos
,
183 gui_synclist_select_item
,
184 gui_synclist_add_item
,
185 gui_synclist_del_item
,
186 gui_synclist_limit_scroll
,
188 gui_synclist_do_button
,
189 gui_synclist_set_title
,
196 #ifdef HAS_BUTTON_HOLD
201 (open_func
)PREFIX(open
),
205 (creat_func
)PREFIX(creat
),
238 #ifdef HAVE_PRIORITY_SCHEDULING
242 default_event_handler
,
243 default_event_handler_ex
,
246 reset_poweroff_timer
,
251 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
252 #ifdef CPU_BOOST_LOGGING
275 /* special simulator hooks */
276 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
278 sim_lcd_ex_update_rect
,
282 /* strings and memory */
314 #if CONFIG_CODEC == SWCODEC
327 #if CONFIG_CODEC != SWCODEC
331 #if CONFIG_CODEC == SWCODEC
332 &audio_master_sampr_list
[0],
341 pcm_get_bytes_waiting
,
343 #ifdef HAVE_RECORDING
350 pcm_calculate_rec_peaks
,
351 audio_set_recording_gain
,
352 audio_set_output_source
,
354 #endif /* HAVE_RECORDING */
358 /* playback control */
371 audio_has_changed_track
,
373 audio_flush_and_reload_tracks
,
375 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
376 mpeg_get_last_header
,
378 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
379 (CONFIG_CODEC == SWCODEC)
383 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
384 /* MAS communication */
389 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
396 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
402 gui_syncstatusbar_draw
,
408 /* action handling */
411 action_signalscreenchange
,
423 # if CONFIG_CHARGING == CHARGING_MONITOR
427 #ifdef HAVE_USB_POWER
439 plugin_get_audio_buffer
,
444 #if defined(DEBUG) || defined(SIMULATOR)
447 #ifdef ROCKBOX_HAS_LOGF
456 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
457 peak_meter_scale_value
,
458 peak_meter_set_use_dbfs
,
459 peak_meter_get_use_dbfs
,
461 #ifdef HAVE_LCD_BITMAP
463 screen_dump_set_hook
,
468 #ifdef HAVE_WHEEL_POSITION
476 /* new stuff at the end, sort into place next time
477 the API gets incompatible */
479 #ifdef IRIVER_H100_SERIES
480 /* Routines for the iriver_flash -plugin. */
481 detect_original_firmware
,
482 detect_flashed_ramimage
,
483 detect_flashed_romimage
,
492 #if (CONFIG_CODEC == SWCODEC)
498 create_numbered_filename
,
501 int plugin_load(const char* plugin
, void* parameter
)
504 struct plugin_header
*hdr
;
505 const char *p
= strrchr(plugin
,'/');
513 #ifdef HAVE_REMOTE_LCD
518 fb_data
* old_backdrop
;
523 action_signalscreenchange();
525 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
527 if (pfn_tsr_exit(!strcmp(current_plugin
,p
)) == false )
529 /* not allowing another plugin to load */
533 plugin_loaded
= false;
536 gui_syncsplash(0, str(LANG_WAIT
));
537 strcpy(current_plugin
,p
);
540 hdr
= sim_plugin_load((char *)plugin
, &pd
);
542 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
546 || hdr
->magic
!= PLUGIN_MAGIC
547 || hdr
->target_id
!= TARGET_ID
) {
548 sim_plugin_close(pd
);
549 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
552 if (hdr
->api_version
> PLUGIN_API_VERSION
553 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
554 sim_plugin_close(pd
);
555 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
559 fd
= open(plugin
, O_RDONLY
);
561 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
565 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
569 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
572 hdr
= (struct plugin_header
*)pluginbuf
;
574 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
575 || hdr
->magic
!= PLUGIN_MAGIC
576 || hdr
->target_id
!= TARGET_ID
577 || hdr
->load_addr
!= pluginbuf
578 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
579 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
582 if (hdr
->api_version
> PLUGIN_API_VERSION
583 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
584 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
587 plugin_size
= hdr
->end_addr
- pluginbuf
;
589 /* zero out bss area only, above guards end of pluginbuf */
590 if (plugin_size
> readsize
)
591 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
594 plugin_loaded
= true;
596 xm
= lcd_getxmargin();
597 ym
= lcd_getymargin();
600 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
601 old_backdrop
= lcd_get_backdrop();
606 #ifdef HAVE_REMOTE_LCD
607 rxm
= lcd_remote_getxmargin();
608 rym
= lcd_remote_getymargin();
609 lcd_remote_setmargins(0, 0);
610 lcd_remote_clear_display();
616 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
617 /* explicitly casting the pointer here to avoid touching every plugin. */
619 action_signalscreenchange();
620 button_clear_queue();
622 #ifdef HAVE_LCD_BITMAP
624 lcd_set_backdrop(old_backdrop
);
625 #ifdef HAVE_LCD_COLOR
626 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
627 global_settings
.bg_color
);
629 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
631 #else /* LCD_DEPTH == 1 */
632 lcd_set_drawmode(DRMODE_SOLID
);
633 #endif /* LCD_DEPTH */
634 #endif /* HAVE_LCD_BITMAP */
636 /* restore margins */
637 lcd_setmargins(xm
,ym
);
641 #ifdef HAVE_REMOTE_LCD
642 #if LCD_REMOTE_DEPTH > 1
643 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
644 LCD_REMOTE_DEFAULT_BG
);
646 lcd_remote_set_drawmode(DRMODE_SOLID
);
648 lcd_remote_setmargins(rxm
, rym
);
649 lcd_remote_clear_display();
653 if (pfn_tsr_exit
== NULL
)
654 plugin_loaded
= false;
656 sim_plugin_close(pd
);
662 case PLUGIN_USB_CONNECTED
:
663 return PLUGIN_USB_CONNECTED
;
666 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
672 /* Returns a pointer to the portion of the plugin buffer that is not already
673 being used. If no plugin is loaded, returns the entire plugin buffer */
674 void* plugin_get_buffer(size_t *buffer_size
)
680 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
683 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
684 buffer_pos
= plugin_size
;
688 *buffer_size
= PLUGIN_BUFFER_SIZE
;
692 return &pluginbuf
[buffer_pos
];
695 /* Returns a pointer to the mp3 buffer.
696 Playback gets stopped, to avoid conflicts.
697 Talk buffer is stolen as well.
699 void* plugin_get_audio_buffer(size_t *buffer_size
)
701 #if CONFIG_CODEC == SWCODEC
702 return audio_get_buffer(true, buffer_size
);
705 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
706 *buffer_size
= audiobufend
- audiobuf
;
712 /* Initializes plugin IRAM */
713 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
714 char *iedata
, size_t iedata_size
)
717 memcpy(iramstart
, iramcopy
, iram_size
);
718 memset(iedata
, 0, iedata_size
);
719 memset(iramcopy
, 0, iram_size
);
721 #endif /* IRAM_STEAL */
723 /* The plugin wants to stay resident after leaving its main function, e.g.
724 runs from timer or own thread. The callback is registered to later
725 instruct it to free its resources before a new plugin gets loaded. */
726 void plugin_tsr(bool (*exit_callback
)(bool))
728 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */