|
16 | 16 | //! couldn't work with a USB Thumb Drive, but we only supply a `BlockDevice` |
17 | 17 | //! suitable for reading SD and SDHC cards over SPI. |
18 | 18 | //! |
19 | | -//! ```rust,no_run |
20 | | -//! struct DummySpi; |
21 | | -//! struct DummyCsPin; |
22 | | -//! struct DummyUart; |
23 | | -//! struct DummyTimeSource; |
24 | | -//! struct DummyDelayer; |
25 | | -//! use embedded_hal::spi::Operation; |
26 | | -//! use embedded_hal::spi::ErrorType; |
27 | | -//! use core::convert::Infallible; |
28 | | -//! use core::fmt; |
| 19 | +//! ```rust |
| 20 | +//! use embedded_sdmmc::{Error, Mode, SdCard, SdCardError, TimeSource, VolumeIdx, VolumeManager}; |
29 | 21 | //! |
30 | | -//! impl ErrorType for DummySpi { |
31 | | -//! type Error = Infallible; |
32 | | -//! } |
33 | | -//! impl embedded_hal::spi::SpiDevice<u8> for DummySpi { |
34 | | -//! fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { Ok(()) } |
35 | | -//! fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> { Ok(()) } |
36 | | -//! fn write(&mut self, buf: &[u8]) -> Result<(), Self::Error> { Ok(()) } |
37 | | -//! fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error> { Ok(()) } |
38 | | -//! fn transfer_in_place(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> { Ok(()) } |
39 | | -//! } |
40 | | -//! impl embedded_hal::digital::ErrorType for DummyCsPin { |
41 | | -//! type Error = Infallible; |
42 | | -//! } |
43 | | -//! impl embedded_hal::digital::OutputPin for DummyCsPin { |
44 | | -//! fn set_low(&mut self) -> Result<(), Self::Error> { Ok(()) } |
45 | | -//! fn set_high(&mut self) -> Result<(), Self::Error> { Ok(()) } |
46 | | -//! } |
47 | | -//! impl embedded_sdmmc::TimeSource for DummyTimeSource { |
48 | | -//! fn get_timestamp(&self) -> embedded_sdmmc::Timestamp { embedded_sdmmc::Timestamp::from_fat(0, 0) } |
49 | | -//! } |
50 | | -//! impl embedded_hal::delay::DelayNs for DummyDelayer { |
51 | | -//! fn delay_ns(&mut self, ns: u32) {} |
52 | | -//! } |
53 | | -//! impl fmt::Write for DummyUart { |
54 | | -//! fn write_str(&mut self, s: &str) -> fmt::Result { Ok(()) } |
55 | | -//! } |
56 | | -//! use embedded_sdmmc::VolumeManager; |
57 | | -//! |
58 | | -//! fn main() -> Result<(), embedded_sdmmc::Error<embedded_sdmmc::SdCardError>> { |
59 | | -//! let mut sdmmc_spi = DummySpi; |
60 | | -//! let mut sdmmc_cs = DummyCsPin; |
61 | | -//! let time_source = DummyTimeSource; |
62 | | -//! let delayer = DummyDelayer; |
63 | | -//! let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs, delayer); |
| 22 | +//! fn example<S, CS, D, T>(spi: S, cs: CS, delay: D, ts: T) -> Result<(), Error<SdCardError>> |
| 23 | +//! where |
| 24 | +//! S: embedded_hal::spi::SpiDevice, |
| 25 | +//! CS: embedded_hal::digital::OutputPin, |
| 26 | +//! D: embedded_hal::delay::DelayNs, |
| 27 | +//! T: TimeSource, |
| 28 | +//! { |
| 29 | +//! let sdcard = SdCard::new(spi, cs, delay); |
64 | 30 | //! println!("Card size is {} bytes", sdcard.num_bytes()?); |
65 | | -//! let mut volume_mgr = VolumeManager::new(sdcard, time_source); |
66 | | -//! let mut volume0 = volume_mgr.open_volume(embedded_sdmmc::VolumeIdx(0))?; |
| 31 | +//! let mut volume_mgr = VolumeManager::new(sdcard, ts); |
| 32 | +//! let mut volume0 = volume_mgr.open_volume(VolumeIdx(0))?; |
67 | 33 | //! println!("Volume 0: {:?}", volume0); |
68 | 34 | //! let mut root_dir = volume0.open_root_dir()?; |
69 | | -//! let mut my_file = root_dir.open_file_in_dir("MY_FILE.TXT", embedded_sdmmc::Mode::ReadOnly)?; |
| 35 | +//! let mut my_file = root_dir.open_file_in_dir("MY_FILE.TXT", Mode::ReadOnly)?; |
70 | 36 | //! while !my_file.is_eof() { |
71 | 37 | //! let mut buffer = [0u8; 32]; |
72 | 38 | //! let num_read = my_file.read(&mut buffer)?; |
|
0 commit comments