-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Rx/Tx reunification for Serial #390
base: master
Are you sure you want to change the base?
Conversation
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 an Input<Floating>, one could also use Output<OpenDrain> and Input<PullUp>, e.g. when interfacing 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 both Tx and Rx, we need a Serial variant which has that pin information erased.
This becomes relevant as more functions like reconfigure are added to the Serial structs. We use the Tx to stash away the usart instance used by the (Erased-)Serial struct, but this choice is arbitrary and irrelevant because it is zero-sized anyway. Fixes stm32-rs#386.
Note that this answers some of the design questions in #386 in code. I am using this successfully in my async/await experiments on the STM32VLDISCOVERY board, but I'm open for changing things if you disagree about anything. |
Possibly if Tx contain tx_pin and Rx contain rx_pin we will not need ErasedSerial |
See #392 |
cc @TheZoq2 |
Is reconfigure the main goal of reunification for you? |
In this case I can propose easier solution: #393 |
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.