gpiod library event and input request of same gpio line not working

1.6k Views Asked by At

I tried gpiod_line_request_rising_edge_events() and gpiod_line_request_input() call for same gpio line in two difference application, but it returning -1.

I used below code, if I call Application-1 first then gpiod_line_request_rising_edge_events gets failed with -1. and if I call Application-2 first then gpiod_line_request_inputgets failed with -1.

//Application-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;
}

Do we have any have option to make it working or any other alternative solution with libgpiod library.

Thanks.

0

There are 0 best solutions below