Skip to content

Conversation

@thatcomputerguy0101
Copy link
Contributor

@thatcomputerguy0101 thatcomputerguy0101 commented Nov 1, 2025

Description

The old GPIO abstraction was replaced with diozero, which supports most hardware running Linux due to its use of GPIO character devices provided by the Linux kernel. diozero also supports alternate providers if for some reason the character device API is insufficient. Certain capabilities outside of the character device API is also implemented for common hardware.

Custom GPIO commands are implemented via a custom diozero provider. The configuration for custom GPIO will need manually updated according to the Hardware Config documentation page.

This was tested on a RPi 5 with LL3 illumination LEDs and an RGB status led attached. All capabilities worked as expected. All 8 status LED colors were tested and functional via modifying the code. Basic functionality of custom GPIO was tested with dummy commands.

closes #2062

Meta

Merge checklist:

  • Pull Request title is short, imperative summary of proposed changes
  • The description documents the what and why
  • If this PR changes behavior or adds a feature, user documentation is updated
  • If this PR touches photon-serde, all messages have been regenerated and hashes have not changed unexpectedly
  • If this PR touches configuration, this is backwards compatible with settings back to v2025.3.2
  • If this PR touches pipeline settings or anything related to data exchange, the frontend typing is updated
  • If this PR addresses a bug, a regression test for it is added

@thatcomputerguy0101 thatcomputerguy0101 requested a review from a team as a code owner November 1, 2025 01:42
@github-actions github-actions bot added the backend Things relating to photon-core and photon-server label Nov 1, 2025
@thatcomputerguy0101 thatcomputerguy0101 marked this pull request as draft November 1, 2025 01:43
@samfreund
Copy link
Member

Looks like tests need to be fixed.

@samfreund
Copy link
Member

Also seems like you grabbed some commits off a different branch when you created this one. You can fix that using interactive rebase.

@github-actions github-actions bot added the documentation Anything relating to https://docs.photonvision.org label Nov 1, 2025
Copy link
Collaborator

@Gold856 Gold856 left a comment

Choose a reason for hiding this comment

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

Looks pretty good at first glance. The big question I have is boards that support setting LEDs via a command of some sort, but not via diozero. If we do want to support LEDs on that kind of board, we still need CustomGPIO (I think). If not, we should clean up our config to not have those command fields.

@thatcomputerguy0101
Copy link
Contributor Author

I am currently planning to leave custom GPIO commands unimplemented, since diozero should work for the vast majority of boards with built-in GPIO. An advanced user could inject an alternate provider invisible to the rest of PhotonVision if for some reason the built-in provider does not work. The diozero.devicefactory system property could be set from a Photon setting, which will try and load the specified class dynamically, but a user capable of adding another provider is likely also capable of modifying the service file that launches Photon to specify it there.

The commit history and unit tests will be fixed before the draft status of this PR is removed.

@thatcomputerguy0101
Copy link
Contributor Author

I am revisiting custom GPIO before unmarking this as a draft. I have some new ideas on how to make that happen.

@samfreund
Copy link
Member

Can we make a PR to https://github.com/PhotonVision/photon-image-modifier as well to remove the installation of pigpio which is no longer needed?

@thatcomputerguy0101
Copy link
Contributor Author

Can we make a PR to https://github.com/PhotonVision/photon-image-modifier as well to remove the installation of pigpio which is no longer needed?

This was on my plans.

@thatcomputerguy0101
Copy link
Contributor Author

thatcomputerguy0101 commented Nov 9, 2025

I elected to break compatibility with the older GPIO commands due to differences in behavior for the new GPIO commands. Specifically, the presence of new GPIO command dictates if they are enabled, instead of the platform. Also, setPWMCommand now takes a decimal between 0.0 and 1.0, instead of an integer percentage.

}

private int doProcess(boolean wait, Process process) {
private synchronized int doProcess(boolean wait, Process process) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this necessary? If so, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this, I would occasionally get an IllegalThreadStateException from the gobblers since they were overwritten by another thread and were already started. I know the default implementation of blink in diozero uses threads, and I believe threads are also used in the default shutdown process. An alternative to synchronizing this method would to be to remove all of its dependencies on class variables, which would break some of the other methods here.

@Override
public void setMode(DeviceMode mode) {
if (mode == DeviceMode.DIGITAL_INPUT) {
getValue();
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does getting the value do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assumed the getGPIO and setGPIO to also set the data direction of the request pin to input or output, respectively. This is also why I cache the output value instead of getting it.

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

Labels

backend Things relating to photon-core and photon-server documentation Anything relating to https://docs.photonvision.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drop GPIO support

3 participants