-
Notifications
You must be signed in to change notification settings - Fork 183
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
base: master
Are you sure you want to change the base?
Conversation
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]>
Signed-off-by: Perry Melange <[email protected]>
Signed-off-by: Perry Melange <[email protected]>
db29152
to
d114043
Compare
Rebased so that the commits are no longer behind the main branch :) |
Signed-off-by: Perry Melange <[email protected]>
e6486a4
to
4003d51
Compare
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Description
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