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 14:37:59 UTC

[GitHub] [incubator-nuttx] acassis opened a new pull request #3499: esp32: Fix GPIO Pull-Up/Pull-Down using RTC GPIO

acassis opened a new pull request #3499:
URL: https://github.com/apache/incubator-nuttx/pull/3499


   ## Summary
   esp32: Fix GPIO Pull-Up/Pull-Down using RTC GPIO
   ## Impact
   Users will be able to use pull-up and pull-down on pins weren't supporting it
   ## Testing
   ESP32-Devkitc
   


-- 
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



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #3499: esp32: Fix GPIO Pull-Up/Pull-Down using RTC GPIO

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #3499:
URL: https://github.com/apache/incubator-nuttx/pull/3499#discussion_r610830357



##########
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:
       True! hehehe




-- 
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



[GitHub] [incubator-nuttx] Ouss4 merged pull request #3499: esp32: Fix GPIO Pull-Up/Pull-Down using RTC GPIO

Posted by GitBox <gi...@apache.org>.
Ouss4 merged pull request #3499:
URL: https://github.com/apache/incubator-nuttx/pull/3499


   


-- 
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



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #3499: esp32: Fix GPIO Pull-Up/Pull-Down using RTC GPIO

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #3499:
URL: https://github.com/apache/incubator-nuttx/pull/3499#discussion_r610827792



##########
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;
+                }
+              else
+                {
+                  /* First, disable PU/PD */
+
+                  regval &= ~DEFAULT_RTC_PU_BIT;
+                  regval &= ~DEFAULT_RTC_PD_BIT;
+
+                  /* Enable PU/PD, if needed */
+
+                  regval |= (en_pu == true) ? DEFAULT_RTC_PU_BIT : 0;
+                  regval |= (en_pd == true) ? DEFAULT_RTC_PD_BIT : 0;

Review comment:
       ```suggestion
                     regval |= en_pu ? DEFAULT_RTC_PU_BIT : 0;
                     regval |= en_pd ? DEFAULT_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



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #3499: esp32: Fix GPIO Pull-Up/Pull-Down using RTC GPIO

Posted by GitBox <gi...@apache.org>.
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



[GitHub] [incubator-nuttx] acassis commented on pull request #3499: esp32: Fix GPIO Pull-Up/Pull-Down using RTC GPIO

Posted by GitBox <gi...@apache.org>.
acassis commented on pull request #3499:
URL: https://github.com/apache/incubator-nuttx/pull/3499#issuecomment-817308627


   @Ouss4 / @xiaoxiang781216 could you please merge?


-- 
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



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #3499: esp32: Fix GPIO Pull-Up/Pull-Down using RTC GPIO

Posted by GitBox <gi...@apache.org>.
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;
   ```
   nit: Both `en_pu` and `en_pd` are booleans, so the comparison with another boolean is not necessary.

##########
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;
+                }
+              else
+                {
+                  /* First, disable PU/PD */
+
+                  regval &= ~DEFAULT_RTC_PU_BIT;
+                  regval &= ~DEFAULT_RTC_PD_BIT;
+
+                  /* Enable PU/PD, if needed */
+
+                  regval |= (en_pu == true) ? DEFAULT_RTC_PU_BIT : 0;
+                  regval |= (en_pd == true) ? DEFAULT_RTC_PD_BIT : 0;

Review comment:
       ```suggestion
                     regval |= en_pu ? DEFAULT_RTC_PU_BIT : 0;
                     regval |= en_pd ? DEFAULT_RTC_PD_BIT : 0;
   ```
   nit: 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