libgpiod-example
libgpiod-example copied to clipboard
Port to libpgiod v2?
@starnight Thanks for these examples, they have been very instructive.
There is a v2.0-rc1 here https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/commit/?id=7deb50c54746b29b4f3edc098d3b835c1500e53a
Would you considering porting you examples?
Good question!
However, all of the major Linux distribution's packages keep on 1.6.x now. May consider porting to newer version in the future after it is formally released.
Some basic function has changed: This simple code doesn't work anymore and we have no clue how to resolve it:
void ToggleLogLed(bool onState) { const char* chipname = "gpiochip2"; unsigned int line_num = 7; // GPIO Pin #7 unsigned int val = (int)onState; struct gpiod_chip* chip; struct gpiod_line* line; int ret;
chip = gpiod_chip_open_by_name(chipname); if (!chip) { //perror("Open chip failed\n"); return; }
line = gpiod_chip_get_line(chip, line_num); if (!line) { //perror("Get line failed\n"); gpiod_chip_close(chip); return; }
ret = gpiod_line_request_output(line, "Log Led consumer", 0); if (ret < 0) { //perror("Request line as output failed\n"); gpiod_line_release(line); gpiod_chip_close(chip); return; }
ret = gpiod_line_set_value(line, val); if (ret < 0) { //perror("Set line output failed\n"); gpiod_line_release(line); gpiod_chip_close(chip); return; } gpiod_line_release(line); gpiod_chip_close(chip); }
In the meanwhile you might find inspiration with the example provided with the new lib here and the docs here. @starnight Yocto Nanbield is now providing both versions.