Struct embedded_sdmmc::SdCard
source · pub struct SdCard<SPI, CS, DELAYER>{ /* private fields */ }
Expand description
Represents an SD Card on an SPI bus.
Built from an SpiDevice
implementation and a Chip Select pin.
Unfortunately, We need control of the chip select pin separately from the SpiDevice
implementation so we can clock out some bytes without Chip Select asserted
(which is necessary to make the SD card actually release the Spi bus after performing
operations on it, according to the spec). To support this, we provide DummyCsPin
which should be provided to your chosen SpiDevice
implementation rather than the card’s
actual CS pin. Then provide the actual CS pin to SdCard
’s constructor.
All the APIs take &self
- mutability is handled using an inner RefCell
.
Implementations§
source§impl<SPI, CS, DELAYER> SdCard<SPI, CS, DELAYER>
impl<SPI, CS, DELAYER> SdCard<SPI, CS, DELAYER>
sourcepub fn new(spi: SPI, cs: CS, delayer: DELAYER) -> SdCard<SPI, CS, DELAYER>
pub fn new(spi: SPI, cs: CS, delayer: DELAYER) -> SdCard<SPI, CS, DELAYER>
Create a new SD/MMC Card driver using a raw SPI interface.
See the docs of the SdCard
struct for more information about
how to construct the needed SPI
and CS
types.
The card will not be initialised at this time. Initialisation is deferred until a method is called on the object.
Uses the default options.
sourcepub fn new_with_options(
spi: SPI,
cs: CS,
delayer: DELAYER,
options: AcquireOpts
) -> SdCard<SPI, CS, DELAYER>
pub fn new_with_options( spi: SPI, cs: CS, delayer: DELAYER, options: AcquireOpts ) -> SdCard<SPI, CS, DELAYER>
Construct a new SD/MMC Card driver, using a raw SPI interface and the given options.
See the docs of the SdCard
struct for more information about
how to construct the needed SPI
and CS
types.
The card will not be initialised at this time. Initialisation is deferred until a method is called on the object.
sourcepub fn spi<T, F>(&self, func: F) -> T
pub fn spi<T, F>(&self, func: F) -> T
Get a temporary borrow on the underlying SPI device.
The given closure will be called exactly once, and will be passed a mutable reference to the underlying SPI object.
Useful if you need to re-clock the SPI, but does not perform card initialisation.
sourcepub fn num_bytes(&self) -> Result<u64, Error>
pub fn num_bytes(&self) -> Result<u64, Error>
Return the usable size of this SD card in bytes.
This will trigger card (re-)initialisation.
sourcepub fn erase_single_block_enabled(&self) -> Result<bool, Error>
pub fn erase_single_block_enabled(&self) -> Result<bool, Error>
Can this card erase single blocks?
This will trigger card (re-)initialisation.
sourcepub fn mark_card_uninit(&self)
pub fn mark_card_uninit(&self)
Mark the card as requiring a reset.
The next operation will assume the card has been freshly inserted.
sourcepub fn get_card_type(&self) -> Option<CardType>
pub fn get_card_type(&self) -> Option<CardType>
Get the card type.
This will trigger card (re-)initialisation.
sourcepub unsafe fn mark_card_as_init(&self, card_type: CardType)
pub unsafe fn mark_card_as_init(&self, card_type: CardType)
Tell the driver the card has been initialised.
This is here in case you were previously using the SD Card, and then a previous instance of this object got destroyed but you know for certain the SD Card remained powered up and initialised, and you’d just like to read/write to/from the card again without going through the initialisation sequence again.
§Safety
Only do this if the SD Card has actually been initialised. That is, if
you have been through the card initialisation sequence as specified in
the SD Card Specification by sending each appropriate command in turn,
either manually or using another variable of this SdCard
. The card
must also be of the indicated type. Failure to uphold this will cause
data corruption.
Trait Implementations§
source§impl<SPI, CS, DELAYER> BlockDevice for SdCard<SPI, CS, DELAYER>
impl<SPI, CS, DELAYER> BlockDevice for SdCard<SPI, CS, DELAYER>
source§fn read(
&self,
blocks: &mut [Block],
start_block_idx: BlockIdx,
_reason: &str
) -> Result<(), Self::Error>
fn read( &self, blocks: &mut [Block], start_block_idx: BlockIdx, _reason: &str ) -> Result<(), Self::Error>
Read one or more blocks, starting at the given block index.
This will trigger card (re-)initialisation.
source§fn write(
&self,
blocks: &[Block],
start_block_idx: BlockIdx
) -> Result<(), Self::Error>
fn write( &self, blocks: &[Block], start_block_idx: BlockIdx ) -> Result<(), Self::Error>
Write one or more blocks, starting at the given block index.
This will trigger card (re-)initialisation.
source§fn num_blocks(&self) -> Result<BlockCount, Self::Error>
fn num_blocks(&self) -> Result<BlockCount, Self::Error>
Determine how many blocks this device can hold.
This will trigger card (re-)initialisation.