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 2023/01/20 14:28:09 UTC

[GitHub] [nuttx] lucasssvaz opened a new pull request, #8202: arch/xtensa/esp32: Add support for RTC IRQs

lucasssvaz opened a new pull request, #8202:
URL: https://github.com/apache/nuttx/pull/8202

   ## Summary
   
   Separate from GPIOs and add a handler for RTC interrupts.
   Also replaces the RTC watchdog interrupt handler with the new one.
   
   ## Impact
   
   None on existing features. Add support for handling interruptions from RTC peripherals.
   
   ## Testing
   
   Tested using the watchdog example on the ESP32-DevKitC. (watchdog2 is the RTC one)
   
   ```
   NuttShell (NSH) NuttX-10.4.0
   nsh> wdog -i /dev/watchdog2
     ping elapsed=0
     ping elapsed=500
     ping elapsed=1000
     ping elapsed=1500
     ping elapsed=2000
     ping elapsed=2500
     ping elapsed=3000
     ping elapsed=3500
     ping elapsed=4000
     ping elapsed=4500
     NO ping elapsed=5000
     NO ping elapsed=5500
     NO ping elapsed=6000
   ets Jul 29 2019 12:21:46
   
   rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
   configsip: 0, SPIWP:0xee
   clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
   mode:DIO, clock div:2
   load:0x3fff0030,len:6640
   load:0x40078000,len:14848
   load:0x40080400,len:3672
   entry 0x4008068c
   I (28) boot: ESP-IDF v4.4.2 2nd stage bootloader
   I (28) boot: compile time 14:59:14
   I (28) boot: chip revision: 3
   I (30) boot_comm: chip revision: 3, min. bootloader chip revision: 0
   I (38) boot.esp32: SPI Speed      : 40MHz
   I (42) boot.esp32: SPI Mode       : DIO
   I (47) boot.esp32: SPI Flash Size : 4MB
   I (51) boot: Enabling RNG early entropy source...
   I (57) boot: Partition Table:
   I (60) boot: ## Label            Usage          Type ST Offset   Length
   I (68) boot:  0 factory          factory app      00 00 00010000 00100000
   I (75) boot: End of partition table
   I (79) boot_comm: chip revision: 3, min. application chip revision: 0
   I (86) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=027ech ( 10220) map
   I (99) esp_image: segment 1: paddr=00012814 vaddr=3ffb1540 size=00220h (   544) load
   I (103) esp_image: segment 2: paddr=00012a3c vaddr=40080000 size=01608h (  5640) load
   I (114) esp_image: segment 3: paddr=0001404c vaddr=00000000 size=0bfcch ( 49100)
   I (138) esp_image: segment 4: paddr=00020020 vaddr=400d0020 size=10c24h ( 68644) map
   I (163) boot: Loaded app from partition at offset 0x10000
   I (163) boot: Disabling RNG early entropy source...
   �
   NuttShell (NSH) NuttX-10.4.0
   nsh>
   ```


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

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] gustavonihei commented on a diff in pull request #8202: arch/xtensa/esp32: Add support for RTC IRQs

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #8202:
URL: https://github.com/apache/nuttx/pull/8202#discussion_r1082631904


##########
arch/xtensa/src/esp32/esp32_gpio.c:
##########
@@ -222,258 +220,152 @@ int esp32_configgpio(int pin, gpio_pinattr_t attr)
   func  = 0;
   cntrl = 0;
 
