1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

rcvr: support multiple simultaneous receivers

Now also supports multiple instances of the Spektrum driver.
These are configured as Spektrum1 and Spektrum2.
This commit is contained in:
Stacey Sheldon 2011-07-30 15:04:24 -04:00
parent 829b8b83f6
commit 06cdeb7b61
10 changed files with 413 additions and 342 deletions

View File

@ -863,8 +863,12 @@ void PIOS_I2C_main_adapter_er_irq_handler(void)
#if defined(PIOS_INCLUDE_RCVR) #if defined(PIOS_INCLUDE_RCVR)
#include "pios_rcvr_priv.h" #include "pios_rcvr_priv.h"
struct pios_rcvr_channel_map pios_rcvr_channel_to_id_map[PIOS_RCVR_MAX_CHANNELS]; /* One slot per selectable receiver group.
uint32_t pios_rcvr_max_channel; * eg. PWM, PPM, GCS, SPEKTRUM1, SPEKTRUM2, SBUS
* NOTE: No slot in this map for NONE.
*/
uint32_t pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE];
#endif /* PIOS_INCLUDE_RCVR */ #endif /* PIOS_INCLUDE_RCVR */
#if defined(PIOS_INCLUDE_USB_HID) #if defined(PIOS_INCLUDE_USB_HID)
@ -984,7 +988,8 @@ void PIOS_Board_Init(void) {
} }
#endif /* PIOS_INCLUDE_GPS */ #endif /* PIOS_INCLUDE_GPS */
break; break;
case HWSETTINGS_CC_MAINPORT_SPEKTRUM: case HWSETTINGS_CC_MAINPORT_SPEKTRUM1:
case HWSETTINGS_CC_MAINPORT_SPEKTRUM2:
#if defined(PIOS_INCLUDE_SPEKTRUM) #if defined(PIOS_INCLUDE_SPEKTRUM)
{ {
uint32_t pios_usart_spektrum_id; uint32_t pios_usart_spektrum_id;
@ -996,6 +1001,16 @@ void PIOS_Board_Init(void) {
if (PIOS_SPEKTRUM_Init(&pios_spektrum_id, &pios_spektrum_main_cfg, &pios_usart_com_driver, pios_usart_spektrum_id, false)) { if (PIOS_SPEKTRUM_Init(&pios_spektrum_id, &pios_spektrum_main_cfg, &pios_usart_com_driver, pios_usart_spektrum_id, false)) {
PIOS_Assert(0); PIOS_Assert(0);
} }
uint32_t pios_spektrum_rcvr_id;
if (PIOS_RCVR_Init(&pios_spektrum_rcvr_id, &pios_spektrum_rcvr_driver, pios_spektrum_id)) {
PIOS_Assert(0);
}
if (hwsettings_cc_mainport == HWSETTINGS_CC_MAINPORT_SPEKTRUM1) {
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_SPEKTRUM1] = pios_spektrum_rcvr_id;
} else {
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_SPEKTRUM2] = pios_spektrum_rcvr_id;
}
} }
#endif /* PIOS_INCLUDE_SPEKTRUM */ #endif /* PIOS_INCLUDE_SPEKTRUM */
break; break;
@ -1046,7 +1061,8 @@ void PIOS_Board_Init(void) {
} }
#endif /* PIOS_INCLUDE_GPS */ #endif /* PIOS_INCLUDE_GPS */
break; break;
case HWSETTINGS_CC_FLEXIPORT_SPEKTRUM: case HWSETTINGS_CC_FLEXIPORT_SPEKTRUM1:
case HWSETTINGS_CC_FLEXIPORT_SPEKTRUM2:
#if defined(PIOS_INCLUDE_SPEKTRUM) #if defined(PIOS_INCLUDE_SPEKTRUM)
{ {
uint32_t pios_usart_spektrum_id; uint32_t pios_usart_spektrum_id;
@ -1058,6 +1074,16 @@ void PIOS_Board_Init(void) {
if (PIOS_SPEKTRUM_Init(&pios_spektrum_id, &pios_spektrum_flexi_cfg, &pios_usart_com_driver, pios_usart_spektrum_id, false)) { if (PIOS_SPEKTRUM_Init(&pios_spektrum_id, &pios_spektrum_flexi_cfg, &pios_usart_com_driver, pios_usart_spektrum_id, false)) {
PIOS_Assert(0); PIOS_Assert(0);
} }
uint32_t pios_spektrum_rcvr_id;
if (PIOS_RCVR_Init(&pios_spektrum_rcvr_id, &pios_spektrum_rcvr_driver, pios_spektrum_id)) {
PIOS_Assert(0);
}
if (hwsettings_cc_flexiport == HWSETTINGS_CC_FLEXIPORT_SPEKTRUM1) {
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_SPEKTRUM1] = pios_spektrum_rcvr_id;
} else {
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_SPEKTRUM2] = pios_spektrum_rcvr_id;
}
} }
#endif /* PIOS_INCLUDE_SPEKTRUM */ #endif /* PIOS_INCLUDE_SPEKTRUM */
break; break;
@ -1074,95 +1100,43 @@ void PIOS_Board_Init(void) {
break; break;
} }
/* Configure the selected receiver */ /* Configure the rcvr port */
uint8_t manualcontrolsettings_inputmode; uint8_t hwsettings_rcvrport;
ManualControlSettingsInputModeGet(&manualcontrolsettings_inputmode); HwSettingsRcvrPortGet(&hwsettings_rcvrport);
switch (manualcontrolsettings_inputmode) { switch (hwsettings_rcvrport) {
case MANUALCONTROLSETTINGS_INPUTMODE_PWM: case HWSETTINGS_RCVRPORT_DISABLED:
break;
case HWSETTINGS_RCVRPORT_PWM:
#if defined(PIOS_INCLUDE_PWM) #if defined(PIOS_INCLUDE_PWM)
PIOS_PWM_Init(); PIOS_PWM_Init();
uint32_t pios_pwm_rcvr_id; uint32_t pios_pwm_rcvr_id;
if (PIOS_RCVR_Init(&pios_pwm_rcvr_id, &pios_pwm_rcvr_driver, 0)) { if (PIOS_RCVR_Init(&pios_pwm_rcvr_id, &pios_pwm_rcvr_driver, 0)) {
PIOS_Assert(0); PIOS_Assert(0);
} }
for (uint8_t i = 0; pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_PWM] = pios_pwm_rcvr_id;
i < PIOS_PWM_NUM_INPUTS && pios_rcvr_max_channel < NELEMENTS(pios_rcvr_channel_to_id_map);
i++) {
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].id = pios_pwm_rcvr_id;
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].channel = i;
pios_rcvr_max_channel++;
}
#endif /* PIOS_INCLUDE_PWM */ #endif /* PIOS_INCLUDE_PWM */
break; break;
case MANUALCONTROLSETTINGS_INPUTMODE_PPM: case HWSETTINGS_RCVRPORT_PPM:
#if defined(PIOS_INCLUDE_PPM) #if defined(PIOS_INCLUDE_PPM)
PIOS_PPM_Init(); PIOS_PPM_Init();
uint32_t pios_ppm_rcvr_id; uint32_t pios_ppm_rcvr_id;
if (PIOS_RCVR_Init(&pios_ppm_rcvr_id, &pios_ppm_rcvr_driver, 0)) { if (PIOS_RCVR_Init(&pios_ppm_rcvr_id, &pios_ppm_rcvr_driver, 0)) {
PIOS_Assert(0); PIOS_Assert(0);
} }
for (uint8_t i = 0; pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_PPM] = pios_ppm_rcvr_id;
i < PIOS_PPM_NUM_INPUTS && pios_rcvr_max_channel < NELEMENTS(pios_rcvr_channel_to_id_map);
i++) {
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].id = pios_ppm_rcvr_id;
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].channel = i;
pios_rcvr_max_channel++;
}
#endif /* PIOS_INCLUDE_PPM */ #endif /* PIOS_INCLUDE_PPM */
break; break;
case MANUALCONTROLSETTINGS_INPUTMODE_SPEKTRUM:
#if defined(PIOS_INCLUDE_SPEKTRUM)
if (hwsettings_cc_mainport == HWSETTINGS_CC_MAINPORT_SPEKTRUM ||
hwsettings_cc_flexiport == HWSETTINGS_CC_FLEXIPORT_SPEKTRUM) {
uint32_t pios_spektrum_rcvr_id;
if (PIOS_RCVR_Init(&pios_spektrum_rcvr_id, &pios_spektrum_rcvr_driver, 0)) {
PIOS_Assert(0);
} }
for (uint8_t i = 0;
i < PIOS_SPEKTRUM_NUM_INPUTS && pios_rcvr_max_channel < NELEMENTS(pios_rcvr_channel_to_id_map);
i++) {
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].id = pios_spektrum_rcvr_id;
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].channel = i;
pios_rcvr_max_channel++;
}
}
#endif /* PIOS_INCLUDE_SPEKTRUM */
break;
case MANUALCONTROLSETTINGS_INPUTMODE_SBUS:
#if defined(PIOS_INCLUDE_SBUS)
if (hwsettings_cc_mainport == HWSETTINGS_CC_MAINPORT_SBUS) {
uint32_t pios_sbus_rcvr_id;
if (PIOS_RCVR_Init(&pios_sbus_rcvr_id, &pios_sbus_rcvr_driver, 0)) {
PIOS_Assert(0);
}
for (uint8_t i = 0;
i < SBUS_NUMBER_OF_CHANNELS && pios_rcvr_max_channel < NELEMENTS(pios_rcvr_channel_to_id_map);
i++) {
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].id = pios_sbus_rcvr_id;
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].channel = i;
pios_rcvr_max_channel++;
}
}
#endif /* PIOS_INCLUDE_SBUS */
break;
case MANUALCONTROLSETTINGS_INPUTMODE_GCS:
#if defined(PIOS_INCLUDE_GCSRCVR) #if defined(PIOS_INCLUDE_GCSRCVR)
PIOS_GCSRCVR_Init(); PIOS_GCSRCVR_Init();
uint32_t pios_gcsrcvr_rcvr_id; uint32_t pios_gcsrcvr_rcvr_id;
if (PIOS_RCVR_Init(&pios_gcsrcvr_rcvr_id, &pios_gcsrcvr_rcvr_driver, 0)) { if (PIOS_RCVR_Init(&pios_gcsrcvr_rcvr_id, &pios_gcsrcvr_rcvr_driver, 0)) {
PIOS_Assert(0); PIOS_Assert(0);
} }
for (uint8_t i = 0; pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_GCS] = pios_gcsrcvr_rcvr_id;
i < GCSRECEIVER_CHANNEL_NUMELEM && pios_rcvr_max_channel < NELEMENTS(pios_rcvr_channel_to_id_map);
i++) {
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].id = pios_gcsrcvr_rcvr_id;
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].channel = i;
pios_rcvr_max_channel++;
}
#endif /* PIOS_INCLUDE_GCSRCVR */ #endif /* PIOS_INCLUDE_GCSRCVR */
break;
}
/* Remap AFIO pin */ /* Remap AFIO pin */
GPIO_PinRemapConfig( GPIO_Remap_SWJ_NoJTRST, ENABLE); GPIO_PinRemapConfig( GPIO_Remap_SWJ_NoJTRST, ENABLE);

