Merge pull request #1 from betaflight/master

align with master
This commit is contained in:
Nick Bate 2020-05-09 20:57:32 +01:00 committed by GitHub
commit 8c57ae7252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 104 additions and 21 deletions

View File

@ -107,6 +107,7 @@ COMMON_SRC = \
rx/jetiexbus.c \ rx/jetiexbus.c \
rx/msp.c \ rx/msp.c \
rx/pwm.c \ rx/pwm.c \
rx/frsky_crc.c \
rx/rx.c \ rx/rx.c \
rx/rx_bind.c \ rx/rx_bind.c \
rx/rx_spi.c \ rx/rx_spi.c \
@ -255,6 +256,7 @@ SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
rx/rx.c \ rx/rx.c \
rx/rx_spi.c \ rx/rx_spi.c \
rx/crsf.c \ rx/crsf.c \
rx/frsky_crc.c \
rx/sbus.c \ rx/sbus.c \
rx/sbus_channels.c \ rx/sbus_channels.c \
rx/spektrum.c \ rx/spektrum.c \
@ -361,6 +363,7 @@ ifneq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \ SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
drivers/bus_i2c_hal.c \ drivers/bus_i2c_hal.c \
drivers/bus_spi_ll.c \ drivers/bus_spi_ll.c \
rx/frsky_crc.c \
drivers/max7456.c \ drivers/max7456.c \
drivers/pwm_output_dshot.c \ drivers/pwm_output_dshot.c \
drivers/pwm_output_dshot_shared.c \ drivers/pwm_output_dshot_shared.c \

View File

@ -1015,7 +1015,7 @@ const clivalue_t valueTable[] = {
{ "pid_at_min_throttle", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_PID_PROFILE, offsetof(pidProfile_t, pidAtMinThrottle) }, { "pid_at_min_throttle", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_PID_PROFILE, offsetof(pidProfile_t, pidAtMinThrottle) },
{ "anti_gravity_mode", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_ANTI_GRAVITY_MODE }, PG_PID_PROFILE, offsetof(pidProfile_t, antiGravityMode) }, { "anti_gravity_mode", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_ANTI_GRAVITY_MODE }, PG_PID_PROFILE, offsetof(pidProfile_t, antiGravityMode) },
{ "anti_gravity_threshold", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 20, 1000 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermThrottleThreshold) }, { "anti_gravity_threshold", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 20, 1000 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermThrottleThreshold) },
{ "anti_gravity_gain", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 1000, 30000 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermAcceleratorGain) }, { "anti_gravity_gain", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { ITERM_ACCELERATOR_GAIN_OFF, ITERM_ACCELERATOR_GAIN_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, itermAcceleratorGain) },
{ "feedforward_transition", VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, feedForwardTransition) }, { "feedforward_transition", VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, feedForwardTransition) },
{ "acc_limit_yaw", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, yawRateAccelLimit) }, { "acc_limit_yaw", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, yawRateAccelLimit) },
{ "acc_limit", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, rateAccelLimit) }, { "acc_limit", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, rateAccelLimit) },

View File

@ -487,7 +487,7 @@ static const OSD_Entry cmsx_menuProfileOtherEntries[] = {
{ "ANGLE STR", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_angleStrength, 0, 200, 1 } , 0 }, { "ANGLE STR", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_angleStrength, 0, 200, 1 } , 0 },
{ "HORZN STR", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_horizonStrength, 0, 200, 1 } , 0 }, { "HORZN STR", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_horizonStrength, 0, 200, 1 } , 0 },
{ "HORZN TRS", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_horizonTransition, 0, 200, 1 } , 0 }, { "HORZN TRS", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_horizonTransition, 0, 200, 1 } , 0 },
{ "AG GAIN", OME_UINT16, NULL, &(OSD_UINT16_t) { &cmsx_itermAcceleratorGain, 1000, 30000, 10 } , 0 }, { "AG GAIN", OME_UINT16, NULL, &(OSD_UINT16_t) { &cmsx_itermAcceleratorGain, ITERM_ACCELERATOR_GAIN_OFF, ITERM_ACCELERATOR_GAIN_MAX, 10 } , 0 },
{ "AG THR", OME_UINT16, NULL, &(OSD_UINT16_t) { &cmsx_itermThrottleThreshold, 20, 1000, 1 } , 0 }, { "AG THR", OME_UINT16, NULL, &(OSD_UINT16_t) { &cmsx_itermThrottleThreshold, 20, 1000, 1 } , 0 },
#ifdef USE_THROTTLE_BOOST #ifdef USE_THROTTLE_BOOST
{ "THR BOOST", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_throttleBoost, 0, 100, 1 } , 0 }, { "THR BOOST", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_throttleBoost, 0, 100, 1 } , 0 },

