Skip to content

File syn_crsf.c

FileList > proto > syn_crsf.c

Go to the source code of this file

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

  • #include "syntropic/proto/syn_crsf.h"
  • #include <string.h>

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).

Public Static Functions

Type Name
void parse_channels (const uint8_t * payload, SYN_CRSF_ChannelsFrame * channels)
Unpack 11-bit CRSF RC channels from packed byte stream.
void parse_link_stats (const uint8_t * payload, SYN_CRSF_LinkStats * stats)
Unpack CRSF link statistics from payload stream.

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).


Public Static Functions Documentation

function parse_channels

Unpack 11-bit CRSF RC channels from packed byte stream.

static void parse_channels (
    const uint8_t * payload,
    SYN_CRSF_ChannelsFrame * channels
) 

Parameters:

  • payload Pointer to raw payload buffer.
  • channels Pointer to channels frame structure.

Unpack CRSF link statistics from payload stream.

static void parse_link_stats (
    const uint8_t * payload,
    SYN_CRSF_LinkStats * stats
) 

Parameters:

  • payload Pointer to raw payload buffer.
  • stats Pointer to link stats structure.


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