View File

@ -141,7 +141,7 @@ static void manualControlTask(void *parameters)
// Main task loop // Main task loop
lastSysTime = xTaskGetTickCount(); lastSysTime = xTaskGetTickCount();
while (1) { while (1) {
float scaledChannel[MANUALCONTROLCOMMAND_CHANNEL_NUMELEM]; float scaledChannel[MANUALCONTROLSETTINGS_CHANNELGROUPS_NUMELEM];
// Wait until next update // Wait until next update
vTaskDelayUntil(&lastSysTime, UPDATE_PERIOD_MS / portTICK_RATE_MS); vTaskDelayUntil(&lastSysTime, UPDATE_PERIOD_MS / portTICK_RATE_MS);
@ -165,22 +165,28 @@ static void manualControlTask(void *parameters)
if (!ManualControlCommandReadOnly(&cmd)) { if (!ManualControlCommandReadOnly(&cmd)) {
// Read channel values in us // Read channel values in us
for (int n = 0; n < MANUALCONTROLCOMMAND_CHANNEL_NUMELEM; ++n) { for (uint8_t n = 0;
if (pios_rcvr_channel_to_id_map[n].id) { n < MANUALCONTROLSETTINGS_CHANNELGROUPS_NUMELEM && n < MANUALCONTROLCOMMAND_CHANNEL_NUMELEM;
cmd.Channel[n] = PIOS_RCVR_Read(pios_rcvr_channel_to_id_map[n].id, ++n) {
pios_rcvr_channel_to_id_map[n].channel); extern uint32_t pios_rcvr_group_map[];
} else {
if (settings.ChannelGroups[n] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
cmd.Channel[n] = -1; cmd.Channel[n] = -1;
} else if (!pios_rcvr_group_map[settings.ChannelGroups[n]]) {
cmd.Channel[n] = -2;
} else {
cmd.Channel[n] = PIOS_RCVR_Read(pios_rcvr_group_map[settings.ChannelGroups[n]],
settings.ChannelNumber[n]);
} }
scaledChannel[n] = scaleChannel(cmd.Channel[n], settings.ChannelMax[n], settings.ChannelMin[n], settings.ChannelNeutral[n]); scaledChannel[n] = scaleChannel(cmd.Channel[n], settings.ChannelMax[n], settings.ChannelMin[n], settings.ChannelNeutral[n]);
} }
// Check settings, if error raise alarm // Check settings, if error raise alarm
if (settings.Roll >= MANUALCONTROLSETTINGS_ROLL_NONE || if (settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
settings.Pitch >= MANUALCONTROLSETTINGS_PITCH_NONE || settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
settings.Yaw >= MANUALCONTROLSETTINGS_YAW_NONE || settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
settings.Throttle >= MANUALCONTROLSETTINGS_THROTTLE_NONE || settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
settings.FlightMode >= MANUALCONTROLSETTINGS_FLIGHTMODE_NONE) { settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL); AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL);
cmd.Connected = MANUALCONTROLCOMMAND_CONNECTED_FALSE; cmd.Connected = MANUALCONTROLCOMMAND_CONNECTED_FALSE;
ManualControlCommandSet(&cmd); ManualControlCommandSet(&cmd);
@ -188,10 +194,10 @@ static void manualControlTask(void *parameters)
} }
// decide if we have valid manual input or not // decide if we have valid manual input or not
bool valid_input_detected = validInputRange(settings.ChannelMin[settings.Throttle], settings.ChannelMax[settings.Throttle], cmd.Channel[settings.Throttle]) && bool valid_input_detected = validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE]) &&
validInputRange(settings.ChannelMin[settings.Roll], settings.ChannelMax[settings.Roll], cmd.Channel[settings.Roll]) && validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL]) &&
validInputRange(settings.ChannelMin[settings.Yaw], settings.ChannelMax[settings.Yaw], cmd.Channel[settings.Yaw]) && validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW]) &&
validInputRange(settings.ChannelMin[settings.Pitch], settings.ChannelMax[settings.Pitch], cmd.Channel[settings.Pitch]); validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH]);
// Implement hysteresis loop on connection status // Implement hysteresis loop on connection status
if (valid_input_detected && (++connected_count > 10)) { if (valid_input_detected && (++connected_count > 10)) {
@ -218,28 +224,31 @@ static void manualControlTask(void *parameters)
AlarmsClear(SYSTEMALARMS_ALARM_MANUALCONTROL); AlarmsClear(SYSTEMALARMS_ALARM_MANUALCONTROL);
// Scale channels to -1 -> +1 range // Scale channels to -1 -> +1 range
cmd.Roll = scaledChannel[settings.Roll]; cmd.Roll = scaledChannel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL];
cmd.Pitch = scaledChannel[settings.Pitch]; cmd.Pitch = scaledChannel[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH];
cmd.Yaw = scaledChannel[settings.Yaw]; cmd.Yaw = scaledChannel[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW];
cmd.Throttle = scaledChannel[settings.Throttle]; cmd.Throttle = scaledChannel[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE];
flightMode = scaledChannel[settings.FlightMode]; flightMode = scaledChannel[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE];
AccessoryDesiredData accessory; AccessoryDesiredData accessory;
// Set Accessory 0 // Set Accessory 0
if(settings.Accessory0 != MANUALCONTROLSETTINGS_ACCESSORY0_NONE) { if (settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_ACCESSORY0] !=
accessory.AccessoryVal = scaledChannel[settings.Accessory0]; MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
accessory.AccessoryVal = scaledChannel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ACCESSORY0];
if(AccessoryDesiredInstSet(0, &accessory) != 0) if(AccessoryDesiredInstSet(0, &accessory) != 0)
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING); AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING);
} }
// Set Accessory 1 // Set Accessory 1
if(settings.Accessory1 != MANUALCONTROLSETTINGS_ACCESSORY1_NONE) { if (settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_ACCESSORY1] !=
accessory.AccessoryVal = scaledChannel[settings.Accessory1]; MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
accessory.AccessoryVal = scaledChannel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ACCESSORY1];
if(AccessoryDesiredInstSet(1, &accessory) != 0) if(AccessoryDesiredInstSet(1, &accessory) != 0)
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING); AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING);
} }
// Set Accsesory 2 // Set Accessory 2
if(settings.Accessory2 != MANUALCONTROLSETTINGS_ACCESSORY2_NONE) { if (settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_ACCESSORY2] !=
accessory.AccessoryVal = scaledChannel[settings.Accessory2]; MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
accessory.AccessoryVal = scaledChannel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ACCESSORY2];
if(AccessoryDesiredInstSet(2, &accessory) != 0) if(AccessoryDesiredInstSet(2, &accessory) != 0)
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING); AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING);
} }

View File

@ -30,6 +30,7 @@
#include <pios.h> #include <pios.h>
#include <openpilot.h> #include <openpilot.h>
#include <uavobjectsinit.h> #include <uavobjectsinit.h>
#include <hwsettings.h>
#include "manualcontrolsettings.h" #include "manualcontrolsettings.h"
//#define I2C_DEBUG_PIN 0 //#define I2C_DEBUG_PIN 0
@ -496,7 +497,6 @@ static const struct pios_usart_cfg pios_usart_spektrum_cfg = {
}, },
}; };
#include <pios_spektrum_priv.h>
static const struct pios_spektrum_cfg pios_spektrum_cfg = { static const struct pios_spektrum_cfg pios_spektrum_cfg = {
.bind = { .bind = {
.gpio = GPIOA, .gpio = GPIOA,
@ -964,8 +964,12 @@ static const struct stm32_gpio pios_debug_pins[] = {
#if defined(PIOS_INCLUDE_RCVR) #if defined(PIOS_INCLUDE_RCVR)
#include "pios_rcvr_priv.h" #include "pios_rcvr_priv.h"
struct pios_rcvr_channel_map pios_rcvr_channel_to_id_map[PIOS_RCVR_MAX_CHANNELS]; /* One slot per selectable receiver group.
uint32_t pios_rcvr_max_channel; * eg. PWM, PPM, GCS, SPEKTRUM1, SPEKTRUM2, SBUS
* NOTE: No slot in this map for NONE.
*/
uint32_t pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE];
#endif /* PIOS_INCLUDE_RCVR */ #endif /* PIOS_INCLUDE_RCVR */
#if defined(PIOS_INCLUDE_USB_HID) #if defined(PIOS_INCLUDE_USB_HID)
@ -1047,8 +1051,14 @@ void PIOS_Board_Init(void) {
/* Bind the AHRS comms layer to the AHRS SPI link */ /* Bind the AHRS comms layer to the AHRS SPI link */
AhrsConnect(pios_spi_ahrs_id); AhrsConnect(pios_spi_ahrs_id);
/* Initialize the PiOS library */ /* Configure the main IO port */
#if defined(PIOS_INCLUDE_COM) uint8_t hwsettings_op_mainport;
HwSettingsOP_MainPortGet(&hwsettings_op_mainport);
switch (hwsettings_op_mainport) {
case HWSETTINGS_OP_MAINPORT_DISABLED:
break;
case HWSETTINGS_OP_MAINPORT_TELEMETRY:
#if defined(PIOS_INCLUDE_TELEMETRY_RF) #if defined(PIOS_INCLUDE_TELEMETRY_RF)
{ {
uint32_t pios_usart_telem_rf_id; uint32_t pios_usart_telem_rf_id;
@ -1067,7 +1077,17 @@ void PIOS_Board_Init(void) {
} }
} }
#endif /* PIOS_INCLUDE_TELEMETRY_RF */ #endif /* PIOS_INCLUDE_TELEMETRY_RF */
break;
}
/* Configure the flexi port */
uint8_t hwsettings_op_flexiport;
HwSettingsOP_FlexiPortGet(&hwsettings_op_flexiport);
switch (hwsettings_op_flexiport) {
case HWSETTINGS_OP_FLEXIPORT_DISABLED:
break;
case HWSETTINGS_OP_FLEXIPORT_GPS:
#if defined(PIOS_INCLUDE_GPS) #if defined(PIOS_INCLUDE_GPS)
{ {
uint32_t pios_usart_gps_id; uint32_t pios_usart_gps_id;
@ -1083,60 +1103,25 @@ void PIOS_Board_Init(void) {
} }
} }
#endif /* PIOS_INCLUDE_GPS */ #endif /* PIOS_INCLUDE_GPS */
#endif break;
}
PIOS_Servo_Init(); PIOS_Servo_Init();
PIOS_ADC_Init(); PIOS_ADC_Init();
PIOS_GPIO_Init(); PIOS_GPIO_Init();
/* Configure the selected receiver */ /* Configure the aux port */
uint8_t manualcontrolsettings_inputmode; uint8_t hwsettings_op_auxport;
ManualControlSettingsInputModeGet(&manualcontrolsettings_inputmode); HwSettingsOP_AuxPortGet(&hwsettings_op_auxport);
switch (manualcontrolsettings_inputmode) { switch (hwsettings_op_auxport) {
case MANUALCONTROLSETTINGS_INPUTMODE_PWM: case HWSETTINGS_OP_AUXPORT_DISABLED:
#if defined(PIOS_INCLUDE_PWM)
#if (PIOS_PWM_NUM_INPUTS > PIOS_RCVR_MAX_CHANNELS)
#error More receiver inputs than available devices
#endif
PIOS_PWM_Init();
uint32_t pios_pwm_rcvr_id;
if (PIOS_RCVR_Init(&pios_pwm_rcvr_id, &pios_pwm_rcvr_driver, 0)) {
PIOS_Assert(0);
}
for (uint8_t i = 0;
i < PIOS_PWM_NUM_INPUTS && pios_rcvr_max_channel < NELEMENTS(pios_rcvr_channel_to_id_map);
i++) {
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].id = pios_pwm_rcvr_id;
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].channel = i;
pios_rcvr_max_channel++;
}
#endif /* PIOS_INCLUDE_PWM */
break; break;
case MANUALCONTROLSETTINGS_INPUTMODE_PPM: case HWSETTINGS_OP_AUXPORT_DEBUG:
#if defined(PIOS_INCLUDE_PPM) /* Not supported yet */
#if (PIOS_PPM_NUM_INPUTS > PIOS_RCVR_MAX_CHANNELS)
#error More receiver inputs than available devices
#endif
PIOS_PPM_Init();
uint32_t pios_ppm_rcvr_id;
if (PIOS_RCVR_Init(&pios_ppm_rcvr_id, &pios_ppm_rcvr_driver, 0)) {
PIOS_Assert(0);
}
for (uint8_t i = 0;
i < PIOS_PPM_NUM_INPUTS && pios_rcvr_max_channel < NELEMENTS(pios_rcvr_channel_to_id_map);
i++) {
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].id = pios_ppm_rcvr_id;
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].channel = i;
pios_rcvr_max_channel++;
}
#endif /* PIOS_INCLUDE_PPM */
break; break;
case MANUALCONTROLSETTINGS_INPUTMODE_SPEKTRUM: case HWSETTINGS_OP_AUXPORT_SPEKTRUM1:
#if defined(PIOS_INCLUDE_SPEKTRUM) #if defined(PIOS_INCLUDE_SPEKTRUM)
#if (PIOS_SPEKTRUM_NUM_INPUTS > PIOS_RCVR_MAX_CHANNELS)
#error More receiver inputs than available devices
#endif
{ {
uint32_t pios_usart_spektrum_id; uint32_t pios_usart_spektrum_id;
if (PIOS_USART_Init(&pios_usart_spektrum_id, &pios_usart_spektrum_cfg)) { if (PIOS_USART_Init(&pios_usart_spektrum_id, &pios_usart_spektrum_cfg)) {
@ -1149,23 +1134,41 @@ void PIOS_Board_Init(void) {
} }
uint32_t pios_spektrum_rcvr_id; uint32_t pios_spektrum_rcvr_id;
if (PIOS_RCVR_Init(&pios_spektrum_rcvr_id, &pios_spektrum_rcvr_driver, 0)) { if (PIOS_RCVR_Init(&pios_spektrum_rcvr_id, &pios_spektrum_rcvr_driver, pios_spektrum_id)) {
PIOS_Assert(0); PIOS_Assert(0);
} }
for (uint8_t i = 0; pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_SPEKTRUM1] = pios_spektrum_rcvr_id;
i < PIOS_SPEKTRUM_NUM_INPUTS && pios_rcvr_max_channel < NELEMENTS(pios_rcvr_channel_to_id_map);
i++) {
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].id = pios_spektrum_rcvr_id;
pios_rcvr_channel_to_id_map[pios_rcvr_max_channel].channel = i;
pios_rcvr_max_channel++;
}
} }
#endif #endif
break; break;
case MANUALCONTROLSETTINGS_INPUTMODE_SBUS: }
#if defined(PIOS_INCLUDE_SBUS)
#error SBUS NOT ON OP YET /* Configure the rcvr port */
#endif /* PIOS_INCLUDE_SBUS */ uint8_t hwsettings_rcvrport;
HwSettingsRcvrPortGet(&hwsettings_rcvrport);
switch (hwsettings_rcvrport) {
case HWSETTINGS_RCVRPORT_DISABLED:
break;
case HWSETTINGS_RCVRPORT_PWM:
#if defined(PIOS_INCLUDE_PWM)
PIOS_PWM_Init();
uint32_t pios_pwm_rcvr_id;
if (PIOS_RCVR_Init(&pios_pwm_rcvr_id, &pios_pwm_rcvr_driver, 0)) {
PIOS_Assert(0);
}
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_PWM] = pios_pwm_rcvr_id;
#endif /* PIOS_INCLUDE_PWM */
break;
case HWSETTINGS_RCVRPORT_PPM:
#if defined(PIOS_INCLUDE_PPM)
PIOS_PPM_Init();
uint32_t pios_ppm_rcvr_id;
if (PIOS_RCVR_Init(&pios_ppm_rcvr_id, &pios_ppm_rcvr_driver, 0)) {
PIOS_Assert(0);
}
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_PPM] = pios_ppm_rcvr_id;
#endif /* PIOS_INCLUDE_PPM */
break; break;
} }

