static void gpio_write(const char *dev_name, int offset, uint8_t value)
{
struct gpiohandle_request rq;
struct gpiohandle_data data;
int fd, ret;
printf("Write value %d to GPIO at offset %d (OUTPUT mode) on chip %s\n", value, offset, dev_name);
fd = open(dev_name, O_RDONLY);
if (fd < 0)
{
printf("Unabled to open %s: %s", dev_name, strerror(errno));
return;
}
data.values[0] = value;
rq.lineoffsets[0] = offset;
rq.flags = GPIOHANDLE_REQUEST_OUTPUT;
rq.lines = 1;
memcpy(rq.default_values,&data,1);
strcpy(rq.consumer_label,"CCGLED");
ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &rq);
close(fd);
if (ret == -1)
{
printf("Unable to line handle from ioctl : %s", strerror(errno));
return;
}
ret = ioctl(rq.fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
if (ret == -1)
{
printf("Unable to set line value using ioctl : %s", strerror(errno));
}
else
{
usleep(2000000);
}
close(rq.fd);
}
Hi!
Can you give an example of using ioctl to control GPIO on jetpack6, after using the above code to set the IO state, it will not be maintained, and the IO state will return to the default state after the program exits, which is very inconvenient
This is the expected behavior even when using libgpiod.
You need to add some busy waiting/sleep functions to prevent the process from returing immediately.
If the behavior of ioctl() and libgpiod are the same where the effect is gone after the process/function returns, then that means there are some changes in more low-level drivers, and you can only live with it.
Just like the previous Jetpack version was controlled by sysfs, the IO status can be changed at any time, and the set state can be maintained after setting