Skip to content

Commit a0237aa

Browse files
committed
mmc: split MMC traits
Splits the SD/MMC traits into `MmcCommon`, `MmcHost`, and `MmcDevice` to clarify the purpose of each set of trait methods.
1 parent a305178 commit a0237aa

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

embedded-hal/src/mmc.rs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use command::MmcCommand;
2020
use response::MmcResponse;
2121
use tuning::{TuningMode, TuningWidth};
2222

23-
/// Common operations for DesignWare MMC controllers on JH7110 SoCs.
24-
pub trait MmcOps {
23+
/// Common operations for SD/MMC peripherals.
24+
pub trait MmcCommon {
2525
/// Associated error type for the SD/MMC trait.
2626
type Error;
2727

@@ -37,44 +37,33 @@ pub trait MmcOps {
3737
/// Performs device initialization sequence.
3838
fn init(&mut self) -> Result<(), Self::Error>;
3939

40-
/// Sets the sample phase for the MMC controller.
41-
fn set_sample_phase(&mut self, sample_phase: u8);
42-
43-
/// Waits for the FIFO to indicate readiness for read/write operations.
44-
fn fifo_ready(&self, fifo_status: FifoStatus) -> Result<(), Self::Error>;
45-
4640
/// Waits for the CMD line to reset (usually during power-up).
4741
fn wait_for_reset(&mut self, reset: Reset, timeout: u64) -> Result<(), Self::Error>;
4842

4943
/// Waits for the busy signal to clear for maximum `timeout_us` microseconds.
5044
fn wait_while_busy(&mut self, timout_us: u64) -> Result<(), Self::Error>;
5145

52-
/// Writes a SD/MMC command to the card.
53-
fn write_command<C: MmcCommand>(&mut self, cmd: &C) -> Result<(), Self::Error>;
54-
55-
/// Reads a SD/MMC response based on the provided command argument.
56-
///
57-
/// # Note
58-
///
59-
/// `cmd` should match the last call to `write_command`.
60-
fn read_response<C: MmcCommand, R: MmcResponse>(&mut self, cmd: &C) -> Result<R, Self::Error>;
61-
62-
/// Reads the raw response bytes from the MMC controller.
63-
///
64-
/// # Note
65-
///
66-
/// Set `exp_crc` to true if a CRC checksum is expected in the response.
67-
///
68-
/// The generic `N` parameter is for the expected length (in bytes) of the response.
69-
fn response_bytes<const N: usize>(&mut self, exp_crc: bool) -> Result<[u8; N], Self::Error>;
70-
7146
/// Reads data from the MMC data lines.
7247
fn read_data(&mut self, data: &mut [u8]) -> Result<(), Self::Error>;
7348

7449
/// Writes data to the MMC data lines.
7550
fn write_data(&mut self, data: &[u8]) -> Result<(), Self::Error>;
7651

77-
/// Requests the card to send a tuning block.
52+
/// Sets the sample phase for the MMC controller.
53+
fn set_sample_phase(&mut self, sample_phase: u8);
54+
55+
/// Waits for the FIFO to indicate readiness for read/write operations.
56+
fn fifo_ready(&self, fifo_status: FifoStatus) -> Result<(), Self::Error>;
57+
58+
/// Handles tuning block requests.
59+
///
60+
/// For hosts:
61+
///
62+
/// - requests the device to send a tuning block
63+
///
64+
/// For devices:
65+
///
66+
/// - sends the host the requested tuning block
7867
fn send_tuning(&mut self, mode: TuningMode, width: TuningWidth) -> Result<(), Self::Error>;
7968

8069
/// Gets the interrupts status as a 32-bit bitfield.
@@ -95,3 +84,25 @@ pub trait MmcOps {
9584
/// Clear all interrupts.
9685
fn clear_all_response_interrupt(&mut self);
9786
}
87+
88+
/// Common operations for SD/MMC host peripherals.
89+
pub trait MmcHost: MmcCommon {
90+
/// Writes a SD/MMC command to the card.
91+
fn write_command<C: MmcCommand>(&mut self, cmd: &C) -> Result<(), Self::Error>;
92+
93+
/// Reads a SD/MMC response based on the provided command argument.
94+
///
95+
/// # Note
96+
///
97+
/// `cmd` should match the last call to `write_command`.
98+
fn read_response<C: MmcCommand, R: MmcResponse>(&mut self, cmd: &C) -> Result<R, Self::Error>;
99+
}
100+
101+
/// Common operations for SD/MMC device peripherals.
102+
pub trait MmcDevice: MmcCommon {
103+
/// Reads a SD/MMC command sent from the host.
104+
fn read_command<C: MmcCommand>(&mut self) -> Result<C, Self::Error>;
105+
106+
/// Writes a SD/MMC response based on the previous command.
107+
fn write_response<R: MmcResponse>(&mut self, response: &R) -> Result<(), Self::Error>;
108+
}

embedded-hal/src/mmc/bus_width.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Represents the variants of the `bus width` field of the [Argument](super::Argument).
1+
/// Represents the variants of the `bus width` configuration for the SD/MMC peripheral.
22
#[repr(u8)]
33
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
44
pub enum BusWidth {

0 commit comments

Comments
 (0)