gpio: libgpiod 2.0: port gpiod_chip_num_lines

This commit is contained in:
marcin
2024-05-13 22:29:23 +02:00
parent 88e85ae7c2
commit b1bb871eb7

View File

@@ -237,6 +237,22 @@ clean_chip_open:
return NULL;
}
unsigned int gpio_chip_num_lines(struct EG25Manager *manager, unsigned int chip_num) {
struct gpiod_chip *chip = manager->gpiochip[chip_num];
struct gpiod_chip_info *info;
unsigned int num_lines;
info = gpiod_chip_get_info(chip);
if (!info)
g_error("gpio: failed to read info: %s", strerror(errno));
num_lines = gpiod_chip_info_get_num_lines(info);
gpiod_chip_info_free(info);
return num_lines;
}
int gpio_init(struct EG25Manager *manager, toml_table_t *config[])
{
int i;
@@ -289,7 +305,7 @@ int gpio_init(struct EG25Manager *manager, toml_table_t *config[])
g_error("Wrong chip ID for output GPIO '%s'", gpio_out_names[i]);
line = toml_int_in(table, "line");
if (!line.ok || line.u.i < 0 || line.u.i > gpiod_chip_num_lines(manager->gpiochip[chip.u.i]))
if (!line.ok || line.u.i < 0 || line.u.i > gpio_chip_num_lines(manager, chip.u.i))
g_error("Wrong line ID for output GPIO '%s'", gpio_out_names[i]);
manager->gpio_out[i] = gpio_request_output_line(manager, chip.u.i, line.u.i);
@@ -313,7 +329,7 @@ int gpio_init(struct EG25Manager *manager, toml_table_t *config[])
g_error("Wrong chip ID for input GPIO '%s'", gpio_in_names[i]);
line = toml_int_in(table, "line");
if (!line.ok || line.u.i < 0 || line.u.i > gpiod_chip_num_lines(manager->gpiochip[chip.u.i]))
if (!line.ok || line.u.i < 0 || line.u.i > gpio_chip_num_lines(manager, chip.u.i))
g_error("Wrong line ID for input GPIO '%s'", gpio_in_names[i]);
manager->gpio_in[i] = gpio_request_input_line(manager, chip.u.i, line.u.i);