View File

@ -51,6 +51,8 @@
// Anti gravity I constant // Anti gravity I constant
#define AG_KI 21.586988f; #define AG_KI 21.586988f;
#define ITERM_ACCELERATOR_GAIN_OFF 1000
#define ITERM_ACCELERATOR_GAIN_MAX 30000
typedef enum { typedef enum {
PID_ROLL, PID_ROLL,
PID_PITCH, PID_PITCH,

View File

@ -34,6 +34,7 @@
#include "fc/runtime_config.h" #include "fc/runtime_config.h"
#include "flight/mixer.h" #include "flight/mixer.h"
#include "flight/pid.h"
#include "sensors/sensors.h" #include "sensors/sensors.h"
@ -184,7 +185,13 @@ void initActiveBoxIds(void)
BME(BOXAIRMODE); BME(BOXAIRMODE);
} }
if (!featureIsEnabled(FEATURE_ANTI_GRAVITY)) { bool acceleratorGainsEnabled = false;
for (unsigned i = 0; i < PID_PROFILE_COUNT; i++) {
if (pidProfiles(i)->itermAcceleratorGain != ITERM_ACCELERATOR_GAIN_OFF) {
acceleratorGainsEnabled = true;
}
}
if (acceleratorGainsEnabled && !featureIsEnabled(FEATURE_ANTI_GRAVITY)) {
BME(BOXANTIGRAVITY); BME(BOXANTIGRAVITY);
} }

View File

