The PYNQ Microblaze library is the primary way of interacting with Microblaze subsystems. It consists of a set of wrapper drivers for I/O controllers and is optimised for the situation where these are connected to a PYNQ I/O switch.
This document describes all of the C functions and types provided by the API - see the Python/C interoperability guide for more details on how this API translates into Python.
This library provides GPIO, I2C, SPI, PWM/Timer and UART functionality.
All of these libraries follow the same design. Each defines a type which
represents a handle to the device. *_open
functions are used in
situations where there is an I/O switch in the design and takes a set of
pins to connect the device to. The number of pins depends on the
protocol. *_open_device
opens a specific device and can be passed
either the base address of the controller or the index as defined by the
BSP. *_close
is used to release a handle.
GPIO devices allow for one or multiple pins to be read and written
directly. All of these functions are in gpio.h
A handle to one or more pins which can be set simultaneously.
Returns a new handle to a GPIO device for a specific pin on the I/O switch. This function can only be called if there is an I/O switch in the design.
Returns a handle to an AXI GPIO controller based either on the base address or device index. The handle will allow for all pins on channel 1 to be set simultaneously.
Returns a new handle tied to the specified pins of the controller. This function does not change the configuration of the parent handle.
Sets the direction of all pins tied to the specified handle. The
direction can either be GPIO_IN
or GPIO_OUT
.
Sets the value of the output pins represented by the handle. If the handle represents multiple pins then the least significant bit refers to the lowest index pin. Writing to pins configured as input has no effect.
Reads the value of input pins represented by the handle, If the handle represents multiple pins then the least significant bit refers to the lowest index pin. Read from pins configured as output results in 0 being returned.
Returns the specified pins to high-impedance output and closes the device.
The I2C driver is designed for master operation only and provides
interfaces to read and write from a slave device. All of these functions
are in i2c.h
.
Represents an I2C master. It is possible for multiple handles to reference the same master device.
Open an I2C device attached to an I/O switch configured to use the specified pins. Calling this function will disconnect any previously assigned pins and return them to a high-impedance state.
Open an I2C master by base address or ID
Issue a read command to the specified slave. buffer
is an array
allocated by the caller of at least length length
.
Issue a write command to the specified slave.
Close the I2C device.
SPI operates on a synchronous transfer of data so rather than read and
write, only a transfer
function is provided. These functions are all
provided by spi.h
.
Handle to a SPI master.
Opens a SPI master on the specified pins. If a pin is not needed for a
device, -1
can be passed in to leave it unconnected.
Opens a SPI master by base address or device ID.
Configures the SPI master with the specified clock phase and polarity. These settings are global to all handles to a SPI master.
Transfer bytes to and from the SPI slave. Both write_data
and
write_data
should be allocated by the caller and NULL. Buffers
should be at least of length length
.
Closes a SPI master
Timer devices serve two purposes. They can either be used to output PWM
signals or as program timers for inserting accurate delays. It is not
possible to use these functions simultaneously and attempting to delay
while PWM is in operation will result in undefined behavior. All of these
functions are in timer.h
.
Handle to an AXI timer
Open an AXI timer attached to the specified pin
Open an AXI timer by address or device ID
Delay the program by a specified number of cycles
Generate a PWM signal using the specified timer
Stop the PWM output
Close the specified timer
Delay the program by a number of microseconds using the default delay timer (timer index 0).
Delay the program by a number of milliseconds using the default delay timer (timer index 0).
This device driver controls a UART master.
Handle to a UART master device.
Open a UART device on the specified pins
Open a UART device by base address or index
Read a fixed length of data from the UART
Write a block of data to the UART.
Close the handle.