Struct embedded_sdmmc::SdCard

source ·
pub struct SdCard<SPI, CS, DELAYER>
where SPI: SpiDevice<u8>, CS: OutputPin, DELAYER: DelayNs,
{ /* 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>
where SPI: SpiDevice<u8>, CS: OutputPin, DELAYER: DelayNs,

source

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.

source

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.

source

pub fn spi<T, F>(&self, func: F) -> T
where F: FnOnce(&mut SPI) -> 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.

source

pub fn num_bytes(&self) -> Result<u64, Error>

Return the usable size of this SD card in bytes.

This will trigger card (re-)initialisation.

source

pub fn erase_single_block_enabled(&self) -> Result<bool, Error>

Can this card erase single blocks?

This will trigger card (re-)initialisation.

source

pub fn mark_card_uninit(&self)

Mark the card as requiring a reset.

The next operation will assume the card has been freshly inserted.

source

pub fn get_card_type(&self) -> Option<CardType>

Get the card type.

This will trigger card (re-)initialisation.

source

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>
where SPI: SpiDevice<u8>, CS: OutputPin, DELAYER: DelayNs,

source§

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>

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>

Determine how many blocks this device can hold.

This will trigger card (re-)initialisation.

§

type Error = Error

The errors that the BlockDevice can return. Must be debug formattable.

Auto Trait Implementations§

§

impl<SPI, CS, DELAYER> !RefUnwindSafe for SdCard<SPI, CS, DELAYER>

§

impl<SPI, CS, DELAYER> Send for SdCard<SPI, CS, DELAYER>
where CS: Send, DELAYER: Send, SPI: Send,

§

impl<SPI, CS, DELAYER> !Sync for SdCard<SPI, CS, DELAYER>

§

impl<SPI, CS, DELAYER> Unpin for SdCard<SPI, CS, DELAYER>
where CS: Unpin, DELAYER: Unpin, SPI: Unpin,

§

impl<SPI, CS, DELAYER> UnwindSafe for SdCard<SPI, CS, DELAYER>
where CS: UnwindSafe, DELAYER: UnwindSafe, SPI: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.