Linux GPIO V2 请求线 ioctl 失败

问题描述 投票:0回答:1

我正在尝试实现新的 linux gpio api。使用 v1 api,我能够确认此代码是否有效:

// req is part of larger code
struct gpiohandle_request lreq;
memset(lreq.default_values, 0, sizeof(lreq.default_values));
strcpy(lreq.consumer_label, "TESTIO");
lreq.lines = req.bank_count[bank];
lreq.flags = GPIOHANDLE_REQUEST_OUTPUT;

for (int line = 0; line < lreq.lines; line++)
  lreq.lineoffsets[line] = req.pins[bank][line];

if (ioctl(bank_fd[bank], GPIO_GET_LINEHANDLE_IOCTL, &lreq) < 0) {
  std::cerr << "Error on chip io\n";
  return -1;
}

但是,当我尝试切换到 v2 时:

struct gpio_v2_line_request lreq;
lreq.config.flags = GPIO_V2_LINE_FLAG_OUTPUT;
lreq.config.num_attrs = 0;
strcpy(lreq.consumer, "TESTIO");
lreq.num_lines = req.bank_count[bank];

for (int line = 0; line < lreq.num_lines; line++) {
  lreq.offsets[line] = req.pins[bank][line];
}

if (ioctl(bank_fd[bank], GPIO_V2_GET_LINE_IOCTL, &lreq) < 0) {
  std::cerr << "Error on chip io\n";
  return -1;
}

我的 ioctl 总是失败,并显示

errno
22

我不确定

memset(lreq.default_values, 0, sizeof(lreq.default_values))
的等价物是什么

c linux embedded-linux gpio
1个回答
0
投票

解决方案是先简单地执行此操作:

memset(&lreq, 0, sizeof(lreq));

我猜这相当于默认值。在libgpiod的master分支中找到这里

© www.soinside.com 2019 - 2024. All rights reserved.