X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Fi2c_bitbang.c;h=8d93e1b1187a5391e9352ed2fc7841e2cc6f708e;hb=fe0574946861850880407c1be53f3b12c61cbb04;hp=2cf0e573aaee4b918cb3c45f727e895e8e3090d3;hpb=0d4c0c64f736f37dba565aa9e113d3920ef905f9;p=bertos.git diff --git a/bertos/drv/i2c_bitbang.c b/bertos/drv/i2c_bitbang.c index 2cf0e573..8d93e1b1 100644 --- a/bertos/drv/i2c_bitbang.c +++ b/bertos/drv/i2c_bitbang.c @@ -54,6 +54,7 @@ #include +#if !CONFIG_I2C_DISABLE_OLD_API INLINE bool i2c_bitbang_start(void) { @@ -181,7 +182,7 @@ void i2c_bitbang_init(void) SCL_HI; MOD_INIT(i2c); } - +#endif /* !CONFIG_I2C_DISABLE_OLD_API */ /* * New I2C API @@ -190,21 +191,21 @@ void i2c_bitbang_init(void) static void i2c_bitbang_stop_1(struct I2c *i2c) { - i2c_hw_sdaLo(I2C_DEV(i2c)); - i2c_hw_sclHi(I2C_DEV(i2c)); - i2c_hw_halfbitDelay(I2C_DEV(i2c)); - i2c_hw_sdaHi(I2C_DEV(i2c)); + i2c_sdaLo(I2C_DEV(i2c)); + i2c_sclHi(I2C_DEV(i2c)); + i2c_halfbitDelay(I2C_DEV(i2c)); + i2c_sdaHi(I2C_DEV(i2c)); } INLINE bool i2c_bitbang_start_1(struct I2c *i2c) { - i2c_hw_sdaHi(I2C_DEV(i2c)); - i2c_hw_sclHi(I2C_DEV(i2c)); - i2c_hw_halfbitDelay(I2C_DEV(i2c)); - i2c_hw_sdaLo(I2C_DEV(i2c)); - i2c_hw_halfbitDelay(I2C_DEV(i2c)); + i2c_sdaHi(I2C_DEV(i2c)); + i2c_sclHi(I2C_DEV(i2c)); + i2c_halfbitDelay(I2C_DEV(i2c)); + i2c_sdaLo(I2C_DEV(i2c)); + i2c_halfbitDelay(I2C_DEV(i2c)); - return !i2c_hw_sdaIn(I2C_DEV(i2c)); + return !i2c_sdaIn(I2C_DEV(i2c)); } @@ -213,29 +214,29 @@ static uint8_t i2c_bitbang_getc(struct I2c *i2c) uint8_t data = 0; for (uint8_t i = 0x80; i != 0; i >>= 1) { - i2c_hw_sclLo(I2C_DEV(i2c)); - i2c_hw_halfbitDelay(I2C_DEV(i2c)); - i2c_hw_sclHi(I2C_DEV(i2c)); - if (i2c_hw_sdaIn(I2C_DEV(i2c))) + i2c_sclLo(I2C_DEV(i2c)); + i2c_halfbitDelay(I2C_DEV(i2c)); + i2c_sclHi(I2C_DEV(i2c)); + if (i2c_sdaIn(I2C_DEV(i2c))) data |= i; else data &= ~i; - i2c_hw_halfbitDelay(I2C_DEV(i2c)); + i2c_halfbitDelay(I2C_DEV(i2c)); } - i2c_hw_sclLo(I2C_DEV(i2c)); + i2c_sclLo(I2C_DEV(i2c)); /* Generate ACK/NACK */ if (i2c->xfer_size > 1) - i2c_hw_sdaLo(I2C_DEV(i2c)); + i2c_sdaLo(I2C_DEV(i2c)); else - i2c_hw_sdaHi(I2C_DEV(i2c)); + i2c_sdaHi(I2C_DEV(i2c)); - i2c_hw_halfbitDelay(I2C_DEV(i2c)); - i2c_hw_sclHi(I2C_DEV(i2c)); - i2c_hw_halfbitDelay(I2C_DEV(i2c)); - i2c_hw_sclLo(I2C_DEV(i2c)); - i2c_hw_sdaHi(I2C_DEV(i2c)); + i2c_halfbitDelay(I2C_DEV(i2c)); + i2c_sclHi(I2C_DEV(i2c)); + i2c_halfbitDelay(I2C_DEV(i2c)); + i2c_sclLo(I2C_DEV(i2c)); + i2c_sdaHi(I2C_DEV(i2c)); /* Generate stop condition (if requested) */ if ((i2c->xfer_size == 1) && (i2c->flags & I2C_STOP)) @@ -251,20 +252,20 @@ static void i2c_bitbang_putc(struct I2c *i2c, uint8_t _data) for (uint16_t i = 0x100; i != 0; i >>= 1) { - i2c_hw_sclLo(I2C_DEV(i2c)); + i2c_sclLo(I2C_DEV(i2c)); if (data & i) - i2c_hw_sdaHi(I2C_DEV(i2c)); + i2c_sdaHi(I2C_DEV(i2c)); else - i2c_hw_sdaLo(I2C_DEV(i2c)); - i2c_hw_halfbitDelay(I2C_DEV(i2c)); + i2c_sdaLo(I2C_DEV(i2c)); + i2c_halfbitDelay(I2C_DEV(i2c)); - i2c_hw_sclHi(I2C_DEV(i2c)); - i2c_hw_halfbitDelay(I2C_DEV(i2c)); + i2c_sclHi(I2C_DEV(i2c)); + i2c_halfbitDelay(I2C_DEV(i2c)); } - bool ack = !i2c_hw_sdaIn(I2C_DEV(i2c)); - i2c_hw_sclLo(I2C_DEV(i2c)); - i2c_hw_halfbitDelay(I2C_DEV(i2c)); + bool ack = !i2c_sdaIn(I2C_DEV(i2c)); + i2c_sclLo(I2C_DEV(i2c)); + i2c_halfbitDelay(I2C_DEV(i2c)); if (!ack) { @@ -333,8 +334,8 @@ void i2c_hw_bitbangInit(I2c *i2c, int dev) i2c->hw = (struct I2cHardware *)(dev - I2C_BITBANG0); i2c->vt = &i2c_bitbang_vt; - i2c_hw_bitbang_init(I2C_DEV(i2c)); - i2c_hw_sdaHi(I2C_DEV(i2c)); - i2c_hw_sclHi(I2C_DEV(i2c)); + i2c_bitbangInit(I2C_DEV(i2c)); + i2c_sdaHi(I2C_DEV(i2c)); + i2c_sclHi(I2C_DEV(i2c)); }