Exemplo n.º 1
0
void init_a7105(void) {
	uint8_t i;
	uint8_t if_calibration1;
	uint8_t vco_calibration0;
	uint8_t vco_calibration1;
	lib_timers_delaymilliseconds(10);	//wait 10ms for A7105 wakeup
		A7105_Reset();	//reset A7105
		A7105_WriteID(0x5475c52A);	//A7105 id
		A7105_ReadID((uint8_t*)&aid);
//		Serial.print(aid[0], HEX);
//		Serial.print(aid[1], HEX);
//		Serial.print(aid[2], HEX);
//		Serial.print(aid[3], HEX);
//		Serial.println("fin id");
		for (i = 0; i < 0x33; i++) {
			if (A7105_regs[i] != 0xff)
				A7105_WriteRegister(i, A7105_regs[i]);

		}
		A7105_Strobe(A7105_STANDBY);	//stand-by
		A7105_WriteRegister(0x02, 0x01);
		while (A7105_ReadRegister(0x02)) {
			if_calibration1 = A7105_ReadRegister(0x22);
			if (if_calibration1 & 0x10) {	//do nothing
			}
		}

		A7105_WriteRegister(0x24, 0x13);
		A7105_WriteRegister(0x26, 0x3b);
		A7105_WriteRegister(0x0F, 0x00);	//channel 0
		A7105_WriteRegister(0x02, 0x02);
		while (A7105_ReadRegister(0x02)) {
			vco_calibration0 = A7105_ReadRegister(0x25);
			if (vco_calibration0 & 0x08) {	//do nothing
			}
		}

		A7105_WriteRegister(0x0F, 0xA0);
		A7105_WriteRegister(0x02, 0x02);
		while (A7105_ReadRegister(0x02)) {
			vco_calibration1 = A7105_ReadRegister(0x25);
			if (vco_calibration1 & 0x08) {	//do nothing
			}
		}

		A7105_WriteRegister(0x25, 0x08);
		A7105_Strobe(A7105_STANDBY);	//stand-by
}
Exemplo n.º 2
0
void A7105_ReadData(u8 *dpbuffer, u8 len)
{
    A7105_Strobe(A7105_RST_RDPTR);
    for(int i = 0; i < len; i++)
        dpbuffer[i] = A7105_ReadReg(0x05);
    return;
}
Exemplo n.º 3
0
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;

}
Exemplo n.º 4
0
//BIND_TX
uint32_t bind_Flysky() {
	unsigned long timeout_timer=lib_timers_starttimer();
	uint32_t _id=0;
	// set channel 0;
	A7105_Strobe(0xA0);
	A7105_WriteRegister(A7105_0F_PLL_I,00);
	A7105_Strobe(A7105_RX);
	while(!_id && lib_timers_gettimermicroseconds(timeout_timer) < BIND_READ_TOGGLE_TIMEOUT)
	{
	if( lib_timers_gettimermicroseconds(0) % 524288 > 262144)
            leds_set(LED2 | LED4);
        else
            leds_set(LED1 | LED3);
				
	char mode = A7105_ReadRegister(A7105_00_MODE);

	if(mode & A7105_MODE_TRER_MASK || mode & (1<<6) ||  mode & ( 1<<5) )	
		{
		A7105_Strobe(A7105_RST_RDPTR); 
		A7105_Strobe(A7105_RX);
		continue;
		}
	A7105_ReadPayload((uint8_t*)&packet, sizeof(packet)); 
  A7105_Strobe(A7105_RST_RDPTR);
	if ( packet[0] == 170 )  // 170
			{
				//set found tx		
			  _id=( ( packet[1] << 0 |  packet[2] <<8 |  packet[3] << 16 | packet[4]<<24 ) );
			}
	 A7105_Strobe(A7105_RX);		
	}
	return _id;
}
Exemplo n.º 5
0
int _readrx(void) {
	for (int i=0;i<21;i++) packet[i]=0;
	channel=tx_channels[chanrow][chancol]-1-chanoffset;
	A7105_Strobe(A7105_STANDBY);
	A7105_Strobe(A7105_RST_RDPTR);
	A7105_WriteRegister(0x0F, channel);
	A7105_Strobe(A7105_RX);
	chancol = (chancol + 1) % 16;
	unsigned long pause;
	uint8_t x;
	pause=lib_timers_starttimer();
	while(1){
		if (lib_timers_gettimermicroseconds(pause) > 2000) {
//			Red_LED_OFF;
			chancol = (chancol + 1) % 16;
			channel=tx_channels[chanrow][chancol]-1-chanoffset;
			break;
		}
		if(A7105_ReadRegister(A7105_00_MODE) & A7105_MODE_TRER_MASK){
			continue;
		}
		x=A7105_ReadRegister(0x00);
		if (!(bitRead(x,5)==0)&& !(bitRead(x,6)==0)){
			continue;
		}
		Read_Packet();
		if (convert2id(packet[1],packet[2],packet[3],packet[4])!=usersettings.flysky_id) {
//			Serial.println("bad id");
			continue;
		}


		decodepacket();

		// reset the failsafe timer
		global.failsafetimer = lib_timers_starttimer();
		return 1;
	}
	return 0;
}
Exemplo n.º 6
0
void A7105_ReadData(u8 *dpbuffer, u8 len)
{
    A7105_Strobe(0xF0); //A7105_RST_RDPTR
    for(int i = 0; i < len; i++)
        dpbuffer[i] = A7105_ReadReg(0x05);
/*
    CS_LO();
    spi_xfer(SPI2, 0x40 | 0x05);
    spi_disable(SPI2);
    spi_set_bidirectional_receive_only_mode(SPI2);
    spi_enable(SPI2);
    int i;
    for(i = 0; i < 10; i++)
       ;
    spi_disable(SPI2);
    for(i = 0; i < len; i++)
        dpbuffer[i] = spi_read(SPI2);
    CS_HI();
    spi_set_unidirectional_mode(SPI2);
    spi_enable(SPI2);
*/
    return;
}
Exemplo n.º 7
0
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;
}