WiringPi for Android

Im just wondering if khadas-WiringPi has a version for edge2? If so will this work on android?

Im a Senior Engineer/Tech Lead in my day job and i do most of my work in c++ so woudl like to use the gpio pins from code, i can maybe look at porting khadas-WiringPi to edge2 if needed.

For some background im reading can messages in my custom lib and pass the decoded messages to java.
I would like to do some stuff with my led’s based on can activity/device info, i can use shell commands but this woudl be slow and not very efficient.

@Blah_Blah Because there were very few pins in edge2, there was no development. Actually, if you don’t want to use Java, you can add functions to control those pins in the driver layer, and then call the control functions through nodes.

That sounds like a good plan, could you point me to the files/supply any info on the process?

Actually, there’s no need to be so troublesome. You can still control the GPIO port by operating the node. The following code has not been validated(copied from the internet), it is just an example.

#define SYSFS_GPIO_EXPORT          "/sys/class/gpio/export"
#define SYSFS_GPIO_BUSY_PIN_VAL      "154"
#define SYSFS_GPIO_BUSY_DIR          "/sys/class/gpio/gpio154/direction"
#define SYSFS_GPIO_BUSY_DIR_VAL      "in"
#define SYSFS_GPIO_BUSY_VAL          "/sys/class/gpio/gpio154/value"

static int gpio_set(void)
{
	int fd;

	//~sys/class/gpio# echo 48 > export
	fd = open(SYSFS_GPIO_EXPORT, O_WRONLY);
	if(fd == -1){
		  printf("ERR: Radio hard reset pin open error.\n");
		  return -1;
	}
	write(fd, SYSFS_GPIO_BUSY_PIN_VAL ,sizeof(SYSFS_GPIO_BUSY_PIN_VAL));
	close(fd);

	//~/sys/class/gpio/gpio48# echo out > direction
	fd = open(SYSFS_GPIO_BUSY_DIR, O_WRONLY);

	if(fd == -1){
		  printf("ERR: Radio hard reset pin direction open error.\n");
		  return -1;
	}
	write(fd, SYSFS_GPIO_BUSY_DIR_VAL, sizeof(SYSFS_GPIO_BUSY_DIR_VAL));
	close(fd);
	return 0;
}

static  unsigned char gpio_read(void)
{
    int fd;
    unsigned char buf = 0;

    fd = open(SYSFS_GPIO_BUSY_VAL, O_RDONLY);

    if (fd < 0) {
        printf("Failed to open gpio value for reading!\n");
        return -1;
    }

    if (read(fd, &buf, 1) < 0) {

        printf("Failed to read value!\n");

        return -1;

    }
    close(fd);

    return buf;
}

https://docs.khadas.com/products/sbc/edge2/applications/gpio/40pin-header

Thanks for that, i have made this into a class for exporting/unexporting + setting and getting pin values/directions, i have added this to my custom rom and will make some changes to KSettings to allow for pin managment.

I can post the git repos once the changes are ready.

1 Like