CRpi
A library for rpi with intefaces to: gpio, pwm, dma
Macros | Functions
gpio.h File Reference

Interface to the GPIO peripheral. More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define BCM_MIN   0
 The lowest valid bcm port number.
 
#define BCM_MAX   27
 The highest valid bcm port number.
 
#define PORT_FUNCTION_INPUT   0
 Port function: Input. used in gpio_setFunction()
 
#define PORT_FUNCTION_OUTPUT   1
 Port function: Output. used in gpio_setFunction()
 
#define PORT_FUNCTION_ALT_0   4
 Port function: Alternative function 0. used in gpio_setFunction()
 
#define PORT_FUNCTION_ALT_1   5
 Port function: Alternative function 1. used in gpio_setFunction()
 
#define PORT_FUNCTION_ALT_2   6
 Port function: Alternative function 2. used in gpio_setFunction()
 
#define PORT_FUNCTION_ALT_3   7
 Port function: Alternative function 3. used in gpio_setFunction()
 
#define PORT_FUNCTION_ALT_4   3
 Port function: Alternative function 4. used in gpio_setFunction()
 
#define PORT_FUNCTION_ALT_5   2
 Port function: Alternative function 5. used in gpio_setFunction()
 

Functions

int gpio_init ()
 Initializes the interface, to be called before any other function in this file. More...
 
int gpio_isInit ()
 true if gpio_init has been called with success
 
int gpio_setFunction (int bcmPort, int function)
 Sets the function of the specified port. More...
 
int gpio_setOutput (int bcmPort, int value)
 Sets the output at the specified port. The port will output this value if set to the output function. If you use this function with the port not set to output then the port will remember the value until you set it to the output function. More...
 
int gpio_setOutputAll (uint64_t set, uint64_t clear)
 sets all the specified gpios to the specified values More...
 

Detailed Description

Interface to the GPIO peripheral.

This peripheral is able to set the function of each GPIO port and it's output status.
See documentation at "BCM2835 ARM peripherals" page 89

Function Documentation

int gpio_init ( )

Initializes the interface, to be called before any other function in this file.

Returns
negative in case of error
int gpio_setFunction ( int  bcmPort,
int  function 
)

Sets the function of the specified port.

Parameters
bcmPortThe port bcm number
functionThe desired function (PORT_FUNCTION_INPUT, PORT_FUNCTION_OUTPUT, PORT_FUNCTION_ALT_x)
Returns
negative in case of error
int gpio_setOutput ( int  bcmPort,
int  value 
)

Sets the output at the specified port. The port will output this value if set to the output function. If you use this function with the port not set to output then the port will remember the value until you set it to the output function.

Parameters
bcmPortThe port bcm number
value0 means low, any other number means high
Returns
negative in case of error
int gpio_setOutputAll ( uint64_t  set,
uint64_t  clear 
)

sets all the specified gpios to the specified values

Parameters
setThe gpios to set to 1
clearThe values to set to 0
Returns
negative in case of error