1

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 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;
}
0andriy
  • 4,183
  • 1
  • 24
  • 37
void_brain
  • 642
  • 2
  • 13
  • 1
    First of all, read this https://stackoverflow.com/a/55579640/2511795 for understanding offsets. Second, why not using the `libgpiod` and its APIs? – 0andriy May 22 '23 at 20:04
  • Thank you for your reply @0andriy. I am aware of the existence of libgpiod. I have already use it for some testing. I think it will be easier if I use libgpiod indeed. – void_brain May 23 '23 at 08:29
  • For my 128 gpio, I wanted to use `int gpiod_chip_get_all_lines(struct gpiod_chip *chip, struct gpiod_line_bulk *bulk);` However I noticed that there is `#define GPIOD_LINE_BULK_MAX_LINES 64`. What will be the behaviour then ? Is there a way to handle 128 gpio in one go ? @0andriy – void_brain May 23 '23 at 09:16
  • No, but you may always discuss this with Kent and Bart in the linux-gpio@ mailing list. – 0andriy May 23 '23 at 16:52

1 Answers1

1

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.

0andriy
  • 4,183
  • 1
  • 24
  • 37
0___________
  • 60,014
  • 4
  • 34
  • 74