lpc55_hal/peripherals/
iocon.rs

1use crate::{peripherals::syscon, raw, typestates::init_state};
2
3// use crate::pins::{
4//     Pins,
5// };
6
7crate::wrap_stateful_peripheral!(Iocon, IOCON);
8
9impl<State> Iocon<State> {
10    /// Enable IO pin configuration
11    ///
12    /// Turn on the clock for a disabled Iocon, enabling it.
13    pub fn enabled(mut self, syscon: &mut syscon::Syscon) -> Iocon<init_state::Enabled> {
14        // dbg!(syscon.is_clock_enabled(&self.iocon));
15        syscon.enable_clock(&mut self.raw);
16        // dbg!(syscon.is_clock_enabled(&self.iocon));
17
18        Iocon {
19            raw: self.raw,
20            _state: init_state::Enabled(()),
21        }
22    }
23
24    /// Disable IO pin configuration
25    ///
26    /// Turns off the clock for an enabled Iocon, disabling it.
27    /// Code that attempts to call this method when the peripheral is already
28    /// disabled will not compile.
29    ///
30    /// Consumes this instance of `IOCON` and returns another instance that has
31    /// its `State` type parameter set to [`Disabled`].
32    ///
33    /// [`Enabled`]: ../init_state/struct.Enabled.html
34    /// [`Disabled`]: ../init_state/struct.Disabled.html
35    pub fn disabled(mut self, syscon: &mut syscon::Syscon) -> Iocon<init_state::Disabled> {
36        syscon.disable_clock(&mut self.raw);
37
38        Iocon {
39            raw: self.raw,
40            _state: init_state::Disabled,
41        }
42    }
43}
44
45impl Iocon<init_state::Enabled> {
46    pub fn get_pio_0_8_config(&self) -> u32 {
47        self.raw.pio0_8.read().bits()
48    }
49
50    pub fn get_pio_0_8_func(&self) -> u8 {
51        self.raw.pio0_8.read().func().bits()
52    }
53
54    pub fn set_pio_0_8_swo_func(&self) {
55        self.raw.pio0_8.modify(|_, w| w.func().alt4());
56    }
57
58    pub fn get_pio_0_10_config(&self) -> u32 {
59        self.raw.pio0_10.read().bits()
60    }
61
62    pub fn get_pio_0_10_func(&self) -> u8 {
63        self.raw.pio0_10.read().func().bits()
64    }
65
66    pub fn set_pio_0_10_swo_func(&self) {
67        self.raw.pio0_10.modify(|_, w| w.func().alt6());
68    }
69
70    pub fn get_pio_0_22_config(&self) -> u32 {
71        self.raw.pio0_22.read().bits()
72    }
73
74    pub fn configure_pio_0_22_as_usb0_vbus(&self) {
75        self.raw.pio0_22.modify(
76            |_, w| {
77                w.func()
78                    .alt7() // FUNC7, pin configured as USB0_VBUS
79                    .mode()
80                    .inactive() // MODE_INACT, no additional pin function
81                    .slew()
82                    .standard() // SLEW_STANDARD, standard mode, slew rate control is enabled
83                    .invert()
84                    .disabled() // INV_DI, input function is not inverted
85                    .digimode()
86                    .digital() // DIGITAL_EN, enable digital fucntion
87                    .od()
88                    .normal()
89            }, // OPENDRAIN_DI, open drain is disabled
90        );
91    }
92}