host icon indicating copy to clipboard operation
host copied to clipboard

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

Open penguinland opened this issue 2 years ago • 6 comments

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.

  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?

penguinland avatar Jan 09 '23 22:01 penguinland

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] avatar Jan 09 '23 22:01 google-cla[bot]

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] avatar Jan 09 '23 22:01 google-cla[bot]

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 avatar Jan 10 '23 20:01 maruel

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.

maruel avatar Jan 10 '23 20:01 maruel

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

codecov-commenter avatar Jan 10 '23 21:01 codecov-commenter

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!

penguinland avatar Jan 10 '23 21:01 penguinland

Closing because no one (including myself) has looked at this for 1.5 years.

penguinland avatar Jul 29 '24 19:07 penguinland