-  if ((attr & FUNCTION_MASK) == FUNCTION_RTC) /* RTCIO */
+  if ((attr & INPUT) != 0)
     {
-      if (rtc_gpio_is_valid_gpio(pin) == 0)
-        {
-          gpioerr("Pin %d is not a valid RTC pin!\n", pin);
-          return -1;
-        }
-
-      rtc_gpio_idx = g_rtc_io_num_map[pin];
-      rtc_reg_desc = g_rtc_io_desc[rtc_gpio_idx];
-      g_pin_rtc_controlled[rtc_gpio_idx] = true;
-
-      setbits(rtc_reg_desc.reg, rtc_reg_desc.mux);
-
-      modifyreg32(rtc_reg_desc.reg,
-        ((RTC_IO_TOUCH_PAD1_FUN_SEL_V) << (rtc_reg_desc.func)),
-        (((RTCIO_PIN_FUNC) & RTC_IO_TOUCH_PAD1_FUN_SEL_V) <<
-        (rtc_reg_desc.func)));
-
-      if (rtc_reg_desc.pulldown)
-        {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.pulldown);
-        }
-
-      if (rtc_reg_desc.pullup)
-        {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.pullup);
-        }
-
-      if ((attr & PULLUP) != 0)
+      if (pin < 32)
         {
-          if (rtc_reg_desc.pullup)
-            {
-              setbits(rtc_reg_desc.reg, rtc_reg_desc.pullup);
-            }
+          putreg32((UINT32_C(1) << pin), GPIO_ENABLE_W1TC_REG);
         }
-      else if ((attr & PULLDOWN) != 0)
+      else
         {
-          if (rtc_reg_desc.pulldown)
-            {
-              setbits(rtc_reg_desc.reg, rtc_reg_desc.pulldown);
-            }
+          putreg32((UINT32_C(1) << (pin - 32)), GPIO_ENABLE1_W1TC_REG);
         }
 
-      if ((attr & INPUT) != 0)
-        {
-          /* Enable Input */
-
-          setbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
-
-          /* Disable Output */
-
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TC_REG);
-        }
-      else if ((attr & OUTPUT) != 0)
-        {
-          /* Disable Input */
+      /* Input enable */
 
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
+      func |= FUN_IE;
 
-          /* Enable Output */
+      /* Some pins only support Pull-Up and Pull-Down resistor on RTC GPIO */
 
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TS_REG);
-        }
-      else
+      if (gpio_is_valid_rtc_gpio(pin))
         {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TC_REG);
-        }
+          uint32_t rtc_gpio_idx = g_gpio_to_rtcio_map[pin];
+          uint32_t regval;
+          uint32_t rtc_gpio_pin;
+          bool en_pu = false;
+          bool en_pd = false;
 
-      if ((attr & DRIVE_MASK) != 0)
-        {
-          if (rtc_reg_desc.drv_v)
+          if ((attr & PULLUP) != 0)
             {
-              uint32_t val = ((attr & DRIVE_MASK) >> DRIVE_SHIFT) - 1;
-              modifyreg32(rtc_reg_desc.reg,
-                ((rtc_reg_desc.drv_v) << (rtc_reg_desc.drv_s)),
-                (((val) & rtc_reg_desc.drv_v) << (rtc_reg_desc.drv_s)));
-            }
-        }
-
-      if ((attr & OPEN_DRAIN) != 0)
-        {
-          /* All RTC GPIOs have the same position for the drive bits.
-           * We can use any RTC_GPIO_PINn_PAD_DRIVER.
-           */
-
-          REG_SET_FIELD(rtc_gpio_to_addr[rtc_gpio_idx],
-                        RTC_GPIO_PIN0_PAD_DRIVER,
-                        true);
-        }
-      else
-        {
-          REG_SET_FIELD(rtc_gpio_to_addr[rtc_gpio_idx],
-                        RTC_GPIO_PIN0_PAD_DRIVER,
-                        false);
-        }
+              if (!rtc_gpio_is_pull_supported(rtc_gpio_idx))
+                {
+                  gpioerr("Pins 34-39 don't support PullUp/PullDown\n");
+                  PANIC();
+                }

