From e527892d89ff14b6af4aad778945c4675423fa77 Mon Sep 17 00:00:00 2001 From: Joshua Salzedo Date: Sun, 26 Sep 2021 16:29:22 -0700 Subject: [PATCH] Start work on CRC_v1 --- embassy-stm32/src/crc/mod.rs | 4 ++++ embassy-stm32/src/crc/v1.rs | 21 +++++++++++++++++++++ embassy-stm32/src/crc/v2.rs | 0 embassy-stm32/src/crc/v3.rs | 0 embassy-stm32/src/lib.rs | 2 ++ 5 files changed, 27 insertions(+) create mode 100644 embassy-stm32/src/crc/mod.rs create mode 100644 embassy-stm32/src/crc/v1.rs create mode 100644 embassy-stm32/src/crc/v2.rs create mode 100644 embassy-stm32/src/crc/v3.rs diff --git a/embassy-stm32/src/crc/mod.rs b/embassy-stm32/src/crc/mod.rs new file mode 100644 index 00000000..79e00be7 --- /dev/null +++ b/embassy-stm32/src/crc/mod.rs @@ -0,0 +1,4 @@ +#[cfg_attr(crc_v1, path = "v1.rs")] +#[cfg_attr(crc_v2, path = "v2.rs")] +#[cfg_attr(crc_v3, path = "v3.rs")] +mod _version; \ No newline at end of file diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs new file mode 100644 index 00000000..4fc23fe3 --- /dev/null +++ b/embassy-stm32/src/crc/v1.rs @@ -0,0 +1,21 @@ +use crate::pac::{CRC as PAC_CRC, RCC}; +use crate::peripherals::CRC; +use crate::rcc::sealed::RccPeripheral; + +pub struct Crc { + _peripheral: CRC +} + +impl Crc{ + pub fn new(peripheral: CRC) -> Self{ + // enable CRC clock in RCC. + CRC::enable(); + // Reset CRC to default values. + CRC::reset(); + Self { _peripheral: peripheral} + } + + pub fn reset() { + unsafe { PAC_CRC.cr().modify(|w| w.set_reset(true)) }; + } +} \ No newline at end of file diff --git a/embassy-stm32/src/crc/v2.rs b/embassy-stm32/src/crc/v2.rs new file mode 100644 index 00000000..e69de29b diff --git a/embassy-stm32/src/crc/v3.rs b/embassy-stm32/src/crc/v3.rs new file mode 100644 index 00000000..e69de29b diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 073e79f2..711c2997 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -49,6 +49,8 @@ pub mod sdmmc; pub mod spi; #[cfg(usart)] pub mod usart; +#[cfg(crc)] +pub mod crc; #[cfg(feature = "subghz")] pub mod subghz;