View File

@ -69,6 +69,7 @@ UAVOBJSRCFILENAMES += velocityactual
UAVOBJSRCFILENAMES += velocitydesired UAVOBJSRCFILENAMES += velocitydesired
UAVOBJSRCFILENAMES += watchdogstatus UAVOBJSRCFILENAMES += watchdogstatus
UAVOBJSRCFILENAMES += flightstatus UAVOBJSRCFILENAMES += flightstatus
UAVOBJSRCFILENAMES += hwsettings
UAVOBJSRC = $(foreach UAVOBJSRCFILE,$(UAVOBJSRCFILENAMES),$(UAVOBJSYNTHDIR)/$(UAVOBJSRCFILE).c ) UAVOBJSRC = $(foreach UAVOBJSRCFILE,$(UAVOBJSRCFILENAMES),$(UAVOBJSYNTHDIR)/$(UAVOBJSRCFILE).c )
UAVOBJDEFINE = $(foreach UAVOBJSRCFILE,$(UAVOBJSRCFILENAMES),-DUAVOBJ_INIT_$(UAVOBJSRCFILE) ) UAVOBJDEFINE = $(foreach UAVOBJSRCFILE,$(UAVOBJSRCFILENAMES),-DUAVOBJ_INIT_$(UAVOBJSRCFILE) )

