esp32: drivers: gpio: remove pinmux dependency
Refactor the GPIO driver code to remove dependency from the pinmux API. Signed-off-by: Glauber Maroto Ferreira <glauber.ferreira@espressif.com>
This commit is contained in:
parent
c66db46507
commit
5e549b57b6
1 changed files with 43 additions and 28 deletions
|
@ -27,7 +27,6 @@
|
||||||
#endif
|
#endif
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <sys/util.h>
|
#include <sys/util.h>
|
||||||
#include <drivers/pinmux.h>
|
|
||||||
|
|
||||||
#include "gpio_utils.h"
|
#include "gpio_utils.h"
|
||||||
|
|
||||||
|
@ -63,7 +62,6 @@ struct gpio_esp32_config {
|
||||||
struct gpio_esp32_data {
|
struct gpio_esp32_data {
|
||||||
/* gpio_driver_data needs to be first */
|
/* gpio_driver_data needs to be first */
|
||||||
struct gpio_driver_data common;
|
struct gpio_driver_data common;
|
||||||
const struct device *pinmux;
|
|
||||||
sys_slist_t cb;
|
sys_slist_t cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -109,22 +107,51 @@ static int gpio_esp32_config(const struct device *dev,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Set pin function as GPIO */
|
if (io_pin >= GPIO_NUM_MAX) {
|
||||||
ret = pinmux_pin_set(data->pinmux, io_pin, PIN_FUNC_GPIO);
|
LOG_ERR("Invalid pin.");
|
||||||
if (ret < 0) {
|
ret = -EINVAL;
|
||||||
LOG_ERR("Invalid pinmux configuration.");
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set pin function as GPIO */
|
||||||
|
gpio_ll_iomux_func_sel(GPIO_PIN_MUX_REG[io_pin], PIN_FUNC_GPIO);
|
||||||
|
|
||||||
if (flags & GPIO_PULL_UP) {
|
if (flags & GPIO_PULL_UP) {
|
||||||
ret = pinmux_pin_pullup(data->pinmux, io_pin, PINMUX_PULLUP_ENABLE);
|
if (!rtc_gpio_is_valid_gpio(io_pin) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) {
|
||||||
} else if (flags & GPIO_PULL_DOWN) {
|
gpio_ll_pulldown_dis(&GPIO, io_pin);
|
||||||
ret = pinmux_pin_pullup(data->pinmux, io_pin, PINMUX_PULLUP_DISABLE);
|
gpio_ll_pullup_en(&GPIO, io_pin);
|
||||||
}
|
} else {
|
||||||
|
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||||
|
int rtcio_num = rtc_io_num_map[io_pin];
|
||||||
|
|
||||||
if (ret < 0) {
|
rtcio_hal_pulldown_disable(rtc_io_num_map[io_pin]);
|
||||||
LOG_ERR("Invalid pinmux configuration.");
|
|
||||||
goto end;
|
if (rtc_io_desc[rtcio_num].pullup) {
|
||||||
|
rtcio_hal_pullup_enable(rtc_io_num_map[io_pin]);
|
||||||
|
} else {
|
||||||
|
ret = -ENOTSUP;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} else if (flags & GPIO_PULL_DOWN) {
|
||||||
|
if (!rtc_gpio_is_valid_gpio(io_pin) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) {
|
||||||
|
gpio_ll_pullup_dis(&GPIO, io_pin);
|
||||||
|
gpio_ll_pulldown_en(&GPIO, io_pin);
|
||||||
|
} else {
|
||||||
|
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||||
|
int rtcio_num = rtc_io_num_map[io_pin];
|
||||||
|
|
||||||
|
rtcio_hal_pulldown_enable(rtc_io_num_map[io_pin]);
|
||||||
|
|
||||||
|
if (rtc_io_desc[rtcio_num].pullup) {
|
||||||
|
rtcio_hal_pullup_disable(rtc_io_num_map[io_pin]);
|
||||||
|
} else {
|
||||||
|
ret = -ENOTSUP;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & GPIO_OUTPUT) {
|
if (flags & GPIO_OUTPUT) {
|
||||||
|
@ -189,14 +216,12 @@ static int gpio_esp32_config(const struct device *dev,
|
||||||
gpio_ll_set_level(cfg->gpio_base, io_pin, 0);
|
gpio_ll_set_level(cfg->gpio_base, io_pin, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = pinmux_pin_input_enable(data->pinmux, io_pin, PINMUX_OUTPUT_ENABLED);
|
gpio_ll_output_enable(&GPIO, io_pin);
|
||||||
if (ret < 0) {
|
esp_rom_gpio_matrix_out(io_pin, SIG_GPIO_OUT_IDX, false, false);
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & GPIO_INPUT) {
|
if (flags & GPIO_INPUT) {
|
||||||
ret = pinmux_pin_input_enable(data->pinmux, io_pin, PINMUX_INPUT_ENABLED);
|
gpio_ll_input_enable(&GPIO, io_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
@ -397,16 +422,6 @@ static int gpio_esp32_init(const struct device *dev)
|
||||||
struct gpio_esp32_data *data = dev->data;
|
struct gpio_esp32_data *data = dev->data;
|
||||||
static bool isr_connected;
|
static bool isr_connected;
|
||||||
|
|
||||||
data->pinmux = DEVICE_DT_GET(DT_NODELABEL(pinmux));
|
|
||||||
if ((data->pinmux != NULL)
|
|
||||||
&& !device_is_ready(data->pinmux)) {
|
|
||||||
data->pinmux = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!data->pinmux) {
|
|
||||||
return -ENOTSUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isr_connected) {
|
if (!isr_connected) {
|
||||||
esp_intr_alloc(DT_IRQN(DT_NODELABEL(gpio0)),
|
esp_intr_alloc(DT_IRQN(DT_NODELABEL(gpio0)),
|
||||||
0,
|
0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue