From ec0cb8be8f844b1ea5a416cdcdd506df12c4b297 Mon Sep 17 00:00:00 2001 From: Grant Miller Date: Tue, 31 Aug 2021 18:05:41 -0500 Subject: [PATCH 1/3] Fix missing `capture` module --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 1692c2eaa..bf1e222ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -418,6 +418,7 @@ pub mod fmt; pub use nb; pub mod adc; +pub mod capture; pub mod delay; pub mod digital; pub mod i2c; From 746ce08df7b1535296d5989ea9ddc8fb2806a414 Mon Sep 17 00:00:00 2001 From: Grant Miller Date: Tue, 31 Aug 2021 18:06:08 -0500 Subject: [PATCH 2/3] rustfmt --- src/capture.rs | 164 ++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/src/capture.rs b/src/capture.rs index fecfcf3db..d4342e987 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -2,96 +2,96 @@ /// Non-blocking input capture traits pub mod nb { -/// Input capture -/// -/// # Examples -/// -/// You can use this interface to measure the period of (quasi) periodic signals -/// / events -/// -/// ``` -/// extern crate embedded_hal as hal; -/// #[macro_use(block)] -/// extern crate nb; -/// -/// use hal::nb::capture::Capture; -/// -/// fn main() { -/// let mut capture: Capture1 = { -/// // .. -/// # Capture1 -/// }; -/// -/// capture.set_resolution(1.ms()).unwrap(); -/// -/// let before = block!(capture.capture(Channel::_1)).unwrap(); -/// let after = block!(capture.capture(Channel::_1)).unwrap(); -/// -/// let period = after.wrapping_sub(before); -/// -/// println!("Period: {} ms", period); -/// } -/// -/// # use core::convert::Infallible; -/// # struct MilliSeconds(u32); -/// # trait U32Ext { fn ms(self) -> MilliSeconds; } -/// # impl U32Ext for u32 { fn ms(self) -> MilliSeconds { MilliSeconds(self) } } -/// # struct Capture1; -/// # enum Channel { _1 } -/// # impl hal::nb::capture::Capture for Capture1 { -/// # type Error = Infallible; -/// # type Capture = u16; -/// # type Channel = Channel; -/// # type Time = MilliSeconds; -/// # fn capture(&mut self, _: Channel) -> ::nb::Result { Ok(0) } -/// # fn disable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() } -/// # fn enable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() } -/// # fn get_resolution(&self) -> Result { unimplemented!() } -/// # fn set_resolution(&mut self, _: T) -> Result<(), Self::Error> where T: Into { Ok(()) } -/// # } -/// ``` -// unproven reason: pre-singletons API. With singletons a `CapturePin` (cf. `PwmPin`) trait seems more -// appropriate -pub trait Capture { - /// Enumeration of `Capture` errors + /// Input capture /// - /// Possible errors: + /// # Examples /// - /// - *overcapture*, the previous capture value was overwritten because it - /// was not read in a timely manner - type Error: core::fmt::Debug; - - /// Enumeration of channels that can be used with this `Capture` interface + /// You can use this interface to measure the period of (quasi) periodic signals + /// / events + /// + /// ``` + /// extern crate embedded_hal as hal; + /// #[macro_use(block)] + /// extern crate nb; + /// + /// use hal::nb::capture::Capture; + /// + /// fn main() { + /// let mut capture: Capture1 = { + /// // .. + /// # Capture1 + /// }; + /// + /// capture.set_resolution(1.ms()).unwrap(); + /// + /// let before = block!(capture.capture(Channel::_1)).unwrap(); + /// let after = block!(capture.capture(Channel::_1)).unwrap(); /// - /// If your `Capture` interface has no channels you can use the type `()` - /// here - type Channel; + /// let period = after.wrapping_sub(before); + /// + /// println!("Period: {} ms", period); + /// } + /// + /// # use core::convert::Infallible; + /// # struct MilliSeconds(u32); + /// # trait U32Ext { fn ms(self) -> MilliSeconds; } + /// # impl U32Ext for u32 { fn ms(self) -> MilliSeconds { MilliSeconds(self) } } + /// # struct Capture1; + /// # enum Channel { _1 } + /// # impl hal::nb::capture::Capture for Capture1 { + /// # type Error = Infallible; + /// # type Capture = u16; + /// # type Channel = Channel; + /// # type Time = MilliSeconds; + /// # fn capture(&mut self, _: Channel) -> ::nb::Result { Ok(0) } + /// # fn disable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() } + /// # fn enable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() } + /// # fn get_resolution(&self) -> Result { unimplemented!() } + /// # fn set_resolution(&mut self, _: T) -> Result<(), Self::Error> where T: Into { Ok(()) } + /// # } + /// ``` + // unproven reason: pre-singletons API. With singletons a `CapturePin` (cf. `PwmPin`) trait seems more + // appropriate + pub trait Capture { + /// Enumeration of `Capture` errors + /// + /// Possible errors: + /// + /// - *overcapture*, the previous capture value was overwritten because it + /// was not read in a timely manner + type Error: core::fmt::Debug; - /// A time unit that can be converted into a human time unit (e.g. seconds) - type Time; + /// Enumeration of channels that can be used with this `Capture` interface + /// + /// If your `Capture` interface has no channels you can use the type `()` + /// here + type Channel; - /// The type of the value returned by `capture` - type Capture; + /// A time unit that can be converted into a human time unit (e.g. seconds) + type Time; - /// "Waits" for a transition in the capture `channel` and returns the value - /// of counter at that instant - /// - /// NOTE that you must multiply the returned value by the *resolution* of - /// this `Capture` interface to get a human time unit (e.g. seconds) - fn capture(&mut self, channel: Self::Channel) -> nb::Result; + /// The type of the value returned by `capture` + type Capture; - /// Disables a capture `channel` - fn disable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>; + /// "Waits" for a transition in the capture `channel` and returns the value + /// of counter at that instant + /// + /// NOTE that you must multiply the returned value by the *resolution* of + /// this `Capture` interface to get a human time unit (e.g. seconds) + fn capture(&mut self, channel: Self::Channel) -> nb::Result; - /// Enables a capture `channel` - fn enable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>; + /// Disables a capture `channel` + fn disable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>; - /// Returns the current resolution - fn get_resolution(&self) -> Result; + /// Enables a capture `channel` + fn enable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>; - /// Sets the resolution of the capture timer - fn set_resolution(&mut self, resolution: R) -> Result<(), Self::Error> - where - R: Into; -} + /// Returns the current resolution + fn get_resolution(&self) -> Result; + + /// Sets the resolution of the capture timer + fn set_resolution(&mut self, resolution: R) -> Result<(), Self::Error> + where + R: Into; + } } From 05afa3179120fd5599ee05d4ae9f2ccf2f85f378 Mon Sep 17 00:00:00 2001 From: Grant Miller Date: Tue, 31 Aug 2021 18:12:52 -0500 Subject: [PATCH 3/3] Fix tests --- src/capture.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/capture.rs b/src/capture.rs index d4342e987..81f43b520 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -14,7 +14,7 @@ pub mod nb { /// #[macro_use(block)] /// extern crate nb; /// - /// use hal::nb::capture::Capture; + /// use hal::capture::nb::Capture; /// /// fn main() { /// let mut capture: Capture1 = { @@ -38,7 +38,7 @@ pub mod nb { /// # impl U32Ext for u32 { fn ms(self) -> MilliSeconds { MilliSeconds(self) } } /// # struct Capture1; /// # enum Channel { _1 } - /// # impl hal::nb::capture::Capture for Capture1 { + /// # impl hal::capture::nb::Capture for Capture1 { /// # type Error = Infallible; /// # type Capture = u16; /// # type Channel = Channel;