View File

@ -206,7 +206,7 @@ extern uint32_t pios_com_telem_usb_id;
// PIOS_RCVR // PIOS_RCVR
// See also pios_board.c // See also pios_board.c
//------------------------ //------------------------
#define PIOS_RCVR_MAX_DEVS 1 #define PIOS_RCVR_MAX_DEVS 3
#define PIOS_RCVR_MAX_CHANNELS 12 #define PIOS_RCVR_MAX_CHANNELS 12
//------------------------- //-------------------------
@ -222,6 +222,7 @@ extern uint32_t pios_com_telem_usb_id;
//------------------------- //-------------------------
// Receiver SPEKTRUM input // Receiver SPEKTRUM input
//------------------------- //-------------------------
#define PIOS_SPEKTRUM_MAX_DEVS 2
#define PIOS_SPEKTRUM_NUM_INPUTS 12 #define PIOS_SPEKTRUM_NUM_INPUTS 12
//------------------------- //-------------------------

View File

@ -195,6 +195,7 @@ extern uint32_t pios_com_aux_id;
//------------------------- //-------------------------
// Receiver SPEKTRUM input // Receiver SPEKTRUM input
//------------------------- //-------------------------
#define PIOS_SPEKTRUM_MAX_DEVS 1
#define PIOS_SPEKTRUM_NUM_INPUTS 12 #define PIOS_SPEKTRUM_NUM_INPUTS 12
//------------------------- //-------------------------

View File

