#include "QN8035.h"
#include "simu_I2C_port.h"
//#include "Rx_I2C.h"
//#include "W5500.h"
//#include "qn8007.h"
//#include "Define.h"
//#include "UART.h"
#define I2C_TIMEOUT_COUNT 8
u8 qn8035channle=4;
unsigned char qnd_ChipID,qnd_i2c,qnd_i2c_timeout,qnd_Country,qnd_div1,qnd_div2,qnd_nco,qnd_IsQN8035B,qnd_CH_STEP;
unsigned int qnd_CH_START,qnd_CH_STOP;
/**********************************************************************
void QNF_RXInit()
**********************************************************************
Description: set to SNR based MPX control. Call this function before
tune to one specific channel
Parameters:
None
Return Value:
None
**********************************************************************/
u8 QNF_RXInit()
{
QNF_SetRegBit(0x1b,0x08,0x00); //Let NFILT adjust freely
QNF_SetRegBit(0x2c,0x3f,0x12);
QNF_SetRegBit(0x1d,0x40,0x00);
QNF_SetRegBit(0x41,0x0f,0x0a);
QND_WriteReg(0x45,0x50);
// QNF_SetRegBit(0x40,0x70,0x70);
//QNF_SetRegBit(0x19,0x80,0x80);
QNF_SetRegBit(0x3e,0x80,0x80);
QNF_SetRegBit(0x41,0xe0,0xc0);
if(qnd_ChipID == CHIPSUBID_QN8035A0)
{
QNF_SetRegBit(0x42,0x10,0x10);
}
return 1;
}
u8 QND_WriteReg(u8 Regis_Addr,u8 Data)
{
return QND_I2C_WRITE(Regis_Addr,Data);
}
/**********************************************************************
void QNF_SetRegBit(uint8 reg, uint8 bitMask, uint8 data_val)
***********************************************************************
Description: set register specified bit
Parameters:
reg: register that will be set
bitMask: mask specified bit of register
data_val: data will be set for specified bit
Return Value:
None
**********************************************************************/
void QNF_SetRegBit(u8 reg, u8 bitMask, u8 data_val)
{
u8 temp;
temp = QND_ReadReg(reg);
temp &= (unsigned char)(~bitMask);
temp |= data_val & bitMask;
QND_WriteReg(reg, temp);
}
u8 QND_ReadReg(u8 Regis_Addr)
{
unsigned char Data;
Data = QND_I2C_READ(Regis_Addr);
return Data;
}
u8 QND_I2C_WRITE(u8 Regis_Addr,u8 Data)
{
u8 ret;
u8 tryCount = I2C_TIMEOUT_COUNT;
qnd_i2c = 1;
while(--tryCount) {
// ret = Rx_I2C_Write_Byte(I2C_DEV0_ADDRESS, Regis_Addr, Data);
Reg8bit_Write_Byte(I2C_DEV0_ADDRESS,Regis_Addr,Data,qn8035channle);
if(ret) break;
}
if(!tryCount) {
// SPRINTF(("QND_I2C_WRITE error!\n"));
return 0;
}
qnd_i2c = 0;
return 1;
}
u8 QND_I2C_READ(u8 Regis_Addr)
{
u8 ret;
u8 tryCount = I2C_TIMEOUT_COUNT;
qnd_i2c = 1;
while(--tryCount) {
// ret = Rx_I2C_Read_Byte(I2C_DEV0_ADDRESS, Regis_Addr);
ret =Reg8bit_Read_Byte(I2C_DEV0_ADDRESS,Regis_Addr,qn8035channle);
if(!qnd_i2c_timeout) break;
}
if(!tryCount) {
// SPRINTF(("QND_I2C_READ error!\n"));
}
qnd_i2c = 0;
return ret;
}
//unsigned char QND_I2C_NREAD(unsigned char Regis_Addr, unsigned char *buf, unsigned char n)
//{
// unsigned char ret;
// unsigned char tryCount = I2C_TIMEOUT_COUNT;
// qnd_i2c = 1;
// while(--tryCount) {
// ret = Rx_I2C_Read_nByte(I2C_DEV0_ADDRESS, Regis_Addr, buf, n);
//
// if(!qnd_i2c_timeout) break;
// }
// if(!tryCount) {
//// SPRINTF(("QND_I2C_READ error!\n"));
// }
// qnd_i2c = 0;
// return ret;
//}
/*
unsigned char QND_I2C_NWRITE(unsigned char Regis_Addr, unsigned char *buf, unsigned char n)
{
unsigned char ret;
unsigned char tryCount = I2C_TIMEOUT_COUNT;
qnd_i2c = 1;
while(--tryCount) {
ret = I2C_Write_nbyte(I2C_DEV0_ADDRESS, Regis_Addr, buf, n);
if(!qnd_i2c_timeout) break;
}
if(!tryCount) {
// SPRINTF(("QND_I2C_READ error!\n"));
}
qnd_i2c = 0;
return ret;
}
*/
void QND_SetCountry(u8 country)
{
qnd_Country = country;
switch(country)
{
case COUNTRY_CHINA:
qnd_CH_START = 8750;
qnd_CH_STOP = 10800;
qnd_CH_STEP = 1;
break;
case COUNTRY_USA:
qnd_CH_START = 8810;
qnd_CH_STOP = 10790;
qnd_CH_STEP = 2;
break;
case COUNTRY_JAPAN:
qnd_CH_START = 7600;
qnd_CH_STOP = 9000;
qnd_CH_STEP = 1;
break;
default:
break;
}
}
void QND_Set_Vol(u8 temp_vol)
{
QND_WriteReg(QN8035_VOL_CTL,0x40|temp_vol);
}
/**********************************************************************
void QNF_SetMute(UINT8 On)
***********************************************************************
Description: set register specified bit
Parameters:
On: 1: mute, 0: unmute
Return Value:
None
**********************************************************************/
void QNF_SetMute(u8 On)
{
if(On)
{
// QNF_SetRegBit(0x4C, 0x0B, 0x0B);
QNF_SetRegBit(QN8035_VOL_CTL,0x80,0x80); //This is my command
}
else
{
// DelayWaitMs(QND_DELAY_BEFORE_UNMUTE);
// QNF_SetRegBit(0x4C, 0x0B, 0x00);
QNF_SetRegBit(QN8035_VOL_CTL,0x80,0x00);//This is my command;
}
}
/**********************************************************************
void QND_SetSysMode(uint16 mode)
***********************************************************************
Description: Set device system mode(like: sleep ,wakeup etc)
Parameters:
mode: set the system mode , it will be set by some macro define usually:
SLEEP : set chip to sleep mode
WAKEUP: wake up chip
RX: set chip work on RX mode
Return Value:
None
**********************************************************************/
void QND_SetSysMode(u16 mode)
{
u8 val;
switch(mode)
{
case QND_MODE_SLEEP: //set sleep mode
QNF_SetRegBit(QN8035_REG_DAC, 0x08, 0x00); //make sure Power down control by FSM control
QNF_SetRegBit(QN8035_SYSTEM1, QN8035_STNBY_RX_MASK, QN8035_STNBY_MODE);
break;
case QND_MODE_WAKEUP: //set wakeup mode
QNF_SetRegBit(QN8035_REG_DAC, 0x08, 0x00); //make sure Power down control by FSM control
QNF_SetRegBit(QN8035_SYSTEM1, QN8035_STNBY_RX_MASK, QN8035_RX_MODE);
QNF_SetMute(1);
Delay_ms(SLEEP_TO_WAKEUP_DELAY_TIME); //avoid noise from sleep to wakeup mode during.
QNF_SetMute(0);
break;
default:
val = (unsigned char)(mode >> 8);
if (val)
{
val = val >> 3;
if(val&0x10)
// set to new mode if it's not same as old
if((QND_ReadReg(QN8035_SYSTEM1) & QN8035_STNBY_RX_MASK) != val)
{
QNF_SetMute(1);
QNF_SetRegBit(QN8035_SYSTEM1, QN8035_STNBY_RX_MASK, val);
}
}
break;
}
}
/**********************************************************************
void QNF_SetCh(uint16 freq)
**********************************************************************
Description: set channel frequency
Parameters:
freq: channel frequency to be set
Return Value:
None
**********************************************************************/
void QNF_SetCh(u16 freq)
{
u8 tStep;
u8 tCh;
u16 f;
// uint16 pll_dlt;
if(freq == 8550)
{
QND_WriteReg(QN8035_XTAL_DIV1, QND_XTAL_DIV1_855);
QND_WriteReg(QN8035_XTAL_DIV2, QND_XTAL_DIV2_855);
QND_WriteReg(QN8035_NCO_COMP_VAL, 0x69);
freq = 8570;
}
else
{
QND_WriteReg(QN8035_XTAL_DIV1, qnd_div1);
QND_WriteReg(QN8035_
评论1