lpc8xx_hal/pins/
state.rs

1//! Contains types that indicate pin states
2//!
3//! Please refer to [`Pin`] for documentation about how these types are used.
4//!
5//! [`Pin`]: ../struct.Pins.html
6
7use core::marker::PhantomData;
8
9/// Implemented by types that indicate pin state
10///
11/// [`Pin`] uses this type as a trait bound for the type parameter that
12/// indicates the pin's state. This is done for the purpose of
13/// documentation, to show which states a pin can be in. Other than that,
14/// this trait should not be relevant to users of this crate.
15///
16/// [`Pin`]: ../struct.Pin.html
17pub trait State {}
18
19/// Marks a [`Pin`] as being unused
20///
21/// [`Pin`]: ../struct.Pin.html
22pub struct Unused;
23
24impl Unused {
25    pub(crate) fn new() -> Self {
26        Self
27    }
28}
29
30impl State for Unused {}
31
32/// Marks a [`Pin`]  as being assigned to the analog-to-digital converter
33///
34/// [`Pin`]: ../struct.Pin.html
35pub struct Analog;
36
37impl State for Analog {}
38
39/// Marks a [`Pin`]  as being available for switch matrix function assigment
40///
41/// The type parameters of this struct track whether output and input
42/// functions have been assigned to a pin:
43///
44/// - `Output` tracks whether an output function has been assigned. Zero or
45///   one output functions can be assigned to a pin at a time.
46/// - `Inputs` tracks the number of assigned input functions. Any number of
47///   input functions can be assigned to a pin at the same time.
48///
49/// Both type parameters use nested tuples to count the number of assigned
50/// functions. The empty tuple, `()`, represents zero assigned functions,
51/// the empty tuple nested in another tuple, `((),)`, represents one
52/// function being assigned, `(((),))` represents two assigned functions,
53/// and so forth. This is a bit of a hack, of course, but it should do until
54/// [const generics] become available.
55///
56/// [const generics]: https://github.com/rust-lang/rust/issues/44580
57/// [`Pin`]: ../struct.Pin.html
58pub struct Swm<Output, Inputs>(
59    pub(crate) PhantomData<Output>,
60    pub(crate) PhantomData<Inputs>,
61);
62
63impl<Output, Inputs> Swm<Output, Inputs> {
64    pub(crate) const fn new() -> Self {
65        Swm(PhantomData, PhantomData)
66    }
67}
68
69impl<Output, Inputs> State for Swm<Output, Inputs> {}