00001 
00007 
#include "vs10xx.h"
00008 
#include "lcd.h"
00009 
#include "filesys.h"
00010 
#include "storage.h"
00011 
#include "ui.h"
00012 
00013 
00014 
00015 
00017 unsigned int Mp3ReadRegister (
unsigned char addressbyte){
00018   
unsigned int resultvalue = 0;
00019 
00020   
Mp3SelectControl();
00021   
SPIPutCharWithoutWaiting(
VS_READ_COMMAND);
00022   
SPIPutChar((addressbyte));
00023   
SPIPutChar(0xff);
00024   
SPIWait();
00025   resultvalue = (
SPI_RESULT_BYTE) << 8;
00026   
SPIPutCharWithoutWaiting(0xff);
00027   
SPIWait();
00028   resultvalue |= (
SPI_RESULT_BYTE);
00029   
Mp3DeselectControl();
00030   
return resultvalue;
00031 }
00032   
00033 
00035 void Mp3SoftReset(){
00036 
00037   
00038   
Mp3WriteRegister (
SPI_MODE, 0x08, 0x04); 
00039 
00040   
Delay(1); 
00041   
while (!
MP3_DREQ) 
00042     ;
00043   
00044   
00045 
#ifdef VS1003
00046 
  Mp3WriteRegister(
SPI_CLOCKF, 0xa6, 0x96);
00047 
#else
00048 
  Mp3WriteRegister(
SPI_CLOCKF, 156, 204);
00049 
#endif
00050 
  
00051   
Delay(1); 
00052 
00053  
00054   
00055   
Mp3SelectData();
00056   
SPIPutCharWithoutWaiting(0);
00057   
SPIPutChar(0);
00058   
SPIPutChar(0);
00059   
SPIPutChar(0);
00060   
SPIWait();
00061   
Mp3DeselectData();
00062 
00063 }
00064 
00065 
00066 
00067 
00069 void Mp3Reset(){
00070 
00071   
Mp3PutInReset();
00072   
Delay(1);
00073 
00074   
00075   
SPIPutCharWithoutWaiting(0xFF);
00076 
00077   
00078   
Mp3DeselectControl();
00079   
Mp3DeselectData();
00080   
Mp3ReleaseFromReset();
00081   
Mp3SetVolume(0xff,0xff);
00082   
00083   
00084 
#ifdef VS1003
00085 
  Mp3WriteRegister(
SPI_CLOCKF, 0xa6, 0x6c);
00086 
#else
00087 
  Mp3WriteRegister(
SPI_CLOCKF, 156, 204);
00088 
#endif
00089 
  
00090   
00091   
while (!
MP3_DREQ)
00092     ;
00093   
00094   
00095   
Mp3WriteRegister(
SPI_AUDATA, 0, 10); 
00096   
Delay(100);
00097 
00098   
00099   
Mp3SetVolume(0xfe,0xfe);
00100   
Mp3WriteRegister (
SPI_AUDATA, 31, 64); 
00101   
Mp3SetVolume(20,20);
00102   
Mp3SoftReset();
00103   
SPISetFastClock();
00104   
00105 
00106   ConsoleWrite (
"Init: VS10XX\r");
00107 
00108 }
00109 
00110 
00112 void VsSineTest(){
00113 
00114   
00115   
Mp3PutInReset();       
00116   
Delay(100);            
00117 
00118   
00119   
SPIPutCharWithoutWaiting(0xFF);
00120 
00121   
00122   
Mp3DeselectControl();  
00123   
Mp3DeselectData();     
00124   
Mp3ReleaseFromReset(); 
00125   
Delay(100);            
00126 
00127   
GREEN_LED = 
LED_ON;
00128   
RED_LED = 
LED_ON;
00129 
00130   
00131   
00132   
Mp3SelectControl();    
00133   
SPIPutChar(0x02);      
00134   
SPIPutChar(0x00);      
00135   
SPIPutChar(0x08);      
00136   
SPIPutChar(0x20);      
00137   
SPIWait();             
00138   
Mp3DeselectControl();  
00139 
00140   
while (!
MP3_DREQ)      
00141     ;                    
00142 
00143   
00144   
Mp3SelectData();       
00145 
00146   
SPIPutChar(0x53);      
00147   
SPIPutChar(0xef);      
00148   
SPIPutChar(0x6e);      
00149   
SPIPutChar(0x44);      
00150   
SPIPutChar(0x00);      
00151   
SPIPutChar(0x00);
00152   
SPIPutChar(0x00);
00153   
SPIPutChar(0x00);
00154   
SPIWait();
00155   
Mp3DeselectData();
00156   
00157   
RED_LED = 
LED_OFF;
00158   
Delay (500);           
00159   
GREEN_LED = 
LED_OFF;
00160 
00161   
00162   
Mp3SelectData();
00163   
SPIPutChar(0x45);
00164   
SPIPutChar(0x78);
00165   
SPIPutChar(0x69);
00166   
SPIPutChar(0x74);
00167   
SPIPutChar(0x00);
00168   
SPIPutChar(0x00);
00169   
SPIPutChar(0x00);
00170   
SPIPutChar(0x00);
00171   
SPIWait();
00172   
Mp3DeselectData();
00173 
00174   
Delay(500);            
00175 }  
00176 
00178 void SendZerosToVS10xx(){
00179   
Mp3SelectData();
00180   
SPIPutCharWithoutWaiting(0);
00181   
for (
temp.
i=0; 
temp.
i<1048; 
temp.
i++){ 
00182     
while (!
MP3_DREQ)
00183       ;
00184     
SPIPutChar(0);
00185   }
00186   
SPIWait();
00187   
Mp3DeselectData();
00188 }  
00189 
00190 
00191 #define AVIPLAY
00192 
00193 
#ifdef AVIPLAY
00194 
#include "aviplay.c"
00195 
#endif
00196 
00197 
00198 
00202 unsigned char PlayDiskSectors (
unsigned int nSectorsToPlay){
00203   
00205   
unsigned char fallbackCount = 0;
00206 
00207 
00208 
#ifdef AVIPLAY
00209 
  if (!
PlayAvi()) 
return 0; 
00210                             
00211 
#endif
00212 
00213 
00214   
PrepareToReadDiskSector(
sectorAddress.
l);
00215   
while (nSectorsToPlay--){
00216 
00217     
AvailableProcessorTime();
00218 
00219     
ReadDiskSector(
sectorAddress.
l);
00220 
00221     
00222 
00223     
if ((
playingState==
PS_END_OF_SONG)||
00224         (
playingState==
PS_NEXT_SONG)||
00225         (
playingState==
PS_RECORDING)||
00226         (
playingState==
PS_PREVIOUS_SONG)){
00227       
return playingState;
00228     }
00229 
00230 
00231     
00232     
00233 
00234     
if (
playingState==
PS_FALLBACK_N){
00235       
if ((--fallbackCount)==0){
00236         
playingState=
PS_NORMAL;
00237       }
00238     }
00239 
00240     
if (
playingState==
PS_FALLBACK_1){
00241       
00242 
00243       ConsoleWrite(
"(Zeros)");
00244       
SendZerosToVS10xx();
00245       ConsoleWrite(
"->Fallback to normal");
00246       fallbackCount = 24;
00247       
playingState = 
PS_FALLBACK_N;
00248     }
00249 
00250 
00251     
if (
playingState==
PS_CUE){ 
00252       
if (
Mp3ReadRegister(
SPI_HDAT1)==((
int)
'W'<< 8)+
'm'){
00253         ConsoleWrite(
"\rWmCUE->Wait");
00254         
Mp3WriteRegister(
SPI_AICTRL2, 0x12, 0x34);
00255         
playingState = 
PS_CUE_WAIT1003;
00256       }
else{
00257         
playingState = 
PS_CUE_ACTION;
00258       }
00259     }
00260     
00261     
if (
playingState==
PS_CUE_WAIT1003){ 
00262       
if (
Mp3ReadRegister(
SPI_AICTRL2)==0x2345){ 
00263         ConsoleWrite(
"->Action");
00264         
playingState = 
PS_CUE_ACTION;
00265       }
00266     }
00267     
00268     
if (
playingState==
PS_CUE_ACTION){
00269       
if (nSectorsToPlay>128){
00270         
sectorAddress.
l += 128; 
00271         nSectorsToPlay -= 128;
00272         
00273         ConsoleWrite(
"->Fallback(5)");
00274         
playingState = 
PS_FALLBACK_1; 
00275       }
00276     }
00277 
00278     
if (
playingState==
PS_REWIND){ 
00279       
Mp3WriteRegister(
SPI_AICTRL2, 0x12, 0x34);
00280       
playingState = 
PS_REW_WAIT1003;
00281     }
00282 
00283     
if (
playingState==
PS_REW_WAIT1003){ 
00284       
if (1){
00285         
if (1 || (
Mp3ReadRegister(
SPI_AICTRL2)==0x2345)){ 
00286           
sectorAddress.
l -= 128;
00287           nSectorsToPlay += 128;
00288           
playingState = 
PS_FALLBACK_1; 
00289         }
00290       }
00291     }
00292     
00293 
00294     
00295     
00296  
00297   
00298     
sectorAddress.
l++;
00299     
if (nSectorsToPlay){
00300       
00301       
PrepareToReadDiskSector(
sectorAddress.
l);
00302     }
00303 
00304     
Mp3SelectData();
00305 
00306     
dataBufPtr = 
diskSect.
raw.
buf;
00307     
while (
dataBufPtr < 
diskSect.
raw.
buf+512){
00308 
00309       
if (!
MP3_DREQ){
00310         
GREEN_LED = 
LED_ON;
00311         
while (!
MP3_DREQ){
00312           
Mp3DeselectData();
00313           
AvailableProcessorTime();
00314           
Mp3SelectData();
00315         }
00316       }
00317       
GREEN_LED = 
LED_OFF;
00318       
00319       
00320       
SPIPutCharWithoutWaiting(*
dataBufPtr++);
00321       
SPIWait();
00322       
SPIPutChar(*
dataBufPtr++);
00323       
SPIPutChar(*
dataBufPtr++);
00324       
SPIPutChar(*
dataBufPtr++);
00325       
SPIPutChar(*
dataBufPtr++);
00326       
SPIPutChar(*
dataBufPtr++);
00327       
SPIPutChar(*
dataBufPtr++);
00328       
SPIPutChar(*
dataBufPtr++);
00329       
SPIPutChar(*
dataBufPtr++);
00330       
SPIPutChar(*
dataBufPtr++);
00331       
SPIPutChar(*
dataBufPtr++);
00332       
SPIPutChar(*
dataBufPtr++);
00333       
SPIPutChar(*
dataBufPtr++);
00334       
SPIPutChar(*
dataBufPtr++);
00335       
SPIPutChar(*
dataBufPtr++);
00336       
SPIPutChar(*
dataBufPtr++);
00337       
SPIPutChar(*
dataBufPtr++);
00338       
SPIPutChar(*
dataBufPtr++);
00339       
SPIPutChar(*
dataBufPtr++);
00340       
SPIPutChar(*
dataBufPtr++);
00341       
SPIPutChar(*
dataBufPtr++);
00342       
SPIPutChar(*
dataBufPtr++);
00343       
SPIPutChar(*
dataBufPtr++);
00344       
SPIPutChar(*
dataBufPtr++);
00345       
SPIPutChar(*
dataBufPtr++);
00346       
SPIPutChar(*
dataBufPtr++);
00347       
SPIPutChar(*
dataBufPtr++);
00348       
SPIPutChar(*
dataBufPtr++);
00349       
SPIPutChar(*
dataBufPtr++);
00350       
SPIPutChar(*
dataBufPtr++);
00351       
SPIPutChar(*
dataBufPtr++);
00352       
SPIPutChar(*
dataBufPtr++);
00353       
SPIWait();
00354     }
00355 
00356 
00357     
SPIWait();
00358     
Mp3DeselectData();
00359   }
00360 
00361 
00362   
return 0; 
00363 }
00364 
00365