Making a tri-state pin (switching between input and output), perhaps like embedded_hal::digital::IoPin
#583
Labels
hal-api
API design for the different components of avr-hal
hal-generic
Related to MCU generic parts of avr-hal
Hi,
(Please excuse the terminology and knowledge, I'm new to both Rust and MCU programming.)
I am trying to write some code that drives a charlieplexed LED array. In order to do so, I need to switch pins from input (high impedance) to output hi/lo, and then return them to input when switching the circuit off.
I have tried badly at moving the pin into an output pin with a small scoped block, and then back into an input pin, pseudocode like this:
but I'm struggling with managing the types for all the pins attached to the matrix, and using Dynamic doesn't help as you can't change the pin mode afterwards.
Now, because I also want to use the
arduino_hal::pins!()
pins in order to commuinicate with I2C devices and the serial port, I don't want to simplyunsafe
to the pins directly withPORTB.ddrb
and friends, but I think that's my only option at the moment.What I would like is an interface that is in-between the bit-bang layer and the full safety of static pin modes, which I think the
PinOps
trait offers with its unsafe methodsout_set
,out_clear
,make_input
.Is this a reasonable request? Once I get the pins out of
arduino_hal::pins!*()
, unsafely turning specific pins into different modes is an easier bit of code to reason about than sharing all the pins fromPORTB
et al after safely sharing some of them for serial and i2c access.Maybe it's easier than this and I just need to understand how to move a pin safely, generic across the
PinOps
?Finally, if avr-hal supported
embedded_hal::digital::IoPin
, I think that's close to what I want, but rust-embedded/embedded-hal#340 makes me think this is also not a trivial request either.Thanks for any advice you can offer.
The text was updated successfully, but these errors were encountered: