FMSi4700.c
上传用户:hjhsjcl
上传日期:2020-09-25
资源大小:11378k
文件大小:22k
源码类别:

压缩解压

开发平台:

C++ Builder

  1. #define      FMSi4700_GLOBALS
  2. //#include "user.h"
  3. #include <DP8051XP.H>
  4.  
  5. #include "TypeDef.h"
  6. #include "Const.h"
  7. #include "Reg5661.h"
  8. #if(FM_MODULE==2)
  9. #include "Common.h"
  10. #include "UiFm.h"
  11. //#include "UiSysStr.h"
  12. //#include "UiCommon.h"
  13. //#include "Lcd.h"
  14. //#include "Playback.h"
  15. //#include "DDM.h"
  16. //#include "Idma.h"
  17. //#include "ImaAdpcm.h"
  18. //#include "SysStrDef.h"
  19. //#include "ExtCodec.h"
  20. #include "IntCodec.h"
  21. #include "intrins.h"
  22. #include "I2C.h"
  23. #include "FMSi4700.h"
  24. //#include "Lcd.h"
  25. //#include "SysFontDef.h" // WHH070207
  26. // extern XBYTE  FMShowFg[5]={0x0c,0x1C,0x3c,0x1c,0x0c};
  27. //extern XBYTE xbFmShowFreqNum[10]; //Show FM Freq Number(EX 103.9 MHz) //Dennis060517#1
  28. /* // WHH070207
  29. #define UI_CENTER_COLUMN(pbSTR_ARY) ((127-sizeof(pbSTR_ARY)*8)/2)
  30. extern void LcdShowTitleNum(WORD bShowNum,BYTE bPage,BYTE bColNum,BYTE bLen) large;
  31. extern BYTE LcdShowString(PBYTE pbShowStr,BYTE bPage,BYTE bColNum,BYTE bLen);  //Walace060918#1
  32. extern void LcdClearAll() large;
  33. extern void LcdClearBlock(BYTE bPage, BYTE bColNum, BYTE bHeight, BYTE bWidth) large;
  34. extern void LcdWritePic(PBYTE pbDataSource, BYTE bPage, BYTE bColNum, BYTE bHeight, BYTE bWidth) large;
  35. extern void LcdOrWrite(BYTE bPage,BYTE bColNum,BYTE bData) large;
  36. extern void LcdShowSysFont(PWORD pwFontCode,BYTE bPage,BYTE bColNum,BYTE bLen);
  37. extern void LcdCtrlEn();
  38. extern void LcdCtrlDis();
  39. */
  40. #if(FMTEST)
  41. extern void OledShowNumber(WORD wShowNum, BYTE bColStart, BYTE bRowStart, BYTE bNumLen); //WHH070207
  42. #endif
  43. // Globals
  44. //XWORD FMshadowReg[16];
  45. //XWORD FMseekChannels[FMCHANNELSMAX];
  46. #if (_PM_FM_)
  47. //================================================================
  48. void FmSi4700_FmInit(void) large
  49. {
  50. // BYTE readData8[16]; //maya for FM A/B chip
  51. BYTE i; //webber070412
  52. //obGPIOHDIR|=0x60;
  53. //obGPIOHDAT&=~0x60;
  54. //obGPIOEDIR |=~0xBF; // WHH 070130 Power On FM
  55. //obGPIOEDAT &=0xBF; // WHH 070130 Power On FM
  56. I2C_FM_SCL_1();
  57. I2C_FM_SDA_OUT();
  58. I2C_FM_SEN_1();
  59. I2C_FM_SDA_0();
  60. I2C_FM_RST_0();
  61. //Delay1--50ms
  62. for(i = 0x60;i > 0;i --); //webber070412  
  63. I2C_FM_RST_1();
  64. //Delay2--50ms
  65. for(i = 0x60;i > 0;i --);//webber070412 
  66. I2C_FM_SEN_1();
  67. I2C_FM_SDA_1();
  68. //maya for FM A/B chip
  69. //if(i2c_rd(I2C_FM,I2C_FM_RD_DATA,16,readData8))//;
  70. // LcdShowTitleNum(FMshadowReg[1],0,0,5);
  71. // else
  72. // LcdShowTitleNum(FMshadowReg[1],2,0,5);
  73. // FMshadowReg[1] = readData8[14]*0x100 + readData8[15]; 
  74. // FMshadowReg[1]=((FMshadowReg[1]>>10) & 0x0002);
  75. //LcdShowTitleNum(FMshadowReg[1],0,0,5);
  76. // if ( (FMshadowReg[1]>>10) & 0x0002)
  77. //if(1)//  (gxbFmChip&0x20)
  78. {
  79. // FMshadowReg[1]=2; //test show chip number
  80. FmPowerUpB();
  81. }
  82. /*
  83. else
  84. {
  85. // FMshadowReg[1]=1; //test show chip number
  86. FmPowerUpA();
  87. }
  88. //*/
  89. }
  90. //================================================================
  91. BYTE FmWaitSTC1(void) large
  92. {
  93. #if(WAITGPIO2)
  94. #if(FMTEST)
  95. WORD a,b;
  96. #else
  97. WORD i;
  98. #endif
  99. WAIT_FOR_GPIO2();
  100. #if(FMTEST)
  101. for(a=2000;a>0;a--)
  102. for(b=1000;b>0;b--);
  103. #else
  104. for(i=0x2000;i>0;i--); 
  105. #endif
  106. return(1);
  107. #else
  108. BYTE readData8[2];
  109. WORD loop_counter = 0;
  110. do
  111. {
  112. if(i2c_rd(I2C_FM,I2C_FM_RD_DATA,2,readData8)==0) return(0);
  113. loop_counter++;
  114. }
  115. while(((readData8[0]&0x40)==0)&& (loop_counter < 0xfff));
  116. return(1);
  117. #endif
  118. }
  119. //================================================================
  120. BYTE FmWaitSTC0(void) large
  121. {
  122. //WORD i;
  123. //for(i=0x2000;i>0;i--) ;
  124. //return(1);
  125. BYTE readData8[2];
  126. WORD loop_counter = 0;
  127. do
  128. {
  129. if(i2c_rd(I2C_FM,I2C_FM_RD_DATA,2,readData8)==0) return(0);
  130. loop_counter++;
  131. }
  132. while(((readData8[0]&0x40)!=0)&& (loop_counter < 0xfff));
  133. return(1);
  134. }
  135. //================================================================
  136. BYTE FmPowerUpB(void) large
  137. {
  138. XWORD i,j;
  139. XBYTE writeData8[12];
  140. //xuehui070406(star) //webber070412(start)
  141. for(i = 0; i < 12;i ++)
  142. writeData8[i] = 0x00;
  143. FMshadowReg[7] = 0x8100;
  144. writeData8[10] = (FMshadowReg[7] >> 8);
  145. writeData8[11] = (FMshadowReg[7]);
  146. if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,12,writeData8) == 0)
  147. return 0;
  148. //Delay3--500ms
  149. for(i=0x500;i>0;i--)
  150. for(j=0x100;j>0;j--) ;  //wait  for RCLK
  151. //xuehui070406(end) //webber070412(end)
  152.  FMshadowReg[2] = 0x0000;  // MUTE Enable, ENABLE = 0 //webber 070411
  153.  if( gxbFmState&FM_STATE_STEREO_SET)
  154.   FMshadowReg[2] &=0xdfff;
  155.  else
  156.   FMshadowReg[2] |=0x2000;
  157.  
  158. FMshadowReg[3] = 0x0000;
  159. FMshadowReg[4] = 0xC004;  // RDSIEN = 1, STCIEN = 1, GPIO[2] = 1
  160.        //shadowReg[4] = 0xC0c4;
  161. // FMshadowReg[5] = 0x130F | FMSPACE;  // SEEKTH = 0x13, BAND = 0(US), VOLUME = 0xF(MAX.)
  162. FMshadowReg[5] = (RSSI_THRESHOLD_B)*0x100+FMSPACE+0xF;
  163. FMshadowReg[6] = RSSI_SEEKSNR*16+RSSI_SEEKCNT_B; //RSSI_ADD_VALUE;
  164. FMshadowReg[7] = 0x8100;
  165. writeData8[0] = (FMshadowReg[2] >> 8);
  166. writeData8[1] = (FMshadowReg[2]);
  167. writeData8[2] = (FMshadowReg[3] >> 8);
  168. writeData8[3] = (FMshadowReg[3]);
  169. writeData8[4] = (FMshadowReg[4] >> 8);
  170. writeData8[5] = (FMshadowReg[4]);
  171. writeData8[6] = (FMshadowReg[5] >> 8);
  172. writeData8[7] = (FMshadowReg[5]);
  173. writeData8[8] = (FMshadowReg[6] >> 8);
  174. writeData8[9] = (FMshadowReg[6]);
  175. writeData8[10] = (FMshadowReg[7] >> 8);
  176. writeData8[11] = (FMshadowReg[7]);
  177. if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,12,writeData8))
  178. {
  179. for(i=0x300;i>0;i--) //webber 070411
  180. for(j=0x100;j>0;j--) ;  //wait 50ms for RCLK
  181. FMshadowReg[2] = 0x4001;  // MUTE disable, ENABLE = 1
  182.  if( gxbFmState&FM_STATE_STEREO_SET)
  183.    FMshadowReg[2] &=0xdfff;    
  184.        else
  185.              FMshadowReg[2] |=0x2000;   
  186. writeData8[0] = (FMshadowReg[2] >> 8);
  187. writeData8[1] = (FMshadowReg[2]);
  188. if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8))
  189. {
  190. //Delay4 ---50ms
  191. //for(i=0x100;i>0;i--)
  192. for(i=0x300;i>0;i--)           //webber 070411
  193. for(j=0x100;j>0;j--) ; //wait 50ms for boot
  194. return (1);
  195. }
  196. else
  197. return (0);
  198. }
  199. else
  200. return (0);
  201. }
  202. //=======================================================================
  203. #if 0
  204. BYTE FmPowerUpA(void) large
  205. {
  206. WORD i,j;
  207. BYTE writeData8[10];
  208. FMshadowReg[2] = 0x4001;  // MUTE disable, ENABLE = 1
  209. FMshadowReg[3] = 0x0000;
  210. FMshadowReg[4] = 0xC004;  // RDSIEN = 1, STCIEN = 1, GPIO[2] = 1
  211. // FMshadowReg[5] = 0x130F | FMSPACE;  // SEEKTH = 0x13, BAND = 0(US), VOLUME = 0xF(MAX.)
  212. #if(FM_FREQ_JANPA)
  213. FMshadowReg[5] = (RSSI_THRESHOLD_A)*0x100+FMSPACE+0xF+0x40;
  214. #else
  215. FMshadowReg[5] = (RSSI_THRESHOLD_A)*0x100+FMSPACE+0xF;
  216. #endif
  217. FMshadowReg[6] = RSSI_SEEKCNT_A;
  218. writeData8[0] = (FMshadowReg[2] >> 8);
  219. writeData8[1] = (FMshadowReg[2]);
  220. writeData8[2] = (FMshadowReg[3] >> 8);
  221. writeData8[3] = (FMshadowReg[3]);
  222. writeData8[4] = (FMshadowReg[4] >> 8);
  223. writeData8[5] = (FMshadowReg[4]);
  224. writeData8[6] = (FMshadowReg[5] >> 8);
  225. writeData8[7] = (FMshadowReg[5]);
  226. writeData8[8] = (FMshadowReg[6] >> 8);
  227. writeData8[9] = (FMshadowReg[6]);
  228. if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,10,writeData8))
  229. {
  230. for(i=0x100;i>0;i--)
  231. for(j=0x100;j>0;j--) ; //wait 50ms for boot
  232. return (1);
  233. }
  234. else
  235. return (0);
  236. }
  237. #endif
  238. #endif
  239. #if(_PM_FM_|_PM_INIT_)
  240. //================================================================
  241. BYTE FmPowerDownB(void) large 
  242. {
  243. XBYTE writeData8[12];
  244. FMshadowReg[2] = 0x0041; // DISABLE = 1, ENABLE = 1
  245. FMshadowReg[3] = 0x0000;
  246. //FMshadowReg[4] = 0xC0c4;  // RDSIEN = 1, STCIEN = 1, GPIO[2] = 1
  247. FMshadowReg[4] = 0xC004;  // RDSIEN = 1, STCIEN = 1, GPIO[2] = 1
  248. // FMshadowReg[5] = 0x130F | FMSPACE;  // SEEKTH = 0x13, BAND = 0(US), VOLUME = 0xF(MAX.)
  249. FMshadowReg[5] = (RSSI_THRESHOLD_B)*0x100+FMSPACE+0xF;
  250. FMshadowReg[6] =RSSI_SEEKSNR*16+RSSI_SEEKCNT_B;
  251. FMshadowReg[7] = 0x0100;
  252. writeData8[0] = (FMshadowReg[2] >> 8);
  253. writeData8[1] = (FMshadowReg[2]);
  254. writeData8[2] = (FMshadowReg[3])>>8;
  255. writeData8[3] = (FMshadowReg[3]);
  256. writeData8[4] = (FMshadowReg[4] >> 8);
  257. writeData8[5] = (FMshadowReg[4]);
  258. writeData8[6] = (FMshadowReg[5] >> 8);
  259. writeData8[7] = (FMshadowReg[5]);
  260. writeData8[8] = (FMshadowReg[6] >> 8);
  261. writeData8[9] = (FMshadowReg[6]);
  262. writeData8[10] = (FMshadowReg[7] >> 8);
  263. writeData8[11] = (FMshadowReg[7]);
  264. if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,12,writeData8))
  265. {
  266. I2C_FM_RST_0();
  267. return (1);
  268. }
  269. else
  270. {
  271. I2C_FM_RST_0();
  272. return (0);
  273. }
  274. }
  275. //================================================================
  276. #if 0
  277. BYTE FmPowerDownA(void) large 
  278. {
  279. BYTE writeData8[2];
  280. FMshadowReg[2] = 0x0041; // DISABLE = 1, ENABLE = 1
  281. writeData8[0] = (FMshadowReg[2] >> 8);
  282. writeData8[1] = (FMshadowReg[2]);
  283. if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8))
  284. {
  285. I2C_FM_RST_0();
  286. return (1);
  287. }
  288. else
  289. return (0);
  290. }
  291. #endif
  292. #endif
  293. #if(_PM_FM_)
  294. //================================================================
  295. WORD FmChanToFreq(BYTE channel) large
  296. {
  297. XWORD channelSpacing;
  298. XWORD bottomOfBand;
  299. XWORD frequency;
  300. if ((FMshadowReg[5] & 0x0080) == 0x0000) 
  301. bottomOfBand = 875;
  302. else 
  303. bottomOfBand = 760;
  304. if ((FMshadowReg[5] & 0x0030) == 0x0000) 
  305. channelSpacing = 2;
  306. else if ((FMshadowReg[5] & 0x0030) == 0x0010) 
  307. channelSpacing = 1;
  308. else 
  309. channelSpacing = 1;
  310. frequency = (bottomOfBand + channelSpacing * channel);
  311. return (frequency);
  312. }
  313. //================================================================
  314. WORD FmFreqToChan(WORD frequency) large 
  315. {
  316. XWORD channelSpacing;
  317. XWORD bottomOfBand;
  318. XWORD channel;
  319. if ((FMshadowReg[5] & 0x0080) == 0x0000) 
  320. bottomOfBand = 875;
  321. else 
  322. bottomOfBand = 760;
  323. if ((FMshadowReg[5] & 0x0030) == 0x0000) 
  324. channelSpacing = 2;
  325. else if ((FMshadowReg[5] & 0x0030) == 0x0010) 
  326. channelSpacing = 1;
  327. else 
  328. channelSpacing = 1;
  329. channel = (frequency - bottomOfBand) / channelSpacing;
  330. return (channel);
  331. }
  332. //================================================================
  333.  BYTE FmTune(WORD channel) large
  334. {
  335. XBYTE readData8[32];
  336. XBYTE writeData8[4];
  337.         if( gxbFmState&FM_STATE_STEREO_SET)
  338.  FMshadowReg[2] &=0xdfff;
  339.  else
  340.          FMshadowReg[2] |=0x2000;
  341. // FMshadowReg[2]|=0x0001;
  342. // FMshadowReg[2]&=~0x0040;  
  343. //set tune bit
  344. writeData8[0] = (FMshadowReg[2] >> 8);
  345. //writeData8[0] |=0x20;
  346. writeData8[1] = (FMshadowReg[2]);
  347. writeData8[2] = ((channel >> 8) | 0x80);  // TUNE = 1, channel MSB
  348. writeData8[3] = channel;  // channel LSB
  349. if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,4,writeData8)==0) return(0);
  350. //wait STC=1
  351. if(FmWaitSTC1()==0) return(0);
  352. //read REG0A&0B
  353. #if(FMTEST)
  354. if (i2c_rd(I2C_FM,I2C_FM_RD_DATA,32,readData8)==0) return(0);
  355. #else
  356. if (i2c_rd(I2C_FM,I2C_FM_RD_DATA,4,readData8)==0) return(0);
  357. #endif
  358. FMshadowReg[10] = readData8[0]*0x100 + readData8[1];
  359. FMshadowReg[11] = readData8[2]*0x100 + readData8[3];  
  360. #if(FMTEST)
  361. FMshadowReg[12] = readData8[4]*0x100 + readData8[5];
  362. FMshadowReg[13] = readData8[6]*0x100 + readData8[7]; 
  363. FMshadowReg[14] = readData8[8]*0x100 + readData8[9];
  364. FMshadowReg[15] = readData8[10]*0x100 + readData8[11]; 
  365. FMshadowReg[0] = readData8[12]*0x100 + readData8[13];
  366. FMshadowReg[1] = readData8[14]*0x100 + readData8[15]; 
  367. FMshadowReg[2] = readData8[16]*0x100 + readData8[17];
  368. FMshadowReg[3] = readData8[18]*0x100 + readData8[19]; 
  369. FMshadowReg[4] = readData8[20]*0x100 + readData8[21];
  370. FMshadowReg[5] = readData8[22]*0x100 + readData8[23]; 
  371. FMshadowReg[6] = readData8[24]*0x100 + readData8[25];
  372. FMshadowReg[7] = readData8[26]*0x100 + readData8[27]; 
  373. FMshadowReg[8] = readData8[28]*0x100 + readData8[29];
  374. FMshadowReg[9] = readData8[30]*0x100 + readData8[31];
  375. OledShowNumber(FMshadowReg[2],120,0,5);
  376. OledShowNumber(FMshadowReg[10],120,30,5);
  377. OledShowNumber(FMshadowReg[0],0,0,5);
  378. OledShowNumber(FMshadowReg[1],0,30,5);
  379. OledShowNumber(FMshadowReg[2],0,60,5);
  380. OledShowNumber(FMshadowReg[3],0,90,5);
  381. OledShowNumber(FMshadowReg[4],40,0,5);
  382. OledShowNumber(FMshadowReg[5],40,30,5);
  383. OledShowNumber(FMshadowReg[6],40,60,5);
  384. OledShowNumber(FMshadowReg[7],40,90,5);
  385. OledShowNumber(FMshadowReg[8],80,0,5);
  386. OledShowNumber(FMshadowReg[9],80,30,5);
  387. OledShowNumber(FMshadowReg[10],80,60,5);
  388. OledShowNumber(FMshadowReg[11],80,90,5);
  389. for(readData8[0]=200;readData8[0]>0;readData8[0]--)
  390. for(readData8[1]=200;readData8[1]>0;readData8[1]--)
  391. for(readData8[2]=200;readData8[2]>0;readData8[2]--);
  392. #endif
  393. //clear tune bit
  394. writeData8[0] = (FMshadowReg[2] >> 8);
  395. writeData8[1] = (FMshadowReg[2]);
  396. writeData8[2] = (channel >> 8) & 0x7F;  // TUNE = 0, channel MSB
  397. writeData8[3] = channel;  // channel LSB
  398. if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,4,writeData8)==0) return(0);
  399. //wait STC=0
  400. if(FmWaitSTC0()==0) return(0);
  401. return(1);
  402. }
  403. //================================================================
  404. BYTE FmSeek(BYTE seekDirection) large
  405. {
  406. XBYTE readData8[4];
  407. XBYTE writeData8[2];
  408. BOOL fTemp=0;
  409.  if( gxbFmState&FM_STATE_STEREO_SET)
  410.   FMshadowReg[2] &=0xdfff;    
  411.  else
  412.   FMshadowReg[2] |=0x2000;
  413.  
  414. //set seek bit
  415. if(seekDirection == 0) 
  416. writeData8[0] = ((FMshadowReg[2]>>8) | 0x01); // seek down
  417. else 
  418. writeData8[0] = ((FMshadowReg[2]>>8) | 0x03);  // seek up
  419. writeData8[1] = FMshadowReg[2];
  420. if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
  421. //wait STC=1
  422. if(FmWaitSTC1()==0) return(0);
  423. //check whether SF=1
  424. //if((readData8[0]&0x20)!=0) fTemp=1; // modify by Rojam 2007-05-18 16:26
  425. #if(FMTEST)
  426. OledShowNumber(FMshadowReg[10],0,17,5);
  427. OledShowNumber(FmChanToFreq(FMshadowReg[11]),4,17,5);
  428. //LcdShowString(xbFmShowFreqNum,UI_FM_FREQ2_PAGE,UI_CENTER_COLUMN(xbFmShowFreqNum),sizeof(xbFmShowFreqNum));
  429. #endif
  430. //clear seek bit
  431. writeData8[0] = (FMshadowReg[2] >> 8);
  432. writeData8[1] = (FMshadowReg[2]);
  433. if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
  434. //wait STC=0
  435. if(FmWaitSTC0()==0) return(0);
  436. //read REG0A&0B
  437. if(i2c_rd(I2C_FM,I2C_FM_RD_DATA,4,readData8)==0) return(0);
  438. FMshadowReg[10] = readData8[0]*0x100 + readData8[1];
  439. FMshadowReg[11] = readData8[2]*0x100 + readData8[3];
  440. //read the freqence from si4702 REG 0x0B
  441. //gxwFmFreq = readData8[3]+FM_FREQ_MIN;
  442. if(fTemp) return(0);  
  443. else    return(1);
  444. }
  445. //================================================================
  446. BYTE FmAutoSeek (BYTE *numChannels) large
  447. {
  448.     //   XBYTE bColNum;
  449.      //XWORD xwLogoNumber; // WHH070207
  450. XBYTE doneSeeking = 0;
  451. XBYTE chanIndex = 0;
  452.        //XBYTE xbFmShowFreqNum1[10]; // WHH070207
  453. //XWORD xwPercent; // WHH070207
  454.        /*xbFmShowFreqNum1[3]='.';
  455. xbFmShowFreqNum1[5]=' ';
  456. xbFmShowFreqNum1[6]='M';
  457. xbFmShowFreqNum1[7]='H';
  458. xbFmShowFreqNum1[8]='z';
  459. xbFmShowFreqNum1[9]=' ';//[8]='z';*/ // WHH070207
  460. // tune to the bottom of the band
  461. if (FmTune(0)==0) return (0);
  462. // seek through the band
  463. while (!doneSeeking) 
  464. {
  465. if (FmSeek(1)==0)
  466. {
  467. *numChannels = chanIndex; //maya for FM clear Freq
  468. return (0);
  469. }
  470. // done seeking if
  471. // at least one channel has been found previously (chanIndex != 0) and
  472. // current channel is lower frequency than previous channel
  473. // (indicating the seek has wrapped the band)
  474. if ((chanIndex != 0) && (FMshadowReg[11] <= (FMseekChannels[chanIndex-1]))) 
  475. doneSeeking = 1;
  476. // otherwise store the channel and keep seeking
  477. else
  478. {
  479. if((FMshadowReg[10]&0x1000)==0)
  480. {
  481. FMseekChannels[chanIndex] = FMshadowReg[11]; // store chan
  482. gxwPresetData[chanIndex]=FmChanToFreq(FMshadowReg[11]);
  483. /*  // WHH070207
  484. //---------------------------
  485. //========================================
  486.                        if(gxwFmFreq>=1000)
  487.                xbFmShowFreqNum1[0]=0x30+(gxwFmFreq/1000);
  488.                 else
  489.               xbFmShowFreqNum1[0]=' ';
  490.                   xbFmShowFreqNum1[1]=0x30+((gxwFmFreq/100)%10);
  491.                   xbFmShowFreqNum1[2]=0x30+((gxwFmFreq/10)%10);
  492.                   xbFmShowFreqNum1[4]=0x30+(gxwFmFreq%10);
  493. gxwFmFreq=gxwPresetData[chanIndex];
  494. // LcdClearBlock(UI_FM_FREQ2_PAGE,0,2,MAX_COLNUM+1);
  495. #if(USE_SYS_STR_UNICODE)
  496. gxfSourceUnicode=STRING_TYPE_ASCII;
  497. #endif
  498. LcdShowString(xbFmShowFreqNum1,UI_FM_FREQ1_PAGE,UI_CENTER_COLUMN(xbFmShowFreqNum1),sizeof(xbFmShowFreqNum1));
  499. #if(USE_SYS_STR_UNICODE)
  500. gxfSourceUnicode=STRING_TYPE_UNICODE;
  501.                      #endif
  502.  //bColNum=(BYTE)(gxwFmFreq-FM_FREQ_MIN)/1.7;
  503.                       //LcdClearBlock(6, 0,1, 128);
  504.                       //LcdWritePic(FMShowFg,6, bColNum, 1, 5);
  505. //xwLogoNumber = X_LOGO_23;
  506. xwLogoNumber=0; // WHH 070129
  507. LcdShowSysFont(&xwLogoNumber,3,0,1);
  508. xwPercent=(gxwFmFreq-FM_FREQ_MIN)*90;//LV24000 need divide 10.
  509. xwPercent/=205;
  510. xwPercent+=19;
  511. LcdOrWrite(7,(BYTE)xwPercent-2,0x04);//show indicator above freq ruler.
  512. LcdOrWrite(7,(BYTE)xwPercent-1,0x0c);
  513. LcdOrWrite(7,(BYTE)xwPercent,0x1c);
  514. LcdOrWrite(7,(BYTE)xwPercent+1,0x0c);
  515. LcdOrWrite(7,(BYTE)xwPercent+2,0x04);
  516. //=========================================
  517. //-----------------------------
  518. */
  519. chanIndex++; // increment channel index
  520. //fPresetNum++;
  521. gxbFmPreset++;
  522. gxbPresetMax = gxbFmPreset;
  523. //LcdShowTitleNum(gxbFmPreset,2,46,2);//current station
  524. //LcdShowTitleNum(gxbFmPreset,0,64,2);//current station // WHH070207
  525. //LcdShowTitleNum(gxbPresetMax,0,80,2);//total station // WHH070207
  526. if (chanIndex == FMCHANNELSMAX) doneSeeking = 1;// max channels stored
  527. }
  528. }
  529. // #if(FMTEST)
  530. // LcdShowTitleNum(chanIndex,0,17,2);
  531. // #endif
  532. }
  533. *numChannels = chanIndex;
  534. if(chanIndex)  return(1);
  535. else return(0);
  536. }
  537. #endif
  538. #if (_PM_FM_|_PM_MPTEST_)
  539. /*--------------------------------------------------------------------------
  540. Desciption:
  541. Set FM IC's PLL by "gxwFmFreq"
  542. Arguments:
  543. void
  544. Global arguments:
  545. gxwFmFreq : FM frequency based on 100KHz
  546. Returns:
  547. TRUE: Set Freq successful
  548. FALSE: Busy time out or Nack error
  549. --------------------------------------------------------------------------*/
  550.  BYTE FmSi4700_FmSetFrequency(void)
  551. {
  552. XWORD xwPLL;
  553. if(gxwFmFreq<FM_FREQ_MIN) gxwFmFreq=FM_FREQ_MIN;
  554. if(gxwFmFreq>FM_FREQ_MAX) gxwFmFreq=FM_FREQ_MAX;
  555. //gxwFmFreq=1065;
  556. xwPLL=FmFreqToChan(gxwFmFreq);
  557. return FmTune(xwPLL);
  558. }
  559. // WHH 070207
  560. /*bit FmSetFreq(void)
  561. {
  562. return (1);
  563. }*/
  564. #endif
  565. #if (_PM_FM_|_PM_INIT_)
  566. /*--------------------------------------------------------------------------
  567. Desciption:
  568. Stop FM Module, set IC mute and standby
  569. Arguments:
  570. void
  571. Global arguments:
  572. void
  573. Returns:
  574. void
  575. --------------------------------------------------------------------------*/
  576. void FmSi4700_FmEnd(void)
  577. {
  578. /*
  579. ClkCdcEn(); //2004.11.16 Renshuo
  580. //obALGPAREG |= 0x04;  //power down PDY
  581. //obALGPAREG |= 0x01; //power down PD
  582. //obALGPAREG |= 0x02; //power down PDX
  583. IntCdcPowerDownPa(); //Renshuo041207#A //Ren050312#1
  584. */
  585. // ClkCdcDis();
  586. // gfCdcAlreadyInit = FALSE; /*2004.11.17 Renshuo add*/
  587. // if ( (FMshadowReg[1]>>10) & 0x0002)
  588. //if(1)// (gxbFmChip&0x20)
  589. {
  590. FmPowerDownB();
  591. }/*
  592. else
  593. {
  594. FmPowerDownA();
  595. }
  596. */
  597. }
  598. #endif
  599. #if (_PM_FM_)
  600. /*--------------------------------------------------------------------------
  601. Desciption:
  602. Search Up/Down from currently frequency
  603. Arguments:
  604. fSearchUp 1: Up 0: Down
  605. bStopLevel
  606. Global arguments:
  607. void
  608. Returns:
  609. TRUE: A station is found
  610. FALSE:Reach the band limit
  611. --------------------------------------------------------------------------*/
  612. BYTE FmSi4700_FmSearch(BYTE fSearchUp)
  613. {
  614. BOOL fTemp;
  615. fTemp=FmSeek(fSearchUp);
  616. gxwFmFreq=FmChanToFreq(FMshadowReg[11]);
  617. return(fTemp);
  618. }
  619. #endif
  620. #if (_PM_FM_)
  621. /*--------------------------------------------------------------------------
  622. Desciption:
  623. Set FM in mute mode, this function will set frequ, too.
  624. If You want to unmute, just call FmSetFreq
  625. Arguments:
  626. void
  627. Global arguments:
  628. gxwFmFreq : FM frequency based on 100KHz
  629. Returns:
  630. void
  631. --------------------------------------------------------------------------*/
  632. BYTE FmSi4700_FmSetMute(void)
  633. {
  634. XBYTE writeData8[2];
  635. FMshadowReg[2] = 0x0001;  // MUTE ENABLE = 0
  636. writeData8[0] = (FMshadowReg[2] >> 8);
  637. writeData8[1] = (FMshadowReg[2]);
  638. if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8))
  639. {
  640. return (1);
  641. }
  642. else
  643. return (0);
  644. // XWORD xwPLL;
  645. //
  646. // xwPLL=CalculatePLL(gxwFmFreq);
  647. // if (gfHILOInjection)
  648. // gxbFmWriteData[2] |= FM_HI_INJECTION_EN;
  649. // else
  650. // gxbFmWriteData[2] &= FM_LO_INJECTION_ENJ;
  651. //
  652. // gxbFmWriteData[0]=((xwPLL>>8) | FM_CMD_MUTE_EN) & FM_CMD_SEARCH_DIS; //mute and not in search mode
  653. //    gxbFmWriteData[1]=xwPLL ;
  654. // TEA5767Write();
  655. }
  656. BYTE FmSi4700_FmMuteDisable(void)
  657. {
  658. XBYTE writeData8[2];
  659. FMshadowReg[2] = 0x4001;  // MUTE ENABLE = 0
  660. writeData8[0] = (FMshadowReg[2] >> 8);
  661. writeData8[1] = (FMshadowReg[2]);
  662. if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8))
  663. {
  664. return (1);
  665. }
  666. else
  667. return (0);
  668. }
  669. #endif
  670. #if (_PM_FM_)
  671. /*--------------------------------------------------------------------------
  672. Desciption:
  673. Set FM in mute mode, this function will set frequ, too.
  674. If You want to unmute, just call FmSetFreq
  675. Arguments:
  676. void
  677. Global arguments:
  678. gxwFmFreq : FM frequency based on 100KHz
  679. Returns:
  680. void
  681. --------------------------------------------------------------------------*/
  682. API void FmUpdateRSSI(void)
  683. {
  684. XBYTE readData8[4];
  685. //read REG0A&0B
  686. if (i2c_rd(I2C_FM,I2C_FM_RD_DATA,4,readData8)==0) return;
  687. FMshadowReg[10] = readData8[0]*0x100 + readData8[1];
  688. FMshadowReg[11] = readData8[2]*0x100 + readData8[3];  
  689. }
  690. #endif
  691. #if(_PM_INIT_| _PM_FM_)
  692. BYTE FmCheck(void) //MAYA FOR FM CHIP CHECK
  693. {
  694. XBYTE readData8[16];
  695. BYTE bI;
  696. //init_i2c(I2C_FM);
  697. I2C_FM_SCL_1();
  698. I2C_FM_SDA_OUT();
  699. I2C_FM_SEN_1();
  700. I2C_FM_SDA_0();
  701. I2C_FM_RST_0();
  702. _nop_();
  703. _nop_();
  704. _nop_();
  705. I2C_FM_RST_1();
  706. _nop_();
  707. _nop_();
  708. _nop_();
  709. I2C_FM_SEN_1();
  710. I2C_FM_SDA_1();
  711. i2c_rd(I2C_FM,I2C_FM_RD_DATA,16,readData8);
  712. FMshadowReg[1] = readData8[14]*0x100 + readData8[15]; 
  713. //LcdShowTitleNum(33,2,64,2);
  714. bI = 11;
  715. if ( (FMshadowReg[1]>>10) & 0x0002)
  716. {
  717. //gxbFmChip=0x22;
  718. //LcdShowTitleNum(22,2,64,2);
  719. bI = 22;
  720. FmSi4700_FmEnd();
  721. }
  722. else if( (FMshadowReg[1]>>10) & 0x0001)
  723. {
  724. //gxbFmChip=0x12;
  725. //LcdShowTitleNum(12,2,64,2);
  726. bI = 33;
  727. //FmSi4700_FmEnd();
  728. }
  729. return bI;
  730. }
  731. #endif
  732. #endif // #if(FM_MODULE==2)