libgpiod v2: new major release with a ton of new features

Slide Note
Embed
Share

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.


Uploaded on Apr 02, 2024 | 3 Views


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


  1. Bartosz Golaszewski libgpiod v2: new major release with a ton of new features

  2. 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

  3. Recap

  4. 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

  5. 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

  6. API design is hard

  7. 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?

  8. GPIO character device v2

  9. GPIO cdev v2 Character device v1 was not designed to be extended Users came up with valid reasons for extending v1 anyway

  10. 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

  11. Disclaimer

  12. 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 :(

  13. libgpiod v2

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. New features line_info watch_line_info() Chip Info_event read_info_event() line_info

  20. New features request_lines Line Info Used: False Line Info Used: True Chip watch_line_info read_info_event

  21. 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()

  22. New features Line Settings Direction: INPUT Edge: BOTH Bias: PULL_UP Event clock: REALTIME

  23. New features Line Config Offsets: 3, 5 Line Settings A Offsets: 1 Line Settings B Offsets: 7, 4, 2 Line Settings C

  24. 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

  25. 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

  26. New features Sysfs Configfs New GPIO device Enable chip New simulated GPIO device pops up! New GPIO bank

  27. 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

  28. 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

  29. 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()

  30. 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)

  31. 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

  32. Q & A

More Related Content