Review Comment:
   A suggestion for a cleaner code:
   The error message should be moved to where the check is made:
   ```c
   static bool rtc_gpio_is_pull_supported(uint32_t rtcio_num)
   {
     /* Pins 34 thorugh 39 use RTC channels 0 to 5 and don't support PU/PD */
   
     bool is_pull_supported = rtcio_num > 5;
   
     gpioerr("Pins 34-39 don't support PullUp/PullDown\n");
   
     return is_pull_supported;
   }
   ```
   Then we may just use an assertion in every other place.
   ```suggestion
                 ASSERT(rtc_gpio_is_pull_supported(rtc_gpio_idx));
   ```
   
   The `inline` keyword I believe may be omitted, the compiler most probably will inline it when GPIO logs are deactivated.



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

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] gustavonihei commented on a diff in pull request #8202: arch/xtensa/esp32: Add support for RTC IRQs

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #8202:
URL: https://github.com/apache/nuttx/pull/8202#discussion_r1082635223


##########
arch/xtensa/src/esp32/esp32_gpio.c:
##########
@@ -222,258 +220,152 @@ int esp32_configgpio(int pin, gpio_pinattr_t attr)
   func  = 0;
   cntrl = 0;
 
-  if ((attr & FUNCTION_MASK) == FUNCTION_RTC) /* RTCIO */
+  if ((attr & INPUT) != 0)
     {
-      if (rtc_gpio_is_valid_gpio(pin) == 0)
-        {
-          gpioerr("Pin %d is not a valid RTC pin!\n", pin);
-          return -1;
-        }
-
-      rtc_gpio_idx = g_rtc_io_num_map[pin];
-      rtc_reg_desc = g_rtc_io_desc[rtc_gpio_idx];
-      g_pin_rtc_controlled[rtc_gpio_idx] = true;
-
-      setbits(rtc_reg_desc.reg, rtc_reg_desc.mux);
-
-      modifyreg32(rtc_reg_desc.reg,
-        ((RTC_IO_TOUCH_PAD1_FUN_SEL_V) << (rtc_reg_desc.func)),
-        (((RTCIO_PIN_FUNC) & RTC_IO_TOUCH_PAD1_FUN_SEL_V) <<
-        (rtc_reg_desc.func)));
-
-      if (rtc_reg_desc.pulldown)
-        {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.pulldown);
-        }
-
-      if (rtc_reg_desc.pullup)
-        {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.pullup);
-        }
-
-      if ((attr & PULLUP) != 0)
+      if (pin < 32)
         {
-          if (rtc_reg_desc.pullup)
-            {
-              setbits(rtc_reg_desc.reg, rtc_reg_desc.pullup);
-            }
+          putreg32((UINT32_C(1) << pin), GPIO_ENABLE_W1TC_REG);
         }
-      else if ((attr & PULLDOWN) != 0)
+      else
         {
-          if (rtc_reg_desc.pulldown)
-            {
-              setbits(rtc_reg_desc.reg, rtc_reg_desc.pulldown);
-            }
+          putreg32((UINT32_C(1) << (pin - 32)), GPIO_ENABLE1_W1TC_REG);
         }
 
-      if ((attr & INPUT) != 0)
-        {
-          /* Enable Input */
-
-          setbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
-
-          /* Disable Output */
-
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TC_REG);
-        }
-      else if ((attr & OUTPUT) != 0)
-        {
-          /* Disable Input */
+      /* Input enable */
 
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
+      func |= FUN_IE;
 
-          /* Enable Output */
+      /* Some pins only support Pull-Up and Pull-Down resistor on RTC GPIO */
 
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TS_REG);
-        }
-      else
+      if (gpio_is_valid_rtc_gpio(pin))
         {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TC_REG);
-        }
+          uint32_t rtc_gpio_idx = g_gpio_to_rtcio_map[pin];
+          uint32_t regval;
+          uint32_t rtc_gpio_pin;
+          bool en_pu = false;
+          bool en_pd = false;
 
