1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 Wincent Balin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
34 /* Minimal memory size. */
35 #define MIN_MEM_SIZE (4 * 1024 * 1024)
37 /* Memory prototypes. */
40 /* Direct memory allocator functions to TLSF. */
41 #define malloc(size) tlsf_malloc(size)
42 #define free(ptr) tlsf_free(ptr)
43 #define realloc(ptr, size) tlsf_realloc(ptr, size)
44 #define calloc(elements, elem_size) tlsf_calloc(elements, elem_size)
48 extern void set_memory_pool(void* memory_pool
, size_t memory_size
);
49 extern void clear_memory_pool(void);
50 extern void* mcalloc(size_t nmemb
, size_t size
);
51 extern void* mmalloc(size_t size
);
52 extern void mfree(void* ptr
);
53 extern void* mrealloc(void* ptr
, size_t size
);
54 extern void print_memory_pool(void);
56 #define malloc mmalloc
58 #define realloc mrealloc
59 #define calloc mcalloc
66 #define realloc realloc
70 /* Audio declarations. */
71 #define PD_SAMPLERATE 22050
72 #define PD_SAMPLES_PER_HZ ((PD_SAMPLERATE / HZ) + \
73 (PD_SAMPLERATE % HZ > 0 ? 1 : 0))
74 #define PD_OUT_CHANNELS 2
76 /* Audio buffer part. Contains data for one HZ period. */
78 #define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS * 32)
80 #define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS)
84 int16_t data
[AUDIOBUFSIZE
];
89 /* Additional functions. */
90 char *rb_strncat(char *s
, const char *t
, size_t n
);
91 double rb_strtod(const char*, char**);
92 double rb_atof(const char*);
93 void rb_ftoan(float, char*, int);
94 float rb_floor(float);
95 long rb_atol(const char* s
);
96 float rb_sin(float rad
);
97 float rb_cos(float rad
);
98 int rb_fscanf_f(int fd
, float* f
);
99 int rb_fprintf_f(int fd
, float f
);
100 float rb_log10(float);
103 float rb_pow(float, float);
104 float rb_sqrt(float);
105 float rb_fabs(float);
106 float rb_atan(float);
107 float rb_atan2(float, float);
108 float rb_sinh(float);
116 div_t div(int x
, int y
);
122 void sys_findlibdir(const char* filename
);
123 int sys_startgui(const char *guidir
);
126 /* Network declarations. */
128 /* Maximal size of the datagram. */
129 #define MAX_DATAGRAM_SIZE 255
131 /* This structure replaces a UDP datagram. */
136 char data
[MAX_DATAGRAM_SIZE
];
139 /* Prototypes of network functions. */
141 void net_destroy(void);
142 bool send_datagram(struct event_queue
* route
, int port
,
143 char* data
, size_t size
);
144 bool receive_datagram(struct event_queue
* route
, int port
,
145 struct datagram
* buffer
);
147 /* Network message queues. */
148 extern struct event_queue gui_to_core
;
149 extern struct event_queue core_to_gui
;
151 /* UDP ports of the original software. */
152 #define PD_CORE_PORT 3333
153 #define PD_GUI_PORT 3334
155 /* Convinience macros. */
156 #define SEND_TO_CORE(data) \
157 send_datagram(&gui_to_core, PD_CORE_PORT, data, strlen(data))
158 #define RECEIVE_TO_CORE(buffer) \
159 receive_datagram(&gui_to_core, PD_CORE_PORT, buffer)
160 #define SEND_FROM_CORE(data) \
161 send_datagram(&core_to_gui, PD_GUI_PORT, data, strlen(data))
162 #define RECEIVE_FROM_CORE(buffer) \
163 receive_datagram(&core_to_gui, PD_GUI_PORT, buffer)
165 /* PD core message callback. */
166 void rockbox_receive_callback(struct datagram
* dg
);
169 /* Pure Data declarations. */
171 /* Pure Data function prototypes. */
175 /* Redefinitons of ANSI C functions. */
176 #include "lib/wrappers.h"
178 #define strncmp rb->strncmp
179 #define atoi rb->atoi
180 #define write rb->write
182 #define strncat rb_strncat
183 #define floor rb_floor
186 #define ftoan rb_ftoan
189 #define log10 rb_log10
196 #define atan2 rb_atan2
200 #define strtok_r rb->strtok_r
201 #define strstr rb->strcasestr
204 /* PdPod GUI declarations. */
220 enum pd_widget_id id
;
244 /* Map real keys to virtual ones.
245 Feel free to add your preferred keymap here. */
246 #if defined(IRIVER_H300_SERIES)
247 /* Added by wincent */
248 #define PDPOD_QUIT (BUTTON_OFF)
249 #define PDPOD_PLAY (BUTTON_ON)
250 #define PDPOD_PREVIOUS (BUTTON_LEFT)
251 #define PDPOD_NEXT (BUTTON_RIGHT)
252 #define PDPOD_MENU (BUTTON_SELECT)
253 #define PDPOD_WHEELLEFT (BUTTON_DOWN)
254 #define PDPOD_WHEELRIGHT (BUTTON_UP)
255 #define PDPOD_ACTION (BUTTON_MODE)
256 #elif defined(IRIVER_H100_SERIES)
257 /* Added by wincent */
258 #define PDPOD_QUIT (BUTTON_OFF)
259 #define PDPOD_PLAY (BUTTON_REC)
260 #define PDPOD_PREVIOUS (BUTTON_LEFT)
261 #define PDPOD_NEXT (BUTTON_RIGHT)
262 #define PDPOD_MENU (BUTTON_SELECT)
263 #define PDPOD_WHEELLEFT (BUTTON_DOWN)
264 #define PDPOD_WHEELRIGHT (BUTTON_UP)
265 #define PDPOD_ACTION (BUTTON_ON)
267 #warning "No keys defined for this architecture!"
270 /* Prototype of GUI functions. */
271 void pd_gui_init(void);
272 unsigned int pd_gui_load_patch(struct pd_widget
* wg
, unsigned int max_widgets
);
273 void pd_gui_draw(struct pd_widget
* wg
, unsigned int widgets
);
274 bool pd_gui_parse_buttons(unsigned int widgets
);
275 void pd_gui_parse_message(struct datagram
* dg
,
276 struct pd_widget
* wg
, unsigned int widgets
);
277 bool pd_gui_apply_timeouts(struct pd_widget
* wg
, unsigned int widgets
);