11 releases
0.5.4 | May 23, 2024 |
---|---|
0.5.3 | Feb 20, 2024 |
0.5.2 | Aug 11, 2023 |
0.5.1 | Jul 18, 2023 |
0.4.0 | Nov 24, 2022 |
#424 in Unix APIs
699 downloads per month
385KB
8K
SLoC
gpiocdev-cli
A command line tool to access and control GPIO lines on Linux.
This is equivalent to the tools provided by libgpiod, combined into a single tool.
$ gpiocdev -h
A utility to control GPIO lines on Linux using GPIO character devices.
Usage: gpiocdev [OPTIONS] <COMMAND>
Commands:
chip Get information about GPIO chips
edges Monitor GPIO lines for edge events
get Read the levels of GPIO lines
line Get information about GPIO lines (everything but levels)
notify Monitor lines for requests and changes to configuration state
platform Get information about the platform GPIO uAPI support
set Set the levels of GPIO lines
help Print this message or the help of the given subcommand(s)
Options:
-v, --verbose Provide more detailed error messages
-h, --help Print help
-V, --version Print version
Refer to the help for each subcommand for more details.
Example Usage
chip
$ gpiocdev chip
gpiochip0 [pinctrl-bcm2711] (58 lines)
gpiochip1 [raspberrypi-exp-gpio] (8 lines)
line
$ gpiocdev line -c 1
gpiochip1 - 8 lines:
line 0: BT_ON output
line 1: WL_ON output
line 2: PWR_LED_OFF output active-low consumer=led1
line 3: GLOBAL_RESET output
line 4: VDD_SD_IO_SEL output consumer=vdd-sd-io
line 5: CAM_GPIO output consumer=cam1_regulator
line 6: SD_PWR_ON output consumer=sd_vcc_reg
line 7: SD_OC_N input
$ gpiocdev line RXD0 GPIO22 WL_ON
gpiochip0 22 GPIO22 input
gpiochip0 33 RXD0 input
gpiochip1 1 WL_ON output
get
$ gpiocdev get RXD0 GPIO22
RXD0=active GPIO22=inactive
$ gpiocdev get --quoted RXD0 GPIO22
"RXD0"=active "GPIO22"=inactive
$ gpiocdev get --numeric RXD0 GPIO22
1 0
set
$ gpiocdev set GPIO22=active
$ gpiocdev set GPIO17=1
Interactive mode:
$ gpiocdev set -i GPIO23=1 GPIO24=0
gpiocdev-set> get
GPIO23=active GPIO24=inactive
gpiocdev-set> toggle
gpiocdev-set> get
GPIO23=inactive GPIO24=active
gpiocdev-set> toggle GPIO23
gpiocdev-set> get
GPIO23=active GPIO24=active
gpiocdev-set> set GPIO24=0
gpiocdev-set> get
GPIO23=active GPIO24=inactive
gpiocdev-set> exit
edges
$ gpiocdev edges GPIO22
264.429997058 rising GPIO22
270.948800095 falling GPIO22
279.482197087 rising GPIO22
$ gpiocdev edges --localtime GPIO22
2022-10-10T08:01:59.078908766 falling GPIO22
2022-10-10T08:01:59.810733200 rising GPIO22
2022-10-10T08:02:00.497461672 falling GPIO22
notify
$ gpiocdev notify GPIO23
390.467444514 requested GPIO23
390.467655548 released GPIO23
391.701420722 requested GPIO23
391.701624886 released GPIO23
$ gpiocdev notify --localtime GPIO23
2022-10-10T08:03:35.365989261 requested GPIO23
2022-10-10T08:03:35.366200648 released GPIO23
2022-10-10T08:03:35.884780936 requested GPIO23
2022-10-10T08:03:35.884881408 released GPIO23
platform
$ gpiocdev platform
Kernel 5.4.237-yocto-standard
uAPI ABI v1 is supported.
uAPI ABI v2 is not supported by the kernel.
$ gpiocdev platform -v
Kernel 5.15.0-72-generic
Kernel does not support HTE (added in 5.19).
uAPI ABI v1 is supported.
uAPI ABI v2 is supported.
ABI compatibility
The cli supports both GPIO uAPI v1 and v2.
Options that require v2, such as debounce, will fail if applied to a kernel that only supports v1.
Either or both uAPI versions can be supported in the one executable.
By default both are supported, with the most recent ABI supported by the
kernel being used.
The --abi-version
option can be used to force the use of a particular ABI.
libgpiod compatibility
The tools are plug compatible with the libgpiod v2 tools, though unlike those can also work with both GPIO uAPI v1 and v2.
The subcommands map to libgpiod tools as follows:
Subcommand | libgpiod Tool | Alias |
---|---|---|
chip | gpiodetect | detect |
edges | gpiomon | mon |
get | gpioget | - |
line | gpioinfo | info |
notify | gpionotify | - |
platform | - | - |
set | gpioset | - |
The subcommand aliases provide an alternative drawn from the libgpiod tool name, minus the gpio prefix. e.g.
gpiocdev detect
is equivalent to
gpiocdev chip
The libgpiod v1 gpiofind tool is obsoleted by the line subcommand.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~6–18MB
~186K SLoC