You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/04/09 18:25:36 UTC
[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #3499: esp32: Fix GPIO Pull-Up/Pull-Down using RTC GPIO
gustavonihei commented on a change in pull request #3499:
URL: https://github.com/apache/incubator-nuttx/pull/3499#discussion_r610827590
##########
File path: arch/xtensa/src/esp32/esp32_gpio.c
##########
@@ -178,7 +193,71 @@ int esp32_configgpio(int pin, gpio_pinattr_t attr)
func |= FUN_IE;
- if ((attr & PULLUP) != 0)
+ /* Some pins only support Pull-Up and Pull-Down resistor on RTC GPIO */
+
+ if (rtc_gpio_is_valid_gpio(pin))
+ {
+ uint32_t rtc_gpio_idx = g_rtc_io_num_map[pin];
+
+ if (rtc_gpio_idx >= RTCIO_GPIO34_IDX)
+ {
+ gpioerr("Pins 34-39 don't support PullUp/PullDown\n");
+ }
+ else
+ {
+ uint32_t regval;
+ uint32_t rtc_gpio_pin;
+ bool en_pu = false;
+ bool en_pd = false;
+
+ if ((attr & PULLUP) != 0)
+ {
+ en_pu = true;
+ }
+ else if ((attr & PULLDOWN) != 0)
+ {
+ en_pd = true;
+ }
+
+ /* Get the pin register */
+
+ rtc_gpio_pin = g_rtc_io_desc[rtc_gpio_idx];
+
+ /* Read the current value from RTC GPIO pin */
+
+ regval = getreg32(rtc_gpio_pin);
+
+ /* RTC_IO_X32P (GPIO32) uses different PU/PD bits */
+
+ if (rtc_gpio_idx == RTCIO_GPIO32_IDX)
+ {
+ /* First, disable PU/PD */
+
+ regval &= ~SPECIAL_RTC_PU_BIT;
+ regval &= ~SPECIAL_RTC_PD_BIT;
+
+ /* Enable PU/PD, if needed */
+
+ regval |= (en_pu == true) ? SPECIAL_RTC_PU_BIT : 0;
+ regval |= (en_pd == true) ? SPECIAL_RTC_PD_BIT : 0;
Review comment:
```suggestion
regval |= en_pu ? SPECIAL_RTC_PU_BIT : 0;
regval |= en_pd ? SPECIAL_RTC_PD_BIT : 0;
```
Both `en_pu` and `en_pd` are booleans, so the comparison with another boolean is not necessary.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org