X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fcommon%2Fmx25l.rs;h=56c2d4489658e3f10b0f1354c0a70e4b435ebd4b;hb=934532a7d2b013015455ccfeb6bb2845948626ce;hp=a6ad39550e9cbb9d9df7b1c0236e2e7228fabb51;hpb=a6747c47ca99a182f6cb4c41bad0232fb2754ff7;p=gps-watch.git diff --git a/src/common/mx25l.rs b/src/common/mx25l.rs index a6ad395..56c2d44 100644 --- a/src/common/mx25l.rs +++ b/src/common/mx25l.rs @@ -39,6 +39,7 @@ enum Command { RDSR = 0x05, WREN = 0x06, SE = 0x20, + CE = 0x60, RDID = 0x9f, } @@ -72,6 +73,17 @@ impl Mx25l { }) } + pub fn erase_all(&self) { + self.write_enable(); + + self.with_selected(|| { + spi::tx8(spi::SPI0, Command::CE as u8); + }); + + while self.write_in_progress() { + } + } + pub fn erase_sector(&self, address: usize) -> Result<(), Error> { if (address & (SECTOR_SIZE - 1)) != 0 { return Err(Error::UnalignedAddress); @@ -103,6 +115,8 @@ impl Mx25l { return Ok(()); } + self.write_enable(); + self.with_selected(|| { spi::tx8(spi::SPI0, Command::PP as u8); @@ -145,6 +159,10 @@ impl Mx25l { } impl Storage for Mx25l { + fn size(&self) -> usize { + 2 << 20 + } + fn read(&self, address: usize, buffer: &mut [u8]) { self.with_selected(|| { spi::tx8(spi::SPI0, Command::READ as u8); @@ -179,4 +197,8 @@ impl Storage for Mx25l { Ok(()) } + + fn clear(&mut self) { + self.erase_all(); + } }