Raspberry Pi GPIO Library
0.3
Library allowing for control of the Raspberry Pi's GPIO pins.
|
Contains source for the GPIO functionality. More...
#include "gpio.h"
Go to the source code of this file.
Macros | |
#define | ERROR(x) #x, |
Functions | |
static errStatus | gpioValidatePin (int gpioNumber) |
Internal function which Validates that the pin gpioNumber is valid for the Raspberry Pi. More... | |
errStatus | gpioSetup (void) |
Maps the memory used for GPIO access. This function must be called prior to any of the other GPIO calls. More... | |
errStatus | gpioCleanup (void) |
Unmaps the memory used for the gpio pins. This function should be called when finished with the GPIO pins. More... | |
errStatus | gpioSetFunction (int gpioNumber, eFunction function) |
Sets the functionality of the desired pin. More... | |
errStatus | gpioSetPin (int gpioNumber, eState state) |
Sets a pin to high or low. More... | |
errStatus | gpioReadPin (int gpioNumber, eState *state) |
Reads the current state of a gpio pin. More... | |
errStatus | gpioSetPullResistor (int gpioNumber, eResistor resistorOption) |
Allows configuration of the internal resistor at a GPIO pin. More... | |
errStatus | gpioGetI2cPins (int *gpioNumberScl, int *gpioNumberSda) |
Get the correct I2C pins. More... | |
const char * | gpioErrToString (errStatus error) |
Debug function which converts an error from errStatus to a string. More... | |
int | dbgPrint (FILE *stream, const char *file, int line, const char *format,...) |
Debug function wrapper for fprintf(). More... | |
Variables | |
static volatile uint32_t * | gGpioMap = NULL |
Pointer which will be mmap'd to the GPIO memory in /dev/mem. | |
static tPcbRev | pcbRev = pcbRevError |
PCB revision that executable is being run on. | |
Contains source for the GPIO functionality.
This is is part of https://github.com/alanbarr/RaspberryPi-GPIO a C library for basic control of the Raspberry Pi's GPIO pins. Copyright (C) Alan Barr 2012
This code was loosely based on the example code provided by Dom and Gert found at: http://elinux.org/RPi_Low-level_peripherals
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file gpio.c.
#define ERROR | ( | x | ) | #x, |
Redefining to replace macro with x as a string, i.e. "x". For use in gpioErrToString()
int dbgPrint | ( | FILE * | stream, |
const char * | file, | ||
int | line, | ||
const char * | format, | ||
... | |||
) |
Debug function wrapper for fprintf().
Allows file and line information to be added easier to output strings. DBG_INFO is a macro which is useful to call as the "first" parameter to this function. Note this function will add on a newline to the end of a format string so one is generally not required in format
.
[in] | stream | Output stream for strings, e.g. stderr, stdout. |
[in] | file | Name of file to be printed. Should be retrieved with FILE. |
line | Line number to print. Should be retrieved with LINE. | |
[in] | format | Formatted string in the format which printf() would accept. |
... | Additional arguments - to fill in placeholders in parameter format . |
errStatus gpioCleanup | ( | void | ) |
Unmaps the memory used for the gpio pins. This function should be called when finished with the GPIO pins.
const char* gpioErrToString | ( | errStatus | error | ) |
errStatus gpioGetI2cPins | ( | int * | gpioNumberScl, |
int * | gpioNumberSda | ||
) |
Get the correct I2C pins.
The different revisions of the PI have their I2C ports on different GPIO pins which require different BSC modules.
[out] | gpioNumberScl | Integer to be populated with scl gpio number. |
[out] | gpioNumberSda | Integer to be populated with sda gpio number. |
Reads the current state of a gpio pin.
gpioNumber | The number of the GPIO pin to read. | |
[out] | state | Pointer to the variable in which the GPIO pin state is returned. |
Sets the functionality of the desired pin.
gpioNumber | The gpio pin number to change. |
function | The desired functionality for the pin. |
Sets a pin to high or low.
The pin should be configured as an ouput with gpioSetFunction() prior to this.
gpioNumber | The pin to set. |
state | The desired state of the pin. |
Allows configuration of the internal resistor at a GPIO pin.
The GPIO pins on the BCM2835 have the option of configuring a pullup, pulldown or no resistor at the pin.
gpioNumber | The GPIO pin to configure. |
resistorOption | The available resistor options. |
errStatus gpioSetup | ( | void | ) |
Maps the memory used for GPIO access. This function must be called prior to any of the other GPIO calls.
|
static |
Internal function which Validates that the pin gpioNumber
is valid for the Raspberry Pi.
The first time this function is called it will perform some basic initalisation on internal variables.
gpioNumber | The pin number to check. |