libpynq (release 5EWC0-2023 version 0.2.2 of 2023-09-24 22:22)
Loading...
Searching...
No Matches
GPIO library

Macros

#define gpio_t   pin_t
 

Enumerations

enum  gpio_direction_t { GPIO_DIR_INPUT = 0 , GPIO_DIR_OUTPUT = 1 }
 
enum  gpio_level_t { GPIO_LEVEL_LOW = 0 , GPIO_LEVEL_HIGH = 1 }
 

Functions

void gpio_init (void)
 
void gpio_destroy (void)
 
void gpio_reset_pin (const pin_t pin)
 
void gpio_set_direction (const pin_t pin, const gpio_direction_t direction)
 
gpio_direction_t gpio_get_direction (const pin_t pin)
 
void gpio_set_level (const pin_t pin, const gpio_level_t level)
 
gpio_level_t gpio_get_level (const pin_t pin)
 
void gpio_reset (void)
 
bool gpio_is_initialized (void)
 

Detailed Description

Functions for General Purpose I/O (GPIO) access to leds, buttons, etc.

All functions use a GPIO number from 0..NUM_PINS_SWITCHBOX-1.

The LED and button libraries are built on top of this library, but do not expose the full functionality of this library. Use this library when that is required. Also see the I/O switchbox (switchbox.h) and pin mapping (pinmap.h).

In particular, be aware that the numbering used in the high-level libraries is different from the underlying GPIO numbering.

An example of using this library to turn LED0 on:

#include <libpynq.h>
int main (void)
{
// initialize the Library
// set LED 0 as output
// turn LED 0 on
sleep_msec(1000);
// cleanup after use
leds_destroy(); // turn LEDs off
return EXIT_SUCCESS;
}
void gpio_set_direction(const pin_t pin, const gpio_direction_t dir)
Set the GPIO pin as in input or output.
Definition gpio.c:81
void gpio_set_level(const pin_t pin, const gpio_level_t level)
Set the level of the output GPIO pin. If the pin is configured as input, this function does nothing.
Definition gpio.c:104
void gpio_init(void)
Definition gpio.c:40
@ GPIO_DIR_OUTPUT
Definition gpio.h:85
@ GPIO_LEVEL_HIGH
Definition gpio.h:95
void leds_destroy(void)
Definition leds.c:96
@ SWB_LD0
LED output pins.
Definition pinmap.h:91
void sleep_msec(int msec)
Wait for msec milliseconds.
Definition util.c:32
void pynq_destroy(void)
Reset and destroy the switchbox and GPIO of the PYNQ.
Definition libpynq.c:35

Macro Definition Documentation

◆ gpio_t

#define gpio_t   pin_t

For backwards compatibility. Map gpio_t to the pin_t type.

Definition at line 102 of file gpio.h.

Enumeration Type Documentation

◆ gpio_direction_t

Enumerate the direction state (input/output) of the pin

Enumerator
GPIO_DIR_INPUT 

The GPIO pin is an input.

GPIO_DIR_OUTPUT 

The GPIO pin is an output.

Definition at line 81 of file gpio.h.

◆ gpio_level_t

Enumerate the signal level.

Enumerator
GPIO_LEVEL_LOW 

A low signal

GPIO_LEVEL_HIGH 

A high signal

Definition at line 91 of file gpio.h.

Function Documentation

◆ gpio_destroy()

void gpio_destroy ( void  )

De-initialize the GPIO library. This releases the memory map and memory allocated by gpio_init.

Definition at line 47 of file gpio.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpio_get_direction()

gpio_direction_t gpio_get_direction ( const pin_t  pin)

Returns the direction the set pin is initialized in.

Parameters
pinThe GPIO pin to read the direction set in the shared memory system on the ARM processor.
Warning
Fails with program exit when pin is outside valid range.

Definition at line 95 of file gpio.c.

Here is the caller graph for this function:

◆ gpio_get_level()

gpio_level_t gpio_get_level ( const pin_t  pin)

Return the level of the GPIO pin.

Parameters
pinThe GPIO pin to read it state.
Returns
the output level of pin using enum gpio_level_t.
Warning
Fails with program exit when pin is outside valid range.

Definition at line 118 of file gpio.c.

Here is the caller graph for this function:

◆ gpio_init()

void gpio_init ( void  )

Initializes the GPIO library.

Definition at line 40 of file gpio.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpio_is_initialized()

bool gpio_is_initialized ( void  )

Check if gpio library is initialized.

Returns
true if initialize, false if not.

Definition at line 35 of file gpio.c.

Here is the caller graph for this function:

◆ gpio_reset()

void gpio_reset ( void  )

Reset all GPIO pins.

Definition at line 62 of file gpio.c.

Here is the caller graph for this function:

◆ gpio_reset_pin()

void gpio_reset_pin ( const pin_t  pin)

Function is currently a no-op placeholder for arduino compatibility.

Parameters
pinThe GPIO pin to reset.
Warning
Fails with program exit when LEDs were not initialized with the correct mode.

Definition at line 55 of file gpio.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpio_set_direction()

void gpio_set_direction ( const pin_t  pin,
const gpio_direction_t  direction 
)

Set the GPIO pin as in input or output.

Parameters
pinThe GPIO pin to modify direction for.
directionThe direction to set on the pin.
Warning
Fails with program exit when pin or direction is outside valid range.

Definition at line 81 of file gpio.c.

Here is the caller graph for this function:

◆ gpio_set_level()

void gpio_set_level ( const pin_t  pin,
const gpio_level_t  level 
)

Set the level of the output GPIO pin. If the pin is configured as input, this function does nothing.

Parameters
pinThe GPIO pin to modify direction for
levelThe level to set on the pin.
Warning
Fails with program exit when pin is outside valid range.

Definition at line 104 of file gpio.c.

Here is the caller graph for this function: