use gpio;
use spi;
-use storage::Storage;
+use storage::{Storage, Error};
const SECTOR_SIZE: usize = 4096;
const PAGE_SIZE: usize = 256;
RDID = 0x9f,
}
-pub enum Error {
- UnalignedAddress = 1,
-}
-
const SR_WIP: u8 = 1 << 0;
impl Mx25l {
}
})
}
+
+ fn write(&mut self, address: usize, buffer: &[u8; SECTOR_SIZE])
+ -> Result<(), Error> {
+ if let Err(e) = self.erase_sector(address) {
+ return Err(e);
+ }
+
+ for (i, page_bytes) in buffer.chunks(PAGE_SIZE).enumerate() {
+ let page_address = address + (i * PAGE_SIZE);
+
+ // XXX: Inefficient.
+ let mut ba = [0xff; PAGE_SIZE];
+ ba.copy_from_slice(&page_bytes);
+
+ if let Err(e) = self.program_page(page_address, &ba) {
+ return Err(e);
+ }
+ }
+
+ Ok(())
+ }
}
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+pub enum Error {
+ UnalignedAddress = 1,
+}
+
pub trait Storage {
fn read(&self, address: usize, buffer: &mut [u8]);
+
+ fn write(&mut self, address: usize, buffer: &[u8; 4096]) -> Result<(), Error>;
}