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
,
111 lcd_bitmap_transparent_part
,
112 lcd_bitmap_transparent
,
118 lcd_puts_scroll_style
,
119 &lcd_framebuffer
[0][0],
129 backlight_set_timeout
,
131 #ifdef HAVE_REMOTE_LCD
133 lcd_remote_set_contrast
,
134 lcd_remote_clear_display
,
136 lcd_remote_puts_scroll
,
137 lcd_remote_stop_scroll
,
138 lcd_remote_set_drawmode
,
139 lcd_remote_get_drawmode
,
141 lcd_remote_getstringsize
,
142 lcd_remote_drawpixel
,
148 lcd_remote_mono_bitmap_part
,
149 lcd_remote_mono_bitmap
,
151 lcd_remote_puts_style
,
152 lcd_remote_puts_scroll_style
,
153 &lcd_remote_framebuffer
[0][0],
155 lcd_remote_update_rect
,
158 remote_backlight_off
,
161 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
163 {&screens
[SCREEN_MAIN
]},
165 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
166 lcd_remote_set_foreground
,
167 lcd_remote_get_foreground
,
168 lcd_remote_set_background
,
169 lcd_remote_get_background
,
170 lcd_remote_bitmap_part
,
174 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
179 gui_synclist_set_nb_items
,
180 gui_synclist_set_icon_callback
,
181 gui_synclist_get_nb_items
,
182 gui_synclist_get_sel_pos
,
184 gui_synclist_select_item
,
185 gui_synclist_add_item
,
186 gui_synclist_del_item
,
187 gui_synclist_limit_scroll
,
189 gui_synclist_do_button
,
190 gui_synclist_set_title
,
197 #ifdef HAS_BUTTON_HOLD
202 (open_func
)PREFIX(open
),
206 (creat_func
)PREFIX(creat
),
221 create_numbered_filename
,
240 #ifdef HAVE_PRIORITY_SCHEDULING
244 default_event_handler
,
245 default_event_handler_ex
,
249 reset_poweroff_timer
,
254 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
255 #ifdef CPU_BOOST_LOGGING
278 /* special simulator hooks */
279 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
281 sim_lcd_ex_update_rect
,
285 /* strings and memory */
317 #if CONFIG_CODEC == SWCODEC
330 #if CONFIG_CODEC != SWCODEC
334 #if CONFIG_CODEC == SWCODEC
335 &audio_master_sampr_list
[0],
344 pcm_get_bytes_waiting
,
346 #ifdef HAVE_RECORDING
353 pcm_calculate_rec_peaks
,
354 audio_set_recording_gain
,
355 #endif /* HAVE_RECORDING */
356 #if INPUT_SRC_CAPS != 0
357 audio_set_output_source
,
358 audio_set_input_source
,
360 #endif /* CONFIG_CODEC == SWCODEC */
362 /* playback control */
375 audio_has_changed_track
,
377 audio_flush_and_reload_tracks
,
379 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
380 mpeg_get_last_header
,
382 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
383 (CONFIG_CODEC == SWCODEC)
387 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
388 /* MAS communication */
393 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
400 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
406 gui_syncstatusbar_draw
,
412 #ifdef HAVE_LCD_COLOR
416 /* action handling */
419 action_signalscreenchange
,
431 # if CONFIG_CHARGING == CHARGING_MONITOR
435 #ifdef HAVE_USB_POWER
447 plugin_get_audio_buffer
,
452 #if defined(DEBUG) || defined(SIMULATOR)
455 #ifdef ROCKBOX_HAS_LOGF
464 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
465 peak_meter_scale_value
,
466 peak_meter_set_use_dbfs
,
467 peak_meter_get_use_dbfs
,
469 #ifdef HAVE_LCD_BITMAP
471 screen_dump_set_hook
,
476 #ifdef HAVE_WHEEL_POSITION
481 #ifdef IRIVER_H100_SERIES
482 /* Routines for the iriver_flash -plugin. */
483 detect_original_firmware
,
484 detect_flashed_ramimage
,
485 detect_flashed_romimage
,
487 /* new stuff at the end, sort into place next time
488 the API gets incompatible */
495 #if (CONFIG_CODEC == SWCODEC)
502 int plugin_load(const char* plugin
, void* parameter
)
505 struct plugin_header
*hdr
;
506 const char *p
= strrchr(plugin
,'/');
514 #ifdef HAVE_REMOTE_LCD
519 fb_data
* old_backdrop
;
524 action_signalscreenchange();
526 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
528 if (pfn_tsr_exit(!strcmp(current_plugin
,p
)) == false )
530 /* not allowing another plugin to load */
534 plugin_loaded
= false;
537 gui_syncsplash(0, str(LANG_WAIT
));
538 strcpy(current_plugin
,p
);
541 hdr
= sim_plugin_load((char *)plugin
, &pd
);
543 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
547 || hdr
->magic
!= PLUGIN_MAGIC
548 || hdr
->target_id
!= TARGET_ID
) {
549 sim_plugin_close(pd
);
550 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
553 if (hdr
->api_version
> PLUGIN_API_VERSION
554 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
555 sim_plugin_close(pd
);
556 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
560 fd
= open(plugin
, O_RDONLY
);
562 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
566 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
570 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
573 hdr
= (struct plugin_header
*)pluginbuf
;
575 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
576 || hdr
->magic
!= PLUGIN_MAGIC
577 || hdr
->target_id
!= TARGET_ID
578 || hdr
->load_addr
!= pluginbuf
579 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
580 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
583 if (hdr
->api_version
> PLUGIN_API_VERSION
584 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
585 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
588 plugin_size
= hdr
->end_addr
- pluginbuf
;
590 /* zero out bss area only, above guards end of pluginbuf */
591 if (plugin_size
> readsize
)
592 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
595 plugin_loaded
= true;
597 xm
= lcd_getxmargin();
598 ym
= lcd_getymargin();
601 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
602 old_backdrop
= lcd_get_backdrop();
607 #ifdef HAVE_REMOTE_LCD
608 rxm
= lcd_remote_getxmargin();
609 rym
= lcd_remote_getymargin();
610 lcd_remote_setmargins(0, 0);
611 lcd_remote_clear_display();
617 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
618 /* explicitly casting the pointer here to avoid touching every plugin. */
620 action_signalscreenchange();
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 */