-
Notifications
You must be signed in to change notification settings - Fork 218
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
Treat a Gpio pin as either input or output. #740
Comments
One thing that probably would work right now already is using our internal implementation details (I'm not sure if those should be kept public in future) struct HoldGpioPin<P>
where
P: esp32c3_hal::gpio::InputPin
+ esp32c3_hal::gpio::OutputPin
{
pin: Option<P>,
}
impl<P> HoldGpioPin<P>
where
P: esp32c3_hal::gpio::InputPin
+ esp32c3_hal::gpio::OutputPin
{
fn do_output(&mut self) {
let mut out = self.pin.take().unwrap();
out.set_to_push_pull_output();
out.set_output_high(true);
self.pin.replace(out);
}
fn do_input(&mut self) -> bool {
let mut inp = self.pin.take().unwrap();
inp.set_to_input();
let res = inp.is_input_high();
self.pin.replace(inp);
res
}
} ... and use it like this ...
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let mut foo = HoldGpioPin {
pin: Some(io.pins.gpio5),
};
foo.do_output();
delay.delay_ms(3500u32);
loop {
println!("{}", foo.do_input());
delay.delay_ms(500u32);
}
... This way certainly you cannot implement things in a HAL agnostic way |
Not sure if we should implement the more or less deprecated |
Just hit into this, when tried to implement a driver for my segment display. Would be great to have a working implementation for current supported |
I think with our recent GPIO changes it should be easy to implement a |
I'm trying to implement a bit-bang controller for a peripheral (ADNS5050, specifically), based an CPP arduino code.
The problem I've run into, is that I need to be able to use one of the pins as both input and output. If there's an ergonomic/intuitive way to do this as things already are, I've missed it.
Ideally, I'd be able to write something like this:
Reason being, is I have code a bit like this:
...the ADNSDriver can use the
sdio
field either an output pin XOR an input pin. If there's a way to dance between the two modes in a nice way, I been unable to come across it.Context: rust-embedded/embedded-hal#357 in short:
embedded-hal
has theIoPin
trait as well as some others, but is removing it for1.0.0
(follow link for details).The text was updated successfully, but these errors were encountered: