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;
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> {
#[inline]
pub fn new(pin: P) -> Self {
Self { pin }
}
#[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();
}
}
pub struct GpioRef<'a, P: embedded_hal::digital::OutputPin> {
pin: &'a mut P,
}
impl<'a, P: embedded_hal::digital::OutputPin> GpioRef<'a, P> {
#[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();
}
}
#[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> {
#[inline]
pub fn new(pin: P) -> Self {
Self { pin }
}
#[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();
}
}
#[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> {
#[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();
}
}