sdmmc_protocol/lib.rs
1//! `no_std` SD/MMC protocol building blocks for embedded systems.
2//!
3//! This crate provides protocol-level types and driver skeletons for SD,
4//! MMC and SDIO cards. It is transport-agnostic at the trait level and
5//! brings its own SPI-mode driver plus an SDIO host-controller abstraction.
6//!
7//! # What you get
8//!
9//! - [`cmd::Command`] / [`cmd::DataDirection`]: SD/MMC command opcodes,
10//! argument encoding and per-command data direction.
11//! - [`response::Response`] and friends ([`response::CidResponse`],
12//! [`response::CsdResponse`], [`response::SwitchStatus`], ...): typed
13//! parsers for the response formats defined in the SD spec.
14//! - [`error::Error`]: a single error enum the drivers and parsers return.
15//! - [`spi`] *(feature `spi`, on by default)*: a [`spi::SpiTransport`] trait
16//! plus the [`spi::SpiSdmmc`] driver for SPI-mode SD cards. Includes a
17//! thin [`spi::SpiDeviceWrapper`] adapter for `embedded-hal` 1.0
18//! `SpiDevice<u8>` implementations.
19//! - [`sdio`] *(feature `sdio`)*: a [`sdio::SdioHost`] trait that abstracts
20//! a host controller and the [`sdio::SdioSdmmc`] driver that drives it
21//! through card initialization, block I/O and bus-speed selection.
22//!
23//! # Cargo features
24//!
25//! | Feature | Default | Purpose |
26//! |----------|---------|-------------------------------------------------|
27//! | `spi` | yes | Enables [`spi::SpiTransport`] and [`spi::SpiSdmmc`]. |
28//! | `sdio` | no | Enables the host trait and submit/poll data-command contract. |
29//!
30//! Diagnostic output goes through the [`log`] crate; configure a logger in
31//! your application to capture it.
32//!
33//! # Example
34//!
35//! ```rust,ignore
36//! use embedded_hal::delay::DelayNs;
37//! use sdmmc_protocol::{
38//! Error,
39//! spi::{SpiSdmmc, SpiTransport},
40//! };
41//!
42//! struct MySpi;
43//!
44//! impl SpiTransport for MySpi {
45//! fn transfer_byte(&mut self, byte: u8) -> Result<u8, Error> {
46//! # let _ = byte;
47//! # Ok(0)
48//! }
49//! }
50//!
51//! fn boot<D: DelayNs>(spi: MySpi, delay: D) -> Result<(), Error> {
52//! let mut card = SpiSdmmc::new(spi, delay);
53//! let _info = card.init()?;
54//! let mut block = [0u8; 512];
55//! card.read_block(0, &mut block)?;
56//! Ok(())
57//! }
58//! ```
59//!
60//! # Maturity
61//!
62//! The SPI path has protocol-level unit tests and basic block read/write
63//! support. The SDIO path is a host abstraction skeleton and needs
64//! platform-specific validation before use on real hardware.
65//!
66//! # MSRV
67//!
68//! Rust 1.85 (the first stable to ship edition 2024).
69
70#![no_std]
71
72pub mod block;
73pub mod cmd;
74mod common;
75pub mod error;
76pub mod ext_csd;
77pub mod response;
78
79#[cfg(feature = "spi")]
80pub mod spi;
81
82#[cfg(feature = "sdio")]
83pub mod sdio;
84
85pub use block::{
86 BlockBufferConfig, BlockPoll, BlockRequestId, BlockTransferDirection, BlockTransferMode,
87 BlockTransferState, CommandPoll, CommandResponsePoll, DataCommandDirection, DataCommandPoll,
88 DataCommandState, OperationPoll,
89};
90pub use cmd::{Command, DataDirection};
91pub use error::{Error, ErrorContext, Phase};
92pub use response::{CidResponse, CsdResponse, Response, SwitchStatus};