Strip trailing directory slash
[kugel-rb.git] / apps / plugin.h
blob89b9d290d59aac1f433740d331e38d817f39f57d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
19 #ifndef _PLUGIN_H_
20 #define _PLUGIN_H_
22 /* instruct simulator code to not redefine any symbols when compiling plugins.
23 (the PLUGIN macro is defined in apps/plugins/Makefile) */
24 #ifdef PLUGIN
25 #define NO_REDEFINES_PLEASE
26 #endif
28 #ifndef MEM
29 #define MEM 2
30 #endif
32 #include <stdbool.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include "config.h"
36 #include "dir.h"
37 #include "kernel.h"
38 #include "button.h"
39 #include "font.h"
40 #include "system.h"
41 #include "lcd.h"
42 #include "id3.h"
43 #include "mpeg.h"
44 #include "mp3_playback.h"
45 #include "settings.h"
46 #include "thread.h"
47 #include "playlist.h"
48 #ifdef HAVE_LCD_BITMAP
49 #include "widgets.h"
50 #endif
52 #ifdef PLUGIN
53 #if defined(DEBUG) || defined(SIMULATOR)
54 #define DEBUGF rb->debugf
55 #define LDEBUGF rb->debugf
56 #else
57 #define DEBUGF(...)
58 #define LDEBUGF(...)
59 #endif
60 #endif
62 /* increase this every time the api struct changes */
63 #define PLUGIN_API_VERSION 29
65 /* update this to latest version if a change to the api struct breaks
66 backwards compatibility (and please take the opportunity to sort in any
67 new function which are "waiting" at the end of the function table) */
68 #define PLUGIN_MIN_API_VERSION 29
70 /* plugin return codes */
71 enum plugin_status {
72 PLUGIN_OK = 0,
73 PLUGIN_USB_CONNECTED,
75 PLUGIN_WRONG_API_VERSION = -1,
76 PLUGIN_WRONG_MODEL = -2,
77 PLUGIN_ERROR = -3,
80 /* different (incompatible) plugin models */
81 enum model {
82 PLAYER,
83 RECORDER
86 #ifdef HAVE_LCD_CHARCELLS
87 #define MODEL PLAYER
88 #else
89 #define MODEL RECORDER
90 #endif
92 /* compatibility test macro */
93 #define TEST_PLUGIN_API(_api_) \
94 do { \
95 int _rc_ = _api_->plugin_test(PLUGIN_API_VERSION, MODEL, MEM); \
96 if (_rc_<0) \
97 return _rc_; \
98 } while(0)
100 /* NOTE: To support backwards compatibility, only add new functions at
101 the end of the structure. Every time you add a new function,
102 remember to increase PLUGIN_API_VERSION. If you make changes to the
103 existing APIs then also update PLUGIN_MIN_API_VERSION to current
104 version
106 struct plugin_api {
107 /* these two fields must always be first, to ensure
108 TEST_PLUGIN_API will always work */
109 int version;
110 int (*plugin_test)(int api_version, int model, int memsize);
112 /* lcd */
113 void (*lcd_clear_display)(void);
114 void (*lcd_puts)(int x, int y, const unsigned char *string);
115 void (*lcd_puts_scroll)(int x, int y, const unsigned char* string);
116 void (*lcd_stop_scroll)(void);
117 void (*lcd_set_contrast)(int x);
118 #ifdef HAVE_LCD_CHARCELLS
119 void (*lcd_define_pattern)(int which,const char *pattern);
120 unsigned char (*lcd_get_locked_pattern)(void);
121 void (*lcd_unlock_pattern)(unsigned char pat);
122 void (*lcd_putc)(int x, int y, unsigned short ch);
123 void (*lcd_put_cursor)(int x, int y, char cursor_char);
124 void (*lcd_remove_cursor)(void);
125 void (*lcd_icon)(int icon, bool enable);
126 #else
127 void (*lcd_putsxy)(int x, int y, const unsigned char *string);
128 void (*lcd_puts_style)(int x, int y, const unsigned char *str, int style);
129 void (*lcd_puts_scroll_style)(int x, int y, const unsigned char* string,
130 int style);
131 void (*lcd_bitmap)(const unsigned char *src, int x, int y,
132 int nx, int ny, bool clear);
133 void (*lcd_drawline)(int x1, int y1, int x2, int y2);
134 void (*lcd_clearline)(int x1, int y1, int x2, int y2);
135 void (*lcd_drawpixel)(int x, int y);
136 void (*lcd_clearpixel)(int x, int y);
137 void (*lcd_setfont)(int font);
138 struct font* (*font_get)(int font);
139 void (*lcd_clearrect)(int x, int y, int nx, int ny);
140 void (*lcd_fillrect)(int x, int y, int nx, int ny);
141 void (*lcd_drawrect)(int x, int y, int nx, int ny);
142 void (*lcd_invertrect)(int x, int y, int nx, int ny);
143 int (*lcd_getstringsize)(const unsigned char *str, int *w, int *h);
144 void (*lcd_update)(void);
145 void (*lcd_update_rect)(int x, int y, int width, int height);
146 void (*scrollbar)(int x, int y, int width, int height, int items,
147 int min_shown, int max_shown, int orientation);
148 void (*checkbox)(int x, int y, int width, int height, bool checked);
149 unsigned char* lcd_framebuffer;
150 void (*lcd_blit) (const unsigned char* p_data, int x, int y, int width,
151 int height, int stride);
152 #ifndef SIMULATOR
153 void (*lcd_roll)(int pixels);
154 #endif
155 #endif
156 void (*backlight_on)(void);
157 void (*backlight_off)(void);
158 void (*backlight_set_timeout)(int index);
159 void (*splash)(int ticks, bool center, const char *fmt, ...);
161 /* button */
162 int (*button_get)(bool block);
163 int (*button_get_w_tmo)(int ticks);
164 int (*button_status)(void);
165 void (*button_clear_queue)(void);
167 /* file */
168 int (*open)(const char* pathname, int flags);
169 int (*close)(int fd);
170 ssize_t (*read)(int fd, void* buf, size_t count);
171 off_t (*lseek)(int fd, off_t offset, int whence);
172 int (*creat)(const char *pathname, mode_t mode);
173 ssize_t (*write)(int fd, const void* buf, size_t count);
174 int (*remove)(const char* pathname);
175 int (*rename)(const char* path, const char* newname);
176 int (*ftruncate)(int fd, off_t length);
177 int (*filesize)(int fd);
178 int (*fprintf)(int fd, const char *fmt, ...);
179 int (*read_line)(int fd, char* buffer, int buffer_size);
180 bool (*settings_parseline)(char* line, char** name, char** value);
181 #ifndef SIMULATOR
182 int (*ata_sleep)(void);
183 #endif
185 /* dir */
186 DIR* (*opendir)(const char* name);
187 int (*closedir)(DIR* dir);
188 struct dirent* (*readdir)(DIR* dir);
190 /* kernel/ system */
191 void (*sleep)(int ticks);
192 void (*yield)(void);
193 long* current_tick;
194 int (*default_event_handler)(int event);
195 int (*default_event_handler_ex)(int event, void (*callback)(void *), void *parameter);
196 int (*create_thread)(void* function, void* stack, int stack_size, const char *name);
197 void (*remove_thread)(int threadnum);
198 void (*reset_poweroff_timer)(void);
199 #ifndef SIMULATOR
200 int (*system_memory_guard)(int newmode);
201 #endif
203 /* strings and memory */
204 int (*snprintf)(char *buf, size_t size, const char *fmt, ...);
205 char* (*strcpy)(char *dst, const char *src);
206 char* (*strncpy)(char *dst, const char *src, size_t length);
207 size_t (*strlen)(const char *str);
208 char * (*strrchr)(const char *s, int c);
209 int (*strcmp)(const char *, const char *);
210 int (*strcasecmp)(const char *, const char *);
211 int (*strncasecmp)(const char *s1, const char *s2, size_t n);
212 void* (*memset)(void *dst, int c, size_t length);
213 void* (*memcpy)(void *out, const void *in, size_t n);
214 #ifndef SIMULATOR
215 const char *_ctype_;
216 #endif
217 int (*atoi)(const char *str);
219 /* sound */
220 void (*mpeg_sound_set)(int setting, int value);
221 #ifndef SIMULATOR
222 void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, int* size));
223 void (*mp3_play_pause)(bool play);
224 void (*mp3_play_stop)(void);
225 bool (*mp3_is_playing)(void);
226 void (*bitswap)(unsigned char *data, int length);
227 #endif
229 /* playback control */
230 void (*mpeg_play)(int offset);
231 void (*mpeg_stop)(void);
232 void (*mpeg_pause)(void);
233 void (*mpeg_resume)(void);
234 void (*mpeg_next)(void);
235 void (*mpeg_prev)(void);
236 void (*mpeg_ff_rewind)(int newtime);
237 struct mp3entry* (*mpeg_next_track)(void);
238 int (*playlist_amount)(void);
239 int (*mpeg_status)(void);
240 bool (*mpeg_has_changed_track)(void);
241 struct mp3entry* (*mpeg_current_track)(void);
242 void (*mpeg_flush_and_reload_tracks)(void);
243 int (*mpeg_get_file_pos)(void);
244 unsigned long (*mpeg_get_last_header)(void);
245 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
246 void (*mpeg_set_pitch)(int pitch);
247 #endif
249 /* MAS communication */
250 #ifndef SIMULATOR
251 int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len);
252 int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len);
253 int (*mas_readreg)(int reg);
254 int (*mas_writereg)(int reg, unsigned int val);
255 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
256 int (*mas_codec_writereg)(int reg, unsigned int val);
257 int (*mas_codec_readreg)(int reg);
258 #endif
259 #endif
261 /* misc */
262 void (*srand)(unsigned int seed);
263 int (*rand)(void);
264 void (*qsort)(void *base, size_t nmemb, size_t size,
265 int(*compar)(const void *, const void *));
266 int (*kbd_input)(char* buffer, int buflen);
267 struct tm* (*get_time)(void);
268 int (*set_time)(const struct tm *tm);
269 void* (*plugin_get_buffer)(int* buffer_size);
270 void* (*plugin_get_mp3_buffer)(int* buffer_size);
271 #ifndef SIMULATOR
272 int (*plugin_register_timer)(int cycles, int prio, void (*timer_callback)(void));
273 void (*plugin_unregister_timer)(void);
274 #endif
275 void (*plugin_tsr)(void (*exit_callback)(void));
276 #if defined(DEBUG) || defined(SIMULATOR)
277 void (*debugf)(const char *fmt, ...);
278 #endif
279 struct user_settings* global_settings;
280 bool (*mp3info)(struct mp3entry *entry, const char *filename, bool v1first);
281 int (*count_mp3_frames)(int fd, int startpos, int filesize,
282 void (*progressfunc)(int));
283 int (*create_xing_header)(int fd, int startpos, int filesize,
284 unsigned char *buf, int num_frames,
285 unsigned long header_template,
286 void (*progressfunc)(int), bool generate_toc);
287 unsigned long (*find_next_frame)(int fd, int *offset,
288 int max_offset, unsigned long last_header);
289 int (*battery_level)(void);
290 bool (*battery_level_safe)(void);
291 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
292 unsigned short (*peak_meter_scale_value)(unsigned short val,
293 int meterwidth);
294 void (*peak_meter_set_use_dbfs)(int use);
295 int (*peak_meter_get_use_dbfs)(void);
296 #endif
298 /* new stuff at the end, sort into place next time
299 the API gets incompatible */
303 /* defined by the plugin loader (plugin.c) */
304 int plugin_load(const char* plugin, void* parameter);
305 void* plugin_get_buffer(int *buffer_size);
306 void* plugin_get_mp3_buffer(int *buffer_size);
307 int plugin_register_timer(int cycles, int prio, void (*timer_callback)(void));
308 void plugin_unregister_timer(void);
309 void plugin_tsr(void (*exit_callback)(void));
311 /* defined by the plugin */
312 enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter)
313 __attribute__ ((section (".entry")));
315 #endif