FMSi4700.c
资源名称:SDK_M5661.rar [点击查看]
上传用户:hjhsjcl
上传日期:2020-09-25
资源大小:11378k
文件大小:22k
源码类别:
压缩解压
开发平台:
C++ Builder
- #define FMSi4700_GLOBALS
- //#include "user.h"
- #include <DP8051XP.H>
- #include "TypeDef.h"
- #include "Const.h"
- #include "Reg5661.h"
- #if(FM_MODULE==2)
- #include "Common.h"
- #include "UiFm.h"
- //#include "UiSysStr.h"
- //#include "UiCommon.h"
- //#include "Lcd.h"
- //#include "Playback.h"
- //#include "DDM.h"
- //#include "Idma.h"
- //#include "ImaAdpcm.h"
- //#include "SysStrDef.h"
- //#include "ExtCodec.h"
- #include "IntCodec.h"
- #include "intrins.h"
- #include "I2C.h"
- #include "FMSi4700.h"
- //#include "Lcd.h"
- //#include "SysFontDef.h" // WHH070207
- // extern XBYTE FMShowFg[5]={0x0c,0x1C,0x3c,0x1c,0x0c};
- //extern XBYTE xbFmShowFreqNum[10]; //Show FM Freq Number(EX 103.9 MHz) //Dennis060517#1
- /* // WHH070207
- #define UI_CENTER_COLUMN(pbSTR_ARY) ((127-sizeof(pbSTR_ARY)*8)/2)
- extern void LcdShowTitleNum(WORD bShowNum,BYTE bPage,BYTE bColNum,BYTE bLen) large;
- extern BYTE LcdShowString(PBYTE pbShowStr,BYTE bPage,BYTE bColNum,BYTE bLen); //Walace060918#1
- extern void LcdClearAll() large;
- extern void LcdClearBlock(BYTE bPage, BYTE bColNum, BYTE bHeight, BYTE bWidth) large;
- extern void LcdWritePic(PBYTE pbDataSource, BYTE bPage, BYTE bColNum, BYTE bHeight, BYTE bWidth) large;
- extern void LcdOrWrite(BYTE bPage,BYTE bColNum,BYTE bData) large;
- extern void LcdShowSysFont(PWORD pwFontCode,BYTE bPage,BYTE bColNum,BYTE bLen);
- extern void LcdCtrlEn();
- extern void LcdCtrlDis();
- */
- #if(FMTEST)
- extern void OledShowNumber(WORD wShowNum, BYTE bColStart, BYTE bRowStart, BYTE bNumLen); //WHH070207
- #endif
- // Globals
- //XWORD FMshadowReg[16];
- //XWORD FMseekChannels[FMCHANNELSMAX];
- #if (_PM_FM_)
- //================================================================
- void FmSi4700_FmInit(void) large
- {
- // BYTE readData8[16]; //maya for FM A/B chip
- BYTE i; //webber070412
- //obGPIOHDIR|=0x60;
- //obGPIOHDAT&=~0x60;
- //obGPIOEDIR |=~0xBF; // WHH 070130 Power On FM
- //obGPIOEDAT &=0xBF; // WHH 070130 Power On FM
- I2C_FM_SCL_1();
- I2C_FM_SDA_OUT();
- I2C_FM_SEN_1();
- I2C_FM_SDA_0();
- I2C_FM_RST_0();
- //Delay1--50ms
- for(i = 0x60;i > 0;i --); //webber070412
- I2C_FM_RST_1();
- //Delay2--50ms
- for(i = 0x60;i > 0;i --);//webber070412
- I2C_FM_SEN_1();
- I2C_FM_SDA_1();
- //maya for FM A/B chip
- //if(i2c_rd(I2C_FM,I2C_FM_RD_DATA,16,readData8))//;
- // LcdShowTitleNum(FMshadowReg[1],0,0,5);
- // else
- // LcdShowTitleNum(FMshadowReg[1],2,0,5);
- // FMshadowReg[1] = readData8[14]*0x100 + readData8[15];
- // FMshadowReg[1]=((FMshadowReg[1]>>10) & 0x0002);
- //LcdShowTitleNum(FMshadowReg[1],0,0,5);
- // if ( (FMshadowReg[1]>>10) & 0x0002)
- //if(1)// (gxbFmChip&0x20)
- {
- // FMshadowReg[1]=2; //test show chip number
- FmPowerUpB();
- }
- /*
- else
- {
- // FMshadowReg[1]=1; //test show chip number
- FmPowerUpA();
- }
- //*/
- }
- //================================================================
- BYTE FmWaitSTC1(void) large
- {
- #if(WAITGPIO2)
- #if(FMTEST)
- WORD a,b;
- #else
- WORD i;
- #endif
- WAIT_FOR_GPIO2();
- #if(FMTEST)
- for(a=2000;a>0;a--)
- for(b=1000;b>0;b--);
- #else
- for(i=0x2000;i>0;i--);
- #endif
- return(1);
- #else
- BYTE readData8[2];
- WORD loop_counter = 0;
- do
- {
- if(i2c_rd(I2C_FM,I2C_FM_RD_DATA,2,readData8)==0) return(0);
- loop_counter++;
- }
- while(((readData8[0]&0x40)==0)&& (loop_counter < 0xfff));
- return(1);
- #endif
- }
- //================================================================
- BYTE FmWaitSTC0(void) large
- {
- //WORD i;
- //for(i=0x2000;i>0;i--) ;
- //return(1);
- BYTE readData8[2];
- WORD loop_counter = 0;
- do
- {
- if(i2c_rd(I2C_FM,I2C_FM_RD_DATA,2,readData8)==0) return(0);
- loop_counter++;
- }
- while(((readData8[0]&0x40)!=0)&& (loop_counter < 0xfff));
- return(1);
- }
- //================================================================
- BYTE FmPowerUpB(void) large
- {
- XWORD i,j;
- XBYTE writeData8[12];
- //xuehui070406(star) //webber070412(start)
- for(i = 0; i < 12;i ++)
- writeData8[i] = 0x00;
- FMshadowReg[7] = 0x8100;
- writeData8[10] = (FMshadowReg[7] >> 8);
- writeData8[11] = (FMshadowReg[7]);
- if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,12,writeData8) == 0)
- return 0;
- //Delay3--500ms
- for(i=0x500;i>0;i--)
- for(j=0x100;j>0;j--) ; //wait for RCLK
- //xuehui070406(end) //webber070412(end)
- FMshadowReg[2] = 0x0000; // MUTE Enable, ENABLE = 0 //webber 070411
- if( gxbFmState&FM_STATE_STEREO_SET)
- FMshadowReg[2] &=0xdfff;
- else
- FMshadowReg[2] |=0x2000;
- FMshadowReg[3] = 0x0000;
- FMshadowReg[4] = 0xC004; // RDSIEN = 1, STCIEN = 1, GPIO[2] = 1
- //shadowReg[4] = 0xC0c4;
- // FMshadowReg[5] = 0x130F | FMSPACE; // SEEKTH = 0x13, BAND = 0(US), VOLUME = 0xF(MAX.)
- FMshadowReg[5] = (RSSI_THRESHOLD_B)*0x100+FMSPACE+0xF;
- FMshadowReg[6] = RSSI_SEEKSNR*16+RSSI_SEEKCNT_B; //RSSI_ADD_VALUE;
- FMshadowReg[7] = 0x8100;
- writeData8[0] = (FMshadowReg[2] >> 8);
- writeData8[1] = (FMshadowReg[2]);
- writeData8[2] = (FMshadowReg[3] >> 8);
- writeData8[3] = (FMshadowReg[3]);
- writeData8[4] = (FMshadowReg[4] >> 8);
- writeData8[5] = (FMshadowReg[4]);
- writeData8[6] = (FMshadowReg[5] >> 8);
- writeData8[7] = (FMshadowReg[5]);
- writeData8[8] = (FMshadowReg[6] >> 8);
- writeData8[9] = (FMshadowReg[6]);
- writeData8[10] = (FMshadowReg[7] >> 8);
- writeData8[11] = (FMshadowReg[7]);
- if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,12,writeData8))
- {
- for(i=0x300;i>0;i--) //webber 070411
- for(j=0x100;j>0;j--) ; //wait 50ms for RCLK
- FMshadowReg[2] = 0x4001; // MUTE disable, ENABLE = 1
- if( gxbFmState&FM_STATE_STEREO_SET)
- FMshadowReg[2] &=0xdfff;
- else
- FMshadowReg[2] |=0x2000;
- writeData8[0] = (FMshadowReg[2] >> 8);
- writeData8[1] = (FMshadowReg[2]);
- if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8))
- {
- //Delay4 ---50ms
- //for(i=0x100;i>0;i--)
- for(i=0x300;i>0;i--) //webber 070411
- for(j=0x100;j>0;j--) ; //wait 50ms for boot
- return (1);
- }
- else
- return (0);
- }
- else
- return (0);
- }
- //=======================================================================
- #if 0
- BYTE FmPowerUpA(void) large
- {
- WORD i,j;
- BYTE writeData8[10];
- FMshadowReg[2] = 0x4001; // MUTE disable, ENABLE = 1
- FMshadowReg[3] = 0x0000;
- FMshadowReg[4] = 0xC004; // RDSIEN = 1, STCIEN = 1, GPIO[2] = 1
- // FMshadowReg[5] = 0x130F | FMSPACE; // SEEKTH = 0x13, BAND = 0(US), VOLUME = 0xF(MAX.)
- #if(FM_FREQ_JANPA)
- FMshadowReg[5] = (RSSI_THRESHOLD_A)*0x100+FMSPACE+0xF+0x40;
- #else
- FMshadowReg[5] = (RSSI_THRESHOLD_A)*0x100+FMSPACE+0xF;
- #endif
- FMshadowReg[6] = RSSI_SEEKCNT_A;
- writeData8[0] = (FMshadowReg[2] >> 8);
- writeData8[1] = (FMshadowReg[2]);
- writeData8[2] = (FMshadowReg[3] >> 8);
- writeData8[3] = (FMshadowReg[3]);
- writeData8[4] = (FMshadowReg[4] >> 8);
- writeData8[5] = (FMshadowReg[4]);
- writeData8[6] = (FMshadowReg[5] >> 8);
- writeData8[7] = (FMshadowReg[5]);
- writeData8[8] = (FMshadowReg[6] >> 8);
- writeData8[9] = (FMshadowReg[6]);
- if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,10,writeData8))
- {
- for(i=0x100;i>0;i--)
- for(j=0x100;j>0;j--) ; //wait 50ms for boot
- return (1);
- }
- else
- return (0);
- }
- #endif
- #endif
- #if(_PM_FM_|_PM_INIT_)
- //================================================================
- BYTE FmPowerDownB(void) large
- {
- XBYTE writeData8[12];
- FMshadowReg[2] = 0x0041; // DISABLE = 1, ENABLE = 1
- FMshadowReg[3] = 0x0000;
- //FMshadowReg[4] = 0xC0c4; // RDSIEN = 1, STCIEN = 1, GPIO[2] = 1
- FMshadowReg[4] = 0xC004; // RDSIEN = 1, STCIEN = 1, GPIO[2] = 1
- // FMshadowReg[5] = 0x130F | FMSPACE; // SEEKTH = 0x13, BAND = 0(US), VOLUME = 0xF(MAX.)
- FMshadowReg[5] = (RSSI_THRESHOLD_B)*0x100+FMSPACE+0xF;
- FMshadowReg[6] =RSSI_SEEKSNR*16+RSSI_SEEKCNT_B;
- FMshadowReg[7] = 0x0100;
- writeData8[0] = (FMshadowReg[2] >> 8);
- writeData8[1] = (FMshadowReg[2]);
- writeData8[2] = (FMshadowReg[3])>>8;
- writeData8[3] = (FMshadowReg[3]);
- writeData8[4] = (FMshadowReg[4] >> 8);
- writeData8[5] = (FMshadowReg[4]);
- writeData8[6] = (FMshadowReg[5] >> 8);
- writeData8[7] = (FMshadowReg[5]);
- writeData8[8] = (FMshadowReg[6] >> 8);
- writeData8[9] = (FMshadowReg[6]);
- writeData8[10] = (FMshadowReg[7] >> 8);
- writeData8[11] = (FMshadowReg[7]);
- if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,12,writeData8))
- {
- I2C_FM_RST_0();
- return (1);
- }
- else
- {
- I2C_FM_RST_0();
- return (0);
- }
- }
- //================================================================
- #if 0
- BYTE FmPowerDownA(void) large
- {
- BYTE writeData8[2];
- FMshadowReg[2] = 0x0041; // DISABLE = 1, ENABLE = 1
- writeData8[0] = (FMshadowReg[2] >> 8);
- writeData8[1] = (FMshadowReg[2]);
- if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8))
- {
- I2C_FM_RST_0();
- return (1);
- }
- else
- return (0);
- }
- #endif
- #endif
- #if(_PM_FM_)
- //================================================================
- WORD FmChanToFreq(BYTE channel) large
- {
- XWORD channelSpacing;
- XWORD bottomOfBand;
- XWORD frequency;
- if ((FMshadowReg[5] & 0x0080) == 0x0000)
- bottomOfBand = 875;
- else
- bottomOfBand = 760;
- if ((FMshadowReg[5] & 0x0030) == 0x0000)
- channelSpacing = 2;
- else if ((FMshadowReg[5] & 0x0030) == 0x0010)
- channelSpacing = 1;
- else
- channelSpacing = 1;
- frequency = (bottomOfBand + channelSpacing * channel);
- return (frequency);
- }
- //================================================================
- WORD FmFreqToChan(WORD frequency) large
- {
- XWORD channelSpacing;
- XWORD bottomOfBand;
- XWORD channel;
- if ((FMshadowReg[5] & 0x0080) == 0x0000)
- bottomOfBand = 875;
- else
- bottomOfBand = 760;
- if ((FMshadowReg[5] & 0x0030) == 0x0000)
- channelSpacing = 2;
- else if ((FMshadowReg[5] & 0x0030) == 0x0010)
- channelSpacing = 1;
- else
- channelSpacing = 1;
- channel = (frequency - bottomOfBand) / channelSpacing;
- return (channel);
- }
- //================================================================
- BYTE FmTune(WORD channel) large
- {
- XBYTE readData8[32];
- XBYTE writeData8[4];
- if( gxbFmState&FM_STATE_STEREO_SET)
- FMshadowReg[2] &=0xdfff;
- else
- FMshadowReg[2] |=0x2000;
- // FMshadowReg[2]|=0x0001;
- // FMshadowReg[2]&=~0x0040;
- //set tune bit
- writeData8[0] = (FMshadowReg[2] >> 8);
- //writeData8[0] |=0x20;
- writeData8[1] = (FMshadowReg[2]);
- writeData8[2] = ((channel >> 8) | 0x80); // TUNE = 1, channel MSB
- writeData8[3] = channel; // channel LSB
- if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,4,writeData8)==0) return(0);
- //wait STC=1
- if(FmWaitSTC1()==0) return(0);
- //read REG0A&0B
- #if(FMTEST)
- if (i2c_rd(I2C_FM,I2C_FM_RD_DATA,32,readData8)==0) return(0);
- #else
- if (i2c_rd(I2C_FM,I2C_FM_RD_DATA,4,readData8)==0) return(0);
- #endif
- FMshadowReg[10] = readData8[0]*0x100 + readData8[1];
- FMshadowReg[11] = readData8[2]*0x100 + readData8[3];
- #if(FMTEST)
- FMshadowReg[12] = readData8[4]*0x100 + readData8[5];
- FMshadowReg[13] = readData8[6]*0x100 + readData8[7];
- FMshadowReg[14] = readData8[8]*0x100 + readData8[9];
- FMshadowReg[15] = readData8[10]*0x100 + readData8[11];
- FMshadowReg[0] = readData8[12]*0x100 + readData8[13];
- FMshadowReg[1] = readData8[14]*0x100 + readData8[15];
- FMshadowReg[2] = readData8[16]*0x100 + readData8[17];
- FMshadowReg[3] = readData8[18]*0x100 + readData8[19];
- FMshadowReg[4] = readData8[20]*0x100 + readData8[21];
- FMshadowReg[5] = readData8[22]*0x100 + readData8[23];
- FMshadowReg[6] = readData8[24]*0x100 + readData8[25];
- FMshadowReg[7] = readData8[26]*0x100 + readData8[27];
- FMshadowReg[8] = readData8[28]*0x100 + readData8[29];
- FMshadowReg[9] = readData8[30]*0x100 + readData8[31];
- OledShowNumber(FMshadowReg[2],120,0,5);
- OledShowNumber(FMshadowReg[10],120,30,5);
- OledShowNumber(FMshadowReg[0],0,0,5);
- OledShowNumber(FMshadowReg[1],0,30,5);
- OledShowNumber(FMshadowReg[2],0,60,5);
- OledShowNumber(FMshadowReg[3],0,90,5);
- OledShowNumber(FMshadowReg[4],40,0,5);
- OledShowNumber(FMshadowReg[5],40,30,5);
- OledShowNumber(FMshadowReg[6],40,60,5);
- OledShowNumber(FMshadowReg[7],40,90,5);
- OledShowNumber(FMshadowReg[8],80,0,5);
- OledShowNumber(FMshadowReg[9],80,30,5);
- OledShowNumber(FMshadowReg[10],80,60,5);
- OledShowNumber(FMshadowReg[11],80,90,5);
- for(readData8[0]=200;readData8[0]>0;readData8[0]--)
- for(readData8[1]=200;readData8[1]>0;readData8[1]--)
- for(readData8[2]=200;readData8[2]>0;readData8[2]--);
- #endif
- //clear tune bit
- writeData8[0] = (FMshadowReg[2] >> 8);
- writeData8[1] = (FMshadowReg[2]);
- writeData8[2] = (channel >> 8) & 0x7F; // TUNE = 0, channel MSB
- writeData8[3] = channel; // channel LSB
- if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,4,writeData8)==0) return(0);
- //wait STC=0
- if(FmWaitSTC0()==0) return(0);
- return(1);
- }
- //================================================================
- BYTE FmSeek(BYTE seekDirection) large
- {
- XBYTE readData8[4];
- XBYTE writeData8[2];
- BOOL fTemp=0;
- if( gxbFmState&FM_STATE_STEREO_SET)
- FMshadowReg[2] &=0xdfff;
- else
- FMshadowReg[2] |=0x2000;
- //set seek bit
- if(seekDirection == 0)
- writeData8[0] = ((FMshadowReg[2]>>8) | 0x01); // seek down
- else
- writeData8[0] = ((FMshadowReg[2]>>8) | 0x03); // seek up
- writeData8[1] = FMshadowReg[2];
- if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
- //wait STC=1
- if(FmWaitSTC1()==0) return(0);
- //check whether SF=1
- //if((readData8[0]&0x20)!=0) fTemp=1; // modify by Rojam 2007-05-18 16:26
- #if(FMTEST)
- OledShowNumber(FMshadowReg[10],0,17,5);
- OledShowNumber(FmChanToFreq(FMshadowReg[11]),4,17,5);
- //LcdShowString(xbFmShowFreqNum,UI_FM_FREQ2_PAGE,UI_CENTER_COLUMN(xbFmShowFreqNum),sizeof(xbFmShowFreqNum));
- #endif
- //clear seek bit
- writeData8[0] = (FMshadowReg[2] >> 8);
- writeData8[1] = (FMshadowReg[2]);
- if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
- //wait STC=0
- if(FmWaitSTC0()==0) return(0);
- //read REG0A&0B
- if(i2c_rd(I2C_FM,I2C_FM_RD_DATA,4,readData8)==0) return(0);
- FMshadowReg[10] = readData8[0]*0x100 + readData8[1];
- FMshadowReg[11] = readData8[2]*0x100 + readData8[3];
- //read the freqence from si4702 REG 0x0B
- //gxwFmFreq = readData8[3]+FM_FREQ_MIN;
- if(fTemp) return(0);
- else return(1);
- }
- //================================================================
- BYTE FmAutoSeek (BYTE *numChannels) large
- {
- // XBYTE bColNum;
- //XWORD xwLogoNumber; // WHH070207
- XBYTE doneSeeking = 0;
- XBYTE chanIndex = 0;
- //XBYTE xbFmShowFreqNum1[10]; // WHH070207
- //XWORD xwPercent; // WHH070207
- /*xbFmShowFreqNum1[3]='.';
- xbFmShowFreqNum1[5]=' ';
- xbFmShowFreqNum1[6]='M';
- xbFmShowFreqNum1[7]='H';
- xbFmShowFreqNum1[8]='z';
- xbFmShowFreqNum1[9]=' ';//[8]='z';*/ // WHH070207
- // tune to the bottom of the band
- if (FmTune(0)==0) return (0);
- // seek through the band
- while (!doneSeeking)
- {
- if (FmSeek(1)==0)
- {
- *numChannels = chanIndex; //maya for FM clear Freq
- return (0);
- }
- // done seeking if
- // at least one channel has been found previously (chanIndex != 0) and
- // current channel is lower frequency than previous channel
- // (indicating the seek has wrapped the band)
- if ((chanIndex != 0) && (FMshadowReg[11] <= (FMseekChannels[chanIndex-1])))
- doneSeeking = 1;
- // otherwise store the channel and keep seeking
- else
- {
- if((FMshadowReg[10]&0x1000)==0)
- {
- FMseekChannels[chanIndex] = FMshadowReg[11]; // store chan
- gxwPresetData[chanIndex]=FmChanToFreq(FMshadowReg[11]);
- /* // WHH070207
- //---------------------------
- //========================================
- if(gxwFmFreq>=1000)
- xbFmShowFreqNum1[0]=0x30+(gxwFmFreq/1000);
- else
- xbFmShowFreqNum1[0]=' ';
- xbFmShowFreqNum1[1]=0x30+((gxwFmFreq/100)%10);
- xbFmShowFreqNum1[2]=0x30+((gxwFmFreq/10)%10);
- xbFmShowFreqNum1[4]=0x30+(gxwFmFreq%10);
- gxwFmFreq=gxwPresetData[chanIndex];
- // LcdClearBlock(UI_FM_FREQ2_PAGE,0,2,MAX_COLNUM+1);
- #if(USE_SYS_STR_UNICODE)
- gxfSourceUnicode=STRING_TYPE_ASCII;
- #endif
- LcdShowString(xbFmShowFreqNum1,UI_FM_FREQ1_PAGE,UI_CENTER_COLUMN(xbFmShowFreqNum1),sizeof(xbFmShowFreqNum1));
- #if(USE_SYS_STR_UNICODE)
- gxfSourceUnicode=STRING_TYPE_UNICODE;
- #endif
- //bColNum=(BYTE)(gxwFmFreq-FM_FREQ_MIN)/1.7;
- //LcdClearBlock(6, 0,1, 128);
- //LcdWritePic(FMShowFg,6, bColNum, 1, 5);
- //xwLogoNumber = X_LOGO_23;
- xwLogoNumber=0; // WHH 070129
- LcdShowSysFont(&xwLogoNumber,3,0,1);
- xwPercent=(gxwFmFreq-FM_FREQ_MIN)*90;//LV24000 need divide 10.
- xwPercent/=205;
- xwPercent+=19;
- LcdOrWrite(7,(BYTE)xwPercent-2,0x04);//show indicator above freq ruler.
- LcdOrWrite(7,(BYTE)xwPercent-1,0x0c);
- LcdOrWrite(7,(BYTE)xwPercent,0x1c);
- LcdOrWrite(7,(BYTE)xwPercent+1,0x0c);
- LcdOrWrite(7,(BYTE)xwPercent+2,0x04);
- //=========================================
- //-----------------------------
- */
- chanIndex++; // increment channel index
- //fPresetNum++;
- gxbFmPreset++;
- gxbPresetMax = gxbFmPreset;
- //LcdShowTitleNum(gxbFmPreset,2,46,2);//current station
- //LcdShowTitleNum(gxbFmPreset,0,64,2);//current station // WHH070207
- //LcdShowTitleNum(gxbPresetMax,0,80,2);//total station // WHH070207
- if (chanIndex == FMCHANNELSMAX) doneSeeking = 1;// max channels stored
- }
- }
- // #if(FMTEST)
- // LcdShowTitleNum(chanIndex,0,17,2);
- // #endif
- }
- *numChannels = chanIndex;
- if(chanIndex) return(1);
- else return(0);
- }
- #endif
- #if (_PM_FM_|_PM_MPTEST_)
- /*--------------------------------------------------------------------------
- Desciption:
- Set FM IC's PLL by "gxwFmFreq"
- Arguments:
- void
- Global arguments:
- gxwFmFreq : FM frequency based on 100KHz
- Returns:
- TRUE: Set Freq successful
- FALSE: Busy time out or Nack error
- --------------------------------------------------------------------------*/
- BYTE FmSi4700_FmSetFrequency(void)
- {
- XWORD xwPLL;
- if(gxwFmFreq<FM_FREQ_MIN) gxwFmFreq=FM_FREQ_MIN;
- if(gxwFmFreq>FM_FREQ_MAX) gxwFmFreq=FM_FREQ_MAX;
- //gxwFmFreq=1065;
- xwPLL=FmFreqToChan(gxwFmFreq);
- return FmTune(xwPLL);
- }
- // WHH 070207
- /*bit FmSetFreq(void)
- {
- return (1);
- }*/
- #endif
- #if (_PM_FM_|_PM_INIT_)
- /*--------------------------------------------------------------------------
- Desciption:
- Stop FM Module, set IC mute and standby
- Arguments:
- void
- Global arguments:
- void
- Returns:
- void
- --------------------------------------------------------------------------*/
- void FmSi4700_FmEnd(void)
- {
- /*
- ClkCdcEn(); //2004.11.16 Renshuo
- //obALGPAREG |= 0x04; //power down PDY
- //obALGPAREG |= 0x01; //power down PD
- //obALGPAREG |= 0x02; //power down PDX
- IntCdcPowerDownPa(); //Renshuo041207#A //Ren050312#1
- */
- // ClkCdcDis();
- // gfCdcAlreadyInit = FALSE; /*2004.11.17 Renshuo add*/
- // if ( (FMshadowReg[1]>>10) & 0x0002)
- //if(1)// (gxbFmChip&0x20)
- {
- FmPowerDownB();
- }/*
- else
- {
- FmPowerDownA();
- }
- */
- }
- #endif
- #if (_PM_FM_)
- /*--------------------------------------------------------------------------
- Desciption:
- Search Up/Down from currently frequency
- Arguments:
- fSearchUp 1: Up 0: Down
- bStopLevel
- Global arguments:
- void
- Returns:
- TRUE: A station is found
- FALSE:Reach the band limit
- --------------------------------------------------------------------------*/
- BYTE FmSi4700_FmSearch(BYTE fSearchUp)
- {
- BOOL fTemp;
- fTemp=FmSeek(fSearchUp);
- gxwFmFreq=FmChanToFreq(FMshadowReg[11]);
- return(fTemp);
- }
- #endif
- #if (_PM_FM_)
- /*--------------------------------------------------------------------------
- Desciption:
- Set FM in mute mode, this function will set frequ, too.
- If You want to unmute, just call FmSetFreq
- Arguments:
- void
- Global arguments:
- gxwFmFreq : FM frequency based on 100KHz
- Returns:
- void
- --------------------------------------------------------------------------*/
- BYTE FmSi4700_FmSetMute(void)
- {
- XBYTE writeData8[2];
- FMshadowReg[2] = 0x0001; // MUTE ENABLE = 0
- writeData8[0] = (FMshadowReg[2] >> 8);
- writeData8[1] = (FMshadowReg[2]);
- if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8))
- {
- return (1);
- }
- else
- return (0);
- // XWORD xwPLL;
- //
- // xwPLL=CalculatePLL(gxwFmFreq);
- // if (gfHILOInjection)
- // gxbFmWriteData[2] |= FM_HI_INJECTION_EN;
- // else
- // gxbFmWriteData[2] &= FM_LO_INJECTION_ENJ;
- //
- // gxbFmWriteData[0]=((xwPLL>>8) | FM_CMD_MUTE_EN) & FM_CMD_SEARCH_DIS; //mute and not in search mode
- // gxbFmWriteData[1]=xwPLL ;
- // TEA5767Write();
- }
- BYTE FmSi4700_FmMuteDisable(void)
- {
- XBYTE writeData8[2];
- FMshadowReg[2] = 0x4001; // MUTE ENABLE = 0
- writeData8[0] = (FMshadowReg[2] >> 8);
- writeData8[1] = (FMshadowReg[2]);
- if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8))
- {
- return (1);
- }
- else
- return (0);
- }
- #endif
- #if (_PM_FM_)
- /*--------------------------------------------------------------------------
- Desciption:
- Set FM in mute mode, this function will set frequ, too.
- If You want to unmute, just call FmSetFreq
- Arguments:
- void
- Global arguments:
- gxwFmFreq : FM frequency based on 100KHz
- Returns:
- void
- --------------------------------------------------------------------------*/
- API void FmUpdateRSSI(void)
- {
- XBYTE readData8[4];
- //read REG0A&0B
- if (i2c_rd(I2C_FM,I2C_FM_RD_DATA,4,readData8)==0) return;
- FMshadowReg[10] = readData8[0]*0x100 + readData8[1];
- FMshadowReg[11] = readData8[2]*0x100 + readData8[3];
- }
- #endif
- #if(_PM_INIT_| _PM_FM_)
- BYTE FmCheck(void) //MAYA FOR FM CHIP CHECK
- {
- XBYTE readData8[16];
- BYTE bI;
- //init_i2c(I2C_FM);
- I2C_FM_SCL_1();
- I2C_FM_SDA_OUT();
- I2C_FM_SEN_1();
- I2C_FM_SDA_0();
- I2C_FM_RST_0();
- _nop_();
- _nop_();
- _nop_();
- I2C_FM_RST_1();
- _nop_();
- _nop_();
- _nop_();
- I2C_FM_SEN_1();
- I2C_FM_SDA_1();
- i2c_rd(I2C_FM,I2C_FM_RD_DATA,16,readData8);
- FMshadowReg[1] = readData8[14]*0x100 + readData8[15];
- //LcdShowTitleNum(33,2,64,2);
- bI = 11;
- if ( (FMshadowReg[1]>>10) & 0x0002)
- {
- //gxbFmChip=0x22;
- //LcdShowTitleNum(22,2,64,2);
- bI = 22;
- FmSi4700_FmEnd();
- }
- else if( (FMshadowReg[1]>>10) & 0x0001)
- {
- //gxbFmChip=0x12;
- //LcdShowTitleNum(12,2,64,2);
- bI = 33;
- //FmSi4700_FmEnd();
- }
- return bI;
- }
- #endif
- #endif // #if(FM_MODULE==2)
English
