mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 06:42:32 +00:00
Add block-device-driver impl for use with embedded-fatfs (#2607)
This commit is contained in:
parent
9347571fea
commit
f0a8607051
@ -88,6 +88,8 @@ static_assertions = { version = "1.1" }
|
||||
volatile-register = { version = "0.2.1" }
|
||||
bitflags = "2.4.2"
|
||||
|
||||
block-device-driver = { version = "0.2" }
|
||||
aligned = "0.4.1"
|
||||
|
||||
[dev-dependencies]
|
||||
critical-section = { version = "1.1", features = ["std"] }
|
||||
|
@ -1511,3 +1511,44 @@ foreach_peripheral!(
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
impl<'d, T: Instance, Dma: SdmmcDma<T> + 'd> block_device_driver::BlockDevice<512> for Sdmmc<'d, T, Dma> {
|
||||
type Error = Error;
|
||||
type Align = aligned::A4;
|
||||
|
||||
async fn read(
|
||||
&mut self,
|
||||
mut block_address: u32,
|
||||
buf: &mut [aligned::Aligned<Self::Align, [u8; 512]>],
|
||||
) -> Result<(), Self::Error> {
|
||||
// FIXME/TODO because of missing read_blocks multiple we have to do this one block at a time
|
||||
for block in buf.iter_mut() {
|
||||
// safety aligned by block device
|
||||
let block = unsafe { &mut *(block as *mut _ as *mut crate::sdmmc::DataBlock) };
|
||||
self.read_block(block_address, block).await?;
|
||||
block_address += 1;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn write(
|
||||
&mut self,
|
||||
mut block_address: u32,
|
||||
buf: &[aligned::Aligned<Self::Align, [u8; 512]>],
|
||||
) -> Result<(), Self::Error> {
|
||||
// FIXME/TODO because of missing read_blocks multiple we have to do this one block at a time
|
||||
for block in buf.iter() {
|
||||
// safety aligned by block device
|
||||
let block = unsafe { &*(block as *const _ as *const crate::sdmmc::DataBlock) };
|
||||
self.write_block(block_address, block).await?;
|
||||
block_address += 1;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn size(&mut self) -> Result<u64, Self::Error> {
|
||||
Ok(self.card()?.size())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user