Skip to content

Commit cdd573d

Browse files
fmckeoghjamesmunns
authored andcommitted
refactor: use PAC frequency enum and .variant() instead of match
1 parent b21aaf9 commit cdd573d

File tree

1 file changed

+5
-49
lines changed

1 file changed

+5
-49
lines changed

nrf52-hal-common/src/spim.rs

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use core::ops::Deref;
55
use core::sync::atomic::{compiler_fence, Ordering::SeqCst};
66
use core::cmp::min;
7+
pub use crate::target::spim0::frequency::FREQUENCYW as Frequency;
78
pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
89

910
use crate::target::{spim0, SPIM0};
@@ -158,7 +159,7 @@ impl<T> Spim<T> where T: SpimExt {
158159

159160
// Configure mode
160161
spim.config.write(|w| {
161-
// Can't match on `mode` as embedded_hal::spi::Mode only derives PartialEq, not Eq
162+
// Can't match on `mode` due to embedded-hal, see https://github.com/rust-embedded/embedded-hal/pull/126
162163
if mode == MODE_0 {
163164
w.order().msb_first().cpol().active_high().cpha().leading()
164165
} else if mode == MODE_1 {
@@ -171,37 +172,9 @@ impl<T> Spim<T> where T: SpimExt {
171172
});
172173

173174
// Configure frequency
174-
spim.frequency.write(|w| match frequency {
175-
Frequency::K125 => {
176-
w.frequency().k125() // 125 kHz
177-
}
178-
Frequency::K250 => {
179-
w.frequency().k250() // 250 kHz
180-
}
181-
Frequency::K500 => {
182-
w.frequency().k500() // 500 kHz
183-
}
184-
Frequency::M1 => {
185-
w.frequency().m1() // 1 MHz
186-
}
187-
Frequency::M2 => {
188-
w.frequency().m2() // 2 MHz
189-
}
190-
Frequency::M4 => {
191-
w.frequency().m4() // 4 MHz
192-
}
193-
Frequency::M8 => {
194-
w.frequency().m8() // 8 MHz
195-
}
196-
#[cfg(feature = "52840")]
197-
Frequency::M16 => {
198-
w.frequency().m16() // 16 MHz
199-
}
200-
#[cfg(feature = "52840")]
201-
Frequency::M32 => {
202-
w.frequency().m32() // 32 MHz
203-
}
204-
});
175+
spim.frequency.write(|w|
176+
w.frequency().variant(frequency)
177+
);
205178

206179
// Set over-read character to `0`
207180
spim.orc.write(|w|
@@ -418,23 +391,6 @@ pub struct Pins {
418391
pub miso: Option<Pin<Input<Floating>>>,
419392
}
420393

421-
/// Frequencies for SPIM interface
422-
pub enum Frequency {
423-
K125,
424-
K250,
425-
K500,
426-
M1,
427-
M2,
428-
M4,
429-
M8,
430-
/// (only the 52840 can operate at 16M and 32M)
431-
#[cfg(feature = "52840")]
432-
M16,
433-
/// (only the 52840 can operate at 16M and 32M)
434-
#[cfg(feature = "52840")]
435-
M32,
436-
}
437-
438394
#[derive(Debug)]
439395
pub enum Error {
440396
TxBufferTooLong,

0 commit comments

Comments
 (0)