API Documentation

class crsf : public SerialIO
#include <crsf.h>

A class for handling CRSF protocol communication.

Public Functions

explicit crsf(Stream *rxPort, int rxPin = -1, int txPin = -1, bool inverted = false)

Constructor for the CRSF class.

Parameters:
  • rxPort – Reference to the hardware serial port for RX communication.

  • rxPin – The RX pin number.

  • txPin – The TX pin number.

  • inverted – Whether the serial signal is inverted (true) or not (false).

virtual void begin() override

Initializes the CRSF communication.

virtual void processIncoming() override

Process incoming serial data and decode it.

virtual void getChannel(rc_channels_t *channelData) override

Retrieves the decoded RC channels from the received CRSF data.

Parameters:

channelData – Pointer to a crsf_channels_t struct where the decoded channel data will be stored.

uint8_t crc8(uint8_t *data, uint8_t len)

Private Members

crsf_channels_t _channelData
uint8_t _rxData[CRSF_MAX_PACKET_SIZE] = {0}
bool _headerDetected
uint8_t _rxIndex
uint8_t _buffer
struct crsf_channels_s
#include <crsf_protocol.h>

RC Packet Frame

Public Members

unsigned channel1
unsigned channel2
unsigned channel3
unsigned channel4
unsigned channel5
unsigned channel6
unsigned channel7
unsigned channel8
unsigned channel9
unsigned channel10
unsigned channel11
unsigned channel12
unsigned channel13
unsigned channel14
unsigned channel15
unsigned channel16
struct crsf_header_s
#include <crsf_protocol.h>

Heder of CRSF Packet

Public Members

uint8_t device_addr
uint8_t frame_size
uint8_t type
struct crsf_sensor_battery_s
#include <crsf_protocol.h>

Battery Voltage parameters

Public Members

uint32_t voltage
uint32_t current
uint32_t capacity
uint32_t remaining
struct crsf_sensor_gps_s
#include <crsf_protocol.h>

GPS parameters

Public Members

int32_t latitude
int32_t longitude
uint16_t groundspeed
uint16_t heading
uint16_t altitude
uint8_t satellites
struct crsfPayloadLinkstatistics_s
#include <crsf_protocol.h>

Payload Statics

Public Members

uint8_t active_antenna
uint8_t rf_Mode
class fport : public SerialIO

Public Functions

explicit fport(Stream *rxPort, int rxPin = -1, int txPin = -1, bool inverted = true)
virtual void begin() override

Initialize pins and set up the serial port.

virtual void processIncoming() override

Process incoming serial data and decode it.

virtual void getChannel(rc_channels_t *channelData) override

Retrieve the current channel data.

Note

The structure contains 16 channels, each represented as an 11-bit unsigned integer with a maximum value of 2047.

Parameters:

channelData[out] Pointer to an rc_channels_t structure to store the retrieved channel data.

void crc()

Private Members

uint8_t _rxData[FPORT_MAX_PACKET_SIZE] = {0}
fport_channels_t _channelData
struct fport_channels_s

Public Members

unsigned channel1
unsigned channel2
unsigned channel3
unsigned channel4
unsigned channel5
unsigned channel6
unsigned channel7
unsigned channel8
unsigned channel9
unsigned channel10
unsigned channel11
unsigned channel12
unsigned channel13
unsigned channel14
unsigned channel15
unsigned channel16
unsigned dummy
unsigned failsafe
unsigned framelost
unsigned channel17
unsigned channel18
class ibus : public SerialIO
#include <ibus.h>

A class for handling IBUS protocol communication.

Public Functions

explicit ibus(Stream *rxPort, int rxPin = -1, int txPin = -1, bool inverted = false)

Constructor for the IBUS class.

Parameters:
  • rxPort – Reference to the hardware serial port for RX communication.

  • rxPin – The RX pin number.

  • txPin – The TX pin number.

  • inverted – Whether the serial signal is inverted (true) or not (false).

virtual void begin() override

Initializes the IBUS communication.

virtual void processIncoming() override

Processes incoming IBUS data.

virtual void getChannel(rc_channels_t *channelData) override

Gets the decoded RC channels from the IBUS data.

Parameters:

channelData – Pointer to a rc_channels_t struct where the decoded channel data will be stored.

virtual void getChannel(ibus_channels_t *channelData) override

Gets the decoded RC channels from the IBUS data.

Parameters:

channelData – Pointer to a ibus_channels_t struct where the decoded channel data will be stored.

Private Functions

bool checkSum()

Private Members

ibus_channels_t _channelData
uint8_t _rxData[IBUS_MAX_PACKET_SIZE]

Buffer to store received IBUS data.

struct ibus_channels_s

Public Members

