pihwm
A lightweight C library for Raspberry Pi hardware modules.
 All Data Structures Files Functions Groups Pages
GPIO

GPIO library functions. More...

Functions

int gpio_init (unsigned int pin, unsigned int dir)
 Initialize the GPIO interface for the pin numbered pin on the Raspberry Pi P1 header in the direction specified by dir. dir should be either "in" or "out", for which the defined constants INPUT, IN, OUTPUT or OUT may be used.
 
int gpio_set_int (unsigned int pin, void(*isr)(int), char *mode)
 Set isr as the interrupt service routine (ISR) for pin numbered pin on the Raspberry Pi P1 header. mode should be one of the strings "rising", "falling" or "both" to indicate which edge(s) the ISR is to be triggered on. The function isr is called whenever the edge specified occurs, receiving as argument the number of the pin which triggered the interrupt.
 
int gpio_clear_int (unsigned int pin)
 Clears any interrupt service routine (ISR) set on the pin numbered pin on the Raspberry Pi P1 header. The ISR will have been set originally by a call to gpio_set_int.
 
int gpio_write (unsigned int pin, unsigned int val)
 Set the pin numbered pin on the Raspberry Pi P1 header to the value specified by val. dir should be either "0" or "1". The defined constants LOW or OFF may be used instead of 0 and HIGH or ON instead of 1/.
 
int gpio_read (unsigned int pin)
 Read the value on the pin numbered pin on the Raspberry Pi P1 header.
 
int gpio_release (unsigned int pin)
 The inverse of gpio_init. Frees the pin numbered pin on the Raspberry Pi P1 header, so it can be used for other purposes.
 

Detailed Description

GPIO library functions.

Function Documentation

int gpio_clear_int ( unsigned int  pin)

Clears any interrupt service routine (ISR) set on the pin numbered pin on the Raspberry Pi P1 header. The ISR will have been set originally by a call to gpio_set_int.

Parameters
Pinnumber which has an interrupt attached
Returns
Returns 1 on success. Never fails

Definition at line 304 of file pi_gpio.c.

int gpio_init ( unsigned int  pin,
unsigned int  dir 
)

Initialize the GPIO interface for the pin numbered pin on the Raspberry Pi P1 header in the direction specified by dir. dir should be either "in" or "out", for which the defined constants INPUT, IN, OUTPUT or OUT may be used.

Parameters
pinPin number
dirDirection of pin (input or output)
Returns
1 for success, -1 for failure

Definition at line 125 of file pi_gpio.c.

int gpio_read ( unsigned int  pin)

Read the value on the pin numbered pin on the Raspberry Pi P1 header.

Parameters
pinPin number to read from
Returns
On success, returns 0 or 1 depending on whether the pin is low or high respectively. On failure returns -1.

Definition at line 366 of file pi_gpio.c.

int gpio_release ( unsigned int  pin)

The inverse of gpio_init. Frees the pin numbered pin on the Raspberry Pi P1 header, so it can be used for other purposes.

Parameters
pinPin number to release
Returns
1 for success, -1 for failure

Definition at line 398 of file pi_gpio.c.

int gpio_set_int ( unsigned int  pin,
void(*)(int)  isr,
char *  mode 
)

Set isr as the interrupt service routine (ISR) for pin numbered pin on the Raspberry Pi P1 header. mode should be one of the strings "rising", "falling" or "both" to indicate which edge(s) the ISR is to be triggered on. The function isr is called whenever the edge specified occurs, receiving as argument the number of the pin which triggered the interrupt.

Parameters
pinPin number to attach interrupt to
isrInterrupt service routine to call
modeInterrupt mode
Returns
Returns 1 on success. Never fails

Definition at line 275 of file pi_gpio.c.

int gpio_write ( unsigned int  pin,
unsigned int  val 
)

Set the pin numbered pin on the Raspberry Pi P1 header to the value specified by val. dir should be either "0" or "1". The defined constants LOW or OFF may be used instead of 0 and HIGH or ON instead of 1/.

Parameters
pinPin number to write to
valValue to set (0 or 1)
Returns
1 for success, -1 for failure

Definition at line 322 of file pi_gpio.c.