vrmay23 commented on code in PR #18397:
URL: https://github.com/apache/nuttx/pull/18397#discussion_r2809986939


##########
boards/arm/stm32h7/nucleo-h753zi/src/stm32_buttons.c:
##########
@@ -0,0 +1,806 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h753zi/src/stm32_buttons.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stddef.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <syslog.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+
+#include "stm32_gpio.h"
+#include "nucleo-h753zi.h"
+
+#ifdef CONFIG_NUCLEO_H753ZI_BUTTON_SUPPORT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#if defined(CONFIG_INPUT_BUTTONS) && !defined(CONFIG_ARCH_IRQBUTTONS)
+#  error "The NuttX Buttons Driver depends on IRQ support to work!"
+#endif
+
+#define MAX_PIN_CONFIG_LEN 512
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Dynamic button configuration array */
+
+static uint32_t g_buttons[CONFIG_NUCLEO_H753ZI_BUTTON_COUNT];
+static int g_button_count = 0;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: get_exti_line
+ *
+ * Description:
+ *   Extract EXTI line number from GPIO configuration.
+ *
+ * Input Parameters:
+ *   gpio_config - STM32 GPIO configuration
+ *
+ * Returned Value:
+ *   EXTI line number (0-15), or -1 on error
+ *
+ ****************************************************************************/
+
+static int get_exti_line(uint32_t gpio_config)
+{
+  /* Extract pin number from GPIO_PIN mask */
+
+  uint32_t pin_mask = gpio_config & GPIO_PIN_MASK;
+
+  switch (pin_mask)
+    {
+      case GPIO_PIN0:
+        return 0;
+
+      case GPIO_PIN1:
+        return 1;
+
+      case GPIO_PIN2:
+        return 2;
+
+      case GPIO_PIN3:
+        return 3;
+
+      case GPIO_PIN4:
+        return 4;
+
+      case GPIO_PIN5:
+        return 5;
+
+      case GPIO_PIN6:
+        return 6;
+
+      case GPIO_PIN7:
+        return 7;
+
+      case GPIO_PIN8:
+        return 8;
+
+      case GPIO_PIN9:
+        return 9;
+
+      case GPIO_PIN10:
+        return 10;
+
+      case GPIO_PIN11:
+        return 11;
+
+      case GPIO_PIN12:
+        return 12;
+
+      case GPIO_PIN13:
+        return 13;
+
+      case GPIO_PIN14:
+        return 14;
+
+      case GPIO_PIN15:
+        return 15;
+
+      default:
+        return -1;
+    }
+}
+
+/****************************************************************************
+ * Name: get_gpio_port_letter
+ *
+ * Description:
+ *   Get port letter from GPIO configuration.
+ *
+ * Input Parameters:
+ *   gpio_config - STM32 GPIO configuration
+ *
+ * Returned Value:
+ *   Port letter ('A'-'H'), or '?' on error
+ *
+ ****************************************************************************/
+
+static char get_gpio_port_letter(uint32_t gpio_config)
+{
+  uint32_t port = gpio_config & GPIO_PORT_MASK;
+
+  switch (port)
+    {
+      case GPIO_PORTA:
+        return 'A';
+
+      case GPIO_PORTB:
+        return 'B';
+
+      case GPIO_PORTC:
+        return 'C';
+
+      case GPIO_PORTD:
+        return 'D';
+
+      case GPIO_PORTE:
+        return 'E';
+
+      case GPIO_PORTF:
+        return 'F';
+
+      case GPIO_PORTG:
+        return 'G';
+
+      case GPIO_PORTH:
+        return 'H';
+
+      default:
+        return '?';
+    }
+}
+
+/****************************************************************************
+ * Name: parse_gpio_pin
+ *
+ * Description:
+ *   Parse GPIO pin string like "PF15" into STM32 GPIO configuration.
+ *
+ * Input Parameters:
+ *   pin_str - GPIO pin string (e.g., "PA0", "PF15", "PC13")
+ *   error   - Pointer to error code storage
+ *
+ * Returned Value:
+ *   STM32 GPIO configuration value on success, 0 on error
+ *
+ ****************************************************************************/
+
+static uint32_t parse_gpio_pin(FAR const char *pin_str, FAR int *error)

Review Comment:
   I checked how the other boards do and I consider this a quite better 
approach. It is more user-friendly and scalable. We don't need to edit a code 
to change it, Kconfig is enough.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to