kellerkindt / onewire

OneWire bus implementation in Rust using embedded-hal
Apache License 2.0
35 stars 14 forks source link

use embedded-hal::digital::v2 #8

Closed chernomor closed 4 years ago

chernomor commented 4 years ago

Hello.

I try use last stm32f1xx-hal (along as onewire) in my project and found errors:

error[E0277]: the trait bound `heat_control_f103::gpiob::PBx<heat_control_f103::Output<heat_control_f103::stm32f1xx_hal::gpio::OpenDrain>>: heat_control_f103::_embedded_hal_digital_OutputPin` is not satisfied
   --> src/main.rs:249:33
    |
249 |     let mut wire = OneWire::new(&mut one, false);
    |                                 ^^^^^^^^ the trait `heat_control_f103::_embedded_hal_digital_OutputPin` is not implemented for `heat_control_f103::gpiob::PBx<heat_control_f103::Output<heat_control_f103::stm32f1xx_hal::gpio::OpenDrain>>`
    |
    = note: required because of the requirements on the impl of `onewire::OpenDrainOutput` for `heat_control_f103::gpiob::PBx<heat_control_f103::Output<heat_control_f103::stm32f1xx_hal::gpio::OpenDrain>>`
    = note: required for the cast to the object type `dyn onewire::OpenDrainOutput`

error[E0277]: the trait bound `heat_control_f103::gpiob::PBx<heat_control_f103::Output<heat_control_f103::stm32f1xx_hal::gpio::OpenDrain>>: heat_control_f103::_embedded_hal_digital_InputPin` is not satisfied
   --> src/main.rs:249:33
    |
249 |     let mut wire = OneWire::new(&mut one, false);
    |                                 ^^^^^^^^ the trait `heat_control_f103::_embedded_hal_digital_InputPin` is not implemented for `heat_control_f103::gpiob::PBx<heat_control_f103::Output<heat_control_f103::stm32f1xx_hal::gpio::OpenDrain>>`
    |
    = note: required because of the requirements on the impl of `onewire::OpenDrainOutput` for `heat_control_f103::gpiob::PBx<heat_control_f103::Output<heat_control_f103::stm32f1xx_hal::gpio::OpenDrain>>`
    = note: required for the cast to the object type `dyn onewire::OpenDrainOutput`

Using embedded_hal::digital::v2 solves this problem, so what you say about this PR?

unwrap() in method read() at line 458 looks ugly, but I don't found better solution.. Any ideas?

chernomor commented 4 years ago

Hmm, it seems Void would be replaced with Infallible in future: https://github.com/rust-embedded/embedded-hal/pull/150

riaqn commented 4 years ago

I second this PR. Thanks for the work!

kellerkindt commented 4 years ago

Dang it. I totally missed this PR. Will look into it after work today in the evening!

kellerkindt commented 4 years ago

The current version 0.3.13 generifies over the actual pin-error-type. This should mean that Void, Infallible and even legacy () should work. Feel free to comment on that change and / or open a new issue for discussion (having a discussion in a merged/closed ticket gets lost so fast...)