Add UART line inversion support#5522
Merged
Merged
Conversation
Add InvertTX and InvertRX to UARTConfig to allow enabling hardware line inversion on supported targets. Added hardware implementation for RP2 (RP2040, RP2350), STM32 (newer families), SAM (SAMD51, SAME5x), and ESP (ESP32, ESP32-C3, ESP32-C6).
deadprogram
reviewed
Jul 16, 2026
| if config.TX != NoPin { | ||
| config.TX.Configure(PinConfig{Mode: PinUART}) | ||
| if config.InvertTX { | ||
| config.TX.ioCtrl().ReplaceBits(rp.IO_BANK0_GPIO0_CTRL_OUTOVER_INVERT<<rp.IO_BANK0_GPIO0_CTRL_OUTOVER_Pos, rp.IO_BANK0_GPIO0_CTRL_OUTOVER_Msk, 0) |
Member
There was a problem hiding this comment.
I think this could be something like:
config.TX.ioCtrl().SetGPIO0_CTRL_OUTOVER(rp.IO_BANK0_GPIO0_CTRL_OUTOVER_INVERT)
Contributor
Author
There was a problem hiding this comment.
Easier to say than do unfortunately. I changed the code to use the wrapper, which is confined to gpio implementation,but still uses ReplaceBits under the hood (like other GPIO-related functions on RP2).
Member
|
General comment: we should try to use the generated wrapper functions whenever possible, if you please. |
RP2: Extract setOutOver/setInOver methods on Pin, removing inline IO control register manipulation from UART configure. SAM: Switch to SetCTRLA_TXINV/SetCTRLA_RXINV methods, dropping the unused device/sam import and raw SetBits/ClearBits calls.
Member
|
Anyone else have any feedback on this before merge? |
deadprogram
approved these changes
Jul 17, 2026
Member
|
Now squash/merging. Thanks for adding this feature @digitalentity ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add InvertTX and InvertRX to UARTConfig to allow enabling hardware line inversion on supported targets. Added hardware implementation for RP2 (RP2040, RP2350), STM32 (newer families), SAM (SAMD51, SAME5x), and ESP (ESP32, ESP32-C3, ESP32-C6).
Fixes #5383