Skip to content

Commit 72d7218

Browse files
committed
add release method for CRC peripheral
1 parent a6ff457 commit 72d7218

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/crc.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,24 @@ impl Config {
7777
/// Sets the initial value of the CRC.
7878
pub fn initial_value(mut self, init: u32) -> Self {
7979
self.initial_value = init;
80-
8180
self
8281
}
8382

8483
/// Sets the polynomial of the CRC.
8584
pub fn polynomial(mut self, polynomial: Polynomial) -> Self {
8685
self.polynomial = polynomial;
87-
8886
self
8987
}
9088

9189
/// Enables bit reversal of the inputs.
9290
pub fn input_bit_reversal(mut self, rev: Option<BitReversal>) -> Self {
9391
self.input_bit_reversal = rev;
94-
9592
self
9693
}
9794

9895
/// Enables bit reversal of the outputs.
9996
pub fn output_bit_reversal(mut self, rev: bool) -> Self {
10097
self.output_bit_reversal = rev;
101-
10298
self
10399
}
104100

@@ -147,11 +143,20 @@ impl Config {
147143
pub struct Crc {}
148144

149145
impl Crc {
146+
/// Release CRC peripheral.
147+
pub fn release(self) -> Config {
148+
Config {
149+
initial_value: 0xffff_ffff,
150+
polynomial: Polynomial::L32(0x04c1_1db7),
151+
input_bit_reversal: None,
152+
output_bit_reversal: false,
153+
}
154+
}
155+
150156
/// This will reset the CRC to its initial condition.
151157
#[inline]
152158
pub fn reset(&mut self) {
153159
let crc = unsafe { &(*CRC::ptr()) };
154-
155160
crc.cr().modify(|_, w| w.reset().set_bit());
156161
}
157162

@@ -162,7 +167,6 @@ impl Crc {
162167
#[inline]
163168
pub fn reset_with_inital_value(&mut self, initial_value: u32) {
164169
let crc = unsafe { &(*CRC::ptr()) };
165-
166170
crc.init()
167171
.write(|w| unsafe { w.crc_init().bits(initial_value) });
168172
crc.cr().modify(|_, w| w.reset().set_bit());
@@ -187,9 +191,7 @@ impl Crc {
187191
#[inline]
188192
pub fn result(&mut self) -> u32 {
189193
let ret = self.peek_result();
190-
191194
self.reset();
192-
193195
ret
194196
}
195197

@@ -198,7 +200,6 @@ impl Crc {
198200
#[inline]
199201
pub fn peek_result(&self) -> u32 {
200202
let crc = unsafe { &(*CRC::ptr()) };
201-
202203
crc.dr().read().bits()
203204
}
204205
}

0 commit comments

Comments
 (0)