mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 22:35:23 +03:00
Add special failsafe handling for PPM whilst still keeping failsafe code
out of the PWM RX driver.
This commit is contained in:
parent
910d63a722
commit
d1be2ed5e2
3 changed files with 32 additions and 2 deletions
|
@ -45,6 +45,21 @@ static pwmInputPort_t pwmInputPorts[PWM_INPUT_PORT_COUNT];
|
|||
|
||||
static uint16_t captures[PWM_PORTS_OR_PPM_CAPTURE_COUNT];
|
||||
|
||||
static uint8_t ppmFrameCount = 0;
|
||||
|
||||
static uint8_t lastPPMFrameCount = 0;
|
||||
bool isPPMDataBeingReceived(void)
|
||||
{
|
||||
return (ppmFrameCount != lastPPMFrameCount);
|
||||
}
|
||||
|
||||
void resetPPMDataReceivedState(void)
|
||||
{
|
||||
lastPPMFrameCount = ppmFrameCount;
|
||||
}
|
||||
|
||||
#define MIN_CHANNELS_BEFORE_PPM_FRAME_CONSIDERED_VALID 4
|
||||
|
||||
static void ppmCallback(uint8_t port, captureCompare_t capture)
|
||||
{
|
||||
int32_t diff;
|
||||
|
@ -58,6 +73,9 @@ static void ppmCallback(uint8_t port, captureCompare_t capture)
|
|||
diff = now - last;
|
||||
|
||||
if (diff > 2700) { // Per http://www.rcgroups.com/forums/showpost.php?p=21996147&postcount=3960 "So, if you use 2.5ms or higher as being the reset for the PPM stream start, you will be fine. I use 2.7ms just to be safe."
|
||||
if (chan >= MIN_CHANNELS_BEFORE_PPM_FRAME_CONSIDERED_VALID) {
|
||||
ppmFrameCount++;
|
||||
}
|
||||
chan = 0;
|
||||
} else {
|
||||
if (chan < PPM_CAPTURE_COUNT) {
|
||||
|
@ -65,6 +83,7 @@ static void ppmCallback(uint8_t port, captureCompare_t capture)
|
|||
}
|
||||
chan++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void pwmCallback(uint8_t port, captureCompare_t capture)
|
||||
|
|
|
@ -5,3 +5,5 @@ void pwmInConfig(uint8_t timerIndex, uint8_t channel);
|
|||
|
||||
uint16_t pwmRead(uint8_t channel);
|
||||
|
||||
bool isPPMDataBeingReceived(void);
|
||||
void resetPPMDataReceivedState(void);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "failsafe.h"
|
||||
|
||||
#include "drivers/pwm_rx.h"
|
||||
#include "rx_pwm.h"
|
||||
#include "rx_sbus.h"
|
||||
#include "rx_spektrum.h"
|
||||
|
@ -166,7 +167,7 @@ bool shouldProcessRx(uint32_t currentTime)
|
|||
}
|
||||
|
||||
static bool isRxDataDriven(void) {
|
||||
return !(feature(FEATURE_RX_PARALLEL_PWM) || feature(FEATURE_RX_PPM));
|
||||
return !(feature(FEATURE_RX_PARALLEL_PWM | FEATURE_RX_PPM));
|
||||
}
|
||||
|
||||
static uint8_t rcSampleIndex = 0;
|
||||
|
@ -192,6 +193,14 @@ uint16_t calculateNonDataDrivenChannel(uint8_t chan, uint16_t sample)
|
|||
void processRxChannels(void)
|
||||
{
|
||||
uint8_t chan;
|
||||
|
||||
bool shouldCheckPulse = true;
|
||||
|
||||
if (feature(FEATURE_FAILSAFE | FEATURE_RX_PPM)) {
|
||||
shouldCheckPulse = isPPMDataBeingReceived();
|
||||
resetPPMDataReceivedState();
|
||||
}
|
||||
|
||||
for (chan = 0; chan < rxRuntimeConfig.channelCount; chan++) {
|
||||
|
||||
if (!rcReadRawFunc) {
|
||||
|
@ -204,7 +213,7 @@ void processRxChannels(void)
|
|||
// sample the channel
|
||||
uint16_t sample = rcReadRawFunc(&rxRuntimeConfig, rawChannel);
|
||||
|
||||
if (feature(FEATURE_FAILSAFE)) {
|
||||
if (feature(FEATURE_FAILSAFE) && shouldCheckPulse) {
|
||||
failsafe->vTable->checkPulse(rawChannel, sample);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue