Skip to content

Implement GpioDriver on Pca95x4 for GpioController access#2581

Draft
raffaeler with Copilot wants to merge 3 commits into
mainfrom
copilot/implement-gpiodriver-for-pca95x4
Draft

Implement GpioDriver on Pca95x4 for GpioController access#2581
raffaeler with Copilot wants to merge 3 commits into
mainfrom
copilot/implement-gpiodriver-for-pca95x4

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Pca95x4 is an 8-bit I2C IO expander that only exposed register-level access, so its pins couldn't be used through the standard GPIO abstraction. This makes Pca95x4 derive from GpioDriver, consistent with the Pcx857x and Tca955x bindings.

Users can now drive the expander pins through a GpioController:

Pca95x4 pca95x4 = new(i2cDevice);
GpioController controller = new(pca95x4);

controller.OpenPin(0, PinMode.Output);
controller.Write(0, PinValue.High);

controller.OpenPin(1, PinMode.Input);
PinValue value = controller.Read(1);

Changes

  • Pca95x4.cs — Derives from GpioDriver; implements the driver members (PinCount, open/close, Set/GetPinMode, IsPinModeSupported, Read, Write) by mapping onto the Configuration/InputPort/OutputPort registers via the existing ReadBit/WriteBit helpers. Event-based members throw NotImplementedException with an explanatory message (mirrors Pcx857x). Disposal is moved into an override of Dispose(bool). The existing register-level public API is unchanged.
  • tests/ — New xUnit project covering pin modes, read/write/toggle through GpioController (backed by an in-memory register mock), and a regression check on the register API.
  • samples/Program.cs — Adds a UseAsGpioController example.
  • README.md — Documents GpioController usage.

Notes

  • VirtualGpioController/VirtualGpioPin remap pins from an existing controller and don't supply the hardware driver, so they aren't a substitute here; they can wrap this driver if pin remapping is wanted.
  • Pin direction follows the datasheet: a set Configuration bit is an input, a cleared bit is an output.

Copilot AI linked an issue Jul 1, 2026 that may be closed by this pull request
@dotnet-policy-service dotnet-policy-service Bot added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Jul 1, 2026
Copilot AI changed the title [WIP] Add GpioDriver implementation for Pca95x4 Implement GpioDriver on Pca95x4 for GpioController access Jul 1, 2026
Copilot AI requested a review from raffaeler July 1, 2026 14:26

@pgrawehr pgrawehr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pca95x4 should implement GpioDriver

3 participants