-      if ((attr & DRIVE_MASK) != 0)
-        {
-          if (rtc_reg_desc.drv_v)
+          if ((attr & PULLUP) != 0)
             {
-              uint32_t val = ((attr & DRIVE_MASK) >> DRIVE_SHIFT) - 1;
-              modifyreg32(rtc_reg_desc.reg,
-                ((rtc_reg_desc.drv_v) << (rtc_reg_desc.drv_s)),
-                (((val) & rtc_reg_desc.drv_v) << (rtc_reg_desc.drv_s)));
-            }
-        }
-
-      if ((attr & OPEN_DRAIN) != 0)
-        {
-          /* All RTC GPIOs have the same position for the drive bits.
-           * We can use any RTC_GPIO_PINn_PAD_DRIVER.
-           */
-
-          REG_SET_FIELD(rtc_gpio_to_addr[rtc_gpio_idx],
-                        RTC_GPIO_PIN0_PAD_DRIVER,
-                        true);
-        }
-      else
-        {
-          REG_SET_FIELD(rtc_gpio_to_addr[rtc_gpio_idx],
-                        RTC_GPIO_PIN0_PAD_DRIVER,
-                        false);
-        }
+              if (!rtc_gpio_is_pull_supported(rtc_gpio_idx))
+                {
+                  gpioerr("Pins 34-39 don't support PullUp/PullDown\n");
+                  PANIC();
+                }

Review Comment:
   Or simply remove the error message altogether. The assertion itself is already very informative for the user, since it will fail for `rtc_gpio_is_pull_supported`.



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

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] gustavonihei commented on a diff in pull request #8202: arch/xtensa/esp32: Add support for RTC IRQs

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #8202:
URL: https://github.com/apache/nuttx/pull/8202#discussion_r1082635223


##########
arch/xtensa/src/esp32/esp32_gpio.c:
##########
@@ -222,258 +220,152 @@ int esp32_configgpio(int pin, gpio_pinattr_t attr)
   func  = 0;
   cntrl = 0;
 
-  if ((attr & FUNCTION_MASK) == FUNCTION_RTC) /* RTCIO */
+  if ((attr & INPUT) != 0)
     {
-      if (rtc_gpio_is_valid_gpio(pin) == 0)
-        {
-          gpioerr("Pin %d is not a valid RTC pin!\n", pin);
-          return -1;
-        }
-
-      rtc_gpio_idx = g_rtc_io_num_map[pin];
-      rtc_reg_desc = g_rtc_io_desc[rtc_gpio_idx];
-      g_pin_rtc_controlled[rtc_gpio_idx] = true;
-
-      setbits(rtc_reg_desc.reg, rtc_reg_desc.mux);
-
-      modifyreg32(rtc_reg_desc.reg,
-        ((RTC_IO_TOUCH_PAD1_FUN_SEL_V) << (rtc_reg_desc.func)),
-        (((RTCIO_PIN_FUNC) & RTC_IO_TOUCH_PAD1_FUN_SEL_V) <<
-        (rtc_reg_desc.func)));
-
-      if (rtc_reg_desc.pulldown)
-        {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.pulldown);
-        }
-
-      if (rtc_reg_desc.pullup)
-        {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.pullup);
-        }
-
-      if ((attr & PULLUP) != 0)
+      if (pin < 32)
         {
-          if (rtc_reg_desc.pullup)
-            {
-              setbits(rtc_reg_desc.reg, rtc_reg_desc.pullup);
-            }
+          putreg32((UINT32_C(1) << pin), GPIO_ENABLE_W1TC_REG);
         }
-      else if ((attr & PULLDOWN) != 0)
+      else
         {
-          if (rtc_reg_desc.pulldown)
-            {
-              setbits(rtc_reg_desc.reg, rtc_reg_desc.pulldown);
-            }
+          putreg32((UINT32_C(1) << (pin - 32)), GPIO_ENABLE1_W1TC_REG);
         }
 
-      if ((attr & INPUT) != 0)
-        {
-          /* Enable Input */
-
-          setbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
-
-          /* Disable Output */
-
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TC_REG);
-        }
-      else if ((attr & OUTPUT) != 0)
-        {
-          /* Disable Input */
+      /* Input enable */
 
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
+      func |= FUN_IE;
 
-          /* Enable Output */
+      /* Some pins only support Pull-Up and Pull-Down resistor on RTC GPIO */
 
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TS_REG);
-        }
-      else
+      if (gpio_is_valid_rtc_gpio(pin))
         {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TC_REG);
