This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new e086ef2d02 boards/arm/stm32f7/nucleo-f767zi: enhance button support
e086ef2d02 is described below

commit e086ef2d029fbceb2a3d9bea070f3d286535aa29
Author: vrmay23 <vmay.swe...@gmail.com>
AuthorDate: Sat May 3 14:52:08 2025 +0200

    boards/arm/stm32f7/nucleo-f767zi: enhance button support
    
    Before this patch, the board nucleo-767zi had just one button available for 
the
    user, which one was not working (there was no /dev/buttons on 
stm32_bringup.c).
    
    Aditionally, I have changed the stm32_buttons.c to support not only the
    built-in button but as well as to another four external buttons.
---
 boards/arm/stm32f7/nucleo-f767zi/include/board.h   | 43 +++++++++++++--
 .../arm/stm32f7/nucleo-f767zi/src/nucleo-f767zi.h  | 42 +++++++++++---
 .../arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c  | 15 +++++
 .../arm/stm32f7/nucleo-f767zi/src/stm32_buttons.c  | 64 ++++++++++++++++++++--
 4 files changed, 145 insertions(+), 19 deletions(-)

diff --git a/boards/arm/stm32f7/nucleo-f767zi/include/board.h 
b/boards/arm/stm32f7/nucleo-f767zi/include/board.h
index 24e377f947..01e08d53e8 100644
--- a/boards/arm/stm32f7/nucleo-f767zi/include/board.h
+++ b/boards/arm/stm32f7/nucleo-f767zi/include/board.h
@@ -312,14 +312,45 @@
 
 /* Button definitions *******************************************************/
 
-/* The STM32F7 Discovery supports one button:  Pushbutton B1, labeled "User",
- * is connected to GPIO PI11.
- * A high value will be sensed when the button is depressed.
+/* The STM32F7 Discovery has just one user_button natively, which one is
+ * connected to GPIO PC13. This button, in this context, named as BUILT_IN,
+ * is connected in a pulldown resistor. Thus, when it changes from default
+ * value (LOW) to HIGH value, it is considered as 'pressed'.
+ *
+ * Plus, we can use the same strategy like in stm32103-minimun (bluepill) to
+ * provide more freedom to the users. Hence, four additional buttons will be
+ * available now and, then, five buttons can be directly handled.
+ *
+ * Please, make sure to also use your external buttons with a pulldown
+ * resistor as well, otherwise it will not work as expected.
+ *
+ * For this example we'll use the availables pin at ST Zio connector CN10,
+ * as listed below:
+ *
+ *   -------------------|----------|------------|-----------------
+ *      button_name     | pin_name | pin_number |  stm32_gpio_pin
+ *   -------------------|----------|------------|-----------------
+ *     BUTTON_EXTERN_1  |    D2    |     12     |     PF_15
+ *     BUTTON_EXTERN_2  |    D1    |     14     |     PG_14
+ *     BUTTON_EXTERN_3  |    D0    |     16     |     PG_9
+ *     BUTTON_EXTERN_4  |    D34   |     33     |     PE_0
+ *   -------------------------------------------------------------
+ *
  */
 
-#define BUTTON_USER        0
-#define NUM_BUTTONS        1
-#define BUTTON_USER_BIT    (1 << BUTTON_USER)
+#define BUTTON_BUILT_IN        0
+#define BUTTON_EXTERN_1        1
+#define BUTTON_EXTERN_2        2
+#define BUTTON_EXTERN_3        3
+#define BUTTON_EXTERN_4        4
+
+#define BUTTON_BUILT_IN_BIT    (1 << BUTTON_BUILT_IN)
+#define BUTTON_EXTERN_1_BIT    (1 << BUTTON_EXTERN_1)
+#define BUTTON_EXTERN_2_BIT    (1 << BUTTON_EXTERN_2)
+#define BUTTON_EXTERN_3_BIT    (1 << BUTTON_EXTERN_3)
+#define BUTTON_EXTERN_4_BIT    (1 << BUTTON_EXTERN_4)
+
+#define NUM_BUTTONS            5
 
 /* DMA channels *************************************************************/
 
diff --git a/boards/arm/stm32f7/nucleo-f767zi/src/nucleo-f767zi.h 
b/boards/arm/stm32f7/nucleo-f767zi/src/nucleo-f767zi.h
index d8322770aa..bc925a104d 100644
--- a/boards/arm/stm32f7/nucleo-f767zi/src/nucleo-f767zi.h
+++ b/boards/arm/stm32f7/nucleo-f767zi/src/nucleo-f767zi.h
@@ -56,12 +56,14 @@
  * The following definitions assume the default Solder Bridges are installed.
  */
 
-#define GPIO_LD1       (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | 
GPIO_OUTPUT_CLEAR | \
-                        GPIO_PORTB | GPIO_PIN0)
-#define GPIO_LD2       (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | 
GPIO_OUTPUT_CLEAR | \
-                        GPIO_PORTB | GPIO_PIN7)
-#define GPIO_LD3       (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | 
GPIO_OUTPUT_CLEAR | \
-                        GPIO_PORTB | GPIO_PIN14)
+#define GPIO_LD1       (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | \
+                        GPIO_OUTPUT_CLEAR | GPIO_PORTB | GPIO_PIN0)
+
+#define GPIO_LD2       (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | \
+                        GPIO_OUTPUT_CLEAR | GPIO_PORTB | GPIO_PIN7)
+
+#define GPIO_LD3       (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | \
+                        GPIO_OUTPUT_CLEAR | GPIO_PORTB | GPIO_PIN14)
 
 #define GPIO_LED_GREEN GPIO_LD1
 #define GPIO_LED_BLUE  GPIO_LD2
