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 extern struct thread_entry threads
[MAXTHREADS
];
67 static const struct plugin_api rockbox_api
= {
79 #ifdef HAVE_LCD_CHARCELLS
81 lcd_get_locked_pattern
,
110 lcd_bitmap_transparent_part
,
111 lcd_bitmap_transparent
,
117 lcd_puts_scroll_style
,
118 &lcd_framebuffer
[0][0],
128 backlight_set_timeout
,
130 #ifdef HAVE_REMOTE_LCD
132 lcd_remote_set_contrast
,
133 lcd_remote_clear_display
,
135 lcd_remote_puts_scroll
,
136 lcd_remote_stop_scroll
,
137 lcd_remote_set_drawmode
,
138 lcd_remote_get_drawmode
,
140 lcd_remote_getstringsize
,
141 lcd_remote_drawpixel
,
147 lcd_remote_mono_bitmap_part
,
148 lcd_remote_mono_bitmap
,
150 lcd_remote_puts_style
,
151 lcd_remote_puts_scroll_style
,
152 &lcd_remote_framebuffer
[0][0],
154 lcd_remote_update_rect
,
157 remote_backlight_off
,
160 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
162 {&screens
[SCREEN_MAIN
]},
164 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
165 lcd_remote_set_foreground
,
166 lcd_remote_get_foreground
,
167 lcd_remote_set_background
,
168 lcd_remote_get_background
,
169 lcd_remote_bitmap_part
,
173 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
178 gui_synclist_set_nb_items
,
179 gui_synclist_set_icon_callback
,
180 gui_synclist_get_nb_items
,
181 gui_synclist_get_sel_pos
,
183 gui_synclist_select_item
,
184 gui_synclist_add_item
,
185 gui_synclist_del_item
,
186 gui_synclist_limit_scroll
,
188 gui_synclist_do_button
,
189 gui_synclist_set_title
,
196 #ifdef HAS_BUTTON_HOLD
201 (open_func
)PREFIX(open
),
205 (creat_func
)PREFIX(creat
),
238 #ifdef HAVE_PRIORITY_SCHEDULING
242 default_event_handler
,
243 default_event_handler_ex
,
246 reset_poweroff_timer
,
251 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
252 #ifdef CPU_BOOST_LOGGING
275 /* special simulator hooks */
276 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
278 sim_lcd_ex_update_rect
,
282 /* strings and memory */
314 #if CONFIG_CODEC == SWCODEC
327 #if CONFIG_CODEC != SWCODEC
331 #if CONFIG_CODEC == SWCODEC
332 &audio_master_sampr_list
[0],
341 pcm_get_bytes_waiting
,
343 #ifdef HAVE_RECORDING
350 pcm_calculate_rec_peaks
,
351 audio_set_recording_gain
,
352 #endif /* HAVE_RECORDING */
353 #if INPUT_SRC_CAPS != 0
354 audio_set_output_source
,
355 audio_set_input_source
,
357 #endif /* CONFIG_CODEC == SWCODEC */
359 /* playback control */
372 audio_has_changed_track
,
374 audio_flush_and_reload_tracks
,
376 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
377 mpeg_get_last_header
,
379 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
380 (CONFIG_CODEC == SWCODEC)
384 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
385 /* MAS communication */
390 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
397 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
403 gui_syncstatusbar_draw
,
409 /* action handling */
412 action_signalscreenchange
,
424 # if CONFIG_CHARGING == CHARGING_MONITOR
428 #ifdef HAVE_USB_POWER
440 plugin_get_audio_buffer
,
445 #if defined(DEBUG) || defined(SIMULATOR)
448 #ifdef ROCKBOX_HAS_LOGF
457 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
458 peak_meter_scale_value
,
459 peak_meter_set_use_dbfs
,
460 peak_meter_get_use_dbfs
,
462 #ifdef HAVE_LCD_BITMAP
464 screen_dump_set_hook
,
469 #ifdef HAVE_WHEEL_POSITION
477 /* new stuff at the end, sort into place next time
478 the API gets incompatible */
480 #ifdef IRIVER_H100_SERIES
481 /* Routines for the iriver_flash -plugin. */
482 detect_original_firmware
,
483 detect_flashed_ramimage
,
484 detect_flashed_romimage
,
493 #if (CONFIG_CODEC == SWCODEC)
499 create_numbered_filename
,
501 #ifdef HAVE_LCD_COLOR
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
;
528 action_signalscreenchange();
530 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
532 if (pfn_tsr_exit(!strcmp(current_plugin
,p
)) == false )
534 /* not allowing another plugin to load */
538 plugin_loaded
= false;
541 gui_syncsplash(0, str(LANG_WAIT
));
542 strcpy(current_plugin
,p
);
545 hdr
= sim_plugin_load((char *)plugin
, &pd
);
547 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
551 || hdr
->magic
!= PLUGIN_MAGIC
552 || hdr
->target_id
!= TARGET_ID
) {
553 sim_plugin_close(pd
);
554 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
557 if (hdr
->api_version
> PLUGIN_API_VERSION
558 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
559 sim_plugin_close(pd
);
560 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
564 fd
= open(plugin
, O_RDONLY
);
566 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
570 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
574 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
577 hdr
= (struct plugin_header
*)pluginbuf
;
579 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
580 || hdr
->magic
!= PLUGIN_MAGIC
581 || hdr
->target_id
!= TARGET_ID
582 || hdr
->load_addr
!= pluginbuf
583 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
584 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
587 if (hdr
->api_version
> PLUGIN_API_VERSION
588 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
589 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
592 plugin_size
= hdr
->end_addr
- pluginbuf
;
594 /* zero out bss area only, above guards end of pluginbuf */
595 if (plugin_size
> readsize
)
596 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
599 plugin_loaded
= true;
601 xm
= lcd_getxmargin();
602 ym
= lcd_getymargin();
605 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
606 old_backdrop
= lcd_get_backdrop();
611 #ifdef HAVE_REMOTE_LCD
612 rxm
= lcd_remote_getxmargin();
613 rym
= lcd_remote_getymargin();
614 lcd_remote_setmargins(0, 0);
615 lcd_remote_clear_display();
621 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
622 /* explicitly casting the pointer here to avoid touching every plugin. */
624 action_signalscreenchange();
625 button_clear_queue();
627 #ifdef HAVE_LCD_BITMAP
629 lcd_set_backdrop(old_backdrop
);
630 #ifdef HAVE_LCD_COLOR
631 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
632 global_settings
.bg_color
);
634 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
636 #else /* LCD_DEPTH == 1 */
637 lcd_set_drawmode(DRMODE_SOLID
);
638 #endif /* LCD_DEPTH */
639 #endif /* HAVE_LCD_BITMAP */
641 /* restore margins */
642 lcd_setmargins(xm
,ym
);
646 #ifdef HAVE_REMOTE_LCD
647 #if LCD_REMOTE_DEPTH > 1
648 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
649 LCD_REMOTE_DEFAULT_BG
);
651 lcd_remote_set_drawmode(DRMODE_SOLID
);
653 lcd_remote_setmargins(rxm
, rym
);
654 lcd_remote_clear_display();
658 if (pfn_tsr_exit
== NULL
)
659 plugin_loaded
= false;
661 sim_plugin_close(pd
);
667 case PLUGIN_USB_CONNECTED
:
668 return PLUGIN_USB_CONNECTED
;
671 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
677 /* Returns a pointer to the portion of the plugin buffer that is not already
678 being used. If no plugin is loaded, returns the entire plugin buffer */
679 void* plugin_get_buffer(size_t *buffer_size
)
685 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
688 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
689 buffer_pos
= plugin_size
;
693 *buffer_size
= PLUGIN_BUFFER_SIZE
;
697 return &pluginbuf
[buffer_pos
];
700 /* Returns a pointer to the mp3 buffer.
701 Playback gets stopped, to avoid conflicts.
702 Talk buffer is stolen as well.
704 void* plugin_get_audio_buffer(size_t *buffer_size
)
706 #if CONFIG_CODEC == SWCODEC
707 return audio_get_buffer(true, buffer_size
);
710 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
711 *buffer_size
= audiobufend
- audiobuf
;
717 /* Initializes plugin IRAM */
718 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
719 char *iedata
, size_t iedata_size
)
722 memcpy(iramstart
, iramcopy
, iram_size
);
723 memset(iedata
, 0, iedata_size
);
724 memset(iramcopy
, 0, iram_size
);
726 #endif /* IRAM_STEAL */
728 /* The plugin wants to stay resident after leaving its main function, e.g.
729 runs from timer or own thread. The callback is registered to later
730 instruct it to free its resources before a new plugin gets loaded. */
731 void plugin_tsr(bool (*exit_callback
)(bool))
733 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */