You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Mark Stevens <ma...@thepcsite.co.uk> on 2023/08/29 13:45:02 UTC

GPIO and interrupts

I am trying to figure out GPIO and interrupts.  So the situation is I have four switches connected to GPIOs on my board.  My ideal scenario is to attach a different interrupt to each switch and have that fired when the appropriate button is pressed.

So I have spent some time looking at the gpis_main.c file and I have changed the code that sets the event to:

notify.sigev_notify = SIGEV_THREAD;
notify.sigev_notify_function = sigev_notify_function;


And I am getting the interrupt for one button as expected.  Too many interrupts in fact - I have debounced the input in hardware using a 555 so the signal should be good.

I am struggling to work out how to do this for the remaining buttons without spinning up multiple threads all effectively running the same code but with different devices.

I came across the buttons example but this appears to be disabled for this board.

Any advice would be gratefully received.

Regards,
Mark
_____________________________
Blog: blog.thepcsite.co.uk
Twitter: @nevynuk






Re: GPIO and interrupts

Posted by Petro Karashchenko <pe...@gmail.com>.
Hello Mark,

I think that the best would be to use not GPIO interface, but NuttX buttons
interface. You can try to search for the "btn_lower_initialize" call in the
code tree. I definitely tested that some time ago with same70-qmtech board.

You can also search for the "examples/buttons" application. The difference
in this case would be that you will not need an interrupt handler from a
traditional point of view, but can have a separate thread that will either
wait for a signal or poll on a file descriptor and can
perform button press/release events dispatch when the state of the button
is changed. There is also built-in debounce support
via CONFIG_INPUT_BUTTONS_DEBOUNCE_DELAY, so that might help you as well.

The implementation of buttons interface at board level is pretty trivial I
would say and relies on MCU GPIO interface.

Best regards,
Petro

вт, 29 серп. 2023 р. о 16:45 Mark Stevens <ma...@thepcsite.co.uk> пише:

> I am trying to figure out GPIO and interrupts.  So the situation is I have
> four switches connected to GPIOs on my board.  My ideal scenario is to
> attach a different interrupt to each switch and have that fired when the
> appropriate button is pressed.
>
> So I have spent some time looking at the gpis_main.c file and I have
> changed the code that sets the event to:
>
> notify.sigev_notify = SIGEV_THREAD;
> notify.sigev_notify_function = sigev_notify_function;
>
>
> And I am getting the interrupt for one button as expected.  Too many
> interrupts in fact - I have debounced the input in hardware using a 555 so
> the signal should be good.
>
> I am struggling to work out how to do this for the remaining buttons
> without spinning up multiple threads all effectively running the same code
> but with different devices.
>
> I came across the buttons example but this appears to be disabled for this
> board.
>
> Any advice would be gratefully received.
>
> Regards,
> Mark
> _____________________________
> Blog: blog.thepcsite.co.uk
> Twitter: @nevynuk
>
>
>
>
>
>