periph icon indicating copy to clipboard operation
periph copied to clipboard

sysfs-gpio: use new /sys/bus/gpiochipN when available

Open maruel opened this issue 7 years ago • 2 comments

It's the "new" GPIO API for linux kernels above 4.8, based on ioctl on a single handle instead of having to open multiple handles. Now that devices are using later kernels (Raspbian is on 4.14), periph should enable the use of this interface when available, and fallback with the current code on older kernels.

The primary rationale is that it enables pull resistors via the constants GPIOLINE_FLAG_OPEN_DRAIN and GPIOLINE_FLAG_OPEN_SOURCE. It also enables support for reading and writing multiple lines at once. This would have many uses but the periph gpio API currently doesn't make this use-case easy to implement, so multi-pin synchronized I/O requires more thoughts.

Ref:

  • https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/gpio.h includes the definitions
  • https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/gpio/lsgpio.c#n102 is an example.
  • libgpiod at https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/?h=v1.2 is the "official" user space library to wrap the calls, but it's not necessary.

maruel avatar Jan 07 '19 19:01 maruel

@maruel I've made a separate package for GPIO chardev https://github.com/temoto/gpio-cdev-go with the most open license I know, maybe you want to copy it into periph or use in another way. Thanks for periph, it's great.

temoto avatar Jun 24 '19 15:06 temoto

Thanks! I was trying to do an internal refactoring of the way events are managed first but I got side tracked for a few months. 😞

maruel avatar Jun 24 '19 15:06 maruel

Ported to https://github.com/periph/host/issues/39

maruel avatar Sep 20 '23 16:09 maruel