First pass at CRC_V1

This commit is contained in:
Joshua Salzedo 2021-09-26 16:46:17 -07:00
parent e527892d89
commit e18a27eea2
No known key found for this signature in database
GPG Key ID: C3D0EB484493B731
5 changed files with 45 additions and 10 deletions

View File

@ -1,4 +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;
mod _version;

View File

@ -1,21 +1,54 @@
use crate::pac::{CRC as PAC_CRC, RCC};
use crate::pac::CRC as PAC_CRC;
use crate::peripherals::CRC;
use crate::rcc::sealed::RccPeripheral;
pub struct Crc {
_peripheral: CRC
_peripheral: CRC,
}
impl Crc{
pub fn new(peripheral: CRC) -> Self{
impl Crc {
/// Instantiates the CRC32 peripheral and initializes it to default values.
pub fn new(peripheral: CRC) -> Self {
// Note: enable and reset come from RccPeripheral.
// enable CRC clock in RCC.
CRC::enable();
// Reset CRC to default values.
CRC::reset();
Self { _peripheral: peripheral}
let mut instance = Self {
_peripheral: peripheral,
};
instance.init();
instance
}
pub fn reset() {
/// Resets the CRC unit to default value (0xFFFF_FFFF)
pub fn init(&mut self) {
unsafe { PAC_CRC.cr().modify(|w| w.set_reset(true)) };
}
}
/// Feeds a word to the peripheral and returns the current CRC value
pub fn feed_word(&mut self, word: u32) -> u32 {
// write a single byte to the device, and return the result
unsafe {
PAC_CRC.dr().write_value(word);
PAC_CRC.dr().read()
}
}
/// Feed a slice of words to the peripheral and return the result.
pub fn feed_words(&mut self, words: &[u32]) -> u32 {
for word in words {
unsafe {
PAC_CRC.dr().write_value(*word);
}
}
unsafe { PAC_CRC.dr().read() }
}
/// Reclaims the CRC peripheral.
pub fn release(self) -> CRC {
CRC::disable();
self._peripheral
}
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -39,6 +39,8 @@ pub mod exti;
#[cfg(i2c)]
pub mod i2c;
#[cfg(crc)]
pub mod crc;
#[cfg(pwr)]
pub mod pwr;
#[cfg(rng)]
@ -49,8 +51,6 @@ pub mod sdmmc;
pub mod spi;
#[cfg(usart)]
pub mod usart;
#[cfg(crc)]
pub mod crc;
#[cfg(feature = "subghz")]
pub mod subghz;