mraa  0.6.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Pages
Functions | Typedefs | Enumerations
gpio.h File Reference

API Description

Gpio is the General Purpose IO interface to libmraa. It's features depends on the board type used, it can use gpiolibs (exported via a kernel module through sysfs), or memory mapped IO via a /dev/uio device or /dev/mem depending again on the board configuratio, or memory mapped IO via a /dev/uio device or /dev/mem depending again on the board configuration

gpio = mraa_gpio_init(6);
for (;;) {
fprintf(stdout, "Gpio is %d\n", mraa_gpio_read(gpio));
sleep(1);
}

Go to the source code of this file.

Functions

mraa_gpio_context mraa_gpio_init (int pin)
 
mraa_gpio_context mraa_gpio_init_raw (int gpiopin)
 
mraa_result_t mraa_gpio_edge_mode (mraa_gpio_context dev, gpio_edge_t mode)
 
mraa_result_t mraa_gpio_isr (mraa_gpio_context dev, gpio_edge_t edge, void(*fptr)(void *), void *args)
 
mraa_result_t mraa_gpio_isr_exit (mraa_gpio_context dev)
 
mraa_result_t mraa_gpio_mode (mraa_gpio_context dev, gpio_mode_t mode)
 
mraa_result_t mraa_gpio_dir (mraa_gpio_context dev, gpio_dir_t dir)
 
mraa_result_t mraa_gpio_close (mraa_gpio_context dev)
 
int mraa_gpio_read (mraa_gpio_context dev)
 
mraa_result_t mraa_gpio_write (mraa_gpio_context dev, int value)
 
mraa_result_t mraa_gpio_owner (mraa_gpio_context dev, mraa_boolean_t owner)
 
mraa_result_t mraa_gpio_use_mmaped (mraa_gpio_context dev, mraa_boolean_t mmap)
 
int mraa_gpio_get_pin (mraa_gpio_context dev)
 
int mraa_gpio_get_pin_raw (mraa_gpio_context dev)
 

Typedefs

typedef struct _gpio * mraa_gpio_context
 

Enumerations

enum  gpio_mode_t { MRAA_GPIO_STRONG = 0, MRAA_GPIO_PULLUP = 1, MRAA_GPIO_PULLDOWN = 2, MRAA_GPIO_HIZ = 3 }
 
enum  gpio_dir_t { MRAA_GPIO_OUT = 0, MRAA_GPIO_IN = 1, MRAA_GPIO_OUT_HIGH = 2, MRAA_GPIO_OUT_LOW = 3 }
 
enum  gpio_edge_t { MRAA_GPIO_EDGE_NONE = 0, MRAA_GPIO_EDGE_BOTH = 1, MRAA_GPIO_EDGE_RISING = 2, MRAA_GPIO_EDGE_FALLING = 3 }
 

Function Documentation

mraa_gpio_context mraa_gpio_init ( int  pin)

Initialise gpio_context, based on board number

Parameters
pinPin number read from the board, i.e IO3 is 3
Returns
gpio context or NULL

Here is the caller graph for this function:

mraa_gpio_context mraa_gpio_init_raw ( int  gpiopin)

Initialise gpio context without any mapping to a pin

Parameters
gpiopingpio pin as listed in SYSFS
Returns
gpio context or NULL

Here is the caller graph for this function:

mraa_result_t mraa_gpio_edge_mode ( mraa_gpio_context  dev,
gpio_edge_t  mode 
)

Set the edge mode on the gpio

Parameters
devThe Gpio context
modeThe edge mode to set the gpio into
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_gpio_isr ( mraa_gpio_context  dev,
gpio_edge_t  edge,
void(*)(void *)  fptr,
void *  args 
)

Set an interupt on pin

Parameters
devThe Gpio context
edgeThe edge mode to set the gpio into
fptrFunction pointer to function to be called when interupt is triggered
argsArguments passed to the interrupt handler (fptr)
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_gpio_isr_exit ( mraa_gpio_context  dev)

Stop the current interupt watcher on this Gpio, and set the Gpio edge mode to MRAA_GPIO_EDGE_NONE

Parameters
devThe Gpio context
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_gpio_mode ( mraa_gpio_context  dev,
gpio_mode_t  mode 
)

Set Gpio Output Mode,

Parameters
devThe Gpio context
modeThe Gpio Output Mode
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_gpio_dir ( mraa_gpio_context  dev,
gpio_dir_t  dir 
)

Set Gpio direction

Parameters
devThe Gpio context
dirThe direction of the Gpio
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_gpio_close ( mraa_gpio_context  dev)

Close the Gpio context

  • Will free the memory for the context and unexport the Gpio
Parameters
devThe Gpio context
Returns
Result of operation

Here is the caller graph for this function:

int mraa_gpio_read ( mraa_gpio_context  dev)

Read the Gpio value. This can be 0 or 1. A resonse of -1 means that there was a fatal error.

Parameters
devThe Gpio context
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_gpio_write ( mraa_gpio_context  dev,
int  value 
)

Write to the Gpio Value.

Parameters
devThe Gpio context
valueInteger value to write
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_gpio_owner ( mraa_gpio_context  dev,
mraa_boolean_t  owner 
)

Change ownership of the context.

Parameters
devThe Gpio context
ownerDoes this context own the pin
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_gpio_use_mmaped ( mraa_gpio_context  dev,
mraa_boolean_t  mmap 
)

Enable using memory mapped io instead of sysfs

Parameters
devThe Gpio context
mmapUse mmap instead of sysfs
Returns
Result of operation

Here is the caller graph for this function:

int mraa_gpio_get_pin ( mraa_gpio_context  dev)

Get a pin number of the gpio

Parameters
devThe Gpio context
Returns
Pin number

Here is the caller graph for this function:

int mraa_gpio_get_pin_raw ( mraa_gpio_context  dev)

Get a gpio number as used within sysfs

Parameters
devThe Gpio context
Returns
gpio number

Here is the caller graph for this function:

Typedef Documentation

typedef struct _gpio* mraa_gpio_context

Opaque pointer definition to the internal struct _gpio

Enumeration Type Documentation

Gpio Output modes

Enumerator
MRAA_GPIO_STRONG 

Default. Strong high and low

MRAA_GPIO_PULLUP 

Resistive High

MRAA_GPIO_PULLDOWN 

Resistive Low

MRAA_GPIO_HIZ 

High Z State

enum gpio_dir_t

Gpio Direction options

Enumerator
MRAA_GPIO_OUT 

Output. A Mode can also be set

MRAA_GPIO_IN 

Input

MRAA_GPIO_OUT_HIGH 

Output. Init High

MRAA_GPIO_OUT_LOW 

Output. Init Low

Gpio Edge types for interupts

Enumerator
MRAA_GPIO_EDGE_NONE 

No interrupt on Gpio

MRAA_GPIO_EDGE_BOTH 

Interupt on rising & falling

MRAA_GPIO_EDGE_RISING 

Interupt on rising only

MRAA_GPIO_EDGE_FALLING 

Interupt on falling only

Include dependency graph for gpio.h: