summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/demac/libdemac/crc.c1
-rw-r--r--apps/iap.c1004
-rw-r--r--apps/main.c2
-rw-r--r--apps/recorder/resize.c3
-rw-r--r--firmware/target/arm/ascodec-pp.c1
5 files changed, 507 insertions, 504 deletions
diff --git a/apps/codecs/demac/libdemac/crc.c b/apps/codecs/demac/libdemac/crc.c
index 816c6594f7..fa3ea89d7e 100644
--- a/apps/codecs/demac/libdemac/crc.c
+++ b/apps/codecs/demac/libdemac/crc.c
@@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
23*/ 23*/
24 24
25#include <inttypes.h> 25#include <inttypes.h>
26#include "demac.h"
26 27
27static const uint32_t crctab32[] = 28static const uint32_t crctab32[] =
28{ 29{
diff --git a/apps/iap.c b/apps/iap.c
index a15fd81a90..dd29563b1e 100644
--- a/apps/iap.c
+++ b/apps/iap.c
@@ -86,21 +86,21 @@ void iap_bitrate_set(int ratenum)
86{ 86{
87 switch(ratenum) 87 switch(ratenum)
88 { 88 {
89 case 0: 89 case 0:
90 serial_bitrate(0); 90 serial_bitrate(0);
91 break; 91 break;
92 case 1: 92 case 1:
93 serial_bitrate(9600); 93 serial_bitrate(9600);
94 break; 94 break;
95 case 2: 95 case 2:
96 serial_bitrate(19200); 96 serial_bitrate(19200);
97 break; 97 break;
98 case 3: 98 case 3:
99 serial_bitrate(38400); 99 serial_bitrate(38400);
100 break; 100 break;
101 case 4: 101 case 4:
102 serial_bitrate(57600); 102 serial_bitrate(57600);
103 break; 103 break;
104 } 104 }
105} 105}
106 106
@@ -114,7 +114,7 @@ void iap_bitrate_set(int ratenum)
114 checksum (length+mode+parameters+checksum == 0) 114 checksum (length+mode+parameters+checksum == 0)
115*/ 115*/
116 116
117void iap_send_pkt(unsigned char * data, int len) 117static void iap_send_pkt(const unsigned char * data, int len)
118{ 118{
119 int i, chksum; 119 int i, chksum;
120 120
@@ -127,8 +127,8 @@ void iap_send_pkt(unsigned char * data, int len)
127 chksum = response[2] = len; 127 chksum = response[2] = len;
128 for(i = 0; i < len; i ++) 128 for(i = 0; i < len; i ++)
129 { 129 {
130 chksum += data[i]; 130 chksum += data[i];
131 response[i+3] = data[i]; 131 response[i+3] = data[i];
132 } 132 }
133 133
134 response[i+3] = 0x100 - (chksum & 0xFF); 134 response[i+3] = 0x100 - (chksum & 0xFF);
@@ -136,7 +136,7 @@ void iap_send_pkt(unsigned char * data, int len)
136 for(i = 0; i < responselen; i ++) 136 for(i = 0; i < responselen; i ++)
137 { 137 {
138 while (!tx_rdy()) ; 138 while (!tx_rdy()) ;
139 tx_writec(response[i]); 139 tx_writec(response[i]);
140 } 140 }
141} 141}
142 142
@@ -145,14 +145,14 @@ int iap_getc(unsigned char x)
145 static unsigned char last_x = 0; 145 static unsigned char last_x = 0;
146 static bool newpkt = true; 146 static bool newpkt = true;
147 static unsigned char chksum = 0; 147 static unsigned char chksum = 0;
148 148
149 /* Restart if the sync word is seen */ 149 /* Restart if the sync word is seen */
150 if(x == 0x55 && last_x == 0xff/* && newpkt*/) 150 if(x == 0x55 && last_x == 0xff/* && newpkt*/)
151 { 151 {
152 serbuf[0] = 0; 152 serbuf[0] = 0;
153 serbuf_i = 0; 153 serbuf_i = 0;
154 chksum = 0; 154 chksum = 0;
155 newpkt = false; 155 newpkt = false;
156 } 156 }
157 else 157 else
158 { 158 {
@@ -167,10 +167,10 @@ int iap_getc(unsigned char x)
167 /* Broadcast to queue if we have a complete message */ 167 /* Broadcast to queue if we have a complete message */
168 if(serbuf_i && (serbuf_i == serbuf[0]+2)) 168 if(serbuf_i && (serbuf_i == serbuf[0]+2))
169 { 169 {
170 serbuf_i = 0; 170 serbuf_i = 0;
171 newpkt = true; 171 newpkt = true;
172 if(chksum == 0) 172 if(chksum == 0)
173 queue_post(&button_queue, SYS_IAP_HANDLEPKT, 0); 173 queue_post(&button_queue, SYS_IAP_HANDLEPKT, 0);
174 } 174 }
175 return newpkt; 175 return newpkt;
176} 176}
@@ -194,11 +194,11 @@ void iap_periodic(void)
194 194
195 /* If info has changed, don't flag it right away */ 195 /* If info has changed, don't flag it right away */
196 if(iap_changedctr && iap_changedctr++ >= iap_pollspeed * 2) 196 if(iap_changedctr && iap_changedctr++ >= iap_pollspeed * 2)
197 { 197 {
198 /* track info has changed */ 198 /* track info has changed */
199 iap_changedctr = 0; 199 iap_changedctr = 0;
200 data[3] = 0x01; // 0x02 has same effect? 200 data[3] = 0x01; // 0x02 has same effect?
201 iap_updateflag = true; 201 iap_updateflag = true;
202 } 202 }
203 203
204 data[4] = time_elapsed >> 24; 204 data[4] = time_elapsed >> 24;
@@ -218,495 +218,495 @@ void iap_handlepkt(void)
218 delay the handling of the new packet */ 218 delay the handling of the new packet */
219 if(!iap_remotetick) 219 if(!iap_remotetick)
220 { 220 {
221 queue_post(&button_queue, SYS_IAP_HANDLEPKT, 0); 221 queue_post(&button_queue, SYS_IAP_HANDLEPKT, 0);
222 return; 222 return;
223 } 223 }
224 224
225 /* Handle Mode 0 */ 225 /* Handle Mode 0 */
226 if (serbuf[1] == 0x00) 226 if (serbuf[1] == 0x00)
227 { 227 {
228 switch (serbuf[2]) 228 switch (serbuf[2])
229 { 229 {
230 /* get model info */ 230 /* get model info */
231 case 0x0D: 231 case 0x0D:
232 { 232 {
233 unsigned char data[] = {0x00, 0x0E, 0x00, 0x0B, 0x00, 0x10, 233 unsigned char data[] = {0x00, 0x0E, 0x00, 0x0B, 0x00, 0x10,
234 'R', 'O', 'C', 'K', 'B', 'O', 'X', 0x00}; 234 'R', 'O', 'C', 'K', 'B', 'O', 'X', 0x00};
235 iap_send_pkt(data, sizeof(data)); 235 iap_send_pkt(data, sizeof(data));
236 break; 236 break;
237 } 237 }
238 /* No idea ??? */ 238 /* No idea ??? */
239 case 0x0F: 239 case 0x0F:
240 { 240 {
241 unsigned char data[] = {0x00, 0x10, 0x00, 0x01, 0x05}; 241 unsigned char data[] = {0x00, 0x10, 0x00, 0x01, 0x05};
242 iap_send_pkt(data, sizeof(data)); 242 iap_send_pkt(data, sizeof(data));
243 break; 243 break;
244 } 244 }
245 /* FM transmitter sends this: FF 55 06 00 01 05 00 02 01 F1 (mode switch) */ 245 /* FM transmitter sends this: FF 55 06 00 01 05 00 02 01 F1 (mode switch) */
246 case 0x01: 246 case 0x01:
247 { 247 {
248 if(serbuf[3] == 0x05) 248 if(serbuf[3] == 0x05)
249 { 249 {
250 sleep(HZ/3); 250 sleep(HZ/3);
251 unsigned char data[] = {0x05, 0x02}; 251 unsigned char data[] = {0x05, 0x02};
252 iap_send_pkt(data, sizeof(data)); 252 iap_send_pkt(data, sizeof(data));
253 } 253 }
254 break; 254 break;
255 } 255 }
256 /* FM transmitter sends this: FF 55 0E 00 13 00 00 00 35 00 00 00 04 00 00 00 00 A6 (???)*/ 256 /* FM transmitter sends this: FF 55 0E 00 13 00 00 00 35 00 00 00 04 00 00 00 00 A6 (???)*/
257 case 0x13: 257 case 0x13:
258 { 258 {
259 unsigned char data[] = {0x00, 0x02, 0x00, 0x13}; 259 unsigned char data[] = {0x00, 0x02, 0x00, 0x13};
260 iap_send_pkt(data, sizeof(data)); 260 iap_send_pkt(data, sizeof(data));
261 unsigned char data2[] = {0x00, 0x27, 0x00}; 261 unsigned char data2[] = {0x00, 0x27, 0x00};
262 iap_send_pkt(data2, sizeof(data2)); 262 iap_send_pkt(data2, sizeof(data2));
263 unsigned char data3[] = {0x05, 0x02}; 263 unsigned char data3[] = {0x05, 0x02};
264 iap_send_pkt(data3, sizeof(data3)); 264 iap_send_pkt(data3, sizeof(data3));
265 break; 265 break;
266 } 266 }
267 /* FM transmitter sends this: FF 55 02 00 05 F9 (mode switch: AiR mode) */ 267 /* FM transmitter sends this: FF 55 02 00 05 F9 (mode switch: AiR mode) */
268 case 0x05: 268 case 0x05:
269 { 269 {
270 unsigned char data[] = {0x00, 0x02, 0x06, 0x05, 0x00, 0x00, 0x0B, 0xB8, 0x28}; 270 unsigned char data[] = {0x00, 0x02, 0x06, 0x05, 0x00, 0x00, 0x0B, 0xB8, 0x28};
271 iap_send_pkt(data, sizeof(data)); 271 iap_send_pkt(data, sizeof(data));
272 unsigned char data2[] = {0x00, 0x02, 0x00, 0x05}; 272 unsigned char data2[] = {0x00, 0x02, 0x00, 0x05};
273 iap_send_pkt(data2, sizeof(data2)); 273 iap_send_pkt(data2, sizeof(data2));
274 break; 274 break;
275 } 275 }
276 /* default response is with cmd ok packet */ 276 /* default response is with cmd ok packet */
277 default: 277 default:
278 { 278 {
279 unsigned char data[] = {0x00, 0x02, 0x00, 0x00}; 279 unsigned char data[] = {0x00, 0x02, 0x00, 0x00};
280 data[3] = serbuf[2]; //respond with cmd 280 data[3] = serbuf[2]; //respond with cmd
281 iap_send_pkt(data, sizeof(data)); 281 iap_send_pkt(data, sizeof(data));
282 break; 282 break;
283 } 283 }
284 } 284 }
285 } 285 }
286 /* Handle Mode 2 */ 286 /* Handle Mode 2 */
287 else if (serbuf[1] == 0x02) 287 else if (serbuf[1] == 0x02)
288 { 288 {
289 if(serbuf[2] != 0) return; 289 if(serbuf[2] != 0) return;
290 iap_remotebtn = BUTTON_NONE; 290 iap_remotebtn = BUTTON_NONE;
291 iap_remotetick = false; 291 iap_remotetick = false;
292 292
293 if(serbuf[0] >= 3 && serbuf[3] != 0) 293 if(serbuf[0] >= 3 && serbuf[3] != 0)
294 { 294 {
295 if(serbuf[3] & 1) 295 if(serbuf[3] & 1)
296 iap_remotebtn |= BUTTON_RC_PLAY; 296 iap_remotebtn |= BUTTON_RC_PLAY;
297 if(serbuf[3] & 2) 297 if(serbuf[3] & 2)
298 iap_remotebtn |= BUTTON_RC_VOL_UP; 298 iap_remotebtn |= BUTTON_RC_VOL_UP;
299 if(serbuf[3] & 4) 299 if(serbuf[3] & 4)
300 iap_remotebtn |= BUTTON_RC_VOL_DOWN; 300 iap_remotebtn |= BUTTON_RC_VOL_DOWN;
301 if(serbuf[3] & 8) 301 if(serbuf[3] & 8)
302 iap_remotebtn |= BUTTON_RC_RIGHT; 302 iap_remotebtn |= BUTTON_RC_RIGHT;
303 if(serbuf[3] & 16) 303 if(serbuf[3] & 16)
304 iap_remotebtn |= BUTTON_RC_LEFT; 304 iap_remotebtn |= BUTTON_RC_LEFT;
305 } 305 }
306 else if(serbuf[0] >= 4 && serbuf[4] != 0) 306 else if(serbuf[0] >= 4 && serbuf[4] != 0)
307 { 307 {
308 if(serbuf[4] & 1) /* play */ 308 if(serbuf[4] & 1) /* play */
309 { 309 {
310 if (audio_status() != AUDIO_STATUS_PLAY) 310 if (audio_status() != AUDIO_STATUS_PLAY)
311 { 311 {
312 iap_remotebtn |= BUTTON_RC_PLAY; 312 iap_remotebtn |= BUTTON_RC_PLAY;
313 iap_repeatbtn = 2; 313 iap_repeatbtn = 2;
314 iap_remotetick = false; 314 iap_remotetick = false;
315 iap_changedctr = 1; 315 iap_changedctr = 1;
316 } 316 }
317 } 317 }
318 if(serbuf[4] & 2) /* pause */ 318 if(serbuf[4] & 2) /* pause */
319 { 319 {
320 if (audio_status() == AUDIO_STATUS_PLAY) 320 if (audio_status() == AUDIO_STATUS_PLAY)
321 { 321 {
322 iap_remotebtn |= BUTTON_RC_PLAY; 322 iap_remotebtn |= BUTTON_RC_PLAY;
323 iap_repeatbtn = 2; 323 iap_repeatbtn = 2;
324 iap_remotetick = false; 324 iap_remotetick = false;
325 iap_changedctr = 1; 325 iap_changedctr = 1;
326 } 326 }
327 } 327 }
328 if((serbuf[4] & 128) && !iap_btnshuffle) /* shuffle */ 328 if((serbuf[4] & 128) && !iap_btnshuffle) /* shuffle */
329 { 329 {
330 iap_btnshuffle = true; 330 iap_btnshuffle = true;
331 if(!global_settings.playlist_shuffle) 331 if(!global_settings.playlist_shuffle)
332 { 332 {
333 global_settings.playlist_shuffle = 1; 333 global_settings.playlist_shuffle = 1;
334 settings_save(); 334 settings_save();
335 settings_apply(false); 335 settings_apply(false);
336 if (audio_status() & AUDIO_STATUS_PLAY) 336 if (audio_status() & AUDIO_STATUS_PLAY)
337 playlist_randomise(NULL, current_tick, true); 337 playlist_randomise(NULL, current_tick, true);
338 } 338 }
339 else if(global_settings.playlist_shuffle) 339 else if(global_settings.playlist_shuffle)
340 { 340 {
341 global_settings.playlist_shuffle = 0; 341 global_settings.playlist_shuffle = 0;
342 settings_save(); 342 settings_save();
343 settings_apply(false); 343 settings_apply(false);
344 if (audio_status() & AUDIO_STATUS_PLAY) 344 if (audio_status() & AUDIO_STATUS_PLAY)
345 playlist_sort(NULL, true); 345 playlist_sort(NULL, true);
346 } 346 }
347 } 347 }
348 else 348 else
349 iap_btnshuffle = false; 349 iap_btnshuffle = false;
350 } 350 }
351 else if(serbuf[0] >= 5 && serbuf[5] != 0) 351 else if(serbuf[0] >= 5 && serbuf[5] != 0)
352 { 352 {
353 if((serbuf[5] & 1) && !iap_btnrepeat) /* repeat */ 353 if((serbuf[5] & 1) && !iap_btnrepeat) /* repeat */
354 { 354 {
355 int oldmode = global_settings.repeat_mode; 355 int oldmode = global_settings.repeat_mode;
356 iap_btnrepeat = true; 356 iap_btnrepeat = true;
357 357
358 if (oldmode == REPEAT_ONE) 358 if (oldmode == REPEAT_ONE)
359 global_settings.repeat_mode = REPEAT_OFF; 359 global_settings.repeat_mode = REPEAT_OFF;
360 else if (oldmode == REPEAT_ALL) 360 else if (oldmode == REPEAT_ALL)
361 global_settings.repeat_mode = REPEAT_ONE; 361 global_settings.repeat_mode = REPEAT_ONE;
362 else if (oldmode == REPEAT_OFF) 362 else if (oldmode == REPEAT_OFF)
363 global_settings.repeat_mode = REPEAT_ALL; 363 global_settings.repeat_mode = REPEAT_ALL;
364 364
365 settings_save(); 365 settings_save();
366 settings_apply(false); 366 settings_apply(false);
367 if (audio_status() & AUDIO_STATUS_PLAY) 367 if (audio_status() & AUDIO_STATUS_PLAY)
368 audio_flush_and_reload_tracks(); 368 audio_flush_and_reload_tracks();
369 } 369 }
370 else 370 else
371 iap_btnrepeat = false; 371 iap_btnrepeat = false;
372 372
373 if(serbuf[5] & 16) /* ffwd */ 373 if(serbuf[5] & 16) /* ffwd */
374 { 374 {
375 iap_remotebtn |= BUTTON_RC_RIGHT; 375 iap_remotebtn |= BUTTON_RC_RIGHT;
376 } 376 }
377 if(serbuf[5] & 32) /* frwd */ 377 if(serbuf[5] & 32) /* frwd */
378 { 378 {
379 iap_remotebtn |= BUTTON_RC_LEFT; 379 iap_remotebtn |= BUTTON_RC_LEFT;
380 } 380 }
381 } 381 }
382 } 382 }
383 /* Handle Mode 3 */ 383 /* Handle Mode 3 */
384 else if (serbuf[1] == 0x03) 384 else if (serbuf[1] == 0x03)
385 { 385 {
386 switch(serbuf[2]) 386 switch(serbuf[2])
387 { 387 {
388 /* some kind of status packet? */ 388 /* some kind of status packet? */
389 case 0x01: 389 case 0x01:
390 { 390 {
391 unsigned char data[] = {0x03, 0x02, 0x00, 0x00, 0x00, 0x00}; 391 unsigned char data[] = {0x03, 0x02, 0x00, 0x00, 0x00, 0x00};
392 iap_send_pkt(data, sizeof(data)); 392 iap_send_pkt(data, sizeof(data));
393 break; 393 break;
394 } 394 }
395 } 395 }
396 } 396 }
397 /* Handle Mode 4 */ 397 /* Handle Mode 4 */
398 else if (serbuf[1] == 0x04) 398 else if (serbuf[1] == 0x04)
399 { 399 {
400 switch (((unsigned long)serbuf[2] << 8) | serbuf[3]) 400 switch (((unsigned long)serbuf[2] << 8) | serbuf[3])
401 { 401 {
402 /* Get data updated??? flag */ 402 /* Get data updated??? flag */
403 case 0x0009: 403 case 0x0009:
404 { 404 {
405 unsigned char data[] = {0x04, 0x00, 0x0A, 0x00}; 405 unsigned char data[] = {0x04, 0x00, 0x0A, 0x00};
406 data[3] = iap_updateflag ? 0 : 1; 406 data[3] = iap_updateflag ? 0 : 1;
407 iap_send_pkt(data, sizeof(data)); 407 iap_send_pkt(data, sizeof(data));
408 break; 408 break;
409 } 409 }
410 /* Set data updated??? flag */ 410 /* Set data updated??? flag */
411 case 0x000B: 411 case 0x000B:
412 { 412 {
413 iap_updateflag = serbuf[4] ? 0 : 1; 413 iap_updateflag = serbuf[4] ? 0 : 1;
414 /* respond with cmd ok packet */ 414 /* respond with cmd ok packet */
415 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x0B}; 415 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x0B};
416 iap_send_pkt(data, sizeof(data)); 416 iap_send_pkt(data, sizeof(data));
417 break; 417 break;
418 } 418 }
419 /* Get iPod size? */ 419 /* Get iPod size? */
420 case 0x0012: 420 case 0x0012:
421 { 421 {
422 unsigned char data[] = {0x04, 0x00, 0x13, 0x01, 0x0B}; 422 unsigned char data[] = {0x04, 0x00, 0x13, 0x01, 0x0B};
423 iap_send_pkt(data, sizeof(data)); 423 iap_send_pkt(data, sizeof(data));
424 break; 424 break;
425 } 425 }
426 /* Get count of given types */ 426 /* Get count of given types */
427 case 0x0018: 427 case 0x0018:
428 { 428 {
429 unsigned char data[] = {0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00}; 429 unsigned char data[] = {0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00};
430 unsigned long num = 0; 430 unsigned long num = 0;
431 switch(serbuf[4]) /* type number */ 431 switch(serbuf[4]) /* type number */
432 { 432 {
433 case 0x01: /* total number of playlists */ 433 case 0x01: /* total number of playlists */
434 num = 1; 434 num = 1;
435 break; 435 break;
436 case 0x05: /* total number of songs */ 436 case 0x05: /* total number of songs */
437 num = 1; 437 num = 1;
438 } 438 }
439 data[3] = num >> 24; 439 data[3] = num >> 24;
440 data[4] = num >> 16; 440 data[4] = num >> 16;
441 data[5] = num >> 8; 441 data[5] = num >> 8;
442 data[6] = num; 442 data[6] = num;
443 iap_send_pkt(data, sizeof(data)); 443 iap_send_pkt(data, sizeof(data));
444 break; 444 break;
445 } 445 }
446 /* Get time and status */ 446 /* Get time and status */
447 case 0x001C: 447 case 0x001C:
448 { 448 {
449 unsigned char data[] = {0x04, 0x00, 0x1D, 0x00, 0x00, 0x00, 449 unsigned char data[] = {0x04, 0x00, 0x1D, 0x00, 0x00, 0x00,
450 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 450 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
451 struct mp3entry *id3 = audio_current_track(); 451 struct mp3entry *id3 = audio_current_track();
452 unsigned long time_total = id3->length; 452 unsigned long time_total = id3->length;
453 unsigned long time_elapsed = id3->elapsed; 453 unsigned long time_elapsed = id3->elapsed;
454 int status = audio_status(); 454 int status = audio_status();
455 data[3] = time_total >> 24; 455 data[3] = time_total >> 24;
456 data[4] = time_total >> 16; 456 data[4] = time_total >> 16;
457 data[5] = time_total >> 8; 457 data[5] = time_total >> 8;
458 data[6] = time_total; 458 data[6] = time_total;
459 data[7] = time_elapsed >> 24; 459 data[7] = time_elapsed >> 24;
460 data[8] = time_elapsed >> 16; 460 data[8] = time_elapsed >> 16;
461 data[9] = time_elapsed >> 8; 461 data[9] = time_elapsed >> 8;
462 data[10] = time_elapsed; 462 data[10] = time_elapsed;
463 if (status == AUDIO_STATUS_PLAY) 463 if (status == AUDIO_STATUS_PLAY)
464 data[11] = 0x01; /* play */ 464 data[11] = 0x01; /* play */
465 else if (status & AUDIO_STATUS_PAUSE) 465 else if (status & AUDIO_STATUS_PAUSE)
466 data[11] = 0x02; /* pause */ 466 data[11] = 0x02; /* pause */
467 iap_send_pkt(data, sizeof(data)); 467 iap_send_pkt(data, sizeof(data));
468 break; 468 break;
469 } 469 }
470 /* Get current pos in playlist */ 470 /* Get current pos in playlist */
471 case 0x001E: 471 case 0x001E:
472 { 472 {
473 unsigned char data[] = {0x04, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00}; 473 unsigned char data[] = {0x04, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00};
474 long playlist_pos = playlist_next(0); 474 long playlist_pos = playlist_next(0);
475 playlist_pos -= playlist_get_first_index(NULL); 475 playlist_pos -= playlist_get_first_index(NULL);
476 if(playlist_pos < 0) 476 if(playlist_pos < 0)
477 playlist_pos += playlist_amount(); 477 playlist_pos += playlist_amount();
478 data[3] = playlist_pos >> 24; 478 data[3] = playlist_pos >> 24;
479 data[4] = playlist_pos >> 16; 479 data[4] = playlist_pos >> 16;
480 data[5] = playlist_pos >> 8; 480 data[5] = playlist_pos >> 8;
481 data[6] = playlist_pos; 481 data[6] = playlist_pos;
482 iap_send_pkt(data, sizeof(data)); 482 iap_send_pkt(data, sizeof(data));
483 break; 483 break;
484 } 484 }
485 /* Get title of a song number */ 485 /* Get title of a song number */
486 case 0x0020: 486 case 0x0020:
487 /* Get artist of a song number */ 487 /* Get artist of a song number */
488 case 0x0022: 488 case 0x0022:
489 /* Get album of a song number */ 489 /* Get album of a song number */
490 case 0x0024: 490 case 0x0024:
491 { 491 {
492 unsigned char data[70] = {0x04, 0x00, 0xFF}; 492 unsigned char data[70] = {0x04, 0x00, 0xFF};
493 struct mp3entry id3; 493 struct mp3entry id3;
494 int fd; 494 int fd;
495 long tracknum = (signed long)serbuf[4] << 24 | 495 long tracknum = (signed long)serbuf[4] << 24 |
496 (signed long)serbuf[5] << 16 | 496 (signed long)serbuf[5] << 16 |
497 (signed long)serbuf[6] << 8 | serbuf[7]; 497 (signed long)serbuf[6] << 8 | serbuf[7];
498 data[2] = serbuf[3] + 1; 498 data[2] = serbuf[3] + 1;
499 memcpy(&id3, audio_current_track(), sizeof(id3)); 499 memcpy(&id3, audio_current_track(), sizeof(id3));
500 tracknum += playlist_get_first_index(NULL); 500 tracknum += playlist_get_first_index(NULL);
501 if(tracknum >= playlist_amount()) 501 if(tracknum >= playlist_amount())
502 tracknum -= playlist_amount(); 502 tracknum -= playlist_amount();
503 503
504 /* If the tracknumber is not the current one, 504 /* If the tracknumber is not the current one,
505 read id3 from disk */ 505 read id3 from disk */
506 if(playlist_next(0) != tracknum) 506 if(playlist_next(0) != tracknum)
507 { 507 {
508 struct playlist_track_info info; 508 struct playlist_track_info info;
509 playlist_get_track_info(NULL, tracknum, &info); 509 playlist_get_track_info(NULL, tracknum, &info);
510 fd = open(info.filename, O_RDONLY); 510 fd = open(info.filename, O_RDONLY);
511 memset(&id3, 0, sizeof(struct mp3entry)); 511 memset(&id3, 0, sizeof(struct mp3entry));
512 get_metadata(&id3, fd, info.filename); 512 get_metadata(&id3, fd, info.filename);
513 close(fd); 513 close(fd);
514 } 514 }
515 515
516 /* Return the requested track data */ 516 /* Return the requested track data */
517 switch(serbuf[3]) 517 switch(serbuf[3])
518 { 518 {
519 case 0x20: 519 case 0x20:
520 strncpy((char *)&data[3], id3.title, 64); 520 strncpy((char *)&data[3], id3.title, 64);
521 iap_send_pkt(data, 4+strlen(id3.title)); 521 iap_send_pkt(data, 4+strlen(id3.title));
522 break; 522 break;
523 case 0x22: 523 case 0x22:
524 strncpy((char *)&data[3], id3.artist, 64); 524 strncpy((char *)&data[3], id3.artist, 64);
525 iap_send_pkt(data, 4+strlen(id3.artist)); 525 iap_send_pkt(data, 4+strlen(id3.artist));
526 break; 526 break;
527 case 0x24: 527 case 0x24:
528 strncpy((char *)&data[3], id3.album, 64); 528 strncpy((char *)&data[3], id3.album, 64);
529 iap_send_pkt(data, 4+strlen(id3.album)); 529 iap_send_pkt(data, 4+strlen(id3.album));
530 break; 530 break;
531 } 531 }
532 break; 532 break;
533 } 533 }
534 /* Set polling mode */ 534 /* Set polling mode */
535 case 0x0026: 535 case 0x0026:
536 { 536 {
537 iap_pollspeed = serbuf[4] ? 1 : 0; 537 iap_pollspeed = serbuf[4] ? 1 : 0;
538 /*responsed with cmd ok packet */ 538 /*responsed with cmd ok packet */
539 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x26}; 539 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x26};
540 iap_send_pkt(data, sizeof(data)); 540 iap_send_pkt(data, sizeof(data));
541 break; 541 break;
542 } 542 }
543 /* AiR playback control */ 543 /* AiR playback control */
544 case 0x0029: 544 case 0x0029:
545 { 545 {
546 /* respond with cmd ok packet */ 546 /* respond with cmd ok packet */
547 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x29}; 547 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x29};
548 iap_send_pkt(data, sizeof(data)); 548 iap_send_pkt(data, sizeof(data));
549 switch(serbuf[4]) 549 switch(serbuf[4])
550 { 550 {
551 case 0x01: /* play/pause */ 551 case 0x01: /* play/pause */
552 iap_remotebtn = BUTTON_RC_PLAY; 552 iap_remotebtn = BUTTON_RC_PLAY;
553 iap_repeatbtn = 2; 553 iap_repeatbtn = 2;
554 iap_remotetick = false; 554 iap_remotetick = false;
555 iap_changedctr = 1; 555 iap_changedctr = 1;
556 break; 556 break;
557 case 0x02: /* stop */ 557 case 0x02: /* stop */
558 iap_remotebtn = BUTTON_RC_PLAY|BUTTON_REPEAT; 558 iap_remotebtn = BUTTON_RC_PLAY|BUTTON_REPEAT;
559 iap_repeatbtn = 2; 559 iap_repeatbtn = 2;
560 iap_remotetick = false; 560 iap_remotetick = false;
561 iap_changedctr = 1; 561 iap_changedctr = 1;
562 break; 562 break;
563 case 0x03: /* skip++ */ 563 case 0x03: /* skip++ */
564 iap_remotebtn = BUTTON_RC_RIGHT; 564 iap_remotebtn = BUTTON_RC_RIGHT;
565 iap_repeatbtn = 2; 565 iap_repeatbtn = 2;
566 iap_remotetick = false; 566 iap_remotetick = false;
567 break; 567 break;
568 case 0x04: /* skip-- */ 568 case 0x04: /* skip-- */
569 iap_remotebtn = BUTTON_RC_LEFT; 569 iap_remotebtn = BUTTON_RC_LEFT;
570 iap_repeatbtn = 2; 570 iap_repeatbtn = 2;
571 iap_remotetick = false; 571 iap_remotetick = false;
572 break; 572 break;
573 case 0x05: /* ffwd */ 573 case 0x05: /* ffwd */
574 iap_remotebtn = BUTTON_RC_RIGHT; 574 iap_remotebtn = BUTTON_RC_RIGHT;
575 iap_remotetick = false; 575 iap_remotetick = false;
576 if(iap_pollspeed) iap_pollspeed = 5; 576 if(iap_pollspeed) iap_pollspeed = 5;
577 break; 577 break;
578 case 0x06: /* frwd */ 578 case 0x06: /* frwd */
579 iap_remotebtn = BUTTON_RC_LEFT; 579 iap_remotebtn = BUTTON_RC_LEFT;
580 iap_remotetick = false; 580 iap_remotetick = false;
581 if(iap_pollspeed) iap_pollspeed = 5; 581 if(iap_pollspeed) iap_pollspeed = 5;
582 break; 582 break;
583 case 0x07: /* end ffwd/frwd */ 583 case 0x07: /* end ffwd/frwd */
584 iap_remotebtn = BUTTON_NONE; 584 iap_remotebtn = BUTTON_NONE;
585 iap_remotetick = false; 585 iap_remotetick = false;
586 if(iap_pollspeed) iap_pollspeed = 1; 586 if(iap_pollspeed) iap_pollspeed = 1;
587 break; 587 break;
588 } 588 }
589 break; 589 break;
590 } 590 }
591 /* Get shuffle mode */ 591 /* Get shuffle mode */
592 case 0x002C: 592 case 0x002C:
593 { 593 {
594 unsigned char data[] = {0x04, 0x00, 0x2D, 0x00}; 594 unsigned char data[] = {0x04, 0x00, 0x2D, 0x00};
595 data[3] = global_settings.playlist_shuffle ? 1 : 0; 595 data[3] = global_settings.playlist_shuffle ? 1 : 0;
596 iap_send_pkt(data, sizeof(data)); 596 iap_send_pkt(data, sizeof(data));
597 break; 597 break;
598 } 598 }
599 /* Set shuffle mode */ 599 /* Set shuffle mode */
600 case 0x002E: 600 case 0x002E:
601 { 601 {
602 if(serbuf[4] && !global_settings.playlist_shuffle) 602 if(serbuf[4] && !global_settings.playlist_shuffle)
603 { 603 {
604 global_settings.playlist_shuffle = 1; 604 global_settings.playlist_shuffle = 1;
605 settings_save(); 605 settings_save();
606 settings_apply(false); 606 settings_apply(false);
607 if (audio_status() & AUDIO_STATUS_PLAY) 607 if (audio_status() & AUDIO_STATUS_PLAY)
608 playlist_randomise(NULL, current_tick, true); 608 playlist_randomise(NULL, current_tick, true);
609 } 609 }
610 else if(!serbuf[4] && global_settings.playlist_shuffle) 610 else if(!serbuf[4] && global_settings.playlist_shuffle)
611 { 611 {
612 global_settings.playlist_shuffle = 0; 612 global_settings.playlist_shuffle = 0;
613 settings_save(); 613 settings_save();
614 settings_apply(false); 614 settings_apply(false);
615 if (audio_status() & AUDIO_STATUS_PLAY) 615 if (audio_status() & AUDIO_STATUS_PLAY)
616 playlist_sort(NULL, true); 616 playlist_sort(NULL, true);
617 } 617 }
618 618
619 619
620 /* respond with cmd ok packet */ 620 /* respond with cmd ok packet */
621 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x2E}; 621 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x2E};
622 iap_send_pkt(data, sizeof(data)); 622 iap_send_pkt(data, sizeof(data));
623 break; 623 break;
624 } 624 }
625 /* Get repeat mode */ 625 /* Get repeat mode */
626 case 0x002F: 626 case 0x002F:
627 { 627 {
628 unsigned char data[] = {0x04, 0x00, 0x30, 0x00}; 628 unsigned char data[] = {0x04, 0x00, 0x30, 0x00};
629 if(global_settings.repeat_mode == REPEAT_OFF) 629 if(global_settings.repeat_mode == REPEAT_OFF)
630 data[3] = 0; 630 data[3] = 0;
631 else if(global_settings.repeat_mode == REPEAT_ONE) 631 else if(global_settings.repeat_mode == REPEAT_ONE)
632 data[3] = 1; 632 data[3] = 1;
633 else 633 else
634 data[3] = 2; 634 data[3] = 2;
635 iap_send_pkt(data, sizeof(data)); 635 iap_send_pkt(data, sizeof(data));
636 break; 636 break;
637 } 637 }
638 /* Set repeat mode */ 638 /* Set repeat mode */
639 case 0x0031: 639 case 0x0031:
640 { 640 {
641 int oldmode = global_settings.repeat_mode; 641 int oldmode = global_settings.repeat_mode;
642 if (serbuf[4] == 0) 642 if (serbuf[4] == 0)
643 global_settings.repeat_mode = REPEAT_OFF; 643 global_settings.repeat_mode = REPEAT_OFF;
644 else if (serbuf[4] == 1) 644 else if (serbuf[4] == 1)
645 global_settings.repeat_mode = REPEAT_ONE; 645 global_settings.repeat_mode = REPEAT_ONE;
646 else if (serbuf[4] == 2) 646 else if (serbuf[4] == 2)
647 global_settings.repeat_mode = REPEAT_ALL; 647 global_settings.repeat_mode = REPEAT_ALL;
648 648
649 if (oldmode != global_settings.repeat_mode) 649 if (oldmode != global_settings.repeat_mode)
650 { 650 {
651 settings_save(); 651 settings_save();
652 settings_apply(false); 652 settings_apply(false);
653 if (audio_status() & AUDIO_STATUS_PLAY) 653 if (audio_status() & AUDIO_STATUS_PLAY)
654 audio_flush_and_reload_tracks(); 654 audio_flush_and_reload_tracks();
655 } 655 }
656 656
657 /* respond with cmd ok packet */ 657 /* respond with cmd ok packet */
658 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x31}; 658 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x31};
659 iap_send_pkt(data, sizeof(data)); 659 iap_send_pkt(data, sizeof(data));
660 break; 660 break;
661 } 661 }
662 /* Get Max Screen Size for Picture Upload??? */ 662 /* Get Max Screen Size for Picture Upload??? */
663 case 0x0033: 663 case 0x0033:
664 { 664 {
665 unsigned char data[] = {0x04, 0x00, 0x34, 0x01, 0x36, 0x00, 0xA8, 0x01}; 665 unsigned char data[] = {0x04, 0x00, 0x34, 0x01, 0x36, 0x00, 0xA8, 0x01};
666 iap_send_pkt(data, sizeof(data)); 666 iap_send_pkt(data, sizeof(data));
667 break; 667 break;
668 } 668 }
669 /* Get number songs in current playlist */ 669 /* Get number songs in current playlist */
670 case 0x0035: 670 case 0x0035:
671 { 671 {
672 unsigned char data[] = {0x04, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00}; 672 unsigned char data[] = {0x04, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00};
673 unsigned long playlist_amt = playlist_amount(); 673 unsigned long playlist_amt = playlist_amount();
674 data[3] = playlist_amt >> 24; 674 data[3] = playlist_amt >> 24;
675 data[4] = playlist_amt >> 16; 675 data[4] = playlist_amt >> 16;
676 data[5] = playlist_amt >> 8; 676 data[5] = playlist_amt >> 8;
677 data[6] = playlist_amt; 677 data[6] = playlist_amt;
678 iap_send_pkt(data, sizeof(data)); 678 iap_send_pkt(data, sizeof(data));
679 break; 679 break;
680 } 680 }
681 /* Jump to track number in current playlist */ 681 /* Jump to track number in current playlist */
682 case 0x0037: 682 case 0x0037:
683 { 683 {
684 long tracknum = (signed long)serbuf[4] << 24 | 684 long tracknum = (signed long)serbuf[4] << 24 |
685 (signed long)serbuf[5] << 16 | 685 (signed long)serbuf[5] << 16 |
686 (signed long)serbuf[6] << 8 | serbuf[7]; 686 (signed long)serbuf[6] << 8 | serbuf[7];
687 if (!wps_state.paused) 687 if (!wps_state.paused)
688 audio_pause(); 688 audio_pause();
689 audio_skip(tracknum - playlist_next(0)); 689 audio_skip(tracknum - playlist_next(0));
690 if (!wps_state.paused) 690 if (!wps_state.paused)
691 audio_resume(); 691 audio_resume();
692 692
693 /* respond with cmd ok packet */ 693 /* respond with cmd ok packet */
694 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x00}; 694 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x00};
695 data[4] = serbuf[2]; 695 data[4] = serbuf[2];
696 data[5] = serbuf[3]; 696 data[5] = serbuf[3];
697 iap_send_pkt(data, sizeof(data)); 697 iap_send_pkt(data, sizeof(data));
698 break; 698 break;
699 } 699 }
700 default: 700 default:
701 { 701 {
702 /* default response is with cmd ok packet */ 702 /* default response is with cmd ok packet */
703 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x00}; 703 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x00};
704 data[4] = serbuf[2]; 704 data[4] = serbuf[2];
705 data[5] = serbuf[3]; 705 data[5] = serbuf[3];
706 iap_send_pkt(data, sizeof(data)); 706 iap_send_pkt(data, sizeof(data));
707 break; 707 break;
708 } 708 }
709 } 709 }
710 } 710 }
711 serbuf[0] = 0; 711 serbuf[0] = 0;
712} 712}
@@ -716,15 +716,15 @@ int remote_control_rx(void)
716 int btn = iap_remotebtn; 716 int btn = iap_remotebtn;
717 if(iap_repeatbtn) 717 if(iap_repeatbtn)
718 { 718 {
719 iap_repeatbtn--; 719 iap_repeatbtn--;
720 if(!iap_repeatbtn) 720 if(!iap_repeatbtn)
721 { 721 {
722 iap_remotebtn = BUTTON_NONE; 722 iap_remotebtn = BUTTON_NONE;
723 iap_remotetick = true; 723 iap_remotetick = true;
724 } 724 }
725 } 725 }
726 else 726 else
727 iap_remotetick = true; 727 iap_remotetick = true;
728 728
729 return btn; 729 return btn;
730} 730}
diff --git a/apps/main.c b/apps/main.c
index c62ee080b3..d473e66731 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -121,7 +121,7 @@ const char appsversion[]=APPSVERSION;
121 121
122static void init(void); 122static void init(void);
123 123
124void fourhertz_tick_task(void) 124static void fourhertz_tick_task(void)
125{ 125{
126 static long last_fire = 0; 126 static long last_fire = 0;
127 if (TIME_AFTER(current_tick, last_fire+HZ/4)) 127 if (TIME_AFTER(current_tick, last_fire+HZ/4))
diff --git a/apps/recorder/resize.c b/apps/recorder/resize.c
index 658cdd85ae..5c9f7a6dd6 100644
--- a/apps/recorder/resize.c
+++ b/apps/recorder/resize.c
@@ -500,7 +500,8 @@ static inline bool scale_v_linear(struct rowset *rset,
500} 500}
501#endif /* HAVE_UPSCALER */ 501#endif /* HAVE_UPSCALER */
502 502
503void output_row_native(uint32_t row, void * row_in, struct scaler_context *ctx) 503static void output_row_native(uint32_t row, void * row_in,
504 struct scaler_context *ctx)
504{ 505{
505 int col; 506 int col;
506 int fb_width = BM_WIDTH(ctx->bm->width,FORMAT_NATIVE,0); 507 int fb_width = BM_WIDTH(ctx->bm->width,FORMAT_NATIVE,0);
diff --git a/firmware/target/arm/ascodec-pp.c b/firmware/target/arm/ascodec-pp.c
index 5d49c8f472..49a69d1a11 100644
--- a/firmware/target/arm/ascodec-pp.c
+++ b/firmware/target/arm/ascodec-pp.c
@@ -26,6 +26,7 @@
26 26
27#include "audiohw.h" 27#include "audiohw.h"
28#include "i2s.h" 28#include "i2s.h"
29#include "ascodec-target.h"
29 30
30/* 31/*
31 * Initialise the PP I2C and I2S. 32 * Initialise the PP I2C and I2S.