|
8 | 8 | use super::sdmmc_proto::*; |
9 | 9 | use super::{Block, BlockCount, BlockDevice, BlockIdx}; |
10 | 10 | use core::cell::RefCell; |
| 11 | +use core::ops::Deref; |
11 | 12 |
|
12 | 13 | #[cfg(feature = "log")] |
13 | 14 | use log::{debug, trace, warn}; |
@@ -360,6 +361,12 @@ where |
360 | 361 | } |
361 | 362 | Ok(()) |
362 | 363 | } |
| 364 | + |
| 365 | + /// Get a temporary borrow on the underlying SPI device. Useful if you |
| 366 | + /// need to re-clock the SPI. |
| 367 | + pub fn spi(&mut self) -> core::cell::RefMut<SPI> { |
| 368 | + self.spi.borrow_mut() |
| 369 | + } |
363 | 370 | } |
364 | 371 |
|
365 | 372 | impl<SPI, CS> BlockSpi<'_, SPI, CS> |
@@ -481,6 +488,27 @@ where |
481 | 488 | } |
482 | 489 | } |
483 | 490 |
|
| 491 | +impl<U: BlockDevice, T: Deref<Target = U>> BlockDevice for T { |
| 492 | + type Error = U::Error; |
| 493 | + fn read( |
| 494 | + &self, |
| 495 | + blocks: &mut [Block], |
| 496 | + start_block_idx: BlockIdx, |
| 497 | + _reason: &str, |
| 498 | + ) -> Result<(), Self::Error> { |
| 499 | + self.deref().read(blocks, start_block_idx, _reason) |
| 500 | + } |
| 501 | + |
| 502 | + /// Write one or more blocks, starting at the given block index. |
| 503 | + fn write(&self, blocks: &[Block], start_block_idx: BlockIdx) -> Result<(), Self::Error> { |
| 504 | + self.deref().write(blocks, start_block_idx) |
| 505 | + } |
| 506 | + |
| 507 | + fn num_blocks(&self) -> Result<BlockCount, Self::Error> { |
| 508 | + self.deref().num_blocks() |
| 509 | + } |
| 510 | +} |
| 511 | + |
484 | 512 | impl<SPI, CS> BlockDevice for BlockSpi<'_, SPI, CS> |
485 | 513 | where |
486 | 514 | SPI: embedded_hal::blocking::spi::Transfer<u8>, |
|
0 commit comments