aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/crc
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 /embassy-stm32/src/crc
parente527892d89ff14b6af4aad778945c4675423fa77 (diff)
First pass at CRC_V1
Diffstat (limited to 'embassy-stm32/src/crc')
-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
4 files changed, 43 insertions, 8 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 @@