Skip to content

Commit f00a0a9

Browse files
sylvioalvesnashif
authored andcommitted
drivers: pinmux: esp32: use rtcio to control pull up/down
Set pinmux driver to use RTCIO interface for to handle dedicated IOs pull-up/down configuration. Without this, some GPIOS won't have pull-up enabled properly. Also, current implementation automatically disables output pin when input pin is set. It also performs the oppositte. This PR changes it only to enable what is requested, either input or output. Signed-off-by: Sylvio Alves <[email protected]>
1 parent 23d581d commit f00a0a9

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

drivers/pinmux/pinmux_esp32.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,25 @@
1111
#include <soc/soc.h>
1212
#include <hal/gpio_types.h>
1313
#include <hal/gpio_ll.h>
14+
#include <hal/rtc_io_hal.h>
1415
#include <soc.h>
1516

1617
#include <errno.h>
1718
#include <drivers/pinmux.h>
1819

20+
#ifndef SOC_GPIO_SUPPORT_RTC_INDEPENDENT
21+
#define SOC_GPIO_SUPPORT_RTC_INDEPENDENT 0
22+
#endif
23+
24+
static inline bool rtc_gpio_is_valid_gpio(uint32_t gpio_num)
25+
{
26+
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
27+
return (gpio_num < SOC_GPIO_PIN_COUNT && rtc_io_num_map[gpio_num] >= 0);
28+
#else
29+
return false;
30+
#endif
31+
}
32+
1933
static int pinmux_set(const struct device *dev, uint32_t pin, uint32_t func)
2034
{
2135
ARG_UNUSED(dev);
@@ -48,11 +62,26 @@ static int pinmux_pullup(const struct device *dev, uint32_t pin, uint8_t func)
4862

4963
switch (func) {
5064
case PINMUX_PULLUP_DISABLE:
51-
gpio_ll_pullup_dis(&GPIO, pin);
65+
if (!rtc_gpio_is_valid_gpio(pin) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) {
66+
gpio_ll_pullup_dis(&GPIO, pin);
67+
gpio_ll_pulldown_en(&GPIO, pin);
68+
} else {
69+
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
70+
rtcio_hal_pullup_disable(rtc_io_num_map[pin]);
71+
rtcio_hal_pulldown_enable(rtc_io_num_map[pin]);
72+
#endif
73+
}
5274
break;
5375
case PINMUX_PULLUP_ENABLE:
54-
gpio_ll_pulldown_dis(&GPIO, pin);
55-
gpio_ll_pullup_en(&GPIO, pin);
76+
if (!rtc_gpio_is_valid_gpio(pin) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) {
77+
gpio_ll_pulldown_dis(&GPIO, pin);
78+
gpio_ll_pullup_en(&GPIO, pin);
79+
} else {
80+
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
81+
rtcio_hal_pulldown_disable(rtc_io_num_map[pin]);
82+
rtcio_hal_pullup_enable(rtc_io_num_map[pin]);
83+
#endif
84+
}
5685
break;
5786
default:
5887
return -EINVAL;
@@ -67,11 +96,9 @@ static int pinmux_input(const struct device *dev, uint32_t pin, uint8_t func)
6796

6897
switch (func) {
6998
case PINMUX_INPUT_ENABLED:
70-
gpio_ll_output_disable(&GPIO, pin);
7199
gpio_ll_input_enable(&GPIO, pin);
72100
break;
73101
case PINMUX_OUTPUT_ENABLED:
74-
gpio_ll_input_disable(&GPIO, pin);
75102
gpio_ll_output_enable(&GPIO, pin);
76103
esp_rom_gpio_matrix_out(pin, SIG_GPIO_OUT_IDX, false, false);
77104
break;

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ manifest:
6767
groups:
6868
- hal
6969
- name: hal_espressif
70-
revision: c4a591c35385be59a41cde7efc85fe7660172979
70+
revision: bd2e2d8dcdc19defdb1bf6e07fb94f62bc99c925
7171
path: modules/hal/espressif
7272
west-commands: west/west-commands.yml
7373
groups:

0 commit comments

Comments
 (0)