pynq.gpio Module

The pynq.gpio module is a driver for reading and writing PS GPIO pins on a board. PS GPIO pins are not connected to the PL.

class pynq.gpio.GPIO(gpio_index, direction)[source]

Bases: object

Class to wrap Linux’s GPIO Sysfs API.

This GPIO class does not handle PL I/O.

index

int – The index of the GPIO, starting from the GPIO base.

direction

str – Input/output direction of the GPIO.

path

str – The path of the GPIO device in the linux system.

direction

Direction of the GPIO pin - either ‘in’ or ‘out’ – str

static get_gpio_base()[source]

This method returns the GPIO base using Linux’s GPIO Sysfs API.

This is a static method. To use:

>>> from pynq import GPIO
>>> gpio = GPIO.get_gpio_base()

Note

For path ‘/sys/class/gpio/gpiochip138/’, this method returns 138.

Returns:The GPIO index of the base.
Return type:int
static get_gpio_pin(gpio_user_index)[source]

This method returns a GPIO instance for PS GPIO pins.

Users only need to specify an index starting from 0; this static method will map this index to the correct Linux GPIO pin number.

Note

The GPIO pin number can be calculated using: GPIO pin number = GPIO base + GPIO offset + user index e.g. The GPIO base is 138, and pin 54 is the base GPIO offset. Then the Linux GPIO pin would be (138 + 54 + 0) = 192.

Parameters:gpio_user_index (int) – The index specified by users, starting from 0.
Returns:The Linux Sysfs GPIO pin number.
Return type:int
index

Index of the GPIO pin – int

path

Path to the GPIO pin in the filesystem – str

read()[source]

The method to read a value from the GPIO.

Returns:An integer read from the GPIO
Return type:int
write(value)[source]

The method to write a value into the GPIO.

Parameters:value (int) – An integer value, either 0 or 1
Returns:
Return type:None