Skip to content

Commit 5b83b48

Browse files
CopilotMRC3742
andauthored
Add CG022 NRF24 proof-of-possibility protocol
Agent-Logs-Url: https://github.com/MRC3742/DIY-Multiprotocol-TX-Module/sessions/debddf00-846e-461b-872f-49e12a685bad Co-authored-by: MRC3742 <26642502+MRC3742@users.noreply.github.com>
1 parent 234407a commit 5b83b48

File tree

7 files changed

+146
-2
lines changed

7 files changed

+146
-2
lines changed

Multiprotocol/CG022_nrf24l01.ino

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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.
6+
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.
11+
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+
*/
15+
16+
#if defined(CG022_NRF24L01_INO)
17+
18+
#include "iface_nrf24l01.h"
19+
20+
#define CG022_PACKET_PERIOD 2315
21+
#define CG022_BIND_COUNT 166
22+
#define CG022_PACKET_SIZE 10
23+
#define CG022_RF_CHANNEL_COUNT 8
24+
25+
static const uint8_t PROGMEM CG022_hop[] = { 0x0A, 0x32, 0x14, 0x3C, 0x1E, 0x46, 0x00, 0x28 };
26+
static const uint8_t CG022_addr[] = { 0x5A, 0x5A, 0x00, 0x33 };
27+
28+
static uint8_t CG022_scale_channel(uint8_t channel)
29+
{
30+
return (convert_channel_8b(channel) + 2) >> 2;
31+
}
32+
33+
static void __attribute__((unused)) CG022_set_channel()
34+
{
35+
NRF24L01_WriteReg(NRF24L01_05_RF_CH, pgm_read_byte_near(&CG022_hop[hopping_frequency_no]));
36+
hopping_frequency_no++;
37+
if (hopping_frequency_no >= CG022_RF_CHANNEL_COUNT)
38+
hopping_frequency_no = 0;
39+
}
40+
41+
static void __attribute__((unused)) CG022_build_bind_packet()
42+
{
43+
uint8_t id = rx_tx_addr[3] & 0x3F;
44+
45+
packet[0] = 0x0A;
46+
packet[1] = id;
47+
packet[2] = rx_tx_addr[0];
48+
packet[3] = rx_tx_addr[1];
49+
packet[4] = rx_tx_addr[2];
50+
packet[5] = 0x06;
51+
packet[6] = 0xAB;
52+
packet[7] = 0xFC;
53+
packet[8] = 0xAD;
54+
packet[9] = 0x00;
55+
}
56+
57+
static void __attribute__((unused)) CG022_build_data_packet()
58+
{
59+
uint8_t id = rx_tx_addr[3] & 0x3F;
60+
61+
packet[0] = 0x0A;
62+
packet[1] = id;
63+
packet[2] = CG022_scale_channel(THROTTLE);
64+
packet[3] = CG022_scale_channel(ELEVATOR);
65+
packet[4] = CG022_scale_channel(RUDDER);
66+
packet[5] = CG022_scale_channel(AILERON);
67+
packet[6] = 0x20 | GET_FLAG(CH6_SW, 0x80);
68+
packet[7] = 0x20 | GET_FLAG(CH5_SW, 0x40) | GET_FLAG(CH7_SW, 0x80);
69+
packet[8] = 0x20;
70+
packet[9] = (packet[2] + packet[3] + packet[4] + packet[5] + packet[6] + packet[7] + packet[8]) & 0xFF;
71+
}
72+
73+
static void __attribute__((unused)) CG022_send_packet()
74+
{
75+
if (IS_BIND_IN_PROGRESS)
76+
CG022_build_bind_packet();
77+
else
78+
CG022_build_data_packet();
79+
80+
CG022_set_channel();
81+
NRF24L01_WritePayload(packet, CG022_PACKET_SIZE);
82+
NRF24L01_SetPower();
83+
}
84+
85+
static void __attribute__((unused)) CG022_RF_init()
86+
{
87+
NRF24L01_Initialize();
88+
NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x02);
89+
NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, (uint8_t *)CG022_addr, sizeof(CG022_addr));
90+
NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, (uint8_t *)CG022_addr, sizeof(CG022_addr));
91+
NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, CG022_PACKET_SIZE);
92+
NRF24L01_SetBitrate(NRF24L01_BR_1M);
93+
NRF24L01_WriteReg(NRF24L01_00_CONFIG, _BV(NRF24L01_00_PWR_UP));
94+
}
95+
96+
uint16_t CG022_callback()
97+
{
98+
#ifdef MULTI_SYNC
99+
telemetry_set_input_sync(CG022_PACKET_PERIOD);
100+
#endif
101+
if (bind_counter)
102+
{
103+
bind_counter--;
104+
if (bind_counter == 0)
105+
BIND_DONE;
106+
}
107+
CG022_send_packet();
108+
return CG022_PACKET_PERIOD;
109+
}
110+
111+
void CG022_init(void)
112+
{
113+
BIND_IN_PROGRESS; // autobind protocol
114+
bind_counter = CG022_BIND_COUNT;
115+
hopping_frequency_no = 0;
116+
CG022_RF_init();
117+
packet_period = CG022_PACKET_PERIOD;
118+
}
119+
120+
#endif