@@ -72,6 +74,11 @@
 /* BUTTONS
  *
  * The Blue pushbutton B1, labeled "User", is connected to GPIO PC13.
+ * On this context, this button is called 'GPIO_BTN_BUILT_IN'.
+ *
+ * The other buttons (GPIO_BNT_EXERN_X) are the external buttons already
+ * available for the user.
+ *
  * A high value will be sensed when the button is depressed.
  * Note:
  *    1) That the EXTI is included in the definition to enable an interrupt
@@ -80,7 +87,26 @@
  *       installed.
  */
 
-#define GPIO_BTN_USER  (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | GPIO_PORTC | 
GPIO_PIN13)
+#define GPIO_BTN_BUILT_IN  (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | \
+                            GPIO_PORTC | GPIO_PIN13)
+
+#define GPIO_BTN_EXTERN_1  (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | \
+                            GPIO_PORTF | GPIO_PIN15)
+
+#define GPIO_BTN_EXTERN_2  (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | \
+                            GPIO_PORTG | GPIO_PIN14)
+
+#define GPIO_BTN_EXTERN_3  (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | \
+                            GPIO_PORTG | GPIO_PIN9)
+
+#define GPIO_BTN_EXTERN_4  (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | \
+                            GPIO_PORTE | GPIO_PIN0)
+
+#define MIN_IRQBUTTON  BUTTON_BUILT_IN
+#define MAX_IRQBUTTON  BUTTON_EXTERN_4
+#define NUM_IRQBUTTONS (MIN_IRQBUTTON - MAX_IRQBUTTON + 1)
+
+#define BUTTONS_DRIVER_PATH "/dev/buttons"
 
 /* SPI **********************************************************************/
 
@@ -278,7 +304,7 @@ int stm32_sdio_initialize(void);
  * Name: stm32_usbinitialize
  *
  * Description:
- *   Called from stm32_usbinitialize very early in inialization to setup
+ *   Called from stm32_usbinitialize very early in initialization to setup
  *   USB-related GPIO pins for the nucleo-f767zi board.
  *
  ****************************************************************************/
diff --git a/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c 
b/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c
index 1abed8c963..501c6e10e1 100644
--- a/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c
+++ b/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c
@@ -60,6 +60,10 @@
 #  include <semaphore.h>
 #endif
 
+#ifdef CONFIG_INPUT_BUTTONS
+#  include <nuttx/input/buttons.h>
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -81,6 +85,17 @@
 int stm32_bringup(void)
 {
   int ret;
+
+#ifdef CONFIG_INPUT_BUTTONS
+  /* Register the BUTTON driver */
+
+  ret = btn_lower_initialize("/dev/buttons");
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret);
+    }
+#endif
+
 #ifdef CONFIG_I2C
   int i2c_bus;
   struct i2c_master_s *i2c;
diff --git a/boards/arm/stm32f7/nucleo-f767zi/src/stm32_buttons.c 
b/boards/arm/stm32f7/nucleo-f767zi/src/stm32_buttons.c
index 8cdb1da13f..8bf2c3851c 100644
--- a/boards/arm/stm32f7/nucleo-f767zi/src/stm32_buttons.c
+++ b/boards/arm/stm32f7/nucleo-f767zi/src/stm32_buttons.c
@@ -39,6 +39,28 @@
 
 #ifdef CONFIG_ARCH_BUTTONS
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#if defined(CONFIG_INPUT_BUTTONS) && !defined(CONFIG_ARCH_IRQBUTTONS)
+#  error "The NuttX Buttons Driver depends on IRQ support to work!\n"
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/* Pin configuration for each STM32F3Discovery button.  This array is indexed
+ * by the BUTTON_* definitions in board.h
+ */
+
+static const uint32_t g_buttons[NUM_BUTTONS] =
+{
+  GPIO_BTN_BUILT_IN, GPIO_BTN_EXTERN_1, GPIO_BTN_EXTERN_2, GPIO_BTN_EXTERN_3,
+  GPIO_BTN_EXTERN_4
+};
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -56,7 +78,17 @@
 
 uint32_t board_button_initialize(void)
 {
-  stm32_configgpio(GPIO_BTN_USER);
+  int i;
+
+  /* Configure the GPIO pins as inputs.  NOTE that EXTI interrupts are
+   * configured for all pins.
+   */
+
+  for (i = 0; i < NUM_BUTTONS; i++)
+    {
+      stm32_configgpio(g_buttons[i]);
+    }
+
   return NUM_BUTTONS;
 }
 
@@ -66,7 +98,26 @@ uint32_t board_button_initialize(void)
 
 uint32_t board_buttons(void)
 {
-  return stm32_gpioread(GPIO_BTN_USER) ? 1 : 0;
+  uint32_t ret = 0;
+  int i;
+
+  /* Check that state of each key */
+
+  for (i = 0; i < NUM_BUTTONS; i++)
+    {
+      /* A LOW value means that the key is pressed. */
+
+      bool released = stm32_gpioread(g_buttons[i]);
+
+      /* Accumulate the set of depressed (released) keys */
+
+      if (released)
+        {
+           ret |= (1 << i);
+        }
+    }
+
+  return ret;
 }
 
 /****************************************************************************
@@ -96,13 +147,16 @@ int board_button_irq(int id, xcpt_t irqhandler, void *arg)
 {
   int ret = -EINVAL;
 
-  if (id == BUTTON_USER)
+  /* The following should be atomic */
+
+  if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON)
     {
-      ret = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true,
-                               irqhandler, arg);
+      ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler,
+                               arg);
     }
 
   return ret;
 }
 #endif
+
 #endif /* CONFIG_ARCH_BUTTONS */

Reply via email to