From f9ff5336d4c78e571c755e63ef360393e29a1f51 Mon Sep 17 00:00:00 2001 From: Joshua Salzedo Date: Sun, 26 Sep 2021 18:46:19 -0700 Subject: [PATCH] Merge all of the crc_v2 configurations into a single modify call --- embassy-stm32/src/crc/v2.rs | 80 ++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/embassy-stm32/src/crc/v2.rs b/embassy-stm32/src/crc/v2.rs index db4a3699..b21e6c63 100644 --- a/embassy-stm32/src/crc/v2.rs +++ b/embassy-stm32/src/crc/v2.rs @@ -55,59 +55,55 @@ impl Crc { CRC::reset(); let mut instance = Self { _peripheral: peripheral, - _config: config + _config: config, }; unimplemented!(); // instance.init(); // instance } - // Configure device settings - fn configure_revout(&mut self) { - unsafe { - PAC_CRC.cr().modify(|w| {w.set_rev_out( - match self._config.reverse_out { - true => {vals::RevOut::REVERSED} - false => {vals::RevOut::NORMAL} - } - )}) - } - } - fn configure_revin(&mut self) { - unsafe { - PAC_CRC.cr().modify(|w| {w.set_rev_in( - match self._config.reverse_in { - CrcInputReverseConfig::None => {vals::RevIn::NORMAL} - CrcInputReverseConfig::Byte => {vals::RevIn::BYTE} - CrcInputReverseConfig::Halfword => {vals::RevIn::HALFWORD} - CrcInputReverseConfig::Word => {vals::RevIn::WORD} - } - )}) - } - } - - fn configure_polysize(&mut self) { - unsafe { - PAC_CRC.cr().modify(|w| {w.set_polysize( - match self._config.poly_size { - PolySize::Width7 => {vals::Polysize::POLYSIZE7} - PolySize::Width8 => {vals::Polysize::POLYSIZE8} - PolySize::Width16 => {vals::Polysize::POLYSIZE16} - PolySize::Width32 => {vals::Polysize::POLYSIZE32} - } - )}) - } - } pub fn reset(&mut self) { unsafe { PAC_CRC.cr().modify(|w| w.set_reset(true)); } } - fn set_crc_init(&mut self, value: u32) { - unsafe { - PAC_CRC.init().write_value(value) - } - } + fn reconfigure(&mut self) { + unsafe { + // Init CRC value + PAC_CRC.init().write_value(self._config.crc_init_value); + + PAC_CRC.cr().modify(|w| { + // configure reverse output + w.set_rev_out( + match self._config.reverse_out { + true => { vals::RevOut::REVERSED } + false => { vals::RevOut::NORMAL } + } + ); + // configure reverse input + w.set_rev_in( + match self._config.reverse_in { + CrcInputReverseConfig::None => { vals::RevIn::NORMAL } + CrcInputReverseConfig::Byte => { vals::RevIn::BYTE } + CrcInputReverseConfig::Halfword => { vals::RevIn::HALFWORD } + CrcInputReverseConfig::Word => { vals::RevIn::WORD } + } + ); + // configure the polynomial. + w.set_polysize( + match self._config.poly_size { + PolySize::Width7 => { vals::Polysize::POLYSIZE7 } + PolySize::Width8 => { vals::Polysize::POLYSIZE8 } + PolySize::Width16 => { vals::Polysize::POLYSIZE16 } + PolySize::Width32 => { vals::Polysize::POLYSIZE32 } + } + ) + + }) + } + + self.reset(); + } } \ No newline at end of file