blob: bbc5d7d15c1fae357661c9e4e45bcb5552b71b3c [file] [log] [blame]
Björn Stenbergba371fb2003-06-29 16:33:04 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Kevin Ferrare0028b052006-07-01 10:14:27 +000010 * Copyright (C) 2002 Bj�n Stenberg
Björn Stenbergba371fb2003-06-29 16:33:04 +000011 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include <stdbool.h>
20#include <string.h>
21#include <stdio.h>
Daniel Stenberg7b247092003-07-24 10:02:45 +000022#include <atoi.h>
23#include <timefuncs.h>
Linus Nielsen Feltzing0c458c02004-07-13 14:01:41 +000024#include <ctype.h>
Linus Nielsen Feltzinga6142ab2004-06-10 13:29:52 +000025#include "debug.h"
Björn Stenbergba371fb2003-06-29 16:33:04 +000026#include "button.h"
27#include "lcd.h"
28#include "dir.h"
29#include "file.h"
30#include "kernel.h"
Hristo Kovachev495c63f2006-01-25 18:29:56 +000031#include "usb.h"
Björn Stenbergba371fb2003-06-29 16:33:04 +000032#include "sprintf.h"
Miika Pekkarinenef72f992005-06-14 14:36:46 +000033#include "logf.h"
Björn Stenbergba371fb2003-06-29 16:33:04 +000034#include "screens.h"
35#include "misc.h"
Jens Arnold0c09f3e2006-03-26 23:00:24 +000036#include "i2c.h"
Björn Stenbergba371fb2003-06-29 16:33:04 +000037#include "mas.h"
38#include "plugin.h"
39#include "lang.h"
Björn Stenberg0ef911d2003-07-09 22:36:23 +000040#include "keyboard.h"
Jerome Kuptzc7d42bb2003-07-20 21:29:16 +000041#include "mpeg.h"
Jörg Hohensohn95298a92004-01-30 22:30:40 +000042#include "buffer.h"
43#include "mp3_playback.h"
44#include "backlight.h"
Jörg Hohensohnfacfec02004-02-03 23:56:25 +000045#include "ata.h"
Jörg Hohensohn4f36ea82004-03-14 21:33:53 +000046#include "talk.h"
Linus Nielsen Feltzing6f4d7212006-03-26 22:33:25 +000047#include "sound_menu.h"
Linus Nielsen Feltzinga6142ab2004-06-10 13:29:52 +000048#include "mp3data.h"
Björn Stenbergdd265832004-06-15 22:54:37 +000049#include "powermgmt.h"
Linus Nielsen Feltzing2b25e542005-02-09 14:23:35 +000050#include "system.h"
Jens Arnolde44372e2005-07-26 20:01:11 +000051#include "timer.h"
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000052#include "sound.h"
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000053#include "database.h"
Kevin Ferraree991bee2005-11-16 15:12:15 +000054#include "splash.h"
Hristo Kovachev38deb8f2006-04-03 08:51:08 +000055#include "list.h"
Jens Arnoldd6c05452005-08-29 21:15:27 +000056#if (CONFIG_CODEC == SWCODEC)
Michiel Van Der Kolk457e1382005-03-20 23:05:44 +000057#include "pcm_playback.h"
Dan Evertond1088492006-03-05 19:34:54 +000058#include "dsp.h"
Michiel Van Der Kolk9bc62262005-03-21 00:24:31 +000059#endif
Björn Stenberg0ef911d2003-07-09 22:36:23 +000060
Jens Arnold0dd1f8e2006-06-06 22:23:52 +000061#ifdef CONFIG_CHARGING
Hristo Kovachev14cfc652006-02-07 14:46:03 +000062#include "power.h"
63#endif
64
Björn Stenberg0ef911d2003-07-09 22:36:23 +000065#ifdef HAVE_LCD_BITMAP
Linus Nielsen Feltzingbe6c8ab2004-07-29 13:59:04 +000066#include "peakmeter.h"
Björn Stenberg0ef911d2003-07-09 22:36:23 +000067#include "widgets.h"
Linus Nielsen Feltzing250678b2005-04-25 07:42:10 +000068#include "bmp.h"
Antoine Cellerier06e6acd2006-07-19 19:47:34 +000069#include "bidi.h"
Björn Stenberg0ef911d2003-07-09 22:36:23 +000070#endif
Björn Stenbergba371fb2003-06-29 16:33:04 +000071
Christian Gmeinerc63430e2005-04-15 12:55:31 +000072#ifdef HAVE_REMOTE_LCD
73#include "lcd-remote.h"
74#endif
75
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +000076#ifdef SIMULATOR
77static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE];
Jens Arnold38b75472006-03-02 01:08:38 +000078void *sim_plugin_load(char *plugin, void **pd);
79void sim_plugin_close(void *pd);
Jens Arnold6a972e02006-02-26 13:37:42 +000080void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int));
81void sim_lcd_ex_update_rect(int x, int y, int width, int height);
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +000082#else
Daniel Stenberg22b77012005-02-22 12:19:12 +000083#define sim_plugin_close(x)
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +000084extern unsigned char pluginbuf[];
Jens Arnold43412112004-09-26 09:25:59 +000085#include "bitswap.h"
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +000086#endif
87
Linus Nielsen Feltzingecf2f7472005-06-22 02:47:54 +000088/* for actual plugins only, not for codecs */
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +000089static bool plugin_loaded = false;
90static int plugin_size = 0;
Jörg Hohensohn68002762004-04-30 20:37:11 +000091static void (*pfn_tsr_exit)(void) = NULL; /* TSR exit callback */
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +000092
Jens Arnold398e4012004-07-20 21:37:36 +000093static const struct plugin_api rockbox_api = {
Björn Stenbergba371fb2003-06-29 16:33:04 +000094
Björn Stenbergba371fb2003-06-29 16:33:04 +000095 /* lcd */
Jens Arnold04daef12005-06-24 22:33:21 +000096 lcd_set_contrast,
Björn Stenbergba371fb2003-06-29 16:33:04 +000097 lcd_clear_display,
98 lcd_puts,
99 lcd_puts_scroll,
100 lcd_stop_scroll,
101#ifdef HAVE_LCD_CHARCELLS
102 lcd_define_pattern,
Daniel Stenbergafd70422003-07-24 09:35:32 +0000103 lcd_get_locked_pattern,
104 lcd_unlock_pattern,
105 lcd_putc,
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000106 lcd_put_cursor,
107 lcd_remove_cursor,
Daniel Stenbergd65908f2005-02-22 13:02:33 +0000108 PREFIX(lcd_icon),
Linus Nielsen Feltzing60895bc2005-09-02 05:39:09 +0000109 lcd_double_height,
Björn Stenbergba371fb2003-06-29 16:33:04 +0000110#else
Jens Arnold04daef12005-06-24 22:33:21 +0000111 lcd_set_drawmode,
112 lcd_get_drawmode,
113 lcd_setfont,
114 lcd_getstringsize,
115 lcd_drawpixel,
116 lcd_drawline,
Jens Arnold7e11acb2005-06-28 23:15:47 +0000117 lcd_hline,
118 lcd_vline,
Jens Arnold04daef12005-06-24 22:33:21 +0000119 lcd_drawrect,
120 lcd_fillrect,
Jens Arnoldf894a4c2005-07-06 22:58:02 +0000121 lcd_mono_bitmap_part,
122 lcd_mono_bitmap,
Jens Arnolde44372e2005-07-26 20:01:11 +0000123#if LCD_DEPTH > 1
124 lcd_set_foreground,
125 lcd_get_foreground,
126 lcd_set_background,
127 lcd_get_background,
128 lcd_bitmap_part,
129 lcd_bitmap,
130#endif
Brandon Low413da2a2006-02-07 20:38:55 +0000131#if LCD_DEPTH == 16
132 lcd_bitmap_transparent_part,
133 lcd_bitmap_transparent,
134#endif
Björn Stenbergba371fb2003-06-29 16:33:04 +0000135 lcd_putsxy,
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000136 lcd_puts_style,
Jens Arnold1c841b82004-10-23 09:59:53 +0000137 lcd_puts_scroll_style,
Jens Arnold04daef12005-06-24 22:33:21 +0000138 &lcd_framebuffer[0][0],
139 lcd_blit,
Björn Stenbergba371fb2003-06-29 16:33:04 +0000140 lcd_update,
141 lcd_update_rect,
Björn Stenberg0ef911d2003-07-09 22:36:23 +0000142 scrollbar,
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000143 checkbox,
Jens Arnold04daef12005-06-24 22:33:21 +0000144 font_get,
Jens Arnolde44372e2005-07-26 20:01:11 +0000145 font_getstringsize,
Jens Arnolda36b1d42006-01-15 18:20:18 +0000146 font_get_width,
Björn Stenbergba371fb2003-06-29 16:33:04 +0000147#endif
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000148 backlight_on,
149 backlight_off,
Jens Arnold1c841b82004-10-23 09:59:53 +0000150 backlight_set_timeout,
Kevin Ferraree991bee2005-11-16 15:12:15 +0000151 gui_syncsplash,
Christian Gmeinerc63430e2005-04-15 12:55:31 +0000152#ifdef HAVE_REMOTE_LCD
Jens Arnold4c7da882005-06-18 01:25:47 +0000153 /* remote lcd */
Jens Arnold576908d2005-06-29 01:39:50 +0000154 lcd_remote_set_contrast,
Linus Nielsen Feltzing250678b2005-04-25 07:42:10 +0000155 lcd_remote_clear_display,
Christian Gmeiner7d984812005-04-25 23:47:51 +0000156 lcd_remote_puts,
157 lcd_remote_puts_scroll,
158 lcd_remote_stop_scroll,
Jens Arnold576908d2005-06-29 01:39:50 +0000159 lcd_remote_set_drawmode,
160 lcd_remote_get_drawmode,
161 lcd_remote_setfont,
162 lcd_remote_getstringsize,
163 lcd_remote_drawpixel,
164 lcd_remote_drawline,
165 lcd_remote_hline,
166 lcd_remote_vline,
167 lcd_remote_drawrect,
168 lcd_remote_fillrect,
Jens Arnoldd7f94392005-07-07 00:05:29 +0000169 lcd_remote_mono_bitmap_part,
170 lcd_remote_mono_bitmap,
Christian Gmeiner7d984812005-04-25 23:47:51 +0000171 lcd_remote_putsxy,
172 lcd_remote_puts_style,
173 lcd_remote_puts_scroll_style,
Jens Arnold576908d2005-06-29 01:39:50 +0000174 &lcd_remote_framebuffer[0][0],
Christian Gmeiner7d984812005-04-25 23:47:51 +0000175 lcd_remote_update,
176 lcd_remote_update_rect,
Jens Arnold4c7da882005-06-18 01:25:47 +0000177
Jens Arnoldb51f7df2005-11-21 23:55:39 +0000178 remote_backlight_on,
179 remote_backlight_off,
Christian Gmeinerc63430e2005-04-15 12:55:31 +0000180#endif
Björn Stenbergba371fb2003-06-29 16:33:04 +0000181 /* button */
182 button_get,
183 button_get_w_tmo,
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000184 button_status,
185 button_clear_queue,
Zakk Roberts07fcf772006-05-01 05:45:18 +0000186#ifdef HAS_BUTTON_HOLD
Jens Arnold4c7da882005-06-18 01:25:47 +0000187 button_hold,
188#endif
Björn Stenbergba371fb2003-06-29 16:33:04 +0000189
190 /* file */
Daniel Stenbergb0625472003-12-09 06:48:55 +0000191 (open_func)PREFIX(open),
Daniel Stenberg22b77012005-02-22 12:19:12 +0000192 close,
Daniel Stenbergb0625472003-12-09 06:48:55 +0000193 (read_func)read,
Jens Arnold399c0812005-02-28 18:32:57 +0000194 PREFIX(lseek),
Daniel Stenbergb0625472003-12-09 06:48:55 +0000195 (creat_func)PREFIX(creat),
196 (write_func)write,
Linus Nielsen Feltzing80c31c92004-07-23 14:51:49 +0000197 PREFIX(remove),
198 PREFIX(rename),
Daniel Stenberg22b77012005-02-22 12:19:12 +0000199 PREFIX(ftruncate),
Björn Stenbergba371fb2003-06-29 16:33:04 +0000200 PREFIX(filesize),
Daniel Stenberg22b77012005-02-22 12:19:12 +0000201 fdprintf,
Björn Stenbergba371fb2003-06-29 16:33:04 +0000202 read_line,
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000203 settings_parseline,
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000204#ifndef SIMULATOR
205 ata_sleep,
Zakk Roberts07fcf772006-05-01 05:45:18 +0000206 ata_disk_is_active,
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000207#endif
Björn Stenbergba371fb2003-06-29 16:33:04 +0000208
209 /* dir */
210 PREFIX(opendir),
211 PREFIX(closedir),
212 PREFIX(readdir),
Jens Arnold4c7da882005-06-18 01:25:47 +0000213 PREFIX(mkdir),
Björn Stenbergba371fb2003-06-29 16:33:04 +0000214
Jens Arnold1c841b82004-10-23 09:59:53 +0000215 /* kernel/ system */
Björn Stenbergba371fb2003-06-29 16:33:04 +0000216 PREFIX(sleep),
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000217 yield,
Björn Stenbergba371fb2003-06-29 16:33:04 +0000218 &current_tick,
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000219 default_event_handler,
Jens Arnold1c841b82004-10-23 09:59:53 +0000220 default_event_handler_ex,
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000221 create_thread,
222 remove_thread,
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000223 reset_poweroff_timer,
Jens Arnold1c841b82004-10-23 09:59:53 +0000224#ifndef SIMULATOR
225 system_memory_guard,
Jens Arnold4c7da882005-06-18 01:25:47 +0000226 &cpu_frequency,
227#ifdef HAVE_ADJUSTABLE_CPU_FREQ
228 cpu_boost,
229#endif
Jens Arnolde44372e2005-07-26 20:01:11 +0000230 timer_register,
231 timer_unregister,
232 timer_set_period,
Jens Arnold1c841b82004-10-23 09:59:53 +0000233#endif
Brandon Low413da2a2006-02-07 20:38:55 +0000234 queue_init,
235 queue_delete,
236 queue_post,
237 queue_wait_w_tmo,
238 usb_acknowledge,
239#ifdef RB_PROFILE
240 profile_thread,
241 profstop,
242 profile_func_enter,
243 profile_func_exit,
244#endif
Björn Stenbergba371fb2003-06-29 16:33:04 +0000245
Jens Arnold06bc6272006-03-11 09:28:49 +0000246#ifdef SIMULATOR
247 /* special simulator hooks */
248#if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
249 sim_lcd_ex_init,
250 sim_lcd_ex_update_rect,
251#endif
252#endif
253
Björn Stenbergba371fb2003-06-29 16:33:04 +0000254 /* strings and memory */
255 snprintf,
256 strcpy,
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000257 strncpy,
Björn Stenbergba371fb2003-06-29 16:33:04 +0000258 strlen,
Linus Nielsen Feltzinga96a1302004-07-13 14:14:30 +0000259 strrchr,
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000260 strcmp,
Jens Arnolde44372e2005-07-26 20:01:11 +0000261 strncmp,
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000262 strcasecmp,
Jens Arnold1c841b82004-10-23 09:59:53 +0000263 strncasecmp,
Björn Stenbergba371fb2003-06-29 16:33:04 +0000264 memset,
265 memcpy,
Brandon Low413da2a2006-02-07 20:38:55 +0000266 memmove,
Linus Nielsen Feltzing0c458c02004-07-13 14:01:41 +0000267 _ctype_,
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000268 atoi,
Daniel Stenberg22b77012005-02-22 12:19:12 +0000269 strchr,
270 strcat,
271 memcmp,
Jens Arnold4c7da882005-06-18 01:25:47 +0000272 strcasestr,
Jens Arnolda36b1d42006-01-15 18:20:18 +0000273 /* unicode stuff */
274 utf8decode,
275 iso_decode,
276 utf16LEdecode,
277 utf16BEdecode,
278 utf8encode,
279 utf8length,
Björn Stenbergba371fb2003-06-29 16:33:04 +0000280
281 /* sound */
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000282 sound_set,
Jens Arnolda36b1d42006-01-15 18:20:18 +0000283 sound_min,
284 sound_max,
Jörg Hohensohn95298a92004-01-30 22:30:40 +0000285#ifndef SIMULATOR
Jörg Hohensohn95298a92004-01-30 22:30:40 +0000286 mp3_play_data,
287 mp3_play_pause,
288 mp3_play_stop,
289 mp3_is_playing,
Jens Arnoldd6c05452005-08-29 21:15:27 +0000290#if CONFIG_CODEC != SWCODEC
Jörg Hohensohn95298a92004-01-30 22:30:40 +0000291 bitswap,
Jörg Hohensohnfacfec02004-02-03 23:56:25 +0000292#endif
Jens Arnoldd6c05452005-08-29 21:15:27 +0000293#if CONFIG_CODEC == SWCODEC
Zakk Roberts07fcf772006-05-01 05:45:18 +0000294 pcm_play_data,
Jens Arnold4c7da882005-06-18 01:25:47 +0000295 pcm_play_stop,
296 pcm_set_frequency,
297 pcm_is_playing,
298 pcm_play_pause,
Linus Nielsen Feltzinga12ccab2005-06-06 00:34:07 +0000299#endif
Jens Arnold4c7da882005-06-18 01:25:47 +0000300#endif
Jens Arnolddae698c2006-03-11 09:38:12 +0000301#if CONFIG_CODEC == SWCODEC
302 pcm_calculate_peaks,
303#endif
Jens Arnold4c7da882005-06-18 01:25:47 +0000304
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000305 /* playback control */
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000306 PREFIX(audio_play),
307 audio_stop,
308 audio_pause,
309 audio_resume,
310 audio_next,
311 audio_prev,
312 audio_ff_rewind,
313 audio_next_track,
Jörg Hohensohn92e19db2004-06-19 09:36:03 +0000314 playlist_amount,
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000315 audio_status,
316 audio_has_changed_track,
317 audio_current_track,
318 audio_flush_and_reload_tracks,
319 audio_get_file_pos,
Jens Arnoldd6c05452005-08-29 21:15:27 +0000320#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
Linus Nielsen Feltzing78c829f2005-04-25 08:21:10 +0000321 mpeg_get_last_header,
Linus Nielsen Feltzingef73c2e2005-04-25 08:59:19 +0000322#endif
Dan Everton76992552006-03-05 19:46:33 +0000323#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
324 (CONFIG_CODEC == SWCODEC)
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000325 sound_set_pitch,
Dan Everton76992552006-03-05 19:46:33 +0000326#endif
Linus Nielsen Feltzingf4f41112004-07-27 14:10:48 +0000327
Jens Arnoldd6c05452005-08-29 21:15:27 +0000328#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000329 /* MAS communication */
Linus Nielsen Feltzing8fc5b782004-06-10 13:48:53 +0000330 mas_readmem,
331 mas_writemem,
332 mas_readreg,
333 mas_writereg,
Jens Arnoldd6c05452005-08-29 21:15:27 +0000334#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
Linus Nielsen Feltzing8fc5b782004-06-10 13:48:53 +0000335 mas_codec_writereg,
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000336 mas_codec_readreg,
Linus Nielsen Feltzing8fc5b782004-06-10 13:48:53 +0000337#endif
Jens Arnoldd6c05452005-08-29 21:15:27 +0000338#endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000339
Jens Arnolda36b1d42006-01-15 18:20:18 +0000340 /* menu */
341 menu_init,
342 menu_exit,
343 menu_show,
344 menu_run,
345 menu_cursor,
346 menu_description,
347 menu_delete,
348 menu_count,
349 menu_moveup,
350 menu_movedown,
351 menu_draw,
352 menu_insert,
353 menu_set_cursor,
Hristo Kovachevf53f64a2006-03-21 09:36:13 +0000354 set_option,
Jens Arnolda36b1d42006-01-15 18:20:18 +0000355
Brandon Low413da2a2006-02-07 20:38:55 +0000356 /* power */
357 battery_level,
358 battery_level_safe,
359 battery_time,
360#ifndef SIMULATOR
Zakk Roberts07fcf772006-05-01 05:45:18 +0000361 battery_voltage,
Brandon Low413da2a2006-02-07 20:38:55 +0000362#endif
Jens Arnold0dd1f8e2006-06-06 22:23:52 +0000363#ifdef CONFIG_CHARGING
Brandon Low413da2a2006-02-07 20:38:55 +0000364 charger_inserted,
Jens Arnold0dd1f8e2006-06-06 22:23:52 +0000365# if CONFIG_CHARGING == CHARGING_MONITOR
Brandon Low413da2a2006-02-07 20:38:55 +0000366 charging_state,
367# endif
368#endif
369#ifdef HAVE_USB_POWER
370 usb_powered,
371#endif
372
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000373 /* misc */
374 srand,
375 rand,
376 (qsort_func)qsort,
377 kbd_input,
378 get_time,
Björn Stenbergc05b7d72004-06-16 19:35:20 +0000379 set_time,
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000380 plugin_get_buffer,
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000381 plugin_get_audio_buffer,
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000382 plugin_tsr,
383#if defined(DEBUG) || defined(SIMULATOR)
384 debugf,
385#endif
Jens Arnolde44372e2005-07-26 20:01:11 +0000386#ifdef ROCKBOX_HAS_LOGF
387 logf,
388#endif
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000389 &global_settings,
Linus Nielsen Feltzing70de4ec2004-07-27 19:16:58 +0000390 mp3info,
391 count_mp3_frames,
392 create_xing_header,
Jens Arnold1c841b82004-10-23 09:59:53 +0000393 find_next_frame,
Jens Arnoldd6c05452005-08-29 21:15:27 +0000394#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
Jens Arnold1c841b82004-10-23 09:59:53 +0000395 peak_meter_scale_value,
396 peak_meter_set_use_dbfs,
397 peak_meter_get_use_dbfs,
398#endif
Linus Nielsen Feltzing250678b2005-04-25 07:42:10 +0000399#ifdef HAVE_LCD_BITMAP
400 read_bmp_file,
Jens Arnolda36b1d42006-01-15 18:20:18 +0000401 screen_dump_set_hook,
Linus Nielsen Feltzing250678b2005-04-25 07:42:10 +0000402#endif
Linus Nielsen Feltzing60895bc2005-09-02 05:39:09 +0000403 show_logo,
Jens Arnold06bc6272006-03-11 09:28:49 +0000404 tree_get_context,
Jens Arnold4c7da882005-06-18 01:25:47 +0000405
406 /* new stuff at the end, sort into place next time
407 the API gets incompatible */
Linus Nielsen Feltzing6f4d7212006-03-26 22:33:25 +0000408 set_sound,
Jens Arnold0c09f3e2006-03-26 23:00:24 +0000409#if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)) && !defined(SIMULATOR)
410 i2c_begin,
411 i2c_end,
412 i2c_write,
413#endif
Dave Chapman47f4a452006-03-28 15:44:01 +0000414
415 vsnprintf,
416 memchr,
Hristo Kovachev38deb8f2006-04-03 08:51:08 +0000417 /* list */
418 gui_synclist_init,
419 gui_synclist_set_nb_items,
420 gui_synclist_set_icon_callback,
421 gui_synclist_get_nb_items,
422 gui_synclist_get_sel_pos,
423 gui_synclist_draw,
424 gui_synclist_select_item,
425 gui_synclist_select_next,
426 gui_synclist_select_previous,
427 gui_synclist_select_next_page,
428 gui_synclist_select_previous_page,
429 gui_synclist_add_item,
430 gui_synclist_del_item,
431 gui_synclist_limit_scroll,
432 gui_synclist_flash,
433#ifdef HAVE_LCD_BITMAP
434 gui_synclist_scroll_right,
435 gui_synclist_scroll_left,
436#endif
437 gui_synclist_do_button,
Zakk Roberts07fcf772006-05-01 05:45:18 +0000438
439#ifdef HAVE_LCD_BITMAP
440 lcd_setmargins,
441#endif
Jens Arnold93ff9492006-05-02 21:44:04 +0000442 utf8seek,
Antoine Cellerier06e6acd2006-07-19 19:47:34 +0000443
Jens Arnold2343a192006-05-03 23:16:53 +0000444 set_int,
Hardeep Sidhuab3e71c2006-06-04 16:36:49 +0000445 reload_directory,
Kevin Ferrare0028b052006-07-01 10:14:27 +0000446 set_bool,
447#if NB_SCREENS == 2
448 {&screens[SCREEN_MAIN], &screens[SCREEN_REMOTE]},
449#else
450 {&screens[SCREEN_MAIN]},
451#endif
Antoine Cellerier06e6acd2006-07-19 19:47:34 +0000452#ifdef HAVE_LCD_BITMAP
453 bidi_l2v,
454 font_get_bits,
455 font_load,
456#endif
Jens Arnold05ddd9a2006-07-28 07:35:45 +0000457#if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
458 lcd_remote_set_foreground,
459 lcd_remote_get_foreground,
460 lcd_remote_set_background,
461 lcd_remote_get_background,
462 lcd_remote_bitmap_part,
463 lcd_remote_bitmap,
464#endif
Dave Chapmanc9d66562006-08-07 22:11:07 +0000465
Jens Arnoldc5a309a2006-08-08 13:44:43 +0000466#if (CONFIG_LCD == LCD_IPODCOLOR || CONFIG_LCD == LCD_IPODNANO \
467 || CONFIG_LCD == LCD_H300) && !defined(SIMULATOR)
Dave Chapmanc9d66562006-08-07 22:11:07 +0000468 lcd_yuv_blit,
469#endif
Dan Everton58145512006-08-08 10:46:39 +0000470
471 PREFIX(rmdir),
Björn Stenbergba371fb2003-06-29 16:33:04 +0000472};
473
Jens Arnold8fb33612004-08-18 01:09:31 +0000474int plugin_load(const char* plugin, void* parameter)
Björn Stenbergba371fb2003-06-29 16:33:04 +0000475{
Jens Arnold38b75472006-03-02 01:08:38 +0000476 int rc;
Jens Arnolda7902772006-01-16 23:20:58 +0000477 struct plugin_header *hdr;
Jens Arnold38b75472006-03-02 01:08:38 +0000478#ifdef SIMULATOR
479 void *pd;
480#else
481 int fd;
Jens Arnolda40d3552006-01-17 20:39:44 +0000482 ssize_t readsize;
Daniel Stenbergca426012005-02-22 12:56:58 +0000483#endif
Jörg Hohensohn1bad0552004-05-01 15:14:09 +0000484#ifdef HAVE_LCD_BITMAP
Jens Arnolda7902772006-01-16 23:20:58 +0000485 int xm, ym;
Jörg Hohensohn1bad0552004-05-01 15:14:09 +0000486#endif
Jens Arnold35e05ca2006-02-18 00:13:44 +0000487#ifdef HAVE_REMOTE_LCD
488 int rxm, rym;
489#endif
Dave Chapmand9e5b672006-02-02 20:42:56 +0000490#ifdef HAVE_LCD_COLOR
491 fb_data* old_backdrop;
492#endif
Björn Stenbergba371fb2003-06-29 16:33:04 +0000493
Jörg Hohensohn68002762004-04-30 20:37:11 +0000494 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
495 {
496 pfn_tsr_exit(); /* force it to exit now */
497 pfn_tsr_exit = NULL;
Hardeep Sidhub060d3a2005-11-10 08:07:31 +0000498 plugin_loaded = false;
Jörg Hohensohn68002762004-04-30 20:37:11 +0000499 }
500
Jens Arnold7ea4d592006-02-16 22:36:04 +0000501 gui_syncsplash(0, true, str(LANG_WAIT));
502
Björn Stenbergba371fb2003-06-29 16:33:04 +0000503#ifdef SIMULATOR
Jens Arnold38b75472006-03-02 01:08:38 +0000504 hdr = sim_plugin_load((char *)plugin, &pd);
505 if (pd == NULL) {
Jens Arnolda7902772006-01-16 23:20:58 +0000506 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin);
Björn Stenbergba371fb2003-06-29 16:33:04 +0000507 return -1;
Jens Arnolda7902772006-01-16 23:20:58 +0000508 }
509 if (hdr == NULL
510 || hdr->magic != PLUGIN_MAGIC
Jens Arnolda8c408c2006-01-18 08:34:32 +0000511 || hdr->target_id != TARGET_ID) {
Jens Arnold38b75472006-03-02 01:08:38 +0000512 sim_plugin_close(pd);
Jens Arnolda7902772006-01-16 23:20:58 +0000513 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL));
514 return -1;
515 }
516 if (hdr->api_version > PLUGIN_API_VERSION
517 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
Jens Arnold38b75472006-03-02 01:08:38 +0000518 sim_plugin_close(pd);
Jens Arnolda7902772006-01-16 23:20:58 +0000519 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION));
520 return -1;
521 }
Björn Stenbergba371fb2003-06-29 16:33:04 +0000522#else
523 fd = open(plugin, O_RDONLY);
524 if (fd < 0) {
Jens Arnolda36b1d42006-01-15 18:20:18 +0000525 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin);
Björn Stenbergba371fb2003-06-29 16:33:04 +0000526 return fd;
527 }
Jens Arnolda36b1d42006-01-15 18:20:18 +0000528
Jens Arnolda40d3552006-01-17 20:39:44 +0000529 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
530 close(fd);
531
Jens Arnolda8c408c2006-01-18 08:34:32 +0000532 if (readsize < 0) {
Jens Arnolda36b1d42006-01-15 18:20:18 +0000533 gui_syncsplash(HZ*2, true, str(LANG_READ_FAILED), plugin);
534 return -1;
535 }
Jens Arnolda40d3552006-01-17 20:39:44 +0000536 hdr = (struct plugin_header *)pluginbuf;
537
Jens Arnolda8c408c2006-01-18 08:34:32 +0000538 if ((unsigned)readsize <= sizeof(struct plugin_header)
539 || hdr->magic != PLUGIN_MAGIC
Jens Arnolda40d3552006-01-17 20:39:44 +0000540 || hdr->target_id != TARGET_ID
541 || hdr->load_addr != pluginbuf
542 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
Jens Arnolda36b1d42006-01-15 18:20:18 +0000543 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL));
544 return -1;
545 }
Jens Arnolda40d3552006-01-17 20:39:44 +0000546 if (hdr->api_version > PLUGIN_API_VERSION
547 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
Jens Arnolda36b1d42006-01-15 18:20:18 +0000548 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION));
549 return -1;
550 }
Jens Arnolda40d3552006-01-17 20:39:44 +0000551 plugin_size = hdr->end_addr - pluginbuf;
Jens Arnoldb509ff52006-04-06 18:26:14 +0000552
553 /* zero out bss area only, above guards end of pluginbuf */
554 memset(pluginbuf + readsize, 0, plugin_size - readsize);
Björn Stenbergba371fb2003-06-29 16:33:04 +0000555#endif
556
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +0000557 plugin_loaded = true;
Linus Nielsen Feltzing40e9e412005-02-09 14:19:14 +0000558
Jens Arnold7ea4d592006-02-16 22:36:04 +0000559#ifdef HAVE_LCD_BITMAP
560 xm = lcd_getxmargin();
561 ym = lcd_getymargin();
562 lcd_setmargins(0,0);
Dave Chapman1c398552006-02-14 00:39:11 +0000563#ifdef HAVE_LCD_COLOR
564 old_backdrop = lcd_get_backdrop();
565 lcd_set_backdrop(NULL);
Jens Arnold7ea4d592006-02-16 22:36:04 +0000566#endif
567 lcd_clear_display();
Dave Chapman1c398552006-02-14 00:39:11 +0000568 lcd_update();
Jens Arnold7ea4d592006-02-16 22:36:04 +0000569#else /* !HAVE_LCD_BITMAP */
570 lcd_clear_display();
Dave Chapman1c398552006-02-14 00:39:11 +0000571#endif
572
Jens Arnold35e05ca2006-02-18 00:13:44 +0000573#ifdef HAVE_REMOTE_LCD
574 rxm = lcd_remote_getxmargin();
575 rym = lcd_remote_getymargin();
576 lcd_remote_setmargins(0, 0);
577 lcd_remote_clear_display();
578 lcd_remote_update();
579#endif
580
Linus Nielsen Feltzing40e9e412005-02-09 14:19:14 +0000581 invalidate_icache();
582
Jens Arnolda40d3552006-01-17 20:39:44 +0000583 rc = hdr->entry_point((struct plugin_api*) &rockbox_api, parameter);
Linus Nielsen Feltzinga754dd82004-07-21 08:02:23 +0000584 /* explicitly casting the pointer here to avoid touching every plugin. */
585
586 button_clear_queue();
Jens Arnold35e05ca2006-02-18 00:13:44 +0000587
Jens Arnold04daef12005-06-24 22:33:21 +0000588#ifdef HAVE_LCD_BITMAP
Jens Arnold34a610b2005-07-14 18:12:27 +0000589#if LCD_DEPTH > 1
Dave Chapman603f87f2006-02-26 02:48:05 +0000590#ifdef HAVE_LCD_COLOR
Zakk Roberts07fcf772006-05-01 05:45:18 +0000591 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
Dave Chapman603f87f2006-02-26 02:48:05 +0000592 global_settings.bg_color);
593#else
Jens Arnold5b2cba12005-11-16 21:09:23 +0000594 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
Dave Chapman603f87f2006-02-26 02:48:05 +0000595#endif
Jens Arnoldb0e056b2005-07-19 10:33:41 +0000596#else /* LCD_DEPTH == 1 */
Jens Arnold04daef12005-06-24 22:33:21 +0000597 lcd_set_drawmode(DRMODE_SOLID);
Jens Arnoldb0e056b2005-07-19 10:33:41 +0000598#endif /* LCD_DEPTH */
Jens Arnolda7902772006-01-16 23:20:58 +0000599 /* restore margins */
600 lcd_setmargins(xm,ym);
Dave Chapmand9e5b672006-02-02 20:42:56 +0000601#ifdef HAVE_LCD_COLOR
602 lcd_set_backdrop(old_backdrop);
603#endif
Jens Arnold7ea4d592006-02-16 22:36:04 +0000604 lcd_clear_display();
605 lcd_update();
606#endif /* HAVE_LCD_BITMAP */
Jens Arnold35e05ca2006-02-18 00:13:44 +0000607
608#ifdef HAVE_REMOTE_LCD
609 lcd_remote_set_drawmode(DRMODE_SOLID);
610 lcd_remote_setmargins(rxm, rym);
611 lcd_remote_clear_display();
612 lcd_remote_update();
613#endif
614
Hardeep Sidhub060d3a2005-11-10 08:07:31 +0000615 if (pfn_tsr_exit == NULL)
616 plugin_loaded = false;
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +0000617
Jens Arnold38b75472006-03-02 01:08:38 +0000618 sim_plugin_close(pd);
Jens Arnolda7902772006-01-16 23:20:58 +0000619
Björn Stenbergba371fb2003-06-29 16:33:04 +0000620 switch (rc) {
621 case PLUGIN_OK:
622 break;
623
624 case PLUGIN_USB_CONNECTED:
625 return PLUGIN_USB_CONNECTED;
626
Björn Stenbergba371fb2003-06-29 16:33:04 +0000627 default:
Kevin Ferraree991bee2005-11-16 15:12:15 +0000628 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_ERROR));
Björn Stenbergba371fb2003-06-29 16:33:04 +0000629 break;
630 }
631
Björn Stenbergba371fb2003-06-29 16:33:04 +0000632 return PLUGIN_OK;
633}
634
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +0000635/* Returns a pointer to the portion of the plugin buffer that is not already
636 being used. If no plugin is loaded, returns the entire plugin buffer */
637void* plugin_get_buffer(int* buffer_size)
Björn Stenbergba371fb2003-06-29 16:33:04 +0000638{
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +0000639 int buffer_pos;
640
641 if (plugin_loaded)
642 {
643 if (plugin_size >= PLUGIN_BUFFER_SIZE)
644 return NULL;
Zakk Roberts07fcf772006-05-01 05:45:18 +0000645
Hardeep Sidhu48c2d0f2003-07-25 23:04:59 +0000646 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
647 buffer_pos = plugin_size;
648 }
649 else
650 {
651 *buffer_size = PLUGIN_BUFFER_SIZE;
652 buffer_pos = 0;
653 }
654
655 return &pluginbuf[buffer_pos];
656}
657
Zakk Roberts07fcf772006-05-01 05:45:18 +0000658/* Returns a pointer to the mp3 buffer.
Jörg Hohensohn95298a92004-01-30 22:30:40 +0000659 Playback gets stopped, to avoid conflicts. */
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000660void* plugin_get_audio_buffer(int* buffer_size)
Jörg Hohensohn95298a92004-01-30 22:30:40 +0000661{
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000662 audio_stop();
Jörg Hohensohn4f36ea82004-03-14 21:33:53 +0000663 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000664 *buffer_size = audiobufend - audiobuf;
665 return audiobuf;
Jörg Hohensohn95298a92004-01-30 22:30:40 +0000666}
667
Jörg Hohensohn68002762004-04-30 20:37:11 +0000668/* The plugin wants to stay resident after leaving its main function, e.g.
Zakk Roberts07fcf772006-05-01 05:45:18 +0000669 runs from timer or own thread. The callback is registered to later
Jörg Hohensohn68002762004-04-30 20:37:11 +0000670 instruct it to free its resources before a new plugin gets loaded. */
671void plugin_tsr(void (*exit_callback)(void))
672{
673 pfn_tsr_exit = exit_callback; /* remember the callback for later */
674}