Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GPIO Control using libgpiod (as sysfsgpio is deprecated) #1569

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

pmelange
Copy link

Description

  • Adds a new protocol ButtonProtocol and the drivers ManualButtonDriver, ExternalButtonDriver, and DigitalOutputButtonDriver to simulate pushing a button (via GPIO lines). This is needed for the tests I will be doing with the logic behind it.
  • Adds new resources LibGPIO / NetworkLibGPIO / MatchedLibGPIO which uses the libgpiod python library. These new resources also support the active_low attribute
  • Adds a new field to the existing SysfsGPIO / NetworkSysfsGPIO / MatchedSysfsGPIO resource classes to support the active_low option of a GPIO line, used to invert the logical value of an IO line.
  • Adds a new LibGPIODigitalOutputDriver which implements the DigitalOutputProtocol, ResetProtocol, PowerProtocol, and the new ButtonProtocol.
  • Adds support to GPIODigitalOutputDriver to support ResetProtocol, PowerProtocol, and the new ButtonProtocol.
  • Adds a new LibGPIOExport class
  • Updates the GPIOSysFSExport to support the active_low attribute
  • Adds support the labgrid-client to support the new NetworkLibGPIO class and support for the Button actions.
  • Marks the Sysfs GPIO classes as deprecated
  • Updates corresponding documentation
  • Updates the examples for sysfsgpio
  • Adds examples for libgpio.

As far as new features go...

ButtonProtocol is to be used in my test environment to control pressing the reset button of DUTs. For many of the DUTs, pressing the reset button when powering on provides (via uboot) a TFTP client or server or simply access to a web socket to be able to upload a new firmware image. A logical button is better for the test environment I am creating since it encapsulates the high/low logic levels of IO ports into something logical.

LibGPIO classes are added to get away from the deprecated sysfsgpio subsystem (see https://www.kernel.org/doc/Documentation/gpio/sysfs.txt).

Extending the GPIO based drivers (both libgpio and sysfs) to the Reset, Power, and Button protocols was very straight forward and I did wonder why the Reset and Power protocols had not jet been implemented. They seem like logical extensions to general purpose IO lines.

Adding the active_low attribute was necessary because the IO lines used in the testbed are connected to relays which are active_low.


All development and testing was done on a raspberry pi 4 with opto-coupler relays connected to the GPIO lines to control power and reset buttons.


Checklist

  • Documentation for the feature
  • Tests for the feature can be found in the examples/sysfsgpio and examples/libgpio directories
  • The arguments and description in doc/configuration.rst have been updated
  • PR has been tested by pulling high and low IO lines using various calls from the DigitalOutput, Reset, Power and Button protocols, both using the exporter/client and as a standalone python script.

A button can be used to simulate pressing a physical button on a device. For
example a DigitalOutputButtonDriver can be used when a reset button is
connected via a relay to a DigitalOutput.  In addition there are the
ManualButtonDriver and ExternalButtonDriver drivers analogous to the
ManualPowerDriver and ExternalPowerDriver drivers.

Operations on a button include "press", "release", "toggle", "toggle_for",
and "get".

Signed-off-by: Perry Melange <[email protected]>
Add the LibGPIO, NetworkLibGPIO and MatchedLibGPIO resources.  These
resouces bind to the /dev/gpiochipN and it's associated gpio line.  In
addition there is an optional active_low attribute which can be used to
invert the logical value used on the gpio line.

The resources SysfsGPIO, NetworkSysfsGPIO and MatchedSysfsGPIO resources
have been modified to have an additional optional active_low attribute
which can be used to invert the logical value used on the gpio line.

The SysfsGPIO, NetworkSysfsGPIO and MatchedSysfsGPIO resouces are now marked
as deprecated.  See https://www.kernel.org/doc/Documentation/gpio/sysfs.txt

Signed-off-by: Perry Melange <[email protected]>
Add the LibGPIODigitalOutputDriver which implements the DigitalOutputProtocol,
ResetProtocol, PowerProtocol, and ButtonProtocol.

Update the GPIODigitalOutputDriver to also implement the ResetProtocol,
PowerProtocol, and ButtonProtocol.

Update the GpioDigitalOutput agent to use the new active_low attribute

Mark GPIODigitalOutputDriver and GpioDigitalOutput as deprecated.  See
https://www.kernel.org/doc/Documentation/gpio/sysfs.txt

Signed-off-by: Perry Melange <[email protected]>
Add the LibGPIOExport class to the exporter.

Update the GPIOSysFSExport class to use the new active_low attribute

Signed-off-by: Perry Melange <[email protected]>
…otocol

Add NetworkLibGPIO to the client, including commands for io, power, and
button protocols.

Update NetworkLibGPIO to support the commands for power and button protocols.

Signed-off-by: Perry Melange <[email protected]>
…Drivers

Add documentation for LibGPIO, MatchedLibGPIO, ManualButtonDriver,
ExternalButtonDriver, DigitalOutputButtonDriver, and LibGPIODigitalOutputDriver.

Update the SysfsGPIO, MatchedSysfsGPIO, and GpioDigitalOutputDriver to
add the new active_low attribute and the new protocols supported by the
GpioDigitalOutputDriver.  In addition, add documentation that the SysfsGpio
classes are deprecated.

Signed-off-by: Perry Melange <[email protected]>
@pmelange
Copy link
Author

Rebased so that the commits are no longer behind the main branch :)

ManualButtonDriver
~~~~~~~~~~~~~~~~~~
A :any:`ManualButtonDriver` requires the user to control the taget button.
Theis is required if a stratefy is used with the target, but no automatic
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Theis is required if a stratefy is used with the target, but no automatic
This is required if a strategy is used with the target, but no automatic

cmd_toggle_for: 'example_command toggle_for'

Arguments:
- cmd_press (str): command to press the button on the board
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- cmd_press (str): command to press the button on the board
- cmd_press (str): command to press and hold the button on the board

I suggest clarifying that this means the button must be released.

Arguments:
- cmd_press (str): command to press the button on the board
- cmd_release (str): command to release the button on the board
- cmd_toogle (str): command to toggle the button on the board
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- cmd_toogle (str): command to toggle the button on the board
- cmd_toogle (str): command to press and release the button on the board

@step()
def press(self):
self.target.interact(
f"Press the button on target {self.target.name} and press enter"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
f"Press the button on target {self.target.name} and press enter"
f"Press and hold the button on target {self.target.name} and press enter"

@step()
def toggle(self):
self.target.interact(
f"Toggle the bottuon on the target {self.target.name} and press enter"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
f"Toggle the bottuon on the target {self.target.name} and press enter"
f"Toggle the button on the target {self.target.name} and press enter"

- cmd_press (str): command to press the button on the board
- cmd_release (str): command to release the button on the board
- cmd_toogle (str): command to toggle the button on the board
- cmd_toggle_for (str): options command to toggle, pause, and toggle again
Copy link
Contributor

Choose a reason for hiding this comment

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

The current description reads to me as button down, immediately button up, wait, then button down, immediately button up. Is that correct?

Or did you mean button down, wait, button up? If so, would press_and_hold_for be a better name?

Copy link
Author

Choose a reason for hiding this comment

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

I must admit that it really isn't clear.

Actually, the toggle methods don't really apply to a button. Maybe it would be better to add a new method to DigitialOutputProtocol called "invert". An "invert_for" method is probably not necessary.

About the button methods, I think of press as "press and hold". I can understand how people would think that pressing a button is press then release as one movement. I, on the other hand, think of buttons as being pressed and then released as two movements.. I would like to have it as clear as possible. I am open to suggestions.

Currently my thoughts go more towards "press" for press and hold, "release" to release, and "press_for" as press, wait a delay, and release. I would like to keep the names of the commands short for labgrid-client.

Thanks for catching the spelling errors. :)

I might have time this evening to make the changes, otherwise they will be made tomorrow.

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