by pohl7452 » Tue Jun 09, 2020 12:04 pm
Hi,
I have investigated this issue a bit more.
$this->bbcode_second_pass_code('', '
$ sudo gpiomon /dev/gpiochip1 113
gpiomon: error waiting for events: No such device
')
Documentation and examples of the new libgpiod library are still a bit sparse. In case somebody is interested in a working example for interrupt driven event polling:
$this->bbcode_second_pass_code('', '
#include <gpiod.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char *argv[])
{
int offset = 0;
if (argc != 3) {
fprintf(stderr, "usage: %s <controler> <offset>\n", argv[0]);
exit(EXIT_FAILURE);
}
if (sscanf(argv[2], "%d", &offset) != 1) {
fprintf(stderr, "invalid offset: %s\n", argv[2]);
exit(EXIT_FAILURE);
}
int ret = 0;
struct timespec ts = {0, 1000000};
struct gpiod_line_event event;
struct gpiod_chip *chip;
struct gpiod_line *line;
chip = gpiod_chip_open(argv[1]);
if (!chip) {
fprintf(stderr, "GPIO chip %s not found.\n", argv[1]);
exit(EXIT_FAILURE);
}
line = gpiod_chip_get_line(chip, offset);
if (!line) {
gpiod_chip_close(chip);
fprintf(stderr, "GPIO line %d could not be opened.\n", offset);
exit(EXIT_FAILURE);
}
ret = gpiod_line_request_both_edges_events(line, "event_test");
if (ret < 0) {
gpiod_chip_close(chip);
perror("Request events failed");
exit(EXIT_FAILURE);
}
for (;;) {
do {
ret = gpiod_line_event_wait(line, &ts);
} while (ret <= 0);
ret = gpiod_line_event_read(line, &event);
if (!ret) {
fprintf(stdout, "[%ld.%09ld] %s\n",
event.ts.tv_sec, event.ts.tv_nsec,
(event.event_type == GPIOD_CTXLESS_EVENT_RISING_EDGE) ? "rising" :
(event.event_type == GPIOD_CTXLESS_EVENT_FALLING_EDGE) ? "falling" : "??");
}
}
return EXIT_SUCCESS;
}
')
The program works as expected on a poor old Raspberry Pi B+ with Arch Linux ARM, but fails with the same "No such device" error on the Odroid C2.
$this->bbcode_second_pass_code('', '
$ gcc -o gpio_test gpio_test.c -lgpiod
$ sudo ./gpio_test /dev/gpiochip1 113
Request events failed: No such device
')
And running through strace:
$this->bbcode_second_pass_code('', '
# strace -Z ./gpio_test /dev/gpiochip1 113
ioctl(3, GPIO_GET_LINEEVENT_IOCTL, 0xfffff2b0f0f8) = -1 ENODEV (No such device)
Request events failed: No such device
')
Any ideas why the gpiochip device cannot be found?
Would this be working on the new Odroid C4?
Thanks for any help or comments.