CMSIS-Driver_PIC32CZ-CA70  
Peripheral Library (PLIB) Documentation
 
Loading...
Searching...
No Matches
PIO Interface

Driver API for PIO (plib_pio.h) More...

Macros

#define GPIO_MAX_PINS   (32U)
 
#define PIO_GROUP_COUNT   (1U)
 
#define PIO_GPIO_EVENT_RISING_EDGE   (1UL << 0)
 Rising-edge detected.
 
#define PIO_GPIO_EVENT_FALLING_EDGE   (1UL << 1)
 Falling-edge detected.
 
#define PIO_GPIO_EVENT_EITHER_EDGE   (1UL << 2)
 Either edge detected (only when hardware cannot distinguish between rising and falling edge)
 
#define PIO_GPIO_EVENT_LEVEL_HIGH   (1UL << 3)
 Level high detected.
 
#define PIO_GPIO_EVENT_LEVEL_LOW   (1UL << 4)
 Level low detected.
 
#define PIO_PLIB_OK   (0)
 Operation completed successfully.
 
#define PIO_PLIB_ERROR   (-1)
 Unspecified error occurred.
 
#define PIO_PLIB_ERROR_PARAMETER   (-5)
 Invalid parameter provided.
 

Typedefs

typedef uint32_t PIO_PIN
 GPIO pin identifier.
 
typedef void(* PIO_CALLBACK) (uint32_t pin, uint32_t event)
 Callback function pointer type for GPIO pin events.
 

Enumerations

enum  PIO_DIRECTION { PIO_INPUT , PIO_OUTPUT }
 PIO pin direction. More...
 
enum  PIO_OUTPUT_MODE { PIO_PUSH_PULL , PIO_OPEN_DRAIN }
 PIO output mode. More...
 
enum  PIO_PULL_RESISTOR { PIO_PULL_NONE , PIO_PULL_UP , PIO_PULL_DOWN }
 PIO pull resistor configuration. More...
 
enum  PIO_INTERRUPT_TRIGGER_TYPE {
  PIO_INTERRUPT_TRIGGER_RISING_EDGE , PIO_INTERRUPT_TRIGGER_FALLING_EDGE , PIO_INTERRUPT_TRIGGER_EITHER_EDGE , PIO_INTERRUPT_TRIGGER_LEVEL_HIGH ,
  PIO_INTERRUPT_TRIGGER_LEVEL_LOW
}
 PIO input trigger type. More...
 
enum  PIO_PERIPHERAL_FUNCTION { PIO_PERIPHERAL_A , PIO_PERIPHERAL_B , PIO_PERIPHERAL_C , PIO_PERIPHERAL_D }
 PIO peripheral multiplexer function selection. More...
 

Functions

int32_t PIO_EnablePeripheralControl (PIO_PIN pin)
 Enable peripheral control for a specific pin.
 
int32_t PIO_DisablePeripheralControl (PIO_PIN pin)
 Disable peripheral control for a specific pin. The pin will be controlled by PIO module.
 
int32_t PIO_SetDirection (PIO_PIN pin, PIO_DIRECTION direction)
 Set a specific pin direction.
 
int32_t PIO_SetOutputMode (PIO_PIN pin, PIO_OUTPUT_MODE mode)
 Set the output mode for a specific pin.
 
int32_t PIO_SetPullResistor (PIO_PIN pin, PIO_PULL_RESISTOR resistor)
 Set the pull resistor configuration for a specific pin.
 
int32_t PIO_EnableInterrupt (PIO_PIN pin)
 Enable the event interrupt for a specific pin.
 
int32_t PIO_ConfigureInterruptTriggerType (PIO_PIN pin, PIO_INTERRUPT_TRIGGER_TYPE event)
 Configure the interrupt trigger type for a specific pin.
 
int32_t PIO_DisableInterrupt (PIO_PIN pin)
 Disable the event interrupt for a specific pin.
 
void PIO_SetOutput (PIO_PIN pin, uint32_t value)
 Set the output value for a specific pin.
 
int32_t PIO_GetOutput (PIO_PIN pin)
 Get the current output value of a specific pin.
 
uint32_t PIO_GetInput (PIO_PIN pin)
 Get the input state of a specific pin.
 
int32_t PIO_SetPeripheralMuxing (PIO_PIN pin, PIO_PERIPHERAL_FUNCTION peripheral_function)
 Set the peripheral multiplexer for a specific pin.
 
int32_t PIO_EnableDebounceFilter (PIO_PIN pin, uint32_t slow_clock_divider)
 Enables the debounce filter for a specific pin with the specified slow clock divider.
 
int32_t PIO_DisableDebounceFilter (PIO_PIN pin)
 Disables the debounce filter for a specific pin.
 
void PIO_SetCallbackHandler (PIO_PIN pin, PIO_CALLBACK callback)
 Set the callback function to be called when a GPIO event occurs.
 

Description

Driver API for PIO (plib_pio.h)

Macro Definition Documentation

◆ GPIO_MAX_PINS

#define GPIO_MAX_PINS   (32U)

◆ PIO_GPIO_EVENT_EITHER_EDGE

#define PIO_GPIO_EVENT_EITHER_EDGE   (1UL << 2)

Either edge detected (only when hardware cannot distinguish between rising and falling edge)

◆ PIO_GPIO_EVENT_FALLING_EDGE

#define PIO_GPIO_EVENT_FALLING_EDGE   (1UL << 1)

Falling-edge detected.

◆ PIO_GPIO_EVENT_LEVEL_HIGH

#define PIO_GPIO_EVENT_LEVEL_HIGH   (1UL << 3)

Level high detected.

◆ PIO_GPIO_EVENT_LEVEL_LOW

#define PIO_GPIO_EVENT_LEVEL_LOW   (1UL << 4)

Level low detected.

◆ PIO_GPIO_EVENT_RISING_EDGE

#define PIO_GPIO_EVENT_RISING_EDGE   (1UL << 0)

Rising-edge detected.

◆ PIO_GROUP_COUNT

#define PIO_GROUP_COUNT   (1U)

◆ PIO_PLIB_ERROR

#define PIO_PLIB_ERROR   (-1)

Unspecified error occurred.

◆ PIO_PLIB_ERROR_PARAMETER

#define PIO_PLIB_ERROR_PARAMETER   (-5)

Invalid parameter provided.

◆ PIO_PLIB_OK

#define PIO_PLIB_OK   (0)

Operation completed successfully.

Typedef Documentation

◆ PIO_CALLBACK

PIO_CALLBACK

Callback function pointer type for GPIO pin events.

This callback is invoked from the interrupt handler when a configured GPIO event (rising edge, falling edge, either edge, high-level, or low-level) is detected.

Parameters
pinThe GPIO pin that triggered the event
eventThe event type.

◆ PIO_PIN

GPIO pin identifier.

GPIO pins are identified by a single numeric value that encodes both the GPIO pio and the pin number.

The value of a pin identifier is defined by the device DFP and must be one of the DFP-provided pin macros, for example:

  • PIN_PA00, PIN_PA01, ... PIN_PA31
  • PIN_PB00, PIN_PB01, ... PIN_PB31
  • PIN_PC00, PIN_PC01, ... etc.

The numeric encoding follows this rule:

pin_id = (pio_index * 32U) + pin_number

Where:

  • pio_index is the zero-based GPIO pio number (e.g. PA = 0, PB = 1, PC = 2, ...)
  • pin_number is the pin index within the pio (0–31)

This encoding allows the driver to determine the GPIO pio and pin number using simple arithmetic operations.

Note
Users must not define custom pin values. Only pin macros provided by the device DFP are supported.

Enumeration Type Documentation

◆ PIO_DIRECTION

PIO pin direction.

This enumeration defines the direction of a PIO pin.

Enumerator
PIO_INPUT 

Input (default)

PIO_OUTPUT 

Output.

◆ PIO_INTERRUPT_TRIGGER_TYPE

PIO input trigger type.

This enumeration specifies PIO input trigger type for interrupt.

Enumerator
PIO_INTERRUPT_TRIGGER_RISING_EDGE 

Rising-edge.

PIO_INTERRUPT_TRIGGER_FALLING_EDGE 

Falling-edge.

PIO_INTERRUPT_TRIGGER_EITHER_EDGE 

Either edge (rising or falling)

PIO_INTERRUPT_TRIGGER_LEVEL_HIGH 

Level high.

PIO_INTERRUPT_TRIGGER_LEVEL_LOW 

Level low.

◆ PIO_OUTPUT_MODE

PIO output mode.

This enumeration specifies the output mode for a PIO pin.

Enumerator
PIO_PUSH_PULL 

Push-pull (default)

PIO_OPEN_DRAIN 

Open-drain.

◆ PIO_PERIPHERAL_FUNCTION

PIO peripheral multiplexer function selection.

This enumeration specifies which peripheral function (A/B/C/D) is routed to a pin when peripheral control is enabled via PIO_SetPeripheralMuxing().

Enumerator
PIO_PERIPHERAL_A 

Peripheral function A.

PIO_PERIPHERAL_B 

Peripheral function B.

PIO_PERIPHERAL_C 

Peripheral function C.

PIO_PERIPHERAL_D 

Peripheral function D.

◆ PIO_PULL_RESISTOR

PIO pull resistor configuration.

This enumeration specifies the pull resistor configuration for a PIO pin.

Enumerator
PIO_PULL_NONE 

None (default)

PIO_PULL_UP 

Pull-up.

PIO_PULL_DOWN 

Pull-down.

