void A7105_SetPower(int power) { /* Power amp is ~+16dBm so: TXPOWER_100uW = -23dBm == PAC=0 TBG=0 TXPOWER_300uW = -20dBm == PAC=0 TBG=1 TXPOWER_1mW = -16dBm == PAC=0 TBG=2 TXPOWER_3mW = -11dBm == PAC=0 TBG=4 TXPOWER_10mW = -6dBm == PAC=1 TBG=5 TXPOWER_30mW = 0dBm == PAC=2 TBG=7 TXPOWER_100mW = 1dBm == PAC=3 TBG=7 TXPOWER_150mW = 1dBm == PAC=3 TBG=7 */ u8 pac, tbg; switch(power) { case 0: pac = 0; tbg = 0; break; case 1: pac = 0; tbg = 1; break; case 2: pac = 0; tbg = 2; break; case 3: pac = 0; tbg = 4; break; case 4: pac = 1; tbg = 5; break; case 5: pac = 2; tbg = 7; break; case 6: pac = 3; tbg = 7; break; case 7: pac = 3; tbg = 7; break; default: pac = 0; tbg = 0; break; } A7105_WriteReg(0x28, (pac << 3) | tbg); }
// fine tune A7105 LO base frequency // this is required for some A7105 modules / Rx // with inaccurate crystal oscillator // arg: offset in +/-kHz void A7105_AdjustLOBaseFreq(s16 offset) { // LO base frequency = 32e6*(bip+(bfp/(2^16))) u8 bip; // LO base frequency integer part u32 bfp; // LO base frequency fractional part if(offset < 0) { bip = 0x4a; // 2368 MHz bfp = 0xffff+((offset*2048)/1000)+1; } else { bip = 0x4b; // 2400 MHz (default) bfp = (offset*2048)/1000; } if(offset == 0) bfp = 0x0002; // as per datasheet, not sure why recommanded, but that's a +1kHz drift only ... A7105_WriteReg( A7105_11_PLL_III, bip); A7105_WriteReg( A7105_12_PLL_IV, (bfp >> 8) & 0xff); A7105_WriteReg( A7105_13_PLL_V, bfp & 0xff); }
int A7105_Reset() { A7105_WriteReg(0x00, 0x00); usleep(1000); //Set both GPIO as output and low A7105_SetTxRxMode(TXRX_OFF); int result = A7105_ReadReg(0x10) == 0x9E; A7105_Strobe(A7105_STANDBY); return result; }
void A7105_WriteData(u8 *dpbuffer, u8 len, u8 channel) { int i; CS_LO(); PROTOSPI_xfer(A7105_RST_WRPTR); PROTOSPI_xfer(0x05); for (i = 0; i < len; i++) PROTOSPI_xfer(dpbuffer[i]); CS_HI(); A7105_WriteReg(0x0F, channel); CS_LO(); PROTOSPI_xfer(A7105_TX); CS_HI(); }
void A7105_WriteData(u8 *dpbuffer, u8 len, u8 channel) { int i; CS_LO(); spi_xfer(SPI2, A7105_RST_WRPTR); spi_xfer(SPI2, 0x05); for (i = 0; i < len; i++) spi_xfer(SPI2, dpbuffer[i]); CS_HI(); A7105_WriteReg(0x0F, channel); CS_LO(); spi_xfer(SPI2, A7105_TX); CS_HI(); }
/* * 1 - Tx else Rx */ void A7105_SetTxRxMode(enum TXRX_State mode) { if(mode == TX_EN) { A7105_WriteReg(A7105_0B_GPIO1_PIN1, 0x33); A7105_WriteReg(A7105_0C_GPIO2_PIN_II, 0x31); } else if (mode == RX_EN) { A7105_WriteReg(A7105_0B_GPIO1_PIN1, 0x31); A7105_WriteReg(A7105_0C_GPIO2_PIN_II, 0x33); } else { //The A7105 seems to some with a cross-wired power-amp (A7700) //On the XL7105-D03, TX_EN -> RXSW and RX_EN -> TXSW //This means that sleep mode is wired as RX_EN = 1 and TX_EN = 1 //If there are other amps in use, we'll need to fix this A7105_WriteReg(A7105_0B_GPIO1_PIN1, 0x33); A7105_WriteReg(A7105_0C_GPIO2_PIN_II, 0x33); } }
static int hubsan_init() { u8 if_calibration1; u8 vco_calibration0; u8 vco_calibration1; //u8 vco_current; A7105_WriteID(0x55201041); A7105_WriteReg(A7105_01_MODE_CONTROL, 0x63); A7105_WriteReg(A7105_03_FIFOI, 0x0f); A7105_WriteReg(A7105_0D_CLOCK, 0x05); A7105_WriteReg(A7105_0E_DATA_RATE, 0x04); A7105_WriteReg(A7105_15_TX_II, 0x2b); A7105_WriteReg(A7105_18_RX, 0x62); A7105_WriteReg(A7105_19_RX_GAIN_I, 0x80); A7105_WriteReg(A7105_1C_RX_GAIN_IV, 0x0A); A7105_WriteReg(A7105_1F_CODE_I, 0x07); A7105_WriteReg(A7105_20_CODE_II, 0x17); A7105_WriteReg(A7105_29_RX_DEM_TEST_I, 0x47); A7105_Strobe(A7105_STANDBY); //IF Filter Bank Calibration A7105_WriteReg(0x02, 1); //vco_current = A7105_ReadReg(0x02); u32 ms = CLOCK_getms(); CLOCK_ResetWatchdog(); while(CLOCK_getms() - ms < 500) { if(! A7105_ReadReg(0x02)) break; } if (CLOCK_getms() - ms >= 500) { DEBUG_MSG("calibration failed"); return 0; } if_calibration1 = A7105_ReadReg(A7105_22_IF_CALIB_I); A7105_ReadReg(A7105_24_VCO_CURCAL); if(if_calibration1 & A7105_MASK_FBCF) { //Calibration failed...what do we do? return 0; } //VCO Current Calibration //A7105_WriteReg(0x24, 0x13); //Recomended calibration from A7105 Datasheet //VCO Bank Calibration //A7105_WriteReg(0x26, 0x3b); //Recomended limits from A7105 Datasheet //VCO Bank Calibrate channel 0? //Set Channel A7105_WriteReg(A7105_0F_CHANNEL, 0); //VCO Calibration A7105_WriteReg(0x02, 2); ms = CLOCK_getms(); CLOCK_ResetWatchdog(); while(CLOCK_getms() - ms < 500) { if(! A7105_ReadReg(0x02)) break; } if (CLOCK_getms() - ms >= 500) { return 0; } vco_calibration0 = A7105_ReadReg(A7105_25_VCO_SBCAL_I); if (vco_calibration0 & A7105_MASK_VBCF) { //Calibration failed...what do we do? return 0; } //Calibrate channel 0xa0? //Set Channel A7105_WriteReg(A7105_0F_CHANNEL, 0xa0); //VCO Calibration A7105_WriteReg(A7105_02_CALC, 2); ms = CLOCK_getms(); CLOCK_ResetWatchdog(); while(CLOCK_getms() - ms < 500) { if(! A7105_ReadReg(A7105_02_CALC)) break; } if (CLOCK_getms() - ms >= 500) return 0; vco_calibration1 = A7105_ReadReg(A7105_25_VCO_SBCAL_I); if (vco_calibration1 & A7105_MASK_VBCF) { //Calibration failed...what do we do? } //Reset VCO Band calibration //A7105_WriteReg(0x25, 0x08); A7105_SetTxRxMode(TX_EN); A7105_SetPower(Model.tx_power); A7105_Strobe(A7105_STANDBY); return 1; }
void A7105_Reset() { A7105_WriteReg(0x00, 0x00); }