Hardware Reference
In-Depth Information
164 putchar('\n');
165 close(fd); /
Close gpio%d/value
/
166 gpio_close(gpio_inpin); /
Unexport gpio
/
167 return 0;
168 }
169
170 /
End event.c
/
Direct Register Access
It is possible to access the GPIO registers directly. The module gpio_io.c shows the
code that can be used for this. It requires the program to invoke gpio_init() upon
startup, which then makes the registers available. The code as presented is intended to
be #included into the module using it. (Normally, it would be compiled as a separate
module.) The API made available is outlined in the following subsections.
These routines are used in several examples and projects within this topic, including
the following:
pullup : Change the pull-up register setting.
bipolar : Drive a bipolar stepper motor (Chapter 7 of
Experimenting with Raspberry Pi [Apress, 2014]).
rtscts : Change the ALT function (Chapter 9).
valt : View ALT function settings (subdir valt in source code).
unipolar : Drive a unipolar stepper motor (Chapter 6 of
Experimenting with Raspberry Pi [Apress, 2014]).
dht11 : Humidity and temperature sensor (Chapter 1 of
Experimenting with Raspberry Pi [Apress, 2014]).
pwm : Pulse width modulation (Chapter 9 of Experimenting with
Raspberry Pi [Apress, 2014]).
gpio_init()
This function call opens access to the GPIO registers. This will require root privileges, which
is why many programs in this topic were compiled with setuid root. The operation of this
routine is to gain access to the physical memory space, so that the GPIO registers can be
accessed. This procedure is covered in the “Memory Mapping” section of Chapter 4.
void gpio_init(void);
 
Search WWH ::




Custom Search