Skip to content

Commit

Permalink
Add constant option for A1 FrSky SPI (retry)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vodka-bears committed Jan 11, 2019
1 parent d8e8d83 commit c88db1a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/main/interface/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/main/interface/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/main/rx/cc2500_frsky_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 11 additions & 3 deletions src/main/rx/cc2500_frsky_d.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/main/rx/cc2500_frsky_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 11 additions & 3 deletions src/main/rx/cc2500_frsky_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c88db1a

Please sign in to comment.