blob: 56ad568a3b29eabd30dd7bb19d34fca49fd6fdad [file] [log] [blame]
Peter D'Hoye513389b2009-05-22 21:58:48 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Wincent Balin36f3a8d2010-06-01 21:44:55 +000010 * Copyright (C) 2009, 2010 Wincent Balin
Peter D'Hoye513389b2009-05-22 21:58:48 +000011 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef PDBOX_H
23#define PDBOX_H
24
Peter D'Hoye840cd102009-07-23 21:37:35 +000025/* Use TLSF. */
Magnus Holmgrenb11a7fd2009-09-23 18:36:13 +000026#include "codecs/lib/tlsf/src/tlsf.h"
Peter D'Hoye513389b2009-05-22 21:58:48 +000027
Peter D'Hoye0d4560c2009-07-03 22:16:11 +000028/* Pure Data */
Frank Gevaertsca755f72010-02-25 23:35:16 +000029#include "PDa/src/m_pd.h"
Peter D'Hoye0d4560c2009-07-03 22:16:11 +000030
Peter D'Hoye513389b2009-05-22 21:58:48 +000031/* Minimal memory size. */
Wincent Balinf52c9aa2010-06-01 20:37:16 +000032#define MIN_MEM_SIZE (4 * 1024 * 1024)
Peter D'Hoye513389b2009-05-22 21:58:48 +000033
Peter D'Hoye840cd102009-07-23 21:37:35 +000034/* Memory prototypes. */
35
Peter D'Hoye840cd102009-07-23 21:37:35 +000036/* Direct memory allocator functions to TLSF. */
37#define malloc(size) tlsf_malloc(size)
38#define free(ptr) tlsf_free(ptr)
39#define realloc(ptr, size) tlsf_realloc(ptr, size)
40#define calloc(elements, elem_size) tlsf_calloc(elements, elem_size)
Peter D'Hoye0d4560c2009-07-03 22:16:11 +000041
42/* Audio declarations. */
Wincent Balin53425ad2010-07-05 01:26:41 +000043#ifdef SIMULATOR
44 #define PD_SAMPLERATE 44100
45#elif (HW_SAMPR_CAPS & SAMPR_CAP_22)
46 #define PD_SAMPLERATE 22050
47#elif (HW_SAMPR_CAPS & SAMPR_CAP_32)
48 #define PD_SAMPLERATE 32000
49#elif (HW_SAMPR_CAPS & SAMPR_CAP_44)
50 #define PD_SAMPLERATE 44100
51#else
52 #error No sufficient sample rate available!
53#endif
Peter D'Hoye66a04922009-07-12 18:44:26 +000054#define PD_SAMPLES_PER_HZ ((PD_SAMPLERATE / HZ) + \
55 (PD_SAMPLERATE % HZ > 0 ? 1 : 0))
56#define PD_OUT_CHANNELS 2
Peter D'Hoye0d4560c2009-07-03 22:16:11 +000057
Peter D'Hoye66a04922009-07-12 18:44:26 +000058/* Audio buffer part. Contains data for one HZ period. */
Wincent Balinf52c9aa2010-06-01 20:37:16 +000059#ifdef SIMULATOR
60#define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS * 16)
61#else
Peter D'Hoye66a04922009-07-12 18:44:26 +000062#define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS)
Wincent Balinf52c9aa2010-06-01 20:37:16 +000063#endif
Peter D'Hoye66a04922009-07-12 18:44:26 +000064struct audio_buffer
Peter D'Hoye0d4560c2009-07-03 22:16:11 +000065{
Peter D'Hoye66a04922009-07-12 18:44:26 +000066 int16_t data[AUDIOBUFSIZE];
Peter D'Hoye0d4560c2009-07-03 22:16:11 +000067 unsigned int fill;
Peter D'Hoye0d4560c2009-07-03 22:16:11 +000068};
69
70
71/* Additional functions. */
72char *rb_strncat(char *s, const char *t, size_t n);
73double rb_strtod(const char*, char**);
74double rb_atof(const char*);
75void rb_ftoan(float, char*, int);
76float rb_floor(float);
77long rb_atol(const char* s);
78float rb_sin(float rad);
79float rb_cos(float rad);
80int rb_fscanf_f(int fd, float* f);
81int rb_fprintf_f(int fd, float f);
82float rb_log10(float);
83float rb_log(float);
84float rb_exp(float);
85float rb_pow(float, float);
86float rb_sqrt(float);
87float rb_fabs(float);
88float rb_atan(float);
89float rb_atan2(float, float);
90float rb_sinh(float);
91float rb_tan(float);
Thomas Martitz0246f0c2010-05-14 13:21:40 +000092#ifndef SIMULATOR
Peter D'Hoye0d4560c2009-07-03 22:16:11 +000093typedef struct
94{
95 int quot;
96 int rem;
97}
98div_t;
99div_t div(int x, int y);
Thomas Martitz0246f0c2010-05-14 13:21:40 +0000100#endif
Peter D'Hoyec133c6a2009-07-12 19:18:59 +0000101union f2i
102{
103 float f;
104 int32_t i;
105};
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000106void sys_findlibdir(const char* filename);
107int sys_startgui(const char *guidir);
108
109
110/* Network declarations. */
111
Peter D'Hoye513389b2009-05-22 21:58:48 +0000112/* Maximal size of the datagram. */
113#define MAX_DATAGRAM_SIZE 255
114
115/* This structure replaces a UDP datagram. */
116struct datagram
117{
118 bool used;
119 uint8_t size;
120 char data[MAX_DATAGRAM_SIZE];
121};
122
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000123/* Prototypes of network functions. */
Peter D'Hoye513389b2009-05-22 21:58:48 +0000124void net_init(void);
125void net_destroy(void);
126bool send_datagram(struct event_queue* route, int port,
127 char* data, size_t size);
128bool receive_datagram(struct event_queue* route, int port,
129 struct datagram* buffer);
130
131/* Network message queues. */
132extern struct event_queue gui_to_core;
133extern struct event_queue core_to_gui;
134
135/* UDP ports of the original software. */
136#define PD_CORE_PORT 3333
137#define PD_GUI_PORT 3334
138
139/* Convinience macros. */
140#define SEND_TO_CORE(data) \
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000141 send_datagram(&gui_to_core, PD_CORE_PORT, data, strlen(data))
Peter D'Hoye513389b2009-05-22 21:58:48 +0000142#define RECEIVE_TO_CORE(buffer) \
143 receive_datagram(&gui_to_core, PD_CORE_PORT, buffer)
144#define SEND_FROM_CORE(data) \
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000145 send_datagram(&core_to_gui, PD_GUI_PORT, data, strlen(data))
Peter D'Hoye513389b2009-05-22 21:58:48 +0000146#define RECEIVE_FROM_CORE(buffer) \
147 receive_datagram(&core_to_gui, PD_GUI_PORT, buffer)
148
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000149/* PD core message callback. */
150void rockbox_receive_callback(struct datagram* dg);
Peter D'Hoye655ae812009-05-23 06:24:18 +0000151
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000152
153/* Pure Data declarations. */
154
155/* Pure Data function prototypes. */
156void pd_init(void);
157
158
159/* Redefinitons of ANSI C functions. */
160#include "lib/wrappers.h"
161
Peter D'Hoye66a04922009-07-12 18:44:26 +0000162#define strncmp rb->strncmp
163#define atoi rb->atoi
164#define write rb->write
165
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000166#define strncat rb_strncat
Thomas Martitz0246f0c2010-05-14 13:21:40 +0000167
168#ifndef SIMULATOR
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000169#define floor rb_floor
170#define atof rb_atof
171#define atol rb_atol
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000172#define sin rb_sin
173#define cos rb_cos
174#define log10 rb_log10
175#define log rb_log
176#define exp rb_exp
177#define pow rb_pow
178#define sqrt rb_sqrt
179#define fabs rb_fabs
180#define atan rb_atan
181#define atan2 rb_atan2
182#define sinh rb_sinh
183#define tan rb_tan
Thomas Martitz0246f0c2010-05-14 13:21:40 +0000184#else
185#include <math.h>
186#endif
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000187
Thomas Martitz0246f0c2010-05-14 13:21:40 +0000188#define ftoan rb_ftoan
Wincent Balinbec80ca2009-08-04 02:01:55 +0000189#define strtok_r rb->strtok_r
190#define strstr rb->strcasestr
191
192
193/* PdPod GUI declarations. */
194
195enum pd_widget_id
196{
197 PD_BANG,
198 PD_VSLIDER,
199 PD_HSLIDER,
200 PD_VRADIO,
201 PD_HRADIO,
202 PD_NUMBER,
203 PD_SYMBOL,
204 PD_TEXT
205};
206
207struct pd_widget
208{
209 enum pd_widget_id id;
210 char name[128];
211 int x;
212 int y;
213 int w;
214 int h;
215 int min;
216 int max;
217 float value;
218 int timeout;
219};
220
221enum pd_key_id
222{
223 KEY_PLAY,
224 KEY_REWIND,
225 KEY_FORWARD,
226 KEY_MENU,
227 KEY_ACTION,
228 KEY_WHEELLEFT,
229 KEY_WHEELRIGHT,
230 PD_KEYS
231};
232
233/* Map real keys to virtual ones.
234 Feel free to add your preferred keymap here. */
Wincent Balind2f848f2010-06-03 02:34:19 +0000235#if (CONFIG_KEYPAD == IRIVER_H300_PAD)
Wincent Balinbec80ca2009-08-04 02:01:55 +0000236 /* Added by wincent */
237 #define PDPOD_QUIT (BUTTON_OFF)
238 #define PDPOD_PLAY (BUTTON_ON)
239 #define PDPOD_PREVIOUS (BUTTON_LEFT)
240 #define PDPOD_NEXT (BUTTON_RIGHT)
241 #define PDPOD_MENU (BUTTON_SELECT)
242 #define PDPOD_WHEELLEFT (BUTTON_DOWN)
243 #define PDPOD_WHEELRIGHT (BUTTON_UP)
244 #define PDPOD_ACTION (BUTTON_MODE)
Wincent Balind2f848f2010-06-03 02:34:19 +0000245#elif (CONFIG_KEYPAD == IRIVER_H100_PAD)
Wincent Balin54ba8512009-08-05 13:21:08 +0000246 /* Added by wincent */
247 #define PDPOD_QUIT (BUTTON_OFF)
248 #define PDPOD_PLAY (BUTTON_REC)
249 #define PDPOD_PREVIOUS (BUTTON_LEFT)
250 #define PDPOD_NEXT (BUTTON_RIGHT)
251 #define PDPOD_MENU (BUTTON_SELECT)
252 #define PDPOD_WHEELLEFT (BUTTON_DOWN)
253 #define PDPOD_WHEELRIGHT (BUTTON_UP)
254 #define PDPOD_ACTION (BUTTON_ON)
Wincent Balind2f848f2010-06-03 02:34:19 +0000255#elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
256 /* Added by funman */
Rafaël Carréef574752010-06-02 20:15:44 +0000257 #define PDPOD_QUIT (BUTTON_HOME|BUTTON_REPEAT)
258 #define PDPOD_PLAY BUTTON_UP
259 #define PDPOD_PREVIOUS BUTTON_LEFT
260 #define PDPOD_NEXT BUTTON_RIGHT
261 #define PDPOD_MENU BUTTON_SELECT
262 #define PDPOD_WHEELLEFT BUTTON_SCROLL_BACK
263 #define PDPOD_WHEELRIGHT BUTTON_SCROLL_FWD
264 #define PDPOD_ACTION BUTTON_DOWN
Wincent Balind5342fd2010-07-05 01:31:57 +0000265#elif (CONFIG_KEYPAD == SANSA_E200_PAD)
266 #define PDPOD_QUIT (BUTTON_POWER|BUTTON_REPEAT)
267 #define PDPOD_PLAY BUTTON_UP
268 #define PDPOD_PREVIOUS BUTTON_LEFT
269 #define PDPOD_NEXT BUTTON_RIGHT
270 #define PDPOD_MENU BUTTON_DOWN
271 #define PDPOD_WHEELLEFT BUTTON_SCROLL_BACK
272 #define PDPOD_WHEELRIGHT BUTTON_SCROLL_FWD
273 #define PDPOD_ACTION BUTTON_SELECT
Wincent Balind2f848f2010-06-03 02:34:19 +0000274#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
275 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
276 /* Added by wincent */
277 #define PDPOD_QUIT (BUTTON_SELECT | BUTTON_MENU)
278 #define PDPOD_PLAY (BUTTON_PLAY)
279 #define PDPOD_PREVIOUS (BUTTON_LEFT)
280 #define PDPOD_NEXT (BUTTON_RIGHT)
281 #define PDPOD_MENU (BUTTON_MENU)
282 #define PDPOD_WHEELLEFT (BUTTON_SCROLL_BACK)
283 #define PDPOD_WHEELRIGHT (BUTTON_SCROLL_FWD)
284 #define PDPOD_ACTION (BUTTON_SELECT)
Wincent Balinbec80ca2009-08-04 02:01:55 +0000285#else
286 #warning "No keys defined for this architecture!"
287#endif
288
289/* Prototype of GUI functions. */
290void pd_gui_init(void);
291unsigned int pd_gui_load_patch(struct pd_widget* wg, unsigned int max_widgets);
292void pd_gui_draw(struct pd_widget* wg, unsigned int widgets);
293bool pd_gui_parse_buttons(unsigned int widgets);
294void pd_gui_parse_message(struct datagram* dg,
295 struct pd_widget* wg, unsigned int widgets);
296bool pd_gui_apply_timeouts(struct pd_widget* wg, unsigned int widgets);
297
Peter D'Hoye0d4560c2009-07-03 22:16:11 +0000298#endif