Implement Rx/Tx reunification for Serial #390
Open
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.
There are many possible pin combinations for a Serial peripheral. Many support at least one alternative pin group to be used, and in addition to that, each pin can also be configured differently. For instance, instead of the common
Output<PushPull>
with anInput<Floating>
, one could also useOutput<OpenDrain>
andInput<PullUp>
, e.g. wheninterfacing with a 1-Wire bus.
This pin information is already lost when splitting the Serial object into
Rx
/Tx
. In order to allow a reunification into a Serial object which represents ownership of bothTx
andRx
, we need a Serial variant which has that pin information erased.This PR introduces
ErasedSerial
, which serves exactly that purpose. In addition,Tx
andRx
both gain a consumingreunite
function which restores the originalSerial
. To facilitate that and provide the original contents of theErasedSerial
struct, we use theTx
to stash away the USART instance -- this choice is arbitrary. As the USART is zero-sized anyway and we get both parts (Rx and Tx) when reuniting, it shouldn't matter where we stash it away.Fixes #386.