1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 13:25:30 +03:00

Add constant option for A1 FrSky SPI (retry)

When using external XJT it annoyingly beeps when A1 drops below 3.7v (72 out of 255). I removed frsky_spi_use_external_adc and added frsky_spi_a1_source = VBAT, EXTADC, CONST. To prevent XJT from beeping ever set CONST and XJT will assume that the "reciever" is powered with 5v. I messed up previous PR #7305 branch so I decided that it's easier to open a new one.

Closes #7297
This commit is contained in:
vodka-bears 2019-01-11 10:22:30 +03:00
parent d8e8d8374d
commit c88db1a43a
6 changed files with 44 additions and 10 deletions

View file

@ -311,6 +311,12 @@ static const char * const lookupTableMax7456Clock[] = {
};
#endif
#ifdef USE_RX_FRSKY_SPI
static const char * const lookupTableFrskySpiA1Source[] = {
"VBAT", "EXTADC", "CONST"
};
#endif
#ifdef USE_GYRO_OVERFLOW_CHECK
static const char * const lookupTableGyroOverflowCheck[] = {
"OFF", "YAW", "ALL"
@ -473,6 +479,9 @@ const lookupTableEntry_t lookupTables[] = {
#ifdef USE_MAX7456
LOOKUP_TABLE_ENTRY(lookupTableMax7456Clock),
#endif
#ifdef USE_RX_FRSKY_SPI
LOOKUP_TABLE_ENTRY(lookupTableFrskySpiA1Source),
#endif
#ifdef USE_RANGEFINDER
LOOKUP_TABLE_ENTRY(lookupTableRangefinderHardware),
#endif
@ -1215,7 +1224,7 @@ const clivalue_t valueTable[] = {
{ "frsky_spi_offset", VAR_INT8 | MASTER_VALUE, .config.minmax = { -127, 127 }, PG_RX_FRSKY_SPI_CONFIG, offsetof(rxFrSkySpiConfig_t, bindOffset) },
{ "frsky_spi_bind_hop_data", VAR_UINT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = 50, PG_RX_FRSKY_SPI_CONFIG, offsetof(rxFrSkySpiConfig_t, bindHopData) },
{ "frsky_x_rx_num", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 255 }, PG_RX_FRSKY_SPI_CONFIG, offsetof(rxFrSkySpiConfig_t, rxNum) },
{ "frsky_spi_use_external_adc", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RX_FRSKY_SPI_CONFIG, offsetof(rxFrSkySpiConfig_t, useExternalAdc) },
{ "frsky_spi_a1_source", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_RX_FRSKY_SPI_A1_SOURCE }, PG_RX_FRSKY_SPI_CONFIG, offsetof(rxFrSkySpiConfig_t, a1Source) },
#endif
{ "led_inversion", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, ((1 << STATUS_LED_NUMBER) - 1) }, PG_STATUS_LED_CONFIG, offsetof(statusLedConfig_t, inversion) },
#ifdef USE_DASHBOARD

View file

@ -79,6 +79,9 @@ typedef enum {
#ifdef USE_MAX7456
TABLE_MAX7456_CLOCK,
#endif
#ifdef USE_RX_FRSKY_SPI
TABLE_RX_FRSKY_SPI_A1_SOURCE,
#endif
#ifdef USE_RANGEFINDER
TABLE_RANGEFINDER_HARDWARE,
#endif
@ -116,7 +119,7 @@ typedef enum {
TABLE_DYNAMIC_FILTER_RANGE,
#endif // USE_GYRO_DATA_ANALYSE
#ifdef USE_VTX_COMMON
TABLE_VTX_LOW_POWER_DISARM,
TABLE_VTX_LOW_POWER_DISARM,
#endif
TABLE_GYRO_HARDWARE,
#ifdef USE_SDCARD

View file

@ -24,13 +24,19 @@
#include "rx/rx_spi.h"
typedef enum {
FRSKY_SPI_A1_SOURCE_VBAT = 0,
FRSKY_SPI_A1_SOURCE_EXTADC,
FRSKY_SPI_A1_SOURCE_CONST
} frSkySpiA1Source_e;
typedef struct rxFrSkySpiConfig_s {
uint8_t autoBind;
uint8_t bindTxId[2];
int8_t bindOffset;
uint8_t bindHopData[50];
uint8_t rxNum;
uint8_t useExternalAdc;
uint8_t a1Source;
} rxFrSkySpiConfig_t;
PG_DECLARE(rxFrSkySpiConfig_t, rxFrSkySpiConfig);

View file

@ -66,6 +66,8 @@ static bool telemetryEnabled = false;
#define MAX_SERIAL_BYTES 64
#define A1_CONST_D 100
static uint8_t telemetryBytesGenerated;
static uint8_t serialBuffer[MAX_SERIAL_BYTES]; // buffer for telemetry serial data
@ -113,10 +115,16 @@ static void frSkyDTelemetryWriteByte(const char data)
static void buildTelemetryFrame(uint8_t *packet)
{
uint8_t a1Value;
if (rxFrSkySpiConfig()->useExternalAdc) {
a1Value = (adcGetChannel(ADC_EXTERNAL1) & 0xff0) >> 4;
} else {
switch (rxFrSkySpiConfig()->a1Source) {
case FRSKY_SPI_A1_SOURCE_VBAT:
a1Value = (getBatteryVoltage() / 5) & 0xff;
break;
case FRSKY_SPI_A1_SOURCE_EXTADC:
a1Value = (adcGetChannel(ADC_EXTERNAL1) & 0xff0) >> 4;
break;
case FRSKY_SPI_A1_SOURCE_CONST:
a1Value = A1_CONST_D & 0xff;
break;
}
const uint8_t a2Value = (adcGetChannel(ADC_RSSI)) >> 4;
telemetryId = packet[4];

View file

@ -79,7 +79,7 @@ PG_RESET_TEMPLATE(rxFrSkySpiConfig_t, rxFrSkySpiConfig,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
.rxNum = 0,
.useExternalAdc = false,
.a1Source = FRSKY_SPI_A1_SOURCE_VBAT,
);
static void initialise() {

View file

@ -97,6 +97,8 @@ const uint16_t crcTable[] = {
#define TELEMETRY_SEQUENCE_LENGTH 4
#define A1_CONST_X 50
typedef struct telemetrySequenceMarkerData_s {
unsigned int packetSequenceId: 2;
unsigned int unused: 1;
@ -197,10 +199,16 @@ static void buildTelemetryFrame(uint8_t *packet)
frame[4] = (uint8_t)cc2500getRssiDbm() | 0x80;
} else {
uint8_t a1Value;
if (rxFrSkySpiConfig()->useExternalAdc) {
a1Value = (uint8_t)((adcGetChannel(ADC_EXTERNAL1) & 0xfe0) >> 5);
} else {
switch (rxFrSkySpiConfig()->a1Source) {
case FRSKY_SPI_A1_SOURCE_VBAT:
a1Value = getLegacyBatteryVoltage() & 0x7f;
break;
case FRSKY_SPI_A1_SOURCE_EXTADC:
a1Value = (uint8_t)((adcGetChannel(ADC_EXTERNAL1) & 0xfe0) >> 5);
break;
case FRSKY_SPI_A1_SOURCE_CONST:
a1Value = A1_CONST_X & 0x7f;
break;
}
frame[4] = a1Value;
}