mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Added RFM22B (OPLink) receiver.
This commit is contained in:
parent
6e929d7a92
commit
3a1803b7a1
@ -33,6 +33,7 @@
|
||||
#include <uavobjectmanager.h>
|
||||
#include <gcsreceiver.h>
|
||||
#include <oplinksettings.h>
|
||||
#include <pios_rfm22b_rcvr.h>
|
||||
|
||||
// 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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
99
flight/PiOS/Common/pios_rfm22b_rcvr.c
Normal file
99
flight/PiOS/Common/pios_rfm22b_rcvr.c
Normal file
@ -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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -36,6 +36,7 @@
|
||||
#include <uavobjectmanager.h>
|
||||
#include <oplinkstatus.h>
|
||||
#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;
|
||||
};
|
||||
|
||||
|
||||
|
40
flight/PiOS/inc/pios_rfm22b_rcvr.h
Normal file
40
flight/PiOS/inc/pios_rfm22b_rcvr.h
Normal file
@ -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 */
|
@ -174,6 +174,9 @@
|
||||
#ifdef PIOS_INCLUDE_RFM22B_COM
|
||||
#include <pios_rfm22b_com.h>
|
||||
#endif
|
||||
#ifdef PIOS_INCLUDE_RFM22B_RCVR
|
||||
#include <pios_rfm22b_rcvr.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <pios_crc.h>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -3,7 +3,7 @@
|
||||
<description>Settings to indicate how to decode receiver input by @ref ManualControlModule.</description>
|
||||
<field name="ChannelGroups" units="Channel Group" type="enum"
|
||||
elementnames="Throttle,Roll,Pitch,Yaw,FlightMode,Collective,Accessory0,Accessory1,Accessory2"
|
||||
options="PWM,PPM,DSM (MainPort),DSM (FlexiPort),S.Bus,GCS,None" defaultvalue="None"/>
|
||||
options="PWM,PPM,DSM (MainPort),DSM (FlexiPort),S.Bus,GCS,OPLink,None" defaultvalue="None"/>
|
||||
<field name="ChannelNumber" units="channel" type="uint8" defaultvalue="0"
|
||||
elementnames="Throttle,Roll,Pitch,Yaw,FlightMode,Collective,Accessory0,Accessory1,Accessory2"/>
|
||||
<field name="ChannelMin" units="us" type="int16" defaultvalue="1000"
|
||||
|
@ -2,7 +2,7 @@
|
||||
<object name="ReceiverActivity" singleinstance="true" settings="false">
|
||||
<description>Monitors which receiver channels have been active within the last second.</description>
|
||||
<field name="ActiveGroup" units="Channel Group" type="enum" elements="1"
|
||||
options="PWM,PPM,DSM (MainPort),DSM (FlexiPort),S.Bus,GCS,None"
|
||||
options="PWM,PPM,DSM (MainPort),DSM (FlexiPort),S.Bus,GCS,OPLink,None"
|
||||
defaultvalue="None"/>
|
||||
<field name="ActiveChannel" units="channel" type="uint8" elements="1"
|
||||
defaultvalue="255"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user