hi, I have my colibri-imx6ull running a Ångström/ OpenEmbedded based image that I cook with yocto, and I´m using the sysfs driver to control GPIO pins, that works fine, but is very slow, and I read that sysfs is deprecated, is posible to use libgpiod on my colibri-imx6ull/Ångström or libgpiod is only suported by torizon??
thanks
Libgpiod is supported not only by Torizon but by our “regular” BSP also since version 3.0b3. However 3.x BSP does not support Angstrom anymore.
sorry my ditro is not angstrom, my distro is “tdx-x11” and my bsp 5.0.
but I´m working in eclipse with the old sdk downloaded from toradex and this is 2017, and I don´t have the gpiod.h in the sysroot of my sdk :(.
I will try to make my own lib using linux/gpio.h and ioctl() functions.
gpio working with this code 20 times faster than sysfs
#include "my_gpio.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <poll.h>
#include <string.h>
#include <sys/ioctl.h>
//manejadores para los 4 chips de gpio
int chip[4];
//llamar a esta funcion al inicia para abrir los manejadores de los chips gpio
void GPIO_init(void){
chip[0] = open("/dev/gpiochip0", 0);
chip[1] = open("/dev/gpiochip1", 0);
chip[2] = open("/dev/gpiochip2", 0);
chip[3] = open("/dev/gpiochip3", 0);
}
//esta funcion inicializa la direccion del gpio y me devuelve el manejador
struct gpiohandle_request * GPIO_get_handle(uint8_t nchip, uint8_t nport, bool direction, char * name){
struct gpiohandle_request * req = malloc(sizeof(struct gpiohandle_request));
req->lineoffsets[0] = nport;
req->lines = 1;
strcpy(req->consumer_label, name);
if(direction == IN) req->flags = GPIOHANDLE_REQUEST_INPUT;
if(direction == OUT) req->flags = GPIOHANDLE_REQUEST_OUTPUT;
ioctl(chip[nchip], GPIO_GET_LINEHANDLE_IOCTL, req);
return req;
}
void GPIO_set_value(struct gpiohandle_request * handle, bool value){
struct gpiohandle_data data;
data.values[0] = value;
ioctl(handle->fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
}
bool GPIO_get_value(struct gpiohandle_request * handle){
struct gpiohandle_data data;
ioctl(handle->fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data);
return (bool) data.values[0];
}