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 extern struct thread_entry threads
[MAXTHREADS
];
69 static const struct plugin_api rockbox_api
= {
81 #ifdef HAVE_LCD_CHARCELLS
83 lcd_get_locked_pattern
,
100 lcd_mono_bitmap_part
,
113 lcd_bitmap_transparent_part
,
114 lcd_bitmap_transparent
,
120 lcd_puts_scroll_style
,
121 &lcd_framebuffer
[0][0],
131 backlight_set_timeout
,
133 #ifdef HAVE_REMOTE_LCD
135 lcd_remote_set_contrast
,
136 lcd_remote_clear_display
,
138 lcd_remote_puts_scroll
,
139 lcd_remote_stop_scroll
,
140 lcd_remote_set_drawmode
,
141 lcd_remote_get_drawmode
,
143 lcd_remote_getstringsize
,
144 lcd_remote_drawpixel
,
150 lcd_remote_mono_bitmap_part
,
151 lcd_remote_mono_bitmap
,
153 lcd_remote_puts_style
,
154 lcd_remote_puts_scroll_style
,
155 &lcd_remote_framebuffer
[0][0],
157 lcd_remote_update_rect
,
160 remote_backlight_off
,
163 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
165 {&screens
[SCREEN_MAIN
]},
167 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
168 lcd_remote_set_foreground
,
169 lcd_remote_get_foreground
,
170 lcd_remote_set_background
,
171 lcd_remote_get_background
,
172 lcd_remote_bitmap_part
,
176 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
181 gui_synclist_set_nb_items
,
182 gui_synclist_set_icon_callback
,
183 gui_synclist_get_nb_items
,
184 gui_synclist_get_sel_pos
,
186 gui_synclist_select_item
,
187 gui_synclist_add_item
,
188 gui_synclist_del_item
,
189 gui_synclist_limit_scroll
,
191 gui_synclist_do_button
,
192 gui_synclist_set_title
,
199 #ifdef HAS_BUTTON_HOLD
204 (open_func
)PREFIX(open
),
208 (creat_func
)PREFIX(creat
),
223 create_numbered_filename
,
235 #ifdef HAVE_PRIORITY_SCHEDULING
239 default_event_handler
,
240 default_event_handler_ex
,
244 reset_poweroff_timer
,
249 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
250 #ifdef CPU_BOOST_LOGGING
274 /* special simulator hooks */
275 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
277 sim_lcd_ex_update_rect
,
281 /* strings and memory */
313 #if CONFIG_CODEC == SWCODEC
325 #if CONFIG_CODEC != SWCODEC
329 #if CONFIG_CODEC == SWCODEC
330 &audio_master_sampr_list
[0],
339 pcm_get_bytes_waiting
,
341 #ifdef HAVE_RECORDING
348 pcm_calculate_rec_peaks
,
349 audio_set_recording_gain
,
350 #endif /* HAVE_RECORDING */
351 #if INPUT_SRC_CAPS != 0
352 audio_set_output_source
,
353 audio_set_input_source
,
355 #endif /* CONFIG_CODEC == SWCODEC */
357 /* playback control */
370 audio_has_changed_track
,
372 audio_flush_and_reload_tracks
,
374 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
375 mpeg_get_last_header
,
377 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
378 (CONFIG_CODEC == SWCODEC)
382 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
383 /* MAS communication */
388 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
395 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
401 gui_syncstatusbar_draw
,
409 #ifdef HAVE_LCD_COLOR
413 /* action handling */
427 # if CONFIG_CHARGING == CHARGING_MONITOR
431 #ifdef HAVE_USB_POWER
446 plugin_get_audio_buffer
,
451 #if defined(DEBUG) || defined(SIMULATOR)
454 #ifdef ROCKBOX_HAS_LOGF
463 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
464 peak_meter_scale_value
,
465 peak_meter_set_use_dbfs
,
466 peak_meter_get_use_dbfs
,
468 #ifdef HAVE_LCD_BITMAP
470 screen_dump_set_hook
,
475 #ifdef HAVE_WHEEL_POSITION
480 #ifdef IRIVER_H100_SERIES
481 /* Routines for the iriver_flash -plugin. */
482 detect_original_firmware
,
483 detect_flashed_ramimage
,
484 detect_flashed_romimage
,
486 /* new stuff at the end, sort into place next time
487 the API gets incompatible */
489 #if (CONFIG_CODEC == SWCODEC)
498 #ifdef HAVE_LCD_BITMAP
506 int plugin_load(const char* plugin
, void* parameter
)
509 struct plugin_header
*hdr
;
510 const char *p
= strrchr(plugin
,'/');
518 #ifdef HAVE_REMOTE_LCD
523 fb_data
* old_backdrop
;
529 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
531 if (pfn_tsr_exit(!strcmp(current_plugin
,p
)) == false )
533 /* not allowing another plugin to load */
537 plugin_loaded
= false;
540 gui_syncsplash(0, str(LANG_WAIT
));
541 strcpy(current_plugin
,p
);
544 hdr
= sim_plugin_load((char *)plugin
, &pd
);
546 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
550 || hdr
->magic
!= PLUGIN_MAGIC
551 || hdr
->target_id
!= TARGET_ID
) {
552 sim_plugin_close(pd
);
553 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
556 if (hdr
->api_version
> PLUGIN_API_VERSION
557 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
558 sim_plugin_close(pd
);
559 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
563 fd
= open(plugin
, O_RDONLY
);
565 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
569 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
573 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
576 hdr
= (struct plugin_header
*)pluginbuf
;
578 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
579 || hdr
->magic
!= PLUGIN_MAGIC
580 || hdr
->target_id
!= TARGET_ID
581 || hdr
->load_addr
!= pluginbuf
582 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
583 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
586 if (hdr
->api_version
> PLUGIN_API_VERSION
587 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
588 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
591 plugin_size
= hdr
->end_addr
- pluginbuf
;
593 /* zero out bss area only, above guards end of pluginbuf */
594 if (plugin_size
> readsize
)
595 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
598 plugin_loaded
= true;
600 xm
= lcd_getxmargin();
601 ym
= lcd_getymargin();
604 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
605 old_backdrop
= lcd_get_backdrop();
610 #ifdef HAVE_REMOTE_LCD
611 rxm
= lcd_remote_getxmargin();
612 rym
= lcd_remote_getymargin();
613 lcd_remote_setmargins(0, 0);
614 lcd_remote_clear_display();
620 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
621 /* explicitly casting the pointer here to avoid touching every plugin. */
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 /* writeback cleared iedata and iramcopy areas */
728 #endif /* IRAM_STEAL */
730 /* The plugin wants to stay resident after leaving its main function, e.g.
731 runs from timer or own thread. The callback is registered to later
732 instruct it to free its resources before a new plugin gets loaded. */
733 void plugin_tsr(bool (*exit_callback
)(bool))
735 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */