0

我在两个不同的应用程序中尝试了 gpiod_line_request_rising_edge_events() 和 gpiod_line_request_input() 调用相同的 gpio 线,但它返回 -1。

我使用了下面的代码,如果我先调用 Application-1,那么 gpiod_line_request_rising_edge_events 会以 -1 失败。如果我先调用 Application-2,则 gpiod_line_request_inputgets 以 -1 失败。

//应用程序-1

#include <stdio.h>
#include <gpiod.h>

int main()
{
char tBuffer[64] = {0,};
int gpio_num = 64, ret;
static struct gpiod_chip *gs_gpiod_chip = NULL;
struct gpiod_line *gs_gpiod_line = NULL;

unsigned int tgpio_chip = gpio_num / 32;
unsigned int tgpio_line = gpio_num % 32;

sprintf(tBuffer, "/dev/gpiochip%d", tgpio_chip);

gs_gpiod_chip = gpiod_chip_open(tBuffer);
if(!gs_gpiod_chip)
{
    printf("Error gpiod_chip_open\n");
    return -1;
}

gs_gpiod_line = gpiod_chip_get_line(gs_gpiod_chip, tgpio_line);
if(!gs_gpiod_line)
{
    printf("Error gs_gpiod_line\n");
    return -1;
}

ret = gpiod_line_request_input(gs_gpiod_line, "gpio-test");
if(ret == -1)
{
    printf("Error gpiod_line_request_input\n");
    return -1;
}

while(1);

gpiod_chip_close(gs_gpiod_chip);

printf("success\n");
return 0;
}

//Application-2

#include <stdio.h>
#include <gpiod.h>

int main()
{
char tBuffer[64] = {0,};
int gpio_num = 64, ret;
static struct gpiod_chip *gs_gpiod_chip = NULL;
struct gpiod_line *gs_gpiod_line = NULL;

unsigned int tgpio_chip = gpio_num / 32;
unsigned int tgpio_line = gpio_num % 32;

sprintf(tBuffer, "/dev/gpiochip%d", tgpio_chip);

gs_gpiod_chip = gpiod_chip_open(tBuffer);
if(!gs_gpiod_chip)
{
    printf("Error gpiod_chip_open\n");
    return -1;
}

gs_gpiod_line = gpiod_chip_get_line(gs_gpiod_chip, tgpio_line);
if(!gs_gpiod_line)
{
    printf("Error gs_gpiod_line\n");
    return -1;
}

ret = gpiod_line_request_rising_edge_events(gs_gpiod_line, "DICnt-TEST");
if(ret == -1)
{
    printf("Error gpiod_line_request_rising_edge_events\n");
    return -1;
}
    
while(1);

gpiod_chip_close(gs_gpiod_chip);

printf("success\n");
return 0;
}

我们是否可以选择使其工作或使用 libgpiod 库的任何其他替代解决方案。

谢谢。

4

0 回答 0