pub struct Spi2CardGuard<'a, CS: OutputPin> { /* private fields */ }Expand description
The SPI2 bus and the card’s chip-select, held together.
This exists because chip-select continuity is not expressible from
outside the BSP. SpiDevice::transaction asserts CS on entry and
deasserts on exit, and one SD command is several transactions — the
0xFE data-token wait is unbounded, so it cannot be folded into a single
fixed operation list. A driver holding only a SpiDevice therefore drops
CS mid-command no matter how carefully it locks.
The BSP owns both halves, so it can hand them out together: take this guard once per command, assert CS yourself, and CS stays low for the whole exchange. Drop it between commands (and between busy-poll probes) so the display still gets the bus — a full-card erase must not freeze the UI.
Implementations§
Source§impl<CS: OutputPin> Spi2CardGuard<'_, CS>
impl<CS: OutputPin> Spi2CardGuard<'_, CS>
Sourcepub fn split(&mut self) -> (&mut SpiBusType, &mut PresenceCs<CS>)
pub fn split(&mut self) -> (&mut SpiBusType, &mut PresenceCs<CS>)
The bus and the chip-select, borrowed together for one command.
Sourcepub fn apply_config(&mut self, config: &SpiConfig) -> Result<(), ConfigError>
pub fn apply_config(&mut self, config: &SpiConfig) -> Result<(), ConfigError>
Re-configure the bus while holding it — the SD clock raise after
init(), in practice.
Needed because the card driver no longer holds a SpiDevice to
carry a per-device config: it drives the bus directly, so the clock
change has to happen here, under the same guard, or the card would
stay at the 400 kHz init clock for its whole life.
Trait Implementations§
Source§impl<CS: OutputPin> Drop for Spi2CardGuard<'_, CS>
impl<CS: OutputPin> Drop for Spi2CardGuard<'_, CS>
Source§fn drop(&mut self)
fn drop(&mut self)
Deselect the card as the bus is released.
These are the same event: leaving CS low after the guard drops would
leave the card selected while another master owns the bus, which is
worse than the mid-command CS drops this guard exists to remove. It
also lets the driver assert CS once per command and then use ?
freely — every early return releases the card by unwinding here.
§fn pin_drop(self: Pin<&mut Self>)
fn pin_drop(self: Pin<&mut Self>)
pin_ergonomics)Drop::drop, it requires self
to be pinned. Read more