Peter D'Hoye | 513389b | 2009-05-22 21:58:48 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
Wincent Balin | 36f3a8d | 2010-06-01 21:44:55 +0000 | [diff] [blame] | 10 | * Copyright (C) 2009, 2010 Wincent Balin |
Peter D'Hoye | 513389b | 2009-05-22 21:58:48 +0000 | [diff] [blame] | 11 | * |
| 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'Hoye | 840cd10 | 2009-07-23 21:37:35 +0000 | [diff] [blame] | 25 | /* Use TLSF. */ |
Magnus Holmgren | b11a7fd | 2009-09-23 18:36:13 +0000 | [diff] [blame] | 26 | #include "codecs/lib/tlsf/src/tlsf.h" |
Peter D'Hoye | 513389b | 2009-05-22 21:58:48 +0000 | [diff] [blame] | 27 | |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 28 | /* Pure Data */ |
Frank Gevaerts | ca755f7 | 2010-02-25 23:35:16 +0000 | [diff] [blame] | 29 | #include "PDa/src/m_pd.h" |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 30 | |
Peter D'Hoye | 513389b | 2009-05-22 21:58:48 +0000 | [diff] [blame] | 31 | /* Minimal memory size. */ |
Wincent Balin | f52c9aa | 2010-06-01 20:37:16 +0000 | [diff] [blame] | 32 | #define MIN_MEM_SIZE (4 * 1024 * 1024) |
Peter D'Hoye | 513389b | 2009-05-22 21:58:48 +0000 | [diff] [blame] | 33 | |
Peter D'Hoye | 840cd10 | 2009-07-23 21:37:35 +0000 | [diff] [blame] | 34 | /* Memory prototypes. */ |
| 35 | |
Peter D'Hoye | 840cd10 | 2009-07-23 21:37:35 +0000 | [diff] [blame] | 36 | /* 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'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 41 | |
| 42 | /* Audio declarations. */ |
Wincent Balin | 53425ad | 2010-07-05 01:26:41 +0000 | [diff] [blame] | 43 | #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'Hoye | 66a0492 | 2009-07-12 18:44:26 +0000 | [diff] [blame] | 54 | #define PD_SAMPLES_PER_HZ ((PD_SAMPLERATE / HZ) + \ |
| 55 | (PD_SAMPLERATE % HZ > 0 ? 1 : 0)) |
| 56 | #define PD_OUT_CHANNELS 2 |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 57 | |
Peter D'Hoye | 66a0492 | 2009-07-12 18:44:26 +0000 | [diff] [blame] | 58 | /* Audio buffer part. Contains data for one HZ period. */ |
Wincent Balin | f52c9aa | 2010-06-01 20:37:16 +0000 | [diff] [blame] | 59 | #ifdef SIMULATOR |
| 60 | #define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS * 16) |
| 61 | #else |
Peter D'Hoye | 66a0492 | 2009-07-12 18:44:26 +0000 | [diff] [blame] | 62 | #define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS) |
Wincent Balin | f52c9aa | 2010-06-01 20:37:16 +0000 | [diff] [blame] | 63 | #endif |
Peter D'Hoye | 66a0492 | 2009-07-12 18:44:26 +0000 | [diff] [blame] | 64 | struct audio_buffer |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 65 | { |
Peter D'Hoye | 66a0492 | 2009-07-12 18:44:26 +0000 | [diff] [blame] | 66 | int16_t data[AUDIOBUFSIZE]; |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 67 | unsigned int fill; |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | |
| 71 | /* Additional functions. */ |
| 72 | char *rb_strncat(char *s, const char *t, size_t n); |
| 73 | double rb_strtod(const char*, char**); |
| 74 | double rb_atof(const char*); |
| 75 | void rb_ftoan(float, char*, int); |
| 76 | float rb_floor(float); |
| 77 | long rb_atol(const char* s); |
| 78 | float rb_sin(float rad); |
| 79 | float rb_cos(float rad); |
| 80 | int rb_fscanf_f(int fd, float* f); |
| 81 | int rb_fprintf_f(int fd, float f); |
| 82 | float rb_log10(float); |
| 83 | float rb_log(float); |
| 84 | float rb_exp(float); |
| 85 | float rb_pow(float, float); |
| 86 | float rb_sqrt(float); |
| 87 | float rb_fabs(float); |
| 88 | float rb_atan(float); |
| 89 | float rb_atan2(float, float); |
| 90 | float rb_sinh(float); |
| 91 | float rb_tan(float); |
Thomas Martitz | 0246f0c | 2010-05-14 13:21:40 +0000 | [diff] [blame] | 92 | #ifndef SIMULATOR |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 93 | typedef struct |
| 94 | { |
| 95 | int quot; |
| 96 | int rem; |
| 97 | } |
| 98 | div_t; |
| 99 | div_t div(int x, int y); |
Thomas Martitz | 0246f0c | 2010-05-14 13:21:40 +0000 | [diff] [blame] | 100 | #endif |
Peter D'Hoye | c133c6a | 2009-07-12 19:18:59 +0000 | [diff] [blame] | 101 | union f2i |
| 102 | { |
| 103 | float f; |
| 104 | int32_t i; |
| 105 | }; |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 106 | void sys_findlibdir(const char* filename); |
| 107 | int sys_startgui(const char *guidir); |
| 108 | |
| 109 | |
| 110 | /* Network declarations. */ |
| 111 | |
Peter D'Hoye | 513389b | 2009-05-22 21:58:48 +0000 | [diff] [blame] | 112 | /* Maximal size of the datagram. */ |
| 113 | #define MAX_DATAGRAM_SIZE 255 |
| 114 | |
| 115 | /* This structure replaces a UDP datagram. */ |
| 116 | struct datagram |
| 117 | { |
| 118 | bool used; |
| 119 | uint8_t size; |
| 120 | char data[MAX_DATAGRAM_SIZE]; |
| 121 | }; |
| 122 | |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 123 | /* Prototypes of network functions. */ |
Peter D'Hoye | 513389b | 2009-05-22 21:58:48 +0000 | [diff] [blame] | 124 | void net_init(void); |
| 125 | void net_destroy(void); |
| 126 | bool send_datagram(struct event_queue* route, int port, |
| 127 | char* data, size_t size); |
| 128 | bool receive_datagram(struct event_queue* route, int port, |
| 129 | struct datagram* buffer); |
| 130 | |
| 131 | /* Network message queues. */ |
| 132 | extern struct event_queue gui_to_core; |
| 133 | extern 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'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 141 | send_datagram(&gui_to_core, PD_CORE_PORT, data, strlen(data)) |
Peter D'Hoye | 513389b | 2009-05-22 21:58:48 +0000 | [diff] [blame] | 142 | #define RECEIVE_TO_CORE(buffer) \ |
| 143 | receive_datagram(&gui_to_core, PD_CORE_PORT, buffer) |
| 144 | #define SEND_FROM_CORE(data) \ |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 145 | send_datagram(&core_to_gui, PD_GUI_PORT, data, strlen(data)) |
Peter D'Hoye | 513389b | 2009-05-22 21:58:48 +0000 | [diff] [blame] | 146 | #define RECEIVE_FROM_CORE(buffer) \ |
| 147 | receive_datagram(&core_to_gui, PD_GUI_PORT, buffer) |
| 148 | |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 149 | /* PD core message callback. */ |
| 150 | void rockbox_receive_callback(struct datagram* dg); |
Peter D'Hoye | 655ae81 | 2009-05-23 06:24:18 +0000 | [diff] [blame] | 151 | |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 152 | |
| 153 | /* Pure Data declarations. */ |
| 154 | |
| 155 | /* Pure Data function prototypes. */ |
| 156 | void pd_init(void); |
| 157 | |
| 158 | |
| 159 | /* Redefinitons of ANSI C functions. */ |
| 160 | #include "lib/wrappers.h" |
| 161 | |
Peter D'Hoye | 66a0492 | 2009-07-12 18:44:26 +0000 | [diff] [blame] | 162 | #define strncmp rb->strncmp |
| 163 | #define atoi rb->atoi |
| 164 | #define write rb->write |
| 165 | |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 166 | #define strncat rb_strncat |
Thomas Martitz | 0246f0c | 2010-05-14 13:21:40 +0000 | [diff] [blame] | 167 | |
| 168 | #ifndef SIMULATOR |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 169 | #define floor rb_floor |
| 170 | #define atof rb_atof |
| 171 | #define atol rb_atol |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 172 | #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 Martitz | 0246f0c | 2010-05-14 13:21:40 +0000 | [diff] [blame] | 184 | #else |
| 185 | #include <math.h> |
| 186 | #endif |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 187 | |
Thomas Martitz | 0246f0c | 2010-05-14 13:21:40 +0000 | [diff] [blame] | 188 | #define ftoan rb_ftoan |
Wincent Balin | bec80ca | 2009-08-04 02:01:55 +0000 | [diff] [blame] | 189 | #define strtok_r rb->strtok_r |
| 190 | #define strstr rb->strcasestr |
| 191 | |
| 192 | |
| 193 | /* PdPod GUI declarations. */ |
| 194 | |
| 195 | enum 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 | |
| 207 | struct 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 | |
| 221 | enum 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 Balin | d2f848f | 2010-06-03 02:34:19 +0000 | [diff] [blame] | 235 | #if (CONFIG_KEYPAD == IRIVER_H300_PAD) |
Wincent Balin | bec80ca | 2009-08-04 02:01:55 +0000 | [diff] [blame] | 236 | /* 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 Balin | d2f848f | 2010-06-03 02:34:19 +0000 | [diff] [blame] | 245 | #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) |
Wincent Balin | 54ba851 | 2009-08-05 13:21:08 +0000 | [diff] [blame] | 246 | /* 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 Balin | d2f848f | 2010-06-03 02:34:19 +0000 | [diff] [blame] | 255 | #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD) |
| 256 | /* Added by funman */ |
Rafaël Carré | ef57475 | 2010-06-02 20:15:44 +0000 | [diff] [blame] | 257 | #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 Balin | d5342fd | 2010-07-05 01:31:57 +0000 | [diff] [blame^] | 265 | #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 Balin | d2f848f | 2010-06-03 02:34:19 +0000 | [diff] [blame] | 274 | #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 Balin | bec80ca | 2009-08-04 02:01:55 +0000 | [diff] [blame] | 285 | #else |
| 286 | #warning "No keys defined for this architecture!" |
| 287 | #endif |
| 288 | |
| 289 | /* Prototype of GUI functions. */ |
| 290 | void pd_gui_init(void); |
| 291 | unsigned int pd_gui_load_patch(struct pd_widget* wg, unsigned int max_widgets); |
| 292 | void pd_gui_draw(struct pd_widget* wg, unsigned int widgets); |
| 293 | bool pd_gui_parse_buttons(unsigned int widgets); |
| 294 | void pd_gui_parse_message(struct datagram* dg, |
| 295 | struct pd_widget* wg, unsigned int widgets); |
| 296 | bool pd_gui_apply_timeouts(struct pd_widget* wg, unsigned int widgets); |
| 297 | |
Peter D'Hoye | 0d4560c | 2009-07-03 22:16:11 +0000 | [diff] [blame] | 298 | #endif |