Skip to content

Commit

Permalink
MSP VTX device (#2007)
Browse files Browse the repository at this point in the history
* MSP VTX device

* switched band and channel structure to arrays

* fixed PWM output

* Checking only RX bit in serial config

* Refactored frequency table to common place, fixed lowband frequencies

* Fix compilation error after master merge

Also changed to use CRSF in a static way

* Fix the unit tests after the master merge

* fixes to pit mode

---------

Co-authored-by: Paul Kendall <pkendall64@gmail.com>
Co-authored-by: Jye <14170229+JyeSmith@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 26, 2023
1 parent f06d2dd commit a005e31
Show file tree
Hide file tree
Showing 22 changed files with 702 additions and 81 deletions.
Binary file added src/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions src/hardware/RX/Generic 2400 True Diversity PA and VTx.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"vtx_amp_vpd": 4,
"vtx_amp_vref": 2,

"vtx_amp_vpd_25mW": [1350,1350,1350,1350],
"vtx_amp_vpd_100mW": [1600,1600,1600,1600],
"vtx_amp_vpd_25mW": [600,600,600,600],
"vtx_amp_vpd_100mW": [1500,1500,1500,1500],

"button": 0
}
4 changes: 2 additions & 2 deletions src/hardware/RX/Generic 2400 True Diversity and VTx.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"vtx_amp_vpd": 4,
"vtx_amp_vref": 2,

"vtx_amp_vpd_25mW": [1350,1350,1350,1350],
"vtx_amp_vpd_100mW": [1600,1600,1600,1600],
"vtx_amp_vpd_25mW": [600,600,600,600],
"vtx_amp_vpd_100mW": [1500,1500,1500,1500],

"button": 0
}
4 changes: 2 additions & 2 deletions src/hardware/RX/Generic 2400 Whoop Rx and VTx.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"vtx_amp_vpd": 4,
"vtx_amp_vref": 2,

"vtx_amp_vpd_25mW": [1350,1350,1350,1350],
"vtx_amp_vpd_100mW": [1600,1600,1600,1600],
"vtx_amp_vpd_25mW": [600,600,600,600],
"vtx_amp_vpd_100mW": [1500,1500,1500,1500],

"button": 0
}
1 change: 1 addition & 0 deletions src/include/target/Unified_ESP_RX.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@

// VTX
#define HAS_VTX_SPI
#define HAS_MSP_VTX
#define OPT_HAS_VTX_SPI (hardware_pin(HARDWARE_vtx_nss) != UNDEF_PIN)
#define GPIO_PIN_RF_AMP_PWM hardware_pin(HARDWARE_vtx_amp_pwm)
#define GPIO_PIN_RF_AMP_VPD hardware_pin(HARDWARE_vtx_amp_vpd)
Expand Down
1 change: 1 addition & 0 deletions src/include/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#if defined(GPIO_PIN_SPI_VTX_NSS)
#if !defined(HAS_VTX_SPI)
#define HAS_VTX_SPI
#define HAS_MSP_VTX
#define OPT_HAS_VTX_SPI true
#endif
#else
Expand Down
13 changes: 13 additions & 0 deletions src/lib/CRSF/CRSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,19 @@ void CRSF::GetDeviceInformation(uint8_t *frame, uint8_t fieldCount)
device->parameterVersion = 0;
}

void CRSF::SetMspV2Request(uint8_t *frame, uint16_t function, uint8_t *payload, uint8_t payloadLength)
{
uint8_t *packet = (uint8_t *)(frame + sizeof(crsf_ext_header_t));
packet[0] = 0x50; // no error, version 2, beginning of the frame, first frame (0)
packet[1] = 0; // flags
packet[2] = function & 0xFF;
packet[3] = (function >> 8) & 0xFF;
packet[4] = payloadLength & 0xFF;
packet[5] = (payloadLength >> 8) & 0xFF;
memcpy(packet + 6, payload, payloadLength);
packet[6 + payloadLength] = CalcCRCMsp(packet + 1, payloadLength + 5); // crc = flags + function + length + payload
}

