diff --git a/inc/i2c_bb.h b/inc/i2c_bb.h index c06f49b..7313279 100644 --- a/inc/i2c_bb.h +++ b/inc/i2c_bb.h @@ -1,11 +1,11 @@ #ifndef __I2C_BB_H__ #define __I2C_BB_H__ -#include +#include struct i2c_bb { - struct gpio *sda; - struct gpio *scl; + struct gpio_sys *sda; + struct gpio_sys *scl; }; int i2c_open(const struct i2c_bb *i2c); diff --git a/src/i2c.c b/src/i2c.c index ab4356c..d4166e1 100644 --- a/src/i2c.c +++ b/src/i2c.c @@ -161,7 +161,7 @@ static void write_bit(const struct i2c_bb *i2c, uint8_t bit) static uint8_t read_bit(const struct i2c_bb *i2c) { - unsigned int res; + int res; assert(NULL != i2c); @@ -169,8 +169,12 @@ static uint8_t read_bit(const struct i2c_bb *i2c) usleep(5); gpio_write(i2c->scl, 1); usleep(5); - gpio_read(i2c->sda, &res); + res = gpio_read(i2c->sda); gpio_write(i2c->scl, 0); + if(res < 0) { + res = 0; + } + return (uint8_t) res; } diff --git a/test/inc/mock_ftdi.h b/test/inc/mock_ftdi.h index 772737b..3109cc1 100644 --- a/test/inc/mock_ftdi.h +++ b/test/inc/mock_ftdi.h @@ -5,10 +5,10 @@ DEFINE_FFF_GLOBALS; -DECLARE_FAKE_VALUE_FUNC(int, gpio_open, const struct gpio *); -DECLARE_FAKE_VALUE_FUNC(int, gpio_close, const struct gpio *); -DECLARE_FAKE_VALUE_FUNC(int, gpio_read, const struct gpio *, unsigned int *); -DECLARE_FAKE_VALUE_FUNC(int, gpio_write, const struct gpio *, unsigned int); -DECLARE_FAKE_VALUE_FUNC(int, gpio_toggle, const struct gpio *); +DECLARE_FAKE_VALUE_FUNC(int, gpio_open, const struct gpio_sys *); +DECLARE_FAKE_VALUE_FUNC(int, gpio_close, const struct gpio_sys *); +DECLARE_FAKE_VALUE_FUNC(int, gpio_read, const struct gpio_sys *); +DECLARE_FAKE_VALUE_FUNC(int, gpio_write, const struct gpio_sys *, int); +DECLARE_FAKE_VALUE_FUNC(int, gpio_toggle, const struct gpio_sys *); #endif diff --git a/test/unit/mock_ftdi.c b/test/unit/mock_ftdi.c index 874f00d..cc2fa89 100644 --- a/test/unit/mock_ftdi.c +++ b/test/unit/mock_ftdi.c @@ -2,8 +2,8 @@ DEFINE_FFF_GLOBALS; -DEFINE_FAKE_VALUE_FUNC(int, gpio_open, const struct gpio *); -DEFINE_FAKE_VALUE_FUNC(int, gpio_close, const struct gpio *); -DEFINE_FAKE_VALUE_FUNC(int, gpio_read, const struct gpio *, unsigned int *); -DEFINE_FAKE_VALUE_FUNC(int, gpio_write, const struct gpio *, unsigned int); -DEFINE_FAKE_VALUE_FUNC(int, gpio_toggle, const struct gpio *); +DEFINE_FAKE_VALUE_FUNC(int, gpio_open, const struct gpio_sys *); +DEFINE_FAKE_VALUE_FUNC(int, gpio_close, const struct gpio_sys *); +DEFINE_FAKE_VALUE_FUNC(int, gpio_read, const struct gpio_sys *); +DEFINE_FAKE_VALUE_FUNC(int, gpio_write, const struct gpio_sys *, int); +DEFINE_FAKE_VALUE_FUNC(int, gpio_toggle, const struct gpio_sys *);