lpc8xx_hal/pins/
gen.rs

1//! Types generated by a macro
2
3use core::marker::PhantomData;
4
5use super::{pin::Pin, state, traits::Trait};
6
7macro_rules! pins {
8    ($(
9        $field:ident, // e.g. pio0_0
10        $type:ident,  // e.g. PIO0_0
11        $port:expr,
12        $id:expr,     // e.g. 0x00
13        $default_state_ty:ty;
14    )*) => {
15        /// Provides access to all pins
16        ///
17        /// You can get access to an instance of this struct through
18        ///[`Peripherals`].
19        ///
20        /// # Limitations
21        ///
22        /// This struct currently provides access to all pins that can be
23        /// available on an LPC8xx part. Please make sure that you are aware of
24        /// which pins are actually available on your specific part, and only
25        /// use those.
26        ///
27        /// [`Peripherals`]: ../struct.Peripherals.html
28        #[allow(missing_docs)]
29        pub struct Pins {
30            $(pub $field: Pin<$type, $default_state_ty>,)*
31        }
32
33        impl Pins {
34            pub(crate) fn new() -> Self {
35                Pins {
36                    $(
37                        $field: Pin {
38                            ty:     $type(()),
39                            _state: <$default_state_ty>::new(),
40                        },
41                    )*
42                }
43            }
44        }
45
46
47        $(
48            /// Identifies a specific pin
49            ///
50            /// This type is used as a type parameter on [`Pin`]. Check out
51            /// [`Pin`]'s documentation for more information.
52            ///
53            /// [`Pin`]: struct.Pin.html
54            #[allow(non_camel_case_types)]
55            pub struct $type(());
56
57            impl Trait for $type {
58                fn port(&self) -> u8 {
59                    $port
60                }
61
62                fn id(&self) -> u8 {
63                    $id
64                }
65
66                fn mask(&self) -> u32 {
67                    0x1 << $id
68                }
69            }
70        )*
71
72
73        /// Contains a token for each pin
74        ///
75        /// This is used by the GPIO API to uphold certain guarantees regarding
76        /// pins. Please refer to [`GPIO`] for more information.
77        ///
78        /// [`GPIO`]: ../gpio/struct.GPIO.html
79        pub struct Tokens<State> {
80            $(
81                /// A token representing a pin
82                pub $field: Token<$type, State>,
83            )*
84        }
85
86        impl<State> Tokens<State> {
87            pub(crate) fn new() -> Self {
88                Self {
89                    $(
90                        $field: Token(PhantomData, PhantomData),
91                    )*
92                }
93            }
94
95            /// Switches the state of all tokens
96            ///
97            /// Since this consumes `self`, it can only be called if all tokens
98            /// are available.
99            pub(crate) fn switch_state<NewState>(self) -> Tokens<NewState> {
100                Tokens {
101                    $(
102                        $field: Token(self.$field.0, PhantomData),
103                    )*
104                }
105            }
106        }
107
108        /// A token representing a pin.
109        ///
110        /// Used by [`GPIO`] to uphold correctness guarantees. Please refer to
111        /// [`GPIO`] for more information.
112        ///
113        /// [`GPIO`]: ../gpio/struct.GPIO.html
114        pub struct Token<Pin, State>(PhantomData<Pin>, PhantomData<State>);
115    }
116}
117
118#[cfg(feature = "82x")]
119pins!(
120    pio0_0 , PIO0_0 , 0, 0x00, state::Unused;
121    pio0_1 , PIO0_1 , 0, 0x01, state::Unused;
122    pio0_2 , PIO0_2 , 0, 0x02, state::Swm<((),), ()>;
123    pio0_3 , PIO0_3 , 0, 0x03, state::Swm<((),), ()>;
124    pio0_4 , PIO0_4 , 0, 0x04, state::Unused;
125    pio0_5 , PIO0_5 , 0, 0x05, state::Swm<(), ((),)>;
126    pio0_6 , PIO0_6 , 0, 0x06, state::Unused;
127    pio0_7 , PIO0_7 , 0, 0x07, state::Unused;
128    pio0_8 , PIO0_8 , 0, 0x08, state::Unused;
129    pio0_9 , PIO0_9 , 0, 0x09, state::Unused;
130    pio0_10, PIO0_10, 0, 0x0a, state::Unused;
131    pio0_11, PIO0_11, 0, 0x0b, state::Unused;
132    pio0_12, PIO0_12, 0, 0x0c, state::Unused;
133    pio0_13, PIO0_13, 0, 0x0d, state::Unused;
134    pio0_14, PIO0_14, 0, 0x0e, state::Unused;
135    pio0_15, PIO0_15, 0, 0x0f, state::Unused;
136    pio0_16, PIO0_16, 0, 0x10, state::Unused;
137    pio0_17, PIO0_17, 0, 0x11, state::Unused;
138    pio0_18, PIO0_18, 0, 0x12, state::Unused;
139    pio0_19, PIO0_19, 0, 0x13, state::Unused;
140    pio0_20, PIO0_20, 0, 0x14, state::Unused;
141    pio0_21, PIO0_21, 0, 0x15, state::Unused;
142    pio0_22, PIO0_22, 0, 0x16, state::Unused;
143    pio0_23, PIO0_23, 0, 0x17, state::Unused;
144    pio0_24, PIO0_24, 0, 0x18, state::Unused;
145    pio0_25, PIO0_25, 0, 0x19, state::Unused;
146    pio0_26, PIO0_26, 0, 0x1a, state::Unused;
147    pio0_27, PIO0_27, 0, 0x1b, state::Unused;
148    pio0_28, PIO0_28, 0, 0x1c, state::Unused;
149);
150
151#[cfg(feature = "845")]
152pins!(
153    pio0_0 , PIO0_0 , 0, 0x00, state::Unused;
154    pio0_1 , PIO0_1 , 0, 0x01, state::Unused;
155    pio0_2 , PIO0_2 , 0, 0x02, state::Swm<((),), ()>;
156    pio0_3 , PIO0_3 , 0, 0x03, state::Swm<((),), ()>;
157    pio0_4 , PIO0_4 , 0, 0x04, state::Unused;
158    pio0_5 , PIO0_5 , 0, 0x05, state::Swm<(), ((),)>;
159    pio0_6 , PIO0_6 , 0, 0x06, state::Unused;
160    pio0_7 , PIO0_7 , 0, 0x07, state::Unused;
161    pio0_8 , PIO0_8 , 0, 0x08, state::Unused;
162    pio0_9 , PIO0_9 , 0, 0x09, state::Unused;
163    pio0_10, PIO0_10, 0, 0x0a, state::Unused;
164    pio0_11, PIO0_11, 0, 0x0b, state::Unused;
165    pio0_12, PIO0_12, 0, 0x0c, state::Unused;
166    pio0_13, PIO0_13, 0, 0x0d, state::Unused;
167    pio0_14, PIO0_14, 0, 0x0e, state::Unused;
168    pio0_15, PIO0_15, 0, 0x0f, state::Unused;
169    pio0_16, PIO0_16, 0, 0x10, state::Unused;
170    pio0_17, PIO0_17, 0, 0x11, state::Unused;
171    pio0_18, PIO0_18, 0, 0x12, state::Unused;
172    pio0_19, PIO0_19, 0, 0x13, state::Unused;
173    pio0_20, PIO0_20, 0, 0x14, state::Unused;
174    pio0_21, PIO0_21, 0, 0x15, state::Unused;
175    pio0_22, PIO0_22, 0, 0x16, state::Unused;
176    pio0_23, PIO0_23, 0, 0x17, state::Unused;
177    pio0_24, PIO0_24, 0, 0x18, state::Unused;
178    pio0_25, PIO0_25, 0, 0x19, state::Unused;
179    pio0_26, PIO0_26, 0, 0x1a, state::Unused;
180    pio0_27, PIO0_27, 0, 0x1b, state::Unused;
181    pio0_28, PIO0_28, 0, 0x1c, state::Unused;
182    pio0_29, PIO0_29, 0, 0x1d, state::Unused;
183    pio0_30, PIO0_30, 0, 0x1e, state::Unused;
184    pio0_31, PIO0_31, 0, 0x1f, state::Unused;
185    pio1_0 , PIO1_0 , 1, 0x00, state::Unused;
186    pio1_1 , PIO1_1 , 1, 0x01, state::Unused;
187    pio1_2 , PIO1_2 , 1, 0x02, state::Unused;
188    pio1_3 , PIO1_3 , 1, 0x03, state::Unused;
189    pio1_4 , PIO1_4 , 1, 0x04, state::Unused;
190    pio1_5 , PIO1_5 , 1, 0x05, state::Unused;
191    pio1_6 , PIO1_6 , 1, 0x06, state::Unused;
192    pio1_7 , PIO1_7 , 1, 0x07, state::Unused;
193    pio1_8 , PIO1_8 , 1, 0x08, state::Unused;
194    pio1_9 , PIO1_9 , 1, 0x09, state::Unused;
195    pio1_10, PIO1_10, 1, 0x0a, state::Unused;
196    pio1_11, PIO1_11, 1, 0x0b, state::Unused;
197    pio1_12, PIO1_12, 1, 0x0c, state::Unused;
198    pio1_13, PIO1_13, 1, 0x0d, state::Unused;
199    pio1_14, PIO1_14, 1, 0x0e, state::Unused;
200    pio1_15, PIO1_15, 1, 0x0f, state::Unused;
201    pio1_16, PIO1_16, 1, 0x10, state::Unused;
202    pio1_17, PIO1_17, 1, 0x11, state::Unused;
203    pio1_18, PIO1_18, 1, 0x12, state::Unused;
204    pio1_19, PIO1_19, 1, 0x13, state::Unused;
205    pio1_20, PIO1_20, 1, 0x14, state::Unused;
206    pio1_21, PIO1_21, 1, 0x15, state::Unused;
207);