summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/i2c.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-11-11 17:53:45 +1100
committerDamien George <damien.p.george@gmail.com>2016-11-11 17:53:45 +1100
commit1375c52772ad4f07d4bce40bfa114a0f2f0e6cfc (patch)
tree12cb3458f2d09395d656d52d146d01fd8ad94099 /stmhal/i2c.c
parent74fb5d6932c835f92c6985799e30ea28b6449705 (diff)
downloadmicropython-1375c52772ad4f07d4bce40bfa114a0f2f0e6cfc.tar.gz
micropython-1375c52772ad4f07d4bce40bfa114a0f2f0e6cfc.zip
stmhal: Rename mp_hal_pin_set_af to _config_alt, to simplify alt config.
This way the caller doesn't need to initialise a big GPIO_InitTypeDef struct, and HAL_GPIO_Init is no longer called.
Diffstat (limited to 'stmhal/i2c.c')
-rw-r--r--stmhal/i2c.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/stmhal/i2c.c b/stmhal/i2c.c
index 0af2232143..9b7ec4dabd 100644
--- a/stmhal/i2c.c
+++ b/stmhal/i2c.c
@@ -203,12 +203,6 @@ void i2c_init0(void) {
}
void i2c_init(I2C_HandleTypeDef *i2c) {
- // init the GPIO lines
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
- GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
- GPIO_InitStructure.Pull = GPIO_NOPULL; // have external pull-up resistors on both lines
-
int i2c_unit;
const pin_obj_t *scl_pin;
const pin_obj_t *sda_pin;
@@ -241,8 +235,10 @@ void i2c_init(I2C_HandleTypeDef *i2c) {
}
// init the GPIO lines
- mp_hal_pin_set_af(scl_pin, &GPIO_InitStructure, AF_FN_I2C, i2c_unit);
- mp_hal_pin_set_af(sda_pin, &GPIO_InitStructure, AF_FN_I2C, i2c_unit);
+ uint32_t mode = MP_HAL_PIN_MODE_ALT_OPEN_DRAIN;
+ uint32_t pull = MP_HAL_PIN_PULL_NONE; // have external pull-up resistors on both lines
+ mp_hal_pin_config_alt(scl_pin, mode, pull, AF_FN_I2C, i2c_unit);
+ mp_hal_pin_config_alt(sda_pin, mode, pull, AF_FN_I2C, i2c_unit);
// init the I2C device
if (HAL_I2C_Init(i2c) != HAL_OK) {