mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 01:35:41 +03:00
Spektrum SRXL improvements. Collect TM data in sync with transmission instead of async 30Hz, performancs +50%. B-channel Cap/Cur/temp was visible even though not used, corrected. Incomplete compile conditions corrected. (#5556)
This commit is contained in:
parent
efef50ced1
commit
11e22e634f
5 changed files with 41 additions and 25 deletions
|
@ -633,7 +633,7 @@ void init(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_CMS) && defined(USE_SPEKTRUM_CMS_TELEMETRY)
|
#if defined(USE_CMS) && defined(USE_SPEKTRUM_CMS_TELEMETRY) && defined(USE_TELEMETRY_SRXL)
|
||||||
// Register the srxl Textgen telemetry sensor as a displayport device
|
// Register the srxl Textgen telemetry sensor as a displayport device
|
||||||
cmsDisplayPortRegister(displayPortSrxlInit());
|
cmsDisplayPortRegister(displayPortSrxlInit());
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#if defined (USE_SPEKTRUM_CMS_TELEMETRY) && defined (USE_CMS)
|
#if defined (USE_SPEKTRUM_CMS_TELEMETRY) && defined (USE_CMS) && defined(USE_TELEMETRY_SRXL)
|
||||||
|
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "io/spektrum_vtx_control.h"
|
#include "io/spektrum_vtx_control.h"
|
||||||
|
|
||||||
#include "telemetry/telemetry.h"
|
#include "telemetry/telemetry.h"
|
||||||
|
#include "telemetry/srxl.h"
|
||||||
|
|
||||||
#include "rx/rx.h"
|
#include "rx/rx.h"
|
||||||
#include "rx/spektrum.h"
|
#include "rx/spektrum.h"
|
||||||
|
@ -61,10 +62,13 @@ static volatile uint8_t spekFrame[SPEK_FRAME_SIZE];
|
||||||
static rxRuntimeConfig_t *rxRuntimeConfigPtr;
|
static rxRuntimeConfig_t *rxRuntimeConfigPtr;
|
||||||
static serialPort_t *serialPort;
|
static serialPort_t *serialPort;
|
||||||
|
|
||||||
|
#if defined(USE_TELEMETRY) && defined(USE_TELEMETRY_SRXL)
|
||||||
static uint8_t telemetryBuf[SRXL_FRAME_SIZE_MAX];
|
static uint8_t telemetryBuf[SRXL_FRAME_SIZE_MAX];
|
||||||
static uint8_t telemetryBufLen = 0;
|
static uint8_t telemetryBufLen = 0;
|
||||||
|
|
||||||
void srxlRxSendTelemetryDataDispatch(dispatchEntry_t *self);
|
void srxlRxSendTelemetryDataDispatch(dispatchEntry_t *self);
|
||||||
|
static dispatchEntry_t srxlTelemetryDispatch = { .dispatch = srxlRxSendTelemetryDataDispatch};
|
||||||
|
#endif
|
||||||
|
|
||||||
// Receive ISR callback
|
// Receive ISR callback
|
||||||
static void spektrumDataReceive(uint16_t c, void *data)
|
static void spektrumDataReceive(uint16_t c, void *data)
|
||||||
|
@ -95,7 +99,6 @@ static void spektrumDataReceive(uint16_t c, void *data)
|
||||||
|
|
||||||
|
|
||||||
uint32_t spekChannelData[SPEKTRUM_MAX_SUPPORTED_CHANNEL_COUNT];
|
uint32_t spekChannelData[SPEKTRUM_MAX_SUPPORTED_CHANNEL_COUNT];
|
||||||
static dispatchEntry_t srxlTelemetryDispatch = { .dispatch = srxlRxSendTelemetryDataDispatch};
|
|
||||||
|
|
||||||
static uint8_t spektrumFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
|
static uint8_t spektrumFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
|
||||||
{
|
{
|
||||||
|
@ -139,10 +142,21 @@ static uint8_t spektrumFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* only process if srxl enabled, some data in buffer AND servos in phase 0 */
|
#if defined(USE_TELEMETRY) && defined(USE_TELEMETRY_SRXL)
|
||||||
if (srxlEnabled && telemetryBufLen && (spekFrame[2] & 0x80) == 0) {
|
if (srxlEnabled) {
|
||||||
dispatchAdd(&srxlTelemetryDispatch, SPEKTRUM_TELEMETRY_FRAME_DELAY);
|
/* Only dispatch for transmission if there are some data in buffer AND servos in phase 0 */
|
||||||
|
if (telemetryBufLen && (spekFrame[2] & 0x80) == 0) {
|
||||||
|
dispatchAdd(&srxlTelemetryDispatch, SPEKTRUM_TELEMETRY_FRAME_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Trigger tm data collection if buffer has been sent and is empty,
|
||||||
|
so data will be ready to transmit in the next phase 0 */
|
||||||
|
if (telemetryBufLen == 0) {
|
||||||
|
srxlCollectTelemetryNow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return RX_FRAME_COMPLETE;
|
return RX_FRAME_COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,12 +232,12 @@ void spektrumBind(rxConfig_t *rxConfig)
|
||||||
// Take care half-duplex case
|
// Take care half-duplex case
|
||||||
switch (rxConfig->serialrx_provider) {
|
switch (rxConfig->serialrx_provider) {
|
||||||
case SERIALRX_SRXL:
|
case SERIALRX_SRXL:
|
||||||
#ifdef USE_TELEMETRY
|
#if defined(USE_TELEMETRY) && defined(USE_TELEMETRY_SRXL)
|
||||||
if (feature(FEATURE_TELEMETRY) && !telemetryCheckRxPortShared(portConfig)) {
|
if (feature(FEATURE_TELEMETRY) && !telemetryCheckRxPortShared(portConfig)) {
|
||||||
bindPin = txPin;
|
bindPin = txPin;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif // USE_TELEMETRY
|
#endif // USE_TELEMETRY && USE_TELEMETRY_SRXL
|
||||||
|
|
||||||
default:
|
default:
|
||||||
bindPin = rxConfig->halfDuplex ? txPin : rxPin;
|
bindPin = rxConfig->halfDuplex ? txPin : rxPin;
|
||||||
|
@ -294,7 +308,7 @@ bool spektrumInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
srxlEnabled = false;
|
srxlEnabled = false;
|
||||||
#ifdef USE_TELEMETRY
|
#if defined(USE_TELEMETRY) && defined(USE_TELEMETRY_SRXL)
|
||||||
bool portShared = telemetryCheckRxPortShared(portConfig);
|
bool portShared = telemetryCheckRxPortShared(portConfig);
|
||||||
#else
|
#else
|
||||||
bool portShared = false;
|
bool portShared = false;
|
||||||
|
@ -302,7 +316,7 @@ bool spektrumInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig
|
||||||
|
|
||||||
switch (rxConfig->serialrx_provider) {
|
switch (rxConfig->serialrx_provider) {
|
||||||
case SERIALRX_SRXL:
|
case SERIALRX_SRXL:
|
||||||
#ifdef USE_TELEMETRY
|
#if defined(USE_TELEMETRY) && defined(USE_TELEMETRY_SRXL)
|
||||||
srxlEnabled = (feature(FEATURE_TELEMETRY) && !portShared);
|
srxlEnabled = (feature(FEATURE_TELEMETRY) && !portShared);
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
#endif
|
#endif
|
||||||
|
@ -337,8 +351,7 @@ bool spektrumInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig
|
||||||
portShared || srxlEnabled ? MODE_RXTX : MODE_RX,
|
portShared || srxlEnabled ? MODE_RXTX : MODE_RX,
|
||||||
(rxConfig->serialrx_inverted ? SERIAL_INVERTED : 0) | ((srxlEnabled || rxConfig->halfDuplex) ? SERIAL_BIDIR : 0)
|
(rxConfig->serialrx_inverted ? SERIAL_INVERTED : 0) | ((srxlEnabled || rxConfig->halfDuplex) ? SERIAL_BIDIR : 0)
|
||||||
);
|
);
|
||||||
|
#if defined(USE_TELEMETRY) && defined(USE_TELEMETRY_SRXL)
|
||||||
#ifdef USE_TELEMETRY
|
|
||||||
if (portShared) {
|
if (portShared) {
|
||||||
telemetrySharedPort = serialPort;
|
telemetrySharedPort = serialPort;
|
||||||
}
|
}
|
||||||
|
@ -355,6 +368,7 @@ bool spektrumInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig
|
||||||
return serialPort != NULL;
|
return serialPort != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USE_TELEMETRY) && defined(USE_TELEMETRY_SRXL)
|
||||||
void srxlRxWriteTelemetryData(const void *data, int len)
|
void srxlRxWriteTelemetryData(const void *data, int len)
|
||||||
{
|
{
|
||||||
len = MIN(len, (int)sizeof(telemetryBuf));
|
len = MIN(len, (int)sizeof(telemetryBuf));
|
||||||
|
@ -371,6 +385,7 @@ void srxlRxSendTelemetryDataDispatch(dispatchEntry_t* self)
|
||||||
telemetryBufLen = 0; // reset telemetry buffer
|
telemetryBufLen = 0; // reset telemetry buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool srxlRxIsActive(void)
|
bool srxlRxIsActive(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
#ifdef USE_TELEMETRY
|
#if defined(USE_TELEMETRY) && defined(USE_TELEMETRY_SRXL)
|
||||||
|
|
||||||
#include "build/version.h"
|
#include "build/version.h"
|
||||||
|
|
||||||
|
@ -58,8 +58,6 @@
|
||||||
#include "io/vtx_tramp.h"
|
#include "io/vtx_tramp.h"
|
||||||
#include "io/vtx_smartaudio.h"
|
#include "io/vtx_smartaudio.h"
|
||||||
|
|
||||||
#define SRXL_CYCLETIME_US 33000 // 33ms, 30 Hz
|
|
||||||
|
|
||||||
#define SRXL_ADDRESS_FIRST 0xA5
|
#define SRXL_ADDRESS_FIRST 0xA5
|
||||||
#define SRXL_ADDRESS_SECOND 0x80
|
#define SRXL_ADDRESS_SECOND 0x80
|
||||||
#define SRXL_PACKET_LENGTH 0x15
|
#define SRXL_PACKET_LENGTH 0x15
|
||||||
|
@ -73,6 +71,13 @@
|
||||||
|
|
||||||
static bool srxlTelemetryEnabled;
|
static bool srxlTelemetryEnabled;
|
||||||
static uint8_t srxlFrame[SRXL_FRAME_SIZE_MAX];
|
static uint8_t srxlFrame[SRXL_FRAME_SIZE_MAX];
|
||||||
|
static bool srxlTelemetryNow = false;
|
||||||
|
|
||||||
|
void srxlCollectTelemetryNow(void)
|
||||||
|
{
|
||||||
|
srxlTelemetryNow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void srxlInitializeFrame(sbuf_t *dst)
|
static void srxlInitializeFrame(sbuf_t *dst)
|
||||||
{
|
{
|
||||||
|
@ -191,8 +196,8 @@ bool srxlFrameFlightPackCurrent(sbuf_t *dst, timeUs_t currentTimeUs)
|
||||||
sbufWriteU16(dst, amps);
|
sbufWriteU16(dst, amps);
|
||||||
sbufWriteU16(dst, mah);
|
sbufWriteU16(dst, mah);
|
||||||
sbufWriteU16(dst, 0x7fff); // temp A
|
sbufWriteU16(dst, 0x7fff); // temp A
|
||||||
sbufWriteU16(dst, 0xffff); // Amps B
|
sbufWriteU16(dst, 0x7fff); // Amps B
|
||||||
sbufWriteU16(dst, 0xffff); // mAH B
|
sbufWriteU16(dst, 0x7fff); // mAH B
|
||||||
sbufWriteU16(dst, 0x7fff); // temp B
|
sbufWriteU16(dst, 0x7fff); // temp B
|
||||||
sbufWriteU16(dst, 0xffff);
|
sbufWriteU16(dst, 0xffff);
|
||||||
|
|
||||||
|
@ -507,16 +512,11 @@ bool checkSrxlTelemetryState(void)
|
||||||
*/
|
*/
|
||||||
void handleSrxlTelemetry(timeUs_t currentTimeUs)
|
void handleSrxlTelemetry(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
static uint32_t srxlLastCycleTime;
|
if (!srxlTelemetryNow) {
|
||||||
|
|
||||||
if (!srxlTelemetryEnabled) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actual telemetry data only needs to be sent at a low frequency, ie 10Hz
|
srxlTelemetryNow = false;
|
||||||
if (currentTimeUs >= srxlLastCycleTime + SRXL_CYCLETIME_US) {
|
processSrxl(currentTimeUs);
|
||||||
srxlLastCycleTime = currentTimeUs;
|
|
||||||
processSrxl(currentTimeUs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "common/time.h"
|
#include "common/time.h"
|
||||||
|
|
||||||
|
void srxlCollectTelemetryNow(void);
|
||||||
void initSrxlTelemetry(void);
|
void initSrxlTelemetry(void);
|
||||||
bool checkSrxlTelemetryState(void);
|
bool checkSrxlTelemetryState(void);
|
||||||
void handleSrxlTelemetry(timeUs_t currentTimeUs);
|
void handleSrxlTelemetry(timeUs_t currentTimeUs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue