Skip to content

Commit a33b10f

Browse files
authored
Merge pull request #63 from gauteh/sdmmc-spi-borrow
sdmmcspi: add method for borrowing spi (useful for re-clocking)
2 parents aa1d3c2 + 71d15ab commit a33b10f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/sdmmc.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use super::sdmmc_proto::*;
99
use super::{Block, BlockCount, BlockDevice, BlockIdx};
1010
use core::cell::RefCell;
11+
use core::ops::Deref;
1112

1213
#[cfg(feature = "log")]
1314
use log::{debug, trace, warn};
@@ -360,6 +361,12 @@ where
360361
}
361362
Ok(())
362363
}
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+
}
363370
}
364371

365372
impl<SPI, CS> BlockSpi<'_, SPI, CS>
@@ -481,6 +488,27 @@ where
481488
}
482489
}
483490

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+
484512
impl<SPI, CS> BlockDevice for BlockSpi<'_, SPI, CS>
485513
where
486514
SPI: embedded_hal::blocking::spi::Transfer<u8>,

0 commit comments

Comments
 (0)