Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202549766


##
boards/arm/stm32/stm32f4discovery/configs/sbutton/defconfig:
##
@@ -0,0 +1,56 @@
+#

Review Comment:
   @mlyszczek this config was based on stm32f4discovery:nsh and I used "make 
savedefconfig" to generate it. I don't think CONFIG_RAM_START=0x2000 is 
defined because RAM_START is defined in arch/Kconfig with default value 0x0. So 
since it is different from default value it is included in the defconfig.



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202549766


##
boards/arm/stm32/stm32f4discovery/configs/sbutton/defconfig:
##
@@ -0,0 +1,56 @@
+#

Review Comment:
   @mlyszczek this config was based on stm32f4discovery:nsh and I used "make 
savedefconfig" to generate it. I don't know why CONFIG_RAM_START=0x2000 is 
not present, probably because this is default. You know Kconfig doesn't define 
symbols on defconfig that wasn't modified



##
boards/arm/stm32/stm32f4discovery/configs/sbutton/defconfig:
##
@@ -0,0 +1,56 @@
+#

Review Comment:
   @mlyszczek this config was based on stm32f4discovery:nsh and I used "make 
savedefconfig" to generate it. I don't know why CONFIG_RAM_START=0x2000 is 
not present, probably because this is default. You know Kconfig doesn't define 
symbols on defconfig that wasn't modified from its default value



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202549766


##
boards/arm/stm32/stm32f4discovery/configs/sbutton/defconfig:
##
@@ -0,0 +1,56 @@
+#

Review Comment:
   @mlyszczek this config was based on stm32f4discovery:nsh and I used "make 
savedefconfig" to generate it. I don't know why CONFIG_RAM_START=0x2000 is 
not present, probably because this is default. You know Kconfig doesn't define 
on defconfig symbols that wasn't modified



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202580485


##
drivers/input/Make.defs:
##
@@ -118,6 +118,10 @@ ifeq ($(CONFIG_INPUT_NUNCHUCK),y)
   CSRCS += nunchuck.c
 endif
 
+ifeq ($(CONFIG_INPUT_SBUTTON),y)
+  CSRCS += sbutton.c

Review Comment:
   Done



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202568085


