/* ************************** * By Midelic on RCGroups * ************************** This project is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Multiprotocol is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Multiprotocol. If not, see . */ #if defined(FRSKYX_CC2500_INO) #include "iface_cc2500.h" uint8_t chanskip; uint8_t calData[48][3]; uint8_t channr; uint8_t pass_ = 1 ; uint8_t counter_rst; uint8_t ctr; uint8_t FS_flag=0; // uint8_t ptr[4]={0x01,0x12,0x23,0x30}; //uint8_t ptr[4]={0x00,0x11,0x22,0x33}; const PROGMEM uint8_t hop_data[]={ 0x02, 0xD4, 0xBB, 0xA2, 0x89, 0x70, 0x57, 0x3E, 0x25, 0x0C, 0xDE, 0xC5, 0xAC, 0x93, 0x7A, 0x61, 0x48, 0x2F, 0x16, 0xE8, 0xCF, 0xB6, 0x9D, 0x84, 0x6B, 0x52, 0x39, 0x20, 0x07, 0xD9, 0xC0, 0xA7, 0x8E, 0x75, 0x5C, 0x43, 0x2A, 0x11, 0xE3, 0xCA, 0xB1, 0x98, 0x7F, 0x66, 0x4D, 0x34, 0x1B, 0x00, 0x1D, 0x03 }; uint8_t hop(uint8_t byte) { return pgm_read_byte_near(&hop_data[byte]); } uint16_t initFrSkyX() { while(!chanskip) { randomSeed((uint32_t)analogRead(A6) << 10 | analogRead(A7)); chanskip=random(0xfefefefe)%47; } while((chanskip-ctr)%4) ctr=(ctr+1)%4; counter_rst=(chanskip-ctr)>>2; //for test*************** //rx_tx_addr[3]=0xB3; //rx_tx_addr[2]=0xFD; //************************ frskyX_init(); // if(IS_AUTOBIND_FLAG_on) { state = FRSKY_BIND; initialize_data(1); } else { state = FRSKY_DATA1; initialize_data(0); } return 10000; } uint16_t ReadFrSkyX() { switch(state) { default: set_start(47); CC2500_SetPower(); cc2500_strobe(CC2500_SFRX); // frskyX_build_bind_packet(); cc2500_strobe(CC2500_SIDLE); cc2500_writeFifo(packet, packet[0]+1); state++; return 9000; case FRSKY_BIND_DONE: initialize_data(0); channr=0; BIND_DONE; state++; break; case FRSKY_DATA1: LED_ON; CC2500_SetTxRxMode(TX_EN); set_start(channr); CC2500_SetPower(); cc2500_strobe(CC2500_SFRX); channr = (channr+chanskip)%47; cc2500_strobe(CC2500_SIDLE); cc2500_writeFifo(packet, packet[0]+1); // frskyX_data_frame(); state++; return 5500; case FRSKY_DATA2: CC2500_SetTxRxMode(RX_EN); cc2500_strobe(CC2500_SIDLE); state++; return 200; case FRSKY_DATA3: cc2500_strobe(CC2500_SRX); state++; return 3000; case FRSKY_DATA4: len = cc2500_readReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; if (len &&(len>8) & 0x0F)|(chan_1 << 4))); packet[9+i+2]=crc_Byte(chan_1>>4); } //packet[21]=crc_Byte(0x08);//first packet[21]=crc_Byte(0x80);//??? when received first telemetry frame is changed to 0x80 //packet[21]=crc_Byte(ptr[p]);//??? //p=(p+1)%4;//repeating 4 bytes sequence pattern every 4th frame. pass_=lpass+1; for (uint8_t i=22;i<28;i++) packet[i]=crc_Byte(0); packet[28]=highByte(crc); packet[29]=lowByte(crc); } uint16_t scaleForPXX( uint8_t i ) { //mapped 860,2140(125%) range to 64,1984(PXX values); return (uint16_t)(((Servo_data[i]-PPM_MIN)*3)>>1)+64; } uint8_t crc_Byte( uint8_t byte ) { crc = (crc<<8) ^ pgm_read_word(&CRCTable[((uint8_t)(crc>>8) ^ byte) & 0xFF]); return byte; } #endif