Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read_gpioab()/write_gpioab() aren't congruent #8

Open
AGSaidi opened this issue Jan 9, 2022 · 0 comments
Open

read_gpioab()/write_gpioab() aren't congruent #8

AGSaidi opened this issue Jan 9, 2022 · 0 comments

Comments

@AGSaidi
Copy link

AGSaidi commented Jan 9, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant