On 7/18/23 20:00, andy pugh wrote:
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);

Andy, I wonder that by_name is the same as currently called by-id in /dev/serial? there is currently a udev bug in debian they have indicated will not be fixed before trixie, so if you have serial devices, you get /dev/serial/by-path but not /dev/serial/by-id, which is used by klipper to assure klipper its not accidentally feeding your epson or hp printer. so it is /dev/serial/*, if that is not a not found error, then add a /* to the line. If by_path exists, but not by-id, your machine has the bug. The temp fix is a script, pinned on "discord/klipper/configuration"


Cheers, Gene Heskett.
--
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
 - Louis D. Brandeis
Genes Web page <http://geneslinuxbox.net:6309/>



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

Reply via email to