@ -31,10 +31,11 @@
/* Project Includes */ /* Project Includes */
#include "pios.h" #include "pios.h"
#include "pios_spektrum_priv.h"
#if defined(PIOS_INCLUDE_SPEKTRUM) #if defined(PIOS_INCLUDE_SPEKTRUM)
#include "pios_spektrum_priv.h"
/** /**
* @Note Framesyncing: * @Note Framesyncing:
* The code resets the watchdog timer whenever a single byte is received, so what watchdog code * The code resets the watchdog timer whenever a single byte is received, so what watchdog code
@ -52,22 +53,80 @@ const struct pios_rcvr_driver pios_spektrum_rcvr_driver = {
.read = PIOS_SPEKTRUM_Get, .read = PIOS_SPEKTRUM_Get,
}; };
/* Local Variables */ enum pios_spektrum_dev_magic {
static uint16_t CaptureValue[PIOS_SPEKTRUM_NUM_INPUTS],CaptureValueTemp[PIOS_SPEKTRUM_NUM_INPUTS]; PIOS_SPEKTRUM_DEV_MAGIC = 0xa9b9c9d9,
static uint8_t prev_byte = 0xFF, sync = 0, bytecount = 0, datalength=0, frame_error=0, byte_array[20] = { 0 }; };
uint8_t sync_of = 0;
uint16_t supv_timer=0; struct pios_spektrum_fsm {
uint16_t channel;
uint16_t CaptureValue[PIOS_SPEKTRUM_NUM_INPUTS];
uint16_t CaptureValueTemp[PIOS_SPEKTRUM_NUM_INPUTS];
uint8_t prev_byte;
uint8_t sync;
uint8_t bytecount;
uint8_t datalength;
uint8_t frame_error;
uint8_t sync_of;
};
struct pios_spektrum_dev {
enum pios_spektrum_dev_magic magic;
const struct pios_spektrum_cfg * cfg;
struct pios_spektrum_fsm fsm;
uint16_t supv_timer;
};
static bool PIOS_SPEKTRUM_validate(struct pios_spektrum_dev * spektrum_dev)
{
return (spektrum_dev->magic == PIOS_SPEKTRUM_DEV_MAGIC);
}
#if defined(PIOS_INCLUDE_FREERTOS) && 0
static struct pios_spektrum_dev * PIOS_SPEKTRUM_alloc(void)
{
struct pios_spektrum_dev * spektrum_dev;
spektrum_dev = (struct pios_spektrum_dev *)malloc(sizeof(*spektrum_dev));
if (!spektrum_dev) return(NULL);
spektrum_dev->magic = PIOS_SPEKTRUM_DEV_MAGIC;
return(spektrum_dev);
}
#else
static struct pios_spektrum_dev pios_spektrum_devs[PIOS_SPEKTRUM_MAX_DEVS];
static uint8_t pios_spektrum_num_devs;
static struct pios_spektrum_dev * PIOS_SPEKTRUM_alloc(void)
{
struct pios_spektrum_dev * spektrum_dev;
if (pios_spektrum_num_devs >= PIOS_SPEKTRUM_MAX_DEVS) {
return (NULL);
}
spektrum_dev = &pios_spektrum_devs[pios_spektrum_num_devs++];
spektrum_dev->magic = PIOS_SPEKTRUM_DEV_MAGIC;
return (spektrum_dev);
}
#endif
static void PIOS_SPEKTRUM_Supervisor(uint32_t spektrum_id); static void PIOS_SPEKTRUM_Supervisor(uint32_t spektrum_id);
static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg); static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg);
static int32_t PIOS_SPEKTRUM_Decode(uint8_t b); static int32_t PIOS_SPEKTRUM_UpdateFSM(struct pios_spektrum_fsm * fsm, uint8_t b);
static uint16_t PIOS_SPEKTRUM_RxInCallback(uint32_t context, uint8_t * buf, uint16_t buf_len, uint16_t * headroom, bool * need_yield) static uint16_t PIOS_SPEKTRUM_RxInCallback(uint32_t context, uint8_t * buf, uint16_t buf_len, uint16_t * headroom, bool * need_yield)
{ {
struct pios_spektrum_dev * spektrum_dev = (struct pios_spektrum_dev *)context;
bool valid = PIOS_SPEKTRUM_validate(spektrum_dev);
PIOS_Assert(valid);
/* process byte(s) and clear receive timer */ /* process byte(s) and clear receive timer */
for (uint8_t i = 0; i < buf_len; i++) { for (uint8_t i = 0; i < buf_len; i++) {
PIOS_SPEKTRUM_Decode(buf[i]); PIOS_SPEKTRUM_UpdateFSM(&(spektrum_dev->fsm), buf[i]);
supv_timer = 0; spektrum_dev->supv_timer = 0;
} }
/* Always signal that we can accept another byte */ /* Always signal that we can accept another byte */
@ -82,23 +141,118 @@ static uint16_t PIOS_SPEKTRUM_RxInCallback(uint32_t context, uint8_t * buf, uint
return (buf_len); return (buf_len);
} }
static void PIOS_SPEKTRUM_ResetFSM(struct pios_spektrum_fsm * fsm)
{
fsm->channel = 0;
fsm->prev_byte = 0xFF;
fsm->sync = 0;
fsm->bytecount = 0;
fsm->datalength = 0;
fsm->frame_error = 0;
fsm->sync_of = 0;
}
/**
* Decodes a byte
* \param[in] b byte which should be spektrum decoded
* \return 0 if no error
* \return -1 if USART not available
* \return -2 if buffer full (retry)
*/
static int32_t PIOS_SPEKTRUM_UpdateFSM(struct pios_spektrum_fsm * fsm, uint8_t b)
{
fsm->bytecount++;
if (fsm->sync == 0) {
/* Known sync bytes, 0x01, 0x02, 0x12 */
if (fsm->bytecount == 2) {
if (b == 0x01) {
fsm->datalength=0; // 10bit
fsm->sync = 1;
fsm->bytecount = 2;
}
else if(b == 0x02) {
fsm->datalength=0; // 10bit
fsm->sync = 1;
fsm->bytecount = 2;
}
else if(b == 0x12) {
fsm->datalength=1; // 11bit
fsm->sync = 1;
fsm->bytecount = 2;
}
else
{
fsm->bytecount = 0;
}
}
} else {
if ((fsm->bytecount % 2) == 0) {
uint16_t data;
uint8_t channeln;
fsm->channel = (fsm->prev_byte << 8) + b;
channeln = (fsm->channel >> (10+fsm->datalength)) & 0x0F;
data = fsm->channel & (0x03FF+(0x0400*fsm->datalength));
if(channeln==0 && data<10) // discard frame if throttle misbehaves
{
fsm->frame_error=1;
}
if (channeln < PIOS_SPEKTRUM_NUM_INPUTS && !fsm->frame_error)
fsm->CaptureValueTemp[channeln] = data;
}
}
if (fsm->bytecount == 16) {
fsm->bytecount = 0;
fsm->sync = 0;
fsm->sync_of = 0;
if (!fsm->frame_error)
{
for(int i=0;i<PIOS_SPEKTRUM_NUM_INPUTS;i++)
{
fsm->CaptureValue[i] = fsm->CaptureValueTemp[i];
}
}
fsm->frame_error=0;
}
fsm->prev_byte = b;
return 0;
}
/** /**
* Bind and Initialise Spektrum satellite receiver * Bind and Initialise Spektrum satellite receiver
*/ */
int32_t PIOS_SPEKTRUM_Init(uint32_t * spektrum_id, const struct pios_spektrum_cfg *cfg, const struct pios_com_driver * driver, uint32_t lower_id, bool bind) int32_t PIOS_SPEKTRUM_Init(uint32_t * spektrum_id, const struct pios_spektrum_cfg *cfg, const struct pios_com_driver * driver, uint32_t lower_id, bool bind)
{ {
// TODO: need setting flag for bind on next powerup PIOS_DEBUG_Assert(spektrum_id);
PIOS_DEBUG_Assert(cfg);
PIOS_DEBUG_Assert(driver);
struct pios_spektrum_dev * spektrum_dev;
spektrum_dev = (struct pios_spektrum_dev *) PIOS_SPEKTRUM_alloc();
if (!spektrum_dev) goto out_fail;
/* Bind the configuration to the device instance */
spektrum_dev->cfg = cfg;
if (bind) { if (bind) {
PIOS_SPEKTRUM_Bind(cfg); PIOS_SPEKTRUM_Bind(cfg);
} }
(driver->bind_rx_cb)(lower_id, PIOS_SPEKTRUM_RxInCallback, 0); PIOS_SPEKTRUM_ResetFSM(&(spektrum_dev->fsm));
if (!PIOS_RTC_RegisterTickCallback(PIOS_SPEKTRUM_Supervisor, 0)) { *spektrum_id = (uint32_t)spektrum_dev;
(driver->bind_rx_cb)(lower_id, PIOS_SPEKTRUM_RxInCallback, *spektrum_id);
if (!PIOS_RTC_RegisterTickCallback(PIOS_SPEKTRUM_Supervisor, *spektrum_id)) {
PIOS_DEBUG_Assert(0); PIOS_DEBUG_Assert(0);
} }
return (0); return (0);
out_fail:
return(-1);
} }
/** /**
@ -109,11 +263,16 @@ int32_t PIOS_SPEKTRUM_Init(uint32_t * spektrum_id, const struct pios_spektrum_cf
*/ */
static int32_t PIOS_SPEKTRUM_Get(uint32_t rcvr_id, uint8_t channel) static int32_t PIOS_SPEKTRUM_Get(uint32_t rcvr_id, uint8_t channel)
{ {
struct pios_spektrum_dev * spektrum_dev = (struct pios_spektrum_dev *)rcvr_id;
bool valid = PIOS_SPEKTRUM_validate(spektrum_dev);
PIOS_Assert(valid);
/* Return error if channel not available */ /* Return error if channel not available */
if (channel >= PIOS_SPEKTRUM_NUM_INPUTS) { if (channel >= PIOS_SPEKTRUM_NUM_INPUTS) {
return -1; return -1;
} }
return CaptureValue[channel]; return spektrum_dev->fsm.CaptureValue[channel];
} }
/** /**
@ -145,114 +304,38 @@ static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg)
return true; return true;
} }
/**
* Decodes a byte
* \param[in] b byte which should be spektrum decoded
* \return 0 if no error
* \return -1 if USART not available
* \return -2 if buffer full (retry)
* \note Applications shouldn't call these functions directly
*/
static int32_t PIOS_SPEKTRUM_Decode(uint8_t b)
{
static uint16_t channel = 0; /*, sync_word = 0;*/
uint8_t channeln = 0, frame = 0;
uint16_t data = 0;
byte_array[bytecount] = b;
bytecount++;
if (sync == 0) {
//sync_word = (prev_byte << 8) + b;
#if 0
/* maybe create object to show this data */
if(bytecount==1)
{
/* record losscounter into channel8 */
CaptureValueTemp[7]=b;
/* instant write */
CaptureValue[7]=b;
}
#endif
/* Known sync bytes, 0x01, 0x02, 0x12 */
if (bytecount == 2) {
if (b == 0x01) {
datalength=0; // 10bit
//frames=1;
sync = 1;
bytecount = 2;
}
else if(b == 0x02) {
datalength=0; // 10bit
//frames=2;
sync = 1;
bytecount = 2;
}
else if(b == 0x12) {
datalength=1; // 11bit
//frames=2;
sync = 1;
bytecount = 2;
}
else
{
bytecount = 0;
}
}
} else {
if ((bytecount % 2) == 0) {
channel = (prev_byte << 8) + b;
frame = channel >> 15;
channeln = (channel >> (10+datalength)) & 0x0F;
data = channel & (0x03FF+(0x0400*datalength));
if(channeln==0 && data<10) // discard frame if throttle misbehaves
{
frame_error=1;
}
if (channeln < PIOS_SPEKTRUM_NUM_INPUTS && !frame_error)
CaptureValueTemp[channeln] = data;
}
}
if (bytecount == 16) {
//PIOS_COM_SendBufferNonBlocking(PIOS_COM_TELEM_RF,byte_array,16); //00 2c 58 84 b0 dc ff
bytecount = 0;
sync = 0;
sync_of = 0;
if (!frame_error)
{
for(int i=0;i<PIOS_SPEKTRUM_NUM_INPUTS;i++)
{
CaptureValue[i] = CaptureValueTemp[i];
}
}
frame_error=0;
}
prev_byte = b;
return 0;
}
/** /**
*@brief This function is called between frames and when a spektrum word hasnt been decoded for too long *@brief This function is called between frames and when a spektrum word hasnt been decoded for too long
*@brief clears the channel values *@brief clears the channel values
*/ */
static void PIOS_SPEKTRUM_Supervisor(uint32_t spektrum_id) { static void PIOS_SPEKTRUM_Supervisor(uint32_t spektrum_id)
{
struct pios_spektrum_dev * spektrum_dev = (struct pios_spektrum_dev *)spektrum_id;
bool valid = PIOS_SPEKTRUM_validate(spektrum_dev);
PIOS_Assert(valid);
/* 125hz */ /* 125hz */
supv_timer++; spektrum_dev->supv_timer++;
if(supv_timer > 5) { if(spektrum_dev->supv_timer > 5) {
/* sync between frames */ /* sync between frames */
sync = 0; struct pios_spektrum_fsm * fsm = &(spektrum_dev->fsm);
bytecount = 0;
prev_byte = 0xFF; fsm->sync = 0;
frame_error = 0; fsm->bytecount = 0;
sync_of++; fsm->prev_byte = 0xFF;
fsm->frame_error = 0;
fsm->sync_of++;
/* watchdog activated after 100ms silence */ /* watchdog activated after 100ms silence */
if (sync_of > 12) { if (fsm->sync_of > 12) {
/* signal lost */ /* signal lost */
sync_of = 0; fsm->sync_of = 0;
for (int i = 0; i < PIOS_SPEKTRUM_NUM_INPUTS; i++) { for (int i = 0; i < PIOS_SPEKTRUM_NUM_INPUTS; i++) {
CaptureValue[i] = 0; fsm->CaptureValue[i] = 0;
CaptureValueTemp[i] = 0; fsm->CaptureValueTemp[i] = 0;
} }
} }
supv_timer = 0; spektrum_dev->supv_timer = 0;
} }
} }

View File

@ -31,13 +31,6 @@
#ifndef PIOS_RCVR_H #ifndef PIOS_RCVR_H
#define PIOS_RCVR_H #define PIOS_RCVR_H
struct pios_rcvr_channel_map {
uint32_t id;
uint8_t channel;
};
extern struct pios_rcvr_channel_map pios_rcvr_channel_to_id_map[];
struct pios_rcvr_driver { struct pios_rcvr_driver {
void (*init)(uint32_t id); void (*init)(uint32_t id);
int32_t (*read)(uint32_t id, uint8_t channel); int32_t (*read)(uint32_t id, uint8_t channel);

View File

@ -1,8 +1,14 @@
<xml> <xml>
<object name="HwSettings" singleinstance="true" settings="true"> <object name="HwSettings" singleinstance="true" settings="true">
<description>Selection of optional hardware configurations.</description> <description>Selection of optional hardware configurations.</description>
<field name="CC_FlexiPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,Spektrum,ComAux,I2C" defaultvalue="Disabled"/> <field name="CC_FlexiPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,Spektrum1,Spektrum2,ComAux,I2C" defaultvalue="Disabled"/>
<field name="CC_MainPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,S.Bus,GPS,Spektrum,ComAux" defaultvalue="Telemetry"/> <field name="CC_MainPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,S.Bus,GPS,Spektrum1,Spektrum2,ComAux" defaultvalue="Telemetry"/>
<field name="OP_FlexiPort" units="function" type="enum" elements="1" options="Disabled,GPS" defaultvalue="GPS"/>
<field name="OP_MainPort" units="function" type="enum" elements="1" options="Disabled,Telemetry" defaultvalue="Telemetry"/>
<field name="OP_AuxPort" units="function" type="enum" elements="1" options="Disabled,Debug,Spektrum1" defaultvalue="Disabled"/>
<field name="RcvrPort" units="function" type="enum" elements="1" options="Disabled,PWM,PPM" defaultvalue="PWM"/>
<access gcs="readwrite" flight="readwrite"/> <access gcs="readwrite" flight="readwrite"/>
<telemetrygcs acked="true" updatemode="onchange" period="0"/> <telemetrygcs acked="true" updatemode="onchange" period="0"/>
<telemetryflight acked="true" updatemode="onchange" period="0"/> <telemetryflight acked="true" updatemode="onchange" period="0"/>

View File

@ -1,15 +1,18 @@
<xml> <xml>
<object name="ManualControlSettings" singleinstance="true" settings="true"> <object name="ManualControlSettings" singleinstance="true" settings="true">
<description>Settings to indicate how to decode receiver input by @ref ManualControlModule.</description> <description>Settings to indicate how to decode receiver input by @ref ManualControlModule.</description>
<field name="InputMode" units="" type="enum" elements="1" options="PWM,PPM,Spektrum,S.Bus,GCS" defaultvalue="PWM"/> <field name="ChannelGroups" units="Channel Group" type="enum"
<field name="Roll" units="channel" type="enum" elements="1" options="Channel1,Channel2,Channel3,Channel4,Channel5,Channel6,Channel7,Channel8,None" defaultvalue="None"/> elementnames="Roll,Pitch,Yaw,Throttle,FlightMode,Accessory0,Accessory1,Accessory2"
<field name="Pitch" units="channel" type="enum" elements="1" options="Channel1,Channel2,Channel3,Channel4,Channel5,Channel6,Channel7,Channel8,None" defaultvalue="None"/> options="PWM,PPM,Spektrum1,Spektrum2,S.Bus,GCS,None" defaultvalue="None"/>
<field name="Yaw" units="channel" type="enum" elements="1" options="Channel1,Channel2,Channel3,Channel4,Channel5,Channel6,Channel7,Channel8,None" defaultvalue="None"/> <field name="ChannelNumber" units="channel" type="uint8" defaultvalue="255"
<field name="Throttle" units="channel" type="enum" elements="1" options="Channel1,Channel2,Channel3,Channel4,Channel5,Channel6,Channel7,Channel8,None" defaultvalue="None"/> elementnames="Roll,Pitch,Yaw,Throttle,FlightMode,Accessory0,Accessory1,Accessory2"/>
<field name="FlightMode" units="channel" type="enum" elements="1" options="Channel1,Channel2,Channel3,Channel4,Channel5,Channel6,Channel7,Channel8,None" defaultvalue="None"/> <field name="ChannelMin" units="us" type="int16" defaultvalue="1000"
<field name="Accessory0" units="channel" type="enum" elements="1" options="Channel1,Channel2,Channel3,Channel4,Channel5,Channel6,Channel7,Channel8,None" defaultvalue="None"/> elementnames="Roll,Pitch,Yaw,Throttle,FlightMode,Accessory0,Accessory1,Accessory2"/>
<field name="Accessory1" units="channel" type="enum" elements="1" options="Channel1,Channel2,Channel3,Channel4,Channel5,Channel6,Channel7,Channel8,None" defaultvalue="None"/> <field name="ChannelNeutral" units="us" type="int16" defaultvalue="1500"
<field name="Accessory2" units="channel" type="enum" elements="1" options="Channel1,Channel2,Channel3,Channel4,Channel5,Channel6,Channel7,Channel8,None" defaultvalue="None"/> elementnames="Roll,Pitch,Yaw,Throttle,FlightMode,Accessory0,Accessory1,Accessory2"/>
<field name="ChannelMax" units="us" type="int16" defaultvalue="2000"
elementnames="Roll,Pitch,Yaw,Throttle,FlightMode,Accessory0,Accessory1,Accessory2"/>
<field name="Arming" units="" type="enum" elements="1" options="Always Disarmed,Always Armed,Roll Left,Roll Right,Pitch Forward,Pitch Aft,Yaw Left,Yaw Right" defaultvalue="Always Disarmed"/> <field name="Arming" units="" type="enum" elements="1" options="Always Disarmed,Always Armed,Roll Left,Roll Right,Pitch Forward,Pitch Aft,Yaw Left,Yaw Right" defaultvalue="Always Disarmed"/>
<!-- Note these options should be identical to those in StabilizationDesired.StabilizationMode --> <!-- Note these options should be identical to those in StabilizationDesired.StabilizationMode -->
@ -20,9 +23,6 @@
<!-- Note these options values should be identical to those defined in FlightMode --> <!-- Note these options values should be identical to those defined in FlightMode -->
<field name="FlightModePosition" units="" type="enum" elements="3" options="Manual,Stabilized1,Stabilized2,Stabilized3,VelocityControl,PositionHold" defaultvalue="Manual,Stabilized1,Stabilized2"/> <field name="FlightModePosition" units="" type="enum" elements="3" options="Manual,Stabilized1,Stabilized2,Stabilized3,VelocityControl,PositionHold" defaultvalue="Manual,Stabilized1,Stabilized2"/>
<field name="ChannelMax" units="us" type="int16" elements="8" defaultvalue="2000"/>
<field name="ChannelNeutral" units="us" type="int16" elements="8" defaultvalue="1500"/>
<field name="ChannelMin" units="us" type="int16" elements="8" defaultvalue="1000"/>
<field name="ArmedTimeout" units="ms" type="uint16" elements="1" defaultvalue="30000"/> <field name="ArmedTimeout" units="ms" type="uint16" elements="1" defaultvalue="30000"/>
<access gcs="readwrite" flight="readwrite"/> <access gcs="readwrite" flight="readwrite"/>
<telemetrygcs acked="true" updatemode="onchange" period="0"/> <telemetrygcs acked="true" updatemode="onchange" period="0"/>