|
21 | 21 | //! # struct DummyCsPin;
|
22 | 22 | //! # struct DummyUart;
|
23 | 23 | //! # struct DummyTimeSource;
|
| 24 | +//! # struct DummyDelayer; |
24 | 25 | //! # impl embedded_hal::blocking::spi::Transfer<u8> for DummySpi {
|
25 | 26 | //! # type Error = ();
|
26 |
| -//! # fn transfer<'w>(&mut self, data: &'w mut [u8]) -> Result<&'w [u8], ()> { Ok(&[0]) } |
| 27 | +//! # fn transfer<'w>(&mut self, data: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { Ok(&[0]) } |
| 28 | +//! # } |
| 29 | +//! # impl embedded_hal::blocking::spi::Write<u8> for DummySpi { |
| 30 | +//! # type Error = (); |
| 31 | +//! # fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> { Ok(()) } |
27 | 32 | //! # }
|
28 | 33 | //! # impl embedded_hal::digital::v2::OutputPin for DummyCsPin {
|
29 | 34 | //! # type Error = ();
|
|
33 | 38 | //! # impl embedded_sdmmc::TimeSource for DummyTimeSource {
|
34 | 39 | //! # fn get_timestamp(&self) -> embedded_sdmmc::Timestamp { embedded_sdmmc::Timestamp::from_fat(0, 0) }
|
35 | 40 | //! # }
|
| 41 | +//! # impl embedded_hal::blocking::delay::DelayUs<u8> for DummyDelayer { |
| 42 | +//! # fn delay_us(&mut self, us: u8) {} |
| 43 | +//! # } |
36 | 44 | //! # impl std::fmt::Write for DummyUart { fn write_str(&mut self, s: &str) -> std::fmt::Result { Ok(()) } }
|
37 | 45 | //! # use std::fmt::Write;
|
38 | 46 | //! # use embedded_sdmmc::VolumeManager;
|
39 |
| -//! # fn main() -> Result<(), embedded_sdmmc::Error<embedded_sdmmc::SdMmcError>> { |
| 47 | +//! # fn main() -> Result<(), embedded_sdmmc::Error<embedded_sdmmc::SdCardError>> { |
40 | 48 | //! # let mut sdmmc_spi = DummySpi;
|
41 | 49 | //! # let mut sdmmc_cs = DummyCsPin;
|
42 | 50 | //! # let time_source = DummyTimeSource;
|
43 |
| -//! let mut spi_dev = embedded_sdmmc::SdMmcSpi::new(sdmmc_spi, sdmmc_cs); |
44 |
| -//! let block = spi_dev.acquire()?; |
45 |
| -//! println!("Card size {} bytes", block.card_size_bytes()?); |
46 |
| -//! let mut volume_mgr = VolumeManager::new(block, time_source); |
47 |
| -//! println!("Card size is still {} bytes", volume_mgr.device().card_size_bytes()?); |
| 51 | +//! # let delayer = DummyDelayer; |
| 52 | +//! let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs, delayer); |
| 53 | +//! println!("Card size {} bytes", sdcard.num_bytes()?); |
| 54 | +//! let mut volume_mgr = VolumeManager::new(sdcard, time_source); |
| 55 | +//! println!("Card size is still {} bytes", volume_mgr.device().num_bytes()?); |
48 | 56 | //! let mut volume0 = volume_mgr.get_volume(embedded_sdmmc::VolumeIdx(0))?;
|
49 | 57 | //! println!("Volume 0: {:?}", volume0);
|
50 | 58 | //! let root_dir = volume_mgr.open_root_dir(&volume0)?;
|
@@ -91,24 +99,53 @@ mod structure;
|
91 | 99 | pub mod blockdevice;
|
92 | 100 | pub mod fat;
|
93 | 101 | pub mod filesystem;
|
94 |
| -pub mod sdmmc; |
95 |
| -pub mod sdmmc_proto; |
| 102 | +pub mod sdcard; |
96 | 103 |
|
97 | 104 | pub use crate::blockdevice::{Block, BlockCount, BlockDevice, BlockIdx};
|
98 | 105 | pub use crate::fat::FatVolume;
|
99 | 106 | pub use crate::filesystem::{
|
100 | 107 | Attributes, Cluster, DirEntry, Directory, File, FilenameError, Mode, ShortFileName, TimeSource,
|
101 | 108 | Timestamp, MAX_FILE_SIZE,
|
102 | 109 | };
|
103 |
| -pub use crate::sdmmc::Error as SdMmcError; |
104 |
| -pub use crate::sdmmc::{BlockSpi, SdMmcSpi}; |
| 110 | +pub use crate::sdcard::Error as SdCardError; |
| 111 | +pub use crate::sdcard::SdCard; |
105 | 112 |
|
106 | 113 | mod volume_mgr;
|
107 | 114 | pub use volume_mgr::VolumeManager;
|
108 | 115 |
|
109 | 116 | #[deprecated]
|
110 | 117 | pub use volume_mgr::VolumeManager as Controller;
|
111 | 118 |
|
| 119 | +#[cfg(all(feature = "defmt-log", feature = "log"))] |
| 120 | +compile_error!("Cannot enable both log and defmt-log"); |
| 121 | + |
| 122 | +#[cfg(feature = "log")] |
| 123 | +use log::{debug, trace, warn}; |
| 124 | + |
| 125 | +#[cfg(feature = "defmt-log")] |
| 126 | +use defmt::{debug, trace, warn}; |
| 127 | + |
| 128 | +#[cfg(all(not(feature = "defmt-log"), not(feature = "log")))] |
| 129 | +#[macro_export] |
| 130 | +/// Like log::debug! but does nothing at all |
| 131 | +macro_rules! debug { |
| 132 | + ($($arg:tt)+) => {}; |
| 133 | +} |
| 134 | + |
| 135 | +#[cfg(all(not(feature = "defmt-log"), not(feature = "log")))] |
| 136 | +#[macro_export] |
| 137 | +/// Like log::trace! but does nothing at all |
| 138 | +macro_rules! trace { |
| 139 | + ($($arg:tt)+) => {}; |
| 140 | +} |
| 141 | + |
| 142 | +#[cfg(all(not(feature = "defmt-log"), not(feature = "log")))] |
| 143 | +#[macro_export] |
| 144 | +/// Like log::warn! but does nothing at all |
| 145 | +macro_rules! warn { |
| 146 | + ($($arg:tt)+) => {}; |
| 147 | +} |
| 148 | + |
112 | 149 | // ****************************************************************************
|
113 | 150 | //
|
114 | 151 | // Public Types
|
|
0 commit comments