<?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>NRF52840 dongle 10 button USB HID with zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102614/nrf52840-dongle-10-button-usb-hid-with-zephyr</link><description>Goodday 
 
 I thought this could be good learning curve to get started with Zephyr. Im having some problems with the GPIO. If I rewrite this code for 3 buttons with PORT1 (pin 1.10 pin 1.13 and pin 1.15) the code works. But it does not work on PORT 0</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 22 Aug 2023 06:17:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102614/nrf52840-dongle-10-button-usb-hid-with-zephyr" /><item><title>RE: NRF52840 dongle 10 button USB HID with zephyr</title><link>https://devzone.nordicsemi.com/thread/442419?ContentTypeID=1</link><pubDate>Tue, 22 Aug 2023 06:17:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f7feaed-9dc8-443d-a487-20aa5f9ed107</guid><dc:creator>melt</dc:creator><description>&lt;p&gt;Thank you Jared, very helpfull&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 dongle 10 button USB HID with zephyr</title><link>https://devzone.nordicsemi.com/thread/442238?ContentTypeID=1</link><pubDate>Mon, 21 Aug 2023 09:09:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5bb81e0-4223-4388-9256-f3f59f792618</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;That looks correct, did you do a pristine build?&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re using nRF Connect SDK VS Code extension, then there is a DTS GUI that will make it easier for you to map out the pins and replace and delete properties. Maybe you could try and see if that helps?&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 dongle 10 button USB HID with zephyr</title><link>https://devzone.nordicsemi.com/thread/441053?ContentTypeID=1</link><pubDate>Sun, 13 Aug 2023 08:46:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e3b2a9d-6397-4e4d-a9f9-8a289fcd98e7</guid><dc:creator>melt</dc:creator><description>&lt;p&gt;Thanks Jared.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have done an overlay file as per below. I see&amp;nbsp;in the overlay file some of my pins say &amp;quot;&amp;amp;GPIO already assigned to 2 other nodes&amp;quot;&amp;nbsp; I dont think im removing SPI,I2C and UART nodes correctl&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// To get started, press Ctrl+Space to bring up the completion menu and view the available nodes.

// You can also use the buttons in the sidebar to perform actions on nodes.
// Actions currently available include:

// * Enabling / disabling the node
// * Adding the bus to a bus
// * Removing the node
// * Connecting ADC channels

// For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html
// You can also visit the nRF DeviceTree extension documentation at https://nrfconnect.github.io/vscode-nrf-connect/devicetree/nrfdevicetree.html

/{leds {

		compatible = &amp;quot;gpio-leds&amp;quot;;
		led0_green: led_0 {
			gpios = &amp;lt;&amp;amp;gpio0 6 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Green LED 0&amp;quot;;
		};
		led1_red: led_1 {
			gpios = &amp;lt;&amp;amp;gpio0 8 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Red LED 1&amp;quot;;
		};
		led1_green: led_2 {
			gpios = &amp;lt;&amp;amp;gpio1 9 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Green LED 1&amp;quot;;
		};
		led1_blue: led_3 {
			gpios = &amp;lt;&amp;amp;gpio0 12 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Blue LED 1&amp;quot;;
		};
	};
};

/{
    buttons {
    compatible = &amp;quot;gpio-keys&amp;quot;;
    button0: button_0 {
		gpios = &amp;lt;&amp;amp;gpio1 6 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)&amp;gt;;
		label = &amp;quot;Push button switch 0&amp;quot;;
		};
    compatible = &amp;quot;gpio-keys&amp;quot;;
    button1: button_1 {
        gpios = &amp;lt;&amp;amp;gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)&amp;gt;;
        label = &amp;quot;Push button switch 1&amp;quot;;
    };
    compatible = &amp;quot;gpio-keys&amp;quot;;
    button2: button_2 {
        gpios = &amp;lt;&amp;amp;gpio0 15 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)&amp;gt;;
        label = &amp;quot;Push button switch 2&amp;quot;;
    };
    compatible = &amp;quot;gpio-keys&amp;quot;;
    button3: button_3 {
        gpios = &amp;lt;&amp;amp;gpio0 17 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)&amp;gt;;
        label = &amp;quot;Push button switch 3&amp;quot;;
    };
    compatible = &amp;quot;gpio-keys&amp;quot;;
    button4: button_4 {
        gpios = &amp;lt;&amp;amp;gpio0 20 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)&amp;gt;;
        label = &amp;quot;Push button switch 4&amp;quot;;
    };
};
};


/* These aliases are provided for compatibility with samples */
/{		aliases {
        sw0 = &amp;amp;button0;
        sw1 = &amp;amp;button1;
        sw2 = &amp;amp;button2;
        sw3 = &amp;amp;button3;
        sw4 = &amp;amp;button4;
	
        led0 = &amp;amp;led0_green;
		led1 = &amp;amp;led1_red;
		led2 = &amp;amp;led1_green;
		led3 = &amp;amp;led1_blue;
		led0-green = &amp;amp;led0_green;
		led1-red   = &amp;amp;led1_red;
		led1-green = &amp;amp;led1_green;
		led1-blue  = &amp;amp;led1_blue;

	};
};


&amp;amp;uart0 {
   
    /delete-property/ some-unwanted-property;
};

&amp;amp;i2c0 {
    /delete-property/ some-unwanted-property;

};

&amp;amp;i2c1 {
    /delete-property/ some-unwanted-property;

};

&amp;amp;pwm0 {
    /delete-property/ some-unwanted-property;

};


&amp;amp;spi0 {
    /delete-property/ some-unwanted-property;

};

&amp;amp;spi1 {
    /delete-property/ some-unwanted-property;

};

&amp;amp;uart0 {
   /delete-property/ some-unwanted-property;
};

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 dongle 10 button USB HID with zephyr</title><link>https://devzone.nordicsemi.com/thread/440486?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2023 12:00:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c59a73bf-f2b1-465b-a756-e2d4d4853fed</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Ideally, using PORT 0 shouldn&amp;#39;t be much difference than using PORT 1. Contrary to nRF5SDK, In zephyr we have something that we call the device tree that is used to describe the HW that the application will run on. Additional GPIOs that you&amp;#39;re going to use should be added in an overlay which will map the pins in the device tree.&amp;nbsp; For example, here is an example on how to set interrupt on button1 (port 0, pin11)&amp;nbsp; on the nRF52840 DK so that LED1 will flash every time it&amp;#39;s pressed:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   1000

/* The devicetree node identifier for the &amp;quot;led0&amp;quot; alias. */
#define LED0_NODE DT_ALIAS(led0)
#define BUTTON0_NODE DT_ALIAS(sw0)

/*
 * A build error on this line means your board is unsupported.
 * See the sample documentation for information on how to fix this.
 */
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET(BUTTON0_NODE, gpios);


void button_cb_handler(const struct device *dev, struct gpio_callback *cb, gpio_port_pins_t pins)
{
		int ret = gpio_pin_toggle_dt(&amp;amp;led);
		if (ret &amp;lt; 0) {
		}
}


int main(void)
{
	int ret;

	if (!gpio_is_ready_dt(&amp;amp;led)) {
		return 0;
	}

	if (!gpio_is_ready_dt(&amp;amp;button))
	{
		return 0;
	}




	ret = gpio_pin_configure_dt(&amp;amp;led, GPIO_OUTPUT_ACTIVE);
	if (ret &amp;lt; 0) {
		return 0;
	}
	ret = gpio_pin_configure_dt(&amp;amp;button, GPIO_INPUT);
	if (ret &amp;lt; 0) {
		return 0;
	}


	gpio_pin_interrupt_configure_dt(&amp;amp;button,GPIO_INT_EDGE_TO_ACTIVE);


	static struct gpio_callback pin_cb_data;
	gpio_init_callback(&amp;amp;pin_cb_data, button_cb_handler, BIT(button.pin));
	gpio_add_callback(button.port,&amp;amp;pin_cb_data);

	while (1) {
		k_msleep(SLEEP_TIME_MS);
	}
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can try to build this project with your dongle, and first add 1 or 2 gpios with an overlay, and repeat the steps that I did for the button for the additional gpios that you&amp;#39;ve added. Then eventually you can try to expand it to 10 buttons,&lt;/p&gt;
&lt;p&gt;I also strongly suggest to go through our &lt;a href="https://www.nordicsemi.com/Support/Nordic-Developer-Academy"&gt;DevAcademy&lt;/a&gt;, the first lessons are very relevant for your question &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;,&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 dongle 10 button USB HID with zephyr</title><link>https://devzone.nordicsemi.com/thread/440083?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2023 10:52:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:074469ba-f7dd-400a-821b-b88bcd917c09</guid><dc:creator>melt</dc:creator><description>&lt;p&gt;HI Jared&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If I only declare 3 pins namely 10,13,15 the switches do work, but only port 1. One of my questions was how do I&amp;nbsp;select&amp;nbsp;PORT 0 so I can test the pins currently defined in the code. Ideally, I would like to make the entire PORT 0, GPIO inputs for buttons.&lt;/p&gt;
&lt;p&gt;You&amp;#39;re right some of the GPIOs are declared in the DTS that&amp;#39;s why I asked if I need to reconfigure it somehow.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for the help&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 dongle 10 button USB HID with zephyr</title><link>https://devzone.nordicsemi.com/thread/440075?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2023 10:02:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df4a6f84-d07a-4038-a277-d588492e42ae</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Have you connected a debugger and checked if the program asserts or enters the callback handler?&lt;/p&gt;
[quote user=""] If I rewrite this code for&amp;nbsp; 3 buttons with&amp;nbsp; PORT1 (pin 1.10 pin 1.13 and pin 1.14) the code works. But it does not work on PORT 0 with 10 buttons.[/quote]
&lt;p&gt;But does it work with 3 buttons on PORT 0 or even 1?&lt;/p&gt;
&lt;p&gt;Also some of the GPIOs that you&amp;#39;re trying to use are already in use in the Dongle &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/main/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840-pinctrl.dtsi"&gt;dts&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>