Skip to content

Commit 4d3a3ae

Browse files
committed
Make converting SD card frequency easier
1 parent 6b8c27a commit 4d3a3ae

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/sdcard.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ pub enum SdCardFreq {
5757
Custom(Hertz)
5858
}
5959

60+
impl From<SdCardFreq> for Hertz {
61+
fn from(value: SdCardFreq) -> Hertz {
62+
match value {
63+
SdCardFreq::Safe => 200.khz().into(), // using 300 kHz here because the sdcard init needs 100 to 400 kHz (see SdMmcSpi.init)
64+
SdCardFreq::Fast => 27.mhz().into(), // this is the max SPI frequency according to datasheet
65+
SdCardFreq::Custom(val) => val,
66+
}
67+
}
68+
}
69+
6070
/// Constructs SD Card driver from the required components.
6171
pub fn configure(spi: SPI1, pins: SdCardPins, freq: SdCardFreq, rcu: &mut Rcu) -> SdCard {
62-
let freq = match freq {
63-
SdCardFreq::Safe => 200.khz().into(), // using 300 kHz here because the sdcard init needs 100 to 400 kHz (see SdMmcSpi.init)
64-
SdCardFreq::Fast => 27.mhz().into(), // this is the max SPI frequency according to datasheet
65-
SdCardFreq::Custom(val) => val,
66-
};
67-
6872
let spi1 = Spi::spi1(
6973
spi,
7074
(pins.sck, pins.miso, pins.mosi),

0 commit comments

Comments
 (0)