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"
42 #ifdef HAVE_LCD_BITMAP
43 #include "scrollbar.h"
44 #include "peakmeter.h"
50 static unsigned char pluginbuf
[PLUGIN_BUFFER_SIZE
];
51 void *sim_plugin_load(char *plugin
, void **pd
);
52 void sim_plugin_close(void *pd
);
53 void sim_lcd_ex_init(int shades
, unsigned long (*getpixel
)(int, int));
54 void sim_lcd_ex_update_rect(int x
, int y
, int width
, int height
);
56 #define sim_plugin_close(x)
57 extern unsigned char pluginbuf
[];
61 /* for actual plugins only, not for codecs */
62 static bool plugin_loaded
= false;
63 static int plugin_size
= 0;
64 static bool (*pfn_tsr_exit
)(bool reenter
) = NULL
; /* TSR exit callback */
65 static char current_plugin
[MAX_PATH
];
67 char *plugin_get_current_filename(void);
69 extern struct thread_entry threads
[MAXTHREADS
];
71 static const struct plugin_api rockbox_api
= {
83 #ifdef HAVE_LCD_CHARCELLS
85 lcd_get_locked_pattern
,
102 lcd_mono_bitmap_part
,
115 lcd_bitmap_transparent_part
,
116 lcd_bitmap_transparent
,
122 lcd_puts_scroll_style
,
123 &lcd_framebuffer
[0][0],
134 backlight_set_timeout
,
136 #ifdef HAVE_REMOTE_LCD
138 lcd_remote_set_contrast
,
139 lcd_remote_clear_display
,
141 lcd_remote_puts_scroll
,
142 lcd_remote_stop_scroll
,
143 lcd_remote_set_drawmode
,
144 lcd_remote_get_drawmode
,
146 lcd_remote_getstringsize
,
147 lcd_remote_drawpixel
,
153 lcd_remote_mono_bitmap_part
,
154 lcd_remote_mono_bitmap
,
156 lcd_remote_puts_style
,
157 lcd_remote_puts_scroll_style
,
158 &lcd_remote_framebuffer
[0][0],
160 lcd_remote_update_rect
,
163 remote_backlight_off
,
166 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
168 {&screens
[SCREEN_MAIN
]},
170 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
171 lcd_remote_set_foreground
,
172 lcd_remote_get_foreground
,
173 lcd_remote_set_background
,
174 lcd_remote_get_background
,
175 lcd_remote_bitmap_part
,
179 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
184 gui_synclist_set_nb_items
,
185 gui_synclist_set_icon_callback
,
186 gui_synclist_get_nb_items
,
187 gui_synclist_get_sel_pos
,
189 gui_synclist_select_item
,
190 gui_synclist_add_item
,
191 gui_synclist_del_item
,
192 gui_synclist_limit_scroll
,
194 gui_synclist_do_button
,
195 gui_synclist_set_title
,
202 #ifdef HAS_BUTTON_HOLD
207 (open_func
)PREFIX(open
),
211 (creat_func
)PREFIX(creat
),
226 create_numbered_filename
,
238 #ifdef HAVE_PRIORITY_SCHEDULING
242 default_event_handler
,
243 default_event_handler_ex
,
247 reset_poweroff_timer
,
252 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
253 #ifdef CPU_BOOST_LOGGING
277 /* special simulator hooks */
278 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
280 sim_lcd_ex_update_rect
,
284 /* strings and memory */
316 #if CONFIG_CODEC == SWCODEC
328 #if CONFIG_CODEC != SWCODEC
332 #if CONFIG_CODEC == SWCODEC
333 &audio_master_sampr_list
[0],
342 pcm_get_bytes_waiting
,
344 #ifdef HAVE_RECORDING
351 pcm_calculate_rec_peaks
,
352 audio_set_recording_gain
,
353 #endif /* HAVE_RECORDING */
354 #if INPUT_SRC_CAPS != 0
355 audio_set_output_source
,
356 audio_set_input_source
,
358 #endif /* CONFIG_CODEC == SWCODEC */
360 /* playback control */
373 audio_has_changed_track
,
375 audio_flush_and_reload_tracks
,
377 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
378 mpeg_get_last_header
,
380 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
381 (CONFIG_CODEC == SWCODEC)
385 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
386 /* MAS communication */
391 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
398 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
404 gui_syncstatusbar_draw
,
412 #ifdef HAVE_LCD_COLOR
416 /* action handling */
430 # if CONFIG_CHARGING == CHARGING_MONITOR
434 #ifdef HAVE_USB_POWER
449 plugin_get_audio_buffer
,
451 plugin_get_current_filename
,
455 #if defined(DEBUG) || defined(SIMULATOR)
458 #ifdef ROCKBOX_HAS_LOGF
467 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
468 peak_meter_scale_value
,
469 peak_meter_set_use_dbfs
,
470 peak_meter_get_use_dbfs
,
472 #ifdef HAVE_LCD_BITMAP
474 screen_dump_set_hook
,
481 #ifdef HAVE_WHEEL_POSITION
486 #ifdef IRIVER_H100_SERIES
487 /* Routines for the iriver_flash -plugin. */
488 detect_original_firmware
,
489 detect_flashed_ramimage
,
490 detect_flashed_romimage
,
492 /* new stuff at the end, sort into place next time
493 the API gets incompatible */
495 #if (CONFIG_CODEC == SWCODEC)
507 int plugin_load(const char* plugin
, void* parameter
)
510 struct plugin_header
*hdr
;
518 #ifdef HAVE_REMOTE_LCD
523 fb_data
* old_backdrop
;
526 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
528 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
530 /* not allowing another plugin to load */
534 plugin_loaded
= false;
537 gui_syncsplash(0, ID2P(LANG_WAIT
));
538 strcpy(current_plugin
, plugin
);
541 hdr
= sim_plugin_load((char *)plugin
, &pd
);
543 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
547 || hdr
->magic
!= PLUGIN_MAGIC
548 || hdr
->target_id
!= TARGET_ID
) {
549 sim_plugin_close(pd
);
550 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
553 if (hdr
->api_version
> PLUGIN_API_VERSION
554 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
555 sim_plugin_close(pd
);
556 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
560 fd
= open(plugin
, O_RDONLY
);
562 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
566 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
570 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
573 hdr
= (struct plugin_header
*)pluginbuf
;
575 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
576 || hdr
->magic
!= PLUGIN_MAGIC
577 || hdr
->target_id
!= TARGET_ID
578 || hdr
->load_addr
!= pluginbuf
579 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
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 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
588 plugin_size
= hdr
->end_addr
- pluginbuf
;
590 /* zero out bss area only, above guards end of pluginbuf */
591 if (plugin_size
> readsize
)
592 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
595 plugin_loaded
= true;
597 xm
= lcd_getxmargin();
598 ym
= lcd_getymargin();
601 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
602 old_backdrop
= lcd_get_backdrop();
607 #ifdef HAVE_REMOTE_LCD
608 rxm
= lcd_remote_getxmargin();
609 rym
= lcd_remote_getymargin();
610 lcd_remote_setmargins(0, 0);
611 lcd_remote_clear_display();
617 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
618 /* explicitly casting the pointer here to avoid touching every plugin. */
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 /* writeback cleared iedata and iramcopy areas */
725 #endif /* IRAM_STEAL */
727 /* The plugin wants to stay resident after leaving its main function, e.g.
728 runs from timer or own thread. The callback is registered to later
729 instruct it to free its resources before a new plugin gets loaded. */
730 void plugin_tsr(bool (*exit_callback
)(bool))
732 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
735 char *plugin_get_current_filename(void)
737 return current_plugin
;