unsigned header
unsigned channel1
unsigned channel2
unsigned channel3
unsigned channel4
unsigned channel5
unsigned channel6
unsigned channel7
unsigned channel8
unsigned channel9
unsigned channel10
unsigned channel11
unsigned channel12
unsigned channel13
unsigned channel14
unsigned checksum
struct rc_channels_s
#include <SerialIO.h>

Structure representing 16 RC channels using 11-bit values.

Public Members

unsigned channel1
unsigned channel2
unsigned channel3
unsigned channel4
unsigned channel5
unsigned channel6
unsigned channel7
unsigned channel8
unsigned channel9
unsigned channel10
unsigned channel11
unsigned channel12
unsigned channel13
unsigned channel14
unsigned channel15
unsigned channel16
class sbus : public SerialIO
#include <sbus.h>

A class for handling SBUS protocol communication.

Public Functions

explicit sbus(Stream *rxPort, int rxPin = -1, int txPin = -1, bool inverted = true)

Constructor for the SBUS class.

Parameters:
  • rxPort – Reference to the hardware serial port for RX communication.

  • rxPin – The RX pin number.

  • txPin – The TX pin number.

  • inverted – Whether the serial signal is inverted (true) or not (false).

virtual void begin() override

Initializes the SBUS communication.

virtual void processIncoming() override

Process incoming serial data and decode it.

virtual void getChannel(rc_channels_t *channelData) override

Gets the decoded RC channels from the SBUS data.

Parameters:

channelData – Pointer to a crsf_channels_t struct where the decoded channel data will be stored.

bool getFailsafe()

Gets the failsafe status from the SBUS data.

Returns:

True if failsafe is active, false otherwise.

bool getFramelost()

Gets the frame lost status from the SBUS data.

Returns:

True if frame lost is active, false otherwise.

bool getChannel17()

Gets the channel 17 status from the SBUS data.

Returns:

True if channel 17 is active, false otherwise.

bool getChannel18()

Gets the channel 18 status from the SBUS data.

Returns:

True if channel 18 is active, false otherwise.

bool getSerialConnectionStatus()

Gets the serial connection status.

Returns:

True if the connection is active, false if it has timed out.

Private Members

sbus_channels_t _channelData
uint8_t _rxData[SBUS_MAX_PACKET_SIZE]
struct sbus_channels_s

Public Members

unsigned header
unsigned channel1
unsigned channel2
unsigned channel3
unsigned channel4
unsigned channel5
unsigned channel6
unsigned channel7
unsigned channel8
unsigned channel9
unsigned channel10
unsigned channel11
unsigned channel12
unsigned channel13
unsigned channel14
unsigned channel15
unsigned channel16
unsigned dummy
unsigned failsafe
unsigned framelost
unsigned channel17
unsigned channel18
unsigned footer
class SerialIO
#include <SerialIO.h>

Class providing methods for initializing and decoding RC protocols.

Subclassed by crsf, fport, ibus, sbus

Public Functions

SerialIO(Stream *rxPort, int rxPin, int txPin, bool inverted)

Constructor to initialize the SerialIO class.

Parameters:
  • rxPort – Pointer to the hardware serial port to use.

  • rxPin – RX pin number.

  • txPin – TX pin number.

  • inverted – Set to true if the serial signal is inverted.

virtual ~SerialIO()

Virtual destructor.

virtual void begin() = 0

Initialize pins and set up the serial port.

virtual void processIncoming() = 0

Process incoming serial data and decode it.

virtual void getChannel(rc_channels_t *channelData) = 0

Retrieve the current channel data.

Note

The structure contains 16 channels, each represented as an 11-bit unsigned integer with a maximum value of 2047.

Parameters:

channelData[out] Pointer to an rc_channels_t structure to store the retrieved channel data.

virtual void getChannel(ibus_channels_t *channelData)

Retrieve the current channel data using ibus_channels_t.

Parameters:

channelData[out] Pointer to an ibus_channels_t structure to store the channel data.

Protected Functions

void leftShift(uint8_t arr[], size_t size)

Perform a left shift operation on the given byte array.

Parameters:
  • arr – Pointer to the byte array.

  • size – Size of the array.

void rightShift(uint8_t arr[], size_t size)

Perform a right shift operation on the given byte array.

Parameters:
  • arr – Pointer to the byte array.

  • size – Size of the array.

Protected Attributes

Stream *_rxPort

Pointer to the hardware serial port used for communication.

bool _inverted

Indicates whether the serial signal is inverted.

int _rxPin

RX pin number.

int _txPin

TX pin number.

uint32_t _lastPacketTime = 0

Timestamp of the last received packet.

bool _connectionTimeout = false

Indicates whether the connection has timed out.

