Page MenuHomeFreeBSD

gpioctl add -N to operate on pin name instead of pin number
ClosedPublic

Authored by manu_bidouilliste.com on Feb 5 2016, 10:18 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, May 3, 5:25 AM
Unknown Object (File)
Fri, May 3, 5:25 AM
Unknown Object (File)
Fri, May 3, 5:25 AM
Unknown Object (File)
Fri, May 3, 5:25 AM
Unknown Object (File)
Fri, May 3, 5:25 AM
Unknown Object (File)
Fri, May 3, 5:25 AM
Unknown Object (File)
Thu, May 2, 11:24 PM
Unknown Object (File)
Wed, Apr 24, 5:32 AM

Details

Summary

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.

Test Plan

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 Not Applicable
Unit
Tests Not Applicable

Event Timeline

manu_bidouilliste.com retitled this revision from to gpioctl add -N to operate on pin name instead of pin number.
manu_bidouilliste.com updated this object.
manu_bidouilliste.com edited the test plan for this revision. (Show Details)
manu_bidouilliste.com set the repository for this revision to rS FreeBSD src repository - subversion.

The man page .Dd needs to be updated as well.

usr.sbin/gpioctl/gpioctl.8
44 ↗(On Diff #13054)

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@

In D5201#111038, @gonzo wrote:

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.

manu_bidouilliste.com edited edge metadata.

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.

manu_bidouilliste.com edited edge metadata.

Fix if condition for str2int.

usr.sbin/gpioctl/gpioctl.c
111 ↗(On Diff #13125)

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.

manu_bidouilliste.com edited edge metadata.

Restore back str2int function.

This revision was automatically updated to reflect the committed changes.