##
include/nuttx/input/sbutton.h:
##
@@ -0,0 +1,114 @@
+/
+ * include/nuttx/input/sbutton.h
+ *
+ * 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.
+ *
+ /
+
+/* The single button driver exports a standard character driver interface. By
+ * convention, the driver is exposed as /dev/sbtn[n] and works like a common
+ * keyboard device, but generates only INPUT_TAB and INPUT_ENTER events.
+ */
+
+#ifndef __INCLUDE_NUTTX_INPUT_SBUTTON_H
+#define __INCLUDE_NUTTX_INPUT_SBUTTON_H
+
+/
+ * Included Files
+ /
+
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/
+ * Public Types
+ /
+
+/* A reference to a structure of this type must be passed to the
+ * single button keyboard driver.  This structure provides information
+ * about the configuration and provides some board-specific hooks.
+ */
+
+struct sbutton_config_s
+{
+  /* IRQ/GPIO access callbacks.  These operations all hidden behind
+   * callbacks to isolate the Q10 Keyboard driver from differences in GPIO
+   * interrupt handling by varying boards and MCUs.
+   *
+   * attach  - Attach the Q10 kbd interrupt handler to the GPIO interrupt
+   * enable  - Enable or disable the GPIO interrupt
+   * clear   - Acknowledge/clear any pending GPIO interrupt
+   */
+
+  int  (*attach)(FAR const struct sbutton_config_s *state, xcpt_t isr,

Review Comment:
   Good finding!



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202568721


##
include/nuttx/input/sbutton.h:
##
@@ -0,0 +1,114 @@
+/
+ * include/nuttx/input/sbutton.h
+ *
+ * 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.
+ *
+ /
+
+/* The single button driver exports a standard character driver interface. By
+ * convention, the driver is exposed as /dev/sbtn[n] and works like a common
+ * keyboard device, but generates only INPUT_TAB and INPUT_ENTER events.
+ */
+
+#ifndef __INCLUDE_NUTTX_INPUT_SBUTTON_H
+#define __INCLUDE_NUTTX_INPUT_SBUTTON_H
+
+/
+ * Included Files
+ /
+
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/
+ * Public Types
+ /
+
+/* A reference to a structure of this type must be passed to the
+ * single button keyboard driver.  This structure provides information
+ * about the configuration and provides some board-specific hooks.
+ */
+
+struct sbutton_config_s

Review Comment:
   @xiaoxiang781216 although using ioexpander could bring more flexibility it 
makes the code more complex and also it could generate issues: a key from a 
real I2C ioexpander will not work very well with this driver.



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202566344


##
include/nuttx/input/sbutton.h:
##
@@ -0,0 +1,114 @@
+/
+ * include/nuttx/input/sbutton.h
+ *
+ * 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.
+ *
+ /
+
+/* The single button driver exports a standard character driver interface. By
+ * convention, the driver is exposed as /dev/sbtn[n] and works like a common
+ * keyboard device, but generates only INPUT_TAB and INPUT_ENTER events.
+ */
+
+#ifndef __INCLUDE_NUTTX_INPUT_SBUTTON_H
+#define __INCLUDE_NUTTX_INPUT_SBUTTON_H
+
+/
+ * Included Files
+ /
+
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/
+ * Public Types
+ /
+
+/* A reference to a structure of this type must be passed to the
+ * single button keyboard driver.  This structure provides information
+ * about the configuration and provides some board-specific hooks.
+ */
+
+struct sbutton_config_s
+{
+  /* IRQ/GPIO access callbacks.  These operations all hidden behind
+   * callbacks to isolate the Q10 Keyboard driver from differences in GPIO
+   * interrupt handling by varying boards and MCUs.
+   *
+   * attach  - Attach the Q10 kbd interrupt handler to the GPIO interrupt
+   * enable  - Enable or disable the GPIO interrupt
+   * clear   - Acknowledge/clear any pending GPIO interrupt
+   */
+
+  int  (*attach)(FAR const struct sbutton_config_s *state, xcpt_t isr,
+ FAR void *arg);
+  void (*enable)(FAR const struct sbutton_config_s *state, bool enable);
+  void (*clear)(FAR const struct sbutton_config_s *state);
+  bool (*pin_status)(void);

Review Comment:
   Ok, changed it, but the the stm32_sbutton I keept to function name as 
sbtn_pin_status() to make it clear for someone adding support to another board.



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202564064


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);
+
+/
+ * Private Data
+ /
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: sbutton_worker
+ /
+
+static void sbutton_worker(FAR void *arg)
+{
+  FAR struct sbutton_dev_s *priv = (FAR struct sbutton_dev_s *)arg;
+  uint8_t   state;
+  int   ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+{
+  return;
+}
+
+  /* Read the status of the button */
+
+  state = priv->config->pin_status();
+
+  /* If the user just pressed the button, start measuring */
+
+  if (state == KEY_PRESS && !priv->pressed)
+{
+  iinfo("Button pressed\n");
+
+  priv->pressed = true;
+  priv->start   = clock_systime_ticks();
+}
+  else
+{
+  if (state == KEY_RELEASE && priv->pressed)
+{
+  uint32_t elapsed;
+
+  iinfo("Button released\n");
+
+  priv->pressed = false;
+  priv->end = clock_systime_ticks();
+
+  elapsed = priv->end - priv->start;
+  if (elapsed < MSEC2TICK(KEY_THRESH_MS))
+{
+  iinfo("KEY_1\n");
+  keyboard_event(&priv->lower, ASCII_A, KEYBOARD_PRESS);
+}
+  else
+{
+  iinfo("KEY_2\n");
+  keyboard_event(&priv->lower, ASCII_B, KEYBOARD_PRESS);

Review 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202561127


##
boards/arm/stm32/common/src/stm32_sbutton.c:
##
@@ -0,0 +1,182 @@
+/
+ * boards/arm/stm32/common/src/stm32_sbutton.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 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include "stm32.h"
+
+/
+ * Pre-processor Definitions
+ /
+
+/
+ * Private Types
+ /
+
+struct stm32_sbtnconfig_s
+{
+  /* Configuration structure as seen by the HC-SR04 driver */
+
+  struct sbutton_config_s config;
+
+  /* Additional private definitions only known to this driver */
+
+  void *arg;/* Argument to pass to the interrupt handler */
+  xcpt_t isr;   /* ISR Handler */
+};
+
+/
+ * Private Function Prototypes
+ /
+
+static int  sbtn_irq_attach(const struct sbutton_config_s *state, xcpt_t isr,
+void *arg);
+static void sbtn_irq_enable(const struct sbutton_config_s *state,
+bool enable);
+static void sbtn_irq_clear(const struct sbutton_config_s *state);
+
+static bool sbtn_pin_status(void);
+
+/
+ * Private Data
+ /
+
+/* A reference to a structure of this type must be passed to the SButton
+ * driver.  This structure provides information about the configuration
+ * of the SButton and provides some board-specific hooks.
+ *
+ * Memory for this structure is provided by the caller.  It is not copied
+ * by the driver and is presumed to persist while the driver is active.
+ */
+
+static struct stm32_sbtnconfig_s g_sbtnconfig =
+{
+  .config =
+  {
+.attach = sbtn_irq_attach,
+.enable = sbtn_irq_enable,
+.clear  = sbtn_irq_clear,
+.pin_status = sbtn_pin_status,
+  },
+};
+
+/
+ * Private Functions
+ /
+
+/* Attach the SBUTTON interrupt handler to the GPIO interrupt */
+
+static int sbtn_irq_attach(const struct sbutton_config_s *state, xcpt_t isr,
+   void *arg)
+{
+  struct stm32_sbtnconfig_s *priv = (struct stm32_sbtnconfig_s *)state;
+  irqstate_t flags;
+
+  sinfo("sbtn_irq_attach\n");
+
+  flags = enter_critical_section();
+
+  priv->isr = isr;
+  priv->arg = arg;
+
+  stm32_gpiosetevent(BOARD_SBUTTON_GPIO_INT, true, true,
+ true, isr, arg);
+
+  leave_critical_section(flags);
+
+  return OK;
+}
+
+/* Enable or disable the GPIO interrupt */
+
+static void sbtn_irq_enable(const struct sbutton_config_s *state,
+bool enable)
+{
+  struct stm32_sbtnconfig_s *priv = (struct stm32_sbtnconfig_s *)state;
+
+  iinfo("%d\n", enable);
+
+  stm32_gpiosetevent(BOARD_SBUTTON_GPIO_INT, true, true,
+ true, enable ? priv->isr : NULL, priv->arg);
+}
+
+/* Acknowledge/clear any pending GPIO interrupt */
+
+static void sbtn_irq_clear(const struct sbutton_config_s *state)
+{
+  /* FIXME: Nothing to do ? */
+}
+
+/* Read and return the status of button (PRESSED = true; RELEASED = false */
+
+static bool sbtn_pin_status(void)
+{
+  /* STM32F4Discovery button B1 is high level 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202560760


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);
+
+/
+ * Private Data
+ /
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: sbutton_worker
+ /
+
+static void sbutton_worker(FAR void *arg)
+{
+  FAR struct sbutton_dev_s *priv = (FAR struct sbutton_dev_s *)arg;
+  uint8_t   state;
+  int   ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+{
+  return;
+}
+
+  /* Read the status of the button */
+
+  state = priv->config->pin_status();
+
+  /* If the user just pressed the button, start measuring */
+
+  if (state == KEY_PRESS && !priv->pressed)
+{
+  iinfo("Button pressed\n");
+
+  priv->pressed = true;
+  priv->start   = clock_systime_ticks();
+}
+  else
+{
+  if (state == KEY_RELEASE && priv->pressed)
+{
+  uint32_t elapsed;
+
+  iinfo("Button released\n");
+
+  priv->pressed = false;
+  priv->end = clock_systime_ticks();
+
+  elapsed = priv->end - priv->start;
+  if (elapsed < MSEC2TICK(KEY_THRESH_MS))
+{
+  iinfo("KEY_1\n");
+  keyboard_event(&priv->lower, ASCII_A, KEYBOARD_PRESS);

Review Comment:
   Good catch, for testing I was using A and B. Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202560480


##
include/nuttx/input/sbutton.h:
##
@@ -0,0 +1,114 @@
+/
+ * include/nuttx/input/sbutton.h
+ *
+ * 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.
+ *
+ /
+
+/* The single button driver exports a standard character driver interface. By
+ * convention, the driver is exposed as /dev/sbtn[n] and works like a common
+ * keyboard device, but generates only INPUT_TAB and INPUT_ENTER events.
+ */
+
+#ifndef __INCLUDE_NUTTX_INPUT_SBUTTON_H
+#define __INCLUDE_NUTTX_INPUT_SBUTTON_H
+
+/
+ * Included Files
+ /
+
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/
+ * Public Types
+ /
+
+/* A reference to a structure of this type must be passed to the
+ * single button keyboard driver.  This structure provides information
+ * about the configuration and provides some board-specific hooks.
+ */
+
+struct sbutton_config_s
+{
+  /* IRQ/GPIO access callbacks.  These operations all hidden behind
+   * callbacks to isolate the Q10 Keyboard driver from differences in GPIO
+   * interrupt handling by varying boards and MCUs.
+   *
+   * attach  - Attach the Q10 kbd interrupt handler to the GPIO interrupt
+   * enable  - Enable or disable the GPIO interrupt
+   * clear   - Acknowledge/clear any pending GPIO interrupt
+   */
+
+  int  (*attach)(FAR const struct sbutton_config_s *state, xcpt_t isr,
+ FAR void *arg);
+  void (*enable)(FAR const struct sbutton_config_s *state, bool enable);
+  void (*clear)(FAR const struct sbutton_config_s *state);
+  bool (*pin_status)(void);
+};
+
+/
+ * Public Data
+ /
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/
+ * Public Function Prototypes
+ /
+
+/
+ * Name: spq10kbd_register
+ *
+ * Description:
+ *   Configure the single button driver to use the provided instance.
+ *   This will register the driver as /dev/sbtnN where N is the
+ *   minor device number.
+ *
+ * Input Parameters:
+ *   config  - Persistent board configuration data
+ *   kbdminor- The keyboard input device minor number
+ *   joydevname  - The name of the joystick device /dev/djoyN

Review Comment:
   Done



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202560081


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);
+
+/
+ * Private Data
+ /
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: sbutton_worker
+ /
+
+static void sbutton_worker(FAR void *arg)
+{
+  FAR struct sbutton_dev_s *priv = (FAR struct sbutton_dev_s *)arg;
+  uint8_t   state;
+  int   ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+{
+  return;
+}
+
+  /* Read the status of the button */
+
+  state = priv->config->pin_status();
+
+  /* If the user just pressed the button, start measuring */
+
+  if (state == KEY_PRESS && !priv->pressed)
+{
+  iinfo("Button pressed\n");
+
+  priv->pressed = true;
+  priv->start   = clock_systime_ticks();
+}
+  else
+{
+  if (state == KEY_RELEASE && priv->pressed)
+{
+  uint32_t elapsed;
+
+  iinfo("Button released\n");
+
+  priv->pressed = false;
+  priv->end = clock_systime_ticks();
+
+  elapsed = priv->end - priv->start;
+  if (elapsed < MSEC2TICK(KEY_THRESH_MS))
+{
+  iinfo("KEY_1\n");
+  keyboard_event(&priv->lower, ASCII_A, KEYBOARD_PRESS);
+}
+  else
+{
+  iinfo("KEY_2\n");
+  keyboard_event(&priv->lower, ASCII_B, KEYBOARD_PRESS);
+   

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202558877


##
include/nuttx/input/sbutton.h:
##
@@ -0,0 +1,114 @@
+/
+ * include/nuttx/input/sbutton.h
+ *
+ * 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.
+ *
+ /
+
+/* The single button driver exports a standard character driver interface. By
+ * convention, the driver is exposed as /dev/sbtn[n] and works like a common

Review Comment:
   Yes, initially I used /dev/sbtn0, but later I changed to /dev/kbd0 to 
simplify the application finding the device



##
include/nuttx/input/sbutton.h:
##
@@ -0,0 +1,114 @@
+/
+ * include/nuttx/input/sbutton.h
+ *
+ * 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.
+ *
+ /
+
+/* The single button driver exports a standard character driver interface. By
+ * convention, the driver is exposed as /dev/sbtn[n] and works like a common

Review Comment:
   Done



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202558154


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);
+
+/
+ * Private Data
+ /
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: sbutton_worker
+ /
+
+static void sbutton_worker(FAR void *arg)
+{
+  FAR struct sbutton_dev_s *priv = (FAR struct sbutton_dev_s *)arg;
+  uint8_t   state;
+  int   ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+{
+  return;
+}
+
+  /* Read the status of the button */
+
+  state = priv->config->pin_status();
+
+  /* If the user just pressed the button, start measuring */
+
+  if (state == KEY_PRESS && !priv->pressed)
+{
+  iinfo("Button pressed\n");
+
+  priv->pressed = true;
+  priv->start   = clock_systime_ticks();
+}
+  else
+{
+  if (state == KEY_RELEASE && priv->pressed)
+{
+  uint32_t elapsed;
+
+  iinfo("Button released\n");
+
+  priv->pressed = false;
+  priv->end = clock_systime_ticks();
+
+  elapsed = priv->end - priv->start;
+  if (elapsed < MSEC2TICK(KEY_THRESH_MS))
+{
+  iinfo("KEY_1\n");
+  keyboard_event(&priv->lower, ASCII_A, KEYBOARD_PRESS);
+}
+  else
+{
+  iinfo("KEY_2\n");
+  keyboard_event(&priv->lower, ASCII_B, KEYBOARD_PRESS);
+   

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202557886


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11

Review Comment:
   Makes sense! Done



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202557828


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);
+
+/
+ * Private Data
+ /
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: sbutton_worker
+ /
+
+static void sbutton_worker(FAR void *arg)
+{
+  FAR struct sbutton_dev_s *priv = (FAR struct sbutton_dev_s *)arg;
+  uint8_t   state;
+  int   ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+{
+  return;
+}
+
+  /* Read the status of the button */
+
+  state = priv->config->pin_status();
+
+  /* If the user just pressed the button, start measuring */
+
+  if (state == KEY_PRESS && !priv->pressed)
+{
+  iinfo("Button pressed\n");
+
+  priv->pressed = true;
+  priv->start   = clock_systime_ticks();
+}
+  else
+{
+  if (state == KEY_RELEASE && priv->pressed)
+{
+  uint32_t elapsed;
+
+  iinfo("Button released\n");
+
+  priv->pressed = false;
+  priv->end = clock_systime_ticks();
+
+  elapsed = priv->end - priv->start;
+  if (elapsed < MSEC2TICK(KEY_THRESH_MS))
+{
+  iinfo("KEY_1\n");
+  keyboard_event(&priv->lower, ASCII_A, KEYBOARD_PRESS);
+}
+  else
+{
+  iinfo("KEY_2\n");
+  keyboard_event(&priv->lower, ASCII_B, KEYBOARD_PRESS);
+   

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202557578


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);

Review Comment:
   Good catch, it is not nitpicking, NuttX code is supposed to have good 
quality ;-)



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202557325


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"

Review Comment:
   I used /dev/kbd because this is the default used by the keyboard application 
example, this way the user don't need to modify the example. And normally a 
board with keyboard will not need a sbutton together, so I don't see conflict 
here



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202554429


##
drivers/input/Kconfig:
##
@@ -622,6 +622,25 @@ config INPUT_BUTTONS_NPOLLWAITERS
 
 endif # INPUT_BUTTONS
 
+config INPUT_SBUTTON

Review Comment:
   done (I'm updating locally and marking as Resolved to simplify my review)



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-12 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202549766


##
boards/arm/stm32/stm32f4discovery/configs/sbutton/defconfig:
##
@@ -0,0 +1,56 @@
+#

Review Comment:
   @mlyszczek this config was based on stm32f4discovery:nsh and I used "make 
savedefconfig" to generate it. I don't know why CONFIG_RAM_START=0x2000, 
probably because this is default. You know Kconfig doesn't define on defconfig 
symbols that wasn't modified



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


xiaoxiang781216 commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202322726


##
include/nuttx/input/sbutton.h:
##
@@ -0,0 +1,114 @@
+/
+ * include/nuttx/input/sbutton.h
+ *
+ * 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.
+ *
+ /
+
+/* The single button driver exports a standard character driver interface. By
+ * convention, the driver is exposed as /dev/sbtn[n] and works like a common
+ * keyboard device, but generates only INPUT_TAB and INPUT_ENTER events.
+ */
+
+#ifndef __INCLUDE_NUTTX_INPUT_SBUTTON_H
+#define __INCLUDE_NUTTX_INPUT_SBUTTON_H
+
+/
+ * Included Files
+ /
+
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/
+ * Public Types
+ /
+
+/* A reference to a structure of this type must be passed to the
+ * single button keyboard driver.  This structure provides information
+ * about the configuration and provides some board-specific hooks.
+ */
+
+struct sbutton_config_s

Review Comment:
   why not write a general one key board driver on top of 
ioexpander(keyboard_ioexpander.c/keyboard_gpio.c)? so, we don't need add the 
duplicated glue logic for each board/chip?



##
include/nuttx/input/sbutton.h:
##
@@ -0,0 +1,114 @@
+/
+ * include/nuttx/input/sbutton.h
+ *
+ * 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.
+ *
+ /
+
+/* The single button driver exports a standard character driver interface. By
+ * convention, the driver is exposed as /dev/sbtn[n] and works like a common
+ * keyboard device, but generates only INPUT_TAB and INPUT_ENTER events.
+ */
+
+#ifndef __INCLUDE_NUTTX_INPUT_SBUTTON_H
+#define __INCLUDE_NUTTX_INPUT_SBUTTON_H
+
+/
+ * Included Files
+ /
+
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/
+ * Public Types
+ /
+
+/* A reference to a structure of this type must be passed to the
+ * single button keyboard driver.  This structure provides information
+ * about the configuration and provides some board-specific hooks.
+ */
+
+struct sbutton_config_s
+{
+  /* IRQ/GPIO access callbacks.  These operations all hidden behind
+   * callbacks to isolate the Q10 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


acassis commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2202017817


##
drivers/input/Kconfig:
##
@@ -622,6 +622,25 @@ config INPUT_BUTTONS_NPOLLWAITERS
 
 endif # INPUT_BUTTONS
 
+config INPUT_SBUTTON

Review Comment:
   Good idea! Thank you!



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201998811


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);
+
+/
+ * Private Data
+ /
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: sbutton_worker
+ /
+
+static void sbutton_worker(FAR void *arg)
+{
+  FAR struct sbutton_dev_s *priv = (FAR struct sbutton_dev_s *)arg;
+  uint8_t   state;
+  int   ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+{
+  return;
+}
+
+  /* Read the status of the button */
+
+  state = priv->config->pin_status();
+
+  /* If the user just pressed the button, start measuring */
+
+  if (state == KEY_PRESS && !priv->pressed)
+{
+  iinfo("Button pressed\n");
+
+  priv->pressed = true;
+  priv->start   = clock_systime_ticks();
+}
+  else
+{
+  if (state == KEY_RELEASE && priv->pressed)
+{
+  uint32_t elapsed;
+
+  iinfo("Button released\n");
+
+  priv->pressed = false;
+  priv->end = clock_systime_ticks();
+
+  elapsed = priv->end - priv->start;
+  if (elapsed < MSEC2TICK(KEY_THRESH_MS))
+{
+  iinfo("KEY_1\n");
+  keyboard_event(&priv->lower, ASCII_A, KEYBOARD_PRESS);
+}
+  else
+{
+  iinfo("KEY_2\n");
+  keyboard_event(&priv->lower, ASCII_B, KEYBOARD_PRESS);

Review 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201994030


##
boards/arm/stm32/common/src/stm32_sbutton.c:
##
@@ -0,0 +1,182 @@
+/
+ * boards/arm/stm32/common/src/stm32_sbutton.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 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include "stm32.h"
+
+/
+ * Pre-processor Definitions
+ /
+
+/
+ * Private Types
+ /
+
+struct stm32_sbtnconfig_s
+{
+  /* Configuration structure as seen by the HC-SR04 driver */
+
+  struct sbutton_config_s config;
+
+  /* Additional private definitions only known to this driver */
+
+  void *arg;/* Argument to pass to the interrupt handler */
+  xcpt_t isr;   /* ISR Handler */
+};
+
+/
+ * Private Function Prototypes
+ /
+
+static int  sbtn_irq_attach(const struct sbutton_config_s *state, xcpt_t isr,
+void *arg);
+static void sbtn_irq_enable(const struct sbutton_config_s *state,
+bool enable);
+static void sbtn_irq_clear(const struct sbutton_config_s *state);
+
+static bool sbtn_pin_status(void);
+
+/
+ * Private Data
+ /
+
+/* A reference to a structure of this type must be passed to the SButton
+ * driver.  This structure provides information about the configuration
+ * of the SButton and provides some board-specific hooks.
+ *
+ * Memory for this structure is provided by the caller.  It is not copied
+ * by the driver and is presumed to persist while the driver is active.
+ */
+
+static struct stm32_sbtnconfig_s g_sbtnconfig =
+{
+  .config =
+  {
+.attach = sbtn_irq_attach,
+.enable = sbtn_irq_enable,
+.clear  = sbtn_irq_clear,
+.pin_status = sbtn_pin_status,
+  },
+};
+
+/
+ * Private Functions
+ /
+
+/* Attach the SBUTTON interrupt handler to the GPIO interrupt */
+
+static int sbtn_irq_attach(const struct sbutton_config_s *state, xcpt_t isr,
+   void *arg)
+{
+  struct stm32_sbtnconfig_s *priv = (struct stm32_sbtnconfig_s *)state;
+  irqstate_t flags;
+
+  sinfo("sbtn_irq_attach\n");
+
+  flags = enter_critical_section();
+
+  priv->isr = isr;
+  priv->arg = arg;
+
+  stm32_gpiosetevent(BOARD_SBUTTON_GPIO_INT, true, true,
+ true, isr, arg);
+
+  leave_critical_section(flags);
+
+  return OK;
+}
+
+/* Enable or disable the GPIO interrupt */
+
+static void sbtn_irq_enable(const struct sbutton_config_s *state,
+bool enable)
+{
+  struct stm32_sbtnconfig_s *priv = (struct stm32_sbtnconfig_s *)state;
+
+  iinfo("%d\n", enable);
+
+  stm32_gpiosetevent(BOARD_SBUTTON_GPIO_INT, true, true,
+ true, enable ? priv->isr : NULL, priv->arg);
+}
+
+/* Acknowledge/clear any pending GPIO interrupt */
+
+static void sbtn_irq_clear(const struct sbutton_config_s *state)
+{
+  /* FIXME: Nothing to do ? */
+}
+
+/* Read and return the status of button (PRESSED = true; RELEASED = false */
+
+static bool sbtn_pin_status(void)
+{
+  /* STM32F4Discovery button B1 is high 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201989924


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);
+
+/
+ * Private Data
+ /
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: sbutton_worker
+ /
+
+static void sbutton_worker(FAR void *arg)
+{
+  FAR struct sbutton_dev_s *priv = (FAR struct sbutton_dev_s *)arg;
+  uint8_t   state;
+  int   ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+{
+  return;
+}
+
+  /* Read the status of the button */
+
+  state = priv->config->pin_status();
+
+  /* If the user just pressed the button, start measuring */
+
+  if (state == KEY_PRESS && !priv->pressed)
+{
+  iinfo("Button pressed\n");
+
+  priv->pressed = true;
+  priv->start   = clock_systime_ticks();
+}
+  else
+{
+  if (state == KEY_RELEASE && priv->pressed)
+{
+  uint32_t elapsed;
+
+  iinfo("Button released\n");
+
+  priv->pressed = false;
+  priv->end = clock_systime_ticks();
+
+  elapsed = priv->end - priv->start;
+  if (elapsed < MSEC2TICK(KEY_THRESH_MS))
+{
+  iinfo("KEY_1\n");
+  keyboard_event(&priv->lower, ASCII_A, KEYBOARD_PRESS);

Review Comment:
   Documentation mentions driver will return enter or tab, but it appears you 
are returning 'a' and 'a' keys here?



-- 
This is an 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201981820


##
include/nuttx/input/sbutton.h:
##
@@ -0,0 +1,114 @@
+/
+ * include/nuttx/input/sbutton.h
+ *
+ * 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.
+ *
+ /
+
+/* The single button driver exports a standard character driver interface. By
+ * convention, the driver is exposed as /dev/sbtn[n] and works like a common

Review Comment:
   You mention `/dev/sbtn[n]` here, but create `/dev/kbd[n]` device. IMO sbtn 
is better than kbd as it's more descriptive.



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201985547


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);
+
+/
+ * Private Data
+ /
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: sbutton_worker
+ /
+
+static void sbutton_worker(FAR void *arg)
+{
+  FAR struct sbutton_dev_s *priv = (FAR struct sbutton_dev_s *)arg;
+  uint8_t   state;
+  int   ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+{
+  return;
+}
+
+  /* Read the status of the button */
+
+  state = priv->config->pin_status();
+
+  /* If the user just pressed the button, start measuring */
+
+  if (state == KEY_PRESS && !priv->pressed)
+{
+  iinfo("Button pressed\n");
+
+  priv->pressed = true;
+  priv->start   = clock_systime_ticks();
+}
+  else
+{
+  if (state == KEY_RELEASE && priv->pressed)
+{
+  uint32_t elapsed;
+
+  iinfo("Button released\n");
+
+  priv->pressed = false;
+  priv->end = clock_systime_ticks();
+
+  elapsed = priv->end - priv->start;
+  if (elapsed < MSEC2TICK(KEY_THRESH_MS))
+{
+  iinfo("KEY_1\n");
+  keyboard_event(&priv->lower, ASCII_A, KEYBOARD_PRESS);
+}
+  else
+{
+  iinfo("KEY_2\n");
+  keyboard_event(&priv->lower, ASCII_B, KEYBOARD_PRESS);
+ 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201978076


##
include/nuttx/input/sbutton.h:
##
@@ -0,0 +1,114 @@
+/
+ * include/nuttx/input/sbutton.h
+ *
+ * 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.
+ *
+ /
+
+/* The single button driver exports a standard character driver interface. By
+ * convention, the driver is exposed as /dev/sbtn[n] and works like a common
+ * keyboard device, but generates only INPUT_TAB and INPUT_ENTER events.
+ */
+
+#ifndef __INCLUDE_NUTTX_INPUT_SBUTTON_H
+#define __INCLUDE_NUTTX_INPUT_SBUTTON_H
+
+/
+ * Included Files
+ /
+
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/
+ * Public Types
+ /
+
+/* A reference to a structure of this type must be passed to the
+ * single button keyboard driver.  This structure provides information
+ * about the configuration and provides some board-specific hooks.
+ */
+
+struct sbutton_config_s
+{
+  /* IRQ/GPIO access callbacks.  These operations all hidden behind
+   * callbacks to isolate the Q10 Keyboard driver from differences in GPIO
+   * interrupt handling by varying boards and MCUs.
+   *
+   * attach  - Attach the Q10 kbd interrupt handler to the GPIO interrupt
+   * enable  - Enable or disable the GPIO interrupt
+   * clear   - Acknowledge/clear any pending GPIO interrupt
+   */
+
+  int  (*attach)(FAR const struct sbutton_config_s *state, xcpt_t isr,
+ FAR void *arg);
+  void (*enable)(FAR const struct sbutton_config_s *state, bool enable);
+  void (*clear)(FAR const struct sbutton_config_s *state);
+  bool (*pin_status)(void);
+};
+
+/
+ * Public Data
+ /
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/
+ * Public Function Prototypes
+ /
+
+/
+ * Name: spq10kbd_register
+ *
+ * Description:
+ *   Configure the single button driver to use the provided instance.
+ *   This will register the driver as /dev/sbtnN where N is the
+ *   minor device number.
+ *
+ * Input Parameters:
+ *   config  - Persistent board configuration data
+ *   kbdminor- The keyboard input device minor number
+ *   joydevname  - The name of the joystick device /dev/djoyN

Review Comment:
   Function does not accept `joydevname` argument.



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201974466


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);
+
+/
+ * Private Data
+ /
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: sbutton_worker
+ /
+
+static void sbutton_worker(FAR void *arg)
+{
+  FAR struct sbutton_dev_s *priv = (FAR struct sbutton_dev_s *)arg;
+  uint8_t   state;
+  int   ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+{
+  return;
+}
+
+  /* Read the status of the button */
+
+  state = priv->config->pin_status();
+
+  /* If the user just pressed the button, start measuring */
+
+  if (state == KEY_PRESS && !priv->pressed)
+{
+  iinfo("Button pressed\n");
+
+  priv->pressed = true;
+  priv->start   = clock_systime_ticks();
+}
+  else
+{
+  if (state == KEY_RELEASE && priv->pressed)
+{
+  uint32_t elapsed;
+
+  iinfo("Button released\n");
+
+  priv->pressed = false;
+  priv->end = clock_systime_ticks();
+
+  elapsed = priv->end - priv->start;
+  if (elapsed < MSEC2TICK(KEY_THRESH_MS))
+{
+  iinfo("KEY_1\n");
+  keyboard_event(&priv->lower, ASCII_A, KEYBOARD_PRESS);
+}
+  else
+{
+  iinfo("KEY_2\n");
+  keyboard_event(&priv->lower, ASCII_B, KEYBOARD_PRESS);
+ 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201972568


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11

Review Comment:
   With size of array being 11, you can only fit `/dev/kbd{0..99}` while minor 
can go up to 127. This would be truncated if someone gets crazy enough to 
create 100+ of those devices and it would result in node leak. Should be 12 to 
be safe.



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201968023


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);
+
+/
+ * Private Data
+ /
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: sbutton_worker
+ /
+
+static void sbutton_worker(FAR void *arg)
+{
+  FAR struct sbutton_dev_s *priv = (FAR struct sbutton_dev_s *)arg;
+  uint8_t   state;
+  int   ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+{
+  return;
+}
+
+  /* Read the status of the button */
+
+  state = priv->config->pin_status();
+
+  /* If the user just pressed the button, start measuring */
+
+  if (state == KEY_PRESS && !priv->pressed)
+{
+  iinfo("Button pressed\n");
+
+  priv->pressed = true;
+  priv->start   = clock_systime_ticks();
+}
+  else
+{
+  if (state == KEY_RELEASE && priv->pressed)
+{
+  uint32_t elapsed;
+
+  iinfo("Button released\n");
+
+  priv->pressed = false;
+  priv->end = clock_systime_ticks();
+
+  elapsed = priv->end - priv->start;
+  if (elapsed < MSEC2TICK(KEY_THRESH_MS))
+{
+  iinfo("KEY_1\n");
+  keyboard_event(&priv->lower, ASCII_A, KEYBOARD_PRESS);
+}
+  else
+{
+  iinfo("KEY_2\n");
+  keyboard_event(&priv->lower, ASCII_B, KEYBOARD_PRESS);
+ 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201961951


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"
+#define DEV_NAMELEN 11
+
+#define KEY_PRESS   true
+#define KEY_RELEASE false
+
+#define KEY_THRESH_MS   500
+
+/
+ * Private Types
+ /
+
+struct sbutton_dev_s
+{
+  FAR const struct sbutton_config_s *config;  /* Board configuration data */
+
+  mutex_t lock; /* Exclusive access to dev */
+  clock_t start;/* Clock tick when the key was pressed */
+  clock_t end;  /* Clock tick when the key was released */
+  boolpressed;  /* Keep previous status of button */
+  struct  work_s work;  /* Supports the interrupt handling "bottom half" */
+
+  /* Keyboard lowerhalf of the registered keyboard */
+
+  struct keyboard_lowerhalf_s lower;
+};
+
+/
+ * Static Function Prototypes
+ /
+
+static int sbutton_interrupt(int irq, FAR void *context, FAR void *arg);
+static void sbutton_worker(FAR void *arg);
+static void sbutton_putbuffer(FAR struct sbutton_dev_s *priv,
+   uint8_t keycode);

Review Comment:
   [nitpicking] alignment seems wrong



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201961117


##
drivers/input/sbutton.c:
##
@@ -0,0 +1,269 @@
+/
+ * drivers/input/sbutton.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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/
+ * Pre-processor Definitions
+ /
+
+/* This format is used to construct the /dev/kbd[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT  "/dev/kbd%d"

Review Comment:
   Is `/dev/kbd` a good naming here? It's very broad name for a very specific 
function. In Linux `/dev/kbd` was used in the past as raw keyboard device.
   
   Why not `/dev/sbutton` or even `/dev/input/sbutton`?



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201953562


##
boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c:
##
@@ -452,6 +456,16 @@ int stm32_bringup(void)
 }
 #endif
 
+#ifdef CONFIG_INPUT_SBUTTON
+  /* Register the Single Button Dual Action driver */
+
+  ret = board_sbutton_initialize(0);

Review Comment:
   I guess you can ignore that. Expanded file and it just follows current 
convention of naming scheme.



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201954298


##
drivers/input/Kconfig:
##
@@ -622,6 +622,25 @@ config INPUT_BUTTONS_NPOLLWAITERS
 
 endif # INPUT_BUTTONS
 
+config INPUT_SBUTTON

Review Comment:
   Maybe add `KEY_THRESH_MS` as configurable value?



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201953038


##
boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c:
##
@@ -452,6 +456,16 @@ int stm32_bringup(void)
 }
 #endif
 
+#ifdef CONFIG_INPUT_SBUTTON
+  /* Register the Single Button Dual Action driver */
+
+  ret = board_sbutton_initialize(0);

Review Comment:
   I would expect function with such name to have external linkage and be 
called outside of specific board. Shouldn't that be prefixed with something 
like `stm32_` as you have in comment for the function? This seems internal to 
stm32f4disco.



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201949834


##
boards/arm/stm32/stm32f4discovery/configs/sbutton/defconfig:
##
@@ -0,0 +1,56 @@
+#

Review Comment:
   Shouldn't this defconfig define an absolute minimum needed for sbutton to 
work? Also, was it indeed generated with `make savedefconfig`? I would expect 
entries like `CONFIG_RAM_START=0x2000` to be defined in default value so it 
should not be present here?



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



Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


mlyszczek commented on code in PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#discussion_r2201944736


##
boards/arm/stm32/common/src/stm32_sbutton.c:
##
@@ -0,0 +1,182 @@
+/
+ * boards/arm/stm32/common/src/stm32_sbutton.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 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include "stm32.h"
+
+/
+ * Pre-processor Definitions
+ /
+
+/
+ * Private Types
+ /
+
+struct stm32_sbtnconfig_s
+{
+  /* Configuration structure as seen by the HC-SR04 driver */
+
+  struct sbutton_config_s config;
+
+  /* Additional private definitions only known to this driver */
+
+  void *arg;/* Argument to pass to the interrupt handler */
+  xcpt_t isr;   /* ISR Handler */
+};
+
+/
+ * Private Function Prototypes
+ /
+
+static int  sbtn_irq_attach(const struct sbutton_config_s *state, xcpt_t isr,
+void *arg);
+static void sbtn_irq_enable(const struct sbutton_config_s *state,
+bool enable);
+static void sbtn_irq_clear(const struct sbutton_config_s *state);
+
+static bool sbtn_pin_status(void);
+
+/
+ * Private Data
+ /
+
+/* A reference to a structure of this type must be passed to the SButton
+ * driver.  This structure provides information about the configuration
+ * of the SButton and provides some board-specific hooks.
+ *
+ * Memory for this structure is provided by the caller.  It is not copied
+ * by the driver and is presumed to persist while the driver is active.
+ */
+
+static struct stm32_sbtnconfig_s g_sbtnconfig =
+{
+  .config =
+  {
+.attach = sbtn_irq_attach,
+.enable = sbtn_irq_enable,
+.clear  = sbtn_irq_clear,
+.pin_status = sbtn_pin_status,
+  },
+};
+
+/
+ * Private Functions
+ /
+
+/* Attach the SBUTTON interrupt handler to the GPIO interrupt */
+
+static int sbtn_irq_attach(const struct sbutton_config_s *state, xcpt_t isr,
+   void *arg)
+{
+  struct stm32_sbtnconfig_s *priv = (struct stm32_sbtnconfig_s *)state;
+  irqstate_t flags;
+
+  sinfo("sbtn_irq_attach\n");
+
+  flags = enter_critical_section();
+
+  priv->isr = isr;
+  priv->arg = arg;
+
+  stm32_gpiosetevent(BOARD_SBUTTON_GPIO_INT, true, true,
+ true, isr, arg);
+
+  leave_critical_section(flags);
+
+  return OK;
+}
+
+/* Enable or disable the GPIO interrupt */
+
+static void sbtn_irq_enable(const struct sbutton_config_s *state,
+bool enable)
+{
+  struct stm32_sbtnconfig_s *priv = (struct stm32_sbtnconfig_s *)state;
+
+  iinfo("%d\n", enable);
+
+  stm32_gpiosetevent(BOARD_SBUTTON_GPIO_INT, true, true,
+ true, enable ? priv->isr : NULL, priv->arg);
+}
+
+/* Acknowledge/clear any pending GPIO interrupt */
+
+static void sbtn_irq_clear(const struct sbutton_config_s *state)
+{
+  /* FIXME: Nothing to do ? */
+}
+
+/* Read and return the status of button (PRESSED = true; RELEASED = false */
+
+static bool sbtn_pin_status(void)
+{
+  /* STM32F4Discovery button B1 is high 

Re: [PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


acassis commented on PR #16714:
URL: https://github.com/apache/nuttx/pull/16714#issuecomment-3063896890

   @simbit18 what is this build issue on msvc ?


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



[PR] drivers/input: Create Single Button Dual Action [nuttx]

2025-07-11 Thread via GitHub


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

   ## Summary
   
   This commit creates a sbutton device that uses a single button to create a 
keyboard driver that returns TAB or ENTER depending how long the user keeps the 
button pressed.
   
   ## Impact
   
   It will be possible to use a single button like in the STM32F4Discover board 
to navigate on OLED/LCD menu display
   
   ## Testing
   
   STM32F4Discovery
   
   
   


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