<?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>need simple devicetree overlay example for gpio</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94963/need-simple-devicetree-overlay-example-for-gpio</link><description>I have this as nrf52840dk_nrf52840.overlay in my application directory: 
 
 / { 
 lightStrings { 
 compatible = &amp;quot;gpio&amp;quot; ; 
 lightString0: lightString_0 { 
 gpios = &amp;lt;&amp;amp; gpio0 29 GPIO_ACTIVE_HIGH &amp;gt;; 
 label = &amp;quot;medusa LED 0&amp;quot; ; 
 }; 
 }; 
 }; 
 
 After I do</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 28 Dec 2022 20:11:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94963/need-simple-devicetree-overlay-example-for-gpio" /><item><title>RE: need simple devicetree overlay example for gpio</title><link>https://devzone.nordicsemi.com/thread/402468?ContentTypeID=1</link><pubDate>Wed, 28 Dec 2022 20:11:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:635fed2f-cebf-4fe1-825b-672a6fb51752</guid><dc:creator>jahess</dc:creator><description>&lt;p&gt;&lt;span&gt;From a comment I made to &lt;/span&gt;&lt;a class="anchor-1MIwyf anchorUnderlineOnHover-2qPutX" title="https://www.youtube.com/watch?v=AMwxj4yUXDQ" href="https://www.youtube.com/watch?v=AMwxj4yUXDQ" rel="noopener noreferrer" target="_blank"&gt;https://www.youtube.com/watch?v=AMwxj4yUXDQ&lt;/a&gt;&lt;span&gt; I learned &amp;quot;the trailing s in latch-en-gpios is required and that the DT... macro support converts any capitals in device tree names to lower case.&amp;quot; The last part means device tree names must be lowercase.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;With that, I was able to use:&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span&gt;GPIO_DT_SPEC_GET&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;DT_PATH&lt;/span&gt;&lt;span&gt;(zephyr_user), lightstring0_gpios)&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;Also note that the note name for zephyr_user in the dts overlay is:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; zephyr,user&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Meaning the , gets converted to _ by the macros.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Kind of strange and hard to find / easy to gloss over&amp;nbsp;zephyr conventions there.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: need simple devicetree overlay example for gpio</title><link>https://devzone.nordicsemi.com/thread/401868?ContentTypeID=1</link><pubDate>Thu, 22 Dec 2022 09:42:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ce86755-3208-4b51-a859-e71bdf34b45f</guid><dc:creator>gianmarcod</dc:creator><description>&lt;p&gt;Hi jahess,&lt;/p&gt;
&lt;p&gt;Try to use the code snippet below inside your &lt;strong&gt;nrf52840dk_nrf52840.overlay&lt;/strong&gt;. It makes use of GPIO P0.28.&lt;/p&gt;
&lt;p&gt;/{&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;&lt;span style="color:#ff0000;"&gt;custom_gpios&lt;/span&gt; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; compatible = &amp;quot;gpio-keys&amp;quot;;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#ff0000;"&gt;cusgpio0&lt;/span&gt;: &lt;span style="color:#ff0000;"&gt;cusgpio_0&lt;/span&gt; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;gpios = &amp;lt;&amp;amp;gpio0 28 GPIO_ACTIVE_HIGH&amp;gt;;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;label = &amp;quot;&lt;span style="color:#ff0000;"&gt;My custom GPIO&lt;/span&gt;&amp;quot;;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; };&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;};&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;aliases {&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;&lt;span style="color:#ff0000;"&gt;mycusgpio&lt;/span&gt; = &amp;amp;&lt;span style="color:#ff0000;"&gt;cusgpio0&lt;/span&gt;;&lt;/p&gt;
&lt;p&gt;};&lt;/p&gt;
&lt;p&gt;Highlighted in red are names which you can change as you prefer. I suggest to leave what remains de-highlighted (in black) as it is. Eventually substitute &amp;amp;gpio0 28 with another pin (i.e. &amp;amp;gpio0 4 or &amp;amp;gpio1 11).&lt;/p&gt;
&lt;p&gt;For what concerns the main program, I am not very keen on DT_SPECS apis. I prefer to enable my gpio pin in the following way:&lt;/p&gt;
&lt;p&gt;#define GPIO028_NODE&amp;nbsp; &amp;nbsp;DT_ALIAS(mycusgpio)&lt;/p&gt;
&lt;p&gt;#define GPIO028&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DT_GPIO_LABEL(GPIO028_NODE, gpios)&lt;/p&gt;
&lt;p&gt;const struct device *dev_gpio0;&lt;/p&gt;
&lt;p&gt;dev_gpio0 = device_get_binding(GPIO028);&lt;/p&gt;
&lt;p&gt;Now you are ready to use GPIO028.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;Note&lt;/span&gt;: I omitted any possible sanity check to make things as simple as possible.&lt;/p&gt;
&lt;p&gt;Hope this can help!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Have a nice day,&lt;/p&gt;
&lt;p&gt;Gianmarco&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>