From fb6cf96a4657e4d7ba462f457d9e8e4258b604bb Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 25 Apr 2011 16:12:57 -0400 Subject: I2C fixup. Added i2c_init() for consistency with rest of libmaple. --- libmaple/i2c.c | 17 +++++++++++++---- libmaple/i2c.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libmaple/i2c.c b/libmaple/i2c.c index 3a1082a..f4cb522 100644 --- a/libmaple/i2c.c +++ b/libmaple/i2c.c @@ -320,10 +320,20 @@ static void i2c_bus_reset(const i2c_dev *dev) { gpio_write_bit(dev->gpio_port, dev->sda_pin, 1); } +/** + * @brief Initialize an I2C device and reset its registers to their + * default values. + * @param dev Device to enable. + */ +void i2c_init(i2c_dev *dev) { + rcc_reset_dev(dev->clk_line); + rcc_clk_enable(dev->clk_line); +} + /** * @brief Initialize an i2c device as bus master - * @param device to enable - * @param flags bitwise or of the following I2C options: + * @param dev Device to enable + * @param flags Bitwise or of the following I2C options: * I2C_FAST_MODE: 400 khz operation * I2C_10BIT_ADDRESSING: Enable 10-bit addressing */ @@ -337,8 +347,7 @@ void i2c_master_enable(i2c_dev *dev, uint32 flags) { i2c_bus_reset(dev); /* Turn on clock and set GPIO modes */ - rcc_reset_dev(dev->clk_line); - rcc_clk_enable(dev->clk_line); + i2c_init(dev); gpio_set_mode(dev->gpio_port, dev->sda_pin, GPIO_AF_OUTPUT_OD); gpio_set_mode(dev->gpio_port, dev->scl_pin, GPIO_AF_OUTPUT_OD); diff --git a/libmaple/i2c.h b/libmaple/i2c.h index 27e24b2..3f351b2 100644 --- a/libmaple/i2c.h +++ b/libmaple/i2c.h @@ -137,6 +137,7 @@ extern i2c_dev* const I2C2; extern "C" { #endif +void i2c_init(i2c_dev *dev); void i2c_master_enable(i2c_dev *dev, uint32 flags); int32 i2c_master_xfer(i2c_dev *dev, i2c_msg *msgs, uint16 num); -- cgit v1.2.3