aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Salzedo <[email protected]>2021-09-26 16:46:17 -0700
committerJoshua Salzedo <[email protected]>2021-09-26 16:46:17 -0700
commite18a27eea2aca005f01fdde72162b14e976f358a (patch)
tree207f7462fe4296287751a42063efa05310d0adf7
parente527892d89ff14b6af4aad778945c4675423fa77 (diff)
First pass at CRC_V1
-rw-r--r--embassy-stm32/src/crc/mod.rs2
-rw-r--r--embassy-stm32/src/crc/v1.rs47
-rw-r--r--embassy-stm32/src/crc/v2.rs1
-rw-r--r--embassy-stm32/src/crc/v3.rs1
-rw-r--r--embassy-stm32/src/lib.rs4
5 files changed, 45 insertions, 10 deletions
diff --git a/embassy-stm32/src/crc/mod.rs b/embassy-stm32/src/crc/mod.rs
index 79e00be73..02fa1278b 100644
--- a/embassy-stm32/src/crc/mod.rs
+++ b/embassy-stm32/src/crc/mod.rs
@@ -1,4 +1,4 @@
1#[cfg_attr(crc_v1, path = "v1.rs")] 1#[cfg_attr(crc_v1, path = "v1.rs")]
2#[cfg_attr(crc_v2, path = "v2.rs")] 2#[cfg_attr(crc_v2, path = "v2.rs")]
3#[cfg_attr(crc_v3, path = "v3.rs")] 3#[cfg_attr(crc_v3, path = "v3.rs")]
4mod _version; \ No newline at end of file 4mod _version;
diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs
index 4fc23fe39..52ccca660 100644
--- a/embassy-stm32/src/crc/v1.rs
+++ b/embassy-stm32/src/crc/v1.rs
@@ -1,21 +1,54 @@
1use crate::pac::{CRC as PAC_CRC, RCC}; 1use crate::pac::CRC as PAC_CRC;
2use crate::peripherals::CRC; 2use crate::peripherals::CRC;
3use crate::rcc::sealed::RccPeripheral; 3use crate::rcc::sealed::RccPeripheral;
4 4
5pub struct Crc { 5pub struct Crc {
6 _peripheral: CRC 6 _peripheral: CRC,
7} 7}
8 8
9impl Crc{ 9impl Crc {
10 pub fn new(peripheral: CRC) -> Self{ 10 /// Instantiates the CRC32 peripheral and initializes it to default values.
11 pub fn new(peripheral: CRC) -> Self {
12 // Note: enable and reset come from RccPeripheral.
11 // enable CRC clock in RCC. 13 // enable CRC clock in RCC.
12 CRC::enable(); 14 CRC::enable();
13 // Reset CRC to default values. 15 // Reset CRC to default values.
14 CRC::reset(); 16 CRC::reset();
15 Self { _peripheral: peripheral} 17 let mut instance = Self {
18 _peripheral: peripheral,
19 };
20 instance.init();
21 instance
16 } 22 }
17 23
18 pub fn reset() { 24 /// Resets the CRC unit to default value (0xFFFF_FFFF)
25 pub fn init(&mut self) {
19 unsafe { PAC_CRC.cr().modify(|w| w.set_reset(true)) }; 26 unsafe { PAC_CRC.cr().modify(|w| w.set_reset(true)) };
20 } 27 }
21} \ No newline at end of file 28
29 /// Feeds a word to the peripheral and returns the current CRC value
30 pub fn feed_word(&mut self, word: u32) -> u32 {
31 // write a single byte to the device, and return the result
32 unsafe {
33 PAC_CRC.dr().write_value(word);
34 PAC_CRC.dr().read()
35 }
36 }
37 /// Feed a slice of words to the peripheral and return the result.
38 pub fn feed_words(&mut self, words: &[u32]) -> u32 {
39 for word in words {
40 unsafe {
41 PAC_CRC.dr().write_value(*word);
42 }
43 }
44
45 unsafe { PAC_CRC.dr().read() }
46 }
47
48 /// Reclaims the CRC peripheral.
49 pub fn release(self) -> CRC {
50 CRC::disable();
51
52 self._peripheral
53 }
54}
diff --git a/embassy-stm32/src/crc/v2.rs b/embassy-stm32/src/crc/v2.rs
index e69de29bb..8b1378917 100644
--- a/embassy-stm32/src/crc/v2.rs
+++ b/embassy-stm32/src/crc/v2.rs
@@ -0,0 +1 @@
diff --git a/embassy-stm32/src/crc/v3.rs b/embassy-stm32/src/crc/v3.rs
index e69de29bb..8b1378917 100644
--- a/embassy-stm32/src/crc/v3.rs
+++ b/embassy-stm32/src/crc/v3.rs
@@ -0,0 +1 @@
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 711c29971..424b1c994 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -39,6 +39,8 @@ pub mod exti;
39#[cfg(i2c)] 39#[cfg(i2c)]
40pub mod i2c; 40pub mod i2c;
41 41
42#[cfg(crc)]
43pub mod crc;
42#[cfg(pwr)] 44#[cfg(pwr)]
43pub mod pwr; 45pub mod pwr;
44#[cfg(rng)] 46#[cfg(rng)]
@@ -49,8 +51,6 @@ pub mod sdmmc;
49pub mod spi; 51pub mod spi;
50#[cfg(usart)] 52#[cfg(usart)]
51pub mod usart; 53pub mod usart;
52#[cfg(crc)]
53pub mod crc;
54 54
55#[cfg(feature = "subghz")] 55#[cfg(feature = "subghz")]
56pub mod subghz; 56pub mod subghz;