2 This project is free software: you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation, either version 3 of the License, or
5 (at your option) any later version.
7 Multiprotocol is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
16 #if defined(SCORPIO_CYRF6936_INO)
18 #include "iface_cyrf6936.h"
20 //#define SCORPIO_FORCE_ID
22 #define SCORPIO_PACKET_PERIOD 12000
23 #define SCORPIO_PACKETCH_PERIOD 2580
24 #define SCORPIO_BINDPAYLOAD_SIZE 8
25 #define SCORPIO_PAYLOAD_SIZE 10
26 #define SCORPIO_BIND_COUNT 1000
27 #define SCORPIO_RF_NUM_CHANNELS 3
29 static uint16_t __attribute__((unused)) SCORPIO_send_packet()
31 if(IS_BIND_IN_PROGRESS)
33 packet[0] = 0x88; //FIXME: What is this?
34 packet[1] = 0x55; //FIXME: What is this?
35 packet[2] = crc; //CRC_low for normal packets
36 packet[3] = crc >> 8; //CRC_high for normal packets
37 packet[4] = hopping_frequency[0]; //RF freq 0
38 packet[5] = hopping_frequency[1]; //RF freq 1
39 packet[6] = hopping_frequency[2]; //RF freq 2
40 packet[7] = 0x80; //FIXME: What is this?
42 CYRF_WriteDataPacketLen(packet, SCORPIO_BINDPAYLOAD_SIZE);
43 return SCORPIO_PACKET_PERIOD;
45 CYRF_ConfigRFChannel(hopping_frequency[hopping_frequency_no]);
46 CYRF_SetPower(0x28); //Update power
47 delayMicroseconds(180); //Frequency settle time
48 packet[0] = hopping_frequency[0];
49 packet[1] = hopping_frequency[1];
50 packet[2] = hopping_frequency[2];
51 packet[3] = convert_channel_8b(THROTTLE);
52 packet[4] = 0xFF - convert_channel_8b(RUDDER);
53 packet[5] = convert_channel_8b(ELEVATOR);
54 packet[6] = convert_channel_8b(AILERON);
55 packet[7] = 0x55; //FIXME: What is this?
56 packet[8] = 0x00; //FIXME: What is this?
57 packet[9] = 0x00; //FIXME: What is this?
58 CYRF_WriteDataPacketLen(packet, SCORPIO_PAYLOAD_SIZE);
59 hopping_frequency_no++;
60 if(hopping_frequency_no >= SCORPIO_RF_NUM_CHANNELS)
62 hopping_frequency_no = 0;
63 return SCORPIO_PACKET_PERIOD - 2*SCORPIO_PACKETCH_PERIOD;
65 return SCORPIO_PACKETCH_PERIOD;
68 static void __attribute__((unused)) SCORPIO_RF_init()
70 /* Initialise CYRF chip */
71 CYRF_WriteRegister(CYRF_32_AUTO_CAL_TIME, 0x3C);
72 CYRF_WriteRegister(CYRF_35_AUTOCAL_OFFSET, 0x14);
73 CYRF_WriteRegister(CYRF_1B_TX_OFFSET_LSB, 0x55);
74 CYRF_WriteRegister(CYRF_1C_TX_OFFSET_MSB, 0x05);
75 CYRF_WriteRegister(CYRF_10_FRAMING_CFG, 0xE8);
77 CYRF_SetTxRxMode(TX_EN);
80 static void __attribute__((unused)) SCORPIO_TX_init()
82 calc_fh_channels(3); // select 3 frequencies between 2 and 77. FIXME: Could they be choosen on the spot finding empty frequencies?
83 crc = (rx_tx_addr[0] ^ rx_tx_addr[1] ^ RX_num) + ((rx_tx_addr[2] ^ rx_tx_addr[3] ^ RX_num) << 8);
85 #ifdef SCORPIO_FORCE_ID
87 hopping_frequency[0] = 0x26;
88 hopping_frequency[1] = 0x49;
89 hopping_frequency[2] = 0x2E;
91 //debugln("C0:%02X, C1:%02X, C2:%02X, CRC:%04X", hopping_frequency[0], hopping_frequency[1], hopping_frequency[2], crc);
92 CYRF_ConfigRFChannel(hopping_frequency[0]); // Use first RF channel for bind
95 uint16_t SCORPIO_callback()
98 telemetry_set_input_sync(SCORPIO_PACKET_PERIOD);
101 if(--bind_counter==0)
103 CYRF_ConfigCRCSeed(crc);
106 return SCORPIO_send_packet();
113 if(IS_BIND_IN_PROGRESS)
115 bind_counter = SCORPIO_BIND_COUNT;
116 CYRF_ConfigCRCSeed(0x0001);
120 hopping_frequency_no = 0;