vrmay23 commented on code in PR #18397: URL: https://github.com/apache/nuttx/pull/18397#discussion_r2809994466
########## 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: Review Comment: You're right. I checked the STM32H7 GPIO header and GPIO_PIN_SHIFT = 0, so GPIO_PINx values are direct indices. The switch is unnecessary. I'll simplify get_exti_line to return (gpio_config & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT. I can not change it today but during the week I'll do it and test. Thanks for good feedback! -- 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]
