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)
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)
509 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
514 int plugin_load(const char* plugin
, void* parameter
)
517 struct plugin_header
*hdr
;
525 #ifdef HAVE_REMOTE_LCD
530 fb_data
* old_backdrop
;
533 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
535 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
537 /* not allowing another plugin to load */
541 plugin_loaded
= false;
544 gui_syncsplash(0, ID2P(LANG_WAIT
));
545 strcpy(current_plugin
, plugin
);
548 hdr
= sim_plugin_load((char *)plugin
, &pd
);
550 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
554 || hdr
->magic
!= PLUGIN_MAGIC
555 || hdr
->target_id
!= TARGET_ID
) {
556 sim_plugin_close(pd
);
557 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
560 if (hdr
->api_version
> PLUGIN_API_VERSION
561 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
562 sim_plugin_close(pd
);
563 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
567 fd
= open(plugin
, O_RDONLY
);
569 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
573 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
577 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
580 hdr
= (struct plugin_header
*)pluginbuf
;
582 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
583 || hdr
->magic
!= PLUGIN_MAGIC
584 || hdr
->target_id
!= TARGET_ID
585 || hdr
->load_addr
!= pluginbuf
586 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
587 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
590 if (hdr
->api_version
> PLUGIN_API_VERSION
591 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
592 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
595 plugin_size
= hdr
->end_addr
- pluginbuf
;
597 /* zero out bss area only, above guards end of pluginbuf */
598 if (plugin_size
> readsize
)
599 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
602 plugin_loaded
= true;
604 xm
= lcd_getxmargin();
605 ym
= lcd_getymargin();
608 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
609 old_backdrop
= lcd_get_backdrop();
614 #ifdef HAVE_REMOTE_LCD
615 rxm
= lcd_remote_getxmargin();
616 rym
= lcd_remote_getymargin();
617 lcd_remote_setmargins(0, 0);
618 lcd_remote_clear_display();
624 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
625 /* explicitly casting the pointer here to avoid touching every plugin. */
627 button_clear_queue();
629 #ifdef HAVE_LCD_BITMAP
631 lcd_set_backdrop(old_backdrop
);
632 #ifdef HAVE_LCD_COLOR
633 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
634 global_settings
.bg_color
);
636 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
638 #else /* LCD_DEPTH == 1 */
639 lcd_set_drawmode(DRMODE_SOLID
);
640 #endif /* LCD_DEPTH */
641 #endif /* HAVE_LCD_BITMAP */
643 /* restore margins */
644 lcd_setmargins(xm
,ym
);
648 #ifdef HAVE_REMOTE_LCD
649 #if LCD_REMOTE_DEPTH > 1
650 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
651 LCD_REMOTE_DEFAULT_BG
);
653 lcd_remote_set_drawmode(DRMODE_SOLID
);
655 lcd_remote_setmargins(rxm
, rym
);
656 lcd_remote_clear_display();
660 if (pfn_tsr_exit
== NULL
)
661 plugin_loaded
= false;
663 sim_plugin_close(pd
);
669 case PLUGIN_USB_CONNECTED
:
670 return PLUGIN_USB_CONNECTED
;
673 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
679 /* Returns a pointer to the portion of the plugin buffer that is not already
680 being used. If no plugin is loaded, returns the entire plugin buffer */
681 void* plugin_get_buffer(size_t *buffer_size
)
687 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
690 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
691 buffer_pos
= plugin_size
;
695 *buffer_size
= PLUGIN_BUFFER_SIZE
;
699 return &pluginbuf
[buffer_pos
];
702 /* Returns a pointer to the mp3 buffer.
703 Playback gets stopped, to avoid conflicts.
704 Talk buffer is stolen as well.
706 void* plugin_get_audio_buffer(size_t *buffer_size
)
708 #if CONFIG_CODEC == SWCODEC
709 return audio_get_buffer(true, buffer_size
);
712 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
713 *buffer_size
= audiobufend
- audiobuf
;
719 /* Initializes plugin IRAM */
720 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
721 char *iedata
, size_t iedata_size
)
724 memcpy(iramstart
, iramcopy
, iram_size
);
725 memset(iedata
, 0, iedata_size
);
726 memset(iramcopy
, 0, iram_size
);
728 /* writeback cleared iedata and iramcopy areas */
732 #endif /* IRAM_STEAL */
734 /* The plugin wants to stay resident after leaving its main function, e.g.
735 runs from timer or own thread. The callback is registered to later
736 instruct it to free its resources before a new plugin gets loaded. */
737 void plugin_tsr(bool (*exit_callback
)(bool))
739 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
742 char *plugin_get_current_filename(void)
744 return current_plugin
;