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 static const struct plugin_api rockbox_api
= {
76 #ifdef HAVE_LCD_CHARCELLS
78 lcd_get_locked_pattern
,
107 lcd_bitmap_transparent_part
,
108 lcd_bitmap_transparent
,
114 lcd_puts_scroll_style
,
115 &lcd_framebuffer
[0][0],
126 backlight_set_timeout
,
128 #ifdef HAVE_REMOTE_LCD
130 lcd_remote_set_contrast
,
131 lcd_remote_clear_display
,
133 lcd_remote_puts_scroll
,
134 lcd_remote_stop_scroll
,
135 lcd_remote_set_drawmode
,
136 lcd_remote_get_drawmode
,
138 lcd_remote_getstringsize
,
139 lcd_remote_drawpixel
,
145 lcd_remote_mono_bitmap_part
,
146 lcd_remote_mono_bitmap
,
148 lcd_remote_puts_style
,
149 lcd_remote_puts_scroll_style
,
150 &lcd_remote_framebuffer
[0][0],
152 lcd_remote_update_rect
,
155 remote_backlight_off
,
158 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
160 {&screens
[SCREEN_MAIN
]},
162 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
163 lcd_remote_set_foreground
,
164 lcd_remote_get_foreground
,
165 lcd_remote_set_background
,
166 lcd_remote_get_background
,
167 lcd_remote_bitmap_part
,
171 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
176 gui_synclist_set_nb_items
,
177 gui_synclist_set_icon_callback
,
178 gui_synclist_get_nb_items
,
179 gui_synclist_get_sel_pos
,
181 gui_synclist_select_item
,
182 gui_synclist_add_item
,
183 gui_synclist_del_item
,
184 gui_synclist_limit_scroll
,
186 gui_synclist_do_button
,
187 gui_synclist_set_title
,
194 #ifdef HAS_BUTTON_HOLD
199 (open_func
)PREFIX(open
),
203 (creat_func
)PREFIX(creat
),
237 default_event_handler
,
238 default_event_handler_ex
,
241 reset_poweroff_timer
,
246 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
247 #ifdef CPU_BOOST_LOGGING
270 /* special simulator hooks */
271 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
273 sim_lcd_ex_update_rect
,
277 /* strings and memory */
319 #if CONFIG_CODEC != SWCODEC
323 #if CONFIG_CODEC == SWCODEC
330 #if CONFIG_CODEC == SWCODEC
334 /* playback control */
345 audio_has_changed_track
,
347 audio_flush_and_reload_tracks
,
349 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
350 mpeg_get_last_header
,
352 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
353 (CONFIG_CODEC == SWCODEC)
357 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
358 /* MAS communication */
363 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
370 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
374 /* OLD API - dont use unless you have to */
384 /* action handling */
387 action_signalscreenchange
,
399 # if CONFIG_CHARGING == CHARGING_MONITOR
403 #ifdef HAVE_USB_POWER
415 plugin_get_audio_buffer
,
417 #if defined(DEBUG) || defined(SIMULATOR)
420 #ifdef ROCKBOX_HAS_LOGF
428 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
429 peak_meter_scale_value
,
430 peak_meter_set_use_dbfs
,
431 peak_meter_get_use_dbfs
,
433 #ifdef HAVE_LCD_BITMAP
435 screen_dump_set_hook
,
440 #ifdef HAVE_WHEEL_POSITION
447 /* new stuff at the end, sort into place next time
448 the API gets incompatible */
450 /* Keep these at the bottom till fully proven */
451 #if CONFIG_CODEC == SWCODEC
452 &audio_master_sampr_list
[0],
457 #ifdef HAVE_RECORDING
464 pcm_calculate_rec_peaks
,
465 audio_set_recording_gain
,
466 audio_set_output_source
,
469 #endif /* HAVE_RECORDING */
470 #endif /* CONFIG_CODEC == SWCODEC */
476 #if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) && !defined(SIMULATOR)
481 #ifdef IRIVER_H100_SERIES
482 /* Routines for the iriver_flash -plugin. */
483 detect_original_firmware
,
484 detect_flashed_ramimage
,
485 detect_flashed_romimage
,
491 #if CONFIG_CODEC == SWCODEC
492 pcm_get_bytes_waiting
,
496 int plugin_load(const char* plugin
, void* parameter
)
499 struct plugin_header
*hdr
;
500 const char *p
= strrchr(plugin
,'/');
507 #ifdef HAVE_LCD_BITMAP
510 #ifdef HAVE_REMOTE_LCD
515 fb_data
* old_backdrop
;
520 action_signalscreenchange();
522 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
524 if (pfn_tsr_exit(!strcmp(current_plugin
,p
)) == false )
526 /* not allowing another plugin to load */
530 plugin_loaded
= false;
533 gui_syncsplash(0, str(LANG_WAIT
));
534 strcpy(current_plugin
,p
);
537 hdr
= sim_plugin_load((char *)plugin
, &pd
);
539 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
543 || hdr
->magic
!= PLUGIN_MAGIC
544 || hdr
->target_id
!= TARGET_ID
) {
545 sim_plugin_close(pd
);
546 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
549 if (hdr
->api_version
> PLUGIN_API_VERSION
550 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
551 sim_plugin_close(pd
);
552 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
556 fd
= open(plugin
, O_RDONLY
);
558 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
562 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
566 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
569 hdr
= (struct plugin_header
*)pluginbuf
;
571 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
572 || hdr
->magic
!= PLUGIN_MAGIC
573 || hdr
->target_id
!= TARGET_ID
574 || hdr
->load_addr
!= pluginbuf
575 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
576 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
579 if (hdr
->api_version
> PLUGIN_API_VERSION
580 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
581 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
584 plugin_size
= hdr
->end_addr
- pluginbuf
;
586 /* zero out bss area only, above guards end of pluginbuf */
587 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
590 plugin_loaded
= true;
592 #ifdef HAVE_LCD_BITMAP
593 xm
= lcd_getxmargin();
594 ym
= lcd_getymargin();
598 old_backdrop
= lcd_get_backdrop();
603 #else /* !HAVE_LCD_BITMAP */
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 /* restore margins */
635 lcd_setmargins(xm
,ym
);
638 #endif /* HAVE_LCD_BITMAP */
640 #ifdef HAVE_REMOTE_LCD
641 #if LCD_REMOTE_DEPTH > 1
642 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
643 LCD_REMOTE_DEFAULT_BG
);
645 lcd_remote_set_drawmode(DRMODE_SOLID
);
647 lcd_remote_setmargins(rxm
, rym
);
648 lcd_remote_clear_display();
651 action_signalscreenchange();
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(int* 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(int* buffer_size
)
701 #if CONFIG_CODEC == SWCODEC
702 return audio_get_buffer(true, (size_t *)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 */