Multiprotocol/Multi.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,6 @@
100100
102,JIABAILE,STD,GYRO
101101
103,H36
102102
104,KAMTOM
103-
105,Shenqi2
104-
106,WL91x
103+
105,Shenqi2
104+
106,WL91x
105+
109,CG022,AO-SENMA

Multiprotocol/Multi_Protos.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const char STR_SYMAX[] ="SymaX";
2727
const char STR_SLT[] ="SLT";
2828
const char STR_CX10[] ="CX10";
2929
const char STR_CG023[] ="CG023";
30+
const char STR_CG022[] ="CG022";
3031
const char STR_BAYANG[] ="Bayang";
3132
const char STR_FRSKYL[] ="FrSky L";
3233
const char STR_FRSKYX[] ="FrSky X";
@@ -143,6 +144,7 @@ const char STR_SUBTYPE_SYMAX[] = "\x03""Std""X5C";
143144
const char STR_SUBTYPE_SLT[] = "\x07""V1_6ch\0""V2_8ch\0""Q100\0 ""Q200\0 ""MR100\0 ""V1_4ch\0""RF_SIM\0""SLT6_Tx";
144145
const char STR_SUBTYPE_CX10[] = "\x07""Green\0 ""Blue\0 ""DM007\0 ""-\0 ""JC3015a""JC3015b""MK33041";
145146
const char STR_SUBTYPE_CG023[] = "\x05""Std\0 ""YD829";
147+
const char STR_SUBTYPE_CG022[] = "\x08""AO-SENMA";
146148
const char STR_SUBTYPE_BAYANG[] = "\x07""Std\0 ""H8S3D\0 ""X16 AH\0""IRDrone""DHD D4\0""QX100\0 ";
147149
const char STR_SUBTYPE_MT99[] = "\x06""MT99\0 ""H7\0 ""YZ\0 ""LS\0 ""FY805\0""A180\0 ""Dragon""F949G\0";
148150
const char STR_SUBTYPE_MT992[] = "\x04""PA18""SU35";
@@ -261,6 +263,9 @@ const mm_protocol_definition multi_protocols[] = {
261263
#if defined(CFLIE_NRF24L01_INO)
262264
{PROTO_CFLIE, STR_CFLIE, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, SW_NRF, CFLIE_init, CFLIE_callback }, // review protocol
263265
#endif
266+
#if defined(CG022_NRF24L01_INO)
267+
{PROTO_CG022, STR_CG022, STR_SUBTYPE_CG022, 1, OPTION_NONE, 0, 0, SW_NRF, CG022_init, CG022_callback },
268+
#endif
264269
#if defined(CG023_NRF24L01_INO)
265270
{PROTO_CG023, STR_CG023, STR_SUBTYPE_CG023, 2, OPTION_NONE, 0, 0, SW_NRF, CG023_init, CG023_callback },
266271
#endif

Multiprotocol/Multiprotocol.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ enum PROTOCOLS
136136
PROTO_WL91X = 106, // =>CC2500 & NRF24L01
137137
PROTO_WPL = 107, // =>NRF24L01
138138
PROTO_ARES = 108, // =>CC2500
139+
PROTO_CG022 = 109, // =>NRF24L01
139140

140141
PROTO_NANORF = 126, // =>NRF24L01
141142
PROTO_TEST = 127, // =>CC2500
@@ -242,6 +243,10 @@ enum CG023
242243
CG023 = 0,
243244
YD829 = 1,
244245
};
246+
enum CG022
247+
{
248+
AO_SEN_MA = 0,
249+
};
245250
enum BAYANG
246251
{
247252
BAYANG = 0,

Multiprotocol/Validate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@
315315
#undef BUGSMINI_NRF24L01_INO
316316
#undef CABELL_NRF24L01_INO
317317
#undef CFLIE_NRF24L01_INO
318+
#undef CG022_NRF24L01_INO
318319
#undef CG023_NRF24L01_INO
319320
#undef CX10_NRF24L01_INO
320321
#undef DM002_NRF24L01_INO
@@ -434,6 +435,7 @@
434435
#undef BUGSMINI_NRF24L01_INO
435436
#undef CABELL_NRF24L01_INO
436437
#undef CFLIE_NRF24L01_INO
438+
#undef CG022_NRF24L01_INO
437439
#undef CG023_NRF24L01_INO
438440
#undef CX10_NRF24L01_INO
439441
#undef DM002_NRF24L01_INO

Multiprotocol/_Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
#define BUGSMINI_NRF24L01_INO
232232
#define CABELL_NRF24L01_INO
233233
#define CFLIE_NRF24L01_INO
234+
#define CG022_NRF24L01_INO
234235
#define CG023_NRF24L01_INO
235236
#define CX10_NRF24L01_INO //Include Q2X2 protocol
236237
#define DM002_NRF24L01_INO
@@ -598,6 +599,8 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= {
598599
CABELL_UNBIND
599600
PROTO_CFLIE
600601
NONE
602+
PROTO_CG022
603+
AO_SEN_MA
601604
PROTO_CG023
602605
CG023
603606
YD829

Protocols_Details.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Protocol Name|Build|Protocol Number|Sub_Proto 0|Sub_Proto 1|Sub_Proto 2|Sub_Prot
7272
[BugsMini](Protocols_Details.md#BUGSMINI---42)|AIR|42|BUGSMINI|BUGS3H|||||||NRF24L01|XN297
7373
[Cabell](Protocols_Details.md#Cabell---34)||34|Cabell_V3|C_TELEM|-|-|-|-|F_SAFE|UNBIND|NRF24L01|
7474
CFlie|AIR|38|CFlie||||||||NRF24L01|
75+
[CG022](Protocols_Details.md#CG022---109)|AIR|109|AO-SENMA||||||||NRF24L01|LT8910 (test)
7576
[CG023](Protocols_Details.md#CG023---13)|AIR|13|CG023|YD829|||||||NRF24L01|XN297
7677
[Corona](Protocols_Details.md#CORONA---37)|AIR/SFC|37|COR_V1|COR_V2|FD_V3||||||CC2500|
7778
[CX10](Protocols_Details.md#CX10---12)|AIR|12|GREEN|BLUE|DM007|-|J3015_1|J3015_2|MK33041||NRF24L01|XN297
@@ -1756,6 +1757,13 @@ Stores failsafe values in the RX. The channel values are set when the sub-proto
17561757
### Sub_protocol CABELL_UNBIND - *7*
17571758
The receiver bound to the model is un-bound. This happens immediately when the sub-protocol is set to 7.
17581759

1760+
## CG022 - *109*
1761+
Proof-of-possibility NRF24L01 transmission test for the CG022 AO-SEN-MA (LT8910) protocol.
1762+
1763+
CH1|CH2|CH3|CH4|CH5|CH6|CH7
1764+
---|---|---|---|---|---|---
1765+
A|E|T|R|FLIP|LED|HEADLESS
1766+
17591767
## CG023 - *13*
17601768
Autobind protocol
17611769

0 commit comments

Comments
 (0)