Accessing The Hardware; Digital I/O - GARZ&FRICKE GUF-Yocto-34.0-r5756-0-VINCELL User Manual

Embedded computer systems
Table of Contents

Advertisement

GUF-Yocto-34.0-r5756-0

6 Accessing the hardware

This chapter gives a short overview of how to access the different hardware parts and interfaces from within the
Linux operating system. It is written universally in order to fit all Garz & Fricke platforms in general.

6.1 Digital I/O

The digital I/O pins for a platform are controlled by the kernel's
a sysfs interface to the user space. For each pin, there is a virtual folder in the file system under
with the same name as in the hardware manual.
Each folder contains the following virtual files that can be accessed like normal files. In the command shell, there
are the standard Linux commands
from C/C++ code, the standard POSIX operations open(), read(), write() and close() can be used.
sysfs file
Valid values
value
0, 1
direction
in, out
active_low
0, 1
Most of the Garz & Fricke hardware platforms include a dedicated connector with isolated digital I/O pins. On
these pins, the direction cannot be changed, since it is determined by the wiring. Thus, the direction file is missing
here. Some platforms also have a keypad connector, which can be used as a bi-directional GPIO port.
The following examples show how to use the virtual files in order to control the GPIO pins.
Example 1: Verify that the GPIO pin keypad_pin7, which is pin 7 on the keypad connector, is interpreted as
active
high, configure the pin as an output and set it to high level in the Linux shell:
root@vincell:~# cat /sys/class/gpio/keypad_pin7/active_low
0
root@vincell:~# echo out > /sys/class/gpio/keypad_pin7/direction
root@vincell:~# echo 1 > /sys/class/gpio/keypad_pin7/value
Example 2: Verify that
keypad_pin12
is recognized by this pin in the Linux shell:
root@vincell:~# cat /sys/class/gpio/keypad_pin12/direction
in
root@vincell:~# cat /sys/class/gpio/keypad_pin12/active_low
1
root@vincell:~# cat /sys/class/gpio/keypad_pin12/value
1
Example 3: C function to set / clear the
void set_gpio(unsigned int state)
{
int fd = -1; // GPIO file handle
char gpio[4];
fd = open("/sys/class/gpio/dig_out1/value", O_RDWR);
if (fd == -1)
{
printf("GPIO-ERR\n");
return;
}
sprintf(gpio, "%d", state);
write(fd, gpio, strlen(gpio));
close(fd);
}
26
VINCELL
User Manual
¡
¡
cat
for read access and
Meaning
The current level of the GPIO pin. The
below) has to be taken into account for interpretation.
The direction of the GPIO pin.
Indicates if the pin is interpreted active low.
is an input pin and interpreted as
dig_out1
output pin:
GPIO Library
interface driver. This driver exports
echo
for write access. To acces those virtual files
acive_low
and verify that the level
active low
/sys/class/gpio/
flag (see
LOW

Advertisement

Table of Contents
loading

Table of Contents