Skip to content

Commit cd381f1

Browse files
committed
Add extra XPlus channels to DSM protocol
#1137
1 parent bf38415 commit cd381f1

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

Multiprotocol/DSM_cyrf6936.ino

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
//#define DSM_DEBUG_FWD_PGM
2121
//#define DEBUG_BIND 1
2222

23-
#define CLONE_BIT_MASK 0x20
23+
#define CLONE_BIT_MASK 0x20
24+
#define MODE_11MS_BIT_MASK 0x40
25+
#define MAX_THROW_BIT_MASK 0x80
26+
2427
#define DSM_BIND_CHANNEL 0x0D //13 This can be any odd channel
2528
#define DSM2_SFC_PERIOD 16500
2629

@@ -51,6 +54,12 @@ enum {
5154
DSM_CH2_READ_B,
5255
};
5356

57+
#if defined(DSM_X_PLUS)
58+
#define XP_CH CH13 // X-Plus channel placeholder in frame
59+
uint8_t x_plus_ch = 0; // X-Plus channel currently multiplexing
60+
#else
61+
#define XP_CH 0xff // No Channel
62+
#endif
5463
//
5564
uint8_t ch_map[14];
5665
const uint8_t PROGMEM DSM_ch_map_progmem[][14] = {
@@ -65,7 +74,7 @@ const uint8_t PROGMEM DSM_ch_map_progmem[][14] = {
6574
{1, 5, 2, 3, 6, 0xff, 0xff, 4, 0, 7, 8, 0xff, 0xff, 0xff}, //9ch - Guess
6675
{1, 5, 2, 3, 6, 0xff, 0xff, 4, 0, 7, 8, 9, 0xff, 0xff}, //10ch - Guess
6776
{1, 5, 2, 3, 6, 10, 0xff, 4, 0, 7, 8, 9, 0xff, 0xff}, //11ch - Guess
68-
{1, 5, 2, 4, 6, 10, 0xff, 0, 7, 3, 8, 9 , 11 , 0xff}, //12ch - DX18/DX8G2
77+
{1, 5, 2, 4, 6, 10, XP_CH, 0, 7, 3, 8, 9 , 11 , 0xff}, //12ch - DX18/DX8G2
6978
//11ms for 8..11 channels
7079
{1, 5, 2, 3, 6, 7, 0xff, 1, 5, 2, 4, 0, 0xff, 0xff}, //8ch - DX7
7180
{1, 5, 2, 3, 6, 7, 0xff, 1, 5, 2, 4, 0, 8, 0xff}, //9ch - Guess
@@ -148,7 +157,7 @@ static void __attribute__((unused)) DSM_update_channels()
148157

149158
// Create channel map based on number of channels and refresh rate
150159
uint8_t idx=num_ch-3;
151-
if((option & 0x40) && num_ch>7 && num_ch<12)
160+
if((option & MODE_11MS_BIT_MASK) && num_ch>7 && num_ch<12)
152161
idx+=5; // In 11ms mode change index only for channels 8..11
153162
for(uint8_t i=0;i<14;i++)
154163
ch_map[i]=pgm_read_byte_near(&DSM_ch_map_progmem[idx][i]);
@@ -199,20 +208,23 @@ static void __attribute__((unused)) DSM_build_data_packet(uint8_t upper)
199208
}
200209
#endif
201210

202-
#ifdef DSM_THROTTLE_KILL_CH
211+
#if defined(DSM_THROTTLE_KILL_CH) && not defined(DSM_X_PLUS)
203212
uint16_t kill_ch=Channel_data[DSM_THROTTLE_KILL_CH-1];
204213
#endif
205214
for (uint8_t i = 0; i < 7; i++)
206215
{
207216
uint8_t idx = ch_map[(upper?7:0) + i]; // 1,5,2,3,0,4
208217
uint16_t value = 0xffff;
209-
if((option&0x40) == 0 && num_ch < 8 && upper)
218+
219+
if((option & MODE_11MS_BIT_MASK) == 0 && num_ch < 8 && upper)
210220
idx=0xff; // in 22ms do not transmit upper channels if <8, is it the right method???
211-
if (idx != 0xff)
221+
222+
else
223+
if (idx != 0xff)
212224
{
213225
/* Spektrum own remotes transmit normal values during bind and actually use this (e.g. Nano CP X) to
214226
select the transmitter mode (e.g. computer vs non-computer radio), so always send normal output */
215-
#ifdef DSM_THROTTLE_KILL_CH
227+
#if defined(DSM_THROTTLE_KILL_CH) && not defined(DSM_X_PLUS)
216228
if(idx==CH1 && kill_ch<=604)
217229
{//Activate throttle kill only if channel is throttle and DSM_THROTTLE_KILL_CH below -50%
218230
if(kill_ch<CHANNEL_MIN_100) // restrict val to 0...400
@@ -223,17 +235,38 @@ static void __attribute__((unused)) DSM_build_data_packet(uint8_t upper)
223235
}
224236
else
225237
#endif
238+
{
239+
#if defined(DSM_X_PLUS)
240+
if (idx==XP_CH) { // X-Plus special channel placeholder
241+
idx = XP_CH + x_plus_ch; // Encode CH13-CH16 instead
242+
}
243+
#endif
226244
#ifdef DSM_MAX_THROW
227245
value=Channel_data[CH_TAER[idx]]; // -100%..+100% => 1024..1976us and -125%..+125% => 904..2096us based on Redcon 6 channel DSM2 RX
228246
#else
229-
if(option & 0x80)
247+
if(option & MAX_THROW_BIT_MASK)
230248
value=Channel_data[CH_TAER[idx]]; // -100%..+100% => 1024..1976us and -125%..+125% => 904..2096us based on Redcon 6 channel DSM2 RX
231249
else
232250
value=convert_channel_16b_nolimit(CH_TAER[idx],0x156,0x6AA,false); // -100%..+100% => 1100..1900us and -125%..+125% => 1000..2000us based on a DX8 G2 dump
233251
#endif
234-
if(bits==10) value>>=1;
235-
value |= (upper && i==0 ? 0x8000 : 0) | (idx << bits);
236-
}
252+
}
253+
254+
#if defined(DSM_X_PLUS)
255+
if (idx >= XP_CH) { // X-Plus Channel
256+
// Multiplexing 4 chanels on the same frame channel placeholder for channel 13 (ID=12) over time (Refresh cycle 88ms)
257+
// CH13-16 lower frame, and Ch17-20 upper. We only do lower right now, since MM cannot handle more than 16ch
258+
// Channel value is 9 bits, and upper 2 bits is the X-Plus channel (CH13..CH16).
259+
value >>= 2; // Convert to 9 bits
260+
value |= (XP_CH << 11) | (x_plus_ch << 9); // CH13 (4bits), XPlus Ch (2 bits), Value (9 bits)
261+
x_plus_ch = (x_plus_ch + 1) % 4; // only 0..3
262+
} else
263+
#endif
264+
{ // Regular channel
265+
if(bits==10) value>>=1;
266+
value |= (upper && i==0 ? 0x8000 : 0) | (idx << bits);
267+
}
268+
}
269+
237270
packet[i*2+2] = value >> 8;
238271
packet[i*2+3] = value;
239272
}

