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

Allow reading current output value if set by another application. #43

Closed
arre525 opened this issue May 16, 2019 · 1 comment
Closed

Comments

@arre525
Copy link

arre525 commented May 16, 2019

I am moving from using sysfs to libgpiod, and so far it works pretty nicely.
But, one thing I cannot seem to do, is to read the current state of a gpio pin if it is in output-direction and set in another context.

For example: Other program sets pin to output, and to value 1.
In my program, I just want to see what value the pin is at, WITHOUT changing the direction to input (since this would change the behaivour of the pin).

In sysfs, this was easily done by just polling the value (and as long as you did not write to anything, you did not change anything.). But if I try to do this with libgpio, it returns an error if I don’t first change direction to input.

After some quick correspondance with Bartosz it seems this is currently not possible, but future plans are there for a single daemon that can be interfaced with.

Still, if it can be fixed in the library alone, it would avoid more userspace applications that are required (and have something as lightweight as sysfs (where you basically only need the kernel and no libraries).

Keeping this issue open here for other ppl to track as well:)

@arre525
Copy link
Author

arre525 commented May 16, 2019

Apparently, the library already supports this.

I found this by looking at some kernel source: (https://elixir.bootlin.com/linux/v5.1.2/source/drivers/gpio/gpiolib.c).
Turns out you can request a gpio line in "AS-IS" mode. You can already do this in the library by something like:

config.consumer = "test"; config.request_type = GPIOD_LINE_REQUEST_DIRECTION_AS_IS; gpiod_line_request(line,&config,0);

Ideally, we should have a "simple" call for this as well, just like gpiod_line_request_output exists.

So never mind, it works already:)

@arre525 arre525 closed this as completed May 16, 2019
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

No branches or pull requests

1 participant