host
host copied to clipboard
sysfs: (fixes #26) Add GPIO support for the Jetson Orin AGX board
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:
- At initialization, store the board name (the contents of
/proc/device-tree/model
). - When you need to generate the
root
directory of a GPIO pin, check the board name: if it's a Jetson Orin AGX, use a giant lookup table to go from pin number to their custom name, and for literally everything else ever, use the standard name like usual.
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.
- 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?
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.
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.
I was wondering, could we have the code look at gpiochipXX symlinks, then look at /base and /label and try to calculate from there?
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 Report
Merging #27 (0716beb) into main (339d73c) will decrease coverage by
0.0%
. The diff coverage is0.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
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!
Closing because no one (including myself) has looked at this for 1.5 years.