Skip to content

Commit 9be1ec0

Browse files
committed
improvements for SD card module
1 parent 69e1754 commit 9be1ec0

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic
1717
- Added `open_long_name_file_in_dir` API, to open files using their Long File Name
1818
- Updated directory iterator callback, to allow bailing out early (breaking change)
1919
- `crc7` function now returns the actual CRC7 value without left-shifting by and XOR-ing by/with 1.
20+
- `CardType::SDHC` renamed to `CardType::SdhcSdcx`
2021

2122
### Added
2223

src/sdcard/cid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use arbitrary_int::{u7, u12, u40};
55
use crate::sdcard::crc7;
66

77
/// Checksum is invalid.
8-
#[derive(Debug, thiserror::Error)]
8+
#[derive(Debug, Copy, Clone, thiserror::Error)]
99
#[error("checksum is invalid")]
1010
pub struct ChecksumInvalidError;
1111

src/sdcard/csd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub enum Csd {
1515
}
1616

1717
/// The CSD structure field is invalid.
18-
#[derive(Debug, PartialEq, Eq, thiserror::Error)]
18+
#[derive(Debug, PartialEq, Eq, Copy, Clone, thiserror::Error)]
1919
pub enum CsdCreationError {
2020
/// Invalid CSD structure field.
2121
#[error("invalid CSD structure field")]

src/sdcard/spi.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ where
203203
fn read(&mut self, blocks: &mut [Block], start_block_idx: BlockIdx) -> Result<(), Error> {
204204
let start_idx = match self.card_type {
205205
Some(CardType::SD1 | CardType::SD2) => start_block_idx.0 * 512,
206-
Some(CardType::SDHC) => start_block_idx.0,
206+
Some(CardType::SdhcSdxc) => start_block_idx.0,
207207
None => return Err(Error::CardNotFound),
208208
};
209209

@@ -227,7 +227,7 @@ where
227227
fn write(&mut self, blocks: &[Block], start_block_idx: BlockIdx) -> Result<(), Error> {
228228
let start_idx = match self.card_type {
229229
Some(CardType::SD1 | CardType::SD2) => start_block_idx.0 * 512,
230-
Some(CardType::SDHC) => start_block_idx.0,
230+
Some(CardType::SdhcSdxc) => start_block_idx.0,
231231
None => return Err(Error::CardNotFound),
232232
};
233233
if blocks.len() == 1 {
@@ -293,7 +293,7 @@ where
293293
self.read_data(&mut csd_raw)?;
294294
Ok(csd::Csd::V1(csd::CsdV1::from_be_bytes(&csd_raw)))
295295
}
296-
Some(CardType::SD2 | CardType::SDHC) => {
296+
Some(CardType::SD2 | CardType::SdhcSdxc) => {
297297
if self.card_command(CMD9, 0)? != 0 {
298298
return Err(Error::RegisterReadError);
299299
}
@@ -443,7 +443,7 @@ where
443443
let mut buffer = [0xFF; 4];
444444
s.transfer_bytes(&mut buffer)?;
445445
if (buffer[0] & 0xC0) == 0xC0 {
446-
card_type = CardType::SDHC;
446+
card_type = CardType::SdhcSdxc;
447447
}
448448
// Ignore the other three bytes
449449
}
@@ -642,10 +642,10 @@ pub enum CardType {
642642
///
643643
/// Uses byte-addressing internally, so limited to 2GiB in size.
644644
SD2,
645-
/// An high-capacity 'SDHC' Card.
645+
/// An high-capacity 'SDHC' Card or an extended-capacity 'SDXC' card.
646646
///
647647
/// Uses block-addressing internally to support capacities above 2GiB.
648-
SDHC,
648+
SdhcSdxc,
649649
}
650650

651651
/// This an object you can use to busy-wait with a timeout.

0 commit comments

Comments
 (0)