diff --git a/Multiprotocol/ASSAN_nrf24l01.ino b/Multiprotocol/ASSAN_nrf24l01.ino new file mode 100644 index 0000000..d91d2bf --- /dev/null +++ b/Multiprotocol/ASSAN_nrf24l01.ino @@ -0,0 +1,174 @@ +/* + 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(ASSAN_NRF24L01_INO) + +#include "iface_nrf24l01.h" + +#define ASSAN_PACKET_SIZE 20 +#define ASSAN_RF_BIND_CHANNEL 0x03 +#define ASSAN_ADDRESS_LENGTH 4 + +enum { + ASSAN_BIND0=0, + ASSAN_BIND1, + ASSAN_BIND2, + ASSAN_DATA0, + ASSAN_DATA1, + ASSAN_DATA2, + ASSAN_DATA3, + ASSAN_DATA4, + ASSAN_DATA5 +}; + +void ASSAN_init() +{ + NRF24L01_Initialize(); + NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x02); // 4 bytes rx/tx address + NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, (uint8_t *)"\x80\x80\x80\xB8", ASSAN_ADDRESS_LENGTH); // Bind address + NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, (uint8_t *)"\x80\x80\x80\xB8", ASSAN_ADDRESS_LENGTH); // Bind address + NRF24L01_FlushTx(); + NRF24L01_FlushRx(); + NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit + NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x00); // No Auto Acknowldgement on all data pipes + NRF24L01_WriteReg(NRF24L01_02_EN_RXADDR, 0x01); // Enable data pipe 0 only + NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, ASSAN_PACKET_SIZE); + NRF24L01_SetPower(); +} + +void ASSAN_send_packet() +{ + uint16_t temp; + for(uint8_t i=0;i<10;i++) + { + temp=Servo_data[i]<<3; + packet[2*i]=temp>>8; + packet[2*i+1]=temp; + } + NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit + NRF24L01_FlushTx(); + NRF24L01_WritePayload(packet, ASSAN_PACKET_SIZE); +} + +uint16_t ASSAN_callback() +{ + switch (phase) + { + // Bind + case ASSAN_BIND0: + //Config RX @1M + NRF24L01_WriteReg(NRF24L01_05_RF_CH, ASSAN_RF_BIND_CHANNEL); + NRF24L01_SetBitrate(NRF24L01_BR_1M); // 1Mbps + NRF24L01_SetTxRxMode(RX_EN); + phase++; + case ASSAN_BIND1: + //Wait for RX to send the frames + if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & BV(NRF24L01_07_RX_DR)) + { //Something has been received + NRF24L01_ReadPayload(packet, ASSAN_PACKET_SIZE); + if(packet[19]==0x13) + { //Last packet received + phase++; + //Switch to TX + NRF24L01_SetTxRxMode(TXRX_OFF); + NRF24L01_SetTxRxMode(TX_EN); + //Prepare packet + memset(packet,0x05,ASSAN_PACKET_SIZE-5); + packet[15]=0x99; + for(uint8_t i=0;i<4;i++) + packet[16+i]=packet[23-i]; + packet_count=0; + delay(260); + return 10000; // Wait 270ms in total... + } + } + return 1000; + case ASSAN_BIND2: + // Send 20 packets + packet_count++; + if(packet_count==20) + packet[15]=0x13; // different value for last packet + NRF24L01_WritePayload(packet, ASSAN_PACKET_SIZE); + if(packet_count==20) + { + phase++; + delay(2165); + } + return 22520; + // Normal operation + case ASSAN_DATA0: + // Bind Done + BIND_DONE; + NRF24L01_SetBitrate(NRF24L01_BR_250K); // 250Kbps + NRF24L01_SetTxRxMode(TXRX_OFF); + NRF24L01_SetTxRxMode(TX_EN); + case ASSAN_DATA1: + case ASSAN_DATA4: + // Change ID and RF channel + NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR,packet+20+4*hopping_frequency_no, ASSAN_ADDRESS_LENGTH); + NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no]); + hopping_frequency_no^=0x01; + NRF24L01_SetPower(); + phase=ASSAN_DATA2; + return 2000; + case ASSAN_DATA2: + case ASSAN_DATA3: + ASSAN_send_packet(); + phase++; // DATA 3 or 4 + return 5000; + } + return 0; +} + +static void __attribute__((unused)) ASSAN_initialize_txid() +{ +/* //Renaud TXID with Freq=36 and alternate freq 67 or 68 or 69 or 70 or 71 or 73 or 74 or 75 or 78 and may be more... + packet[23]=0x22; + packet[22]=0x37; + packet[21]=0xFA; + packet[20]=0x53; */ + // Using packet[20..23] to store the ID1 and packet[24..27] to store the ID2 + uint8_t freq=0; + for(uint8_t i=0;i<4;i++) + { + uint8_t temp=rx_tx_addr[0]; + packet[i+20]=temp; + packet[i+24]=temp+1; + freq+=temp; + } + + // Main frequency + freq=((freq%25)+2)<<1; + if(freq&0x02) freq|=0x01; + hopping_frequency[0]=freq; + // Alternate frequency + hopping_frequency[1]=freq*2-6; + hopping_frequency[1]+=analogRead(A6)%12; // Add some random to the second channel +} + +uint16_t initASSAN() +{ + ASSAN_initialize_txid(); + ASSAN_init(); + hopping_frequency_no = 0; + + if(IS_AUTOBIND_FLAG_on) + phase=ASSAN_BIND0; + else + phase=ASSAN_DATA0; + return 1000; +} + +#endif \ No newline at end of file diff --git a/Multiprotocol/CYRF6936_SPI.ino b/Multiprotocol/CYRF6936_SPI.ino index f381990..24a5f30 100644 --- a/Multiprotocol/CYRF6936_SPI.ino +++ b/Multiprotocol/CYRF6936_SPI.ino @@ -58,17 +58,17 @@ uint8_t CYRF_ReadRegister(uint8_t address) uint8_t CYRF_Reset() { - CYRF_WriteRegister(CYRF_1D_MODE_OVERRIDE, 0x01);//software reset - delayMicroseconds(200);// - // RS_HI; - // delayMicroseconds(100); - // RS_LO; - // delayMicroseconds(100); - CYRF_WriteRegister(CYRF_0C_XTAL_CTRL, 0xC0); //Enable XOUT as GPIO - CYRF_WriteRegister(CYRF_0D_IO_CFG, 0x04); //Enable PACTL as GPIO + CYRF_RST_HI; //Hardware reset + delayMicroseconds(100); + CYRF_RST_LO; + delayMicroseconds(100); +/* CYRF_WriteRegister(CYRF_1D_MODE_OVERRIDE, 0x01); //Software reset + delayMicroseconds(200); +*/ CYRF_WriteRegister(CYRF_0C_XTAL_CTRL, 0xC0); //Enable XOUT as GPIO + CYRF_WriteRegister(CYRF_0D_IO_CFG, 0x04); //Enable PACTL as GPIO CYRF_SetTxRxMode(TXRX_OFF); - //Verify the CYRD chip is responding - return (CYRF_ReadRegister(CYRF_10_FRAMING_CFG) == 0xa5);//return if reset + //Verify the CYRF chip is responding + return (CYRF_ReadRegister(CYRF_10_FRAMING_CFG) == 0xa5); } /* diff --git a/Multiprotocol/FQ777_nrf24l01.ino b/Multiprotocol/FQ777_nrf24l01.ino index c5e920b..369812f 100644 --- a/Multiprotocol/FQ777_nrf24l01.ino +++ b/Multiprotocol/FQ777_nrf24l01.ino @@ -32,7 +32,7 @@ enum { }; const uint8_t ssv_xor[] = {0x80,0x44,0x64,0x75,0x6C,0x71,0x2A,0x36,0x7C,0xF1,0x6E,0x52,0x9,0x9D,0x1F,0x78,0x3F,0xE1,0xEE,0x16,0x6D,0xE8,0x73,0x9,0x15,0xD7,0x92,0xE7,0x3,0xBA}; -const uint8_t FQ777_bind_addr [] = {0xe7,0xe7,0xe7,0xe7,0x67}; +uint8_t FQ777_bind_addr [] = {0xe7,0xe7,0xe7,0xe7,0x67}; static void __attribute__((unused)) ssv_pack_dpl(uint8_t addr[], uint8_t pid, uint8_t* len, uint8_t* payload, uint8_t* packed_payload) { diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index f9ffdbb..9ecfddf 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -51,7 +51,8 @@ enum PROTOCOLS MODE_FY326=20, // =>NRF24L01 MODE_SFHSS=21, // =>CC2500 MODE_J6PRO=22, // =>CYRF6936 - MODE_FQ777=23 // =>NRF24L01 + MODE_FQ777=23, // =>NRF24L01 + MODE_ASSAN=24 // =>NRF24L01 }; enum Flysky @@ -238,6 +239,8 @@ struct PPM_Parameters #else #define CYRF_CSN_on PORTB |= _BV(1) //D9 #define CYRF_CSN_off PORTB &= ~_BV(1) //D9 +#define CYRF_RST_HI PORTC|=_BV(5) //reset cyrf +#define CYRF_RST_LO PORTB &= ~_BV(5) // #endif // #ifdef XMEGA @@ -248,9 +251,6 @@ struct PPM_Parameters #define SDO_0 (PIND & (1< 0x80 1=Bind/0=No AutoBindBit=> 0x40 1=Yes /0=No RangeCheck=> 0x20 1=Yes /0=No diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 882541a..c8c6170 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -584,6 +584,12 @@ static void protocol_init() next_callback=initFQ777(); remote_callback = FQ777_callback; break; +#endif +#if defined(ASSAN_NRF24L01_INO) + case MODE_ASSAN: + next_callback=initASSAN(); + remote_callback = ASSAN_callback; + break; #endif } @@ -674,7 +680,7 @@ static void module_reset() case MODE_J6PRO: CYRF_Reset(); break; - default: // MODE_HISKY, MODE_V2X2, MODE_YD717, MODE_KN, MODE_SYMAX, MODE_SLT, MODE_CX10, MODE_CG023, MODE_BAYANG, MODE_ESKY, MODE_MT99XX, MODE_MJXQ, MODE_SHENQI, MODE_FY326, MODE_FQ777 + default: // MODE_HISKY, MODE_V2X2, MODE_YD717, MODE_KN, MODE_SYMAX, MODE_SLT, MODE_CX10, MODE_CG023, MODE_BAYANG, MODE_ESKY, MODE_MT99XX, MODE_MJXQ, MODE_SHENQI, MODE_FY326, MODE_FQ777, MODE_ASSAN NRF24L01_Reset(); break; } diff --git a/Multiprotocol/SHENQI_nrf24l01.ino b/Multiprotocol/SHENQI_nrf24l01.ino index c829f7e..293e30b 100644 --- a/Multiprotocol/SHENQI_nrf24l01.ino +++ b/Multiprotocol/SHENQI_nrf24l01.ino @@ -1,3 +1,18 @@ +/* + 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(SHENQI_NRF24L01_INO) #include "iface_nrf24l01.h" diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 449829c..52f8cc9 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -65,6 +65,7 @@ #define SHENQI_NRF24L01_INO #define FY326_NRF24L01_INO #define FQ777_NRF24L01_INO + #define ASSAN_NRF24L01_INO #endif /**************************/ @@ -185,6 +186,8 @@ const PPM_Parameters PPM_prot[15]= { NONE MODE_FQ777 NONE + MODE_ASSAN + NONE RX_Num value between 0 and 15