use paste::paste;
pub(crate) mod pull_sealed {
use super::DynPullType;
pub trait PullType {
fn from(pm: DynPullType) -> Self;
fn as_dyn(&self) -> DynPullType;
}
}
pub trait PullType: pull_sealed::PullType {}
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DynPullType {
None,
Up,
Down,
BusKeep,
}
impl PullType for DynPullType {}
impl pull_sealed::PullType for DynPullType {
fn from(pm: DynPullType) -> Self {
pm
}
fn as_dyn(&self) -> DynPullType {
*self
}
}
macro_rules! pin_pull_type {
($($pull_type:ident),*) => {
$(paste! {
#[derive(Debug)]
pub struct [<Pull $pull_type>](pub(super) ());
impl PullType for [<Pull $pull_type>] {}
impl pull_sealed::PullType for [<Pull $pull_type>] {
fn from(_pm: DynPullType) -> Self {
Self(())
}
fn as_dyn(&self) -> DynPullType {
DynPullType::[<$pull_type>]
}
}
})*
};
}
pin_pull_type!(None, Up, Down, BusKeep);