From b1bb871eb756a5fc6bb3b644baa935d43a494609 Mon Sep 17 00:00:00 2001 From: marcin Date: Mon, 13 May 2024 22:29:23 +0200 Subject: [PATCH] gpio: libgpiod 2.0: port gpiod_chip_num_lines --- src/gpio.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/gpio.c b/src/gpio.c index 995f6a3..f8e1470 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -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);