From d7bbc911b87c764764587cb96631613f1ab9d5ee Mon Sep 17 00:00:00 2001 From: Alex Williams Date: Fri, 22 Jan 2021 02:30:47 +0000 Subject: [PATCH] Add fix for chips with only 2 address bytes --- Cargo.toml | 2 +- README.md | 2 +- src/lib.rs | 2 +- src/sram23x.rs | 10 ++++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9e9310c..e6d19f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sram23x" -version = "0.2.2" +version = "0.3.0" authors = ["Alexander Williams, On-Prem "] repository = "https://github.com/aw/sram23x" edition = "2018" diff --git a/README.md b/README.md index c3705b2..f0d0d84 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Include [library](https://crates.io/crates/sram23x) as a dependency in your Carg ```toml [dependencies] -sram23x = "0.2.2" +sram23x = "0.3.0" ``` Some example usage: diff --git a/src/lib.rs b/src/lib.rs index 13a9f71..ba44a01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ Include [library](https://crates.io/crates/sram23x) as a dependency in your Carg ```toml [dependencies] -sram23x = "0.2.2" +sram23x = "0.3.0" ``` Some example usage: diff --git a/src/sram23x.rs b/src/sram23x.rs index cd6051f..b52aca8 100644 --- a/src/sram23x.rs +++ b/src/sram23x.rs @@ -163,20 +163,22 @@ where DT::fill_address(&mut addr, Instruction::Read); let data = addr.to_be_bytes(); let mut buf: [u8; 36] = [0; 36]; - match DT::ADDRESS_BYTES { + let size: usize = DT::ADDRESS_BYTES + 32; + let res: [u8; 32] = match DT::ADDRESS_BYTES { 3 => { buf[0] = data[0]; buf[1] = data[2]; buf[2] = data[3]; + self.transfer(&mut buf[..size])?; + TryFrom::try_from(&buf[3..35]).unwrap() } 4 => { buf[..4].clone_from_slice(&data[..]); + self.transfer(&mut buf[..size])?; + TryFrom::try_from(&buf[4..]).unwrap() } _ => return Err(Error::InvalidAddressSize), }; - let size: usize = DT::ADDRESS_BYTES + 32; - self.transfer(&mut buf[..size])?; - let res: [u8; 32] = TryFrom::try_from(&buf[DT::ADDRESS_BYTES..]).unwrap(); Ok(res) } }