lpc8xx_hal/spi/
clock.rs

1use core::marker::PhantomData;
2
3use crate::syscon::{self, clock_source::PeripheralClockSelector};
4
5/// Contains the clock configuration for an SPI instance
6pub struct Clock<Clock> {
7    pub(crate) divval: u16,
8    // The fields in the DLY register are ignored, since SSEL & EOF aren't used
9    pub(crate) _clock: PhantomData<Clock>,
10}
11
12impl<C> Clock<C>
13where
14    C: ClockSource,
15{
16    /// Create the clock config for the SPI peripheral
17    pub fn new(_: &C, divval: u16) -> Self {
18        Self {
19            divval,
20            _clock: PhantomData,
21        }
22    }
23}
24
25/// Implemented for SPI clock sources
26pub trait ClockSource: private::Sealed {
27    /// Select the clock source
28    ///
29    /// This method is used by the SPI API internally. It should not be relevant
30    /// to most users.
31    ///
32    /// The `selector` argument should not be required to implement this trait,
33    /// but it makes sure that the caller has access to the peripheral they are
34    /// selecting the clock for.
35    fn select<S>(selector: &S, handle: &mut syscon::Handle)
36    where
37        S: PeripheralClockSelector;
38}
39
40#[cfg(feature = "82x")]
41mod target {
42    use crate::syscon;
43
44    use super::ClockSource;
45
46    impl super::private::Sealed for () {}
47
48    impl ClockSource for () {
49        fn select<S>(_: &S, _: &mut syscon::Handle) {
50            // nothing to do; `()` represents the clock that is selected by
51            // default
52        }
53    }
54}
55
56#[cfg(feature = "845")]
57mod target {
58    use crate::syscon::{
59        self,
60        clock_source::{PeripheralClock, PeripheralClockSelector},
61    };
62
63    use super::ClockSource;
64
65    impl<T> super::private::Sealed for T where T: PeripheralClock {}
66    impl<T> ClockSource for T
67    where
68        T: PeripheralClock,
69    {
70        fn select<S>(selector: &S, handle: &mut syscon::Handle)
71        where
72            S: PeripheralClockSelector,
73        {
74            T::select(selector, handle);
75        }
76    }
77}
78
79mod private {
80    pub trait Sealed {}
81}