periph / host

Go·Hardware·Lean - Host drivers
https://periph.io
Apache License 2.0
57 stars 32 forks source link

sysfs: GPIO unexport at exit #29

Open sausagenoods opened 1 year ago

sausagenoods commented 1 year ago

Describe the bug I need to manually "unexport" pins after using this library. Let's say I've used pin 17 with the debounce example code. I'm unable to use the same pin again (using another library) without rebooting the Pi or running a command like this:

$ sudo bash -c "for ((i=0; i<32; i++)); do echo \$i >/sys/class/gpio/unexport; done"

Otherwise the other library fails with: RequestLine returned error: device or resource busy. And no I'm not running both programs at the same time. Apologies if this is normal, I don't know much about GPIO. To Reproduce Steps to reproduce the behavior:

  1. Run the debounce example code.
  2. Run the input pin watcher example from the other library.
  3. 2nd step fails with the RequestLine error I mentioned above and I'm unable to reuse the same pin unless I manually unexport it.

Expected behavior Be able to reuse the same pin. I think it would be nice to have a function that unexports and people would defer that.

Platform (please complete the following information):

maruel commented 1 year ago

We would need a new shutdown function exported from either sysfs or as a generic form in periph.