Skip to content

Add multi-GPIO group support - #256

Merged
fhunleth merged 1 commit into
mainfrom
multi-gpio-2
Jul 12, 2026
Merged

fhunleth merged 1 commit into
mainfrom
multi-gpio-2

Conversation

@fhunleth

Copy link
Copy Markdown
Member

This updates Circuits.GPIO.open/3 to support being passed a list of
GPIOs. These GPIOs are then read or written together. GPIO values are
numbers where the least significant bit is the first GPIO, then the next
one, etc. This improves performance and removes inter-GPIO delays. All
lines in a group must be on the same controller.

@fhunleth
fhunleth force-pushed the multi-gpio-2 branch 2 times, most recently from 3cf8107 to fe8e960 Compare July 11, 2026 22:29
@fhunleth
fhunleth requested a review from Copilot July 11, 2026 22:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds multi-GPIO “group” support to Circuits.GPIO.open/3, allowing callers to open a list of GPIO specs as a single handle that reads/writes an aggregate integer bitmap (LSB = first GPIO), improving throughput and reducing inter-GPIO delays.

Changes:

  • Extend the Elixir API and backend contract to accept lists of GPIO specs and treat them as a single grouped handle.
  • Update the NIF + cdev/stub HAL implementations to request/read/write multiple lines together and emit group-aware notifications (with value/previous_value bitmaps).
  • Add/expand tests and documentation (README + Livebooks) to cover group semantics and diagnostics.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/test_helper.exs Adjust ExUnit ANSI/color configuration to support diagnostics output testing.
test/gpio/diagnostics_test.exs Add coverage for multi-pair and multi-GPIO diagnostics report/run behavior.
test/circuits_gpio_test.exs Add integration tests for grouped open/read/write semantics and group subscriptions.
REUSE.toml Add REUSE licensing annotation for the new Livebook.
README.md Clarify set_interrupts/3 limitations with GPIO groups and recommend subscribe/2.
notebooks/rotary_encoder.livemd Add a new Livebook demonstrating rotary encoder reading using multi-GPIO groups.
notebooks/basics.livemd Update documentation about the richer subscribe notification payload.
mix.lock Bump makeup dependency version.
lib/gpio/handle.ex Document that group reads/writes use one-bit-per-line integer values.
lib/gpio/diagnostics.ex Extend diagnostics to accept multiple GPIO pairs and add multi-GPIO group diagnostics.
lib/gpio/cdev.ex Resolve grouped GPIO specs to a single controller + offsets list for cdev v2 requests.
lib/gpio/backend.ex Update backend callback contract/docs to support opening groups.
lib/gpio.ex Add group API/docs, widen value type, and clarify group notification behavior.
c_src/hal_stub.c Update stub HAL to track grouped lines and emit group-aware notifications.
c_src/hal_cdev_gpio.c Update cdev HAL to request/read/write multiple lines using gpio-cdev v2 ioctls.
c_src/hal_cdev_gpio_interrupts.c Update interrupt polling to maintain group shadow state and emit grouped notifications.
c_src/gpio_nif.h Expand gpio_pin representation to support up to 64 lines and group shadow state.
c_src/gpio_nif.c Update NIF open/read/write/subscribe plumbing for group locations and values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread c_src/gpio_nif.c
Comment thread lib/gpio.ex Outdated
Comment thread lib/gpio.ex
Comment thread notebooks/rotary_encoder.livemd
Comment thread notebooks/rotary_encoder.livemd Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

lib/gpio.ex:496

  • Typo in the docs: "can be come" is ungrammatical; it should be "can come".
  an OS monotonic timestamp in nanoseconds, and `value` is the new value.

  Timestamps are not necessarily the same as from `System.monotonic_time/0`.
  For example, with the cdev backend, they're applied by the Linux kernel or
  can be come from a hardware timer. Erlang's monotonic time is adjusted so

Comment thread c_src/gpio_nif.c
Comment thread lib/gpio.ex
This updates `Circuits.GPIO.open/3` to support being passed a list of
GPIOs. These GPIOs are then read or written together. GPIO values are
numbers where the least significant bit is the first GPIO, then the next
one, etc. This improves performance and removes inter-GPIO delays. All
lines in a group must be on the same controller.
@fhunleth
fhunleth merged commit 62ccd35 into main Jul 12, 2026
9 checks passed
@fhunleth
fhunleth deleted the multi-gpio-2 branch July 12, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants