esp32: drivers: i2c: use pinctrl
though using pinctrl's subsystem, the I2C driver keeps pin information in case of communication failure. This information is needed in case of FSM failure. Signed-off-by: Glauber Maroto Ferreira <glauber.ferreira@espressif.com>
This commit is contained in:
parent
7fb8fe7c13
commit
bcf79464fa
1 changed files with 8 additions and 1 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <soc.h>
|
#include <soc.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <drivers/gpio.h>
|
#include <drivers/gpio.h>
|
||||||
|
#include <drivers/pinctrl.h>
|
||||||
#include <drivers/i2c.h>
|
#include <drivers/i2c.h>
|
||||||
#include <drivers/interrupt_controller/intc_esp32.h>
|
#include <drivers/interrupt_controller/intc_esp32.h>
|
||||||
#include <drivers/clock_control.h>
|
#include <drivers/clock_control.h>
|
||||||
|
@ -79,6 +80,8 @@ struct i2c_esp32_config {
|
||||||
const struct i2c_esp32_pin scl;
|
const struct i2c_esp32_pin scl;
|
||||||
const struct i2c_esp32_pin sda;
|
const struct i2c_esp32_pin sda;
|
||||||
|
|
||||||
|
const struct pinctrl_dev_config *pcfg;
|
||||||
|
|
||||||
const clock_control_subsys_t clock_subsys;
|
const clock_control_subsys_t clock_subsys;
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
|
@ -646,7 +649,7 @@ static int IRAM_ATTR i2c_esp32_init(const struct device *dev)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = i2c_esp32_config_pin(dev);
|
int ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
LOG_ERR("Failed to configure I2C pins");
|
LOG_ERR("Failed to configure I2C pins");
|
||||||
|
@ -676,6 +679,9 @@ static int IRAM_ATTR i2c_esp32_init(const struct device *dev)
|
||||||
I2C_ESP32_FREQUENCY(DT_INST_PROP(idx, clock_frequency))
|
I2C_ESP32_FREQUENCY(DT_INST_PROP(idx, clock_frequency))
|
||||||
|
|
||||||
#define ESP32_I2C_INIT(idx) \
|
#define ESP32_I2C_INIT(idx) \
|
||||||
|
\
|
||||||
|
PINCTRL_DT_INST_DEFINE(idx); \
|
||||||
|
\
|
||||||
static struct i2c_esp32_data i2c_esp32_data_##idx = { \
|
static struct i2c_esp32_data i2c_esp32_data_##idx = { \
|
||||||
.hal = { \
|
.hal = { \
|
||||||
.dev = (i2c_dev_t *) DT_REG_ADDR(DT_NODELABEL(i2c##idx)), \
|
.dev = (i2c_dev_t *) DT_REG_ADDR(DT_NODELABEL(i2c##idx)), \
|
||||||
|
@ -689,6 +695,7 @@ static int IRAM_ATTR i2c_esp32_init(const struct device *dev)
|
||||||
static const struct i2c_esp32_config i2c_esp32_config_##idx = { \
|
static const struct i2c_esp32_config i2c_esp32_config_##idx = { \
|
||||||
.index = idx, \
|
.index = idx, \
|
||||||
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
|
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
|
||||||
|
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
|
||||||
.clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(idx, offset), \
|
.clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(idx, offset), \
|
||||||
.scl = { \
|
.scl = { \
|
||||||
.gpio_name = DT_I2C_ESP32_GPIO_NAME(idx, scl_pin), \
|
.gpio_name = DT_I2C_ESP32_GPIO_NAME(idx, scl_pin), \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue