diff --git a/src/main/build/debug.h b/src/main/build/debug.h index 7f17cc34c5..69644af5d9 100644 --- a/src/main/build/debug.h +++ b/src/main/build/debug.h @@ -60,6 +60,5 @@ typedef enum { DEBUG_DTERM_FILTER, DEBUG_ANGLERATE, DEBUG_ESC_TELEMETRY, - DEBUG_CRSF, DEBUG_COUNT } debugType_e; diff --git a/src/main/rx/crsf.c b/src/main/rx/crsf.c index 8bf33c87f9..4e200934a2 100644 --- a/src/main/rx/crsf.c +++ b/src/main/rx/crsf.c @@ -39,8 +39,6 @@ #include "rx/rx.h" #include "rx/crsf.h" -#include "telemetry/telemetry.h" - #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 @@ -235,19 +233,7 @@ bool crsfRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig) return false; } -#if defined(TELEMETRY) && defined(TELEMETRY_CRSF) - 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 + serialPort = openSerialPort(portConfig->identifier, FUNCTION_RX_SERIAL, crsfDataReceive, CRSF_BAUDRATE, CRSF_PORT_MODE, CRSF_PORT_OPTIONS); return serialPort != NULL; } diff --git a/src/main/rx/crsf.h b/src/main/rx/crsf.h index f8154e15f0..2f69b260f6 100644 --- a/src/main/rx/crsf.h +++ b/src/main/rx/crsf.h @@ -19,6 +19,7 @@ #define CRSF_BAUDRATE 420000 #define CRSF_PORT_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO | SERIAL_BIDIR) +#define CRSF_PORT_MODE MODE_RXTX #define CRSF_MAX_CHANNEL 16 diff --git a/src/main/target/CC3D/target.h b/src/main/target/CC3D/target.h index c1149951e8..e57b5cbfa8 100644 --- a/src/main/target/CC3D/target.h +++ b/src/main/target/CC3D/target.h @@ -111,7 +111,6 @@ #undef MAG #ifdef CC3D_OPBL -#undef USE_SERIAL_4WAY_BLHELI_INTERFACE #define SKIP_CLI_COMMAND_HELP #undef BARO #undef SONAR diff --git a/src/main/target/NAZE/target.h b/src/main/target/NAZE/target.h index 33e6d9aa59..4eed345152 100644 --- a/src/main/target/NAZE/target.h +++ b/src/main/target/NAZE/target.h @@ -108,7 +108,7 @@ #define USE_BARO_BMP085 #define USE_BARO_BMP280 -//#define MAG +#define MAG #define USE_MAG_HMC5883 #define MAG_HMC5883_ALIGN CW180_DEG diff --git a/src/main/telemetry/crsf.c b/src/main/telemetry/crsf.c index 84345bbf50..41280b3008 100644 --- a/src/main/telemetry/crsf.c +++ b/src/main/telemetry/crsf.c @@ -64,12 +64,8 @@ #include "fc/config.h" #endif -#define TELEMETRY_CRSF_INITIAL_PORT_MODE MODE_RXTX -#define CRSF_CYCLETIME_US 100000 +#define CRSF_CYCLETIME_US 100000 // 100ms, 10 Hz -static serialPort_t *serialPort; -static serialPortConfig_t *serialPortConfig; -static portSharing_e portSharing; static bool crsfTelemetryEnabled; static uint8_t crsfCrc; static uint8_t crsfFrame[CRSF_FRAME_SIZE_MAX]; @@ -351,52 +347,23 @@ static void processCrsf(void) 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) { - serialPortConfig = findSerialPortConfig(FUNCTION_TELEMETRY_CRSF); - portSharing = determinePortSharing(serialPortConfig, FUNCTION_TELEMETRY_CRSF); -} + // check if there is a serial port open for CRSF telemetry (ie opened by the CRSF RX) + // 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) { - if (serialPortConfig && telemetryCheckRxPortShared(serialPortConfig)) { - 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; - } + return crsfTelemetryEnabled; } /* @@ -409,13 +376,12 @@ void handleCrsfTelemetry(uint32_t currentTime) if (!crsfTelemetryEnabled) { return; } - if (!serialPort) { - return; - } - - // give the receiver a change to send any outstanding telemetry data. + // Give the receiver a chance to send any outstanding telemetry data. + // This needs to be done at high frequency, to enable the RX to send the telemetry frame + // in between the RX frames. crsfRxSendTelemetryData(); + // Actual telemetry data only needs to be sent at a low frequency, ie 10Hz if (currentTime >= crsfLastCycleTime + CRSF_CYCLETIME_US) { crsfLastCycleTime = currentTime; processCrsf(); diff --git a/src/main/telemetry/telemetry.h b/src/main/telemetry/telemetry.h index 7a96631c3a..214722f12e 100644 --- a/src/main/telemetry/telemetry.h +++ b/src/main/telemetry/telemetry.h @@ -59,4 +59,4 @@ bool telemetryDetermineEnabledState(portSharing_e portSharing); 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)