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 extern struct thread_entry threads
[MAXTHREADS
];
69 static const struct plugin_api rockbox_api
= {
81 #ifdef HAVE_LCD_CHARCELLS
83 lcd_get_locked_pattern
,
100 lcd_mono_bitmap_part
,
113 lcd_bitmap_transparent_part
,
114 lcd_bitmap_transparent
,
120 lcd_puts_scroll_style
,
121 &lcd_framebuffer
[0][0],
131 backlight_set_timeout
,
133 #ifdef HAVE_REMOTE_LCD
135 lcd_remote_set_contrast
,
136 lcd_remote_clear_display
,
138 lcd_remote_puts_scroll
,
139 lcd_remote_stop_scroll
,
140 lcd_remote_set_drawmode
,
141 lcd_remote_get_drawmode
,
143 lcd_remote_getstringsize
,
144 lcd_remote_drawpixel
,
150 lcd_remote_mono_bitmap_part
,
151 lcd_remote_mono_bitmap
,
153 lcd_remote_puts_style
,
154 lcd_remote_puts_scroll_style
,
155 &lcd_remote_framebuffer
[0][0],
157 lcd_remote_update_rect
,
160 remote_backlight_off
,
163 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
165 {&screens
[SCREEN_MAIN
]},
167 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
168 lcd_remote_set_foreground
,
169 lcd_remote_get_foreground
,
170 lcd_remote_set_background
,
171 lcd_remote_get_background
,
172 lcd_remote_bitmap_part
,
176 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
181 gui_synclist_set_nb_items
,
182 gui_synclist_set_icon_callback
,
183 gui_synclist_get_nb_items
,
184 gui_synclist_get_sel_pos
,
186 gui_synclist_select_item
,
187 gui_synclist_add_item
,
188 gui_synclist_del_item
,
189 gui_synclist_limit_scroll
,
191 gui_synclist_do_button
,
192 gui_synclist_set_title
,
199 #ifdef HAS_BUTTON_HOLD
204 (open_func
)PREFIX(open
),
208 (creat_func
)PREFIX(creat
),
223 create_numbered_filename
,
235 #ifdef HAVE_PRIORITY_SCHEDULING
239 default_event_handler
,
240 default_event_handler_ex
,
244 reset_poweroff_timer
,
249 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
250 #ifdef CPU_BOOST_LOGGING
274 /* special simulator hooks */
275 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
277 sim_lcd_ex_update_rect
,
281 /* strings and memory */
313 #if CONFIG_CODEC == SWCODEC
325 #if CONFIG_CODEC != SWCODEC
329 #if CONFIG_CODEC == SWCODEC
330 &audio_master_sampr_list
[0],
339 pcm_get_bytes_waiting
,
341 #ifdef HAVE_RECORDING
348 pcm_calculate_rec_peaks
,
349 audio_set_recording_gain
,
350 #endif /* HAVE_RECORDING */
351 #if INPUT_SRC_CAPS != 0
352 audio_set_output_source
,
353 audio_set_input_source
,
355 #endif /* CONFIG_CODEC == SWCODEC */
357 /* playback control */
370 audio_has_changed_track
,
372 audio_flush_and_reload_tracks
,
374 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
375 mpeg_get_last_header
,
377 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
378 (CONFIG_CODEC == SWCODEC)
382 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
383 /* MAS communication */
388 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
395 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
401 gui_syncstatusbar_draw
,
409 #ifdef HAVE_LCD_COLOR
413 /* action handling */
427 # if CONFIG_CHARGING == CHARGING_MONITOR
431 #ifdef HAVE_USB_POWER
446 plugin_get_audio_buffer
,
451 #if defined(DEBUG) || defined(SIMULATOR)
454 #ifdef ROCKBOX_HAS_LOGF
463 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
464 peak_meter_scale_value
,
465 peak_meter_set_use_dbfs
,
466 peak_meter_get_use_dbfs
,
468 #ifdef HAVE_LCD_BITMAP
470 screen_dump_set_hook
,
475 #ifdef HAVE_WHEEL_POSITION
480 #ifdef IRIVER_H100_SERIES
481 /* Routines for the iriver_flash -plugin. */
482 detect_original_firmware
,
483 detect_flashed_ramimage
,
484 detect_flashed_romimage
,
486 /* new stuff at the end, sort into place next time
487 the API gets incompatible */
489 #if (CONFIG_CODEC == SWCODEC)
498 #ifdef HAVE_LCD_BITMAP
504 int plugin_load(const char* plugin
, void* parameter
)
507 struct plugin_header
*hdr
;
508 const char *p
= strrchr(plugin
,'/');
516 #ifdef HAVE_REMOTE_LCD
521 fb_data
* old_backdrop
;
527 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
529 if (pfn_tsr_exit(!strcmp(current_plugin
,p
)) == false )
531 /* not allowing another plugin to load */
535 plugin_loaded
= false;
538 gui_syncsplash(0, str(LANG_WAIT
));
539 strcpy(current_plugin
,p
);
542 hdr
= sim_plugin_load((char *)plugin
, &pd
);
544 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
548 || hdr
->magic
!= PLUGIN_MAGIC
549 || hdr
->target_id
!= TARGET_ID
) {
550 sim_plugin_close(pd
);
551 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
554 if (hdr
->api_version
> PLUGIN_API_VERSION
555 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
556 sim_plugin_close(pd
);
557 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
561 fd
= open(plugin
, O_RDONLY
);
563 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
567 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
571 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
574 hdr
= (struct plugin_header
*)pluginbuf
;
576 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
577 || hdr
->magic
!= PLUGIN_MAGIC
578 || hdr
->target_id
!= TARGET_ID
579 || hdr
->load_addr
!= pluginbuf
580 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
581 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
584 if (hdr
->api_version
> PLUGIN_API_VERSION
585 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
586 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
589 plugin_size
= hdr
->end_addr
- pluginbuf
;
591 /* zero out bss area only, above guards end of pluginbuf */
592 if (plugin_size
> readsize
)
593 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
596 plugin_loaded
= true;
598 xm
= lcd_getxmargin();
599 ym
= lcd_getymargin();
602 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
603 old_backdrop
= lcd_get_backdrop();
608 #ifdef HAVE_REMOTE_LCD
609 rxm
= lcd_remote_getxmargin();
610 rym
= lcd_remote_getymargin();
611 lcd_remote_setmargins(0, 0);
612 lcd_remote_clear_display();
618 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
619 /* explicitly casting the pointer here to avoid touching every plugin. */
621 button_clear_queue();
623 #ifdef HAVE_LCD_BITMAP
625 lcd_set_backdrop(old_backdrop
);
626 #ifdef HAVE_LCD_COLOR
627 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
628 global_settings
.bg_color
);
630 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
632 #else /* LCD_DEPTH == 1 */
633 lcd_set_drawmode(DRMODE_SOLID
);
634 #endif /* LCD_DEPTH */
635 #endif /* HAVE_LCD_BITMAP */
637 /* restore margins */
638 lcd_setmargins(xm
,ym
);
642 #ifdef HAVE_REMOTE_LCD
643 #if LCD_REMOTE_DEPTH > 1
644 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
645 LCD_REMOTE_DEFAULT_BG
);
647 lcd_remote_set_drawmode(DRMODE_SOLID
);
649 lcd_remote_setmargins(rxm
, rym
);
650 lcd_remote_clear_display();
654 if (pfn_tsr_exit
== NULL
)
655 plugin_loaded
= false;
657 sim_plugin_close(pd
);
663 case PLUGIN_USB_CONNECTED
:
664 return PLUGIN_USB_CONNECTED
;
667 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
673 /* Returns a pointer to the portion of the plugin buffer that is not already
674 being used. If no plugin is loaded, returns the entire plugin buffer */
675 void* plugin_get_buffer(size_t *buffer_size
)
681 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
684 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
685 buffer_pos
= plugin_size
;
689 *buffer_size
= PLUGIN_BUFFER_SIZE
;
693 return &pluginbuf
[buffer_pos
];
696 /* Returns a pointer to the mp3 buffer.
697 Playback gets stopped, to avoid conflicts.
698 Talk buffer is stolen as well.
700 void* plugin_get_audio_buffer(size_t *buffer_size
)
702 #if CONFIG_CODEC == SWCODEC
703 return audio_get_buffer(true, buffer_size
);
706 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
707 *buffer_size
= audiobufend
- audiobuf
;
713 /* Initializes plugin IRAM */
714 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
715 char *iedata
, size_t iedata_size
)
718 memcpy(iramstart
, iramcopy
, iram_size
);
719 memset(iedata
, 0, iedata_size
);
720 memset(iramcopy
, 0, iram_size
);
722 #endif /* IRAM_STEAL */
724 /* The plugin wants to stay resident after leaving its main function, e.g.
725 runs from timer or own thread. The callback is registered to later
726 instruct it to free its resources before a new plugin gets loaded. */
727 void plugin_tsr(bool (*exit_callback
)(bool))
729 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */