1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 21:35:44 +03:00

Simplified CRSF telemetry port handling since sharing not required

This commit is contained in:
Martin Budden 2016-11-18 15:04:13 +00:00
parent e58d4bc0ad
commit 01c272d0ef
7 changed files with 21 additions and 70 deletions

View file

@ -60,6 +60,5 @@ typedef enum {
DEBUG_DTERM_FILTER, DEBUG_DTERM_FILTER,
DEBUG_ANGLERATE, DEBUG_ANGLERATE,
DEBUG_ESC_TELEMETRY, DEBUG_ESC_TELEMETRY,
DEBUG_CRSF,
DEBUG_COUNT DEBUG_COUNT
} debugType_e; } debugType_e;

View file

@ -39,8 +39,6 @@
#include "rx/rx.h" #include "rx/rx.h"
#include "rx/crsf.h" #include "rx/crsf.h"
#include "telemetry/telemetry.h"
#define CRSF_TIME_NEEDED_PER_FRAME_US 1000 #define CRSF_TIME_NEEDED_PER_FRAME_US 1000
#define CRSF_TIME_BETWEEN_FRAMES_US 4000 // a frame is sent by the transmitter every 4 milliseconds #define CRSF_TIME_BETWEEN_FRAMES_US 4000 // a frame is sent by the transmitter every 4 milliseconds
@ -235,19 +233,7 @@ bool crsfRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
return false; return false;
} }
#if defined(TELEMETRY) && defined(TELEMETRY_CRSF) serialPort = openSerialPort(portConfig->identifier, FUNCTION_RX_SERIAL, crsfDataReceive, CRSF_BAUDRATE, CRSF_PORT_MODE, CRSF_PORT_OPTIONS);
const bool portShared = telemetryCheckRxPortShared(portConfig);
#else
const bool portShared = false;
#endif
serialPort = openSerialPort(portConfig->identifier, FUNCTION_RX_SERIAL, crsfDataReceive, CRSF_BAUDRATE, portShared ? MODE_RXTX : MODE_RX, CRSF_PORT_OPTIONS);
#if defined(TELEMETRY) && defined(TELEMETRY_CRSF)
if (portShared) {
telemetrySharedPort = serialPort;
}
#endif
return serialPort != NULL; return serialPort != NULL;
} }

View file

@ -19,6 +19,7 @@
#define CRSF_BAUDRATE 420000 #define CRSF_BAUDRATE 420000
#define CRSF_PORT_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO | SERIAL_BIDIR) #define CRSF_PORT_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO | SERIAL_BIDIR)
#define CRSF_PORT_MODE MODE_RXTX
#define CRSF_MAX_CHANNEL 16 #define CRSF_MAX_CHANNEL 16

View file

@ -111,7 +111,6 @@
#undef MAG #undef MAG
#ifdef CC3D_OPBL #ifdef CC3D_OPBL
#undef USE_SERIAL_4WAY_BLHELI_INTERFACE
#define SKIP_CLI_COMMAND_HELP #define SKIP_CLI_COMMAND_HELP
#undef BARO #undef BARO
#undef SONAR #undef SONAR

View file

@ -108,7 +108,7 @@
#define USE_BARO_BMP085 #define USE_BARO_BMP085
#define USE_BARO_BMP280 #define USE_BARO_BMP280
//#define MAG #define MAG
#define USE_MAG_HMC5883 #define USE_MAG_HMC5883
#define MAG_HMC5883_ALIGN CW180_DEG #define MAG_HMC5883_ALIGN CW180_DEG

View file

