lpc8xx_hal/swm/
movable_functions.rs

1use crate::pins::{self, Trait as _};
2
3use super::{
4    function_kind::{Input, Output},
5    functions::{Function, FunctionTrait},
6    handle::Handle,
7    state::Unassigned,
8};
9
10macro_rules! movable_functions {
11    (
12        $(
13            $field:ident,
14            $type:ident,
15            $kind:ident,
16            $reg_name:ident,
17            $reg_field:ident;
18        )*
19    ) => {
20        /// Provides access to all movable functions
21        ///
22        /// This struct is part of [`swm::Parts`].
23        ///
24        /// [`swm::Parts`]: struct.Parts.html
25        #[allow(missing_docs)]
26        pub struct MovableFunctions {
27            $(pub $field: Function<$type, Unassigned>,)*
28        }
29
30        impl MovableFunctions {
31            pub(crate) fn new() -> Self {
32                MovableFunctions {
33                    $($field: Function::new($type(())),)*
34                }
35            }
36        }
37
38
39        $(
40            /// Represents a movable function
41            ///
42            /// Movable functions can be accessed through [`MovableFunctions`].
43            ///
44            /// [`MovableFunctions`]: struct.MovableFunctions.html
45            #[allow(non_camel_case_types)]
46            pub struct $type(());
47
48            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_0 );
49            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_1 );
50            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_2 );
51            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_3 );
52            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_4 );
53            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_5 );
54            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_6 );
55            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_7 );
56            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_8 );
57            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_9 );
58            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_10);
59            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_11);
60            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_12);
61            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_13);
62            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_14);
63            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_15);
64            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_16);
65            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_17);
66            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_18);
67            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_19);
68            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_20);
69            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_21);
70            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_22);
71            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_23);
72            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_24);
73            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_25);
74            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_26);
75            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_27);
76            impl_function!($type, $kind, $reg_name, $reg_field, PIO0_28);
77            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO0_29);
78            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO0_30);
79            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO0_31);
80            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_0 );
81            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_1 );
82            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_2 );
83            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_3 );
84            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_4 );
85            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_5 );
86            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_6 );
87            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_7 );
88            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_8 );
89            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_9 );
90            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_10);
91            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_11);
92            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_12);
93            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_13);
94            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_14);
95            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_15);
96            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_16);
97            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_17);
98            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_18);
99            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_19);
100            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_20);
101            #[cfg(feature = "845")] impl_function!($type, $kind, $reg_name, $reg_field, PIO1_21);
102        )*
103    }
104}
105
106macro_rules! impl_function {
107    (
108        $type:ident,
109        $kind:ident,
110        $reg_name:ident,
111        $reg_field:ident,
112        $pin:ident
113    ) => {
114        impl FunctionTrait<pins::$pin> for $type {
115            type Kind = $kind;
116
117            fn assign(&mut self, pin: &mut pins::$pin, swm: &mut Handle) {
118                swm.swm.$reg_name.modify(|_, w| unsafe {
119                    w.$reg_field().bits(pin.id() | (pin.port() as u8) << 5)
120                });
121            }
122
123            fn unassign(&mut self, _pin: &mut pins::$pin, swm: &mut Handle) {
124                swm.swm
125                    .$reg_name
126                    .modify(|_, w| unsafe { w.$reg_field().bits(0xff) });
127            }
128        }
129    };
130}
131
132#[cfg(feature = "82x")]
133movable_functions!(
134    u0_txd       , U0_TXD       , Output, pinassign0 , u0_txd_o;
135    u0_rxd       , U0_RXD       , Input , pinassign0 , u0_rxd_i;
136    u0_rts       , U0_RTS       , Output, pinassign0 , u0_rts_o;
137    u0_cts       , U0_CTS       , Input , pinassign0 , u0_cts_i;
138    u0_sclk      , U0_SCLK      , Output, pinassign1 , u0_sclk_io;
139    u1_txd       , U1_TXD       , Output, pinassign1 , u1_txd_o;
140    u1_rxd       , U1_RXD       , Input , pinassign1 , u1_rxd_i;
141    u1_rts       , U1_RTS       , Output, pinassign1 , u1_rts_o;
142    u1_cts       , U1_CTS       , Input , pinassign2 , u1_cts_i;
143    u1_sclk      , U1_SCLK      , Output, pinassign2 , u1_sclk_io;
144    u2_txd       , U2_TXD       , Output, pinassign2 , u2_txd_o;
145    u2_rxd       , U2_RXD       , Input , pinassign2 , u2_rxd_i;
146    u2_rts       , U2_RTS       , Output, pinassign3 , u2_rts_o;
147    u2_cts       , U2_CTS       , Input , pinassign3 , u2_cts_i;
148    u2_sclk      , U2_SCLK      , Output, pinassign3 , u2_sclk_io;
149    spi0_sck     , SPI0_SCK     , Output, pinassign3 , spi0_sck_io;
150    spi0_mosi    , SPI0_MOSI    , Output, pinassign4 , spi0_mosi_io;
151    spi0_miso    , SPI0_MISO    , Output, pinassign4 , spi0_miso_io;
152    spi0_ssel0   , SPI0_SSEL0   , Output, pinassign4 , spi0_ssel0_io;
153    spi0_ssel1   , SPI0_SSEL1   , Output, pinassign4 , spi0_ssel1_io;
154    spi0_ssel2   , SPI0_SSEL2   , Output, pinassign5 , spi0_ssel2_io;
155    spi0_ssel3   , SPI0_SSEL3   , Output, pinassign5 , spi0_ssel3_io;
156    spi1_sck     , SPI1_SCK     , Output, pinassign5 , spi1_sck_io;
157    spi1_mosi    , SPI1_MOSI    , Output, pinassign5 , spi1_mosi_io;
158    spi1_miso    , SPI1_MISO    , Output, pinassign6 , spi1_miso_io;
159    spi1_ssel0   , SPI1_SSEL0   , Output, pinassign6 , spi1_ssel0_io;
160    spi1_ssel1   , SPI1_SSEL1   , Output, pinassign6 , spi1_ssel1_io;
161    sct_pin0     , SCT_PIN0     , Input , pinassign6 , sct_pin0_i;
162    sct_pin1     , SCT_PIN1     , Input , pinassign7 , sct_pin1_i;
163    sct_pin2     , SCT_PIN2     , Input , pinassign7 , sct_pin2_i;
164    sct_pin3     , SCT_PIN3     , Input , pinassign7 , sct_pin3_i;
165    sct_out0     , SCT_OUT0     , Output, pinassign7 , sct_out0_o;
166    sct_out1     , SCT_OUT1     , Output, pinassign8 , sct_out1_o;
167    sct_out2     , SCT_OUT2     , Output, pinassign8 , sct_out2_o;
168    sct_out3     , SCT_OUT3     , Output, pinassign8 , sct_out3_o;
169    sct_out4     , SCT_OUT4     , Output, pinassign8 , sct_out4_o;
170    sct_out5     , SCT_OUT5     , Output, pinassign9 , sct_out5_o;
171    i2c1_sda     , I2C1_SDA     , Output, pinassign9 , i2c1_sda_io;
172    i2c1_scl     , I2C1_SCL     , Output, pinassign9 , i2c1_scl_io;
173    i2c2_sda     , I2C2_SDA     , Output, pinassign9 , i2c2_sda_io;
174    i2c2_scl     , I2C2_SCL     , Output, pinassign10, i2c2_scl_io;
175    i2c3_sda     , I2C3_SDA     , Output, pinassign10, i2c3_sda_io;
176    i2c3_scl     , I2C3_SCL     , Output, pinassign10, i2c3_scl_io;
177    adc_pintrig0 , ADC_PINTRIG0 , Input , pinassign10, adc_pintrig0_i;
178    acd_pintrig1 , ADC_PINTRIG1 , Input , pinassign11, adc_pintrig1_i;
179    acmp_o       , ACMP_O       , Output, pinassign11, acmp_o_o;
180    clkout       , CLKOUT       , Output, pinassign11, clkout_o;
181    gpio_int_bmat, GPIO_INT_BMAT, Output, pinassign11, gpio_int_bmat_o;
182);
183
184#[cfg(feature = "845")]
185movable_functions!(
186    u0_txd       , U0_TXD       , Output, pinassign0 , u0_txd_o;
187    u0_rxd       , U0_RXD       , Input , pinassign0 , u0_rxd_i;
188    u0_rts       , U0_RTS       , Output, pinassign0 , u0_rts_o;
189    u0_cts       , U0_CTS       , Input , pinassign0 , u0_cts_i;
190    u0_sclk      , U0_SCLK      , Output, pinassign1 , u0_sclk_io;
191    u1_txd       , U1_TXD       , Output, pinassign1 , u1_txd_o;
192    u1_rxd       , U1_RXD       , Input , pinassign1 , u1_rxd_i;
193    u1_rts       , U1_RTS       , Output, pinassign1 , u1_rts_o;
194    u1_cts       , U1_CTS       , Input , pinassign2 , u1_cts_i;
195    u1_sclk      , U1_SCLK      , Output, pinassign2 , u1_sclk_io;
196    u2_txd       , U2_TXD       , Output, pinassign2 , u2_txd_o;
197    u2_rxd       , U2_RXD       , Input , pinassign2 , u2_rxd_i;
198    u2_rts       , U2_RTS       , Output, pinassign3 , u2_rts_o;
199    u2_cts       , U2_CTS       , Input , pinassign3 , u2_cts_i;
200    u2_sclk      , U2_SCLK      , Output, pinassign3 , u2_sclk_io;
201    u3_txd       , U3_TXD       , Output, pinassign11, uart3_txd;
202    u3_rxd       , U3_RXD       , Input , pinassign12, uart3_rxd;
203    u3_sclk      , U3_SCLK      , Output, pinassign12, uart3_sclk;
204    u4_txd       , U4_TXD       , Output, pinassign12, uart4_txd;
205    u4_rxd       , U4_RXD       , Input , pinassign12, uart4_rxd;
206    u4_sclk      , U4_SCLK      , Output, pinassign13, uart4_sclk;
207    spi0_sck     , SPI0_SCK     , Output, pinassign3 , spi0_sck_io;
208    spi0_mosi    , SPI0_MOSI    , Output, pinassign4 , spi0_mosi_io;
209    spi0_miso    , SPI0_MISO    , Output, pinassign4 , spi0_miso_io;
210    spi0_ssel0   , SPI0_SSEL0   , Output, pinassign4 , spi0_ssel0_io;
211    spi0_ssel1   , SPI0_SSEL1   , Output, pinassign4 , spi0_ssel1_io;
212    spi0_ssel2   , SPI0_SSEL2   , Output, pinassign5 , spi0_ssel2_io;
213    spi0_ssel3   , SPI0_SSEL3   , Output, pinassign5 , spi0_ssel3_io;
214    spi1_sck     , SPI1_SCK     , Output, pinassign5 , spi1_sck_io;
215    spi1_mosi    , SPI1_MOSI    , Output, pinassign5 , spi1_mosi_io;
216    spi1_miso    , SPI1_MISO    , Output, pinassign6 , spi1_miso_io;
217    spi1_ssel0   , SPI1_SSEL0   , Output, pinassign6 , spi1_ssel0_io;
218    spi1_ssel1   , SPI1_SSEL1   , Output, pinassign6 , spi1_ssel1_io;
219    sct_pin0     , SCT_PIN0     , Input , pinassign6 , sct0_gpio_in_a_i;
220    sct_pin1     , SCT_PIN1     , Input , pinassign7 , sct0_gpio_in_b_i;
221    sct_pin2     , SCT_PIN2     , Input , pinassign7 , sct0_gpio_in_c_i;
222    sct_pin3     , SCT_PIN3     , Input , pinassign7 , sct0_gpio_in_d_i;
223    sct_out0     , SCT_OUT0     , Output, pinassign7 , sct_out0_o;
224    sct_out1     , SCT_OUT1     , Output, pinassign8 , sct_out1_o;
225    sct_out2     , SCT_OUT2     , Output, pinassign8 , sct_out2_o;
226    sct_out3     , SCT_OUT3     , Output, pinassign8 , sct_out3_o;
227    sct_out4     , SCT_OUT4     , Output, pinassign8 , sct_out4_o;
228    sct_out5     , SCT_OUT5     , Output, pinassign9 , sct_out5_o;
229    sct_out6     , SCT_OUT6     , Output, pinassign9 , sct_out6_o;
230    i2c1_sda     , I2C1_SDA     , Output, pinassign9 , i2c1_sda_io;
231    i2c1_scl     , I2C1_SCL     , Output, pinassign9 , i2c1_scl_io;
232    i2c2_sda     , I2C2_SDA     , Output, pinassign10, i2c2_sda_io;
233    i2c2_scl     , I2C2_SCL     , Output, pinassign10, i2c2_scl_io;
234    i2c3_sda     , I2C3_SDA     , Output, pinassign10, i2c3_sda_io;
235    i2c3_scl     , I2C3_SCL     , Output, pinassign10, i2c3_scl_io;
236    acmp_o       , ACMP_O       , Output, pinassign11, comp0_out_o;
237    clkout       , CLKOUT       , Output, pinassign11, clkout_o;
238    gpio_int_bmat, GPIO_INT_BMAT, Output, pinassign11, gpio_int_bmat_o;
239    t0_mat0      , T0_MAT0      , Output, pinassign13, t0_mat0;
240    t0_mat1      , T0_MAT1      , Output, pinassign13, t0_mat1;
241    t0_mat2      , T0_MAT2      , Output, pinassign13, t0_mat2;
242    t0_mat3      , T0_MAT3      , Output, pinassign14, t0_mat3;
243    t0_cap0      , T0_CAP0      , Output, pinassign14, t0_cap0;
244    t0_cap1      , T0_CAP1      , Output, pinassign14, t0_cap1;
245    t0_cap2      , T0_CAP2      , Output, pinassign14, t0_cap2;
246);