diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-20 18:32:17 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-20 18:32:17 +0100 |
commit | 2b925d76962cb325cf5cc49a1becff3cd707b4aa (patch) | |
tree | 3111ee649a5d132207abd3a84b72320df1d18aad /stmhal/i2c.c | |
parent | dde739d364b0faf48e74a88b65dc2468a3aaf64b (diff) | |
parent | f70630c58f5e74c0804ccfc4985a09e54c46249f (diff) | |
download | micropython-2b925d76962cb325cf5cc49a1becff3cd707b4aa.tar.gz micropython-2b925d76962cb325cf5cc49a1becff3cd707b4aa.zip |
Merge branch 'fix-netduino-i2c-spi' of github.com:dhylands/micropython into dhylands-fix-netduino-i2c-spi
Diffstat (limited to 'stmhal/i2c.c')
-rw-r--r-- | stmhal/i2c.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/stmhal/i2c.c b/stmhal/i2c.c index 8a8dd7dc2d..4d2710d8e5 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -13,6 +13,10 @@ #include "genhdr/pins.h" #include "i2c.h" +#if !defined(MICROPU_HW_ENABLE_I2C1) +#define MICROPY_HW_ENABLE_I2C1 (1) +#endif + I2C_HandleTypeDef I2CHandle1 = {.Instance = NULL}; I2C_HandleTypeDef I2CHandle2 = {.Instance = NULL}; @@ -32,6 +36,7 @@ void i2c_init(I2C_HandleTypeDef *i2c) { GPIO_InitStructure.Pull = GPIO_NOPULL; // have external pull-up resistors on both lines const pin_obj_t *pins[2]; +#if MICROPY_HW_ENABLE_I2C1 if (i2c == &I2CHandle1) { // X-skin: X9=PB6=SCL, X10=PB7=SDA pins[0] = &pin_B6; @@ -39,7 +44,9 @@ void i2c_init(I2C_HandleTypeDef *i2c) { GPIO_InitStructure.Alternate = GPIO_AF4_I2C1; // enable the I2C clock __I2C1_CLK_ENABLE(); - } else { + } else +#endif + if (i2c == &I2CHandle2) { // Y-skin: Y9=PB10=SCL, Y10=PB11=SDA pins[0] = &pin_B10; pins[1] = &pin_B11; @@ -54,13 +61,6 @@ void i2c_init(I2C_HandleTypeDef *i2c) { HAL_GPIO_Init(pins[i]->gpio, &GPIO_InitStructure); } - // enable the I2C clock - if (i2c == &I2CHandle1) { - __I2C1_CLK_ENABLE(); - } else { - __I2C2_CLK_ENABLE(); - } - // init the I2C device i2c->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; i2c->Init.ClockSpeed = 400000; @@ -88,7 +88,10 @@ typedef struct _pyb_i2c_obj_t { I2C_HandleTypeDef *i2c; } pyb_i2c_obj_t; -STATIC const pyb_i2c_obj_t pyb_i2c_obj[PYB_NUM_I2C] = {{{&pyb_i2c_type}, &I2CHandle1}, {{&pyb_i2c_type}, &I2CHandle2}}; +STATIC const pyb_i2c_obj_t pyb_i2c_obj[PYB_NUM_I2C] = { + {{&pyb_i2c_type}, &I2CHandle1}, + {{&pyb_i2c_type}, &I2CHandle2} +}; STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { // check arguments |