Function Documentation

◆ PIO_ConfigureInterruptTriggerType()

int32_t PIO_ConfigureInterruptTriggerType ( PIO_PIN pin,
PIO_INTERRUPT_TRIGGER_TYPE event )

Configure the interrupt trigger type for a specific pin.

Parameters
pinPIO pin
eventInput event configuration
Returns
Status code

◆ PIO_DisableDebounceFilter()

int32_t PIO_DisableDebounceFilter ( PIO_PIN pin)

Disables the debounce filter for a specific pin.

Parameters
pinPIO pin
Returns
Status code

◆ PIO_DisableInterrupt()

int32_t PIO_DisableInterrupt ( PIO_PIN pin)

Disable the event interrupt for a specific pin.

Parameters
pinPIO pin
Returns
Status code

◆ PIO_DisablePeripheralControl()

int32_t PIO_DisablePeripheralControl ( PIO_PIN pin)

Disable peripheral control for a specific pin. The pin will be controlled by PIO module.

Parameters
pinPIO pin
Returns
Status code

◆ PIO_EnableDebounceFilter()

int32_t PIO_EnableDebounceFilter ( PIO_PIN pin,
uint32_t slow_clock_divider )

Enables the debounce filter for a specific pin with the specified slow clock divider.

Parameters
pinPIO pin
slow_clock_dividerThe divider for the slow clock used by the debounce filter. tdiv_slck = ((DIV + 1) × 2) × tslck. Default value is 0U.
Returns
Status code
Note
The slow clock divider (PIO_SCDR) is shared across all pins within the same PIO group. Enabling debounce with different divider values on two pins in the same group will result in the last written value applying to all debounce-enabled pins in that group.

◆ PIO_EnableInterrupt()

int32_t PIO_EnableInterrupt ( PIO_PIN pin)

Enable the event interrupt for a specific pin.

Parameters
pinPIO pin
Returns
Status code

◆ PIO_EnablePeripheralControl()

int32_t PIO_EnablePeripheralControl ( PIO_PIN pin)

Enable peripheral control for a specific pin.

Parameters
pinPIO pin
Returns
Status code

◆ PIO_GetInput()

uint32_t PIO_GetInput ( PIO_PIN pin)

Get the input state of a specific pin.

Parameters
pinPIO pin
Returns
Input state (1 if high, 0 if low). Returns 0 if pin is invalid.
Note
Callers cannot distinguish between "pin is low" and "pin is invalid" since both return 0. Ensure the pin is valid before calling this function.

◆ PIO_GetOutput()

int32_t PIO_GetOutput ( PIO_PIN pin)

Get the current output value of a specific pin.

Parameters
pinPIO pin
Returns
Output value (1 if high, 0 if low), or PIO_PLIB_ERROR if pin is invalid

◆ PIO_SetCallbackHandler()

void PIO_SetCallbackHandler ( PIO_PIN pin,
PIO_CALLBACK callback )

Set the callback function to be called when a GPIO event occurs.

Parameters
pinPIO pin for which to set the callback
callbackCallback function to be called on pin events (can be NULL if no callback needed).
Note
For level-triggered pins (PIO_INTERRUPT_TRIGGER_LEVEL_HIGH / PIO_INTERRUPT_TRIGGER_LEVEL_LOW), the callback will be invoked on every ISR entry while the level is asserted. The application is responsible for de-asserting the signal or disabling the interrupt inside the callback to prevent continuous re-entry.

◆ PIO_SetDirection()

int32_t PIO_SetDirection ( PIO_PIN pin,
PIO_DIRECTION direction )

Set a specific pin direction.

Parameters
pinPIO pin
directionDirection (input/output)
Returns
Status code

◆ PIO_SetOutput()

void PIO_SetOutput ( PIO_PIN pin,
uint32_t value )

Set the output value for a specific pin.

Parameters
pinPIO pin
valueOutput value (0 or 1)

◆ PIO_SetOutputMode()

int32_t PIO_SetOutputMode ( PIO_PIN pin,
PIO_OUTPUT_MODE mode )

Set the output mode for a specific pin.

Parameters
pinPIO pin
modeOutput mode (push-pull/open-drain)
Returns
Status code

◆ PIO_SetPeripheralMuxing()

int32_t PIO_SetPeripheralMuxing ( PIO_PIN pin,
PIO_PERIPHERAL_FUNCTION peripheral_function )

Set the peripheral multiplexer for a specific pin.

Parameters
pinPIO pin
peripheral_functionPeripheral function to assign
Returns
Status code

◆ PIO_SetPullResistor()

int32_t PIO_SetPullResistor ( PIO_PIN pin,
PIO_PULL_RESISTOR resistor )

Set the pull resistor configuration for a specific pin.

Parameters
pinPIO pin
resistorPull resistor configuration
Returns
Status code