Multiprotocol/Multiprotocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define VERSION_MAJOR 1
2020
#define VERSION_MINOR 3
2121
#define VERSION_REVISION 4
22-
#define VERSION_PATCH_LEVEL 52
22+
#define VERSION_PATCH_LEVEL 53
2323

2424
#define MODE_SERIAL 0
2525

Multiprotocol/_Config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,17 @@
296296
//#define DSM_MAX_THROW
297297
//Some models (X-Vert, Blade 230S...) require a special value to instant stop the motor(s).
298298
// You can disable this feature by adding "//" on the line below. You have to specify which channel (14 by default) will be used to kill the throttle channel.
299+
299300
// If the channel 14 is above -50% the throttle is untouched but if it is between -50% and -100%, the throttle output will be forced between -100% and -150%.
300301
// For example, a value of -80% applied on channel 14 will instantly kill the motors on the X-Vert.
301302
#define DSM_THROTTLE_KILL_CH 14
302303

303304
//Enable DSM Forward Programming
304305
#define DSM_FWD_PGM
305306

307+
//Enable X-Plus channels, Ch13-16.. if Enabled, will ignore the DSM_THROTTLE_KILL_CH feature
308+
#define DSM_X_PLUS
309+
306310
/**************************/
307311
/*** FAILSAFE SETTINGS ***/
308312
/**************************/

0 commit comments

Comments
 (0)