#[cfg(any(feature = "spi", feature = "sdio"))]
#[inline]
pub(crate) fn block_addr_of(addr: u32, high_capacity: bool) -> u32 {
if high_capacity { addr } else { addr * 512 }
}
#[cfg(feature = "spi")]
pub(crate) fn crc16_ccitt(bytes: &[u8]) -> u16 {
let mut crc: u16 = 0;
for &byte in bytes {
crc ^= (byte as u16) << 8;
for _ in 0..8 {
if crc & 0x8000 != 0 {
crc = (crc << 1) ^ 0x1021;
} else {
crc <<= 1;
}
}
}
crc
}
#[cfg(test)]
mod tests {
#[cfg(feature = "spi")]
use super::crc16_ccitt;
#[cfg(feature = "spi")]
#[test]
fn crc16_ccitt_known_vectors() {
assert_eq!(crc16_ccitt(b"123456789"), 0x31C3);
assert_eq!(crc16_ccitt(&[]), 0);
assert_eq!(crc16_ccitt(&[0u8; 512]), 0);
}
}