epio
A cycle-accurate RP2350 PIO emulator
Loading...
Searching...
No Matches
Functions
GPIO API

Functions for driving and reading GPIO pin states. More...

Functions

EPIO_EXPORT void epio_drive_gpios_ext (epio_t *epio, uint64_t gpios, uint64_t level)
 Drive a set of GPIOs to specified levels from an external source.
 
void epio_set_gpio_input_inverted (epio_t *epio, uint8_t pin, uint8_t inverted)
 Set a GPIO pin as inverted or non-inverted.
 
uint8_t epio_get_gpio_input_inverted (epio_t *epio, uint8_t pin)
 Get the inversion state of a GPIO pin.
 
void epio_set_gpio_output_control (epio_t *epio, uint8_t pin, uint8_t block)
 Set GPIO output control for a pin to a specific block.
 
void epio_clear_gpio_output_control (epio_t *epio, uint8_t pin, uint8_t block)
 Clear GPIO output control for a pin.
 
uint8_t epio_block_can_control_gpio_output (epio_t *epio, uint8_t block, uint8_t pin)
 Check if a block can control the output of a GPIO pin.
 
uint64_t epio_get_gpio_output_control (epio_t *epio, uint8_t block)
 Get the GPIO output control for a block.
 
EPIO_EXPORT uint8_t epio_get_gpio_input (epio_t *epio, uint8_t pin)
 Read the current input level of a single GPIO pin.
 
EPIO_EXPORT void epio_init_gpios (epio_t *epio)
 Reset all GPIOs to their hardware reset defaults.
 
EPIO_EXPORT void epio_set_gpio_force_input_low (epio_t *epio, uint8_t pin, uint8_t force_low)
 Force a GPIO pin configured as an input to present a low level.
 
EPIO_EXPORT void epio_set_gpio_force_input_high (epio_t *epio, uint8_t pin, uint8_t force_high)
 Force a GPIO pin configured as an input to present a high level.
 
EPIO_EXPORT uint8_t epio_get_gpio_force_input_low (epio_t *epio, uint8_t pin)
 Get whether a GPIO pin configured as an input has a forced input level low.
 
EPIO_EXPORT uint8_t epio_get_gpio_force_input_high (epio_t *epio, uint8_t pin)
 Get whether a GPIO pin configured as an input has a forced input level high.
 
EPIO_EXPORT void epio_set_gpio_input (epio_t *epio, uint8_t pin)
 Configure a GPIO pin as an input.
 
EPIO_EXPORT void epio_set_gpio_output (epio_t *epio, uint8_t pin)
 Configure a GPIO pin as an output.
 
EPIO_EXPORT void epio_set_gpio_input_level (epio_t *epio, uint8_t pin, uint8_t level)
 Set the level of a GPIO configured as an input.
 
EPIO_EXPORT void epio_set_gpio_output_level (epio_t *epio, uint8_t pin, uint8_t level)
 Set the level of a GPIO configured as an output.
 
EPIO_EXPORT uint64_t epio_read_pin_states (epio_t *epio)
 Read the current state of all GPIO pins.
 
EPIO_EXPORT uint64_t epio_read_driven_pins (epio_t *epio)
 Read the set of GPIO pins currently being driven by PIO.
 
EPIO_EXPORT uint64_t epio_read_pull_up_pins (epio_t *epio)
 Return a bitmask of all GPIO pins that have a pull-up configured.
 
EPIO_EXPORT uint64_t epio_read_pull_down_pins (epio_t *epio)
 Return a bitmask of all GPIO pins that have a pull-down configured.
 
EPIO_EXPORT void epio_set_gpio_pull_up (epio_t *epio, uint8_t pin, uint8_t enable)
 Enable or disable a pull-up resistor on a GPIO pin.
 
EPIO_EXPORT void epio_set_gpio_pull_down (epio_t *epio, uint8_t pin, uint8_t enable)
 Enable or disable a pull-down resistor on a GPIO pin.
 
