Issue
I want to write to GPIO 128. Inside linux/gpio.h
there is struct gpiohandle_request
which hold information about a GPIO handle request. I saw this href="https://blog.lxsang.me/post/id/33" rel="nofollow noreferrer">example:
Let say we want to configure pin 17 and 27 as OUTPUT and we want to write HIGH (1) on pin 17 and LOW (0) on pin 27.
struct gpiohandle_request rq;
rq.lineoffsets[0] = 17;
rq.lineoffsets[1] = 27;
rq.lines = 2;
rq.flags = GPIOHANDLE_REQUEST_OUTPUT;
Now I am confused about lineoffsets. Documentation specify that:
- @lineoffsets: an array desired lines, specified by offset index for the associated GPIO device
What does a line mean? If I want to configure gpio0
to gpio127
can I make a loop this way:
for (int i = 0; i < 128; i++) {
rq.lineoffsets[i] = i;
}
Solution
Let say we want to configure pin 17 and 27 as OUTPUT and we want to write HIGH (1) on pin 17 and LOW (0) on pin 27.
Setting that structure does not set any GPIOs levels. When you call ioctl()
it will only set the mode of the appropriate GPIOs.
BTW this structure is depreciated.
What does a line mean
It is hardware dependent and you need to consult your implementation.
If i want to configure gpio0 to gpio127
Check if you have enough GPIOs and if the lineoffsets
field is large enough. Even if you have enough physical GPIOs the control structure does not have to handle them in "one go". The maximum handles number is defined in GPIOHANDLES_MAX
.
Answered By - 0___________ Answer Checked By - David Marino (WPSolving Volunteer)