33#include " freertos/event_groups.h"
44#include " Arduino.h"
55
6- #include " esp32-hal-rmt.h"
7-
8- #define XJT_VALID (i ) (i->level0 && !i->level1 && i->duration0 >= 8 && i->duration0 <= 11 )
9-
10-
11- rmt_obj_t * rmt_recv = NULL ;
12-
13- static uint32_t *s_channels;
14-
15- static uint32_t channels[16 ];
16- static uint8_t xjt_flags = 0x0 ;
17- static uint8_t xjt_rxid = 0x0 ;
18-
19-
6+ #include " esp32-hal.h"
7+
8+ //
9+ // Note: This example uses a FrSKY device communication
10+ // using XJT D12 protocol
11+ //
12+ // ; 0 bit = 6us low/10us high
13+ // ; 1 bit = 14us low/10us high
14+ // ;
15+ // ; --------+ +----------+ +----------+
16+ // ; | | | | |
17+ // ; | 0 | | 1 | |
18+ // ; | | | | |
19+ // ; | | | | |
20+ // ; +-------+ +-----------------+ +---------
21+ // ;
22+ // ; | 6us 10us | 14us 10us |
23+ // ; |-------|----------|-----------------|----------|--------
24+ // ; | 16us | 24us |
25+
26+ // Typedef of received frame
27+ //
28+ // ; 0x00 - Sync, 0x7E (sync header ID)
29+ // ; 0x01 - Rx ID, 0x?? (receiver ID number, 0x00-0x??)
30+ // ; 0x02 - Flags 1, 0x?? (used for failsafe and binding)
31+ // ; 0x03 - Flags 2, 0x00 (reserved)
32+ // ; 0x04-0x06, Channels 1/9 and 2/10
33+ // ; 0x07-0x09, Channels 3/11 and 4/12
34+ // ; 0x0A-0x0C, Channels 5/13 and 6/14
35+ // ; 0x0D-0x0F, Channels 7/15 and 8/16
36+ // ; 0x10 - 0x00, always zero
37+ // ; 0x11 - CRC-16 High
38+ // ; 0x12 - CRC-16 Low
39+ // ; 0x13 - Tail, 0x7E (tail ID)
2040typedef union {
2141 struct {
2242 uint8_t head;// 0x7E
@@ -40,6 +60,15 @@ typedef union {
4060 uint8_t buffer[20 ];
4161} xjt_packet_t ;
4262
63+ #define XJT_VALID (i ) (i->level0 && !i->level1 && i->duration0 >= 8 && i->duration0 <= 11 )
64+
65+ rmt_obj_t * rmt_recv = NULL ;
66+
67+ static uint32_t *s_channels;
68+ static uint32_t channels[16 ];
69+ static uint8_t xjt_flags = 0x0 ;
70+ static uint8_t xjt_rxid = 0x0 ;
71+
4372static bool xjtReceiveBit (size_t index, bool bit){
4473 static xjt_packet_t xjt;
4574 static uint8_t xjt_bit_index = 8 ;
@@ -113,7 +142,7 @@ static bool xjtReceiveBit(size_t index, bool bit){
113142
114143void parseRmt (rmt_data_t * items, size_t len, uint32_t * channels){
115144 size_t chan = 0 ;
116- bool valid = false ;
145+ bool valid = true ;
117146 rmt_data_t * it = NULL ;
118147
119148 if (!channels) {
@@ -122,9 +151,9 @@ void parseRmt(rmt_data_t* items, size_t len, uint32_t* channels){
122151 }
123152 s_channels = channels;
124153
125- valid = false ;
126154 it = &items[0 ];
127155 for (size_t i = 0 ; i<len; i++){
156+
128157 if (!valid){
129158 break ;
130159 }
@@ -137,6 +166,9 @@ void parseRmt(rmt_data_t* items, size_t len, uint32_t* channels){
137166 } else {
138167 valid = false ;
139168 }
169+ } else if (!it->duration1 && !it->level1 && it->duration0 >= 5 && it->duration0 <= 8 ) {
170+ valid = xjtReceiveBit (i, false );
171+
140172 }
141173 }
142174}
@@ -158,7 +190,7 @@ void setup()
158190
159191 // Setup 1us tick
160192 float realTick = rmtSetTick (rmt_recv, 1000 );
161- printf (" real tick set to: %fns\n " , realTick);
193+ Serial. printf (" real tick set to: %fns\n " , realTick);
162194
163195 // Ask to start reading
164196 rmtRead (rmt_recv, receive_data);
0 commit comments