b5g-ex / nerves_system_stm32mp157c_odyssey

Apache License 2.0
7 stars 0 forks source link

Can't read input until after the output has been configured once when using circuits_gpio #3

Closed pojiro closed 2 years ago

pojiro commented 2 years ago

In below code, GPIO pin 26 is D18 of Grove Base Hat for Raspberry Pi.

iex(1)>  {:ok, gpio} = Circuits.GPIO.open(26, :input)  
{:ok, #Reference<0.1962860034.377356295.248080>}
iex(2)> Circuits.GPIO.read(gpio)
0 # button is not pushed
iex(3)> Circuits.GPIO.read(gpio)
0 # button is pushed, but can't read its value
iex(4)>  {:ok, gpio} = Circuits.GPIO.open(26, :output)      # once configure with output
{:ok, #Reference<0.1962860034.377356295.248081>}
iex(5)>  {:ok, gpio} = Circuits.GPIO.open(26, :input)       # make it back to input
{:ok, #Reference<0.1962860034.377356295.248082>}
iex(6)> Circuits.GPIO.read(gpio)
0 # button is not pushed
iex(7)> Circuits.GPIO.read(gpio)
1 # button is pushed, now can read its value

This doesn't happen with debian which boots with same kernel and same dtb.

debian@arm:~$ gpioget gpiochip1 10
0
debian@arm:~$ gpioget gpiochip1 10
1

So, this might be a contribution chance to circuits_gpio.

pojiro commented 2 years ago

I confirmed below, also works

iex(3)> cmd "echo 26 > /sys/class/gpio/export"
0
iex(4)> cmd "echo in > /sys/class/gpio/gpio26/direction"
0
iex(5)> cmd "cat /sys/class/gpio/gpio26/value"
0
0
iex(6)> cmd "cat /sys/class/gpio/gpio26/value"
1
0
pojiro commented 2 years ago

Once a version containing https://github.com/elixir-circuits/circuits_gpio/pull/119 is released, this issue is fixed.

pojiro commented 2 years ago

https://github.com/elixir-circuits/circuits_gpio/releases/tag/v1.0.1, includes above fix, is released. Now we can close this, yey!

takasehideki commented 2 years ago

what a fantastic contribution!!