From b46a5f5c521e9dddb1a75faa247ce4aa8f64de0f Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sun, 5 Jan 2020 18:53:58 +0100 Subject: [PATCH] common: Implement Storage::read() in Mx25l. --- src/common/mx25l.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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); + } + }) + } +} -- 2.30.2