Skip to content

Commit b46c26f

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

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

embedded-hal/src/mmc.rs

Lines changed: 4 additions & 7 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_type;
45
mod fifo_status;
56
mod reset;
67

@@ -9,6 +10,7 @@ pub mod response;
910
pub mod tuning;
1011

1112
pub use bus_width::BusWidth;
13+
pub use card_type::CardType;
1214
pub use fifo_status::FifoStatus;
1315
pub use reset::Reset;
1416

@@ -21,13 +23,8 @@ pub trait MmcOps {
2123
/// Associated error type for the SD/MMC trait.
2224
type Error;
2325

24-
/// Gets whether the device is a MMC card.
25-
fn is_mmc(&self) -> bool;
26-
27-
/// Gets whether the device is a SD card.
28-
fn is_sd(&self) -> bool {
29-
!self.is_mmc()
30-
}
26+
/// Gets whether the device [CardType].
27+
fn card_type(&self) -> CardType;
3128

3229
/// Gets whether the device is configured for SPI mode.
3330
fn is_spi(&self) -> bool;

embedded-hal/src/mmc/card_type.rs

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

0 commit comments

Comments
 (0)