-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 0.2.0: Add implementations for GPIO types (#1)
* Release 0.2.0: Add implementations for GPIO types
- Loading branch information
1 parent
613bc28
commit 17fe50e
Showing
8 changed files
with
286 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# Unreleased | ||
|
||
# 0.2.0 | ||
|
||
* Add `Instrument` implementations for GPIOs: `embedded-hal` version 1.0 and `embedded-hal` version 0.2 `OutputPins` | ||
* Hide documentation for `TraceTaskFuture`, `TracePollFuture` and `TraceTaskAndPollFuture` | ||
* Improve documentation | ||
|
||
# 0.1.0 | ||
|
||
* Initial version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "embedded-trace" | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
edition = "2021" | ||
authors = ["Justin Beaurivage <[email protected]>"] | ||
description = "A Future tracing utility for embedded systems" | ||
|
@@ -9,4 +9,11 @@ license = "MIT OR Apache-2.0" | |
keywords = ["trace", "tracing", "async", "futures", "no_std"] | ||
|
||
[dependencies] | ||
pin-project-lite = "0.2.13" | ||
pin-project-lite = "0.2.13" | ||
embedded-hal_1 = { package = "embedded-hal", version = "1.0.0-rc.3" } | ||
embedded-hal_0_2 = { package = "embedded-hal", version = "0.2.7", optional = true} | ||
|
||
[features] | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
//! [`Instrument`] implementations for GPIO pins. | ||
//! | ||
//! Types implementing `embedded-hal v1.0` | ||
//! [`OutputPin`](embedded_hal_1::digital::OutputPin) and `embedded-hal v0.2` | ||
//! [`OutputPin`](embedded_hal_0_2::digital::v2::OutputPin) are supported. | ||
use crate::Instrument; | ||
use embedded_hal_1 as embedded_hal; | ||
|
||
#[cfg(feature = "embedded-hal_0_2")] | ||
use embedded_hal_0_2 as embedded_hal_legacy; | ||
|
||
/// [`Instrument`] implementation for an [`OutputPin`] (`embedded-hal` version | ||
/// 1.0). | ||
/// | ||
/// This type is also available as [`GpioRef`], which does not consume the | ||
/// underlying [`OutputPin`]. For an [`Instrument`] implementation which | ||
/// supports `embedded-hal` version 0.2, see [`LegacyGpio`]. | ||
/// | ||
/// [`OutputPin`]: embedded_hal::digital::OutputPin | ||
pub struct Gpio<P: embedded_hal::digital::OutputPin> { | ||
pin: P, | ||
} | ||
|
||
impl<P: embedded_hal::digital::OutputPin> From<P> for Gpio<P> { | ||
#[inline] | ||
fn from(pin: P) -> Self { | ||
Self::new(pin) | ||
} | ||
} | ||
|
||
impl<P: embedded_hal::digital::OutputPin> Gpio<P> { | ||
/// Create a new [`Gpio`]. | ||
#[inline] | ||
pub fn new(pin: P) -> Self { | ||
Self { pin } | ||
} | ||
|
||
/// Return the underlying [`OutputPin`](embedded_hal::digital::OutputPin). | ||
#[inline] | ||
pub fn free(self) -> P { | ||
self.pin | ||
} | ||
} | ||
|
||
impl<P: embedded_hal::digital::OutputPin> Instrument for Gpio<P> { | ||
#[inline] | ||
fn on_enter(&mut self) { | ||
let _ = self.pin.set_high(); | ||
} | ||
|
||
#[inline] | ||
fn on_exit(&mut self) { | ||
let _ = self.pin.set_low(); | ||
} | ||
} | ||
|
||
/// Reference-taking version of an [`Instrument`] implementation for an | ||
/// [`OutputPin`] (`embedded-hal` version 1.0). | ||
/// | ||
/// This type is also available as [`Gpio`], which does consumes the | ||
/// underlying [`OutputPin`]. For an [`Instrument`] implementation which | ||
/// supports `embedded-hal` version 0.2, see [`LegacyGpioRef`]. | ||
/// | ||
/// [`OutputPin`]: embedded_hal::digital::OutputPin | ||
pub struct GpioRef<'a, P: embedded_hal::digital::OutputPin> { | ||
pin: &'a mut P, | ||
} | ||
|
||
impl<'a, P: embedded_hal::digital::OutputPin> GpioRef<'a, P> { | ||
/// Create a new [`GpioRef`]. | ||
#[inline] | ||
pub fn new(pin: &'a mut P) -> Self { | ||
Self { pin } | ||
} | ||
} | ||
|
||
impl<'a, P: embedded_hal::digital::OutputPin> Instrument for GpioRef<'a, P> { | ||
#[inline] | ||
fn on_enter(&mut self) { | ||
let _ = self.pin.set_high(); | ||
} | ||
|
||
#[inline] | ||
fn on_exit(&mut self) { | ||
let _ = self.pin.set_low(); | ||
} | ||
} | ||
|
||
/// [`Instrument`] implementation for an [`OutputPin`] (`embedded-hal` version | ||
/// 0.2). | ||
/// | ||
/// This type is also available as [`LegacyGpioRef`], which does not consume the | ||
/// underlying [`OutputPin`]. For an [`Instrument`] implementation which | ||
/// supports `embedded-hal` version 1.0, see [`Gpio`]. | ||
/// | ||
/// [`OutputPin`]: embedded_hal::digital::OutputPin | ||
#[cfg(feature = "embedded-hal_0_2")] | ||
pub struct LegacyGpio<P: embedded_hal_legacy::digital::v2::OutputPin> { | ||
pin: P, | ||
} | ||
|
||
#[cfg(feature = "embedded-hal_0_2")] | ||
impl<P: embedded_hal_legacy::digital::v2::OutputPin> From<P> for LegacyGpio<P> { | ||
fn from(pin: P) -> Self { | ||
Self { pin } | ||
} | ||
} | ||
|
||
#[cfg(feature = "embedded-hal_0_2")] | ||
impl<P: embedded_hal_legacy::digital::v2::OutputPin> LegacyGpio<P> { | ||
/// Create a new [`LegacyGpio`]. | ||
#[inline] | ||
pub fn new(pin: P) -> Self { | ||
Self { pin } | ||
} | ||
|
||
/// Return the underlying | ||
/// [`OutputPin`](embedded_hal_legacy::digital::v2::OutputPin). | ||
#[inline] | ||
pub fn free(self) -> P { | ||
self.pin | ||
} | ||
} | ||
|
||
#[cfg(feature = "embedded-hal_0_2")] | ||
impl<P: embedded_hal_legacy::digital::v2::OutputPin> Instrument for LegacyGpio<P> { | ||
#[inline] | ||
fn on_enter(&mut self) { | ||
let _ = self.pin.set_high(); | ||
} | ||
|
||
#[inline] | ||
fn on_exit(&mut self) { | ||
let _ = self.pin.set_low(); | ||
} | ||
} | ||
|
||
/// Reference-taking version of an [`Instrument`] implementation for an | ||
/// [`OutputPin`] (`embedded-hal` version 0.2). | ||
/// | ||
/// This type is also available as [`LegacyGpio`], which consumes the | ||
/// underlying [`OutputPin`]. For an [`Instrument`] implementation which | ||
/// supports `embedded-hal` version 1.0, see [`GpioRef`]. | ||
/// | ||
/// [`OutputPin`]: embedded_hal::digital::OutputPin | ||
#[cfg(feature = "embedded-hal_0_2")] | ||
pub struct LegacyGpioRef<'a, P: embedded_hal_legacy::digital::v2::OutputPin> { | ||
pin: &'a mut P, | ||
} | ||
|
||
#[cfg(feature = "embedded-hal_0_2")] | ||
impl<'a, P: embedded_hal_legacy::digital::v2::OutputPin> LegacyGpioRef<'a, P> { | ||
/// Create a new [`LegacyGpioRef`]. | ||
#[inline] | ||
pub fn new(pin: &'a mut P) -> Self { | ||
Self { pin } | ||
} | ||
} | ||
|
||
#[cfg(feature = "embedded-hal_0_2")] | ||
impl<'a, P: embedded_hal_legacy::digital::v2::OutputPin> Instrument for LegacyGpioRef<'a, P> { | ||
#[inline] | ||
fn on_enter(&mut self) { | ||
let _ = self.pin.set_high(); | ||
} | ||
|
||
#[inline] | ||
fn on_exit(&mut self) { | ||
let _ = self.pin.set_low(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//! [`Instrument`](crate::Instrument) implementations for various types. | ||
pub mod gpio; | ||
pub use gpio::*; |
Oops, something went wrong.