@ -64,12 +64,8 @@
#include "fc/config.h" #include "fc/config.h"
#endif #endif
#define TELEMETRY_CRSF_INITIAL_PORT_MODE MODE_RXTX #define CRSF_CYCLETIME_US 100000 // 100ms, 10 Hz
#define CRSF_CYCLETIME_US 100000
static serialPort_t *serialPort;
static serialPortConfig_t *serialPortConfig;
static portSharing_e portSharing;
static bool crsfTelemetryEnabled; static bool crsfTelemetryEnabled;
static uint8_t crsfCrc; static uint8_t crsfCrc;
static uint8_t crsfFrame[CRSF_FRAME_SIZE_MAX]; static uint8_t crsfFrame[CRSF_FRAME_SIZE_MAX];
@ -351,52 +347,23 @@ static void processCrsf(void)
crsfScheduleIndex = (crsfScheduleIndex + 1) % CRSF_SCHEDULE_COUNT; crsfScheduleIndex = (crsfScheduleIndex + 1) % CRSF_SCHEDULE_COUNT;
} }
static void freeCrsfTelemetryPort(void)
{
closeSerialPort(serialPort);
serialPort = NULL;
crsfTelemetryEnabled = false;
}
static void configureCrsfTelemetryPort(void)
{
if (!serialPortConfig) {
return;
}
serialPort = openSerialPort(serialPortConfig->identifier, FUNCTION_TELEMETRY_CRSF, NULL, CRSF_BAUDRATE, TELEMETRY_CRSF_INITIAL_PORT_MODE, CRSF_PORT_OPTIONS);
if (!serialPort) {
return;
}
crsfTelemetryEnabled = true;
}
void initCrsfTelemetry(void) void initCrsfTelemetry(void)
{ {
serialPortConfig = findSerialPortConfig(FUNCTION_TELEMETRY_CRSF); // check if there is a serial port open for CRSF telemetry (ie opened by the CRSF RX)
portSharing = determinePortSharing(serialPortConfig, FUNCTION_TELEMETRY_CRSF); // if so, set CRSF telemetry enabled
} crsfTelemetryEnabled = false;
const serialPortConfig_t *serialPortConfig = findSerialPortConfig(FUNCTION_TELEMETRY_CRSF);
if (serialPortConfig) {
const serialPort_t *serialPort = openSerialPort(serialPortConfig->identifier, FUNCTION_TELEMETRY_CRSF, NULL, CRSF_BAUDRATE, CRSF_PORT_MODE, CRSF_PORT_OPTIONS);
if (serialPort) {
crsfTelemetryEnabled = true;
}
}
}
bool checkCrsfTelemetryState(void) bool checkCrsfTelemetryState(void)
{ {
if (serialPortConfig && telemetryCheckRxPortShared(serialPortConfig)) { return crsfTelemetryEnabled;
if (!crsfTelemetryEnabled && telemetrySharedPort != NULL) {
serialPort = telemetrySharedPort;
crsfTelemetryEnabled = true;
return true;
}
return false;
} else {
const bool newTelemetryEnabled = telemetryDetermineEnabledState(portSharing);
if (newTelemetryEnabled == crsfTelemetryEnabled) {
return false;
}
if (newTelemetryEnabled) {
configureCrsfTelemetryPort();
} else {
freeCrsfTelemetryPort();
}
return true;
}
} }
/* /*
@ -409,13 +376,12 @@ void handleCrsfTelemetry(uint32_t currentTime)
if (!crsfTelemetryEnabled) { if (!crsfTelemetryEnabled) {
return; return;
} }
if (!serialPort) { // Give the receiver a chance to send any outstanding telemetry data.
return; // This needs to be done at high frequency, to enable the RX to send the telemetry frame
} // in between the RX frames.
// give the receiver a change to send any outstanding telemetry data.
crsfRxSendTelemetryData(); crsfRxSendTelemetryData();
// Actual telemetry data only needs to be sent at a low frequency, ie 10Hz
if (currentTime >= crsfLastCycleTime + CRSF_CYCLETIME_US) { if (currentTime >= crsfLastCycleTime + CRSF_CYCLETIME_US) {
crsfLastCycleTime = currentTime; crsfLastCycleTime = currentTime;
processCrsf(); processCrsf();

View file

@ -59,4 +59,4 @@ bool telemetryDetermineEnabledState(portSharing_e portSharing);
void telemetryUseConfig(telemetryConfig_t *telemetryConfig); void telemetryUseConfig(telemetryConfig_t *telemetryConfig);
#define TELEMETRY_SHAREABLE_PORT_FUNCTIONS_MASK (FUNCTION_TELEMETRY_FRSKY | FUNCTION_TELEMETRY_LTM | FUNCTION_TELEMETRY_CRSF) #define TELEMETRY_SHAREABLE_PORT_FUNCTIONS_MASK (FUNCTION_TELEMETRY_FRSKY | FUNCTION_TELEMETRY_LTM)