file crsf_basic.ino
#include <SerialIO.h>

Functions

void setup()
void loop()

Variables

rc_channels_t channelData
crsf receiver & Serial
file crsf_basic.ino
#include <SerialIO.h>

Defines

CRSF_TX_PIN
CRSF_RX_PIN

Functions

void setup()
void loop()

Variables

rc_channels_t rcdata
crsf receiver & Serial1
file ibus_basic.ino
#include <SerialIO.h>

Functions

void setup()
void loop()

Variables

rc_channels_t channelData
ibus receiver & Serial
file ibus_basic.ino
#include <SerialIO.h>

Defines

IBUS_TX_PIN
IBUS_RX_PIN

Functions

void setup()
void loop()

Variables

rc_channels_t rcdata
ibus receiver & Serial1
file sbus_basic.ino
#include <SerialIO.h>

Functions

void setup()
void loop()

Variables

rc_channels_t channelData
sbus receiver & Serial
file sbus_basic.ino
#include <SerialIO.h>

Defines

SBUS_TX_PIN
SBUS_RX_PIN

Functions

void setup()
void loop()

Variables

rc_channels_t rcdata
sbus receiver & Serial1
file crsf.cpp
#include “crsf.h
file crsf.h
#include “crsf_protocol.h
#include “../SerialIO.h

Header file for the CRSF protocol implementation.

Author

Witty-Wizard

Defines

CRSF_H
CRC8_POLY_D5
file crsf_protocol.h
#include <stdint.h>

Defines

CRSF_PROTOCOL_H
PACKED
CRSF_BAUDRATE

CRSF default baud rate.

CRSF_NUM_CHANNELS

CRSF number of channels.

CRSF_CHANNEL_VALUE_MIN

987us - actual CRSF min is 0 with E.Limits on/*#end#*/

CRSF_CHANNEL_VALUE_1000
CRSF_CHANNEL_VALUE_MID
CRSF_CHANNEL_VALUE_2000
CRSF_CHANNEL_VALUE_MAX

2012us - actual CRSF max is 1984 with E.Limits on/*#end#*/

CRSF_CHANNEL_VALUE_SPAN
CRSF_MAX_PACKET_SIZE

max declared len is 62+DEST+LEN on top of that = 64/*#end#*/

CRSF_MAX_PAYLOAD_LEN

Max size of payload in [dest] [len] [type] [payload] [crc8]/*#end#*/.

Typedefs

typedef struct crsf_header_s crsf_header_t

Heder of CRSF Packet

typedef struct crsf_channels_s crsf_channels_t

RC Packet Frame

typedef struct crsfPayloadLinkstatistics_s crsfLinkStatistics_t

Payload Statics

typedef struct crsf_sensor_battery_s crsf_sensor_battery_t

Battery Voltage parameters

typedef struct crsf_sensor_gps_s crsf_sensor_gps_t

GPS parameters

Enums

Length of different CRSF frame

Values:

enumerator CRSF_FRAME_LENGTH_ADDRESS
enumerator CRSF_FRAME_LENGTH_FRAMELENGTH
enumerator CRSF_FRAME_LENGTH_TYPE
enumerator CRSF_FRAME_LENGTH_CRC
enumerator CRSF_FRAME_LENGTH_TYPE_CRC
enumerator CRSF_FRAME_LENGTH_EXT_TYPE_CRC
enumerator CRSF_FRAME_LENGTH_NON_PAYLOAD

Length of CRSF frames

Values:

enumerator CRSF_FRAME_GPS_PAYLOAD_SIZE
enumerator CRSF_FRAME_BATTERY_SENSOR_PAYLOAD_SIZE
enumerator CRSF_FRAME_RC_CHANNELS_PAYLOAD_SIZE
enumerator CRSF_FRAME_ATTITUDE_PAYLOAD_SIZE
enum crsf_frame_type_e

CRSF Sensor frame type

Values:

enumerator CRSF_FRAMETYPE_GPS
enumerator CRSF_FRAMETYPE_BATTERY_SENSOR
enumerator CRSF_FRAMETYPE_OPENTX_SYNC
enumerator CRSF_FRAMETYPE_RADIO_ID
enumerator CRSF_FRAMETYPE_RC_CHANNELS_PACKED
enumerator CRSF_FRAMETYPE_ATTITUDE
enumerator CRSF_FRAMETYPE_FLIGHT_MODE
enumerator CRSF_FRAMETYPE_DEVICE_PING
enumerator CRSF_FRAMETYPE_DEVICE_INFO
enumerator CRSF_FRAMETYPE_PARAMETER_SETTINGS_ENTRY
enumerator CRSF_FRAMETYPE_PARAMETER_READ
enumerator CRSF_FRAMETYPE_PARAMETER_WRITE
enumerator CRSF_FRAMETYPE_COMMAND
enumerator CRSF_FRAMETYPE_MSP_REQ
enumerator CRSF_FRAMETYPE_MSP_RESP
enumerator CRSF_FRAMETYPE_MSP_WRITE
enum crsf_addr_e

