Skip to content

CRSF: Allow future use of unused bits in the "Arming status byte"#7022

Open
mha1 wants to merge 5 commits into
EdgeTX:mainfrom
mha1:PR_use_more_status_bits
Open

CRSF: Allow future use of unused bits in the "Arming status byte"#7022
mha1 wants to merge 5 commits into
EdgeTX:mainfrom
mha1:PR_use_more_status_bits

Conversation

@mha1
Copy link
Copy Markdown
Contributor

@mha1 mha1 commented Jan 22, 2026

This PR allows future use of the currently unused status bits in the byte we use to communicate the commanded arming status to ExpressLRS modules if we ever have a need for them. The changes are fully backward compatible with the existing V2.11 and V2.12 implementation for communicating the commanded arming status to ExpressLRS modules. It is also compatible with modules using ExpressLRS V3 firmware.

Summary of changes:

  • sends status byte with every CRSF 0x16 RC Channels packet. Note: the TBS CRSF V3 specification allows sending extra fields. CRSF V3 Frame Details: "size may be bigger than expected frame of given type. This should not be a reason to count the frame invalid. Frame receiver should just ignore extra fields.". ExpressLRS pre-V4 firmware ignores the field and will use CH5 Arming.
  • determines arming method and status using bit 0 and 1 of the status byte
image
  • makes status byte bits 2 to 7 available for future use

This complements the changes made to V4 in ExpressLRS/ExpressLRS#3470 and is fully backwards compatible to the existing implementation

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Crossfire CHANNELS frame structure to use a consistent fixed-length payload with dedicated status byte
    • Improved arming status reporting in Crossfire protocol to properly reflect armed state based on configuration

Review Change Stack

Copy link
Copy Markdown
Member

@gagarinlg gagarinlg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this part of the code for?

Comment thread radio/src/pulses/crossfire.cpp Outdated
Comment on lines +139 to +147
// Example: flag crsf errors to ELRS in bit 2 for resending linkstats
//
//extern bool crsfErrorFlag;
//if(crsfErrorFlag) {
// *buf |= 0x04; // flag crsf error
// crsfErrorFlag = false;
//}

buf++;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for?

Copy link
Copy Markdown
Contributor Author

@mha1 mha1 May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed example code on how the spare bits can be used, e.g. for debugging. I'll remove the dead code.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates CRSF channel frame generation so the status byte is always appended, enabling arming-mode signaling while leaving higher bits available for future status flags.

Changes:

  • Always sends a 25-byte CRSF channel frame payload including the extra status byte.
  • Encodes Switch-mode armed state in bit 0 and CH5 arming mode in bit 1.
  • Updates CRC calculation to include the always-present status byte.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

uint8_t * buf = frame;
*buf++ = MODULE_ADDRESS;
*buf++ = 24 + lenAdjust; // 1(ID) + 22(channel data) + (+1 extra byte if Switch mode) + 1(CRC)
*buf++ = 25; // 1(ID) + 22(channel data) + 1(extra status byte) + 1(CRC)
Comment thread radio/src/pulses/crossfire.cpp Outdated
Comment on lines +139 to +146
// Example: flag crsf errors to ELRS in bit 2 for resending linkstats
//
//extern bool crsfErrorFlag;
//if(crsfErrorFlag) {
// *buf |= 0x04; // flag crsf error
// crsfErrorFlag = false;
//}

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c7cc18bc-7954-4fbf-a3b7-2ac54497ada0

📥 Commits

Reviewing files that changed from the base of the PR and between de5f4eb and debd129.

📒 Files selected for processing (1)
  • radio/src/pulses/crossfire.cpp

📝 Walkthrough

Walkthrough

createCrossfireChannelsFrame now builds CHANNELS frames with fixed 25-byte payload including a status byte. Frame header construction and channel-assembly points are adjusted; status byte encodes armed state (Switch mode) or CH5 mode flag, with CRC8 recomputed for the new length.

Changes

Crossfire Frame Status Byte Integration

Layer / File(s) Summary
Frame structure with status byte assembly
radio/src/pulses/crossfire.cpp
Frame header allocates fixed 25-byte payload; channel-ID assembly offset adjusted. Status byte assembled after channel packing: reflects commanded armed status in Switch mode, or constant CH5 indicator (0x02) otherwise. CRC8 length updated to match new frame format.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: allowing future use of unused bits in the arming status byte while maintaining backward compatibility.
Description check ✅ Passed The description covers the key aspects including backward compatibility, the status byte implementation, and a summary of changes with visual documentation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants