#![no_std]
pub mod asynchronous;
pub mod blocking;
mod command;
pub mod error;
pub mod register;
use crate::error::Error;
pub const BLOCK64_SIZE: u32 = 0x010000;
pub const BLOCK32_SIZE: u32 = BLOCK64_SIZE / 2;
pub const SECTOR_SIZE: u32 = 0x1000;
pub const PAGE_SIZE: u32 = 0x100;
pub(crate) fn check_erase<E>(capacity: usize, from: u32, to: u32) -> Result<(), Error<E>> {
let capacity = capacity as u32;
if from > to || to > capacity {
return Err(Error::OutOfBounds);
}
if !from.is_multiple_of(SECTOR_SIZE) || !to.is_multiple_of(SECTOR_SIZE) {
return Err(Error::NotAligned);
}
Ok(())
}
pub(crate) fn check_write<E>(capacity: usize, offset: u32, length: usize) -> Result<(), Error<E>> {
let capacity = capacity as u32;
let length = length as u32;
if length > capacity || offset > capacity - length {
return Err(Error::OutOfBounds);
}
Ok(())
}