diff options
Diffstat (limited to 'embassy-nxp/src/sct.rs')
| -rw-r--r-- | embassy-nxp/src/sct.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/embassy-nxp/src/sct.rs b/embassy-nxp/src/sct.rs new file mode 100644 index 000000000..b6b0e35a9 --- /dev/null +++ b/embassy-nxp/src/sct.rs | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | #![macro_use] | ||
| 2 | |||
| 3 | use embassy_hal_internal::PeripheralType; | ||
| 4 | use nxp_pac::iocon::vals::PioFunc; | ||
| 5 | |||
| 6 | use crate::gpio; | ||
| 7 | |||
| 8 | /// SCT instance. | ||
| 9 | #[allow(private_bounds)] | ||
| 10 | pub trait Instance: SealedInstance + PeripheralType {} | ||
| 11 | |||
| 12 | pub(crate) trait SealedInstance {} | ||
| 13 | |||
| 14 | /// An SCT output. | ||
| 15 | #[allow(private_bounds)] | ||
| 16 | pub trait Output<T: Instance>: SealedOutput + PeripheralType {} | ||
| 17 | |||
| 18 | pub(crate) trait SealedOutput { | ||
| 19 | /// Output number. | ||
| 20 | fn number(&self) -> usize; | ||
| 21 | } | ||
| 22 | |||
| 23 | /// An SCT output capable pin. | ||
| 24 | pub trait OutputPin<T: Instance, O: Output<T>>: gpio::Pin { | ||
| 25 | fn pin_func(&self) -> PioFunc; | ||
| 26 | } | ||
| 27 | |||
| 28 | macro_rules! impl_sct_instance { | ||
| 29 | ($instance: ident) => { | ||
| 30 | impl crate::sct::SealedInstance for crate::peripherals::$instance {} | ||
| 31 | impl crate::sct::Instance for crate::peripherals::$instance {} | ||
| 32 | }; | ||
| 33 | } | ||
| 34 | |||
| 35 | macro_rules! impl_sct_output_instance { | ||
| 36 | ($instance: ident, $name: ident, $num: expr) => { | ||
| 37 | impl crate::sct::SealedOutput for crate::peripherals::$name { | ||
| 38 | fn number(&self) -> usize { | ||
| 39 | $num as usize | ||
| 40 | } | ||
| 41 | } | ||
| 42 | impl crate::sct::Output<crate::peripherals::$instance> for crate::peripherals::$name {} | ||
| 43 | }; | ||
| 44 | } | ||
| 45 | |||
| 46 | macro_rules! impl_sct_output_pin { | ||
| 47 | ($instance: ident, $output_instance: ident, $pin: ident, $alt: ident) => { | ||
| 48 | impl crate::sct::OutputPin<crate::peripherals::$instance, crate::peripherals::$output_instance> | ||
| 49 | for crate::peripherals::$pin | ||
| 50 | { | ||
| 51 | fn pin_func(&self) -> crate::pac::iocon::vals::PioFunc { | ||
| 52 | crate::pac::iocon::vals::PioFunc::$alt | ||
| 53 | } | ||
| 54 | } | ||
| 55 | }; | ||
| 56 | } | ||
