sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
use crate::lib_bitfield;

use super::EraseGroupSize;

lib_bitfield! {
    /// Represents the `ERASE_GROUP_MULT` field of the `CSD` register.
    EraseGroupMult: u8,
    mask: 0x1f,
    default: 0,
    {
        /// Represents one of the parameters used to calculate the card's erase unit size.
        erase_grp_mult: 4, 0;
    }
}

impl EraseGroupMult {
    /// Gets the effective capacity size.
    ///
    /// # Note
    ///
    /// The erase multiplier is calculated with the algorithm:
    ///
    /// ```no_build,no_run
    /// mult = ERASE_GROUP_MULT + 1
    /// ```
    #[inline(always)]
    pub const fn mult(&self) -> usize {
        (self.erase_grp_mult() + 1) as usize
    }

    /// Gets the erase unit size.
    ///
    /// # Note
    ///
    /// The unit size is calculated with the algorithm:
    ///
    /// ```no_build,no_run
    /// unit = (ERASE_GRP_SIZE + 1) * (ERASE_GRP_MULT + 1)
    /// ```
    #[inline(always)]
    pub const fn unit_size(&self, group_size: EraseGroupSize) -> usize {
        self.mult() * group_size.size()
    }
}