I am looking at the possibilities of the gpiod library for Pi (and
other such devices)

I have flashed an led on my Pi400 with a bit of sample code:

********************************************************
#include <gpiod.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
  const char *chipname = "gpiochip0";
  struct gpiod_chip *chip;
  struct gpiod_line *line1;    // Red LED
  int i, val;

  // Open GPIO chip
  chip = gpiod_chip_open_by_name(chipname);

  // Open GPIO lines
  line1 = gpiod_chip_get_line(chip, 17);

  // Open LED lines for output
  gpiod_line_request_output(line1, "example1", 0);

  // Blink LEDs in a binary pattern
  i = 0;
  while (true) {
    gpiod_line_set_value(line1, (i & 1) != 0);
    usleep(100000);
    i++;
  }

  // Release lines and chip
  gpiod_line_release(line1);
  gpiod_chip_close(chip);
  return 0;
}
************************************************************

This requires libgpiod-dev to be installed, but also needs to be compiled with
gcc -libgpiod test.c or it does not compile.

I have very similar code in a .comp. This compiles, but on loading
into HAL I get the same error as the _compile_ time error with the
test code: " undefined symbol: gpiod_chip_open_by_name"

I have tried using:
option extra_compile args "-lgpiod";
in the .comp, and I have also tried adding '-lgpiod" to the makefile
(and then rebuilding LinuxCNC).
EXTRA_CFLAGS += -lgpiod
But so far with no success.

Any pointers?

************************************************************
component gpiod_test;

pin in bit _in;

author "andypugh";
license "GPL";

option extra_setup;
option extra_compile_args "-lgpiod";

function _;

;;

// sudo apt-get install libgpiod.dev
#include <gpiod.h>

const char *chipname = "gpiochip0";
struct gpiod_chip *chip;
struct gpiod_line *line11;    // Red LED


EXTRA_SETUP(){

  // Open GPIO chip
  chip = gpiod_chip_open_by_name(chipname);

  // Open GPIO lines
  line11= gpiod_chip_get_line(chip, 11);

  // Open LED lines for output
  gpiod_line_request_output(line11, "example1", 0);

}

FUNCTION(_){

gpiod_line_set_value(line11, _in);

}


-- 
atp
"A motorcycle is a bicycle with a pandemonium attachment and is
designed for the especial use of mechanical geniuses, daredevils and
lunatics."
— George Fitch, Atlanta Constitution Newspaper, 1912


_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to