-        }
+          uint32_t rtc_gpio_idx = g_gpio_to_rtcio_map[pin];
+          uint32_t regval;
+          uint32_t rtc_gpio_pin;
+          bool en_pu = false;
+          bool en_pd = false;
 
-      if ((attr & DRIVE_MASK) != 0)
-        {
-          if (rtc_reg_desc.drv_v)
+          if ((attr & PULLUP) != 0)
             {
-              uint32_t val = ((attr & DRIVE_MASK) >> DRIVE_SHIFT) - 1;
-              modifyreg32(rtc_reg_desc.reg,
-                ((rtc_reg_desc.drv_v) << (rtc_reg_desc.drv_s)),
-                (((val) & rtc_reg_desc.drv_v) << (rtc_reg_desc.drv_s)));
-            }
-        }
-
-      if ((attr & OPEN_DRAIN) != 0)
-        {
-          /* All RTC GPIOs have the same position for the drive bits.
-           * We can use any RTC_GPIO_PINn_PAD_DRIVER.
-           */
-
-          REG_SET_FIELD(rtc_gpio_to_addr[rtc_gpio_idx],
-                        RTC_GPIO_PIN0_PAD_DRIVER,
-                        true);
-        }
-      else
-        {
-          REG_SET_FIELD(rtc_gpio_to_addr[rtc_gpio_idx],
-                        RTC_GPIO_PIN0_PAD_DRIVER,
-                        false);
-        }
+              if (!rtc_gpio_is_pull_supported(rtc_gpio_idx))
+                {
+                  gpioerr("Pins 34-39 don't support PullUp/PullDown\n");
+                  PANIC();
+                }

Review Comment:
   Or simply remove the error message altogether. The assertion itself is already very informative for the user, since it will fail for `rtc_gpio_is_pull_supported`.
   
   The function documentation  already states that:
   > Pins 34 thorugh 39 use RTC channels 0 to 5 and don't support PU/PD



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

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] gustavonihei commented on a diff in pull request #8202: arch/xtensa/esp32: Add support for RTC IRQs

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #8202:
URL: https://github.com/apache/nuttx/pull/8202#discussion_r1082824622


##########
arch/xtensa/src/esp32/esp32_touch.c:
##########
@@ -51,7 +51,7 @@
 #define TOUCH_PAD_FILTER_FACTOR_DEFAULT (4) /* IIR filter coefficient */
 #define TOUCH_PAD_SHIFT_DEFAULT         (4) /* Increase computing accuracy */
 #define TOUCH_PAD_SHIFT_ROUND_DEFAULT   (8) /* ROUND = 2^(n-1) */
-#define TOUCH_GET_IO_NUM(channel) (touch_channel_to_gpio[channel])
+#define TOUCH_GET_RTCIO_NUM(channel) (touch_channel_to_rtcio[channel])

Review Comment:
   ```suggestion
   #define TOUCH_GET_RTCIO_NUM(channel)    (touch_channel_to_rtcio[channel])
   ```
   nit: align to previous line



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

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 merged pull request #8202: arch/xtensa/esp32: Add support for RTC IRQs

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #8202:
URL: https://github.com/apache/nuttx/pull/8202


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

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] lucasssvaz commented on a diff in pull request #8202: arch/xtensa/esp32: Add support for RTC IRQs

Posted by GitBox <gi...@apache.org>.
lucasssvaz commented on code in PR #8202:
URL: https://github.com/apache/nuttx/pull/8202#discussion_r1082737755


##########
arch/xtensa/src/esp32/esp32_gpio.c:
##########
@@ -222,258 +220,152 @@ int esp32_configgpio(int pin, gpio_pinattr_t attr)
   func  = 0;
   cntrl = 0;
 
