Skip to content

Conversation

@nicoeng
Copy link

@nicoeng nicoeng commented Feb 18, 2025

The file descriptor was left open after the function returns.

@nicoeng nicoeng marked this pull request as draft May 29, 2025 01:22
@nicoeng nicoeng marked this pull request as ready for review May 29, 2025 01:22
@nicoeng
Copy link
Author

nicoeng commented Oct 28, 2025

Also handles /sys/class/i2c-adapter deprecation. On newer kernel this class is not exposed anymore.

@FaSoa
Copy link
Collaborator

FaSoa commented Oct 31, 2025

Hello nicoeng.
I still get gpio.c errors when I use your code from
https://github.com/nicoeng/daqhats.git

I'm using a RPi5 with Trixie 64-bit.

Regards.


gpio.c: In function ‘gpio_init’:
gpio.c:40:25: error: implicit declaration of function ‘gpiod_chip_open_by_name’; did you mean ‘gpiod_chip_info_get_name’? [-Wimplicit-function-declaration]
40 | if (NULL == (chip = gpiod_chip_open_by_name("gpiochip4")))
| ^~~~~~~~~~~~~~~~~~~~~~~
| gpiod_chip_info_get_name
gpio.c:40:23: error: assignment to ‘struct gpiod_chip *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
40 | if (NULL == (chip = gpiod_chip_open_by_name("gpiochip4")))
| ^
gpio.c:43:27: error: assignment to ‘struct gpiod_chip ’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
43 | if (NULL == (chip = gpiod_chip_open_by_name("gpiochip0")))
| ^
gpio.c:78:5: error: implicit declaration of function ‘gpiod_line_bulk_init’ [-Wimplicit-function-declaration]
78 | gpiod_line_bulk_init(&lines);
| ^~~~~~~~~~~~~~~~~~~~
gpio.c:79:26: error: implicit declaration of function ‘gpiod_chip_num_lines’; did you mean ‘gpiod_chip_request_lines’? [-Wimplicit-function-declaration]
79 | unsigned int count = gpiod_chip_num_lines(chip);
| ^~~~~~~~~~~~~~~~~~~~
| gpiod_chip_request_lines
gpio.c:82:35: error: implicit declaration of function ‘gpiod_chip_get_line’; did you mean ‘gpiod_chip_get_info’? [-Wimplicit-function-declaration]
82 | struct gpiod_line
line = gpiod_chip_get_line(chip, i);
| ^~~~~~~~~~~~~~~~~~~
| gpiod_chip_get_info
gpio.c:82:35: error: initialization of ‘struct gpiod_line *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
gpio.c:90:9: error: implicit declaration of function ‘gpiod_line_bulk_add’ [-Wimplicit-function-declaration]
90 | gpiod_line_bulk_add(&lines, line);
| ^~~~~~~~~~~~~~~~~~~
gpio.c: In function ‘gpio_close’:
gpio.c:109:39: error: invalid use of undefined type ‘struct gpiod_line_bulk’
109 | for (unsigned int i = 0; i < lines.num_lines; i++)
| ^
gpio.c:111:9: error: implicit declaration of function ‘gpiod_line_release’; did you mean ‘gpio_release’? [-Wimplicit-function-declaration]
111 | gpiod_line_release(lines.lines[i]);
| ^~~~~~~~~~~~~~~~~~
| gpio_release
gpio.c:111:33: error: invalid use of undefined type ‘struct gpiod_line_bulk’
111 | gpiod_line_release(lines.lines[i]);
| ^
gpio.c: In function ‘gpio_set_output’:
gpio.c:129:21: error: invalid use of undefined type ‘struct gpiod_line_bulk’
129 | if (pin >= lines.num_lines)
| ^
gpio.c:136:15: error: implicit declaration of function ‘gpiod_line_request_output’; did you mean ‘gpiod_line_request_get_fd’? [-Wimplicit-function-declaration]
136 | if (-1 == gpiod_line_request_output(lines.lines[pin], app_name, value))
| ^~~~~~~~~~~~~~~~~~~~~~~~~
| gpiod_line_request_get_fd
gpio.c:136:46: error: invalid use of undefined type ‘struct gpiod_line_bulk’
136 | if (-1 == gpiod_line_request_output(lines.lines[pin], app_name, value))
| ^
gpio.c: In function ‘gpio_write’:
gpio.c:151:21: error: invalid use of undefined type ‘struct gpiod_line_bulk’
151 | if (pin >= lines.num_lines)
| ^
gpio.c:158:15: error: implicit declaration of function ‘gpiod_line_set_value’; did you mean ‘gpiod_line_request_set_value’? [-Wimplicit-function-declaration]
158 | if (-1 == gpiod_line_set_value(lines.lines[pin], value))
| ^~~~~~~~~~~~~~~~~~~~
| gpiod_line_request_set_value
gpio.c:158:41: error: invalid use of undefined type ‘struct gpiod_line_bulk’
158 | if (-1 == gpiod_line_set_value(lines.lines[pin], value))
| ^
gpio.c: In function ‘gpio_input’:
gpio.c:173:21: error: invalid use of undefined type ‘struct gpiod_line_bulk’
173 | if (pin >= lines.num_lines)
| ^
gpio.c:180:15: error: implicit declaration of function ‘gpiod_line_request_input’; did you mean ‘gpiod_line_request_get_fd’? [-Wimplicit-function-declaration]
180 | if (-1 == gpiod_line_request_input(lines.lines[pin], app_name))
| ^~~~~~~~~~~~~~~~~~~~~~~~
| gpiod_line_request_get_fd
gpio.c:180:45: error: invalid use of undefined type ‘struct gpiod_line_bulk’
180 | if (-1 == gpiod_line_request_input(lines.lines[pin], app_name))
| ^
gpio.c: In function ‘gpio_release’:
gpio.c:195:21: error: invalid use of undefined type ‘struct gpiod_line_bulk’
195 | if (pin >= lines.num_lines)
| ^
gpio.c:202:29: error: invalid use of undefined type ‘struct gpiod_line_bulk’
202 | gpiod_line_release(lines.lines[pin]);
| ^
gpio.c: In function ‘gpio_read’:
gpio.c:211:21: error: invalid use of undefined type ‘struct gpiod_line_bulk’
211 | if (pin >= lines.num_lines)
| ^
gpio.c:218:17: error: implicit declaration of function ‘gpiod_line_get_value’; did you mean ‘gpiod_line_request_get_value’? [-Wimplicit-function-declaration]
218 | int value = gpiod_line_get_value(lines.lines[pin]);
| ^~~~~~~~~~~~~~~~~~~~
| gpiod_line_request_get_value
gpio.c:218:43: error: invalid use of undefined type ‘struct gpiod_line_bulk’
218 | int value = gpiod_line_get_value(lines.lines[pin]);
| ^
gpio.c: In function ‘gpio_interrupt_thread’:
gpio.c:235:21: error: invalid use of undefined type ‘struct gpiod_line_bulk’
235 | if (pin >= lines.num_lines)
| ^
gpio.c:243:22: error: implicit declaration of function ‘gpiod_line_event_wait’; did you mean ‘gpiod_edge_event_copy’? [-Wimplicit-function-declaration]
243 | int result = gpiod_line_event_wait(lines.lines[pin], &timeout);
| ^~~~~~~~~~~~~~~~~~~~~
| gpiod_edge_event_copy
gpio.c:243:49: error: invalid use of undefined type ‘struct gpiod_line_bulk’
243 | int result = gpiod_line_event_wait(lines.lines[pin], &timeout);
| ^
gpio.c: In function ‘gpio_interrupt_callback’:
gpio.c:261:21: error: invalid use of undefined type ‘struct gpiod_line_bulk’
261 | if (pin >= lines.num_lines)
| ^
gpio.c:268:29: error: invalid use of undefined type ‘struct gpiod_line_bulk’
268 | gpiod_line_release(lines.lines[pin]);
| ^
gpio.c:273:18: error: implicit declaration of function ‘gpiod_line_request_falling_edge_events’; did you mean ‘gpiod_line_request_wait_edge_events’? [-Wimplicit-function-declaration]
273 | result = gpiod_line_request_falling_edge_events(lines.lines[pin], app_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| gpiod_line_request_wait_edge_events
gpio.c:273:62: error: invalid use of undefined type ‘struct gpiod_line_bulk’
273 | result = gpiod_line_request_falling_edge_events(lines.lines[pin], app_name);
| ^

gpio.c:276:18: error: implicit declaration of function ‘gpiod_line_request_rising_edge_events’; did you mean ‘gpiod_line_request_read_edge_events’? [-Wimplicit-function-declaration]
276 | result = gpiod_line_request_rising_edge_events(lines.lines[pin], app_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| gpiod_line_request_read_edge_events
gpio.c:276:61: error: invalid use of undefined type ‘struct gpiod_line_bulk’
276 | result = gpiod_line_request_rising_edge_events(lines.lines[pin], app_name);
| ^
gpio.c:279:18: error: implicit declaration of function ‘gpiod_line_request_both_edges_events’; did you mean ‘gpiod_line_request_read_edge_events’? [-Wimplicit-function-declaration]
279 | result = gpiod_line_request_both_edges_events(lines.lines[pin], app_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| gpiod_line_request_read_edge_events
gpio.c:279:60: error: invalid use of undefined type ‘struct gpiod_line_bulk’
279 | result = gpiod_line_request_both_edges_events(lines.lines[pin], app_name);
| ^
gpio.c:282:48: error: invalid use of undefined type ‘struct gpiod_line_bulk’
282 | result = gpiod_line_request_input(lines.lines[pin], app_name);
| ^
gpio.c:319:44: error: invalid use of undefined type ‘struct gpiod_line_bulk’
319 | while (1 == gpiod_line_event_wait(lines.lines[pin], &timeout))
| ^
gpio.c: In function ‘gpio_wait_for_low’:
gpio.c:342:21: error: invalid use of undefined type ‘struct gpiod_line_bulk’
342 | if (pin >= lines.num_lines)
| ^
gpio.c:363:58: error: invalid use of undefined type ‘struct gpiod_line_bulk’
363 | if (0 != gpiod_line_request_falling_edge_events(lines.lines[pin], app_name))
| ^
gpio.c:376:44: error: invalid use of undefined type ‘struct gpiod_line_bulk’
376 | while (1 == gpiod_line_event_wait(lines.lines[pin], &timeout_struct))
| ^
gpio.c:387:45: error: invalid use of undefined type ‘struct gpiod_line_bulk’
387 | int result = gpiod_line_event_wait(lines.lines[pin], &timeout_struct);
| ^
gpio.c: At top level:
gpio.c:22:31: error: storage size of ‘lines’ isn’t known
22 | static struct gpiod_line_bulk lines;
| ^~~~~
make: *** [makefile:32: build/gpio.o] Error 1
make: Leaving directory '/home/rpi5-trixie64/daqhats/lib'
Library build failed

@nicoeng
Copy link
Author

nicoeng commented Oct 31, 2025

@FaSoa That's because daqhats uses libgpiod version 1.x. Trixie comes with libgpiod 2.x.
I built and installed an old version of the library to have it running or Trixie.

Have a look at issue #78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants