Quantcast
Viewing all articles
Browse latest Browse all 4398

Interfacing (DSI, CSI, I2C, etc.) • Re: how to stop driving a gpio (pinctrl?)

I need to be able to release a GPIO and let it be tristate, and also to be able to first write a GPIO and then wait for it to be externally pulled. Is this done with pinctrl?
So basically you want the GPIO to be set as Input with no pulls, that's easy with pinctrl.

But pinctrl can't afaik monitor the pin and wait for a state change for you, so you'' have to get the pin state from pinctrl and check it yourself.

Code:

pinctrl set 9 ip pnoldstate="$(pinctrl get 9 | sed "s/^.*| \(..\) .*$/\1/")" # Returns "hi" or "lo"while [ "$oldstate" = "$(pinctrl get 9 | sed "s/^.*| \(..\) .*$/\1/")" ]do  sleep 0.1doneecho "Pin has changed state"
That's just an example. It could do with a bit of tidying up and maybe make a getpin(gpio) function to save having to type the pinctl blah line all over the place.

Of course there are are other ways to do it.

Statistics: Posted by rpdom — Sat Jun 29, 2024 10:09 am



Viewing all articles
Browse latest Browse all 4398

Trending Articles