@ -43,6 +43,7 @@
#include "pg/rx.h" #include "pg/rx.h"
#include "rx/frsky_crc.h"
#include "rx/rx.h" #include "rx/rx.h"
#include "rx/sbus_channels.h" #include "rx/sbus_channels.h"
#include "rx/fport.h" #include "rx/fport.h"
@ -61,8 +62,6 @@
#define FPORT_ESCAPE_CHAR 0x7D #define FPORT_ESCAPE_CHAR 0x7D
#define FPORT_ESCAPE_MASK 0x20 #define FPORT_ESCAPE_MASK 0x20
#define FPORT_CRC_VALUE 0xFF
#define FPORT_BAUDRATE 115200 #define FPORT_BAUDRATE 115200
#define FPORT_PORT_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO) #define FPORT_PORT_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO)
@ -245,18 +244,6 @@ static void smartPortWriteFrameFport(const smartPortPayload_t *payload)
} }
#endif #endif
static bool checkChecksum(uint8_t *data, uint8_t length)
{
uint16_t checksum = 0;
for (unsigned i = 0; i < length; i++) {
checksum = checksum + *(uint8_t *)(data + i);
}
checksum = (checksum & 0xff) + (checksum >> 8);
return checksum == FPORT_CRC_VALUE;
}
static uint8_t fportFrameStatus(rxRuntimeState_t *rxRuntimeState) static uint8_t fportFrameStatus(rxRuntimeState_t *rxRuntimeState)
{ {
static bool hasTelemetryRequest = false; static bool hasTelemetryRequest = false;
@ -276,7 +263,7 @@ static uint8_t fportFrameStatus(rxRuntimeState_t *rxRuntimeState)
if (frameLength != bufferLength - 2) { if (frameLength != bufferLength - 2) {
reportFrameError(DEBUG_FPORT_ERROR_SIZE); reportFrameError(DEBUG_FPORT_ERROR_SIZE);
} else { } else {
if (!checkChecksum(&rxBuffer[rxBufferReadIndex].data[0], bufferLength)) { if (!frskyCheckSumIsGood(&rxBuffer[rxBufferReadIndex].data[0], bufferLength)) {
reportFrameError(DEBUG_FPORT_ERROR_CHECKSUM); reportFrameError(DEBUG_FPORT_ERROR_CHECKSUM);
} else { } else {
fportFrame_t *frame = (fportFrame_t *)&rxBuffer[rxBufferReadIndex].data[1]; fportFrame_t *frame = (fportFrame_t *)&rxBuffer[rxBufferReadIndex].data[1];

56
src/main/rx/frsky_crc.c Normal file
View File

@ -0,0 +1,56 @@
/*
* This file is part of Cleanflight and Betaflight.
*
* Cleanflight and Betaflight are free software. You can redistribute
* this software and/or modify this software 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.
*
* Cleanflight and Betaflight are distributed in the hope that they
* 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 software.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "rx/frsky_crc.h"
void frskyCheckSumStep(uint16_t *checksum, uint8_t byte)
{
*checksum += byte;
}
void frskyCheckSumFini(uint16_t *checksum)
{
while (*checksum > 0xFF) {
*checksum = (*checksum & 0xFF) + (*checksum >> 8);
}
*checksum = 0xFF - *checksum;
}
static uint8_t frskyCheckSum(uint8_t *data, uint8_t length)
{
uint16_t checksum = 0;
for (unsigned i = 0; i < length; i++) {
frskyCheckSumStep(&checksum, *data++);
}
frskyCheckSumFini(&checksum);
return checksum;
}
bool frskyCheckSumIsGood(uint8_t *data, uint8_t length)
{
uint16_t checksum = frskyCheckSum(data, length);
return checksum == 0xFF;
}

26
src/main/rx/frsky_crc.h Normal file
View File

@ -0,0 +1,26 @@
/*
* This file is part of Cleanflight and Betaflight.
*
* Cleanflight and Betaflight are free software. You can redistribute
* this software and/or modify this software 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.
*
* Cleanflight and Betaflight are distributed in the hope that they
* 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 software.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
bool frskyCheckSumIsGood(uint8_t *data, uint8_t length);
void frskyCheckSumStep(uint16_t *checksum, uint8_t byte); // Add byte to checksum
void frskyCheckSumFini(uint16_t *checksum); // Finalize checksum

View File

@ -39,6 +39,8 @@
#include "config/feature.h" #include "config/feature.h"
#include "rx/frsky_crc.h"
#include "drivers/accgyro/accgyro.h" #include "drivers/accgyro/accgyro.h"
#include "drivers/compass/compass.h" #include "drivers/compass/compass.h"
#include "drivers/sensor.h" #include "drivers/sensor.h"
@ -285,7 +287,7 @@ void smartPortSendByte(uint8_t c, uint16_t *checksum, serialPort_t *port)
} }
if (checksum != NULL) { if (checksum != NULL) {
*checksum += c; frskyCheckSumStep(checksum, c);
} }
} }
@ -300,8 +302,8 @@ void smartPortWriteFrameSerial(const smartPortPayload_t *payload, serialPort_t *
for (unsigned i = 0; i < sizeof(smartPortPayload_t); i++) { for (unsigned i = 0; i < sizeof(smartPortPayload_t); i++) {
smartPortSendByte(*data++, &checksum, port); smartPortSendByte(*data++, &checksum, port);
} }
checksum = 0xff - ((checksum & 0xff) + (checksum >> 8)); frskyCheckSumFini(&checksum);
smartPortSendByte((uint8_t)checksum, NULL, port); smartPortSendByte(checksum, NULL, port);
} }
static void smartPortWriteFrameInternal(const smartPortPayload_t *payload) static void smartPortWriteFrameInternal(const smartPortPayload_t *payload)