lpc8xx_hal/swm/
peripheral.rs

1use core::marker::PhantomData;
2
3use crate::{init_state, pac};
4
5use super::{
6    fixed_functions::FixedFunctions, handle::Handle,
7    movable_functions::MovableFunctions,
8};
9
10/// Entry point to the switch matrix (SWM) API
11///
12/// The SWM API is split into multiple parts, which are all available through
13/// [`swm::Parts`]. You can use [`SWM::split`] to gain access to [`swm::Parts`].
14///
15/// You can also use this struct to gain access to the raw peripheral using
16/// [`SWM::free`]. This is the main reason this struct exists, as it's no longer
17/// possible to do this after the API has been split.
18///
19/// Use [`Peripherals`] to gain access to an instance of this struct.
20///
21/// Please refer to the [module documentation] for more information.
22///
23/// [`swm::Parts`]: struct.Parts.html
24/// [`SWM::split`]: #method.split
25/// [`SWM::free`]: #method.free
26/// [`Peripherals`]: ../struct.Peripherals.html
27/// [module documentation]: index.html
28pub struct SWM<State = init_state::Enabled> {
29    swm: pac::SWM0,
30    state: PhantomData<State>,
31}
32
33impl<STATE> SWM<STATE> {
34    pub(crate) fn new(swm: pac::SWM0) -> Self {
35        SWM {
36            swm,
37            state: PhantomData,
38        }
39    }
40
41    /// Splits the SWM API into its component parts
42    ///
43    /// This is the regular way to access the SWM API. It exists as an explicit
44    /// step, as it's no longer possible to gain access to the raw peripheral
45    /// using [`SWM::free`] after you've called this method.
46    ///
47    /// [`SWM::free`]: #method.free
48    pub fn split(self) -> Parts<STATE> {
49        Parts {
50            handle: Handle::new(self.swm),
51            movable_functions: MovableFunctions::new(),
52            fixed_functions: FixedFunctions::new(),
53        }
54    }
55
56    /// Return the raw peripheral
57    ///
58    /// This method serves as an escape hatch from the HAL API. It returns the
59    /// raw peripheral, allowing you to do whatever you want with it, without
60    /// limitations imposed by the API.
61    ///
62    /// If you are using this method because a feature you need is missing from
63    /// the HAL API, please [open an issue] or, if an issue for your feature
64    /// request already exists, comment on the existing issue, so we can
65    /// prioritize it accordingly.
66    ///
67    /// [open an issue]: https://github.com/lpc-rs/lpc8xx-hal/issues
68    pub fn free(self) -> pac::SWM0 {
69        self.swm
70    }
71}
72
73/// The main API for the switch matrix (SWM)
74///
75/// Provides access to all types that make up the SWM API. You gain access to
76/// this struct by calling [`SWM::split`].
77///
78/// Please refer to the [module documentation] for more information.
79///
80/// [`SWM::split`]: struct.SWM.html#method.split
81/// [module documentation]: index.html
82pub struct Parts<STATE> {
83    /// Handle to the switch matrix
84    pub handle: Handle<STATE>,
85
86    /// Movable functions
87    pub movable_functions: MovableFunctions,
88
89    /// Fixed functions
90    pub fixed_functions: FixedFunctions,
91}