从以前已知的 sysfs 接口(interface),任何人都可以设置合理配置的 GPIO 线路的输出,并且该输出将保留该值,直到 SoC 重置或有人更改线路值。 对于 GPIOlib,当消费者关闭 gpiochip 的句柄时,该值将重置为初始值。 假设,GPIO 线控制打开或关闭门的液压系统 - 当应用程序(消费者)因任何原因被终止时,门打开或关闭(可能关闭) - 无论默认线设置是什么。
我做了一些网络搜索并阅读了文档( https://www.kernel.org/doc/html/latest/driver-api/gpio/index.html ),并尝试了 https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/ 提供的示例.
最后 - 结果总是相同的:当进程退出时,该行被重置。 是否有机会保留特定的行值?
最佳答案
来自 gpioset.c 的来源 ( https://github.com/brgl/libgpiod/blob/master/tools/gpioset.c ):
printf("Note: the state of a GPIO line controlled over the character device reverts to default\n");
printf("when the last process referencing the file descriptor representing the device file exits.\n");
printf("This means that it's wrong to run gpioset, have it exit and expect the line to continue\n");
printf("being driven high or low. It may happen if given pin is floating but it must be interpreted\n");
printf("as undefined behavior.\n");
按设计工作...
对我来说,我错过了一个功能,即线路保持(锁定)我设置的状态。 与sysfs的导出机制相比,这绝对是一种退步。
关于c - GPIO 输出状态如何在进程退出时保持不变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58749989/