Skip to content

File syn_crsf.h

FileList > proto > syn_crsf.h

Go to the source code of this file

Zero-Heap CRSF (TBS Crossfire / ExpressLRS) Protocol Parser. More...

  • #include "syntropic/common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_CRSF_ChannelsFrame
struct SYN_CRSF_LinkStats
struct SYN_CRSF_Parser

Public Types

Type Name
enum SYN_CRSF_FrameType

Public Functions

Type Name
uint8_t syn_crsf_calc_crc (const uint8_t * buf, size_t len)
Calculate CRC8 DVB-S2 (poly 0xD5) for CRSF buffer.
SYN_Status syn_crsf_init (SYN_CRSF_Parser * parser)
Initialize CRSF parser.
SYN_Status syn_crsf_parse_byte (SYN_CRSF_Parser * parser, uint8_t byte, SYN_CRSF_FrameType * type_out)
Process single byte from serial RX stream.
uint16_t syn_crsf_raw_to_us (uint16_t raw_val)
Convert raw 11-bit CRSF channel value to pulse width in microseconds (us).

Macros

Type Name
define SYN_CRSF_ADDR_FC 0xC8U
define SYN_CRSF_MAX_PACKET_LEN 64U
define SYN_CRSF_NUM_CHANNELS 16U

Detailed Description

CRSF Specifications: * Baud rate: 420,000 / 921,600 / 1,875,000 bps, 8N1. * Frame Format: [Device Addr] [Payload Length] [Frame Type] [Payload...] [CRC8] * Address: 0xC8 (Flight Controller), 0xEA (Radio Transmitter). * Types: * 0x16: RC Channels Frame (16 11-bit channels packed in 22 bytes, raw 170..1908 -> 988..2012 us). * 0x14: Link Statistics (RSSI 1 & 2, Link Quality, SNR). * 0x08: Battery Telemetry (Voltage, Current, Capacity, Remaining %). * 0x02: GPS Telemetry (Lat, Lon, Groundspeed, Heading, Altitude, Satellites).

  • CRC: CRC8 DVB-S2 (poly 0xD5) over Frame Type + Payload.

Public Types Documentation

enum SYN_CRSF_FrameType

enum SYN_CRSF_FrameType {
    SYN_CRSF_TYPE_GPS = 0x02U,
    SYN_CRSF_TYPE_BATTERY = 0x08U,
    SYN_CRSF_TYPE_LINK_STATISTICS = 0x14U,
    SYN_CRSF_TYPE_RC_CHANNELS = 0x16U
};

CRSF Frame Types.


Public Functions Documentation

function syn_crsf_calc_crc

Calculate CRC8 DVB-S2 (poly 0xD5) for CRSF buffer.

uint8_t syn_crsf_calc_crc (
    const uint8_t * buf,
    size_t len
) 

Parameters:

  • buf Pointer to data.
  • len Length in bytes.

Returns:

8-bit CRC value.


function syn_crsf_init

Initialize CRSF parser.

SYN_Status syn_crsf_init (
    SYN_CRSF_Parser * parser
) 

Parameters:

  • parser Pointer to parser struct.

Returns:

SYN_OK on success.


function syn_crsf_parse_byte

Process single byte from serial RX stream.

SYN_Status syn_crsf_parse_byte (
    SYN_CRSF_Parser * parser,
    uint8_t byte,
    SYN_CRSF_FrameType * type_out
) 

Parameters:

  • parser Pointer to parser struct.
  • byte Incoming byte.
  • type_out Optional pointer to receive frame type when a complete valid packet is parsed.

Returns:

SYN_OK on complete packet, SYN_BUSY if incomplete, SYN_ERROR on CRC failure.


function syn_crsf_raw_to_us

Convert raw 11-bit CRSF channel value to pulse width in microseconds (us).

uint16_t syn_crsf_raw_to_us (
    uint16_t raw_val
) 

Standard scaling: * 170 raw -> 988 us * 992 raw -> 1500 us * 1908 raw -> 2012 us

Parameters:

  • raw_val 11-bit raw value (170..1908).

Returns:

Pulse width in microseconds (clamped 988..2012 us).


Macro Definition Documentation

define SYN_CRSF_ADDR_FC

#define SYN_CRSF_ADDR_FC `0xC8U`

Flight Controller sync address (0xC8)


define SYN_CRSF_MAX_PACKET_LEN

#define SYN_CRSF_MAX_PACKET_LEN `64U`

Maximum CRSF frame byte length


define SYN_CRSF_NUM_CHANNELS

#define SYN_CRSF_NUM_CHANNELS `16U`

Number of RC channels in CRSF frame (16)



The documentation for this class was generated from the following file src/syntropic/proto/syn_crsf.h