Skip to content

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

Open

Description

@tal-zvon

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?

Activity

  1. changed the title [-]Does Line.request()[/-] [+]Does Line.request() matter for Input lines?[/+] on Feb 25, 2021
  2. changed the title [-]Does Line.request() matter for Input lines?[/-] [+]Does Line.request()'s default arg matter for Input lines?[/+] on Feb 25, 2021
  3. JonathonReinhart commented on Dec 18, 2023

    @JonathonReinhart

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions