Skip to content

Commit

Permalink
Merge pull request #6 from geomatsi/i2c-fixup
Browse files Browse the repository at this point in the history
i2c: fix introduced during switch to digital::v2
  • Loading branch information
sajattack authored Jul 24, 2019
2 parents e4373c6 + 8e53c05 commit 11b2a15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 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 = "bitbang-hal"
version = "0.2.3"
version = "0.2.4"
authors = ["Paul Sajna <sajattack@gmail.com>"]
edition = "2018"
description = "Implements embedded-hal traits by bitbanging"
Expand Down
26 changes: 13 additions & 13 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ where
self.sda.set_low().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();

self.sda.set_low().map_err(Error::Bus)?;
self.scl.set_low().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();

Ok(())
}

fn i2c_stop(&mut self) -> Result<(), crate::i2c::Error<E>> {
self.sda.set_high().map_err(Error::Bus)?;
self.scl.set_high().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();

self.sda.set_high().map_err(Error::Bus)?;
Expand All @@ -118,12 +118,12 @@ where

fn i2c_is_ack(&mut self) -> Result<bool, crate::i2c::Error<E>> {
self.sda.set_high().map_err(Error::Bus)?;
self.sda.set_high().map_err(Error::Bus)?;
self.scl.set_high().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();

let ack = self.sda.is_low().map_err(Error::Bus)?;

self.sda.set_low().map_err(Error::Bus)?;
self.scl.set_low().map_err(Error::Bus)?;
self.sda.set_low().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();

Expand All @@ -136,14 +136,14 @@ where
self.sda.set_high().map_err(Error::Bus)?;

for i in 0..8 {
self.sda.set_high().map_err(Error::Bus)?;
self.scl.set_high().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();

if self.sda.is_high().map_err(Error::Bus)? {
byte |= 1 << (7 - i);
}

self.sda.set_low().map_err(Error::Bus)?;
self.scl.set_low().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();
}

Expand All @@ -153,10 +153,10 @@ where
self.sda.set_high().map_err(Error::Bus)?;
}

self.sda.set_high().map_err(Error::Bus)?;
self.scl.set_high().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();

self.sda.set_low().map_err(Error::Bus)?;
self.scl.set_low().map_err(Error::Bus)?;
self.sda.set_low().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();

Expand All @@ -173,10 +173,10 @@ where
self.sda.set_low().map_err(Error::Bus)?;
}

self.sda.set_high().map_err(Error::Bus)?;
self.scl.set_high().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();

self.sda.set_low().map_err(Error::Bus)?;
self.scl.set_low().map_err(Error::Bus)?;
self.sda.set_low().map_err(Error::Bus)?;
block!(self.clk.wait()).ok();
}
Expand All @@ -191,7 +191,7 @@ where
SDA: OutputPin<Error = E> + InputPin<Error = E>,
CLK: CountDown + Periodic,
{
type Error = crate::i2c::Error<E>;
type Error = crate::i2c::Error<E>;

fn write(&mut self, addr: u8, output: &[u8]) -> Result<(), Self::Error> {
if output.is_empty() {
Expand Down Expand Up @@ -229,7 +229,7 @@ where
SDA: OutputPin<Error = E> + InputPin<Error = E>,
CLK: CountDown + Periodic,
{
type Error = crate::i2c::Error<E>;
type Error = crate::i2c::Error<E>;

fn read(&mut self, addr: u8, input: &mut [u8]) -> Result<(), Self::Error> {
if input.is_empty() {
Expand Down Expand Up @@ -263,7 +263,7 @@ where
SDA: OutputPin<Error = E> + InputPin<Error = E>,
CLK: CountDown + Periodic,
{
type Error = crate::i2c::Error<E>;
type Error = crate::i2c::Error<E>;

fn write_read(&mut self, addr: u8, output: &[u8], input: &mut [u8]) -> Result<(), Self::Error> {
if output.is_empty() || input.is_empty() {
Expand Down

0 comments on commit 11b2a15

Please sign in to comment.