read_gpioab()/write_gpioab() aren't congruent
Opened this issue · 0 comments
AGSaidi commented
Thanks for great and straightforward library to interface with the mcp23017.
I came across a bug when using read_gpioab()
and write_gpioab()
. The read half returns GPIOA in bits 8:15 while the write version expects GPIOA in the low bits 0:7. The write version make more sense to me and the change is simply:
--- lib.rs.old 2022-01-09 13:04:33.000000000 -0600
+++ lib.rs 2022-01-09 13:04:25.000000000 -0600
@@ -148,7 +148,7 @@
/// Reads all 16 pins (port A and B) into a single 16 bit variable.
pub fn read_gpioab(&mut self) -> Result<u16, E> {
let buffer = self.read_double_register(Register::GPIOA)?;
- Ok((buffer[0] as u16) << 8 | (buffer[1] as u16))
+ Ok((buffer[1] as u16) << 8 | (buffer[0] as u16))
}
/// Reads a single port, A or B, and returns its current 8 bit value.
However, if someone was relying on it, it would be a breaking change.