EPIO_EXPORT void epio_set_gpio_pull_none (epio_t *epio, uint8_t pin)
 Disable both pull-up and pull-down resistors on a GPIO pin.
 
EPIO_EXPORT uint8_t epio_get_gpio_pull_up (epio_t *epio, uint8_t pin)
 Get the pull-up state of a GPIO pin.
 
EPIO_EXPORT uint8_t epio_get_gpio_pull_down (epio_t *epio, uint8_t pin)
 Get the pull-down state of a GPIO pin.
 
EPIO_EXPORT void epio_set_gpio_input_only (epio_t *epio, uint8_t pin, uint8_t input_only)
 Mark a GPIO pin as input-only (output driver disabled).
 
EPIO_EXPORT uint8_t epio_get_gpio_input_only (epio_t *epio, uint8_t pin)
 Get the input-only state of a GPIO pin.
 
EPIO_EXPORT void epio_set_gpio_drive (epio_t *epio, uint8_t pin, uint8_t strength)
 Set the drive strength for a GPIO output pin.
 
EPIO_EXPORT uint8_t epio_get_gpio_drive (epio_t *epio, uint8_t pin)
 Get the configured drive strength for a GPIO output pin.
 
EPIO_EXPORT void epio_set_gpio_slew_fast (epio_t *epio, uint8_t pin, uint8_t fast)
 Set the slew rate for a GPIO output pin.
 
EPIO_EXPORT uint8_t epio_get_gpio_slew_fast (epio_t *epio, uint8_t pin)
 Get the configured slew rate for a GPIO output pin.
 
EPIO_EXPORT void epio_set_float_mode (epio_t *epio, epio_float_mode_t mode)
 Set the float mode for undriven PULL_NONE pins.
 
EPIO_EXPORT void epio_set_float_seed (epio_t *epio, uint32_t seed)
 Seed the PRNG used by EPIO_FLOAT_RANDOM float mode.
 

Detailed Description

Functions for driving and reading GPIO pin states.

Function Documentation

◆ epio_block_can_control_gpio_output()

uint8_t epio_block_can_control_gpio_output ( epio_t *  epio,
uint8_t  block,
uint8_t  pin 
)

Check if a block can control the output of a GPIO pin.

Returns 1 if the specified block has output control for the specified GPIO pin, meaning it can drive that pin as an output when configured to do so. Returns 0 otherwise.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
pinGPIO pin number (0 to NUM_GPIOS-1).
Returns
1 if the block can control the GPIO pin's output, 0

◆ epio_clear_gpio_output_control()

void epio_clear_gpio_output_control ( epio_t *  epio,
uint8_t  pin,
uint8_t  block 
)

Clear GPIO output control for a pin.

This configures a GPIO pin to not to be able to be driven by the block.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
blockPIO block index (0 to NUM_PIO_BLOCKS-1).

◆ epio_drive_gpios_ext()

EPIO_EXPORT void epio_drive_gpios_ext ( epio_t *  epio,
uint64_t  gpios,
uint64_t  level 
)

Drive a set of GPIOs to specified levels from an external source.

Simulates external hardware driving GPIO pins. gpios is a bitmask of pins to affect; level is a bitmask of the desired levels for those pins. Pins not set in gpios are restored to their configured pull state (pull-up → 1, pull-down → 0, pull-none → float mode value).

This function only affects the input state of the specified pins.

Parameters
epioThe epio instance.
gpiosBitmask of GPIO pins to drive (bit N = GPIO N).
levelBitmask of desired pin levels for the selected pins.

◆ epio_get_gpio_drive()

EPIO_EXPORT uint8_t epio_get_gpio_drive ( epio_t *  epio,
uint8_t  pin 
)

Get the configured drive strength for a GPIO output pin.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
Returns
Drive strength value (APIO_DRIVE_*).

◆ epio_get_gpio_force_input_high()

EPIO_EXPORT uint8_t epio_get_gpio_force_input_high ( epio_t *  epio,
uint8_t  pin 
)

Get whether a GPIO pin configured as an input has a forced input level high.

Returns 1 if the specified pin is configured to force input high, 0 otherwise.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).

◆ epio_get_gpio_force_input_low()

EPIO_EXPORT uint8_t epio_get_gpio_force_input_low ( epio_t *  epio,
uint8_t  pin 
)

Get whether a GPIO pin configured as an input has a forced input level low.

Returns 1 if the specified pin is configured to force input low, 0 otherwise.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).

◆ epio_get_gpio_input()

EPIO_EXPORT uint8_t epio_get_gpio_input ( epio_t *  epio,
uint8_t  pin 
)

Read the current input level of a single GPIO pin.

Returns the level that the specified pin presents as an input to the PIO state machines, accounting for both external and PIO-driven states.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
Returns
Pin level: 0 or 1.

◆ epio_get_gpio_input_inverted()

uint8_t epio_get_gpio_input_inverted ( epio_t *  epio,
uint8_t  pin 
)

Get the inversion state of a GPIO pin.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
Returns
1 if the pin is inverted, 0 if it is non-inverted.

◆ epio_get_gpio_input_only()

EPIO_EXPORT uint8_t epio_get_gpio_input_only ( epio_t *  epio,
uint8_t  pin 
)

Get the input-only state of a GPIO pin.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
Returns
1 if the pin is input-only, 0 otherwise.

◆ epio_get_gpio_output_control()

uint64_t epio_get_gpio_output_control ( epio_t *  epio,
uint8_t  block 
)

Get the GPIO output control for a block.

Returns a bitmask of which GPIO pins are configured to be driven by the specified block when they are configured as outputs.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
Returns
Bitmask of GPIO pins controlled by this block (bit N = GPIO N).

◆ epio_get_gpio_pull_down()

EPIO_EXPORT uint8_t epio_get_gpio_pull_down ( epio_t *  epio,
uint8_t  pin 
)

Get the pull-down state of a GPIO pin.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
Returns
1 if pull-down is enabled, 0 otherwise.

◆ epio_get_gpio_pull_up()

EPIO_EXPORT uint8_t epio_get_gpio_pull_up ( epio_t *  epio,
uint8_t  pin 
)

Get the pull-up state of a GPIO pin.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
Returns
1 if pull-up is enabled, 0 otherwise.

◆ epio_get_gpio_slew_fast()

EPIO_EXPORT uint8_t epio_get_gpio_slew_fast ( epio_t *  epio,
uint8_t  pin 
)

Get the configured slew rate for a GPIO output pin.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
Returns
1 if slew rate is fast, 0 if slow.

◆ epio_init_gpios()

EPIO_EXPORT void epio_init_gpios ( epio_t *  epio)

Reset all GPIOs to their hardware reset defaults.

Sets all pins to input direction, pull-down enabled, 4 mA drive strength, slow slew. Clears force, inversion, input-only, and output-control state. Does not affect the float mode setting. Useful for resetting between test cases.

Parameters
epioThe epio instance.

◆ epio_read_driven_pins()

EPIO_EXPORT uint64_t epio_read_driven_pins ( epio_t *  epio)

Read the set of GPIO pins currently being driven by PIO.

Returns a bitmask indicating which GPIO pins are configured as outputs and are being actively driven by the PIO state machines combined with any externally driven pins. This reflects the driving state by the RP2350, and any undriven pins fall back to their pull configuration.

Bit N corresponds to GPIO N, with GPIO0 being the LSB.

Parameters
epioThe epio instance.
Returns
Bitmask of PIO-driven GPIO pins (bit N = GPIO N).
See also
epio_read_pin_states()

◆ epio_read_pin_states()

EPIO_EXPORT uint64_t epio_read_pin_states ( epio_t *  epio)

Read the current state of all GPIO pins.

Returns the logical level of all GPIO pins as currently observed, reflecting both PIO-driven outputs and externally driven inputs. Bit N corresponds to GPIO N, with GPIO0 being the LSB.

This function returns inverted states, if the pin is configured as such

Parameters
epioThe epio instance.
Returns
Bitmask of GPIO pin states (bit N = GPIO N).
See also
epio_read_driven_pins()

◆ epio_read_pull_down_pins()

EPIO_EXPORT uint64_t epio_read_pull_down_pins ( epio_t *  epio)

Return a bitmask of all GPIO pins that have a pull-down configured.

Bit N corresponds to GPIO N, with GPIO0 being the LSB.

Parameters
epioThe epio instance.
Returns
Bitmask of GPIO pins with pull-down enabled.
See also
epio_read_pull_up_pins()

◆ epio_read_pull_up_pins()

EPIO_EXPORT uint64_t epio_read_pull_up_pins ( epio_t *  epio)

Return a bitmask of all GPIO pins that have a pull-up configured.

Bit N corresponds to GPIO N, with GPIO0 being the LSB.

Parameters
epioThe epio instance.
Returns
Bitmask of GPIO pins with pull-up enabled.
See also
epio_read_pull_down_pins()

◆ epio_set_float_mode()

EPIO_EXPORT void epio_set_float_mode ( epio_t *  epio,
epio_float_mode_t  mode 
)

Set the float mode for undriven PULL_NONE pins.

Controls the level returned by epio_get_gpio_input() for pins with no pull resistor configured that are not being externally driven. Does not affect pins with an explicit pull-up or pull-down.

Default: EPIO_FLOAT_HIGH.

Parameters
epioThe epio instance.
modeOne of EPIO_FLOAT_LOW, EPIO_FLOAT_HIGH, EPIO_FLOAT_RANDOM.

◆ epio_set_float_seed()

EPIO_EXPORT void epio_set_float_seed ( epio_t *  epio,
uint32_t  seed 
)

Seed the PRNG used by EPIO_FLOAT_RANDOM float mode.

Allows deterministic replay of failing test runs: record the seed that produced the failure and pass it here to reproduce the exact same sequence.

Parameters
epioThe epio instance.
seed32-bit seed value.

◆ epio_set_gpio_drive()

EPIO_EXPORT void epio_set_gpio_drive ( epio_t *  epio,
uint8_t  pin,
uint8_t  strength 
)

Set the drive strength for a GPIO output pin.

strength must be one of APIO_DRIVE_2MA, APIO_DRIVE_4MA, APIO_DRIVE_8MA, APIO_DRIVE_12MA. Stored per-pin; has no current behavioural effect in emulation. Hardware reset default: APIO_DRIVE_4MA.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
strengthDrive strength value (APIO_DRIVE_*).

◆ epio_set_gpio_force_input_high()

EPIO_EXPORT void epio_set_gpio_force_input_high ( epio_t *  epio,
uint8_t  pin,
uint8_t  force_high 
)

Force a GPIO pin configured as an input to present a high level.

This sets the emulated hardware INOVER state to always read inputs as high.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
force_high1 to force the pin to read as high, 0 to clear the forced state.

◆ epio_set_gpio_force_input_low()

EPIO_EXPORT void epio_set_gpio_force_input_low ( epio_t *  epio,
uint8_t  pin,
uint8_t  force_low 
)

Force a GPIO pin configured as an input to present a low level.

This sets the emulated hardware INOVER state to always read inputs as low.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
force_low1 to force the pin to read as low, 0 to clear the forced state.

◆ epio_set_gpio_input()

EPIO_EXPORT void epio_set_gpio_input ( epio_t *  epio,
uint8_t  pin 
)

Configure a GPIO pin as an input.

Sets the pin direction to input and updates the input level to reflect the pin's configured pull resistor (pull-up → 1, pull-down → 0, pull-none → float mode value). The hardware reset default is pull-down.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
See also
epio_set_gpio_output()

◆ epio_set_gpio_input_inverted()

void epio_set_gpio_input_inverted ( epio_t *  epio,
uint8_t  pin,
uint8_t  inverted 
)

Set a GPIO pin as inverted or non-inverted.

When a GPIO pin is inverted, the PIO state machines see the opposite level on that pin. For example, if GPIO5 is inverted and externally driven low, the SMs will see it as high. This allows testing of PIO programs that use the INVERT pin configuration to invert GPIO inputs.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
inverted1 to set the pin as inverted, 0 to set it as non-inverted.

◆ epio_set_gpio_input_level()

EPIO_EXPORT void epio_set_gpio_input_level ( epio_t *  epio,
uint8_t  pin,
uint8_t  level 
)

Set the level of a GPIO configured as an input.

Simulates an external signal on an input pin, allowing PIO programs that read GPIO state to observe the specified level.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
levelPin level: 0 (low) or 1 (high).

◆ epio_set_gpio_input_only()

EPIO_EXPORT void epio_set_gpio_input_only ( epio_t *  epio,
uint8_t  pin,
uint8_t  input_only 
)

Mark a GPIO pin as input-only (output driver disabled).

When set, epio_set_gpio_output() on that pin will assert. Corresponds to configuring a pin with PAD_OUTPUT_DIS in hardware.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
input_only1 to mark as input-only, 0 to clear.

◆ epio_set_gpio_output()

EPIO_EXPORT void epio_set_gpio_output ( epio_t *  epio,
uint8_t  pin 
)

Configure a GPIO pin as an output.

Asserts if the pin has been marked input-only via epio_set_gpio_input_only().

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
See also
epio_set_gpio_input()

◆ epio_set_gpio_output_control()

void epio_set_gpio_output_control ( epio_t *  epio,
uint8_t  pin,
uint8_t  block 
)

Set GPIO output control for a pin to a specific block.

This configures a GPIO pin to be driven by the specified PIO block when it is configured as an output. Only a PIO block with output control for that GPIO can drive it as an output.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
blockPIO block index (0 to NUM_PIO_BLOCKS-1).

◆ epio_set_gpio_output_level()

EPIO_EXPORT void epio_set_gpio_output_level ( epio_t *  epio,
uint8_t  pin,
uint8_t  level 
)

Set the level of a GPIO configured as an output.

Overrides the PIO-driven level on an output pin, for test setup purposes.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
levelPin level: 0 (low) or 1 (high).

◆ epio_set_gpio_pull_down()

EPIO_EXPORT void epio_set_gpio_pull_down ( epio_t *  epio,
uint8_t  pin,
uint8_t  enable 
)

Enable or disable a pull-down resistor on a GPIO pin.

Setting pull-down clears any pull-up on the same pin and immediately updates the undriven input level to 0 (unless a force override is active). The hardware reset default is pull-down on all pins.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
enable1 to enable pull-down, 0 to clear it (leaving the pin with no pull).

◆ epio_set_gpio_pull_none()

EPIO_EXPORT void epio_set_gpio_pull_none ( epio_t *  epio,
uint8_t  pin 
)

Disable both pull-up and pull-down resistors on a GPIO pin.

The level of an undriven pull-none pin is governed by the float mode configured via epio_set_float_mode(). Default float mode is EPIO_FLOAT_HIGH.

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).

◆ epio_set_gpio_pull_up()

EPIO_EXPORT void epio_set_gpio_pull_up ( epio_t *  epio,
uint8_t  pin,
uint8_t  enable 
)

Enable or disable a pull-up resistor on a GPIO pin.

Setting pull-up clears any pull-down on the same pin and immediately updates the undriven input level to 1 (unless a force override is active).

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
enable1 to enable pull-up, 0 to clear it (leaving the pin with no pull).

◆ epio_set_gpio_slew_fast()

EPIO_EXPORT void epio_set_gpio_slew_fast ( epio_t *  epio,
uint8_t  pin,
uint8_t  fast 
)

Set the slew rate for a GPIO output pin.

Stored per-pin; has no current behavioural effect in emulation. Hardware reset default: slow (0).

Parameters
epioThe epio instance.
pinGPIO pin number (0 to NUM_GPIOS-1).
fast1 for fast slew, 0 for slow.