|
epio
A cycle-accurate RP2350 PIO emulator
|
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. | |
Functions for driving and reading GPIO pin states.
| 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.
| epio | The epio instance. |
| block | PIO block index (0 to NUM_PIO_BLOCKS-1). |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| block | PIO block index (0 to NUM_PIO_BLOCKS-1). |
| 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.
| epio | The epio instance. |
| gpios | Bitmask of GPIO pins to drive (bit N = GPIO N). |
| level | Bitmask of desired pin levels for the selected pins. |
| 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 | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| uint8_t epio_get_gpio_input_inverted | ( | epio_t * | epio, |
| uint8_t | pin | ||
| ) |
Get the inversion state of a GPIO pin.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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 | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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.
| epio | The epio instance. |
| block | PIO block index (0 to NUM_PIO_BLOCKS-1). |
| 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 | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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 | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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 | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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.
| epio | The epio instance. |
| 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.
| epio | The epio instance. |
| 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
| epio | The epio instance. |
| 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.
| epio | The epio instance. |
| 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.
| epio | The epio instance. |
| 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.
| epio | The epio instance. |
| mode | One of EPIO_FLOAT_LOW, EPIO_FLOAT_HIGH, EPIO_FLOAT_RANDOM. |
| 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.
| epio | The epio instance. |
| seed | 32-bit seed value. |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| strength | Drive strength value (APIO_DRIVE_*). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| force_high | 1 to force the pin to read as high, 0 to clear the forced state. |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| force_low | 1 to force the pin to read as low, 0 to clear the forced state. |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| inverted | 1 to set the pin as inverted, 0 to set it as non-inverted. |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| level | Pin level: 0 (low) or 1 (high). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| input_only | 1 to mark as input-only, 0 to clear. |
| 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().
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| block | PIO block index (0 to NUM_PIO_BLOCKS-1). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| level | Pin level: 0 (low) or 1 (high). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| enable | 1 to enable pull-down, 0 to clear it (leaving the pin with no pull). |
| 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.
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| 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).
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| enable | 1 to enable pull-up, 0 to clear it (leaving the pin with no pull). |
| 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).
| epio | The epio instance. |
| pin | GPIO pin number (0 to NUM_GPIOS-1). |
| fast | 1 for fast slew, 0 for slow. |