Skip to content

Commit d16739e

Browse files
committed
Updated the README and added minor typo fixes
1 parent 5f4b3e7 commit d16739e

File tree

4 files changed

+51
-32
lines changed

4 files changed

+51
-32
lines changed

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,25 @@ By default the `VolumeManager` will initialize with a maximum number of `4` open
4646
let cont: VolumeManager<_, _, 6, 12, 4> = VolumeManager::new_with_limits(block, time_source);
4747
```
4848

49+
### Accessing SD Cards using an SD Host Controller
50+
51+
The `SdCard` type requires something that implements `Transport` in order to speak to the SD Card. We supply a generic `SpiTransport` that implements `Transport` using some underlying user-supplied implementation of `embedded_hal::spi::SpiDevice<u8>`. That will work for most applications.
52+
53+
However, if your MCU has a full SD Host Controller peripheral, and if you need high-performance access to your SD Card, you may wish to instead implement `Transport` in a way that uses that peripheral. SD Host Controllers, for example, often support a 4-bit wide interface instead of the 1-bit wide SPI interface, and run at higher clock rates.
54+
4955
## Supported features
5056

51-
* Open files in all supported methods from an open directory
52-
* Open an arbitrary number of directories and files
53-
* Read data from open files
54-
* Write data to open files
55-
* Close files
56-
* Delete files
57-
* Iterate root directory
58-
* Iterate sub-directories
59-
* Log over defmt or the common log interface (feature flags).
57+
* Talking to SD Cards over SPI (using the `embedded-hal::spi::SpiDevice` trait)
58+
* Talking to SD Cards over a custom transport (using our `Transport` trait)
59+
* Opening files in all supported modes from an open directory
60+
* Opening an arbitrary number of directories and files
61+
* Reading data from open files
62+
* Writing data to open files
63+
* Closing files
64+
* Deleting files
65+
* Iterating the root directory
66+
* Iterating sub-directories
67+
* Logging over defmt or the common log interface (see feature flags).
6068

6169
## No-std usage
6270

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ pub use crate::filesystem::{
9292
use filesystem::DirectoryInfo;
9393

9494
#[doc(inline)]
95-
pub use crate::sdcard::Error as SdCardError;
96-
97-
#[doc(inline)]
98-
pub use crate::sdcard::SdCard;
95+
pub use crate::sdcard::{Error as SdCardError, SdCard, SpiTransport, Transport};
9996

10097
mod volume_mgr;
10198
#[doc(inline)]

src/sdcard/mod.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
66
pub mod proto;
77
mod spi;
8+
9+
#[doc(inline)]
810
pub use spi::SpiTransport;
911

1012
use crate::{Block, BlockCount, BlockDevice, BlockIdx};
@@ -20,18 +22,7 @@ use crate::debug;
2022
// Types and Implementations
2123
// ****************************************************************************
2224

23-
/// Driver for an SD Card on an SPI bus.
24-
///
25-
/// Built from an [`SpiDevice`] implementation and a Chip Select pin.
26-
///
27-
/// Before talking to the SD Card, the caller needs to send 74 clocks cycles on
28-
/// the SPI Clock line, at 400 kHz, with no chip-select asserted (or at least,
29-
/// not the chip-select of the SD Card).
30-
///
31-
/// This kind of breaks the embedded-hal model, so how to do this is left to
32-
/// the caller. You could drive the SpiBus directly, or use an SpiDevice with
33-
/// a dummy chip-select pin. Or you could try just not doing the 74 clocks and
34-
/// see if your card works anyway - some do, some don't.
25+
/// Driver for an SD Card using some generic SD Card [`Transport`].
3526
///
3627
/// All the APIs take `&self` - mutability is handled using an inner `RefCell`.
3728
///
@@ -56,6 +47,12 @@ where
5647
{
5748
/// Create a new SD/MMC Card driver using a raw SPI interface.
5849
///
50+
/// This is just a short-cut method to provide backwards compatibility with
51+
/// our old API.
52+
///
53+
/// It creates an [`SpiTransport`] for you, so refer to the documentation
54+
/// there for important details.
55+
///
5956
/// The card will not be initialised at this time. Initialisation is
6057
/// deferred until a method is called on the object.
6158
///
@@ -64,10 +61,14 @@ where
6461
Self::new_spi_with_options(spi, delayer, AcquireOpts::default())
6562
}
6663

67-
/// Construct a new SD/MMC Card driver, using a raw SPI interface and the given options.
64+
/// Construct a new SD/MMC Card driver, using a raw SPI interface and the
65+
/// given options.
6866
///
69-
/// See the docs of the [`SdCard`] struct for more information about
70-
/// how to construct the needed `SPI` and `CS` types.
67+
/// This is just a short-cut method to provide backwards compatibility with
68+
/// our old API.
69+
///
70+
/// It creates an [`SpiTransport`] for you, so refer to the documentation
71+
/// there for important details.
7172
///
7273
/// The card will not be initialised at this time. Initialisation is
7374
/// deferred until a method is called on the object.
@@ -184,7 +185,11 @@ impl<T: Transport> BlockDevice for SdCard<T> {
184185
}
185186
}
186187

187-
/// Abstract SD card transportation interface.
188+
/// Abstract SD Card Transport interface.
189+
///
190+
/// We implement this trait to produce an SPI based transport over in
191+
/// [`SpiTransport`]. You can implement it yourself to support your favourite SD
192+
/// Host Controller if you prefer.
188193
pub trait Transport {
189194
/// Read one or more blocks, starting at the given block index.
190195
fn read(&mut self, blocks: &mut [Block], start_block_idx: BlockIdx) -> Result<(), Error>;

src/sdcard/spi.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Implements the BlockDevice trait for an SD/MMC Protocol over SPI.
1+
//! Implements the [`Transport`] trait for speaking SD/MMC Protocol over SPI.
22
//!
33
//! This is currently optimised for readability and debugability, not
44
//! performance.
@@ -7,9 +7,9 @@ use super::{proto::*, AcquireOpts, CardType, Delay, Error};
77
use crate::blockdevice::{Block, BlockCount, BlockIdx};
88
use crate::{debug, trace, warn};
99

10-
/// SPI transportation for the SD Card driver.
10+
/// An SPI-based implementation of [`Transport`](crate::Transport).
1111
///
12-
/// All the APIs required `&mut self`.
12+
/// All the APIs require `&mut self`.
1313
pub struct SpiTransport<SPI, DELAYER>
1414
where
1515
SPI: embedded_hal::spi::SpiDevice<u8>,
@@ -27,6 +27,15 @@ where
2727
DELAYER: embedded_hal::delay::DelayNs,
2828
{
2929
/// Construct a new raw SPI transport interface for SD/MMC Card.
30+
///
31+
/// Before talking to the SD Card, the caller needs to send 74 clocks cycles
32+
/// on the SPI Clock line, at 400 kHz, with no chip-select asserted (or at
33+
/// least, not the chip-select of the SD Card).
34+
///
35+
/// This kind of breaks the embedded-hal model, so how to do this is left to
36+
/// the caller. You could drive the SpiBus directly, or use an SpiDevice
37+
/// with a dummy chip-select pin. Or you could try just not doing the 74
38+
/// clocks and see if your card works anyway - some do, some don't.
3039
pub fn new(spi: SPI, delayer: DELAYER, options: AcquireOpts) -> Self {
3140
SpiTransport {
3241
spi,

0 commit comments

Comments
 (0)