Linux gpio c api

I have a powerpc board with kernel version 3.2. Access to gpio with sysfs works as expected, for example.

> echo 242 > /sys/class/gpio/export
> cat /sys/class/gpio/gpio242/value
>  1

Is there an API for direct access to gpio outputs from user space? Should I work with sysfs text interface?

I'm talking about something like: gpio_set (int no, int val);

Thanks Klaus

+5
source share
3 answers

sysfs is the lowest level at which you can manipulate GPIO in the latest kernels. This may be a little tedious, but it offers several advantages over the old API:

  • No ugly ioctl
  • Script can be easily written (think about startup scripts)
  • "" // , .

, C , :

int gpio_open(int number, int out); /* returns handle (fd) */
int gpio_close(int gpio);
int gpio_set(int gpio, int up);
int gpio_get(int gpio, int *up);
int gpio_poll(int gpio, int rising_edge, int timeout);

.

+2

, , vfs, , , , , , makedev, gpio- vfs.

+1

Each GPIO is a memory mapped as a register, so you can access it through / dev / mem. See here . If you want to access directly the GPIO, you must work at the kernel level.

-1
source

All Articles