Skip to main content

R1Response

Struct R1Response 

Source
pub struct R1Response {
    pub raw: u32,
}
Expand description

R1: Standard response — contains status bits

Fields§

§raw: u32

Implementations§

Source§

impl R1Response

Source

pub fn from_native_raw(raw: u32) -> Result<Self, Error>

Parse a native (SDIO/SDHCI) 32-bit R1 response.

SD Physical Layer spec section 4.10.1 (Table 4-42) places the card status error flags at bits 19..=31:

BitName
31OUT_OF_RANGE
30ADDRESS_ERROR
29BLOCK_LEN_ERROR
28ERASE_SEQ_ERROR
27ERASE_PARAM
26WP_VIOLATION
25CARD_IS_LOCKED
24LOCK_UNLOCK_FAILED
23COM_CRC_ERROR
22ILLEGAL_COMMAND
21CARD_ECC_FAILED
20CC_ERROR
19ERROR

If any of those 13 bits is set this returns Err(Error::CardError(..)). Otherwise the raw value is preserved so callers can inspect informational state bits (current_state, ready_for_data, …).

Note: earlier versions only looked at bits 19..=24 and silently dropped OUT_OF_RANGE, ADDRESS_ERROR, BLOCK_LEN_ERROR, ERASE_PARAM, WP_VIOLATION, CARD_IS_LOCKED, and COM_CRC_ERROR. Callers that used to see Ok for one of those now correctly see Err(CardError::..).

Source

pub fn from_spi_byte(byte: u8) -> Result<Self, Error>

Parse a single-byte SPI R1 response.

SPI R1 has a fixed 0 start bit (the high bit must be clear). The remaining bits encode informational state (idle, erase reset) and soft error flags (illegal command, CRC error, …). Because some flags — especially illegal_command — are expected during initialization (e.g. CMD8 on SD v1 cards), this function does NOT itself convert flag bits into Err. Callers should inspect the helpers (R1Response::illegal_command etc.) to decide what to do.

Returns Err(Error::BadResponse(_)) when the high bit is set, which indicates a malformed response or that no R1 byte arrived.

Source

pub fn spi_card_error(&self) -> Option<CardError>

Decode error flag bits in a SPI R1 response into a CardError.

Returns None when no error bits are set. Only meaningful for values produced by R1Response::from_spi_byte; native R1 layouts use a different bit mapping and report errors directly through R1Response::from_native_raw.

Source

pub fn idle(&self) -> bool

Card is in idle state

Source

pub fn erase_reset(&self) -> bool

Erase reset

Source

pub fn illegal_command(&self) -> bool

Illegal command

Source

pub fn command_crc_failed(&self) -> bool

Command CRC failed

Source

pub fn current_state(&self) -> CardState

Current state of the card state machine (bits 12:15).

Only meaningful for native (SDIO) R1 responses; SPI R1 bytes do not encode card state.

Source

pub fn card_is_locked(&self) -> bool

Card is locked (native R1 only)

Source

pub fn ready_for_data(&self) -> bool

READY_FOR_DATA (bit 8): card buffer is empty and the next data transfer can be issued. Used after R1b commands (CMD7, CMD12, MMC CMD6 SWITCH) to know when the busy line has cleared.

Only meaningful for native (SDIO) R1 responses.

Source

pub fn switch_error(&self) -> bool

SWITCH_ERROR (bit 7): the previous MMC CMD6 SWITCH was rejected (e.g. invalid EXT_CSD field, value out of range). Surfaces here because CMD6 itself returns R1b with this bit, but most error reporters hide bits 0..15.

Trait Implementations§

Source§

impl Clone for R1Response

Source§

fn clone(&self) -> R1Response

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for R1Response

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for R1Response

Source§

fn eq(&self, other: &R1Response) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for R1Response

Source§

impl Eq for R1Response

Source§

impl StructuralPartialEq for R1Response

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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>,

Source§

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>,

Source§

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.