<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Zephyr basic button - how to modify to use multi button input</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89391/zephyr-basic-button---how-to-modify-to-use-multi-button-input</link><description>I am using the example zephyr basic button which gives output when the button is pressed. 
 
 https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/samples/basic/button/README.html 
 
 How can I modify it in my application where there are</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 01 Jul 2022 07:48:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89391/zephyr-basic-button---how-to-modify-to-use-multi-button-input" /><item><title>RE: Zephyr basic button - how to modify to use multi button input</title><link>https://devzone.nordicsemi.com/thread/375016?ContentTypeID=1</link><pubDate>Fri, 01 Jul 2022 07:48:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ce5f8bf-f59c-47d7-9c15-a63838aac26b</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi Salman,&lt;/p&gt;
&lt;p&gt;We do not have support for debounce in the GPIO API. In the nRF5 SDK we had the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_button.html?cp=8_1_3_7"&gt;button handling library&lt;/a&gt;. In the nRF Connect SDK, there is a &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/nrf_desktop/doc/buttons.html#nrf-desktop-buttons"&gt;buttons module&lt;/a&gt; but I am not sure if this helps.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Priyanka&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr basic button - how to modify to use multi button input</title><link>https://devzone.nordicsemi.com/thread/374357?ContentTypeID=1</link><pubDate>Mon, 27 Jun 2022 13:44:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7195c814-aeec-4b87-a43f-f797c30231be</guid><dc:creator>Salman</dc:creator><description>&lt;p&gt;I am able to do that this way. Is there any efficient way of doing that? How can I add debounce in it?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2016 Open-RnD Sp. z o.o.
 * Copyright (c) 2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;
#include &amp;lt;sys/util.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;inttypes.h&amp;gt;

#define SLEEP_TIME_MS	1

/*
 * Get button configuration from the devicetree sw0 alias. This is mandatory.
 */
#define SW1_NODE	DT_ALIAS(sw1)
#define SW0_NODE	DT_ALIAS(sw0)
#if !DT_NODE_HAS_STATUS(SW0_NODE, okay)
#error &amp;quot;Unsupported board: sw0 devicetree alias is not defined&amp;quot;
#endif

static const struct gpio_dt_spec button_1 = GPIO_DT_SPEC_GET_OR(SW1_NODE, gpios,
							      {0});

static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,
							      {0});

static struct gpio_callback button_cb_data;
static struct gpio_callback button_cb_data1;

/*
 * The led0 devicetree alias is optional. If present, we&amp;#39;ll use it
 * to turn on the LED whenever the button is pressed.
 */
static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,
						     {0});

void button_pressed(const struct device *dev, struct gpio_callback *cb,
		    uint32_t pins)
{
	printk(&amp;quot;Button pressed at %&amp;quot; PRIu32 &amp;quot;\n&amp;quot;, k_cycle_get_32());
}

void button_pressed_1(const struct device *dev, struct gpio_callback *cb,
		    uint32_t pins)
{
	printk(&amp;quot;Button pressed at %&amp;quot; PRIu32 &amp;quot;\n&amp;quot;, k_cycle_get_32());
}

void main(void)
{
	int ret;

	if (!device_is_ready(button_1.port)) {
		printk(&amp;quot;Error: button_1 device %s is not ready\n&amp;quot;,
		       button_1.port-&amp;gt;name);
		return;
	}

	if (!device_is_ready(button.port)) {
		printk(&amp;quot;Error: button device %s is not ready\n&amp;quot;,
		       button.port-&amp;gt;name);
		return;
	}

	ret = gpio_pin_configure_dt(&amp;amp;button, GPIO_INPUT);
	if (ret != 0) {
		printk(&amp;quot;Error %d: failed to configure %s pin %d\n&amp;quot;,
		       ret, button.port-&amp;gt;name, button.pin);
		return;
	}

	ret = gpio_pin_configure_dt(&amp;amp;button_1, GPIO_INPUT);
	if (ret != 0) {
		printk(&amp;quot;Error %d: failed to configure %s pin %d\n&amp;quot;,
		       ret, button_1.port-&amp;gt;name, button_1.pin);
		return;
	}

	ret = gpio_pin_interrupt_configure_dt(&amp;amp;button_1,GPIO_INT_EDGE_TO_ACTIVE);
	if (ret != 0) {
		printk(&amp;quot;Error %d: failed to configure interrupt on %s pin %d\n&amp;quot;,
			ret, button_1.port-&amp;gt;name, button_1.pin);
		return;
	}

	ret = gpio_pin_interrupt_configure_dt(&amp;amp;button,GPIO_INT_EDGE_TO_ACTIVE);
	if (ret != 0) {
		printk(&amp;quot;Error %d: failed to configure interrupt on %s pin %d\n&amp;quot;,
			ret, button.port-&amp;gt;name, button.pin);
		return;
	}

	gpio_init_callback(&amp;amp;button_cb_data, button_pressed, BIT(button.pin));
	gpio_add_callback(button.port, &amp;amp;button_cb_data);
	printk(&amp;quot;Set up button at %s pin %d\n&amp;quot;, button.port-&amp;gt;name, button.pin);

	gpio_init_callback(&amp;amp;button_cb_data1, button_pressed_1, BIT(button_1.pin));
	gpio_add_callback(button_1.port, &amp;amp;button_cb_data1);
	printk(&amp;quot;Set up button_1 at %s pin %d\n&amp;quot;, button_1.port-&amp;gt;name, button_1.pin);



	if (led.port &amp;amp;&amp;amp; !device_is_ready(led.port)) {
		printk(&amp;quot;Error %d: LED device %s is not ready; ignoring it\n&amp;quot;,ret, led.port-&amp;gt;name);
		led.port = NULL;
	}
	if (led.port) {
		ret = gpio_pin_configure_dt(&amp;amp;led, GPIO_OUTPUT);
		if (ret != 0) {
			printk(&amp;quot;Error %d: failed to configure LED device %s pin %d\n&amp;quot;,ret, led.port-&amp;gt;name, led.pin);
			led.port = NULL;
		} else {
			printk(&amp;quot;Set up LED at %s pin %d\n&amp;quot;, led.port-&amp;gt;name, led.pin);
		}
	}

	printk(&amp;quot;Press the button\n&amp;quot;);
	if (led.port) {
		while (1) {
			/* If we have an LED, match its state to the button&amp;#39;s. */
			int val = gpio_pin_get_dt(&amp;amp;button);

			if (val &amp;gt;= 0) {
				gpio_pin_set_dt(&amp;amp;led, val);
			}
			k_msleep(SLEEP_TIME_MS);
		}
	}
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>