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

API Description

Gpio is the General Purpose IO interface to libmraa. Its features depend 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 configuration.

gpio = mraa_gpio_init(6);
signal(SIGINT, sig_handler);
while (running == 0) {
fprintf(stdout, "Gpio is %d\n", mraa_gpio_read(gpio));
sleep(1);
}
r = mraa_gpio_close(gpio);

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, mraa_gpio_edge_t mode)
 
mraa_result_t mraa_gpio_isr (mraa_gpio_context dev, mraa_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, mraa_gpio_mode_t mode)
 
mraa_result_t mraa_gpio_dir (mraa_gpio_context dev, mraa_gpio_dir_t dir)
 
mraa_result_t mraa_gpio_read_dir (mraa_gpio_context dev, mraa_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)
 
mraa_result_t mraa_gpio_input_mode (mraa_gpio_context dev, mraa_gpio_input_mode_t mode)
 
mraa_result_t mraa_gpio_out_driver_mode (mraa_gpio_context dev, mraa_gpio_out_driver_mode_t mode)
 

Typedefs

typedef struct _gpio * mraa_gpio_context
 

Enumerations

enum  mraa_gpio_mode_t { MRAA_GPIO_STRONG = 0, MRAA_GPIO_PULLUP = 1, MRAA_GPIO_PULLDOWN = 2, MRAA_GPIO_HIZ = 3 }
 
enum  mraa_gpio_dir_t { MRAA_GPIO_OUT = 0, MRAA_GPIO_IN = 1, MRAA_GPIO_OUT_HIGH = 2, MRAA_GPIO_OUT_LOW = 3 }
 
enum  mraa_gpio_edge_t { MRAA_GPIO_EDGE_NONE = 0, MRAA_GPIO_EDGE_BOTH = 1, MRAA_GPIO_EDGE_RISING = 2, MRAA_GPIO_EDGE_FALLING = 3 }
 
enum  mraa_gpio_input_mode_t { MRAA_GPIO_ACTIVE_HIGH = 0, MRAA_GPIO_ACTIVE_LOW = 1 }
 
enum  mraa_gpio_out_driver_mode_t { MRAA_GPIO_OPEN_DRAIN = 0, MRAA_GPIO_PUSH_PULL = 1 }
 

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,
mraa_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,
mraa_gpio_edge_t  edge,
void(*)(void *)  fptr,
void *  args 
)

Set an interrupt on pin

Parameters
devThe Gpio context
edgeThe edge mode to set the gpio into
fptrFunction pointer to function to be called when interrupt 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 interrupt 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,
mraa_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,
mraa_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_read_dir ( mraa_gpio_context  dev,
mraa_gpio_dir_t dir 
)

Read Gpio direction

Parameters
devThe Gpio context
dirThe address where to store the Gpio direction
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, invalid will return -1

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, invalid will return -1

Parameters
devThe Gpio context
Returns
gpio number

Here is the caller graph for this function:

mraa_result_t mraa_gpio_input_mode ( mraa_gpio_context  dev,
mraa_gpio_input_mode_t  mode 
)

Set Gpio input mode

Parameters
devThe Gpio context
modeMode to set input pin state
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_gpio_out_driver_mode ( mraa_gpio_context  dev,
mraa_gpio_out_driver_mode_t  mode 
)

Set Gpio output driver mode. This is not a standard feature, it needs custom implementation for each board

Parameters
devThe Gpio context
modeSet output driver mode
Returns
Result of operation

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

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 interrupts

Enumerator
MRAA_GPIO_EDGE_NONE 

No interrupt on Gpio

MRAA_GPIO_EDGE_BOTH 

Interrupt on rising & falling

MRAA_GPIO_EDGE_RISING 

Interrupt on rising only

MRAA_GPIO_EDGE_FALLING 

Interrupt on falling only

Gpio input modes

Enumerator
MRAA_GPIO_ACTIVE_HIGH 

Resistive High

MRAA_GPIO_ACTIVE_LOW 

Resistive Low

Gpio output driver modes

Enumerator
MRAA_GPIO_OPEN_DRAIN 

Open Drain Configuration

MRAA_GPIO_PUSH_PULL 

Push Pull Configuration

Include dependency graph for gpio.h: