SwapCode1.c
上传用户:hualongjx
上传日期:2022-01-17
资源大小:4k
文件大小:14k
- #include <option.h>
- #include <SMI51.h>
- #include <struct.h>
- #include <local.h>
- #include <local1.h>
- #include <protyp.h>
- #include <fusb.h>
- #include <UI.h>
- #include <fat.H>
- #include <sd.h>
- #include <sdcmd.h>
- #include <isp_def.h>
- #if 1//S_SupportFM //yu5
- void FMdelay()
- {
- delayclk(0x02);
- }
- //code BYTE BATMAPISP[]={0,0,1,2,2,3,3,3};
- code BYTE BATMAPISP[]={0,0,0,0,0,1,2,3};
- void GUI_FM_ShowChanISP()
- {
- for (gxTemp0=0;gxTemp0<16;gxTemp0++)
- XB_FM_TempString[gxTemp0]=' ';
- XB_FM_TempString[0]='F';
- XB_FM_TempString[1]='M';
- //JM=>PLL=(XW_FM_Freq*8.192-225)/100;
- //gxibTempIntegerByte.INTEGER=(XW_FM_Freq&0x01)+(XW_FM_Freq/2);
- gxibTempIntegerByte.INTEGER=(XW_FM_Freq/2); //(GM8)
- gxibTempIntegerByte.INTEGER=hex2dec(gxibTempIntegerByte.INTEGER);
- gxTemp0=2;
- XB_FM_TempString[2]=((gxibTempIntegerByte.SBYTE.B1>>4) & 0x0f) | '0';
- if (XB_FM_TempString[2] != '0') gxTemp0=3;
- XB_FM_TempString[gxTemp0++]=((gxibTempIntegerByte.SBYTE.B1>>0) & 0x0f) | '0';
- XB_FM_TempString[gxTemp0++]=((gxibTempIntegerByte.SBYTE.B0>>4) & 0x0f) | '0';
- XB_FM_TempString[gxTemp0++]='.';
- XB_FM_TempString[gxTemp0++]=((gxibTempIntegerByte.SBYTE.B0>>0) & 0x0f) | '0';
-
- if(XW_FM_Freq&0x01)
- XB_FM_TempString[gxTemp0++]='5';
- else
- XB_FM_TempString[gxTemp0++]='0';
- XB_FM_TempString[9]='C';
- XB_FM_TempString[10]='H';
- gxibTempIntegerByte.SBYTE.B0=hex2dec(XB_FM_MEM);
- XB_FM_TempString[11]=((gxibTempIntegerByte.SBYTE.B0>>4) & 0x0f) | '0';
- XB_FM_TempString[12]=((gxibTempIntegerByte.SBYTE.B0>>0) & 0x0f) | '0';
- XB_FM_TempString[13]=0;
- LCM_xp=0;
- LCM_yp=1;
- GUI_ShowString((XBYTE*)(XB_FM_TempString) ,0);
- if(!(PB_HOST[0x04]&SET_BIT1)) //(GM7)
- {
- uiUpdateMainDisplay(bit0);
- lcmSetPageAddress(0,80); //(G) for FM mode
- MOVERAM_LCM(&XB_BUF0xE000[BATMAPISP[PB_HOST[ADC3BIT_CTRL]]*128],18);
- if(PB_HOST[ADC3BIT_CTRL]<=3)
- {
- M_SetLowBattery;
- GUI_ShowMenu1(C_LowBatteryPictureOffset);
- }
- }
- }
- void I2C_Stop_ISP()
- {
- PB_HOST[FMI2C]=0xF8;
- PB_HOST[I2CSEL]=0x7F;//Set input mode
- FMdelay();
- PB_HOST[FMI2C]=0xFA;
- FMdelay();
- PB_HOST[FMI2C]=0xFB;
- }
- #define k gxTempR
- #define i gxTemp0
- #define temp gxTemp1
- #define tempreg gxTemp2
- void FM_I2C_ADDR_ISP(BYTE addr)
- {
- temp=addr;
-
- PB_HOST[FMI2C]=0xFB;//Start condition,CLK=0
- FMdelay();
- tempreg=0xFA;
- PB_HOST[FMI2C]=0xFA;//Start condition,CLK=0
-
- FMdelay();
-
- for (i=0;i<8;i++)
- {
- tempreg&=0xFD;//Clr clk
- PB_HOST[FMI2C]=tempreg;
- if (temp&0x80)
- {
- tempreg|=0x01;
- }
- else
- {
- tempreg&=0xFE;
- }
- PB_HOST[FMI2C]=tempreg;
- tempreg|=0x02;//Set clk
- PB_HOST[FMI2C]=tempreg;
- temp=temp<<1;
- }
-
- FMdelay();
-
- tempreg&=0xFD;//clr clk
- PB_HOST[FMI2C]=tempreg;
- PB_HOST[I2CSEL]=0x7E;//Set input mode
- FMdelay();
- tempreg|=0x02;//Set clk
- PB_HOST[FMI2C]=tempreg;
- FMdelay();
-
- }
- void FM_I2C_IN_ISP(BYTE addr)
- {
- FM_I2C_ADDR_ISP(addr);
- for (k=0;k<5;k++)
- {
- temp=XB_FM_Data[k];
- for (i=0;i<8;i++)
- {
- tempreg&=0xFD;
- PB_HOST[FMI2C]=tempreg;
- PB_HOST[I2CSEL]=0x7F;
- if (temp&0x80)
- {
- tempreg|=0x01;
- }
- else
- {
- tempreg&=0xFE;
- }
- PB_HOST[FMI2C]=tempreg;
- tempreg|=0x02;//Set clk
- PB_HOST[FMI2C]=tempreg;
- temp=temp<<1;
- }
- FMdelay();
- tempreg&=0xFD;//clr clk
- PB_HOST[FMI2C]=tempreg;
- PB_HOST[I2CSEL]=0x7E;//Set input mode
- FMdelay();
- tempreg|=0x02;//Set clk
- PB_HOST[FMI2C]=tempreg;
- FMdelay();
- }
- I2C_Stop_ISP();
- }
- void FM_I2C_OUT_ISP(BYTE addr)
- {
- FM_I2C_ADDR_ISP(addr);
- for (k=0;k<5;k++)
- {
- temp=0;
- for (i=0;i<8;i++)
- {
- temp=(temp<<1);
- tempreg&=0xFD;//Clr clk
- PB_HOST[FMI2C]=tempreg;
- PB_HOST[I2CSEL]=0x7E;
- FMdelay();
- tempreg|=0x02;//set clk
- PB_HOST[FMI2C]=tempreg;
- FMdelay();
- if (PB_HOST[FMI2C]&0x01)
- {
- temp|=0x01;
- }
- else
- {
- temp&=0xFE;
- }
- }
- XB_FM_Data[k]=temp;
- tempreg&=0xFD;//clr clk
- PB_HOST[FMI2C]=tempreg;
- FMdelay();
- tempreg&=0xFE;
- PB_HOST[I2CSEL]=0x7F;
- PB_HOST[FMI2C]=tempreg;
- tempreg|=0x02;//Set clk
- PB_HOST[FMI2C]=tempreg;
- FMdelay();
- }
- I2C_Stop_ISP();
- }
- #undef k
- #undef i
- #undef temp
- #undef tempreg
- void SetFMDataISP()
- {
- //JM=>XB_FM_Data[1]=XW_FM_Freq&0xFF;
- //JM=>XB_FM_Data[0]=XB_FM_Data[0]|((XW_FM_Freq>>8)&0x3F);
- XB_FM_Data[0]=gxlbTempLongByte.SBYTE.B1;
- XB_FM_Data[1]=gxlbTempLongByte.SBYTE.B0;
- XB_FM_Data[2]=(XB_FM_Data[2]&0xA0)|0x30;
- XB_FM_Data[3]=0x10;
- XB_FM_Data[4]=0;
- FM_I2C_IN_ISP(0xC0);
- }
- void FM_initISP()
- {
- PB_HOST[I2CSEL] |= SET_BIT0;
- if((XW_FM_Freq>FMMax)||(XW_FM_Freq<FMMin))
- XW_FM_Freq=FMMin;
- XB_FM_Data[0]=0;
- XB_FM_Data[2]=0;
- SetFMDataISP();
- }
- #define buf gxTemp4
- #define PTR XB_BUF0xE000
- void LoadSettingISP(void)
- {
- //XBYTE *PTR;
-
- LoadWPROPage(buf,1);
- //PTR=BUFADR[buf];
- if (
- (PTR[0]=='S')&&
- (PTR[1]=='M')&&
- (PTR[2]=='I')
- )
- {
- gxRepeatMode=PTR[0x10];
- XB_ADJ_Language=PTR[0x11];
- XB_ADJ_CurrentV=PTR[0x12];
- if(XB_ADJ_CurrentV>24)
- XB_ADJ_CurrentV=24;
-
- XB_ADJ_EQMode=PTR[0x13];
- XB_ADJ_AutoOff=PTR[0x14];
- XB_ADJ_Contrast=PTR[0x15];
-
- SelectFolderCount=XB_ADJ_Contrast&0x0f;
- FolderStudeLevel=((XB_ADJ_Contrast>>4)&0x0f)*10;
- if( (SelectFolderCount>36)||(!SelectFolderCount) )
- SelectFolderCount=1;
- if( (FolderStudeLevel>100)||(!FolderStudeLevel) )
- FolderStudeLevel=40;
- XB_ADJ_Contrast=4;
- XB_ADJ_BLTimer=PTR[0x16];
- gxUseEngMenu=PTR[0x17];
- gx16TempReg=((UINT16)PTR[0x18]<<8)+PTR[0x19];
- if(gx16TempReg>=XW_TotalFile[XB_FileType])
- gx16PlayIndex=0;
- else
- gx16PlayIndex=gx16TempReg;
-
-
- XW_FM_Freq=PTR[0x20+XB_FM_MEM*2+1];
- XW_FM_Freq=(XW_FM_Freq<<8)+PTR[0x20+XB_FM_MEM*2];
- if((XW_FM_Freq>FMMax)||(XW_FM_Freq<FMMin)) XW_FM_Freq=FMMin;
-
- XB_FM_MEM=PTR[0x20+21*2];
- }
- else
- {
- gxRepeatMode=0x00;
- XB_ADJ_Language=0x02;
- XB_ADJ_CurrentV=18;
- XB_ADJ_EQMode=0x00;
- XB_ADJ_AutoOff=0x00;
- // XB_ADJ_Contrast=0x51;
- XB_ADJ_Contrast=4;
- SelectFolderCount=1;
- FolderStudeLevel=60;
- XB_ADJ_BLTimer=0x00;
- gxUseEngMenu=0;
- gx16PlayIndex=0;
- XW_FM_Freq=FMMin;
- XB_FM_MEM=0;
- }
- }
- #undef buf
- #undef PTR
- void fmGetMemChannelISP()
- {
- if(XB_FM_MEM>20) XB_FM_MEM=0;
- gxTempR=XB_FM_MEM;
- gxTemp4=BUF0xE000;
- LoadSettingISP();
- //LoadSetting(BUF0xE000);
- XB_FM_MEM=gxTempR;
- XB_FM_Data[0]=0;
- XB_FM_Data[2]=0;
-
- gxlbTempLongByte.ULONG=(UINT32)XW_FM_Freq*(12500/2)+28125; //(GM8)
- gxlbTempLongByte.ULONG=gxlbTempLongByte.ULONG>>10; //(J)/1024
-
- SetFMDataISP();
- gxMemChannel=1;
- GUI_FM_ShowChanISP();
- }
- void InitFMISP()
- {
- while (ReadDSP_DMA_CTRbit());
- // WRITE_DSPREG(DMA_CTR,0);
- Disable_DSP();
- XB_FM_RunSeek=0;
- XB_FM_SeekDir=0;
-
- i2cInitialCS42L51(2);
- uiUpdateMainDisplay(bit7);
- XSFR2&=~bit2;//enable FM data bus pull high
- FM_initISP();
- fmGetMemChannelISP();
- M_SetRampUpToVolume;
- gxRampVolume=0;
- GUI_FM_ShowChanISP();
- }
- void FMStandbyISP()
- {
- XB_FM_Data[1]=XW_FM_Freq&0xFF;
- XB_FM_Data[0]=XB_FM_Data[0]|((XW_FM_Freq>>8)&0x3F);
- XB_FM_Data[2]=(XB_FM_Data[2]&0xA0)|0x30;
- XB_FM_Data[3]=0x53;
- XB_FM_Data[4]=0x00;
- FM_I2C_IN_ISP(0xC0);
- XSFR2|=bit2;//disable FM data bus pull high
-
- #if(S_SupportAudioADC)
- WRITE_DSPIO(0x44,C_ADCDefultSetting);
- M_AudioADCPowerDown;
- #endif
- }
- #if(S_CS42L51)
- void I2CMixOff()
- {
- CodecI2COut(0x0e,0x80);
- CodecI2COut(0x0f,0x80);
- }
- void I2CMixOn()
- {
- CodecI2COut(0x0e,0x00);
- CodecI2COut(0x0f,0x00);
- }
- #endif
- void FM_SeekISP(void)
- {
- //XBYTE u8IFCnt; //20060117_Jash use gxTemp0
- gxTempFMLevel=0; //20060411_Jash
-
- if (gxFMSeekDir>1)
- gxFMSeekDir=XB_FM_SeekDir;
- else
- {
- XB_FM_SeekDir=gxFMSeekDir;
- }
-
- if(XB_FM_RunSeek)
- {
- #if(S_CS42L51)
- I2CMixOff();
- #endif
- #if(S_SupportAudioADC)
- CodeI2C_CS_HIGH;
- #endif
- }
-
- XB_FM_Data[0]=0x00; //(J)Step
-
- if (gxFMSeekDir)
- {
- XW_FM_Freq++;
- if (XW_FM_Freq > FMMax) XW_FM_Freq = FMMin;
- }
- else
- {
- XW_FM_Freq--;
- if (XW_FM_Freq < FMMin) XW_FM_Freq = FMMax;
- }
- XB_FM_Data[2]=0x60;
- gxlbTempLongByte.ULONG=(UINT32)XW_FM_Freq*(12500/2)+28125;
- gxlbTempLongByte.ULONG=gxlbTempLongByte.ULONG>>10; //(J)/1024
- SetFMDataISP();
- gx5P5mSCnt=0;
- T1Flag=0;
- XSFR1 |= bit2; //20060719_Jash //(J)active key pad internal pull high
- delayclk(50); //20060719_Jash
- while(gx5P5mSCnt<3)
- {
- if(T1Flag)
- {
- T1Flag=0;
- gx5P5mSCnt++;
- }
-
- //20060719_Jash
- if((gxKeyMinderBuf==0)&&(~PB_HOST[Key_Pad])) //must be release all key then press any key
- {
- XB_FM_RunSeek=3; //XB_FM_RunSeek=3 means in prepare to leave FM seek mode.
- XB_MENULayer[0]=10; //clear auto scan mode
- #if(S_CS42L51)
- I2CMixOn(); //(GM8)after manually stop FM seek, enable I2CMixOn
- #endif
- break;
- }
- }
- XSFR1 &= ~bit2; //20060719_Jash
-
- FM_I2C_OUT_ISP(0xC1);
- gxTemp0=XB_FM_Data[2]&0x7f;
- //u8ADCLevel=XB_FM_Data[3];
-
- if(XB_FM_Data[0]&0x40)
- {
- if(XB_FM_RunSeek!=2) //20060411_Jash
- {
- XB_FM_RunSeek=0; //original
- //I2CMixOn(); //original
-
- }
- else
- {
- gxTempFMLevel=0xF1;
- }
- }
- else if(((XB_FM_Data[3]&0xf0)>=0xA0)&&(gxTemp0>=49)&&(gxTemp0<=63)) //(J)33,41/49,62
- {
- if(XB_FM_RunSeek!=2) //20060411_Jash
- {
- XB_FM_RunSeek=0; //original
- #if(S_CS42L51)
- I2CMixOn();
- #endif
- #if(S_SupportAudioADC)
- CodeI2C_CS_LOW;
- #endif
- }
- else
- {
- gxTempFMLevel=(XB_FM_Data[3]&0xf0);
- }
- }
-
- #if(S_SupportAudioADC)
- if(XB_FM_RunSeek==3 || XB_FM_RunSeek==0)
- CodeI2C_CS_LOW;
- #endif
- //20060411_Jash
- if(XB_FM_RunSeek==2)
- {
- if(gxTempFMLevel&&(XW_FM_Freq!=(960*2)))
- {
- if(XB_FM_MEM<21)
- {
- gx16FMFreq[XB_FM_MEM]=XW_FM_Freq;
- gxFMLevel[XB_FM_MEM]=gxTempFMLevel;
- if(gxTempFMLevel<gxFMMinLevel)
- {
- gxFMMinLevel=gxTempFMLevel;
- gxMinFreqIndex=XB_FM_MEM;
- }
- XB_FM_MEM++;
- }
- else
- {
- if(gxTempFMLevel>=gxFMMinLevel)
- {
- gx16FMFreq[gxMinFreqIndex]=XW_FM_Freq;
- gxFMLevel[gxMinFreqIndex]=gxTempFMLevel;
-
- gxFMMinLevel=0xFF;
- for(gxTemp1=0;gxTemp1<XB_FM_MEM;gxTemp1++)
- {
- if(gxFMLevel[gxTemp1]<gxFMMinLevel)
- {
- //we give 0xFF for gxFMMinLeve initial value, but the max level is 0xF0.
- //So, the fist time will enter here.
- gxFMMinLevel=gxFMLevel[gxTemp1];
- gxMinFreqIndex=gxTemp1;
- }
- else
- {
- if((gxFMLevel[gxTemp1]==gxFMMinLevel)&&(gx16FMFreq[gxTemp1]<gx16FMFreq[gxMinFreqIndex]))
- {
- gxMinFreqIndex=gxTemp1;
- }
- }
- }
- }
- }
- }
- if(XW_FM_Freq==FMMax)
- {
- for(gxTemp1=0;gxTemp1<XB_FM_MEM;gxTemp1++)
- {
- gxibTempIntegerByte.INTEGER=gx16FMFreq[gxTemp1];
- for(gxTemp2=gxTemp1+1;gxTemp2<XB_FM_MEM;gxTemp2++)
- {
- if(gx16FMFreq[gxTemp2]<gxibTempIntegerByte.INTEGER)
- {
- gxibTempIntegerByte.INTEGER=gx16FMFreq[gxTemp2];
- gx16FMFreq[gxTemp2]=gx16FMFreq[gxTemp1];
- gx16FMFreq[gxTemp1]=gxibTempIntegerByte.INTEGER;
- }
- }
- }
- LoadWPROPage(BUF0xE000,1);
- gxTempPtr=BUFADR[BUF0xE000];
- for(gxTemp1=0;gxTemp1<XB_FM_MEM;gxTemp1++)
- {
- gxTempPtr[0x20+gxTemp1*2]=gx16FMFreq[gxTemp1];
- gxTempPtr[0x20+gxTemp1*2+1]=(gx16FMFreq[gxTemp1]>>8);
-
- }
-
- SaveWPROPage(BUF0xE000,1);
-
- XB_FM_RunSeek=0;
- XB_MENULayer[0]=10;
- XB_FM_MEM=0;
- fmGetMemChannelISP();
- #if(S_CS42L51)
- I2CMixOn();
- #endif
- #if(S_SupportAudioADC)
- CodeI2C_CS_LOW;
- #endif
- }
- }
- }
- CBYTE T_FMAutoScan1[]=
- {
- 'A','u','t','o',' ','S','c','a','n','?',0
- };
- CBYTE T_FMAutoScan2[]=
- {
- 'Y','E','S','=','M','E','N','U',0
- };
- void EnableFMAutoScan(void)
- {
- lcmClearLCM();
- LCM_xp=0;
- LCM_yp=0;
- GUI_ShowSmallString((XBYTE*)(T_FMAutoScan1));
- LCM_xp=0;
- LCM_yp=1;
- GUI_ShowSmallString((XBYTE*)(T_FMAutoScan2));
-
- XB_MENULayer[0]=10;
- gxLevelHoldCnt=0;
- M_SetFMAutoScan;
- M_SetStopKeyFunction;
- }
- void FMProcedure(void)
- {
- if(!gbFMMode)
- {
- #if(S_SupportAudioADC)
- CodeI2C_CS_HIGH;
- delayclk(250);
- delayclk(250);
- delayclk(250);
- delayclk(250);
- delayclk(250);
- PB_DAC[DAC_PowerCtrl]=0x0c;
- #endif
- Process_STOP();
- XB_MENULayer[0]=10; //GOTO FM MODE
- SET_PLAYMODE(C_FMMode);
- XB_NoFile=0;
- //i2cInitialCS42L51ISP(2);
-
- InitFMISP();
- #if(S_SupportAudioADC)
-
- WRITE_DSPIO(0x44,C_ADCDefultSetting); //(G)defult setting, loop back always enable for DSP code "RECFILE" in audio ADC case
-
- gxibTempIntegerByte.INTEGER=0x8000; //(G)use 24.576MHz, sampling rate 32k for DSP code "RECFILE"
- SwitchPLL();
- InitDSPType(RECFILE);
- SWITCH_CLK(PLLCLK+DIV2+WAITS);
- Enable_DSP();
-
- PB_DAC[DAC_SamplingRate]=SR_32K;
- PB_DAC[DAC_PowerCtrl]=0x0d;
-
- M_ClrEnableRampUpVolume;
- gx10P10mSCnt1=0;
- M_AudioADCPowerOn;
-
- #endif
- }
- else
- GotoMainPorg();
- }
- #endif //yu5