Skip to content

Commit fc49578

Browse files
committed
mmc: use new-types for the card mode
Adds the `CardMode` enum to represent the device mode for a SD/MMC perpipheral.
1 parent b46c26f commit fc49578

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

embedded-hal/src/mmc.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Types and traits for SD/MMC peripherals.
22
33
mod bus_width;
4+
mod card_mode;
45
mod card_type;
56
mod fifo_status;
67
mod reset;
@@ -10,6 +11,7 @@ pub mod response;
1011
pub mod tuning;
1112

1213
pub use bus_width::BusWidth;
14+
pub use card_mode::CardMode;
1315
pub use card_type::CardType;
1416
pub use fifo_status::FifoStatus;
1517
pub use reset::Reset;
@@ -23,11 +25,11 @@ pub trait MmcOps {
2325
/// Associated error type for the SD/MMC trait.
2426
type Error;
2527

26-
/// Gets whether the device [CardType].
28+
/// Gets the device [CardType].
2729
fn card_type(&self) -> CardType;
2830

29-
/// Gets whether the device is configured for SPI mode.
30-
fn is_spi(&self) -> bool;
31+
/// Gets the device [CardMode].
32+
fn card_mode(&self) -> CardMode;
3133

3234
/// Performs bus setup for the SD/MMC device.
3335
fn setup_bus(&mut self) -> Result<(), Self::Error>;

embedded-hal/src/mmc/card_mode.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// Represents the card mode of the peripheral.
2+
#[repr(u8)]
3+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4+
pub enum CardMode {
5+
/// Represents a device in SD mode.
6+
Sd,
7+
/// Represents a device in SDIO mode.
8+
Sdio,
9+
/// Represents a device in SPI mode.
10+
Spi,
11+
}
12+
13+
impl CardMode {
14+
/// Creates a new [CardMode].
15+
pub const fn new() -> Self {
16+
Self::Sd
17+
}
18+
19+
/// Convenience function to get if the [CardMode] is SD.
20+
pub const fn is_sd(&self) -> bool {
21+
matches!(self, Self::Sd)
22+
}
23+
24+
/// Convenience function to get if the [CardMode] is SDIO.
25+
pub const fn is_sdio(&self) -> bool {
26+
matches!(self, Self::Sdio)
27+
}
28+
29+
/// Convenience function to get if the [CardMode] is SPI.
30+
pub const fn is_spi(&self) -> bool {
31+
matches!(self, Self::Spi)
32+
}
33+
}
34+
35+
impl Default for CardMode {
36+
fn default() -> Self {
37+
Self::new()
38+
}
39+
}

0 commit comments

Comments
 (0)