1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

Input Configuration: support all 18 S.Bus input channels

This commit is contained in:
Oleg Semyonov 2011-09-11 22:04:03 +03:00
parent 7b3056d10f
commit f5369f9338
3 changed files with 32 additions and 18 deletions

View File

@ -34,8 +34,6 @@
#if defined(PIOS_INCLUDE_SBUS)
/* Global Variables */
/* Provide a RCVR driver */
static int32_t PIOS_SBUS_Get(uint32_t rcvr_id, uint8_t channel);
@ -65,21 +63,17 @@ static void reset_channels(void)
/**
* unroll_channels() function computes channel_data[] from received_data[]
* For efficiency it unrolls first 8 channels without loops. If other
* 8 channels are needed they can be unrolled using the same code
* starting from s[11] instead of s[0]. Two extra digital channels are
* accessible using (s[22] & SBUS_FLAG_DGx) logical expressions.
* For efficiency it unrolls first 8 channels without loops and does the
* same for other 8 channels. Also 2 discrete channels will be set.
*/
static void unroll_channels(void)
{
uint8_t *s = received_data;
uint16_t *d = channel_data;
#if (SBUS_NUMBER_OF_CHANNELS != 8)
#error Current S.Bus code unrolls only first 8 channels
#endif
#define F(v,s) ((v) >> s) & 0x7ff
/* unroll channels 1-8 */
*d++ = F(s[0] | s[1] << 8, 0);
*d++ = F(s[1] | s[2] << 8, 3);
*d++ = F(s[2] | s[3] << 8 | s[4] << 16, 6);
@ -88,6 +82,20 @@ static void unroll_channels(void)
*d++ = F(s[6] | s[7] << 8 | s[8] << 16, 7);
*d++ = F(s[8] | s[9] << 8, 2);
*d++ = F(s[9] | s[10] << 8, 5);
/* unroll channels 9-16 */
*d++ = F(s[11] | s[12] << 8, 0);
*d++ = F(s[12] | s[13] << 8, 3);
*d++ = F(s[13] | s[14] << 8 | s[15] << 16, 6);
*d++ = F(s[15] | s[16] << 8, 1);
*d++ = F(s[16] | s[17] << 8, 4);
*d++ = F(s[17] | s[18] << 8 | s[19] << 16, 7);
*d++ = F(s[19] | s[20] << 8, 2);
*d++ = F(s[20] | s[21] << 8, 5);
/* unroll discrete channels 17 and 18 */
*d++ = (s[22] & SBUS_FLAG_DC1) ? SBUS_VALUE_MAX : SBUS_VALUE_MIN;
*d++ = (s[22] & SBUS_FLAG_DC2) ? SBUS_VALUE_MAX : SBUS_VALUE_MIN;
}
/**

View File

@ -44,8 +44,8 @@
* 1 byte - 0x0f (start of frame byte)
* 22 bytes - channel data (11 bit/channel, 16 channels, LSB first)
* 1 byte - bit flags:
* 0x01 - digital channel 1,
* 0x02 - digital channel 2,
* 0x01 - discrete channel 1,
* 0x02 - discrete channel 2,
* 0x04 - lost frame flag,
* 0x08 - failsafe flag,
* 0xf0 - reserved
@ -54,16 +54,20 @@
#define SBUS_FRAME_LENGTH (1+22+1+1)
#define SBUS_SOF_BYTE 0x0f
#define SBUS_EOF_BYTE 0x00
#define SBUS_FLAG_DG1 0x01
#define SBUS_FLAG_DG2 0x02
#define SBUS_FLAG_DC1 0x01
#define SBUS_FLAG_DC2 0x02
#define SBUS_FLAG_FL 0x04
#define SBUS_FLAG_FS 0x08
/*
* S.Bus protocol provides up to 16 analog and 2 digital channels.
* Only 8 channels are currently supported by the OpenPilot.
* S.Bus protocol provides 16 proportional and 2 discrete channels.
* Do not change unless driver code is updated accordingly.
*/
#define SBUS_NUMBER_OF_CHANNELS 8
#define SBUS_NUMBER_OF_CHANNELS (16 + 2)
/* Discrete channels represented as bits, provide values for them */
#define SBUS_VALUE_MIN 352
#define SBUS_VALUE_MAX 1696
/*
* S.Bus configuration programmable invertor

View File

@ -85,11 +85,13 @@ void inputChannelForm::groupUpdated()
count = 8; // Need to make this 6 for CC
break;
case ManualControlSettings::CHANNELGROUPS_PPM:
case ManualControlSettings::CHANNELGROUPS_SBUS:
case ManualControlSettings::CHANNELGROUPS_SPEKTRUM1:
case ManualControlSettings::CHANNELGROUPS_SPEKTRUM2:
count = 12;
break;
case ManualControlSettings::CHANNELGROUPS_SBUS:
count = 18;
break;
case ManualControlSettings::CHANNELGROUPS_GCS:
count = 5;
case ManualControlSettings::CHANNELGROUPS_NONE: