Skip to content

Fixed pin state setup when SX126X_ANT_SW is defined#10947

Open
AlexandrZloy wants to merge 2 commits into
meshtastic:developfrom
AlexandrZloy:patch-1
Open

Fixed pin state setup when SX126X_ANT_SW is defined#10947
AlexandrZloy wants to merge 2 commits into
meshtastic:developfrom
AlexandrZloy:patch-1

Conversation

@AlexandrZloy

@AlexandrZloy AlexandrZloy commented Jul 8, 2026

Copy link
Copy Markdown

Fixed the order of pinMode and digitalWrite calls if SX126X_ANT_SW is defined.

🤝 Attestations

  • [V] I have tested that my proposed changes behave as described.
  • [V] I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other (please specify below)
    • Wio-SX1262 for XIAO LoRa Module with the Waweshare ESP32-S3-Zero as the MCU

Summary by CodeRabbit

  • Bug Fixes
    • Improved SX126x startup behavior by configuring the antenna switch GPIO as an output before driving it high, improving reliability during hardware initialization.

@CLAassistant

CLAassistant commented Jul 8, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d92ab0b3-04c1-4886-b2ee-ce07873e9db2

📥 Commits

Reviewing files that changed from the base of the PR and between 6b52c50 and c7489cc.

📒 Files selected for processing (1)
  • src/mesh/SX126xInterface.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/mesh/SX126xInterface.cpp

📝 Walkthrough

Walkthrough

This change reorders GPIO setup for the optional SX126x antenna switch pins in SX126xInterface::init(), calling pinMode before digitalWrite for both configurations, and adjusts a closing preprocessor directive.

Changes

SX126x Init Fix

Layer / File(s) Summary
Antenna switch pin setup order and file guard
src/mesh/SX126xInterface.cpp
Reorders GPIO initialization for SX126X_ANT_SW and the Portduino antenna switch pin, and adjusts the outer conditional’s closing #endif placement.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing SX126X antenna switch pin setup order.
Description check ✅ Passed The description includes a clear summary and the required attestations section with testing details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/mesh/SX126xInterface.cpp (1)

72-78: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Same ordering bug present in the portduino ANT_SW block.

This PR fixes the digitalWrite-before-pinMode ordering for SX126X_ANT_SW (lines 49-50), but the identical issue remains here for portduino_config.lora_sx126x_ant_sw_pin.pin: digitalWrite is still called before pinMode. For consistency and correctness, this should be reordered too.

♻️ Proposed fix
     if (portduino_config.lora_sx126x_ant_sw_pin.pin != RADIOLIB_NC) {
-        digitalWrite(portduino_config.lora_sx126x_ant_sw_pin.pin, HIGH);
-        pinMode(portduino_config.lora_sx126x_ant_sw_pin.pin, OUTPUT);
+        pinMode(portduino_config.lora_sx126x_ant_sw_pin.pin, OUTPUT);
+        digitalWrite(portduino_config.lora_sx126x_ant_sw_pin.pin, HIGH);
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mesh/SX126xInterface.cpp` around lines 72 - 78, The portduino ANT_SW
setup in SX126xInterface still calls digitalWrite before configuring the pin as
OUTPUT. Update the conditional block that uses
portduino_config.lora_sx126x_ant_sw_pin.pin so pinMode is set before
digitalWrite, matching the corrected SX126X_ANT_SW handling and keeping the
initialization order consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/mesh/SX126xInterface.cpp`:
- Around line 72-78: The portduino ANT_SW setup in SX126xInterface still calls
digitalWrite before configuring the pin as OUTPUT. Update the conditional block
that uses portduino_config.lora_sx126x_ant_sw_pin.pin so pinMode is set before
digitalWrite, matching the corrected SX126X_ANT_SW handling and keeping the
initialization order consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f15ded72-6647-471a-bdc0-1319017cc5e1

📥 Commits

Reviewing files that changed from the base of the PR and between 8cff9e0 and 6b52c50.

📒 Files selected for processing (1)
  • src/mesh/SX126xInterface.cpp

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@AlexandrZloy, Welcome to Meshtastic!

Thanks for opening your first pull request. We really appreciate it.

We discuss work as a team in discord, please join us in the #firmware channel.
There's a big backlog of patches at the moment. If you have time,
please help us with some code review and testing of other PRs!

Welcome to the team 😄

@github-actions github-actions Bot added first-contribution needs-review Needs human review hardware-support Hardware related: new devices or modules, problems specific to hardware labels Jul 8, 2026
@AlexandrZloy

Copy link
Copy Markdown
Author

Agreed with coderabbitai that portduino_config.lora_sx126x_ant_sw_pin.pin case was overlooked and should be fixed as well.

@AlexandrZloy
AlexandrZloy marked this pull request as draft July 11, 2026 12:07
@AlexandrZloy
AlexandrZloy marked this pull request as ready for review July 11, 2026 12:12
Fixed the order of pinMode and digitalWrite calls if SX126X_ANT_SW is defined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-contribution hardware-support Hardware related: new devices or modules, problems specific to hardware needs-review Needs human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants