|
Raspberry Pi GPIO Library
0.3
Library allowing for control of the Raspberry Pi's GPIO pins.
|
The main header file of the GPIO library. More...
Go to the source code of this file.
Macros | |
| #define | CORE_CLK_HZ 250000000 |
| Speed of the core clock core_clk. | |
| #define | ERRORS |
| The list of errors which may be returned from gpio functions. More... | |
| #define | ERROR(x) x, |
| Redefining to replace the macro with x. | |
| #define | I2C_CLOCK_FREQ_MIN 10000 |
| Minimum I2C frequency (Hertz) | |
| #define | I2C_CLOCK_FREQ_MAX 400000 |
| Maximum I2C frequency (Hertz) | |
| #define | DBG_INFO stderr,__FILE__,__LINE__ |
| Macro which covers the first three arguments of dbgPrint. | |
| #define | REV1_PINCNT 17 |
| Pin count on a PCB rev1 Raspberry Pi. | |
| #define | REV2_PINCNT 17 |
| Pin count on a PCB rev2 Raspberry Pi. | |
| #define | REV1_PINS {0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25} |
| #define | REV2_PINS {2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 22, 23, 24, 25, 27} |
| #define | REV1_SDA 0 |
| The BCM2835 pin number of SDA on rev1 Raspberry Pi. | |
| #define | REV1_SCL 1 |
| The BCM2835 pin number of SCL on rev1 Raspberry Pi. | |
| #define | REV2_SDA 2 |
| The BCM2835 pin number of SDA on rev2 Raspberry Pi. | |
| #define | REV2_SCL 3 |
| The BCM2835 pin number of SCL on rev2 Raspberry Pi. | |
Enumerations | |
| enum | errStatus { ERROR_MAX } |
| The enum of possible errors returned from gpio functions. Errors themselves are defined in the macro ERRORS. | |
| enum | eState { low = 0x0, high = 0x1 } |
| The enum of possible pin states in input/output modes. More... | |
| enum | eResistor { pullDisable = GPPUD_DISABLE, pulldown = GPPUD_PULLDOWN, pullup = GPPUD_PULLUP } |
| The enum for possible pull resistors. More... | |
| enum | eFunction { input = GPFSEL_INPUT, output = GPFSEL_OUTPUT, alt0 = GPFSEL_ALT0, alt1 = GPFSEL_ALT1, alt2 = GPFSEL_ALT2, alt3 = GPFSEL_ALT3, alt4 = GPFSEL_ALT4, alt5 = GPFSEL_ALT5, eFunctionMin = GPFSEL_INPUT, eFunctionMax = GPFSEL_ALT3 } |
| The enum of pin functions available. More... | |
| enum | tPcbRev { pcbRevError = 0, pcbRev1 = 1, pcbRev2 = 2 } |
| valid PCB revision values | |
Functions | |
| 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 resistor) |
| Allows configuration of the internal resistor at a GPIO pin. More... | |
| errStatus | gpioGetI2cPins (int *gpioNumberScl, int *gpioNumberSda) |
| Get the correct I2C pins. More... | |
| errStatus | gpioI2cSetup (void) |
| Initial setup of I2C functionality. More... | |
| errStatus | gpioI2cCleanup (void) |
| Disables the I2C controller and unmaps the memory used for the i2c functionality. This function should be called when finished with the I2C module. More... | |
| errStatus | gpioI2cSetClock (int frequency) |
| Sets the I2C Clock Frequency. More... | |
| errStatus | gpioI2cSet7BitSlave (uint8_t slaveAddress) |
| Sets the 7-bit slave address to communicate with. More... | |
| errStatus | gpioI2cWriteData (const uint8_t *data, uint16_t dataLength) |
Writes data to the address previously specified by gpioI2cSet7BitSlave(). More... | |
| errStatus | gpioI2cReadData (uint8_t *buffer, uint16_t bytesToRead) |
| Read a number of bytes from I2C. The slave address should have been previously set with gpioI2cSet7BitSlave(). 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... | |
The main header file of the GPIO library.
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 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 rpiGpio.h.
| #define ERRORS |
The list of errors which may be returned from gpio functions.
Errors are defined within ERROR(x).
| #define REV1_PINS {0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25} |
| #define REV2_PINS {2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 22, 23, 24, 25, 27} |
| enum eFunction |
The enum of pin functions available.
The enum values are equivalent to those in the data sheet.
| enum eResistor |
| enum eState |
| 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 | ) |
| 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. |
| errStatus gpioI2cCleanup | ( | void | ) |
| errStatus gpioI2cReadData | ( | uint8_t * | buffer, |
| uint16_t | bytesToRead | ||
| ) |
Read a number of bytes from I2C. The slave address should have been previously set with gpioI2cSet7BitSlave().
| [out] | buffer | A pointer to a user defined buffer which will store the bytes. |
| bytesToRead | The number of bytes to read. |
| errStatus gpioI2cSet7BitSlave | ( | uint8_t | slaveAddress | ) |
| errStatus gpioI2cSetClock | ( | int | frequency | ) |
Sets the I2C Clock Frequency.
frequency <= I2C_CLOCK_FREQ_MAX. | frequency | Desired frequency in Hertz. |
| errStatus gpioI2cSetup | ( | void | ) |
Initial setup of I2C functionality.
gpioSetup() should be called prior to this.
| errStatus gpioI2cWriteData | ( | const uint8_t * | data, |
| uint16_t | dataLength | ||
| ) |
Writes data to the address previously specified by gpioI2cSet7BitSlave().
| [in] | data | Pointer to the start of data to transmit. |
| dataLength | The length of data. |
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. |
1.8.13