Skip to content

Commit

Permalink
New protocol XK2 for the XK A160S
Browse files Browse the repository at this point in the history
  • Loading branch information
pascallanger committed Jun 7, 2024
1 parent 7a7b4b2 commit c6ff0e2
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 4 deletions.
1 change: 1 addition & 0 deletions Lua_scripts/MultiChan.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
62,0,XK,X450,1,FMode,TakeOf,Emerg,3D_6G,Pict,Video
62,1,XK,X420,1,FMode,TakeOf,Emerg,3D_6G,Pict,Video,Flip,Light
62,2,XK,Cars,0,FMode,TakeOf,Emerg,3D_6G,Pict,Video,Flip,Light
99,0,XK2,X4,0,Rate,Mode,Hover
8,0,YD717,Std,1,Flip,Light,Pict,Video,HLess
8,1,YD717,SkyWlkr,1,Flip,Light,Pict,Video,HLess
8,2,YD717,Simax4,1,Flip,Light,Pict,Video,HLess
Expand Down
3 changes: 2 additions & 1 deletion Multiprotocol/Multi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@
95,BlueFly
96,BumbleB
97,SGF22
98,Kyosho3
98,Kyosho3
99,XK2
4 changes: 4 additions & 0 deletions Multiprotocol/Multi_Protos.ino
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const char STR_FX[] ="FX";
const char STR_BAYANG_RX[] ="BayanRX";
const char STR_PELIKAN[] ="Pelikan";
const char STR_XK[] ="XK";
const char STR_XK2[] ="XK2";
const char STR_XN297DUMP[] ="XN297DP";
const char STR_FRSKYR9[] ="FrSkyR9";
const char STR_PROPEL[] ="Propel";
Expand Down Expand Up @@ -495,6 +496,9 @@ const mm_protocol_definition multi_protocols[] = {
#if defined(XK_CCNRF_INO)
{PROTO_XK, STR_XK, STR_SUBTYPE_XK, 3, OPTION_RFTUNE, 0, 0, SW_NRF, XK_init, XK_callback },
#endif
#if defined(XK2_CCNRF_INO)
{PROTO_XK2, STR_XK2, NO_SUBTYPE, 0, OPTION_RFTUNE, 0, 0, SW_NRF, XK2_init, XK2_callback },
#endif
#if defined(XN297DUMP_NRF24L01_INO)
{PROTO_XN297DUMP, STR_XN297DUMP, STR_SUBTYPE_XN297DUMP, 6, OPTION_RFCHAN, 0, 0, SW_NRF, XN297Dump_init, XN297Dump_callback },
#endif
Expand Down
4 changes: 2 additions & 2 deletions Multiprotocol/Multiprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define VERSION_MAJOR 1
#define VERSION_MINOR 3
#define VERSION_REVISION 4
#define VERSION_PATCH_LEVEL 9
#define VERSION_PATCH_LEVEL 10

#define MODE_SERIAL 0

Expand Down Expand Up @@ -126,7 +126,7 @@ enum PROTOCOLS
PROTO_BUMBLEB = 96, // =>CC2500 & NRF24L01
PROTO_SGF22 = 97, // =>NRF24L01
PROTO_KYOSHO3 = 98, // =>CYRF6936

PROTO_XK2 = 99, // =>CC2500 & NRF24L01

PROTO_NANORF = 126, // =>NRF24L01
PROTO_TEST = 127, // =>CC2500
Expand Down
1 change: 1 addition & 0 deletions Multiprotocol/Validate.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
#undef SLT_CCNRF_INO
#undef V911S_CCNRF_INO
#undef XK_CCNRF_INO
#undef XK2_CCNRF_INO
#endif
#if not defined(DSM_CYRF6936_INO)
#undef LOSI_CYRF6936_INO
Expand Down
201 changes: 201 additions & 0 deletions Multiprotocol/XK2_ccnrf.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
// Compatible with XK TX X4 and model A160S.

#if defined(XK2_CCNRF_INO)

#include "iface_xn297.h"

#define FORCE_XK2_ID

#define XK2_RF_BIND_CHANNEL 71
#define XK2_PAYLOAD_SIZE 9
#define XK2_PACKET_PERIOD 4911
#define XK2_RF_NUM_CHANNELS 4

enum {
XK2_BIND1,
XK2_BIND2,
XK2_DATA_PREP,
XK2_DATA
};

static void __attribute__((unused)) XK2_send_packet()
{
static uint8_t trim_ch=0;

if(IS_BIND_IN_PROGRESS)
{
packet[0] = 0x9D;
//TXID
memcpy(&packet[1], rx_tx_addr, 3);
//RXID
//memcpy(&packet[4], rx_id , 3);
//Unknown
packet[7] = 0x00;
//Checksum seed
packet[8] = 0xC0; //Constant?
}
else
{
XN297_Hopping(hopping_frequency_no);
hopping_frequency_no++;
hopping_frequency_no &= 0x03;
//Channels
packet[0] = convert_channel_16b_limit(AILERON ,0x00,0x64); //Aileron
packet[1] = convert_channel_16b_limit(ELEVATOR,0x00,0x64); //Elevator
packet[2] = convert_channel_16b_limit(THROTTLE,0x00,0x64); //Throttle
packet[3] = convert_channel_16b_limit(RUDDER ,0x00,0x64); //Rudder
//Center the trims
trim_ch++;
if(trim_ch > 2) trim_ch = 0;
packet[4] = 0x20 + 0x40 * trim_ch; //Trims are A=01..20..3F/E=41..60..7F/R=81..A0..BF, E0 appears when telemetry is received, C1 when p[6] changes from 00->08, C0 when p[6] changes from 08->00
if(trim_ch == 2) //Drive rudder trim since otherwise there is no control...
{
packet[4] = 0x80 + (convert_channel_8b(RUDDER)>>2);
if(packet[4] <= 0x81) packet[4] = 0x81;
}
//Flags
packet[5] = GET_FLAG(CH5_SW, 0x01) //Rate
| GET_FLAG(CH6_SW, 0x08) //Mode
| GET_FLAG(CH7_SW, 0x20); //Hover
//Telemetry not received=00, Telemetry received=01 but sometimes switch to 1 even if telemetry is not there...
packet[6] = 0x00;
//Unknown
packet[7] = 0x5A; //Constant?
//Checksum seed
packet[8] = 0x7F; //Constant?
}
//Checksum
for(uint8_t i=0; i<XK2_PAYLOAD_SIZE-1; i++)
packet[8] += packet[i];

// Send
XN297_SetPower();
XN297_SetTxRxMode(TX_EN);
XN297_WritePayload(packet, XK2_PAYLOAD_SIZE);
#if 0
debug("P");
for(uint8_t i=0; i<XK2_PAYLOAD_SIZE; i++)
debug(" %02X",packet[i]);
debugln();
#endif
}

static void __attribute__((unused)) XK2_RF_init()
{
XN297_Configure(XN297_CRCEN, XN297_SCRAMBLED, XN297_250K);

XN297_SetTXAddr((uint8_t*)"\xcc\xcc\xcc\xcc\xcc", 5);
XN297_SetRXAddr((uint8_t*)"\xcc\xcc\xcc\xcc\xcc", XK2_PAYLOAD_SIZE);

XN297_HoppingCalib(XK2_RF_NUM_CHANNELS);
XN297_RFChannel(XK2_RF_BIND_CHANNEL);
}

static void __attribute__((unused)) XK2_initialize_txid()
{
#ifdef FORCE_XK2_ID
rx_tx_addr[0] = 0x66;
rx_tx_addr[1] = 0x4F;
rx_tx_addr[2] = 0x47;
for(uint8_t i=0;i<XK2_RF_NUM_CHANNELS;i++)
hopping_frequency[i] = 65 + i*4; //65=0x41, 69=0x45, 73=0x49, 77=0x4D
#endif
rx_tx_addr[3] = 0xCC;
rx_tx_addr[4] = 0xCC;
}

uint16_t XK2_callback()
{
switch(phase)
{
case XK2_BIND1:
// switch to RX mode
XN297_SetTxRxMode(TXRX_OFF);
XN297_SetTxRxMode(RX_EN);
phase++;
return 5000;
case XK2_BIND2:
if(XN297_IsRX())
{
XN297_ReadPayload(packet, XK2_PAYLOAD_SIZE);
#if 0
debug("RX");
for(uint8_t i=0; i<XK2_PAYLOAD_SIZE; i++)
debug(" %02X",packet[i]);
debugln("");
#endif
crc8 = 0xBF;
for(uint8_t i=0; i<XK2_PAYLOAD_SIZE-1; i++)
crc8 += packet[i];
//phase = XK2_BIND1;
//return 500;
if(crc8 != packet[8])
{
phase = XK2_BIND1;
return 1000;
}
if(packet[0] == 0x9B)
phase++;
else
{
XN297_SetTxRxMode(TXRX_OFF);
XN297_SetTxRxMode(TX_EN);
bind_counter = 10;
phase = XK2_DATA;
}
}
return 1000;
case XK2_DATA_PREP:
XN297_SetTxRxMode(TXRX_OFF);
XN297_SetTxRxMode(TX_EN);
XN297_SetTXAddr(rx_tx_addr, 5);
BIND_DONE;
case XK2_DATA:
#ifdef MULTI_SYNC
telemetry_set_input_sync(XK2_PACKET_PERIOD);
#endif
if(bind_counter)
{
bind_counter--;
if(bind_counter == 0)
{
phase = XK2_DATA_PREP;
//phase = XK2_BIND1;
}
}
XK2_send_packet();
break;
}
return XK2_PACKET_PERIOD;
}

void XK2_init()
{
//BIND_IN_PROGRESS; // autobind protocol
XK2_initialize_txid();
XK2_RF_init();

if(IS_BIND_IN_PROGRESS)
phase = XK2_BIND1;
else
phase = XK2_DATA_PREP;
bind_counter = 0;
hopping_frequency_no = 0;
}

#endif

3 changes: 3 additions & 0 deletions Multiprotocol/_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
#define SLT_CCNRF_INO
#define V911S_CCNRF_INO
#define XK_CCNRF_INO
#define XK2_CCNRF_INO

//The protocols below need a SX1276 to be installed
#define FRSKYR9_SX1276_INO
Expand Down Expand Up @@ -857,6 +858,8 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= {
X450
X420
XK_CARS
PROTO_XK2
NONE
PROTO_YD717
YD717
SKYWLKR
Expand Down
21 changes: 20 additions & 1 deletion Protocols_Details.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ CFlie|38|CFlie||||||||NRF24L01|
[WFLY2](Protocols_Details.md#WFLY2---79)|79|RF20x||||||||A7105|
[WK2x01](Protocols_Details.md#WK2X01---30)|30|WK2801|WK2401|W6_5_1|W6_6_1|W6_HEL|W6_HEL_I|||CYRF6936|
[XERALL](Protocols_Details.md#XERALL---91)|91|Tank||||||||NRF24L01|XN297
[XK](Protocols_Details.md#XK---62)|62|X450|X420|Cars||||||NRF24L01|XN297
[XK](Protocols_Details.md#XK---62)|62|X450|X420|Cars||||||NRF24L011&CC2500|XN297
[XK2](Protocols_Details.md#XK2---99)|99|X4||||||||NRF24L01&CC2500|XN297
[YD717](Protocols_Details.md#YD717---8)|8|YD717|SKYWLKR|SYMAX4|XINXUN|NIHUI||||NRF24L01|
[ZSX](Protocols_Details.md#ZSX---52)|52|280||||||||NRF24L01|XN297
* "*" Sub Protocols designated by * suffix are using a XN297L@250kbps which will be emulated by default with the NRF24L01. If option (freq tune) is diffrent from 0, the CC2500 module (if installed) will be used instead. Each specific sub protocol has a more detailed explanation.
Expand Down Expand Up @@ -1474,6 +1475,24 @@ A|E|T|R|FLIP|LIGHT
### Sub_protocol Cars - *2*
Models: WLtoys cars 284131/284161/284010/124016/124017/144010 and Eachine EAT14

## XK2 - *99*

### Sub_protocol X4 - *0*
Transmitter: XK X4, model: XK A160S

**Only 1 ID and might only work with my plane**

If a CC2500 is installed it will be used for this sub protocol. Option in this case is used for fine frequency tuning like any CC2500 protocols so check the [Frequency Tuning page](/docs/Frequency_Tuning.md).

If only a NRF24L01 is installed then this sub protocol might be problematic because it is using the xn297L emulation with a transmission speed of 250kbps which doesn't work very well with every NRF24L01, this is an hardware issue with the authenticity and accuracy of the components.

CH1|CH2|CH3|CH4|CH5|CH6|CH7
---|---|---|---|---|---|---
A|E|T|R|Rate|Mode|Hover

The plane does not need to be bound each time if it is powered on **after** the radio/protocol is on.

The rudder trim is driven from the rudder channel to increase the range (Original TX rudder has no range once the motor has been turned on...).

***
# NRF24L01 RF Module
Expand Down

0 comments on commit c6ff0e2

Please sign in to comment.