diff --git a/CHANGELOG.md b/CHANGELOG.md index b0caf726..78617174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic - Updated directory iterator callback, to allow bailing out early (breaking change) - `crc7` function now returns the actual CRC7 value without left-shifting by and XOR-ing by/with 1. - Bumped `embedded-io` to 0.7 +- `CardType::SDHC` renamed to `CardType::SdhcSdxc` +- `CardType` is now inside the `sdcard` module ### Added diff --git a/src/sdcard/cid.rs b/src/sdcard/cid.rs index a74b9934..838a4e3d 100644 --- a/src/sdcard/cid.rs +++ b/src/sdcard/cid.rs @@ -6,6 +6,7 @@ use crate::sdcard::crc7; /// Checksum is invalid. #[derive(Debug, PartialEq, Eq, Copy, Clone, thiserror::Error)] +#[cfg_attr(feature = "defmt-log", derive(defmt::Format))] #[error("checksum is invalid")] pub struct ChecksumInvalidError; diff --git a/src/sdcard/csd.rs b/src/sdcard/csd.rs index 37477cfc..e75b33f6 100644 --- a/src/sdcard/csd.rs +++ b/src/sdcard/csd.rs @@ -16,6 +16,7 @@ pub enum Csd { /// The CSD structure field is invalid. #[derive(Debug, PartialEq, Eq, Copy, Clone, thiserror::Error)] +#[cfg_attr(feature = "defmt-log", derive(defmt::Format))] pub enum CsdCreationError { /// Invalid CSD structure field. #[error("invalid CSD structure field")] diff --git a/src/sdcard/mod.rs b/src/sdcard/mod.rs index f22b9299..17e99987 100644 --- a/src/sdcard/mod.rs +++ b/src/sdcard/mod.rs @@ -33,6 +33,24 @@ pub mod cid; pub mod csd; pub mod spi; +/// The different types of card we support. +#[cfg_attr(feature = "defmt-log", derive(defmt::Format))] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum CardType { + /// An standard-capacity SD Card supporting v1.x of the standard. + /// + /// Uses byte-addressing internally, so limited to 2GiB in size. + SD1, + /// An standard-capacity SD Card supporting v2.x of the standard. + /// + /// Uses byte-addressing internally, so limited to 2GiB in size. + SD2, + /// An high-capacity 'SDHC' Card or an extended-capacity 'SDXC' card. + /// + /// Uses block-addressing internally to support capacities above 2GiB. + SdhcSdxc, +} + // Possible errors the SD card can return /// Card indicates last operation was a success pub const ERROR_OK: u8 = 0x00; diff --git a/src/sdcard/spi.rs b/src/sdcard/spi.rs index 0ff5d99d..291bc00e 100644 --- a/src/sdcard/spi.rs +++ b/src/sdcard/spi.rs @@ -203,7 +203,7 @@ where fn read(&mut self, blocks: &mut [Block], start_block_idx: BlockIdx) -> Result<(), Error> { let start_idx = match self.card_type { Some(CardType::SD1 | CardType::SD2) => start_block_idx.0 * 512, - Some(CardType::SDHC) => start_block_idx.0, + Some(CardType::SdhcSdxc) => start_block_idx.0, None => return Err(Error::CardNotFound), }; @@ -227,7 +227,7 @@ where fn write(&mut self, blocks: &[Block], start_block_idx: BlockIdx) -> Result<(), Error> { let start_idx = match self.card_type { Some(CardType::SD1 | CardType::SD2) => start_block_idx.0 * 512, - Some(CardType::SDHC) => start_block_idx.0, + Some(CardType::SdhcSdxc) => start_block_idx.0, None => return Err(Error::CardNotFound), }; if blocks.len() == 1 { @@ -293,7 +293,7 @@ where self.read_data(&mut csd_raw)?; Ok(csd::Csd::V1(csd::CsdV1::from_be_bytes(&csd_raw))) } - Some(CardType::SD2 | CardType::SDHC) => { + Some(CardType::SD2 | CardType::SdhcSdxc) => { if self.card_command(CMD9, 0)? != 0 { return Err(Error::RegisterReadError); } @@ -443,7 +443,7 @@ where let mut buffer = [0xFF; 4]; s.transfer_bytes(&mut buffer)?; if (buffer[0] & 0xC0) == 0xC0 { - card_type = CardType::SDHC; + card_type = CardType::SdhcSdxc; } // Ignore the other three bytes } @@ -630,24 +630,6 @@ impl core::fmt::Display for Error { impl core::error::Error for Error {} -/// The different types of card we support. -#[cfg_attr(feature = "defmt-log", derive(defmt::Format))] -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum CardType { - /// An standard-capacity SD Card supporting v1.x of the standard. - /// - /// Uses byte-addressing internally, so limited to 2GiB in size. - SD1, - /// An standard-capacity SD Card supporting v2.x of the standard. - /// - /// Uses byte-addressing internally, so limited to 2GiB in size. - SD2, - /// An high-capacity 'SDHC' Card. - /// - /// Uses block-addressing internally to support capacities above 2GiB. - SDHC, -} - /// This an object you can use to busy-wait with a timeout. /// /// Will let you call `delay` up to `max_retries` times before `delay` returns