summaryrefslogtreecommitdiff
path: root/firmware/mpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/mpeg.c')
-rw-r--r--firmware/mpeg.c149
1 files changed, 71 insertions, 78 deletions
diff --git a/firmware/mpeg.c b/firmware/mpeg.c
index 754c240a42..18c8e701fd 100644
--- a/firmware/mpeg.c
+++ b/firmware/mpeg.c
@@ -41,6 +41,7 @@
41 41
42extern char* peek_next_track(int type); 42extern char* peek_next_track(int type);
43 43
44#ifndef ARCHOS_RECORDER
44static unsigned int bass_table[] = 45static unsigned int bass_table[] =
45{ 46{
46 0, 47 0,
@@ -80,6 +81,7 @@ static unsigned int treble_table[] =
80 0x58400, /* 14dB */ 81 0x58400, /* 14dB */
81 0x5f800 /* 15dB */ 82 0x5f800 /* 15dB */
82}; 83};
84#endif
83 85
84static unsigned char fliptable[] = 86static unsigned char fliptable[] =
85{ 87{
@@ -159,8 +161,8 @@ static void mas_poll_start(int interval_in_ms)
159 GRA1 = count; 161 GRA1 = count;
160 TCR1 = 0x23; /* Clear at GRA match, sysclock/8 */ 162 TCR1 = 0x23; /* Clear at GRA match, sysclock/8 */
161 163
162 /* Enable interrupt on level 2 */ 164 /* Enable interrupt on level 5 */
163 IPRC = (IPRC & ~0x000f) | 0x0002; 165 IPRC = (IPRC & ~0x000f) | 0x0005;
164 166
165 TSR1 &= ~0x02; 167 TSR1 &= ~0x02;
166 TIER1 = 0xf9; /* Enable GRA match interrupt */ 168 TIER1 = 0xf9; /* Enable GRA match interrupt */
@@ -492,132 +494,123 @@ static void setup_sci0(void)
492 494
493void mpeg_play(char* trackname) 495void mpeg_play(char* trackname)
494{ 496{
495#ifdef ARCHOS_RECORDER
496 DEBUGF("mpeg_play(%s)\n", trackname);
497 return;
498#endif
499
500 queue_post(&mpeg_queue, MPEG_PLAY, trackname); 497 queue_post(&mpeg_queue, MPEG_PLAY, trackname);
501} 498}
502 499
503void mpeg_stop(void) 500void mpeg_stop(void)
504{ 501{
505#ifdef ARCHOS_RECORDER
506 DEBUGF("mpeg_stop()\n");
507 return;
508#endif
509
510 queue_post(&mpeg_queue, MPEG_STOP, NULL); 502 queue_post(&mpeg_queue, MPEG_STOP, NULL);
511} 503}
512 504
513void mpeg_pause(void) 505void mpeg_pause(void)
514{ 506{
515#ifdef ARCHOS_RECORDER
516 return;
517#endif
518
519 queue_post(&mpeg_queue, MPEG_PAUSE, NULL); 507 queue_post(&mpeg_queue, MPEG_PAUSE, NULL);
520} 508}
521 509
522void mpeg_resume(void) 510void mpeg_resume(void)
523{ 511{
524#ifdef ARCHOS_RECORDER
525 return;
526#endif
527
528 queue_post(&mpeg_queue, MPEG_RESUME, NULL); 512 queue_post(&mpeg_queue, MPEG_RESUME, NULL);
529} 513}
530 514
531void mpeg_volume(int percent) 515void mpeg_volume(int percent)
532{ 516{
533#ifdef ARCHOS_RECORDER 517 int volume;
534 return;
535#endif
536 518
537 int volume = 0x38 * percent / 100; 519#ifdef ARCHOS_RECORDER
520 volume = 0x7f00 * percent / 100;
521 mas_codec_writereg(0x10, volume & 0xff00);
522#else
523 volume = 0x38 * percent / 100;
538 dac_volume(volume); 524 dac_volume(volume);
525#endif
539} 526}
540 527
541void mpeg_bass(int percent) 528void mpeg_bass(int percent)
542{ 529{
543#ifdef ARCHOS_RECORDER 530 int bass;
544 return;
545#endif
546 531
547 int bass = 15 * percent / 100; 532#ifdef ARCHOS_RECORDER
533 bass = 0x6000 * percent / 100;
534 mas_codec_writereg(0x14, bass & 0xff00);
535#else
536 bass = 15 * percent / 100;
548 mas_writereg(MAS_REG_KBASS, bass_table[bass]); 537 mas_writereg(MAS_REG_KBASS, bass_table[bass]);
538#endif
549} 539}
550 540
551void mpeg_treble(int percent) 541void mpeg_treble(int percent)
552{ 542{
543 int treble;
544
553#ifdef ARCHOS_RECORDER 545#ifdef ARCHOS_RECORDER
554 return; 546 treble = 0x6000 * percent / 100;
555#endif 547 mas_codec_writereg(0x15, treble & 0xff00);
556 548#else
557 int treble = 15 * percent / 100; 549 treble = 15 * percent / 100;
558 mas_writereg(MAS_REG_KTREBLE, treble_table[treble]); 550 mas_writereg(MAS_REG_KTREBLE, treble_table[treble]);
551#endif
559} 552}
560 553
561void mpeg_init(void) 554void mpeg_init(void)
562{ 555{
563 int rc; 556 int rc;
557 unsigned long val;
564 558
565 setup_sci0(); 559 setup_sci0();
566 i2c_init(); 560 i2c_init();
567 561
568#ifdef ARCHOS_RECORDER 562#ifdef ARCHOS_RECORDER
569 return; 563 /* Reset the MAS */
564 PAIOR |= 0x100;
565 PADR &= ~0x100;
566 sleep(HZ/100);
567 PADR |= 0x100;
568 sleep(HZ/10);
569
570 /* Enable the audio CODEC and the DSP core, max analog voltage range */
571 mas_direct_config_write(MAS_CONTROL, 0x8c00);
572
573 /* Max volume on both ears */
574 val = 0x80000;
575 mas_writemem(MAS_BANK_D0,0x7fc,&val,1);
576 mas_writemem(MAS_BANK_D0,0x7ff,&val,1);
577
578 /* Enable the D/A Converter */
579 mas_codec_writereg(0x0, 0x0001);
580
581 /* DSP scale 100% */
582 rc = mas_codec_writereg(7, 0x4000);
583
584 /* Disable S/PDIF, SDO and SDI */
585 val = 0x2d;
586 mas_writemem(MAS_BANK_D0,0x7f2,&val,1);
587
588 /* Set Demand mode and validate all settings */
589 val = 0x25;
590 mas_writemem(MAS_BANK_D0,0x7f1,&val,1);
591
592 /* Start the Layer2/3 decoder applications */
593 val = 0x0c;
594 mas_writemem(MAS_BANK_D0,0x7f6,&val,1);
570#endif 595#endif
571 596
572#ifdef DEBUG 597#ifdef ARCHOS_RECORDER
573 { 598#else
574 unsigned char buf[32]; 599 mas_writereg(0x3b, 0x20); /* Don't ask why. The data sheet doesn't say */
575 unsigned char str[32]; 600 mas_run(1);
576 int i; 601 mas_writereg(MAS_REG_KPRESCALE, 0xe9400);
577
578 rc = mas_readmem(MAS_BANK_D1,0xff6,(unsigned long*)buf,2);
579 if (rc)
580 panicf("Error - mas_readmem(0xff6) returned %d\n", rc);
581
582 i = buf[0] | buf[1] << 8;
583 DEBUGF("MAS version: %x\n", i);
584 i = buf[4] | buf[5] << 8;
585 DEBUGF("MAS revision: %x\n", i);
586
587 rc = mas_readmem(MAS_BANK_D1,0xff9,(unsigned long*)buf,7);
588 if (rc)
589 panicf("Error - mas_readmem(0xff9) returned %d\n", rc);
590
591 for (i = 0;i < 7;i++) {
592 str[i*2+1] = buf[i*4];
593 str[i*2] = buf[i*4+1];
594 }
595 str[i*2] = 0;
596 DEBUGF("Description: %s\n", str);
597 }
598#endif
599 602
600 rc = mas_writereg(0x3b, 0x20); 603 dac_config(0x04); /* DAC on, all else off */
601 if (rc < 0) 604#endif
602 panicf("Error - mas_writereg(0x3b) returned %d\n", rc); 605
606 mpeg_bass(DEFAULT_BASS_SETTING);
607 mpeg_treble(DEFAULT_TREBLE_SETTING);
608 mpeg_volume(DEFAULT_VOLUME_SETTING);
603 609
604 rc = mas_run(1); 610 mp3buflen = mp3end - mp3buf;
605 if (rc < 0)
606 panicf("Error - mas_run(1) returned %d\n", rc);
607 611
608 queue_init(&mpeg_queue); 612 queue_init(&mpeg_queue);
609 create_thread(mpeg_thread, mpeg_stack, sizeof(mpeg_stack)); 613 create_thread(mpeg_thread, mpeg_stack, sizeof(mpeg_stack));
610 mas_poll_start(2);
611
612 mas_writereg(MAS_REG_KPRESCALE, 0xe9400);
613
614 mp3buflen = mp3end - mp3buf;
615 614
616 if(dac_config(0x04) < 0) { 615 mas_poll_start(2);
617 DEBUGF("dac_config() failed\n");
618 }
619
620 mpeg_volume(DEFAULT_VOLUME_SETTING);
621 mpeg_bass(DEFAULT_BASS_SETTING);
622 mpeg_treble(DEFAULT_TREBLE_SETTING);
623} 616}