mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 06:15:16 +03:00
de-duplicate failsafe code. extract failsafe code to seperate files.
remove dependency on board.h and mw.h on a few files. Moved rx configuration paramaters into rxConfig in order to remove the dependency on config_t from the sbus rx code - sumd/spektrum to follow. Avoided use of YAW/PITCH/ROLL in some files since those constants are from an unrelated enum type. Replaced some magic numbers with constants to remove comments and improve code readability. Note, due to the tight coupling and global variable usage it was difficult to create a smaller commit.
This commit is contained in:
parent
d7eb416aa9
commit
0f02e12f40
26 changed files with 606 additions and 437 deletions
59
src/rx_common.c
Normal file
59
src/rx_common.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "rx_common.h"
|
||||
#include "config.h"
|
||||
|
||||
// FIXME all includes below are just for pwmReadRawRC because it uses mcfg
|
||||
#ifdef FY90Q
|
||||
#include "drivers/pwm_fy90q.h"
|
||||
#else
|
||||
#include "drivers/pwm_common.h"
|
||||
#endif
|
||||
|
||||
|
||||
int16_t rcData[RC_CHANS]; // interval [1000;2000]
|
||||
|
||||
rcReadRawDataPtr rcReadRawFunc = NULL; // receive data from default (pwm/ppm) or additional (spek/sbus/?? receiver drivers)
|
||||
|
||||
uint16_t pwmReadRawRC(rxConfig_t *rxConfig, uint8_t chan)
|
||||
{
|
||||
uint16_t data;
|
||||
|
||||
data = pwmRead(rxConfig->rcmap[chan]);
|
||||
if (data < 750 || data > 2250)
|
||||
data = rxConfig->midrc;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void computeRC(rxConfig_t *rxConfig)
|
||||
{
|
||||
uint8_t chan;
|
||||
|
||||
if (feature(FEATURE_SERIALRX)) {
|
||||
for (chan = 0; chan < 8; chan++)
|
||||
rcData[chan] = rcReadRawFunc(rxConfig, chan);
|
||||
} else {
|
||||
static int16_t rcData4Values[8][4], rcDataMean[8];
|
||||
static uint8_t rc4ValuesIndex = 0;
|
||||
uint8_t a;
|
||||
|
||||
rc4ValuesIndex++;
|
||||
for (chan = 0; chan < 8; chan++) {
|
||||
rcData4Values[chan][rc4ValuesIndex % 4] = rcReadRawFunc(rxConfig, chan);
|
||||
rcDataMean[chan] = 0;
|
||||
for (a = 0; a < 4; a++)
|
||||
rcDataMean[chan] += rcData4Values[chan][a];
|
||||
|
||||
rcDataMean[chan] = (rcDataMean[chan] + 2) / 4;
|
||||
if (rcDataMean[chan] < rcData[chan] - 3)
|
||||
rcData[chan] = rcDataMean[chan] + 2;
|
||||
if (rcDataMean[chan] > rcData[chan] + 3)
|
||||
rcData[chan] = rcDataMean[chan] - 2;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue