Add input path for sysfs GPIOs#1935
Conversation
|
Why are you taking authorship for most commits instead of working on top of @flxzt commits? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1935 +/- ##
========================================
+ Coverage 61.0% 61.3% +0.3%
========================================
Files 182 183 +1
Lines 14881 14919 +38
========================================
+ Hits 9083 9155 +72
+ Misses 5798 5764 -34
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
Hi @Emantor, There was only one original commit containing all the changes. I built on top of it, added my own changes, and reworked parts of the implementation. I included a I’m happy to update the commit metadata accordingly. Let me know which format you prefer. |
| try: | ||
| drv = target.get_driver("DigitalOutputProtocol", name=name) | ||
| if action == "get": | ||
| drv = target.get_driver("DigitalInputProtocol", name=name) |
There was a problem hiding this comment.
I believe this implementation in the client has the same issue as I had when I attempted to implement this.
Have you checked whether #1458 (comment) also happens for you?
There was a problem hiding this comment.
Yes, tested on a Raspberry Pi 2 Model B running Raspbian with kernel 6.12.47+rpt-rpi-v7.
I tested whether labgrid-client io get changes the sysfs direction from out to in after setting the line high:
$labgrid-client -p rpi-gpio io high
cat /sys/class/gpio/gpio529/direction
out
cat /sys/class/gpio/gpio529/value
1
$labgrid-client -p rpi-gpio io get
digital IO for place rpi-gpio is high
cat /sys/class/gpio/gpio529/direction
out
cat /sys/class/gpio/gpio529/value
1So I could not reproduce the behavior from the linked comment with this branch. After io get, the line remains configured as out and the value remains high.
This should be because the resource-only NetworkSysfsGPIO fallback still uses GpioDigitalOutputDriver for labgrid-client io get. The new DigitalInputProtocol path is only used when an input driver is explicitly configured.
|
I would appreciate if attribution is kept in some way. |
I usually retain the original authorship in the commit and add my |
|
|
Add a dedicated DigitalInputProtocol for drivers which can read a digital signal without also exposing writes. Keep DigitalOutputProtocol as a specialization of the input protocol, matching existing output drivers which already implement get(). Co-developed-by: Felix Zwettler <Felix.Zwettler@duagon.com> Signed-off-by: Felix Zwettler <Felix.Zwettler@duagon.com> Signed-off-by: Ozan Durgut <ozan.durgut@analog.com>
Add GpioDigitalInputDriver for sysfs GPIO resources. Extend the sysfsgpio agent to configure lines for input reads while keeping output as the default path for existing users. Reconfigure cached GPIO lines before reuse so switching between input and output access leaves the sysfs direction in the state requested by the active driver. Co-developed-by: Felix Zwettler <Felix.Zwettler@duagon.com> Signed-off-by: Felix Zwettler <Felix.Zwettler@duagon.com> Signed-off-by: Ozan Durgut <ozan.durgut@analog.com>
Resolve labgrid-client io get via DigitalInputProtocol when a matching driver is configured. This allows input-only drivers to use the existing io command. Keep the existing NetworkSysfsGPIO fallback on GpioDigitalOutputDriver so resource-only configurations continue to behave as before. Co-developed-by: Felix Zwettler <Felix.Zwettler@duagon.com> Signed-off-by: Felix Zwettler <Felix.Zwettler@duagon.com> Signed-off-by: Ozan Durgut <ozan.durgut@analog.com>
Document GpioDigitalInputDriver and add coverage for sysfsgpio input direction handling, cached direction reconfiguration, input driver reads, protocol compatibility, and labgrid-client io get routing. Co-developed-by: Felix Zwettler <Felix.Zwettler@duagon.com> Signed-off-by: Felix Zwettler <Felix.Zwettler@duagon.com> Signed-off-by: Ozan Durgut <ozan.durgut@analog.com>
d117758 to
3f87f22
Compare
This is a follow-up to the GPIO input work discussed in #1458. Instead of adding a separate input-only sysfs agent, this PR keeps the existing
sysfsgpioagent and extends it so a GPIO line can be configured either as output or input by the active driver.The change adds:
DigitalInputProtocol, for drivers which can read a digital signal withoutnecessarily supporting writes.
GpioDigitalInputDriver, binding toSysfsGPIO,MatchedSysfsGPIO, andNetworkSysfsGPIO.labgrid-client io get <name>support for explicitly configuredDigitalInputProtocoldrivers.default behavior for existing users.
DigitalOutputProtocolnow derives fromDigitalInputProtocol, matching the existing behavior of digital output drivers which already implementget(). This keeps existing output users compatible while allowing input-only drivers to use the same CLI command for reads.The client-side behavior is intentionally conservative:
io getfirst looks for a configuredDigitalInputProtocoldriver. If no such driver exists, the existing resource-only fallback still creates aGpioDigitalOutputDriverforNetworkSysfsGPIO, so existing configurations continue to work as before.The sysfs agent caches GPIO line objects, so this PR also makes cached lines reconfigure their direction before reuse. This avoids stale direction state if the same GPIO line is accessed through different configured drivers during a test setup.
The implementation still uses the existing sysfs GPIO backend. Moving this to the newer gpiochip/libgpiod interface would be useful, since sysfs GPIO is deprecated, but that is intentionally left as future work to keep this PR small and focused.
Checklist
cc @Emantor @flxzt