Skip to content

Commit

Permalink
Add fix for chips with only 2 address bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
aw committed Jan 22, 2021
1 parent 2474d90 commit d7bbc91
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sram23x"
version = "0.2.2"
version = "0.3.0"
authors = ["Alexander Williams, On-Prem <[email protected]>"]
repository = "https://github.com/aw/sram23x"
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions src/sram23x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit d7bbc91

Please sign in to comment.