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

Does Line.request()'s default arg matter for Input lines? #49

Open
tal-zvon opened this issue Feb 25, 2021 · 1 comment
Open

Does Line.request()'s default arg matter for Input lines? #49

tal-zvon opened this issue Feb 25, 2021 · 1 comment

Comments

@tal-zvon
Copy link

tal-zvon commented Feb 25, 2021

Does it matter what we set this arg for an input line? If not, can we get a short note in the docs that it doesn't matter. Maybe have it be an Option<u8> that can be set to None?

@tal-zvon tal-zvon changed the title Does Line.request() Does Line.request() matter for Input lines? Feb 25, 2021
@tal-zvon tal-zvon changed the title Does Line.request() matter for Input lines? Does Line.request()'s default arg matter for Input lines? Feb 25, 2021
@JonathonReinhart
Copy link

Does it matter what we set this arg for an input line?

Nope. I was in the neighborhood and tracked this down.

In the uAPI, default_values is documented:

 * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is set for a requested
 * line, this specifies the default output value, should be 0 (low) or
 * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high)

So it only applies for REQUEST_OUTPUT.

This is confirmed by looking in the kernel:

		if (lflags & GPIOHANDLE_REQUEST_OUTPUT) {
			int val = !!handlereq.default_values[i];

			ret = gpiod_direction_output(desc, val);
			if (ret)
				goto out_free_lh;
		} else if (lflags & GPIOHANDLE_REQUEST_INPUT) {
			ret = gpiod_direction_input(desc);
			if (ret)
				goto out_free_lh;
		}

You can see that for REQUEST_OUTPUT, the value from default_values[i] (which is the default arg in Rust code) is passed to gpiod_direction_output() to actually set the mode to output and the default state.

For REQUEST_INPUT however, default_values[i] is not used. (It's not used anywhere else in that function.)

I think a short note in the doc to say it only applies for outputs would make sense. Changing it to Option<u8> would just add unnecessary complexity, IMO.

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

2 participants