Split crsf protocol into interface directory

This commit is contained in:
Martin Budden 2017-11-12 16:00:18 +00:00
parent fbbe82591e
commit d96f9ed2b7
7 changed files with 100 additions and 70 deletions

View File

@ -0,0 +1,76 @@
/*
* Crossfire constants provided by Team Black Sheep under terms of the 2-Clause BSD License
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#define CRSF_BAUDRATE 420000
enum { CRSF_SYNC_BYTE = 0xC8 };
enum { CRSF_FRAME_SIZE_MAX = 64 }; // 62 bytes frame plus 2 bytes frame header(<length><type>)
enum { CRSF_PAYLOAD_SIZE_MAX = CRSF_FRAME_SIZE_MAX - 6 };
typedef enum {
CRSF_FRAMETYPE_GPS = 0x02,
CRSF_FRAMETYPE_BATTERY_SENSOR = 0x08,
CRSF_FRAMETYPE_LINK_STATISTICS = 0x14,
CRSF_FRAMETYPE_RC_CHANNELS_PACKED = 0x16,
CRSF_FRAMETYPE_ATTITUDE = 0x1E,
CRSF_FRAMETYPE_FLIGHT_MODE = 0x21,
// Extended Header Frames, range: 0x28 to 0x96
CRSF_FRAMETYPE_DEVICE_PING = 0x28,
CRSF_FRAMETYPE_DEVICE_INFO = 0x29,
CRSF_FRAMETYPE_PARAMETER_SETTINGS_ENTRY = 0x2B,
CRSF_FRAMETYPE_PARAMETER_READ = 0x2C,
CRSF_FRAMETYPE_PARAMETER_WRITE = 0x2D,
CRSF_FRAMETYPE_COMMAND = 0x32,
// MSP commands
CRSF_FRAMETYPE_MSP_REQ = 0x7A, // response request using msp sequence as command
CRSF_FRAMETYPE_MSP_RESP = 0x7B, // reply with 58 byte chunked binary
CRSF_FRAMETYPE_MSP_WRITE = 0x7C // write with 8 byte chunked binary (OpenTX outbound telemetry buffer limit)
} crsfFrameType_e;
enum {
CRSF_FRAME_GPS_PAYLOAD_SIZE = 15,
CRSF_FRAME_BATTERY_SENSOR_PAYLOAD_SIZE = 8,
CRSF_FRAME_LINK_STATISTICS_PAYLOAD_SIZE = 10,
CRSF_FRAME_RC_CHANNELS_PAYLOAD_SIZE = 22, // 11 bits per channel * 16 channels = 22 bytes.
CRSF_FRAME_ATTITUDE_PAYLOAD_SIZE = 6,
};
enum {
CRSF_FRAME_LENGTH_ADDRESS = 1, // length of ADDRESS field
CRSF_FRAME_LENGTH_FRAMELENGTH = 1, // length of FRAMELENGTH field
CRSF_FRAME_LENGTH_TYPE = 1, // length of TYPE field
CRSF_FRAME_LENGTH_CRC = 1, // length of CRC field
CRSF_FRAME_LENGTH_TYPE_CRC = 2, // length of TYPE and CRC fields combined
CRSF_FRAME_LENGTH_EXT_TYPE_CRC = 4, // length of Extended Dest/Origin, TYPE and CRC fields combined
CRSF_FRAME_LENGTH_NON_PAYLOAD = 4, // combined length of all fields except payload
};
enum {
CRSF_FRAME_TX_MSP_FRAME_SIZE = 58,
CRSF_FRAME_RX_MSP_FRAME_SIZE = 8,
CRSF_FRAME_ORIGIN_DEST_SIZE = 2,
};
typedef enum {
CRSF_ADDRESS_BROADCAST = 0x00,
CRSF_ADDRESS_USB = 0x10,
CRSF_ADDRESS_TBS_CORE_PNP_PRO = 0x80,
CRSF_ADDRESS_RESERVED1 = 0x8A,
CRSF_ADDRESS_CURRENT_SENSOR = 0xC0,
CRSF_ADDRESS_GPS = 0xC2,
CRSF_ADDRESS_TBS_BLACKBOX = 0xC4,
CRSF_ADDRESS_FLIGHT_CONTROLLER = 0xC8,
CRSF_ADDRESS_RESERVED2 = 0xCA,
CRSF_ADDRESS_RACE_TAG = 0xCC,
CRSF_ADDRESS_RADIO_TRANSMITTER = 0xEA,
CRSF_ADDRESS_CRSF_RECEIVER = 0xEC,
CRSF_ADDRESS_CRSF_TRANSMITTER = 0xEE
} crsfAddress_e;

View File

@ -17,61 +17,13 @@
#pragma once #pragma once
#define CRSF_BAUDRATE 420000 #include "interface/crsf_protocol.h"
#define CRSF_PORT_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO) #define CRSF_PORT_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO)
#define CRSF_PORT_MODE MODE_RXTX #define CRSF_PORT_MODE MODE_RXTX
#define CRSF_MAX_CHANNEL 16 #define CRSF_MAX_CHANNEL 16
#define CRSF_MSP_RX_BUF_SIZE 128
#define CRSF_MSP_TX_BUF_SIZE 128
typedef enum {
CRSF_FRAMETYPE_GPS = 0x02,
CRSF_FRAMETYPE_BATTERY_SENSOR = 0x08,
CRSF_FRAMETYPE_LINK_STATISTICS = 0x14,
CRSF_FRAMETYPE_RC_CHANNELS_PACKED = 0x16,
CRSF_FRAMETYPE_ATTITUDE = 0x1E,
CRSF_FRAMETYPE_FLIGHT_MODE = 0x21,
CRSF_FRAMETYPE_DEVICE_PING = 0x28,
CRSF_FRAMETYPE_DEVICE_INFO = 0x29,
CRSF_FRAMETYPE_MSP_REQ = 0x7A, // response request using msp sequence as command
CRSF_FRAMETYPE_MSP_RESP = 0x7B, // reply with 58 byte chunked binary
CRSF_FRAMETYPE_MSP_WRITE = 0x7C // write with 8 byte chunked binary (OpenTX outbound telemetry buffer limit)
} crsfFrameType_e;
enum {
CRSF_FRAME_GPS_PAYLOAD_SIZE = 15,
CRSF_FRAME_BATTERY_SENSOR_PAYLOAD_SIZE = 8,
CRSF_FRAME_LINK_STATISTICS_PAYLOAD_SIZE = 10,
CRSF_FRAME_RC_CHANNELS_PAYLOAD_SIZE = 22, // 11 bits per channel * 16 channels = 22 bytes.
CRSF_FRAME_ATTITUDE_PAYLOAD_SIZE = 6,
CRSF_FRAME_TX_MSP_FRAME_SIZE = 58,
CRSF_FRAME_RX_MSP_FRAME_SIZE = 8,
CRSF_FRAME_ORIGIN_DEST_SIZE = 2,
CRSF_FRAME_LENGTH_ADDRESS = 1, // length of ADDRESS field
CRSF_FRAME_LENGTH_FRAMELENGTH = 1, // length of FRAMELENGTH field
CRSF_FRAME_LENGTH_TYPE = 1, // length of TYPE field
CRSF_FRAME_LENGTH_CRC = 1, // length of CRC field
CRSF_FRAME_LENGTH_TYPE_CRC = 2, // length of TYPE and CRC fields combined
CRSF_FRAME_LENGTH_EXT_TYPE_CRC = 4 // length of Extended Dest/Origin, TYPE and CRC fields combined
};
enum {
CRSF_ADDRESS_BROADCAST = 0x00,
CRSF_ADDRESS_TBS_CORE_PNP_PRO = 0x8,
CRSF_ADDRESS_RESERVED1 = 0x8A,
CRSF_ADDRESS_CURRENT_SENSOR = 0xC0,
CRSF_ADDRESS_TBS_BLACKBOX = 0xC4,
CRSF_ADDRESS_BETAFLIGHT = 0xC8,
CRSF_ADDRESS_RESERVED2 = 0xCA,
CRSF_ADDRESS_RACE_TAG = 0xCC,
CRSF_ADDRESS_RADIO_TRANSMITTER = 0xEA,
CRSF_ADDRESS_CRSF_RECEIVER = 0xEC,
CRSF_ADDRESS_CRSF_TRANSMITTER = 0xEE
};
#define CRSF_PAYLOAD_SIZE_MAX 60
#define CRSF_FRAME_SIZE_MAX (CRSF_PAYLOAD_SIZE_MAX + 4)
typedef struct crsfFrameDef_s { typedef struct crsfFrameDef_s {
uint8_t deviceAddress; uint8_t deviceAddress;

View File

@ -23,11 +23,11 @@
#ifdef USE_TELEMETRY #ifdef USE_TELEMETRY
#include "config/feature.h"
#include "build/atomic.h" #include "build/atomic.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "build/version.h" #include "build/version.h"
#include "config/feature.h"
#include "config/parameter_group.h" #include "config/parameter_group.h"
#include "config/parameter_group_ids.h" #include "config/parameter_group_ids.h"
@ -39,27 +39,26 @@
#include "drivers/nvic.h" #include "drivers/nvic.h"
#include "sensors/battery.h" #include "fc/config.h"
#include "fc/rc_modes.h"
#include "fc/runtime_config.h"
#include "flight/imu.h"
#include "interface/crsf_protocol.h"
#include "io/gps.h" #include "io/gps.h"
#include "io/serial.h" #include "io/serial.h"
#include "fc/rc_modes.h"
#include "fc/runtime_config.h"
#include "io/gps.h"
#include "flight/imu.h"
#include "rx/rx.h"
#include "rx/crsf.h" #include "rx/crsf.h"
#include "sensors/battery.h"
#include "sensors/sensors.h"
#include "telemetry/telemetry.h" #include "telemetry/telemetry.h"
#include "telemetry/crsf.h" #include "telemetry/crsf.h"
#include "telemetry/msp_shared.h" #include "telemetry/msp_shared.h"
#include "fc/config.h"
#include "sensors/sensors.h"
#define CRSF_CYCLETIME_US 100000 // 100ms, 10 Hz #define CRSF_CYCLETIME_US 100000 // 100ms, 10 Hz
#define CRSF_DEVICEINFO_VERSION 0x01 #define CRSF_DEVICEINFO_VERSION 0x01
@ -297,7 +296,7 @@ void crsfFrameDeviceInfo(sbuf_t *dst) {
sbufWriteU8(dst, 0); sbufWriteU8(dst, 0);
sbufWriteU8(dst, CRSF_FRAMETYPE_DEVICE_INFO); sbufWriteU8(dst, CRSF_FRAMETYPE_DEVICE_INFO);
sbufWriteU8(dst, CRSF_ADDRESS_RADIO_TRANSMITTER); sbufWriteU8(dst, CRSF_ADDRESS_RADIO_TRANSMITTER);
sbufWriteU8(dst, CRSF_ADDRESS_BETAFLIGHT); sbufWriteU8(dst, CRSF_ADDRESS_FLIGHT_CONTROLLER);
sbufWriteStringWithZeroTerminator(dst, buff); sbufWriteStringWithZeroTerminator(dst, buff);
for (unsigned int ii=0; ii<12; ii++) { for (unsigned int ii=0; ii<12; ii++) {
sbufWriteU8(dst, 0x00); sbufWriteU8(dst, 0x00);
@ -340,7 +339,7 @@ void crsfSendMspResponse(uint8_t *payload)
sbufWriteU8(dst, CRSF_FRAME_TX_MSP_FRAME_SIZE + CRSF_FRAME_LENGTH_EXT_TYPE_CRC); sbufWriteU8(dst, CRSF_FRAME_TX_MSP_FRAME_SIZE + CRSF_FRAME_LENGTH_EXT_TYPE_CRC);
sbufWriteU8(dst, CRSF_FRAMETYPE_MSP_RESP); sbufWriteU8(dst, CRSF_FRAMETYPE_MSP_RESP);
sbufWriteU8(dst, CRSF_ADDRESS_RADIO_TRANSMITTER); sbufWriteU8(dst, CRSF_ADDRESS_RADIO_TRANSMITTER);
sbufWriteU8(dst, CRSF_ADDRESS_BETAFLIGHT); sbufWriteU8(dst, CRSF_ADDRESS_FLIGHT_CONTROLLER);
sbufWriteData(dst, payload, CRSF_FRAME_TX_MSP_FRAME_SIZE); sbufWriteData(dst, payload, CRSF_FRAME_TX_MSP_FRAME_SIZE);
crsfFinalize(dst); crsfFinalize(dst);
} }

View File

@ -21,7 +21,11 @@
#include <stdint.h> #include <stdint.h>
#include "common/time.h" #include "common/time.h"
#include "rx/crsf.h" #include "interface/crsf_protocol.h"
#define CRSF_MSP_RX_BUF_SIZE 128
#define CRSF_MSP_TX_BUF_SIZE 128
void initCrsfTelemetry(void); void initCrsfTelemetry(void);
bool checkCrsfTelemetryState(void); bool checkCrsfTelemetryState(void);

View File

@ -12,8 +12,7 @@
#include "interface/fc_msp.h" #include "interface/fc_msp.h"
#include "rx/crsf.h" #include "telemetry/crsf.h"
#include "telemetry/msp_shared.h" #include "telemetry/msp_shared.h"
#include "telemetry/smartport.h" #include "telemetry/smartport.h"

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "common/streambuf.h" #include "common/streambuf.h"
#include "rx/crsf.h" #include "telemetry/crsf.h"
#include "telemetry/smartport.h" #include "telemetry/smartport.h"
typedef void (*mspResponseFnPtr)(uint8_t *payload); typedef void (*mspResponseFnPtr)(uint8_t *payload);

View File

@ -286,6 +286,6 @@ serialPortConfig_t *findSerialPortConfig(serialPortFunction_e ) {return NULL;}
bool telemetryCheckRxPortShared(const serialPortConfig_t *) {return false;} bool telemetryCheckRxPortShared(const serialPortConfig_t *) {return false;}
serialPort_t *telemetrySharedPort = NULL; serialPort_t *telemetrySharedPort = NULL;
void crsfScheduleDeviceInfoResponse(void) {}; void crsfScheduleDeviceInfoResponse(void) {};
void crsfScheduleMspResponse(mspPackage_t *package) { UNUSED(package); }; void crsfScheduleMspResponse(void) {};
bool bufferMspFrame(uint8_t *, int) {return true;} bool bufferMspFrame(uint8_t *, int) {return true;}
} }