Skip to content

Commit

Permalink
i2c: gpio_i2c_switch: fix gpio api misuse
Browse files Browse the repository at this point in the history
Use GPIO_OUTPUT_INACTIVE to initialize the pin so that the ACTIVE_LOW DT
flag is honored and use the gpio_pin_set_dt functions to set the
(logical) value of the pin instead of gpio_pin_configure_dt, that
tries to reconfigure the pin each time.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
fabiobaltieri committed Nov 10, 2023
1 parent 9a44f7f commit ac450be
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/i2c/gpio_i2c_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ static int gpio_i2c_switch_transfer(const struct device *dev, struct i2c_msg *ms
}

/* enable switch */
gpio_pin_configure_dt(&config->gpio, GPIO_OUTPUT_HIGH);
gpio_pin_set_dt(&config->gpio, 1);
k_busy_wait(GPIO_I2C_TOGGLE_DELAY_US);

res = i2c_transfer(config->bus, msgs, num_msgs, addr);

/* disable switch */
gpio_pin_configure_dt(&config->gpio, GPIO_OUTPUT_LOW);
gpio_pin_set_dt(&config->gpio, 0);
k_busy_wait(GPIO_I2C_TOGGLE_DELAY_US);
k_mutex_unlock(&data->lock);

Expand All @@ -76,7 +76,7 @@ static int gpio_i2c_switch_init(const struct device *dev)

k_mutex_init(&data->lock);

return gpio_pin_configure_dt(&config->gpio, GPIO_OUTPUT_LOW);
return gpio_pin_configure_dt(&config->gpio, GPIO_OUTPUT_INACTIVE);
}

#define DEFINE_GPIO_I2C_SWITCH(inst) \
Expand Down

0 comments on commit ac450be

Please sign in to comment.