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 backlight_set_timeout_plugged
,
139 #ifdef HAVE_REMOTE_LCD
141 lcd_remote_set_contrast
,
142 lcd_remote_clear_display
,
144 lcd_remote_puts_scroll
,
145 lcd_remote_stop_scroll
,
146 lcd_remote_set_drawmode
,
147 lcd_remote_get_drawmode
,
149 lcd_remote_getstringsize
,
150 lcd_remote_drawpixel
,
156 lcd_remote_mono_bitmap_part
,
157 lcd_remote_mono_bitmap
,
159 lcd_remote_puts_style
,
160 lcd_remote_puts_scroll_style
,
161 &lcd_remote_framebuffer
[0][0],
163 lcd_remote_update_rect
,
166 remote_backlight_off
,
169 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
171 {&screens
[SCREEN_MAIN
]},
173 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
174 lcd_remote_set_foreground
,
175 lcd_remote_get_foreground
,
176 lcd_remote_set_background
,
177 lcd_remote_get_background
,
178 lcd_remote_bitmap_part
,
182 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
187 gui_synclist_set_nb_items
,
188 gui_synclist_set_icon_callback
,
189 gui_synclist_get_nb_items
,
190 gui_synclist_get_sel_pos
,
192 gui_synclist_select_item
,
193 gui_synclist_add_item
,
194 gui_synclist_del_item
,
195 gui_synclist_limit_scroll
,
197 gui_synclist_do_button
,
198 gui_synclist_set_title
,
205 #ifdef HAS_BUTTON_HOLD
210 (open_func
)PREFIX(open
),
212 (read_func
)PREFIX(read
),
214 (creat_func
)PREFIX(creat
),
215 (write_func
)PREFIX(write
),
229 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
280 /* special simulator hooks */
281 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
283 sim_lcd_ex_update_rect
,
287 /* strings and memory */
319 #if CONFIG_CODEC == SWCODEC
331 #if CONFIG_CODEC != SWCODEC
335 #if CONFIG_CODEC == SWCODEC
336 &audio_master_sampr_list
[0],
345 pcm_get_bytes_waiting
,
347 #ifdef HAVE_RECORDING
354 pcm_calculate_rec_peaks
,
355 audio_set_recording_gain
,
356 #endif /* HAVE_RECORDING */
357 #if INPUT_SRC_CAPS != 0
358 audio_set_output_source
,
359 audio_set_input_source
,
361 #endif /* CONFIG_CODEC == SWCODEC */
363 /* playback control */
376 audio_has_changed_track
,
378 audio_flush_and_reload_tracks
,
380 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
381 mpeg_get_last_header
,
383 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
384 (CONFIG_CODEC == SWCODEC)
388 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
389 /* MAS communication */
394 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
401 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
407 gui_syncstatusbar_draw
,
415 #ifdef HAVE_LCD_COLOR
419 /* action handling */
433 # if CONFIG_CHARGING == CHARGING_MONITOR
437 #ifdef HAVE_USB_POWER
452 plugin_get_audio_buffer
,
454 plugin_get_current_filename
,
458 #if defined(DEBUG) || defined(SIMULATOR)
461 #ifdef ROCKBOX_HAS_LOGF
470 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
471 peak_meter_scale_value
,
472 peak_meter_set_use_dbfs
,
473 peak_meter_get_use_dbfs
,
475 #ifdef HAVE_LCD_BITMAP
477 screen_dump_set_hook
,
484 #ifdef HAVE_WHEEL_POSITION
489 #ifdef IRIVER_H100_SERIES
490 /* Routines for the iriver_flash -plugin. */
491 detect_original_firmware
,
492 detect_flashed_ramimage
,
493 detect_flashed_romimage
,
495 /* new stuff at the end, sort into place next time
496 the API gets incompatible */
498 #if (CONFIG_CODEC == SWCODEC)
510 int plugin_load(const char* plugin
, void* parameter
)
513 struct plugin_header
*hdr
;
521 #ifdef HAVE_REMOTE_LCD
526 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
, plugin
)) == false )
533 /* not allowing another plugin to load */
537 plugin_loaded
= false;
540 gui_syncsplash(0, ID2P(LANG_WAIT
));
541 strcpy(current_plugin
, plugin
);
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 */
738 char *plugin_get_current_filename(void)
740 return current_plugin
;