CRSF sensor address

Values:

enumerator CRSF_ADDRESS_BROADCAST
enumerator CRSF_ADDRESS_USB
enumerator CRSF_ADDRESS_TBS_CORE_PNP_PRO
enumerator CRSF_ADDRESS_RESERVED1
enumerator CRSF_ADDRESS_CURRENT_SENSOR
enumerator CRSF_ADDRESS_GPS
enumerator CRSF_ADDRESS_TBS_BLACKBOX
enumerator CRSF_ADDRESS_FLIGHT_CONTROLLER
enumerator CRSF_ADDRESS_RESERVED2
enumerator CRSF_ADDRESS_RACE_TAG
enumerator CRSF_ADDRESS_RADIO_TRANSMITTER
enumerator CRSF_ADDRESS_CRSF_RECEIVER
enumerator CRSF_ADDRESS_CRSF_TRANSMITTER

Functions

static inline uint16_t htobe16(uint16_t val)
static inline uint16_t be16toh(uint16_t val)
static inline uint32_t htobe32(uint32_t val)
static inline uint32_t be32toh(uint32_t val)
file fport.cpp
#include “fport.h

Source file for the F.Port implementations.

Author

Witty-Wizard

file fport.h
#include “../SerialIO.h
#include “fport_protocol.h

Header file for the FPort Protocol definations.

Author

Witty-Wizard

Defines

FPORT_H
file fport_protocol.h
#include <stdint.h>

Header file for the F.Port protocol implementation.

Defines

FPORT_PROTOCOL_H
PACKED
FPORT_BAUDRATE

F.Port baudrate.

FPORT_MAX_PACKET_SIZE

F.Port maximum packet length.

FPORT_END_BYTES

Typedefs

typedef struct fport_channels_s fport_channels_t

Enums

enum fport_frame_type_e

Values:

enumerator FPORT_FRAMETYPE_RC_CHANNELS_PACKED
enumerator FPORT_FRAMETYPE_DOWNLINK
enumerator FPORT_FRAMETYPE_UPLINK
file ibus.cpp
#include “ibus.h
file ibus.h
#include “../SerialIO.h
#include “ibus_protocol.h

Header file for the Ibus protocol implementation.

Defines

IBUS_H
file ibus_protocol.h
#include <stdint.h>

Header file for the iBus protocol implementation.

Defines

IBUS_PROTOCOL_H
PACKED
IBUS_MAX_PACKET_SIZE

Maximum packet size for the IBUS protocol.

IBUS_BAUDRATE

Baud rate for IBUS communication.

IBUS_HEADER1
IBUS_HEADER2

Typedefs

typedef struct ibus_channels_s ibus_channels_t
file sbus.cpp
#include “sbus.h

Source file for the SBus implementations.

Author

Witty-Wizard

file sbus.h
#include “../SerialIO.h
#include “sbus_protocol.h

Header file for the SBUS protocol implementation.

Defines

SBUS_H
file sbus_protocol.h
#include <stdint.h>

Header file for the SBus protocol implementation.

Defines

SBUS_PROTOCOL_H
PACKED
HEADER_SBUS

SBus Header Byte.

FOOTER_SBUS

SBus Footer Byte.

SBUS_BAUDRATE

SBus baudrate.

SBUS_MAX_PACKET_SIZE

SBus packet length.

SBUS_TIMEOUT

SBus timeout in milliseconds.

Typedefs

typedef struct sbus_channels_s sbus_channels_t
file SerialIO.cpp
#include “SerialIO.h
file SerialIO.h
#include <Arduino.h>
#include “crsf/crsf.h
#include “fport/fport.h
#include “ibus/ibus.h
#include “sbus/sbus.h

Header file for SerialIO class, providing serial input/output (IO) functionality.

Author

WittyWizard

Defines

SerialIO_H
PACKED

Typedefs

typedef struct rc_channels_s rc_channels_t

Structure representing 16 RC channels using 11-bit values.

dir examples/atmel
dir src/crsf
dir examples/atmel/crsf_basic
dir examples/rp2040/crsf_basic
dir examples
dir src/fport
dir src/ibus
dir examples/atmel/ibus_basic
dir examples/rp2040/ibus_basic
dir examples/rp2040
dir src/sbus
dir examples/atmel/sbus_basic
dir examples/rp2040/sbus_basic
dir src