GPIO available pins


#1

I want to know what all are the available GPIO pins are available to use. I need to send the intermediate response of available GPIO pins for the test and read mode AT commands of AT+KGPIOCFG for WP85 series from my legato application. I tried to read the /sys/class/gpio/export but there is no content inside this file.

char result[1000];
FILE *fp = NULL;
int i;
char c;
fp = fopen("/sys/class/gpio/export", "r");
if (!fp)
{
    LE_INFO("Error opening file %s for reading.\n", "/sys/class/gpio/export");
    return;
}
else
{
    LE_INFO("Opening file %s for reading is successful.\n", "/sys/class/gpio/export");
    return;
}
i = 0;
while (((c = fgetc(fp)) != EOF) && (i < (sizeof(result) - 1)))
{
    result[i] = c;
    i++;
}
result[i] = '\0';
fclose (fp);

LE_INFO("Read result: %s from %s", result, "/sys/class/gpio/export");

Is this correct way of fetching available pins? Any legato GPIO services or method is available to get these values?


#2

You may want to remove that second return…

LE_INFO(“Opening file %s for reading is successful.\n”, “/sys/class/gpio/export”);
return;


#3

The file /sys/class/gpio/export is a write-only file. It’s purpose is to make GPIOs available to user space applications. For example, if you do echo 25 > /sys/class/gpio/export, then the symlink /sys/class/gpio/gpio25 will be created. The symlink points to a folder and inside that you will find files for interacting with that GPIO. If you want to know all of the GPIOs that are currently exported to userspace, you could look at all of the symlinks matching /sys/class/gpio/gpioN.