Traxxas TQ 1st gen: try 5
[DIY-Multiprotocol-TX-Module.git] / Multiprotocol / Joysway_a7105.ino
blobabf05a3eae4f968fd452f42147bfda025c61a746
1 /*
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/>.
14  */
16 #if defined(JOYSWAY_A7105_INO)
18 #include "iface_a7105.h"
20 //#define JOYSWAY_FORCE_ID
22 static void __attribute__((unused)) JOYSWAY_send_packet()
24         static uint8_t next_ch = 0x30;
25         
26         //RF frequency
27         if (packet_count == 254)
28         {
29                 packet_count = 0;
30                 A7105_WriteID(0x5475c52a);
31                 rf_ch_num = 0x0a;
32         }
33         else if (packet_count == 2)
34         {
35                 A7105_WriteID(MProtocol_id);
36                 rf_ch_num = 0x30;
37         }
38         else
39         {
40                 if (packet_count & 0x01)
41                         rf_ch_num = 0x30;
42                 else
43                         rf_ch_num = next_ch;
44         }
45         if (! (packet_count & 0x01))
46         {
47                 next_ch++;
48                 if (next_ch >= 0x45)
49                         next_ch = 0x30;
50         }
52         //Payload
53         packet[0] = packet_count == 0 ? 0xdd : 0xff;
54         //ID
55         packet[1] = rx_tx_addr[0];
56         packet[2] = rx_tx_addr[1];
57         packet[3] = rx_tx_addr[2];
58         packet[4] = rx_tx_addr[3];
59         packet[5] = 0x00;
60         //Channels
61         for (uint8_t i = 0; i < 4; i++)
62                 packet[ 6 + (i & 0x01) + ((i & 0x02)<<1)] = convert_channel_16b_limit(i, 0x00, 0xCC);
63         packet[8] = 0x64;
64         packet[9] = 0x64;
65         packet[12] = 0x64;
66         packet[13] = 0x64;
67         packet[14] = packet_count == 0 ? 0x30 : 0xaa;
68         //Check
69         uint8_t value = 0;
70         for (uint8_t i = 0; i < 15; i++)
71                 value += packet[i];
72         packet[15] = value;
74         //Send
75         #if 0
76                 debug("ch=%02X P=",rf_ch_num);
77                 for(uint8_t i=0; i<16; i++)
78                         debug("%02X ", packet[i]);
79                 debugln("");
80         #endif
81         A7105_WriteData(16, rf_ch_num);
82         A7105_SetPower();
83         packet_count++;
86 uint16_t JOYSWAY_callback()
88         #ifdef MULTI_SYNC
89                 telemetry_set_input_sync(6000);
90         #endif
91         #ifndef FORCE_JOYSWAY_TUNING
92                 A7105_AdjustLOBaseFreq(1);
93         #endif
95         JOYSWAY_send_packet();
96         return 6000;
99 void JOYSWAY_init()
101         BIND_DONE;              // not a bind protocol
103         MProtocol_id &= 0x00FFFFFF;
104         MProtocol_id |= 0xF8000000;
105         #ifdef JOYSWAY_FORCE_ID
106                 MProtocol_id = 0xf82dcaa0;
107         #endif
109         set_rx_tx_addr(MProtocol_id);
111         A7105_Init();
112         
113         packet_count = 2;
115 #endif