periph / host

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

sysfs: (fixes #26) Add GPIO support for the Jetson Orin AGX board #27

Open penguinland opened 1 year ago

penguinland commented 1 year ago

This is a fix for https://github.com/periph/host/issues/26. It's ugly, and I kinda suspect I should have put the data elsewhere, but it works. I'm totally open to suggestions of moving things elsewhere, though!

I am relatively new to both Go and sysfs. I've probably written something unidiomatic, and would be happy to change whatever it is.

The implementation:

Tried on a Jetson Orin AGX on my desk: I'm able to turn the GPIO pins on and off! I have not tried it on other devices, but I believe this repo has a CI system that will test it on various other hardware, and no changes on other hardware are intended.

  1. Once integrated, send a PR to https://github.com/periph/cmd to leverage the new functionality (if relevant).

I don't know if that's relevant or what would go in the PR. Any advice?

google-cla[bot] commented 1 year ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] commented 1 year ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

maruel commented 1 year ago

I was wondering, could we have the code look at gpiochipXX symlinks, then look at /base and /label and try to calculate from there?

maruel commented 1 year ago

https://www.kernel.org/doc/html/latest/driver-api/gpio/index.html?highlight=names#c.gpio_chip tells me names is probably filled up with the right data.

codecov-commenter commented 1 year ago

Codecov Report

Merging #27 (0716beb) into main (339d73c) will decrease coverage by 0.0%. The diff coverage is 0.0%.

@@           Coverage Diff           @@
##            main     #27     +/-   ##
=======================================
- Coverage   34.3%   34.3%   -0.0%     
=======================================
  Files         51      51             
  Lines       7992    8002     +10     
=======================================
  Hits        2744    2744             
- Misses      5117    5127     +10     
  Partials     131     131             
Impacted Files Coverage Δ
sysfs/gpio.go 53.6% <0.0%> (-1.8%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

penguinland commented 1 year ago

You might be right that there's a way to find the right names even for dynamically renumbered pins by examining that data structure. but I feel out of my depth (where would I even get that data structure from?), and don't have the time right now to research this further. I've gotten far enough that my main work is no longer blocked, so I'm going to go back to that instead. You're welcome to modify this PR further to support those extra cases (or close the PR, or something else).

Thank you for the advice and feedback you've provided!