nrf-rs / nrf-hal

A Rust HAL for the nRF family of devices
Apache License 2.0
503 stars 139 forks source link

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

Open nevi-me opened 3 years ago

nevi-me commented 3 years ago

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 commented 3 years ago

I've opened https://github.com/nrf-rs/nrf-hal/pull/340 which should resolve this

valpackett commented 3 years ago

Previously: https://github.com/nrf-rs/nrf51-hal/pull/25

Finomnis commented 1 year ago

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

Finomnis commented 1 year ago

@nevi-me Did #401 solve your problem?