This adds -N option to gpioctl.
When using -N you specify the pin name (set by gpioctl -n) instead of the pin number.
This give a better flexibility when a script is intended to bu used on different boards if you correctly sets the name on the gpio that you use.
Details
- Reviewers
- None
- Group Reviewers
manpages - Commits
- rS296682: Make it possible for operations to refer to GPIO pins by name
Apply patch.
Add a name on a gpio : gpioctl -n 12 test
Configure pin by name : gpioctl -cN test OUT
Toggle pin by name : gpioctl -tN test
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Passed - Unit
No Test Coverage - Build Status
Buildable 2396 Build 2412: arc lint + arc unit
Event Timeline
The man page .Dd needs to be updated as well.
usr.sbin/gpioctl/gpioctl.8 | ||
---|---|---|
44 | This syntax with the angle brackets is basically unused in other FreeBSD man pages. It is much more common to just use the pipe character as a separator with not grouping mark. |
I like the idea but I think -N switch is excessive. Just treat "pin" as pinspec: if it's valid number (i.e. str2num call was successful) - it's pinnum, if not - pinname. Just like ports and /etc/services. This is IMHO and I'd like to get second opinion from imp@ or loos@
It was my first idea but what if a user name the pin #12 to "15" for example, on what pin should "gpioctl 15" should operate ?
Should we allow such name or if a user does this it is his problem ?
I'd have -p -> a number always. -N -> a name always. Nothing would be ambiguous. I'd document that it will interpret it as a number if its a number, even if there's a pin name that matches. Sadly -n is already taken for other functionality. So -N 12 would be an error unless there's a pin named literally "12". And a bare "12" would be pin #12 always, even if ping 17 had the name "12". Highly desirable here would be to detect the ambiguity and force -N or -p to resolve it. Sadly, this may break some scripts, but they are easy enough to fix.
And I'd document this ambiguity in the man page.
Update diff to reflect imp@ suggestion.
By default pin arg to gpioctl can be a pin number or a name and gpioctl auto-detects it.
If a number is supplied and a pin have this number at its name, gpioctl exits and tell the user to use one of the following option:
-p force pin to be interpreted as a number
-N force pin to be interpreted as a name
Reflect the change in the manpage too.
usr.sbin/gpioctl/gpioctl.c | ||
---|---|---|
107 | With this call signature str2int("-1") will be considered failure although it's a valid call. At the moment there are no such use cases in gpioctl code but it's better to avoid this kind of ambiguity at expense of a little bit more inconvenient calling code. Please keep older version of this function. |