(I'm directly using the new V2 system calls rather than libgpiod which uses the deprecated V1 calls).
I have got the device fd by using the ioctl GPIO_V2_GET_LINE_IOCTL and have defined a GPIO line to be an output line in the req.config struct.
As soon as I call the ioctl GPIO_V2_LINE_SET_CONFIG_IOCTL the output line's output goes to zero - I would like it to retain its previous value of 1.
I can immediately follow the set config call with a GPIO_V2_LINE_SET_VALUES_IOCTL ioctl call to explicitly set the value but that seems lame, and will, I assume, cause a short blip on the line.
Is there a way to configure a GPIO output without the line state changing (I am committed to the chardev GPIO model)?
I suppose I could do the hacky thing of configuring the output drive to be open-source with a bias pull-up but that's incredibly ugly and may not be electrically safe depending on what the GPIO is driving (I'm not going to do it).
The comments (mine in particular) did not help. Here is what I have figured out, and what has worked for me.
The problem arises due to confusion about how gpio line output values are set. There are 2 distinct mechanisms, used in 2 different situations, and (IMHO) the documentation is far from clear.
To set an output value at configuration time (ie when configuring the line to be an output), you must use request->config.attrs (request is a gpio_v2_line_request struct pointer). Something like this:
Then you can use the GPIO_V2_LINE_SET_CONFIG_IOCTL ioctl call to send your configuration to the gpio lines.
Once the line has been configured, its output values are changed using a gpio_v2_line_values struct. Like this:
Use the GPIO_V2_LINE_SET_VALUES_IOCTL ioctl call to set the output lines from your values struct.