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)
513 #ifdef CACHE_FUNCTIONS_AS_CALL
519 int plugin_load(const char* plugin
, void* parameter
)
522 struct plugin_header
*hdr
;
530 #ifdef HAVE_REMOTE_LCD
535 fb_data
* old_backdrop
;
538 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
540 if (pfn_tsr_exit(!strcmp(current_plugin
, plugin
)) == false )
542 /* not allowing another plugin to load */
546 plugin_loaded
= false;
549 gui_syncsplash(0, ID2P(LANG_WAIT
));
550 strcpy(current_plugin
, plugin
);
553 hdr
= sim_plugin_load((char *)plugin
, &pd
);
555 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
559 || hdr
->magic
!= PLUGIN_MAGIC
560 || hdr
->target_id
!= TARGET_ID
) {
561 sim_plugin_close(pd
);
562 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
565 if (hdr
->api_version
> PLUGIN_API_VERSION
566 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
567 sim_plugin_close(pd
);
568 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
572 fd
= open(plugin
, O_RDONLY
);
574 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
578 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
582 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
585 hdr
= (struct plugin_header
*)pluginbuf
;
587 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
588 || hdr
->magic
!= PLUGIN_MAGIC
589 || hdr
->target_id
!= TARGET_ID
590 || hdr
->load_addr
!= pluginbuf
591 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
592 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
595 if (hdr
->api_version
> PLUGIN_API_VERSION
596 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
597 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
600 plugin_size
= hdr
->end_addr
- pluginbuf
;
602 /* zero out bss area only, above guards end of pluginbuf */
603 if (plugin_size
> readsize
)
604 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
607 plugin_loaded
= true;
609 xm
= lcd_getxmargin();
610 ym
= lcd_getymargin();
613 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
614 old_backdrop
= lcd_get_backdrop();
619 #ifdef HAVE_REMOTE_LCD
620 rxm
= lcd_remote_getxmargin();
621 rym
= lcd_remote_getymargin();
622 lcd_remote_setmargins(0, 0);
623 lcd_remote_clear_display();
629 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
630 /* explicitly casting the pointer here to avoid touching every plugin. */
632 button_clear_queue();
634 #ifdef HAVE_LCD_BITMAP
636 lcd_set_backdrop(old_backdrop
);
637 #ifdef HAVE_LCD_COLOR
638 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
639 global_settings
.bg_color
);
641 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
643 #else /* LCD_DEPTH == 1 */
644 lcd_set_drawmode(DRMODE_SOLID
);
645 #endif /* LCD_DEPTH */
646 #endif /* HAVE_LCD_BITMAP */
648 /* restore margins */
649 lcd_setmargins(xm
,ym
);
653 #ifdef HAVE_REMOTE_LCD
654 #if LCD_REMOTE_DEPTH > 1
655 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
656 LCD_REMOTE_DEFAULT_BG
);
658 lcd_remote_set_drawmode(DRMODE_SOLID
);
660 lcd_remote_setmargins(rxm
, rym
);
661 lcd_remote_clear_display();
665 if (pfn_tsr_exit
== NULL
)
666 plugin_loaded
= false;
668 sim_plugin_close(pd
);
674 case PLUGIN_USB_CONNECTED
:
675 return PLUGIN_USB_CONNECTED
;
678 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
684 /* Returns a pointer to the portion of the plugin buffer that is not already
685 being used. If no plugin is loaded, returns the entire plugin buffer */
686 void* plugin_get_buffer(size_t *buffer_size
)
692 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
695 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
696 buffer_pos
= plugin_size
;
700 *buffer_size
= PLUGIN_BUFFER_SIZE
;
704 return &pluginbuf
[buffer_pos
];
707 /* Returns a pointer to the mp3 buffer.
708 Playback gets stopped, to avoid conflicts.
709 Talk buffer is stolen as well.
711 void* plugin_get_audio_buffer(size_t *buffer_size
)
713 #if CONFIG_CODEC == SWCODEC
714 return audio_get_buffer(true, buffer_size
);
717 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
718 *buffer_size
= audiobufend
- audiobuf
;
724 /* Initializes plugin IRAM */
725 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
726 char *iedata
, size_t iedata_size
)
729 memcpy(iramstart
, iramcopy
, iram_size
);
730 memset(iedata
, 0, iedata_size
);
731 memset(iramcopy
, 0, iram_size
);
733 /* writeback cleared iedata and iramcopy areas */
737 #endif /* IRAM_STEAL */
739 /* The plugin wants to stay resident after leaving its main function, e.g.
740 runs from timer or own thread. The callback is registered to later
741 instruct it to free its resources before a new plugin gets loaded. */
742 void plugin_tsr(bool (*exit_callback
)(bool))
744 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */
747 char *plugin_get_current_filename(void)
749 return current_plugin
;