libgpiod v2: new major release with a ton of new features
Bartosz Golaszewski, a seasoned developer with 14 years of experience, has unveiled a new major release of libgpiod v2 packed with exciting features. The updated version includes significant improvements in GPIO control, user-space capabilities, API design, and enhancements in the GPIO character device. The release emphasizes the importance of thoughtful API design and considerations for user expertise and programming language familiarity. With new functionalities introduced in libgpiod v2, users can expect an enriched experience in managing GPIOs in the Linux environment.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
Bartosz Golaszewski libgpiod v2: new major release with a ton of new features
About 14 years of experience Kernel and user-space developer Author & maintainer of libgpiod and the GPIO kernel framework Contributor to various Yocto layers Maintainer of Zephyr LVGL stack
Recap Users really want user-space control for GPIOs Linux GPIO subsystem exposes a per-chip character device as /dev/gpiochipX Meant to replace sysfs (/sys/class/gpio) Lots of ioctl()s and data structures libgpiod wraps that functionality libgpiod exposes a C library, C++ and Python bindings and command-line tools
Recap User programs Shell scripts C++ bindings Python bindings gpio-tools libgpiod project libgpiod (core) User space GPIO character device Kernel space GPIO subsystem (gpiolib) GPIO driver A GPIO driver B GPIO driver C
API design is hard Plan to throw one away You don t know what you don t know Do you assume the interface will actually be used by other people? Can you put yourself in other people s shoes? Are your users experts? Do you know your programming languages well?
GPIO cdev v2 Character device v1 was not designed to be extended Users came up with valid reasons for extending v1 anyway
GPIO cdev v2 Debounce period setting from user-space needed for proper edge event detection Sequence numbers for edge events Setting bias Changing the kernel clock used for timestamping Watching changes in line status Getting the PID of the consumer
libgpiod v2 status libgpiod v2 is not out yet :( The API is complete and functional however not yet in master API not likely to change much anymore Some gpio-tools and Python changes upcoming Don t want to commit to a date :(
libgpiod v2 goals Make usage more intuitive Make it more difficult to commit programming errors Allow very concise code when using high- level bindings Don t try to needlessly represent the kernel model exactly
Kernel object model Line 0 Line 1 Request for exclusive usage Line 2 Line 2 Line 3 Provider Consumer Line 4 Request for exclusive usage Line 5 Line 5 Line 6 Line 7
Object model overhaul v1 v2 Immutable snapshots Line 0 get_line() Chip Info get_info() Chip Line bulk Chip Line 1 get_line_bulk() Line Info get_line_info() Line 2
Object model overhaul v1 v2 Can be reused for reconfiguring requested lines Single config structure, need to jump through hoops when reconfiguring lines Used once at request time request_config line_config request_config
Object model overhaul v1 v2 Edge Event Buffer Request read_edge_event() Line 0 line_event_read() Line bulk get_event() Line 1 Additional mechanism for avoiding unnecessary memory allocations line_event_read_bulk() Line 2 Edge Event
New features line_info watch_line_info() Chip Info_event read_info_event() line_info
New features request_lines Line Info Used: False Line Info Used: True Chip watch_line_info read_info_event
New features Edge_event_buffer read_edge_event() edge_event0 Request edge_event1 edge_event2 get_edge_event() edge_event0 copy &edge_event0 edge_event_copy()
New features Line Settings Direction: INPUT Edge: BOTH Bias: PULL_UP Event clock: REALTIME
New features Line Config Offsets: 3, 5 Line Settings A Offsets: 1 Line Settings B Offsets: 7, 4, 2 Line Settings C
New features Request Edge event 0 Edge event 1 Edge event 2 Edge event 3 Offset: 0 Line seqno: 1 Global seqno: 1 Offset: 0 Line seqno: 2 Global seqno: 2 Offset: 3 Line seqno: 1 Global seqno: 3 Offset: 0 Line seqno: 3 Global seqno: 4
New features New test harness based on gpio-sim gpio-sim is a replacement for gpio-mockup Doesn t require module reloading Much more flexible configuration
New features Sysfs Configfs New GPIO device Enable chip New simulated GPIO device pops up! New GPIO bank
New features All C objects are opaque All C++ classes have their implementation hidden (PImpl) Python interface strives to be more Pythonic than v1 Rust bindings coming up
New features gpio-tools are getting a rework New program: gpiowatch Interactive mode for gpioset Specifiying lines by name # gpioset /dev/gpiochip1 GPIO_0=active PHY_RST=inactive
New features All that to make it simple for high-level language: auto request = ::gpiod::chip( /dev/gpiochip0 ) .prepare_request() .set_consumer( foobar ) .add_line_settings( { 3, 4, 8 }, ::gpiod::line_settings() .set_direction(direction::INPUT) .set_edge_detection(edge::BOTH) ) .do_request()
New features request = gpiod.request_lines( chip= /dev/gpiochip0 , lines=["GPIO_0", "GPIO_3", 5], edge_detection=gpiod.Line.Edge.BOTH, event_clock=gpiod.Line.Clock.REALTIME ) for event in request.read_edge_events(): print(event)
Links & Resources https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/ See tools, tests and binding examples for code samples Branch next/libgpiod-2.0 contains current v2 API Development happens on the linux-gpio mailing list Please do help us review v2 before we carve it in stone. Special thanks to Kent Gibson for his hard work on the character device code and reviewing libgpiod patches