void CRSF::SetHeaderAndCrc(uint8_t *frame, uint8_t frameType, uint8_t frameSize, uint8_t destAddr)
{
crsf_header_t *header = (crsf_header_t *)frame;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/CRSF/CRSF.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CRSF
static void End(); //stop timers etc

static void GetDeviceInformation(uint8_t *frame, uint8_t fieldCount);
static void SetMspV2Request(uint8_t *frame, uint16_t function, uint8_t *payload, uint8_t payloadLength);
static void SetHeaderAndCrc(uint8_t *frame, uint8_t frameType, uint8_t frameSize, uint8_t destAddr);
static void SetExtendedHeaderAndCrc(uint8_t *frame, uint8_t frameType, uint8_t frameSize, uint8_t senderAddr, uint8_t destAddr);
static uint32_t VersionStrToU32(const char *verStr);
Expand All @@ -66,8 +67,6 @@ class CRSF

static void packetQueueExtended(uint8_t type, void *data, uint8_t len);

static void ICACHE_RAM_ATTR sendSetVTXchannel(uint8_t band, uint8_t channel);

///// Variables for OpenTX Syncing //////////////////////////
#define OpenTXsyncPacketInterval 200 // in ms
static void ICACHE_RAM_ATTR setSyncParams(int32_t PacketInterval);
Expand Down
44 changes: 44 additions & 0 deletions src/lib/CrsfProtocol/crsf_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,50 @@ typedef struct deviceInformationPacket_s
#define DEVICE_INFORMATION_LENGTH (sizeof(crsf_ext_header_t) + DEVICE_INFORMATION_PAYLOAD_LENGTH + CRSF_FRAME_CRC_SIZE)
#define DEVICE_INFORMATION_FRAME_SIZE (DEVICE_INFORMATION_PAYLOAD_LENGTH + CRSF_FRAME_LENGTH_EXT_TYPE_CRC)

// https://github.com/betaflight/betaflight/blob/master/src/main/msp/msp.c#L1949
typedef struct mspVtxConfigPacket_s
{
uint8_t vtxType;
uint8_t band;
uint8_t channel;
uint8_t power;
uint8_t pitmode;
uint16_t freq;
uint8_t deviceIsReady;
uint8_t lowPowerDisarm;
uint16_t pitModeFreq;
uint8_t vtxTableAvailable;
uint8_t bands;
uint8_t channels;
uint8_t powerLevels;
} PACKED mspVtxConfigPacket_t;

typedef struct mspVtxPowerLevelPacket_s
{
uint8_t powerLevel;
uint16_t powerValue;
uint8_t powerLabelLength;
uint8_t label[3];
} PACKED mspVtxPowerLevelPacket_t;

typedef struct mspVtxBandPacket_s
{
uint8_t band;
uint8_t bandNameLength;
uint8_t bandName[8];
uint8_t bandLetter;
uint8_t isFactoryBand;
uint8_t channels;
uint16_t channel[8];
} PACKED mspVtxBandPacket_t;

#define MSP_REQUEST_PAYLOAD_LENGTH(len) 7 + len // status + flags + 2 function + 2 length + crc + payload
#define MSP_REQUEST_LENGTH(len) (sizeof(crsf_ext_header_t) + MSP_REQUEST_PAYLOAD_LENGTH(len) + CRSF_FRAME_CRC_SIZE)
#define MSP_REQUEST_FRAME_SIZE(len) (MSP_REQUEST_PAYLOAD_LENGTH(len) + CRSF_FRAME_LENGTH_EXT_TYPE_CRC)

#define MSP_SET_VTX_CONFIG_PAYLOAD_LENGTH 15
#define MSP_SET_VTXTABLE_BAND_PAYLOAD_LENGTH 29
#define MSP_SET_VTXTABLE_POWERLEVEL_PAYLOAD_LENGTH 7
/**
* Union to allow accessing the input buffer as different data shapes
* without generating compiler warnings (and relying on undefined C++ behaviour!)
Expand Down
7 changes: 7 additions & 0 deletions src/lib/MSP/msptypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#define MSP_SET_RX_CONFIG 45
#define MSP_VTX_CONFIG 88 //out message Get vtx settings - betaflight
#define MSP_SET_VTX_CONFIG 89 //in message Set vtx settings - betaflight

#define MSP_VTXTABLE_BAND 137 //out message vtxTable band/channel data
#define MSP_SET_VTXTABLE_BAND 227 //in message set vtxTable band/channel data (one band at a time)

#define MSP_VTXTABLE_POWERLEVEL 138 //out message vtxTable powerLevel data
#define MSP_SET_VTXTABLE_POWERLEVEL 228 //in message set vtxTable powerLevel data (one powerLevel at a time)

#define MSP_EEPROM_WRITE 250 //in message no param

// ELRS specific opcodes
Expand Down

0 comments on commit a005e31

Please sign in to comment.