<?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>How to define a direct GPIO IRQ in zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103674/how-to-define-a-direct-gpio-irq-in-zephyr</link><description>Hi, 
 I am developing a PS/2 bitbanging driver for zephyr. The PS/2 device (a mouse in my use case) is connected to the mcu using two GPIO pins 
 I got it working using the zephyr GPIO API interrupts, but frequently the interrupts are missed or not delivered</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 12 Sep 2023 21:21:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103674/how-to-define-a-direct-gpio-irq-in-zephyr" /><item><title>RE: How to define a direct GPIO IRQ in zephyr</title><link>https://devzone.nordicsemi.com/thread/445708?ContentTypeID=1</link><pubDate>Tue, 12 Sep 2023 21:21:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:720cef08-3c0a-4376-ad1d-3c9f9adb75fb</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Kimcha,&lt;/p&gt;
[quote user=""]&lt;p&gt;But I can’t find documentation to figure what the parameters for&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/apidoc/latest/group__isr__apis.html#gac6c8746ac28da6ce02b24714f4144ff3"&gt;IRQ_DIRECT_CONNECT&lt;/a&gt;&amp;nbsp;should be for a specific pin &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can&amp;nbsp;someone link me to some sample code or documentation perhaps?&lt;/p&gt;[/quote]
&lt;p&gt;You cannot use IRQ_DIRECT_CONNECT because &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.3.99-ncs1/drivers/gpio/gpio_nrfx.c#L378-L379"&gt;the Zephyr GPIO API already connected&lt;/a&gt; a different &lt;a href="https://github.com/zephyrproject-rtos/hal_nordic/blob/nrfx-3.0.0/nrfx/drivers/src/nrfx_gpiote.c#L1088"&gt;interrupt handler&lt;/a&gt; to the GPIOTE IRQ.&lt;/p&gt;
[quote user=""]&lt;p&gt;To clarify, my question is: Is it possible to set up a two direct interrupt for two pins even though zephyr is already using the zephyr GPIO API for interrupts on other pins. &lt;/p&gt;
&lt;p&gt;If it’s possible, then how?&lt;/p&gt;[/quote]
&lt;p&gt;Yes~ish. You&amp;nbsp;might&amp;nbsp;theoretically be able to use &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/index.html"&gt;the nrfx GPIOTE driver API&lt;/a&gt; together with the Zephyr GPIO API.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t recommend this very much. A driver can be&amp;nbsp;&lt;em&gt;stateful&lt;/em&gt;. As far as I can see, the nrfx driver is stateful, but only for the purpose of GPIOTE channel use tracking. Since &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.3.99-ncs1/drivers/gpio/gpio_nrfx.c"&gt;the Zephyr GPIO API is actually implemented with nrfx GPIOTE driver API under the hood, they can work together&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Having said all that, please still &lt;em&gt;be very careful about doing it&lt;/em&gt;. Please take some time to analyze the Zephyr GPIO API implementation and understand its use of the nrfx driver.&lt;/p&gt;
&lt;p&gt;The nrfx GPIOTE driver is documented here:&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.2/nrfx/drivers/gpiote/index.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.2/nrfx/drivers/gpiote/index.html&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There is a sample of nrfx GPIOTE driver usage here:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/v3.3.99-ncs1/samples/boards/nrf/nrfx"&gt;sdk-zephyr/samples/boards/nrf/nrfx at v3.3.99-ncs1 · nrfconnect/sdk-zephyr (github.com)&lt;/a&gt;.&lt;br /&gt;One thing to notice is that in the sample, &lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/boards/nrf/nrfx/src/main.c#L40-L42"&gt;the IRQ handler has to be connected&amp;nbsp;in the application&lt;/a&gt;. However, as stated earlier above, when you also use the Zephyr GPIO API, the IRQ handler is already connected.&lt;/p&gt;
&lt;p&gt;You will also find the HAL API. I recommend against using it&amp;nbsp;at the same time as either of the drivers above. That is because the HAL API interacts with the hardware directly and without regard of the state of the nrfx driver.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;
&lt;p&gt;P.s: Please also note that the above information is applicable only for the GPIO/GPIOTE peripheral.&amp;nbsp;It is likely different for other peripherals, depends on how the APIs are implemented.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>