我正在尝试实现新的 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))
的等价物是什么