Skip to content

Configuration and Functionality

Cassandra "ZZ Cat" Robinson edited this page Feb 22, 2024 · 2 revisions

Configuration

CRSF for Arduino comes with a configuration header file that you can use to tailor CRSF for Arduino to suit the needs of your specific application.

CFA_Config.hpp

This is the configuration header file, and is automatically included when you add CRSFforArduino.hpp to the top of your sketches.
CFA_Config is located here: CRSFforArduino/src/CFA_Config.hpp

In the configuration header, you will find a list of pre-processor defines that you can enable (by setting a define's value to 1) or disable (by setting a define's value to 0).
The semantic version defines are largely irrelevant to most use cases. However, they exist for debugging purposes and for firmware applications that require built-in version tracking of all dependencies.

Link Statistics API Configuration

  • CRSF_LINK_STATISTICS_ENABLED
    • Default value: 1 (Enabled)
    • When enabled, you can use the Link Statistics API.
      NB: The Link Statistics API is required for fail-safe detection.

RC Channels API Configuration

  • CRSF_RC_ENABLED
    • Default value: 1 (Enabled)
    • When enabled, you can use the RC Channels API.
  • CRSF_RC_MAX_CHANNELS
    • Default value: 16
    • This determines the maximum number of RC channels you want to use in your firmware.
      NB: This MAY be checked against the maximum number of RC channels that are specified by The Crossfire Protocol, which is limited to 16 channels.
  • CRSF_RC_CHANNEL_MIN
    • Default value: 172
    • The minimum raw RC channel value (from your receiver) that is considered valid.
      NB: This is the raw value. Not the "microseconds" value.
  • CRSF_RC_CHANNEL_MAX
    • Default value: 1811
    • The maximum raw RC channel value (from your receiver) that is considered valid.
      NB: This is the raw value. Not the "microseconds" value.
  • CRSF_RC_CHANNEL_CENTER
    • Default value: 992
    • The middle raw RC channel value (from your receiver).
      NB: This is the raw value. Not the "microseconds" value.
  • CRSF_RC_INITIALISE_CHANNELS
    • Default value: 1
    • When enabled, all 16 RC channels are internally initialised to the value set by CRSF_RC_CHANNEL_CENTER.
  • CRSF_RC_INITIALISE_ARMCHANNEL
    • Requires: CRSF_RC_INITIALISE_CHANNELS set to 1
    • Default value: 1
    • When enabled, Channel 5 (AKA Aux1) is internally initialised to CRSF_RC_CHANNEL_MIN.
  • CRSF_RC_INITIALISE_THROTTLECHANNEL
    • Requires: CRSF_RC_INITIALISE_CHANNELS set to 1
    • Default value: 1
    • When enabled, Channel 3 is internally initialised to CRSF_RC_CHANNEL_MIN.

Flight Modes API Configuration

Telemetry API Configuration

  • CRSF_TELEMETRY_ENABLED
  • CRSF_TELEMETRY_ATTITUDE_ENABLED
    • Requires: CRSF_TELEMETRY_ENABLED set to 1
    • Default value: 1
    • When enabled, you can send Roll, Pitch and Yaw attitude telemetry back to your controller.
  • CRSF_TELEMETRY_BAROALTITUDE_ENABLED
    • Requires: CRSF_TELEMETRY_ENABLED set to 1
    • Default value: 1
    • When enabled, you can send barometric altitude and variometer telemetry back to your controller.
  • CRSF_TELEMETRY_BATTERY_ENABLED
    • Requires: CRSF_TELEMETRY_ENABLED set to 1
    • Default value: 1
    • When enabled, you can send voltage, current, fuel and remaining capacity telemetry back to your controller.
  • CRSF_TELEMETRY_FLIGHTMODE_ENABLED
    • Requires: CRSF_TELEMETRY_ENABLED set to 1, and CRSF_FLIGHTMODES_ENABLED set to 1
    • Default value: 0
    • When enabled, you can send the current flight mode (including your custom flight modes, if CRSF_CUSTOM_FLIGHT_MODES_ENABLED is set to 1) as telemetry back to your controller.
  • CRSF_TELEMETRY_GPS_ENABLED
    • Requires: CRSF_TELEMETRY_ENABLED set to 1, and CRSF_FLIGHTMODES_ENABLED set to 1
    • Default value: 1
    • When enabled, you can send the current flight mode (including your custom flight modes, if CRSF_CUSTOM_FLIGHT_MODES_ENABLED is set to 1) as telemetry back to your controller.

Debug API

This is mostly used during development of CRSF for Arduino, and it provides vital information about the inner machinations of the API.
For daily use, it is best to leave these defines at their default values - IE Disabled.
Information about these defines is listed here, in case Debug Mode is needed.

  • CRSF_DEBUG_ENABLED
    • Default value: 0
    • This puts CRSF for Arduino into Debug Mode.
      In this mode, various information on the inner machinations of CRSF for Arduino (particularly during its initialisation phases) are printed to the Serial Monitor.
  • CRSF_DEBUG_SERIAL_PORT
    • Requires: CRSF_DEBUG_ENABLED set to 1
    • Default value: Serial
    • This is the port that is used to send debug data to the Serial Monitor.
      Usually this is your target development board's USB port.
  • CRSF_DEBUG_ENABLE_COMPATIBILITY_TABLE_OUTPUT
    • Requires: CRSF_DEBUG_ENABLED set to 1
    • Default value: 0
    • When enabled, debug data that is specific to the Compatibility Table is sent to the Serial Monitor.

Configuration checks

At the end of CFA_Config.hpp there are compiler warnings and asserts that will trigger, if any of the aforementioned defines are set to invalid values.

Condition Error Type Reason
Setting CRSF_RC_ENABLED and CRSF_TELEMETRY_ENABLED to 0 Warning You have disabled all of CRSF for Arduino's functionality
Enabling CRSF_FLIGHTMODES_ENABLED but leaving CRSF_RC_ENABLED disabled Assert Failure The Flight Modes API depends on the RC Channels API in order to function.
Leaving CRSF_TELEMETRY_ENABLED enabled, but you individually disabled all telemetry types - EG Barometric altitude, attitude, battery, and GPS telemetry Assert Failure If you want to globally disable telemetry, set CRSF_TELEMETRY_ENABLED to 0 instead of doing this.

Functionality

Baud rate configuration

When you initialise CRSF for Arduino, the UART baud rate is internally set to 420,000 and configured as 8-bits per byte, no parity, and one stop bit.

Transparent functionality

CRSF for Arduino is designed to be transparent to your sketches.
What this means is you can write in CRSF for Arduino's API functions in your sketches, and those functions MAY be disabled by their governing pre-processor define(s) in CFA_Config.hpp. Your sketch will still compile, flash, and function as though nothing has happened.
For example: If it's your intention to have RC Channels and Telemetry in your sketch, and CRSF_TELEMETRY_ENABLED is disabled at compile time, you will notice that everything compiles and flashes seamlessly. But, you have your RC channels, but no telemetry.

The rationale behind this is if you do happen to write in one (or more) API function(s) that are disabled in CFA_Config.hpp, your compiler won't terminate the compilation process, let alone yell at you for it.
This is to save time for different projects and/or for testing certain aspects of your project in isolation.

Keep in mind that if you do flash your target hardware and your source code contains one (or more) API function(s) that are disabled, the functionality that would otherwise be introduced will simply not be there.

This is by design, and it is normal behaviour. If something simply is "not working", check your wiring, then check your CFA_Config.hpp. Chances are, you have flashed your target with something that you did not enable beforehand.