Skip to content
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

Can't use with onewire due to InputPin + OutputPin requirement #339

Open
nevi-me opened this issue Jul 18, 2021 · 4 comments
Open

Can't use with onewire due to InputPin + OutputPin requirement #339

nevi-me opened this issue Jul 18, 2021 · 4 comments

Comments

@nevi-me
Copy link

nevi-me commented Jul 18, 2021

When trying to use nrf-hal-common with OneWire (https://crates.io/crates/onewire), InputPin needs to be implemented for OutputPin.

I tried to implement this myself, but I seem to be a bit out of my depth :(

Example code is:

let peripherals = Peripherals::take().unwrap();

let pin1 = nrf52840_hal::gpio::p1::Parts::new(peripherals.P1);
let mut temp_pin = pin1.p1_08.degrade().into_open_drain_output(
    OpenDrainConfig::Disconnect0HighDrive1, Level::High
);
let mut wire = OneWire::new(&mut temp_pin, false);

This results in the error:

error[E0271]: type mismatch resolving `<nrf52840_hal::gpio::Pin<nrf52840_hal::gpio::Output<OpenDrain>> as nrf52840_hal::prelude::OutputPin>::Error == ()`
  --> src/main.rs:30:29
   |
30 | let mut wire = OneWire::new(&mut temp_pin, false);
   |                             ^^^^^^^^^^^^^ expected `()`, found enum `void::Void`
   |
   = note: required for the cast to the object type `dyn OpenDrainOutput<(), Error = (), Error = ()>`

error[E0277]: the trait bound `nrf52840_hal::gpio::Pin<nrf52840_hal::gpio::Output<OpenDrain>>: _embedded_hal_digital_InputPin` is not satisfied
  --> src/main.rs:30:29
   |
30 | let mut wire = OneWire::new(&mut temp_pin, false);
   |                             ^^^^^^^^^^^^^ the trait `_embedded_hal_digital_InputPin` is not implemented for `nrf52840_hal::gpio::Pin<nrf52840_hal::gpio::Output<OpenDrain>>`
   |
   = note: required because of the requirements on the impl of `nrf52840_hal::prelude::InputPin` for `nrf52840_hal::gpio::Pin<nrf52840_hal::gpio::Output<OpenDrain>>`
@jonas-schievink
Copy link
Contributor

I've opened #340 which should resolve this

@valpackett
Copy link

Previously: nrf-rs/nrf51-hal#25

@Finomnis
Copy link
Contributor

I've opened #401 which should finally resolve this.

bors bot added a commit that referenced this issue Sep 27, 2022
401: Add OpenDrainIO pin state (with InputPin capability) r=jonas-schievink a=Finomnis

As already reported in #339, there is currently no way to create an I/O pin in nrf-hal.

There are several reasons why having this would be useful. My personal usecase is the DHT22/AM2302 sensor. Controlling it requires a single-wire pulled-up open drain IO.

Sadly, this means that all libraries that can interface with it [require `InputPin + OutputPin`](https://docs.rs/dht-sensor/0.2.1/dht_sensor/trait.InputOutputPin.html).

# Solution
There is no inherent reason why nrf chips shouldn't be able to implement this. The input buffer is always available and allows reading back the pin values during every pin configuration. Although for energy saving reasons, the input buffer is currently disabled during the `OpenDrain` state.

My proposal is to add an `OpenDrainIO` state that does not disable the input buffer and implements `InputPin`.

Co-authored-by: Finomnis <finomnis@gmail.com>
@Finomnis
Copy link
Contributor

Finomnis commented Sep 28, 2022

@nevi-me Did #401 solve your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants