use crate::command::class11::cmd48::Mio;
#[cfg(test)]
use crate::crc::Crc7;
use crate::result::{Error, Result};
#[inline]
pub(crate) const fn check_ascii(val: &[u8], len: usize) -> Result<()> {
match val.len() {
vl if vl < len => Err(Error::InvalidVariant(vl)),
_ => {
let mut i = 0;
while i < len {
if !(val[i] as char).is_ascii() {
return Err(Error::InvalidVariant(val[i] as usize));
}
i += 1;
}
Ok(())
}
}
}
#[cfg(test)]
pub(crate) fn raw_with_crc<const N: usize>(mut raw: [u8; N]) -> ([u8; N], Crc7) {
let crc7 = Crc7::calculate(&raw[..N - 1]);
let raw_crc = (crc7.bits() << 1) | 1;
raw[N - 1] = raw_crc;
(raw, crc7)
}
#[inline]
pub(crate) const fn fno_masked(mio: Mio, val: u8, set: bool) -> u8 {
const MEM_MASK: u8 = 0xf;
const IO_MASK: u8 = 0xe;
match mio {
Mio::Memory => val & MEM_MASK,
Mio::Io if set => (val << 1) & IO_MASK,
Mio::Io => (val & IO_MASK) >> 1,
}
}