RocketLogger  1.1.6
gpio.h File Reference
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "log.h"
#include "types.h"
+ Include dependency graph for gpio.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define GPIO_PATH   "/sys/class/gpio/"
 Path to linux GPIO device files. More...
 
#define MIN_BUTTON_TIME   100000
 Minimal time a button needs to be pressed (in µs) More...
 

Typedefs

typedef enum direction rl_direction
 
typedef enum edge rl_edge
 

Enumerations

enum  direction { IN, OUT }
 
enum  edge { NONE, RISING, FALLING, BOTH }
 

Functions

int gpio_unexport (int num)
 
int gpio_export (int num)
 
int gpio_dir (int num, rl_direction dir)
 
int gpio_set_value (int num, int val)
 
int gpio_get_value (int num)
 
int gpio_interrupt (int num, rl_edge e)
 
int gpio_wait_interrupt (int num, int timeout)
 

Macro Definition Documentation

#define GPIO_PATH   "/sys/class/gpio/"

Path to linux GPIO device files.

Copyright (c) 2016-2019, Swiss Federal Institute of Technology (ETH Zurich) All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 46 of file gpio.h.

Referenced by gpio_dir(), gpio_export(), gpio_get_value(), gpio_interrupt(), gpio_set_value(), gpio_unexport(), and gpio_wait_interrupt().

#define MIN_BUTTON_TIME   100000

Minimal time a button needs to be pressed (in µs)

Definition at line 48 of file gpio.h.

Referenced by gpio_wait_interrupt().

Typedef Documentation

typedef enum direction rl_direction

GPIO direction definition

typedef enum edge rl_edge

GPIO interrupt edge definition

Enumeration Type Documentation

enum direction

GPIO direction definition

Enumerator
IN 

GPIO read mode.

OUT 

GPIO write mode.

Definition at line 53 of file gpio.h.

enum edge

GPIO interrupt edge definition

Enumerator
NONE 

No interrupt.

RISING 

Interrupt on rising edge.

FALLING 

Interrupt on falling edge.

BOTH 

Interrupt on both edges.

Definition at line 61 of file gpio.h.

Function Documentation

int gpio_dir ( int  num,
rl_direction  dir 
)

Set direction of GPIO.

Parameters
numLinux GPIO number.
dirDirection.
Returns
SUCCESS in case of success, FAILURE otherwise.

Definition at line 88 of file gpio.c.

References ERROR, FAILURE, GPIO_PATH, MAX_PATH_LENGTH, OUT, rl_log(), and SUCCESS.

Referenced by gpio_setup(), and hw_init().

+ Here is the call graph for this function:

int gpio_export ( int  num)

Export (activate) a GPIO.

Parameters
numLinux GPIO number.
Returns
SUCCESS in case of success, FAILURE otherwise.

Definition at line 63 of file gpio.c.

References ERROR, FAILURE, GPIO_PATH, rl_log(), and SUCCESS.

Referenced by gpio_setup(), and hw_init().

+ Here is the call graph for this function:

int gpio_get_value ( int  num)

Get GPIO value.

Parameters
numLinux GPIO number.
Returns
GPIO value, FAILURE on failure.

Definition at line 185 of file gpio.c.

References ERROR, FAILURE, GPIO_PATH, MAX_PATH_LENGTH, and rl_log().

+ Here is the call graph for this function:

int gpio_interrupt ( int  num,
rl_edge  edge 
)

Set direction of GPIO interrupt edge.

Parameters
numLinux GPIO number.
edgeEdge direction.
Returns
SUCCESS in case of success, FAILURE otherwise.

Definition at line 117 of file gpio.c.

References BOTH, ERROR, FAILURE, FALLING, GPIO_PATH, MAX_PATH_LENGTH, NONE, RISING, rl_log(), and SUCCESS.

Referenced by gpio_setup().

+ Here is the call graph for this function:

int gpio_set_value ( int  num,
int  val 
)

Set value of GPIO.

Parameters
numLinux GPIO number.
valValue (0 or 1).
Returns
SUCCESS in case of success, FAILURE otherwise.

Definition at line 156 of file gpio.c.

References ERROR, FAILURE, GPIO_PATH, MAX_PATH_LENGTH, rl_log(), and SUCCESS.

Referenced by hw_close(), hw_init(), and hw_sample().

+ Here is the call graph for this function:

int gpio_unexport ( int  num)

Copyright (c) 2016-2019, Swiss Federal Institute of Technology (ETH Zurich) All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Unexport (deactivate) a GPIO.

Parameters
numLinux GPIO number.
Returns
SUCCESS in case of success, FAILURE otherwise.

Definition at line 39 of file gpio.c.

References ERROR, FAILURE, GPIO_PATH, rl_log(), and SUCCESS.

Referenced by hw_close().

+ Here is the call graph for this function:

int gpio_wait_interrupt ( int  num,
int  timeout 
)

Wait on GPIO interrupt.

Parameters
numLinux GPIO number.
timeoutMaximum waiting time (in ms). Set to 0 for infinite time out.
Returns
SUCCESS in case of interrupt, FAILURE otherwise.

Definition at line 212 of file gpio.c.

References ERROR, FAILURE, GPIO_PATH, MAX_PATH_LENGTH, MIN_BUTTON_TIME, and rl_log().

Referenced by main().

+ Here is the call graph for this function: