Parallel IO
Introduction
The Parallel IO peripheral is a general purpose parallel interface that can be used to connect to external devices such as LED matrix, LCD display, Printer and Camera. The peripheral has independent TX and RX units. Each unit can have up to 8 or 16 data signals plus 1 or 2 clock signals. 1
Warning
At the moment, the Parallel IO driver only supports TX mode. The RX feature is still working in progress.
Application Examples
Simple REG LED Matrix with HUB75 interface: peripherals/parlio/simple_rgb_led_matrix.
API Reference
Header File
Functions
-
esp_err_t parlio_new_tx_unit(const parlio_tx_unit_config_t *config, parlio_tx_unit_handle_t *ret_unit)
Create a Parallel IO TX unit.
- Parameters
config -- [in] Parallel IO TX unit configuration
ret_unit -- [out] Returned Parallel IO TX unit handle
- Returns
ESP_OK: Create Parallel IO TX unit successfully
ESP_ERR_INVALID_ARG: Create Parallel IO TX unit failed because of invalid argument
ESP_ERR_NO_MEM: Create Parallel IO TX unit failed because of out of memory
ESP_ERR_NOT_FOUND: Create Parallel IO TX unit failed because all TX units are used up and no more free one
ESP_ERR_NOT_SUPPORTED: Create Parallel IO TX unit failed because some feature is not supported by hardware, e.g. clock gating
ESP_FAIL: Create Parallel IO TX unit failed because of other error
-
esp_err_t parlio_del_tx_unit(parlio_tx_unit_handle_t unit)
Delete a Parallel IO TX unit.
- Parameters
unit -- [in] Parallel IO TX unit that created by
parlio_new_tx_unit
- Returns
ESP_OK: Delete Parallel IO TX unit successfully
ESP_ERR_INVALID_ARG: Delete Parallel IO TX unit failed because of invalid argument
ESP_ERR_INVALID_STATE: Delete Parallel IO TX unit failed because it is still in working
ESP_FAIL: Delete Parallel IO TX unit failed because of other error
-
esp_err_t parlio_tx_unit_enable(parlio_tx_unit_handle_t unit)
Enable the Parallel IO TX unit.
Note
This function will transit the driver state from init to enable
Note
This function will acquire a PM lock that might be installed during channel allocation
Note
If there're transaction pending in the queue, this function will pick up the first one and start the transfer
- Parameters
unit -- [in] Parallel IO TX unit that created by
parlio_new_tx_unit
- Returns
ESP_OK: Enable Parallel IO TX unit successfully
ESP_ERR_INVALID_ARG: Enable Parallel IO TX unit failed because of invalid argument
ESP_ERR_INVALID_STATE: Enable Parallel IO TX unit failed because it is already enabled
ESP_FAIL: Enable Parallel IO TX unit failed because of other error
-
esp_err_t parlio_tx_unit_disable(parlio_tx_unit_handle_t unit)
Disable the Parallel IO TX unit.
Note
This function will transit the driver state from enable to init
Note
This function will release the PM lock that might be installed during channel allocation
Note
If one transaction is undergoing, this function will terminate it immediately
- Parameters
unit -- [in] Parallel IO TX unit that created by
parlio_new_tx_unit
- Returns
ESP_OK: Disable Parallel IO TX unit successfully
ESP_ERR_INVALID_ARG: Disable Parallel IO TX unit failed because of invalid argument
ESP_ERR_INVALID_STATE: Disable Parallel IO TX unit failed because it's not enabled yet
ESP_FAIL: Disable Parallel IO TX unit failed because of other error
-
esp_err_t parlio_tx_unit_register_event_callbacks(parlio_tx_unit_handle_t tx_unit, const parlio_tx_event_callbacks_t *cbs, void *user_data)
Set event callbacks for Parallel IO TX unit.
Note
User can deregister a previously registered callback by calling this function and setting the callback member in the
cbs
structure to NULL.Note
When CONFIG_PARLIO_ISR_IRAM_SAFE is enabled, the callback itself and functions called by it should be placed in IRAM. The variables used in the function should be in the SRAM as well. The
user_data
should also reside in SRAM.- Parameters
tx_unit -- [in] Parallel IO TX unit that created by
parlio_new_tx_unit
cbs -- [in] Group of callback functions
user_data -- [in] User data, which will be passed to callback functions directly
- Returns
ESP_OK: Set event callbacks successfully
ESP_ERR_INVALID_ARG: Set event callbacks failed because of invalid argument
ESP_FAIL: Set event callbacks failed because of other error
-
esp_err_t parlio_tx_unit_transmit(parlio_tx_unit_handle_t tx_unit, const void *payload, size_t payload_bits, const parlio_transmit_config_t *config)
Transmit data on by Parallel IO TX unit.
Note
After the function returns, it doesn't mean the transaction is finished. This function only constructs a transcation structure and push into a queue.
- Parameters
tx_unit -- [in] Parallel IO TX unit that created by
parlio_new_tx_unit
payload -- [in] Pointer to the data to be transmitted
payload_bits -- [in] Length of the data to be transmitted, in bits
config -- [in] Transmit configuration
- Returns
ESP_OK: Transmit data successfully
ESP_ERR_INVALID_ARG: Transmit data failed because of invalid argument
ESP_ERR_INVALID_STATE: Transmit data failed because the Parallel IO TX unit is not enabled
ESP_FAIL: Transmit data failed because of other error
-
esp_err_t parlio_tx_unit_wait_all_done(parlio_tx_unit_handle_t tx_unit, int timeout_ms)
Wait for all pending TX transactions done.
- Parameters
tx_unit -- [in] Parallel IO TX unit that created by
parlio_new_tx_unit
timeout_ms -- [in] Timeout in milliseconds,
-1
means to wait forever
- Returns
ESP_OK: All pending TX transactions is finished and recycled
ESP_ERR_INVALID_ARG: Wait for all pending TX transactions done failed because of invalid argument
ESP_ERR_TIMEOUT: Wait for all pending TX transactions done timeout
ESP_FAIL: Wait for all pending TX transactions done failed because of other error
Structures
-
struct parlio_tx_unit_config_t
Parallel IO TX unit configuration.
Public Members
-
parlio_clock_source_t clk_src
Parallel IO internal clock source
-
gpio_num_t clk_in_gpio_num
If the clock source is input from external, set the corresponding GPIO number. Otherwise, set to
-1
and the driver will use the internalclk_src
as clock source. This option has higher priority thanclk_src
-
uint32_t input_clk_src_freq_hz
Frequency of the input clock source, valid only if
clk_in_gpio_num
is not-1
-
uint32_t output_clk_freq_hz
Frequency of the output clock. It's divided from either internal
clk_src
or external clock source
-
size_t data_width
Parallel IO data width, can set to 1/2/4/8/..., but can't bigger than PARLIO_TX_UNIT_MAX_DATA_WIDTH
-
gpio_num_t data_gpio_nums[PARLIO_TX_UNIT_MAX_DATA_WIDTH]
Parallel IO data GPIO numbers, if any GPIO is not used, you can set it to
-1
-
gpio_num_t clk_out_gpio_num
GPIO number of the output clock signal, the clock is synced with TX data
-
gpio_num_t valid_gpio_num
GPIO number of the valid signal, which stays high when transferring data. Note that, the valid signal will always occupy the MSB data bit
-
size_t trans_queue_depth
Depth of internal transaction queue
-
size_t max_transfer_size
Maximum transfer size in one transaction, in bytes. This decides the number of DMA nodes will be used for each transaction
-
parlio_sample_edge_t sample_edge
Parallel IO sample edge
-
parlio_bit_pack_order_t bit_pack_order
Set the order of packing the bits into bytes (only works when
data_width
< 8)
-
uint32_t clk_gate_en
Enable TX clock gating, the output clock will be controlled by the MSB bit of the data bus, i.e. by data_gpio_nums[PARLIO_TX_UNIT_MAX_DATA_WIDTH-1]. High level to enable the clock output, low to disable
-
uint32_t io_loop_back
For debug/test, the signal output from the GPIO will be fed to the input path as well
-
struct parlio_tx_unit_config_t::[anonymous] flags
Extra configuration flags
-
parlio_clock_source_t clk_src
-
struct parlio_tx_done_event_data_t
Type of Parallel IO TX done event data.
-
struct parlio_tx_event_callbacks_t
Group of Parallel IO TX callbacks.
Note
The callbacks are all running under ISR environment
Note
When CONFIG_PARLIO_ISR_IRAM_SAFE is enabled, the callback itself and functions called by it should be placed in IRAM. The variables used in the function should be in the SRAM as well.
Public Members
-
parlio_tx_done_callback_t on_trans_done
Event callback, invoked when one transmission is finished
-
parlio_tx_done_callback_t on_trans_done
Type Definitions
-
typedef bool (*parlio_tx_done_callback_t)(parlio_tx_unit_handle_t tx_unit, const parlio_tx_done_event_data_t *edata, void *user_ctx)
Prototype of parlio tx event callback.
- Param tx_unit
[in] Parallel IO TX unit that created by
parlio_new_tx_unit
- Param edata
[in] Point to Parallel IO TX event data. The lifecycle of this pointer memory is inside this function, user should copy it into static memory if used outside this function.
- Param user_ctx
[in] User registered context, passed from
parlio_tx_unit_register_event_callbacks
- Return
Whether a high priority task has been waken up by this callback function
Header File
Type Definitions
-
typedef struct parlio_tx_unit_t *parlio_tx_unit_handle_t
Type of Parallel IO TX unit handle.
Header File
Macros
-
PARLIO_TX_UNIT_MAX_DATA_WIDTH
Maximum data width of TX unit.
Type Definitions
-
typedef soc_periph_parlio_clk_src_t parlio_clock_source_t
Parallel IO clock source.
Note
User should select the clock source based on the power and resolution requirement
Enumerations
-
enum parlio_sample_edge_t
Parallel IO sample edge.
Values:
-
enumerator PARLIO_SAMPLE_EDGE_NEG
Sample data on falling edge of clock
-
enumerator PARLIO_SAMPLE_EDGE_POS
Sample data on rising edge of clock
-
enumerator PARLIO_SAMPLE_EDGE_NEG
-
enum parlio_bit_pack_order_t
Parallel IO bit packing order.
Data in memory: Byte 0: MSB < B0.7 B0.6 B0.5 B0.4 B0.3 B0.2 B0.1 B0.0 > LSB Byte 1: MSB < B1.7 B1.6 B1.5 B1.4 B1.3 B1.2 B1.1 B1.0 > LSB
Output on line (PARLIO_BIT_PACK_ORDER_LSB): Cycle 0 Cycle 1 Cycle 2 —> time GPIO 0: B0.0 B0.4 B1.0 GPIO 1: B0.1 B0.5 B1.1 GPIO 2: B0.2 B0.6 B1.2 GPIO 3: B0.3 B0.7 B1.3
Output on line (PARLIO_BIT_PACK_ORDER_MSB): Cycle 0 Cycle 1 Cycle 2 —> time GPIO 0: B0.4 B0.0 B1.4 GPIO 1: B0.5 B0.1 B1.5 GPIO 2: B0.6 B0.2 B1.6 GPIO 3: B0.7 B0.3 B1.7
Values:
-
enumerator PARLIO_BIT_PACK_ORDER_LSB
Bit pack order: LSB
-
enumerator PARLIO_BIT_PACK_ORDER_MSB
Bit pack order: MSB
-
enumerator PARLIO_BIT_PACK_ORDER_LSB
- 1
Different ESP chip series might have different numbers of PARLIO TX/RX instances, and the maximum data bus can also be different. For more details, please refer to ESP32-C6 Technical Reference Manual > Chapter Parallel IO (PARLIO) [PDF]. The driver will not forbid you from applying for more driver objects, but it will return error when all available hardware resources are used up. Please always check the return value when doing resource allocation (e.g.
parlio_new_tx_unit()
).