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 default (input, pulled-up) 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.
 
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.
 

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 unaffected.

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_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_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_init_gpios()

EPIO_EXPORT void epio_init_gpios ( epio_t epio)

Reset all GPIOs to their default (input, pulled-up) state.

Clears all GPIO directions and levels. 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 are pulled up.

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_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.

Pull-ups are assumed on all input pins.

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_output()

EPIO_EXPORT void epio_set_gpio_output ( epio_t epio,
uint8_t  pin 
)

Configure a GPIO pin as an output.

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).