libpynq (release 5EWC0-2023 version 0.2.6 of 2023-10-24 17:28)
Loading...
Searching...
No Matches
GPIO library

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 io_t pin)
 
void gpio_set_direction (const io_t pin, const gpio_direction_t direction)
 
gpio_direction_t gpio_get_direction (const io_t pin)
 
void gpio_set_level (const io_t pin, const gpio_level_t level)
 
gpio_level_t gpio_get_level (const io_t pin)
 
void gpio_reset (void)
 
bool gpio_is_initialized (void)
 

Detailed Description

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

All functions use the IO pin number (io_t) from 0..IO_NUM_PINS-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)
{
// set pin A0 to be an input pin and read from it
// alternatively, set A0 to be an output pin and write to it
sleep_msec(100);
// set LED 0 as output
// turn LED 0 on
sleep_msec(1000);
leds_destroy(); // turn LEDs off
return EXIT_SUCCESS;
}
void gpio_set_direction(const io_t pin, const gpio_direction_t dir)
Set the IO pin as in input or output.
Definition gpio.c:81
void gpio_set_level(const io_t pin, const gpio_level_t level)
Set the level of the output IO pin. If the pin is configured as input, this function does nothing.
Definition gpio.c:104
gpio_level_t
Definition gpio.h:98
gpio_level_t gpio_get_level(const io_t pin)
Return the level of the IO pin.
Definition gpio.c:118
void gpio_init(void)
Definition gpio.c:40
@ GPIO_DIR_OUTPUT
Definition gpio.h:92
@ GPIO_DIR_INPUT
Definition gpio.h:90
@ GPIO_LEVEL_LOW
Definition gpio.h:100
@ GPIO_LEVEL_HIGH
Definition gpio.h:102
void leds_destroy(void)
Definition leds.c:96
@ IO_LD0
LED output pins.
Definition pinmap.h:91
@ IO_A0
Analog input pins (Arduino header).
Definition pinmap.h:67
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

Enumeration Type Documentation

◆ gpio_direction_t

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

Enumerator
GPIO_DIR_INPUT 

The IO pin is an input.

GPIO_DIR_OUTPUT 

The IO pin is an output.

Definition at line 88 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 98 of file gpio.h.

Function Documentation

◆ gpio_destroy()

void gpio_destroy ( void  )
extern

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 io_t  pin)
extern

Returns the direction the set pin is initialized in.

Parameters
pinThe IO 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 io_t  pin)
extern

Return the level of the IO pin.

Parameters
pinThe IO pin to read it state.
Returns
the output level of pin.
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  )
extern

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  )
extern

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  )
extern

Reset all IO 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 io_t  pin)
extern

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

Parameters
pinThe IO 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 io_t  pin,
const gpio_direction_t  direction 
)
extern

Set the IO pin as in input or output.

Parameters
pinThe IO 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 io_t  pin,
const gpio_level_t  level 
)
extern

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

Parameters
pinThe IO 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: