Skip to content

Commit 22cc4f3

Browse files
committed
Update example for using PeripheralRef
1 parent 335b359 commit 22cc4f3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/traits.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ pub fn runner() -> Result<()> {
104104
}
105105
/// Use `esp_idf_hal` as an example for advanced used of Traits and trait objects
106106
mod lesson_3 {
107-
use crate::into_ref;
107+
use crate::{
108+
into_ref,
109+
traits::lesson_3::peripheral::{Peripheral, PeripheralRef},
110+
};
108111
use anyhow::Result;
109112

110113
mod core {
@@ -623,19 +626,23 @@ mod lesson_3 {
623626
}
624627

625628
pub fn run() -> Result<()> {
626-
use self::core::*;
627629
use gpio::*;
628-
use peripheral::{Peripheral, PeripheralRef};
630+
use std::ops::Deref;
629631

630632
gpio::pin!(Gpio0:0, IO);
631633
gpio::pin!(Gpio34:34, Input);
632634

633635
unsafe {
634636
let pin = Gpio0::new();
635-
gpio::PinDriver::output(pin);
637+
gpio::PinDriver::output(pin)?;
636638

637-
let pin2 = Gpio34::new();
638-
gpio::PinDriver::input(pin2);
639+
let mut pin2 = Gpio34::new();
640+
let pin2_ref = pin2.into_ref();
641+
642+
let driver = gpio::PinDriver::input(pin2_ref)?;
643+
driver.into_input()?;
644+
645+
// let pin2_d = pin2_ref.deref();
639646
}
640647

641648
Ok(())

0 commit comments

Comments
 (0)