RocketLogger 2.1.1
gpio.h File Reference
#include <gpiod.h>
#include <time.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_FHR1   30
 GPIO number for forcing I1 high.
 
#define GPIO_FHR2   60
 GPIO number for forcing I2 high.
 
#define GPIO_LED_STATUS   45
 GPIO number of status LED.
 
#define GPIO_LED_ERROR   44
 GPIO number of error LED.
 
#define GPIO_BUTTON   26
 GPIO number of start/stop button.
 
#define GPIO_POWER   31
 GPIO number of RocketLogger cape power enable.
 

Typedefs

typedef enum gpio_mode gpio_mode_t
 
typedef enum gpio_interrupt gpio_interrupt_t
 
typedef struct gpiod_line gpio_t
 

Enumerations

enum  gpio_mode { GPIO_MODE_IN , GPIO_MODE_OUT }
 
enum  gpio_interrupt { GPIO_INTERRUPT_NONE , GPIO_INTERRUPT_RISING , GPIO_INTERRUPT_FALLING , GPIO_INTERRUPT_BOTH }
 

Functions

int gpio_init ()
 
void gpio_deinit ()
 
gpio_tgpio_setup (int gpio_number, gpio_mode_t mode, const char *name)
 
gpio_tgpio_setup_interrupt (int gpio_number, gpio_interrupt_t edge, const char *name)
 
void gpio_release (gpio_t *gpio)
 
int gpio_set_value (gpio_t *gpio, int value)
 
int gpio_get_value (gpio_t *gpio)
 
int gpio_wait_interrupt (gpio_t *gpio, const struct timespec *timeout)
 

Macro Definition Documentation

◆ GPIO_BUTTON

#define GPIO_BUTTON   26

GPIO number of start/stop button.

Definition at line 47 of file gpio.h.

◆ GPIO_FHR1

#define GPIO_FHR1   30

GPIO number for forcing I1 high.

Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group 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 39 of file gpio.h.

◆ GPIO_FHR2

#define GPIO_FHR2   60

GPIO number for forcing I2 high.

Definition at line 41 of file gpio.h.

◆ GPIO_LED_ERROR

#define GPIO_LED_ERROR   44

GPIO number of error LED.

Definition at line 45 of file gpio.h.

◆ GPIO_LED_STATUS

#define GPIO_LED_STATUS   45

GPIO number of status LED.

Definition at line 43 of file gpio.h.

◆ GPIO_POWER

#define GPIO_POWER   31

GPIO number of RocketLogger cape power enable.

Definition at line 49 of file gpio.h.

Typedef Documentation

◆ gpio_interrupt_t

GPIO interrupt edge definition

◆ gpio_mode_t

typedef enum gpio_mode gpio_mode_t

GPIO direction definition

◆ gpio_t

typedef struct gpiod_line gpio_t

GPIO type wrapper

Definition at line 72 of file gpio.h.

Enumeration Type Documentation

◆ gpio_interrupt

GPIO interrupt edge definition

Enumerator
GPIO_INTERRUPT_NONE 

No interrupt.

GPIO_INTERRUPT_RISING 

Interrupt on rising edge.

GPIO_INTERRUPT_FALLING 

Interrupt on falling edge.

GPIO_INTERRUPT_BOTH 

Interrupt on both edges.

Definition at line 62 of file gpio.h.

◆ gpio_mode

enum gpio_mode

GPIO direction definition

Enumerator
GPIO_MODE_IN 

GPIO read mode.

GPIO_MODE_OUT 

GPIO write mode.

Definition at line 54 of file gpio.h.

Function Documentation

◆ gpio_deinit()

void gpio_deinit ( )

Denitialize GPIO module.

Note
release any used GPIO pin first.

Definition at line 92 of file gpio.c.

References gpio_chip, and GPIO_CHIP_COUNT.

Referenced by hw_deinit(), and main().

◆ gpio_get_value()

int gpio_get_value ( gpio_t gpio)

Get the GPIO value.

Parameters
gpioGPIO resource to get the value
Returns
The read GPIO value, negative on failure with errno set accordingly

Definition at line 146 of file gpio.c.

◆ gpio_init()

int gpio_init ( )

Initialize GPIO module.

Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 77 of file gpio.c.

References ERROR, gpio_chip, GPIO_CHIP_COUNT, rl_log(), RL_LOG_ERROR, and SUCCESS.

Referenced by hw_init(), and main().

+ Here is the call graph for this function:

◆ gpio_release()

void gpio_release ( gpio_t gpio)

Release an aquired GPIO resource.

Parameters
gpioThe GPIO resource to release

Definition at line 130 of file gpio.c.

Referenced by hw_deinit(), and main().

◆ gpio_set_value()

int gpio_set_value ( gpio_t gpio,
int  value 
)

Set the GPIO value.

Parameters
gpioGPIO resource to set the output value
valueGPIO state to set (0 or 1)
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 135 of file gpio.c.

References ERROR.

Referenced by hw_deinit(), hw_init(), hw_sample(), and main().

◆ gpio_setup()

gpio_t * gpio_setup ( int  gpio_number,
gpio_mode_t  mode,
const char *  name 
)

Set up a specific GPIO pin for input/output.

Note
need to initialize GPIO module first.
Parameters
gpio_numberResource number of the GPIO to set up
modeGPIO mode (input or output) to configure
nameName to label the set up GPIO
Returns
Returns GPIO resource on success, NULL on failure with errno set accordingly

Definition at line 103 of file gpio.c.

References GPIO_MODE_IN, GPIO_MODE_OUT, rl_log(), and RL_LOG_ERROR.

Referenced by hw_init(), and main().

+ Here is the call graph for this function:

◆ gpio_setup_interrupt()

gpio_t * gpio_setup_interrupt ( int  gpio_number,
gpio_interrupt_t  edge,
const char *  name 
)

Set up a specific GPIO pin for interrupt event.

Parameters
gpio_numberResource number of the GPIO to set up
edgeGPIO interrupt edge to configure
nameName to label the set up GPIO
Returns
Returns GPIO resource on success, NULL on failure with errno set accordingly

Definition at line 148 of file gpio.c.

References GPIO_INTERRUPT_BOTH, GPIO_INTERRUPT_FALLING, GPIO_INTERRUPT_NONE, GPIO_INTERRUPT_RISING, rl_log(), and RL_LOG_ERROR.

Referenced by main().

+ Here is the call graph for this function:

◆ gpio_wait_interrupt()

int gpio_wait_interrupt ( gpio_t gpio,
const struct timespec *  timeout 
)

Wait for interrupt on GPIO pin.

Parameters
gpio_numberLinux sysfs GPIO resource number
timeoutPointer to timeout timespec, NULL for infinite timeout
Returns
Returns the GPIO pin value (0 or 1) on success, negative on failure with errno set accordingly

Definition at line 187 of file gpio.c.

References ERROR, GPIO_DEBOUNCE_DELAY_US, rl_log(), and RL_LOG_ERROR.

Referenced by main().

+ Here is the call graph for this function: