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 static const struct plugin_api rockbox_api
= {
77 #ifdef HAVE_LCD_CHARCELLS
79 lcd_get_locked_pattern
,
108 lcd_bitmap_transparent_part
,
109 lcd_bitmap_transparent
,
115 lcd_puts_scroll_style
,
116 &lcd_framebuffer
[0][0],
126 backlight_set_timeout
,
128 #ifdef HAVE_REMOTE_LCD
130 lcd_remote_set_contrast
,
131 lcd_remote_clear_display
,
133 lcd_remote_puts_scroll
,
134 lcd_remote_stop_scroll
,
135 lcd_remote_set_drawmode
,
136 lcd_remote_get_drawmode
,
138 lcd_remote_getstringsize
,
139 lcd_remote_drawpixel
,
145 lcd_remote_mono_bitmap_part
,
146 lcd_remote_mono_bitmap
,
148 lcd_remote_puts_style
,
149 lcd_remote_puts_scroll_style
,
150 &lcd_remote_framebuffer
[0][0],
152 lcd_remote_update_rect
,
155 remote_backlight_off
,
158 {&screens
[SCREEN_MAIN
], &screens
[SCREEN_REMOTE
]},
160 {&screens
[SCREEN_MAIN
]},
162 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
163 lcd_remote_set_foreground
,
164 lcd_remote_get_foreground
,
165 lcd_remote_set_background
,
166 lcd_remote_get_background
,
167 lcd_remote_bitmap_part
,
171 #if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR)
176 gui_synclist_set_nb_items
,
177 gui_synclist_set_icon_callback
,
178 gui_synclist_get_nb_items
,
179 gui_synclist_get_sel_pos
,
181 gui_synclist_select_item
,
182 gui_synclist_add_item
,
183 gui_synclist_del_item
,
184 gui_synclist_limit_scroll
,
186 gui_synclist_do_button
,
187 gui_synclist_set_title
,
194 #ifdef HAS_BUTTON_HOLD
199 (open_func
)PREFIX(open
),
203 (creat_func
)PREFIX(creat
),
236 #ifdef HAVE_PRIORITY_SCHEDULING
240 default_event_handler
,
241 default_event_handler_ex
,
244 reset_poweroff_timer
,
249 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
250 #ifdef CPU_BOOST_LOGGING
273 /* special simulator hooks */
274 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
276 sim_lcd_ex_update_rect
,
280 /* strings and memory */
312 #if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
325 #if CONFIG_CODEC != SWCODEC
329 #if CONFIG_CODEC == SWCODEC
330 &audio_master_sampr_list
[0],
341 pcm_get_bytes_waiting
,
343 #ifdef HAVE_RECORDING
351 pcm_calculate_rec_peaks
,
352 audio_set_recording_gain
,
353 audio_set_output_source
,
356 #endif /* HAVE_RECORDING */
360 /* playback control */
373 audio_has_changed_track
,
375 audio_flush_and_reload_tracks
,
377 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
378 mpeg_get_last_header
,
380 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
381 (CONFIG_CODEC == SWCODEC)
385 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
386 /* MAS communication */
391 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
398 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
402 /* OLD API - dont use unless you have to */
412 /* action handling */
415 action_signalscreenchange
,
427 # if CONFIG_CHARGING == CHARGING_MONITOR
431 #ifdef HAVE_USB_POWER
443 plugin_get_audio_buffer
,
448 #if defined(DEBUG) || defined(SIMULATOR)
451 #ifdef ROCKBOX_HAS_LOGF
460 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
461 peak_meter_scale_value
,
462 peak_meter_set_use_dbfs
,
463 peak_meter_get_use_dbfs
,
465 #ifdef HAVE_LCD_BITMAP
467 screen_dump_set_hook
,
472 #ifdef HAVE_WHEEL_POSITION
480 /* new stuff at the end, sort into place next time
481 the API gets incompatible */
483 #ifdef IRIVER_H100_SERIES
484 /* Routines for the iriver_flash -plugin. */
485 detect_original_firmware
,
486 detect_flashed_ramimage
,
487 detect_flashed_romimage
,
491 int plugin_load(const char* plugin
, void* parameter
)
494 struct plugin_header
*hdr
;
495 const char *p
= strrchr(plugin
,'/');
503 #ifdef HAVE_REMOTE_LCD
508 fb_data
* old_backdrop
;
513 action_signalscreenchange();
515 if (pfn_tsr_exit
!= NULL
) /* if we have a resident old plugin: */
517 if (pfn_tsr_exit(!strcmp(current_plugin
,p
)) == false )
519 /* not allowing another plugin to load */
523 plugin_loaded
= false;
526 gui_syncsplash(0, str(LANG_WAIT
));
527 strcpy(current_plugin
,p
);
530 hdr
= sim_plugin_load((char *)plugin
, &pd
);
532 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
536 || hdr
->magic
!= PLUGIN_MAGIC
537 || hdr
->target_id
!= TARGET_ID
) {
538 sim_plugin_close(pd
);
539 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
542 if (hdr
->api_version
> PLUGIN_API_VERSION
543 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
544 sim_plugin_close(pd
);
545 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
549 fd
= open(plugin
, O_RDONLY
);
551 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_CANT_OPEN
), plugin
);
555 readsize
= read(fd
, pluginbuf
, PLUGIN_BUFFER_SIZE
);
559 gui_syncsplash(HZ
*2, str(LANG_READ_FAILED
), plugin
);
562 hdr
= (struct plugin_header
*)pluginbuf
;
564 if ((unsigned)readsize
<= sizeof(struct plugin_header
)
565 || hdr
->magic
!= PLUGIN_MAGIC
566 || hdr
->target_id
!= TARGET_ID
567 || hdr
->load_addr
!= pluginbuf
568 || hdr
->end_addr
> pluginbuf
+ PLUGIN_BUFFER_SIZE
) {
569 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_MODEL
));
572 if (hdr
->api_version
> PLUGIN_API_VERSION
573 || hdr
->api_version
< PLUGIN_MIN_API_VERSION
) {
574 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_WRONG_VERSION
));
577 plugin_size
= hdr
->end_addr
- pluginbuf
;
579 /* zero out bss area only, above guards end of pluginbuf */
580 if (plugin_size
> readsize
)
581 memset(pluginbuf
+ readsize
, 0, plugin_size
- readsize
);
584 plugin_loaded
= true;
586 xm
= lcd_getxmargin();
587 ym
= lcd_getymargin();
590 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
591 old_backdrop
= lcd_get_backdrop();
596 #ifdef HAVE_REMOTE_LCD
597 rxm
= lcd_remote_getxmargin();
598 rym
= lcd_remote_getymargin();
599 lcd_remote_setmargins(0, 0);
600 lcd_remote_clear_display();
606 rc
= hdr
->entry_point((struct plugin_api
*) &rockbox_api
, parameter
);
607 /* explicitly casting the pointer here to avoid touching every plugin. */
609 action_signalscreenchange();
610 button_clear_queue();
612 #ifdef HAVE_LCD_BITMAP
614 lcd_set_backdrop(old_backdrop
);
615 #ifdef HAVE_LCD_COLOR
616 lcd_set_drawinfo(DRMODE_SOLID
, global_settings
.fg_color
,
617 global_settings
.bg_color
);
619 lcd_set_drawinfo(DRMODE_SOLID
, LCD_DEFAULT_FG
, LCD_DEFAULT_BG
);
621 #else /* LCD_DEPTH == 1 */
622 lcd_set_drawmode(DRMODE_SOLID
);
623 #endif /* LCD_DEPTH */
624 #endif /* HAVE_LCD_BITMAP */
626 /* restore margins */
627 lcd_setmargins(xm
,ym
);
631 #ifdef HAVE_REMOTE_LCD
632 #if LCD_REMOTE_DEPTH > 1
633 lcd_remote_set_drawinfo(DRMODE_SOLID
, LCD_REMOTE_DEFAULT_FG
,
634 LCD_REMOTE_DEFAULT_BG
);
636 lcd_remote_set_drawmode(DRMODE_SOLID
);
638 lcd_remote_setmargins(rxm
, rym
);
639 lcd_remote_clear_display();
643 if (pfn_tsr_exit
== NULL
)
644 plugin_loaded
= false;
646 sim_plugin_close(pd
);
652 case PLUGIN_USB_CONNECTED
:
653 return PLUGIN_USB_CONNECTED
;
656 gui_syncsplash(HZ
*2, str(LANG_PLUGIN_ERROR
));
662 /* Returns a pointer to the portion of the plugin buffer that is not already
663 being used. If no plugin is loaded, returns the entire plugin buffer */
664 void* plugin_get_buffer(int* buffer_size
)
670 if (plugin_size
>= PLUGIN_BUFFER_SIZE
)
673 *buffer_size
= PLUGIN_BUFFER_SIZE
-plugin_size
;
674 buffer_pos
= plugin_size
;
678 *buffer_size
= PLUGIN_BUFFER_SIZE
;
682 return &pluginbuf
[buffer_pos
];
685 /* Returns a pointer to the mp3 buffer.
686 Playback gets stopped, to avoid conflicts.
687 Talk buffer is stolen as well.
689 void* plugin_get_audio_buffer(int* buffer_size
)
691 #if CONFIG_CODEC == SWCODEC
692 return audio_get_buffer(true, (size_t *)buffer_size
);
695 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
696 *buffer_size
= audiobufend
- audiobuf
;
702 /* Initializes plugin IRAM */
703 void plugin_iram_init(char *iramstart
, char *iramcopy
, size_t iram_size
,
704 char *iedata
, size_t iedata_size
)
707 memcpy(iramstart
, iramcopy
, iram_size
);
708 memset(iedata
, 0, iedata_size
);
709 memset(iramcopy
, 0, iram_size
);
711 #endif /* IRAM_STEAL */
713 /* The plugin wants to stay resident after leaving its main function, e.g.
714 runs from timer or own thread. The callback is registered to later
715 instruct it to free its resources before a new plugin gets loaded. */
716 void plugin_tsr(bool (*exit_callback
)(bool))
718 pfn_tsr_exit
= exit_callback
; /* remember the callback for later */