diff --git a/flight/Libraries/inc/packet_handler.h b/flight/Libraries/inc/packet_handler.h index 6bbbb1d88..54f55e63e 100644 --- a/flight/Libraries/inc/packet_handler.h +++ b/flight/Libraries/inc/packet_handler.h @@ -33,6 +33,7 @@ #include #include #include +#include // Public defines / macros #define PHPacketSize(p) ((uint8_t*)(p->data) + p->header.data_size - (uint8_t*)p) @@ -75,7 +76,7 @@ typedef struct { #define PH_PPM_DATA_SIZE(p) ((uint8_t*)((p)->ecc) - (uint8_t*)(((PHPacketHandle)(p))->data)) typedef struct { PHPacketHeader header; - uint16_t channels[GCSRECEIVER_CHANNEL_NUMELEM]; + uint16_t channels[PIOS_RFM22B_RCVR_MAX_CHANNELS]; uint8_t ecc[RS_ECC_NPARITY]; } PHPpmPacket, *PHPpmPacketHandle; diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index ffea27457..16beac710 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -498,6 +498,9 @@ static bool updateRcvrActivityCompare(uint32_t rcvr_id, struct rcvr_activity_fsm case MANUALCONTROLSETTINGS_CHANNELGROUPS_GCS: group = RECEIVERACTIVITY_ACTIVEGROUP_GCS; break; + case MANUALCONTROLSETTINGS_CHANNELGROUPS_OPLINK: + group = RECEIVERACTIVITY_ACTIVEGROUP_OPLINK; + break; default: PIOS_Assert(0); break; diff --git a/flight/PiOS/Boards/STM32F4xx_RevoMini.h b/flight/PiOS/Boards/STM32F4xx_RevoMini.h index 6dd7041dc..3421afd9a 100644 --- a/flight/PiOS/Boards/STM32F4xx_RevoMini.h +++ b/flight/PiOS/Boards/STM32F4xx_RevoMini.h @@ -214,6 +214,7 @@ extern uint32_t pios_packet_handler; #define PIOS_RCVR_MAX_DEVS 3 #define PIOS_RCVR_MAX_CHANNELS 12 #define PIOS_GCSRCVR_TIMEOUT_MS 100 +#define PIOS_RFM22B_RCVR_TIMEOUT_MS 100 //------------------------- // Receiver PPM input diff --git a/flight/PiOS/Common/pios_rfm22b.c b/flight/PiOS/Common/pios_rfm22b.c index c6b101ee4..0ae6ac2a3 100644 --- a/flight/PiOS/Common/pios_rfm22b.c +++ b/flight/PiOS/Common/pios_rfm22b.c @@ -1767,6 +1767,14 @@ static enum pios_rfm22b_event rfm22_rxData(struct pios_rfm22b_dev *rfm22b_dev) case PACKET_TYPE_NACK: ret_event = RFM22B_EVENT_PACKET_NACKED; break; + case PACKET_TYPE_PPM: + { + PHPpmPacketHandle ppmp = (PHPpmPacketHandle)&(rfm22b_dev->rx_packet); + for (uint8_t i = 0; i < PIOS_RFM22B_RCVR_MAX_CHANNELS; ++i) + rfm22b_dev->ppm_channel[i] = ppmp->channels[i]; + rfm22b_dev->ppm_fresh = true; + break; + } default: break; } diff --git a/flight/PiOS/Common/pios_rfm22b_rcvr.c b/flight/PiOS/Common/pios_rfm22b_rcvr.c new file mode 100644 index 000000000..0878da0f1 --- /dev/null +++ b/flight/PiOS/Common/pios_rfm22b_rcvr.c @@ -0,0 +1,99 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_RFM22B_RCVR RFM22B Receiver Input Functions + * @brief Code to output the PPM signal from the RFM22B + * @{ + * + * @file pios_rfm22b_rcvr.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @brief Implements a receiver interface to the RFM22B device + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* Project Includes */ +#include "pios.h" + +#if defined(PIOS_INCLUDE_RFM22B_RCVR) + +#include "pios_rfm22b_priv.h" + +/* Provide a RCVR driver */ +static int32_t PIOS_RFM22B_RCVR_Get(uint32_t rcvr_id, uint8_t channel); +static void PIOS_RFM22B_RCVR_Supervisor(uint32_t rcvr_id); + +const struct pios_rcvr_driver pios_rfm22b_rcvr_driver = { + .read = PIOS_RFM22B_RCVR_Get, +}; + +int32_t PIOS_RFM22B_RCVR_Init(uint32_t rcvr_id) +{ + struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rcvr_id; + if (!PIOS_RFM22B_validate(rfm22b_dev)) + return -1; + + // Initialize + for (uint8_t i = 0; i < PIOS_RFM22B_RCVR_MAX_CHANNELS; ++i) + rfm22b_dev->ppm_channel[i] = PIOS_RCVR_TIMEOUT; + rfm22b_dev->ppm_supv_timer = 0; + + // Register the failsafe timer callback. + if (!PIOS_RTC_RegisterTickCallback(PIOS_RFM22B_RCVR_Supervisor, rcvr_id)) + PIOS_DEBUG_Assert(0); + + return 0; +} + +static int32_t PIOS_RFM22B_RCVR_Get(uint32_t rcvr_id, uint8_t channel) +{ + struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rcvr_id; + if (!PIOS_RFM22B_validate(rfm22b_dev)) + return -1; + + if (channel >= GCSRECEIVER_CHANNEL_NUMELEM) + /* channel is out of range */ + return -1; + + return rfm22b_dev->ppm_channel[channel]; +} + +static void PIOS_RFM22B_RCVR_Supervisor(uint32_t rcvr_id) { + struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rcvr_id; + if (!PIOS_RFM22B_validate(rfm22b_dev)) + return; + + // RTC runs at 625Hz. + if (++(rfm22b_dev->ppm_supv_timer) < (PIOS_RFM22B_RCVR_TIMEOUT_MS * 1000 / 625)) + return; + rfm22b_dev->ppm_supv_timer = 0; + + // Have we received fresh values since the last update? + if (!rfm22b_dev->ppm_fresh) + for (uint8_t i = 0; i < PIOS_RFM22B_RCVR_MAX_CHANNELS; ++i) + rfm22b_dev->ppm_channel[i] = 0; + rfm22b_dev->ppm_fresh = false; +} + +#endif /* PIOS_INCLUDE_GCSRCVR */ + +/** + * @} + * @} + */ diff --git a/flight/PiOS/inc/pios_rfm22b_priv.h b/flight/PiOS/inc/pios_rfm22b_priv.h index fdd57a83e..27883311c 100644 --- a/flight/PiOS/inc/pios_rfm22b_priv.h +++ b/flight/PiOS/inc/pios_rfm22b_priv.h @@ -36,6 +36,7 @@ #include #include #include "pios_rfm22b.h" +#include "pios_rfm22b_rcvr.h" // ************************************ @@ -780,6 +781,11 @@ struct pios_rfm22b_dev { portTickType tx_complete_ticks; portTickType rx_complete_ticks; uint8_t max_ack_delay; + + // The PPM channel values + uint16_t ppm_channel[PIOS_RFM22B_RCVR_MAX_CHANNELS]; + uint8_t ppm_supv_timer; + bool ppm_fresh; }; diff --git a/flight/PiOS/inc/pios_rfm22b_rcvr.h b/flight/PiOS/inc/pios_rfm22b_rcvr.h new file mode 100644 index 000000000..74d176c4e --- /dev/null +++ b/flight/PiOS/inc/pios_rfm22b_rcvr.h @@ -0,0 +1,40 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS RFM22B Receiver Input Functions + * @{ + * + * @file pios_rfm22b_rcvr.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief RFM22B Receiver Input functions header. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PIOS_RFM22B_RCVR_H + +#define PIOS_RFM22B_RCVR_MAX_CHANNELS 12 + +extern const struct pios_rcvr_driver pios_rfm22b_rcvr_driver; + +extern int32_t PIOS_RFM22B_RCVR_Init(uint32_t rcvr_id); + +#define PIOS_RFM22B_RCVR_H + +#endif /* PIOS_RFM22B_RCVR_H */ diff --git a/flight/PiOS/pios.h b/flight/PiOS/pios.h index de641011b..5d2fa8d6e 100644 --- a/flight/PiOS/pios.h +++ b/flight/PiOS/pios.h @@ -174,6 +174,9 @@ #ifdef PIOS_INCLUDE_RFM22B_COM #include #endif +#ifdef PIOS_INCLUDE_RFM22B_RCVR +#include +#endif #endif #include diff --git a/flight/RevoMini/Makefile b/flight/RevoMini/Makefile index 42d3f5ec1..5f74a9f4e 100644 --- a/flight/RevoMini/Makefile +++ b/flight/RevoMini/Makefile @@ -170,6 +170,7 @@ SRC += $(PIOSCOMMON)/pios_crc.c SRC += $(PIOSCOMMON)/pios_com.c SRC += $(PIOSCOMMON)/pios_rfm22b.c SRC += $(PIOSCOMMON)/pios_rfm22b_com.c +SRC += $(PIOSCOMMON)/pios_rfm22b_rcvr.c SRC += $(PIOSCOMMON)/pios_rcvr.c SRC += $(PIOSCOMMON)/pios_sbus.c SRC += $(PIOSCOMMON)/pios_flash_jedec.c diff --git a/flight/RevoMini/System/inc/pios_config.h b/flight/RevoMini/System/inc/pios_config.h index 1ae25020c..2507b0cc6 100644 --- a/flight/RevoMini/System/inc/pios_config.h +++ b/flight/RevoMini/System/inc/pios_config.h @@ -58,7 +58,8 @@ /* Variables related to the RFM22B functionality */ #define PIOS_INCLUDE_RFM22B #define PIOS_INCLUDE_RFM22B_COM - +#define PIOS_INCLUDE_RFM22B_RCVR + /* Select the sensors to include */ #define PIOS_INCLUDE_HMC5883 #define PIOS_HMC5883_HAS_GPIOS diff --git a/flight/RevoMini/System/pios_board.c b/flight/RevoMini/System/pios_board.c index 8feac9fa3..3cc1fb105 100644 --- a/flight/RevoMini/System/pios_board.c +++ b/flight/RevoMini/System/pios_board.c @@ -616,15 +616,24 @@ void PIOS_Board_Init(void) { if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, pios_rfm22b_cfg->slave_num, pios_rfm22b_cfg)) { PIOS_Assert(0); } +#ifdef PIOS_INCLUDE_RFM22B_COM uint8_t *rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_RFM22B_RF_RX_BUF_LEN); uint8_t *tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_RFM22B_RF_TX_BUF_LEN); PIOS_Assert(rx_buffer); PIOS_Assert(tx_buffer); if (PIOS_COM_Init(&pios_com_telem_rf_id, &pios_rfm22b_com_driver, pios_rfm22b_id, rx_buffer, PIOS_COM_RFM22B_RF_RX_BUF_LEN, - tx_buffer, PIOS_COM_RFM22B_RF_TX_BUF_LEN)) { + tx_buffer, PIOS_COM_RFM22B_RF_TX_BUF_LEN)) PIOS_Assert(0); - } +#endif +#ifdef PIOS_INCLUDE_RFM22B_RCVR + if (PIOS_RFM22B_RCVR_Init(pios_rfm22b_id) != 0) + PIOS_Assert(0); + uint32_t pios_rfm22b_rcvr_id; + if (PIOS_RCVR_Init(&pios_rfm22b_rcvr_id, &pios_rfm22b_rcvr_driver, pios_rfm22b_id)) + PIOS_Assert(0); + pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_OPLINK] = pios_rfm22b_rcvr_id; +#endif break; } } diff --git a/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp b/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp index bd2d5830e..e5fcbcaa5 100755 --- a/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp +++ b/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp @@ -109,6 +109,7 @@ void inputChannelForm::groupUpdated() count = 8; // Need to make this 6 for CC break; case ManualControlSettings::CHANNELGROUPS_PPM: + case ManualControlSettings::CHANNELGROUPS_OPLINK: case ManualControlSettings::CHANNELGROUPS_DSMMAINPORT: case ManualControlSettings::CHANNELGROUPS_DSMFLEXIPORT: count = 12; @@ -117,7 +118,7 @@ void inputChannelForm::groupUpdated() count = 18; break; case ManualControlSettings::CHANNELGROUPS_GCS: - count = GCSReceiver::CHANNEL_NUMELEM; + count = 8; break; case ManualControlSettings::CHANNELGROUPS_NONE: count = 0; diff --git a/shared/uavobjectdefinition/manualcontrolsettings.xml b/shared/uavobjectdefinition/manualcontrolsettings.xml index 7dc2711a6..46aa8353a 100644 --- a/shared/uavobjectdefinition/manualcontrolsettings.xml +++ b/shared/uavobjectdefinition/manualcontrolsettings.xml @@ -3,7 +3,7 @@ Settings to indicate how to decode receiver input by @ref ManualControlModule. + options="PWM,PPM,DSM (MainPort),DSM (FlexiPort),S.Bus,GCS,OPLink,None" defaultvalue="None"/> Monitors which receiver channels have been active within the last second.