pub struct SpiSdCard<SPI, D> { /* private fields */ }Expand description
An SD card behind a SpiDevice, so the bus can be shared with other devices. Every device on a
shared bus keeps its own clock and mode in its own SpiDevice; this driver never touches the bus
configuration. The card is read-only unless the write feature is on.
The SD spec wants chip select low from the command through the data block. A read is therefore one transaction: the command frame, a window for the R1 and the idle bytes before the data token, and the block with its CRC. The window follows the gap the card shows (it clocks the whole window every time, so it stays as small as the card allows). If the token has not arrived when the window ends, the read falls back to polling for it with chip select released between polls, which a card that aborts on chip select rising will fail; the window then grows, so a retry takes the single transaction path.
The SpiDevice must be at a clock of 400 kHz or less for new, and can be raised afterwards
through spi_mut. A card’s MISO driver can take a clock edge to let go of the line after chip
select rises, so on a bus shared with a device that is selected right afterwards the first bit it
sends can be corrupted; give the card its own bus if that matters.
Implementations§
Source§impl<SPI, D> SpiSdCard<SPI, D>
impl<SPI, D> SpiSdCard<SPI, D>
Sourcepub async fn new(spi: SPI, delay: D) -> Result<Self, SpiError<SPI::Error>>
pub async fn new(spi: SPI, delay: D) -> Result<Self, SpiError<SPI::Error>>
Initialises the card: resets it, negotiates SDHC/SDXC, turns on CRCs and reads its size. The SpiDevice must be at
400 kHz or less, and the card must already have had its 74 init clocks (see send_init_clocks).
Sourcepub async fn init(
spi: SPI,
delay: D,
) -> Result<Self, (SPI, SpiError<SPI::Error>)>
pub async fn init( spi: SPI, delay: D, ) -> Result<Self, (SPI, SpiError<SPI::Error>)>
new, giving the SPI device back when the card does not initialise (none fitted, a bad card), so the caller can
try again.
Sourcepub fn is_high_capacity(&self) -> bool
pub fn is_high_capacity(&self) -> bool
Whether the card is SDHC or SDXC (block addressed) rather than standard capacity.