libpynq (release 5EWC0-2023 version 0.2.0 of 2023-08-28 20:33)
Loading...
Searching...
No Matches
GPIO library

Typedefs

typedef uint8_t gpio_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 gpio_t pin)
 
void gpio_set_direction (const gpio_t pin, const gpio_direction_t direction)
 
gpio_direction_t gpio_get_direction (const gpio_t pin)
 
void gpio_set_level (const gpio_t pin, const gpio_level_t level)
 
gpio_level_t gpio_get_level (const gpio_t pin)
 
void gpio_reset (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 pynq_destroy(void)
Reset and destroy the switchbox and GPIO of the PYNQ.
Definition libpynq.c:3
void gpio_set_level(const gpio_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:7
void gpio_set_direction(const gpio_t pin, const gpio_direction_t direction)
Set the GPIO pin as in input or output.
Definition gpio.c:5
void gpio_init(void)
Definition gpio.c:2
@ GPIO_DIR_OUTPUT
Definition gpio.h:83
@ GPIO_LEVEL_HIGH
Definition gpio.h:93
void leds_destroy(void)
Definition leds.c:5
#define SWB_LD0
LED output pins.
Definition pinmap.h:91
void sleep_msec(int msec)
Wait for msec milliseconds.
Definition util.c:2

Typedef Documentation

◆ gpio_t

typedef uint8_t gpio_t

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

Definition at line 99 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 79 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 89 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 3 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 gpio_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 6 of file gpio.c.

Here is the caller graph for this function:

◆ gpio_get_level()

gpio_level_t gpio_get_level ( const gpio_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 8 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 2 of file gpio.c.

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

◆ gpio_reset()

void gpio_reset ( void  )

Reset all GPIO pins.

Definition at line 18 of file gpio.c.

Here is the caller graph for this function:

◆ gpio_reset_pin()

void gpio_reset_pin ( const gpio_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 4 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 gpio_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 5 of file gpio.c.

Here is the caller graph for this function:

◆ gpio_set_level()

void gpio_set_level ( const gpio_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 7 of file gpio.c.

Here is the caller graph for this function: