From: Tilman Sauerbeck Date: Sun, 5 Jan 2020 17:53:58 +0000 (+0100) Subject: common: Implement Storage::read() in Mx25l. X-Git-Url: http://git.code-monkey.de/?p=gps-watch.git;a=commitdiff_plain;h=b46a5f5c521e9dddb1a75faa247ce4aa8f64de0f common: Implement Storage::read() in Mx25l. --- diff --git a/src/common/mx25l.rs b/src/common/mx25l.rs index 6e74f4a..24f9c36 100644 --- a/src/common/mx25l.rs +++ b/src/common/mx25l.rs @@ -23,6 +23,7 @@ use gpio; use spi; +use storage::Storage; pub struct Mx25l { cs_gpio: u32, @@ -30,6 +31,7 @@ pub struct Mx25l { } enum Command { + READ = 0x03, RDSR = 0x05, RDID = 0x9f, } @@ -74,3 +76,19 @@ impl Mx25l { r } } + +impl Storage for Mx25l { + fn read(&self, address: usize, buffer: &mut [u8]) { + self.with_selected(|| { + spi::tx8(spi::SPI0, Command::READ as u8); + + spi::tx8(spi::SPI0, (address >> 16) as u8); + spi::tx8(spi::SPI0, (address >> 8) as u8); + spi::tx8(spi::SPI0, (address >> 0) as u8); + + for i in 0..buffer.len() { + buffer[i] = spi::tx8(spi::SPI0, 0xff); + } + }) + } +}