-  if ((attr & FUNCTION_MASK) == FUNCTION_RTC) /* RTCIO */
+  if ((attr & INPUT) != 0)
     {
-      if (rtc_gpio_is_valid_gpio(pin) == 0)
-        {
-          gpioerr("Pin %d is not a valid RTC pin!\n", pin);
-          return -1;
-        }
-
-      rtc_gpio_idx = g_rtc_io_num_map[pin];
-      rtc_reg_desc = g_rtc_io_desc[rtc_gpio_idx];
-      g_pin_rtc_controlled[rtc_gpio_idx] = true;
-
-      setbits(rtc_reg_desc.reg, rtc_reg_desc.mux);
-
-      modifyreg32(rtc_reg_desc.reg,
-        ((RTC_IO_TOUCH_PAD1_FUN_SEL_V) << (rtc_reg_desc.func)),
-        (((RTCIO_PIN_FUNC) & RTC_IO_TOUCH_PAD1_FUN_SEL_V) <<
-        (rtc_reg_desc.func)));
-
-      if (rtc_reg_desc.pulldown)
-        {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.pulldown);
-        }
-
-      if (rtc_reg_desc.pullup)
-        {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.pullup);
-        }
-
-      if ((attr & PULLUP) != 0)
+      if (pin < 32)
         {
-          if (rtc_reg_desc.pullup)
-            {
-              setbits(rtc_reg_desc.reg, rtc_reg_desc.pullup);
-            }
+          putreg32((UINT32_C(1) << pin), GPIO_ENABLE_W1TC_REG);
         }
-      else if ((attr & PULLDOWN) != 0)
+      else
         {
-          if (rtc_reg_desc.pulldown)
-            {
-              setbits(rtc_reg_desc.reg, rtc_reg_desc.pulldown);
-            }
+          putreg32((UINT32_C(1) << (pin - 32)), GPIO_ENABLE1_W1TC_REG);
         }
 
-      if ((attr & INPUT) != 0)
-        {
-          /* Enable Input */
-
-          setbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
-
-          /* Disable Output */
-
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TC_REG);
-        }
-      else if ((attr & OUTPUT) != 0)
-        {
-          /* Disable Input */
+      /* Input enable */
 
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
+      func |= FUN_IE;
 
-          /* Enable Output */
+      /* Some pins only support Pull-Up and Pull-Down resistor on RTC GPIO */
 
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TS_REG);
-        }
-      else
+      if (gpio_is_valid_rtc_gpio(pin))
         {
-          resetbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
-          putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TC_REG);
-        }
+          uint32_t rtc_gpio_idx = g_gpio_to_rtcio_map[pin];
+          uint32_t regval;
+          uint32_t rtc_gpio_pin;
+          bool en_pu = false;
+          bool en_pd = false;
 
-      if ((attr & DRIVE_MASK) != 0)
-        {
-          if (rtc_reg_desc.drv_v)
+          if ((attr & PULLUP) != 0)
             {
-              uint32_t val = ((attr & DRIVE_MASK) >> DRIVE_SHIFT) - 1;
-              modifyreg32(rtc_reg_desc.reg,
-                ((rtc_reg_desc.drv_v) << (rtc_reg_desc.drv_s)),
-                (((val) & rtc_reg_desc.drv_v) << (rtc_reg_desc.drv_s)));
-            }
-        }
-
-      if ((attr & OPEN_DRAIN) != 0)
-        {
-          /* All RTC GPIOs have the same position for the drive bits.
-           * We can use any RTC_GPIO_PINn_PAD_DRIVER.
-           */
-
-          REG_SET_FIELD(rtc_gpio_to_addr[rtc_gpio_idx],
-                        RTC_GPIO_PIN0_PAD_DRIVER,
-                        true);
-        }
-      else
-        {
-          REG_SET_FIELD(rtc_gpio_to_addr[rtc_gpio_idx],
-                        RTC_GPIO_PIN0_PAD_DRIVER,
-                        false);
-        }
+              if (!rtc_gpio_is_pull_supported(rtc_gpio_idx))
+                {
+                  gpioerr("Pins 34-39 don't support PullUp/PullDown\n");
+                  PANIC();
+                }

Review Comment:
   Fixed!



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

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org