Skip to content

Commit 7c5ee32

Browse files
Renamed some types and cleaned up some clippy lints.
Changed BlockSpi to AcquiredSdCard. Changed SdMmcSpi to SdCard.
1 parent a1aa27c commit 7c5ee32

File tree

8 files changed

+28
-28
lines changed

8 files changed

+28
-28
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
[Unreleased]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.4.0...develop
1111

1212
- Renamed `Controller` to `VolumeManager`, to better describe what it does.
13+
- Renamed `SdMmcSpi` to `SdCard`
14+
- Renamed `BlockSpi` to `AcquiredSdCard`
1315

1416
## [Version 0.4.0](https://github.com/rust-embedded-community/embedded-sdmmc-rs/releases/tag/v0.4.0)
1517

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ You will need something that implements the `BlockDevice` trait, which can read
1212

1313
```rust
1414
// Build an SD Card interface out of an SPI device
15-
let mut spi_dev = embedded_sdmmc::SdMmcSpi::new(sdmmc_spi, sdmmc_cs);
15+
let mut spi_dev = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs);
1616
// Try and initialise the SD card
1717
let block_dev = spi_dev.acquire()?;
18-
// The SD Card was initialised, and we have a `BlockSpi` object
18+
// The SD Card was initialised, and we have a `AcquiredSdCard` object
1919
// representing the initialised card.
2020
write!(uart, "Card size is {} bytes", block_dev.card_size_bytes()?)?;
2121
// Now let's look for volumes (also known as partitions) on our block device.

src/fat/volume.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl FatVolume {
149149
}
150150
FatSpecificInfo::Fat32(_fat32_info) => {
151151
// FAT32 => 4 bytes per entry
152-
let fat_offset = cluster.0 as u32 * 4;
152+
let fat_offset = cluster.0 * 4;
153153
this_fat_block_num = self.lba_start + self.fat_start.offset_bytes(fat_offset);
154154
let this_fat_ent_offset = (fat_offset % Block::LEN_U32) as usize;
155155
volume_mgr

src/filesystem/filename.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,7 @@ impl ShortFileName {
8181
}
8282
}
8383
_ => {
84-
let ch = if (b'a'..=b'z').contains(&ch) {
85-
// Uppercase characters only
86-
ch - 32
87-
} else {
88-
ch
89-
};
84+
let ch = ch.to_ascii_uppercase();
9085
if seen_dot {
9186
if (Self::FILENAME_BASE_MAX_LEN..Self::FILENAME_MAX_LEN).contains(&idx) {
9287
sfn.contents[idx] = ch;

src/filesystem/timestamp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct Timestamp {
2727
impl Timestamp {
2828
/// Create a `Timestamp` from the 16-bit FAT date and time fields.
2929
pub fn from_fat(date: u16, time: u16) -> Timestamp {
30-
let year = (1980 + (date >> 9)) as u16;
30+
let year = 1980 + (date >> 9);
3131
let month = ((date >> 5) & 0x000F) as u8;
3232
let day = (date & 0x001F) as u8;
3333
let hours = ((time >> 11) & 0x001F) as u8;

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
//! # let mut sdmmc_spi = DummySpi;
4141
//! # let mut sdmmc_cs = DummyCsPin;
4242
//! # let time_source = DummyTimeSource;
43-
//! let mut spi_dev = embedded_sdmmc::SdMmcSpi::new(sdmmc_spi, sdmmc_cs);
43+
//! let mut spi_dev = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs);
4444
//! let block = spi_dev.acquire()?;
4545
//! println!("Card size {} bytes", block.card_size_bytes()?);
4646
//! let mut volume_mgr = VolumeManager::new(block, time_source);
@@ -101,7 +101,7 @@ pub use crate::filesystem::{
101101
Timestamp, MAX_FILE_SIZE,
102102
};
103103
pub use crate::sdmmc::Error as SdMmcError;
104-
pub use crate::sdmmc::{BlockSpi, SdMmcSpi};
104+
pub use crate::sdmmc::{AcquiredSdCard, SdCard};
105105

106106
mod volume_mgr;
107107
pub use volume_mgr::VolumeManager;

src/sdmmc.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const DEFAULT_DELAY_COUNT: u32 = 32_000;
2222
/// Built from an SPI peripheral and a Chip
2323
/// Select pin. We need Chip Select to be separate so we can clock out some
2424
/// bytes without Chip Select asserted (which puts the card into SPI mode).
25-
pub struct SdMmcSpi<SPI, CS>
25+
pub struct SdCard<SPI, CS>
2626
where
2727
SPI: embedded_hal::blocking::spi::Transfer<u8>,
2828
CS: embedded_hal::digital::v2::OutputPin,
@@ -35,15 +35,16 @@ where
3535
}
3636

3737
/// An initialized block device used to access the SD card.
38-
/// **Caution**: any data must be flushed manually before dropping `BlockSpi`, see `deinit`.
38+
///
39+
/// **Caution**: any data must be flushed manually before dropping `AcquiredSdCard`, see `deinit`.
3940
/// Uses SPI mode.
40-
pub struct BlockSpi<'a, SPI, CS>(&'a mut SdMmcSpi<SPI, CS>)
41+
pub struct AcquiredSdCard<'a, SPI, CS>(&'a mut SdCard<SPI, CS>)
4142
where
4243
SPI: embedded_hal::blocking::spi::Transfer<u8>,
4344
CS: embedded_hal::digital::v2::OutputPin,
4445
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug;
4546

46-
/// The possible errors `SdMmcSpi` can generate.
47+
/// The possible errors this crate can generate.
4748
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
4849
#[derive(Debug, Copy, Clone)]
4950
pub enum Error {
@@ -77,7 +78,7 @@ pub enum Error {
7778
GpioError,
7879
}
7980

80-
/// The possible states `SdMmcSpi` can be in.
81+
/// The possible states `SdCard` can be in.
8182
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
8283
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
8384
pub enum State {
@@ -92,6 +93,7 @@ pub enum State {
9293
/// The different types of card we support.
9394
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
9495
#[derive(Debug, Copy, Clone, PartialEq)]
96+
#[allow(clippy::upper_case_acronyms)]
9597
enum CardType {
9698
SD1,
9799
SD2,
@@ -137,15 +139,15 @@ impl Default for AcquireOpts {
137139
}
138140
}
139141

140-
impl<SPI, CS> SdMmcSpi<SPI, CS>
142+
impl<SPI, CS> SdCard<SPI, CS>
141143
where
142144
SPI: embedded_hal::blocking::spi::Transfer<u8>,
143145
CS: embedded_hal::digital::v2::OutputPin,
144146
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,
145147
{
146148
/// Create a new SD/MMC interface using a raw SPI interface.
147-
pub fn new(spi: SPI, cs: CS) -> SdMmcSpi<SPI, CS> {
148-
SdMmcSpi {
149+
pub fn new(spi: SPI, cs: CS) -> SdCard<SPI, CS> {
150+
SdCard {
149151
spi: RefCell::new(spi),
150152
cs: RefCell::new(cs),
151153
card_type: CardType::SD1,
@@ -165,12 +167,15 @@ where
165167
}
166168

167169
/// Initializes the card into a known state
168-
pub fn acquire(&mut self) -> Result<BlockSpi<SPI, CS>, Error> {
170+
pub fn acquire(&mut self) -> Result<AcquiredSdCard<SPI, CS>, Error> {
169171
self.acquire_with_opts(Default::default())
170172
}
171173

172174
/// Initializes the card into a known state
173-
pub fn acquire_with_opts(&mut self, options: AcquireOpts) -> Result<BlockSpi<SPI, CS>, Error> {
175+
pub fn acquire_with_opts(
176+
&mut self,
177+
options: AcquireOpts,
178+
) -> Result<AcquiredSdCard<SPI, CS>, Error> {
174179
debug!("acquiring card with opts: {:?}", options);
175180
let f = |s: &mut Self| {
176181
// Assume it hasn't worked
@@ -269,7 +274,7 @@ where
269274
let result = f(self);
270275
self.cs_high()?;
271276
let _ = self.receive();
272-
result.map(move |()| BlockSpi(self))
277+
result.map(move |()| AcquiredSdCard(self))
273278
}
274279

275280
/// Perform a function that might error with the chipselect low.
@@ -377,7 +382,7 @@ where
377382
}
378383
}
379384

380-
impl<SPI, CS> BlockSpi<'_, SPI, CS>
385+
impl<SPI, CS> AcquiredSdCard<'_, SPI, CS>
381386
where
382387
SPI: embedded_hal::blocking::spi::Transfer<u8>,
383388
CS: embedded_hal::digital::v2::OutputPin,
@@ -517,7 +522,7 @@ impl<U: BlockDevice, T: Deref<Target = U>> BlockDevice for T {
517522
}
518523
}
519524

520-
impl<SPI, CS> BlockDevice for BlockSpi<'_, SPI, CS>
525+
impl<SPI, CS> BlockDevice for AcquiredSdCard<'_, SPI, CS>
521526
where
522527
SPI: embedded_hal::blocking::spi::Transfer<u8>,
523528
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,
@@ -595,7 +600,7 @@ where
595600
}
596601
}
597602

598-
impl<SPI, CS> Drop for BlockSpi<'_, SPI, CS>
603+
impl<SPI, CS> Drop for AcquiredSdCard<'_, SPI, CS>
599604
where
600605
SPI: embedded_hal::blocking::spi::Transfer<u8>,
601606
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,

src/volume_mgr.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ where
237237
break;
238238
}
239239
}
240-
drop(dir);
241240
}
242241

243242
/// Look in a directory for a named file.
@@ -603,7 +602,6 @@ where
603602
break;
604603
}
605604
}
606-
drop(file);
607605
Ok(())
608606
}
609607

0 commit comments

Comments
 (0)