Driver API for PIO (plib_pio.h)
More...
|
| 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.
|
| |
|
| 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...
|
| |
Driver API for PIO (plib_pio.h)
◆ 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) |
◆ PIO_GPIO_EVENT_LEVEL_HIGH
| #define PIO_GPIO_EVENT_LEVEL_HIGH (1UL << 3) |
◆ PIO_GPIO_EVENT_LEVEL_LOW
| #define PIO_GPIO_EVENT_LEVEL_LOW (1UL << 4) |
◆ PIO_GPIO_EVENT_RISING_EDGE
| #define PIO_GPIO_EVENT_RISING_EDGE (1UL << 0) |
◆ 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
Operation completed successfully.
◆ 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
-
| pin | The GPIO pin that triggered the event |
| event | The 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.
◆ 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.
|
◆ PIO_ConfigureInterruptTriggerType()
Configure the interrupt trigger type for a specific pin.
- Parameters
-
| pin | PIO pin |
| event | Input event configuration |
- Returns
- Status code
◆ PIO_DisableDebounceFilter()
| int32_t PIO_DisableDebounceFilter |
( |
PIO_PIN | pin | ) |
|
Disables the debounce filter for a specific pin.
- Parameters
-
- Returns
- Status code
◆ PIO_DisableInterrupt()
| int32_t PIO_DisableInterrupt |
( |
PIO_PIN | pin | ) |
|
Disable the event interrupt for a specific pin.
- Parameters
-
- 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
-
- 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
-
| pin | PIO pin |
| slow_clock_divider | The 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
-
- Returns
- Status code
◆ PIO_EnablePeripheralControl()
| int32_t PIO_EnablePeripheralControl |
( |
PIO_PIN | pin | ) |
|
Enable peripheral control for a specific pin.
- Parameters
-
- Returns
- Status code
◆ PIO_GetInput()
| uint32_t PIO_GetInput |
( |
PIO_PIN | pin | ) |
|
Get the input state of a specific pin.
- Parameters
-
- 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
-
- Returns
- Output value (1 if high, 0 if low), or PIO_PLIB_ERROR if pin is invalid
◆ PIO_SetCallbackHandler()
Set the callback function to be called when a GPIO event occurs.
- Parameters
-
| pin | PIO pin for which to set the callback |
| callback | Callback 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()
Set a specific pin direction.
- Parameters
-
| pin | PIO pin |
| direction | Direction (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
-
| pin | PIO pin |
| value | Output value (0 or 1) |
◆ PIO_SetOutputMode()
Set the output mode for a specific pin.
- Parameters
-
| pin | PIO pin |
| mode | Output mode (push-pull/open-drain) |
- Returns
- Status code
◆ PIO_SetPeripheralMuxing()
Set the peripheral multiplexer for a specific pin.
- Parameters
-
| pin | PIO pin |
| peripheral_function | Peripheral function to assign |
- Returns
- Status code
◆ PIO_SetPullResistor()
Set the pull resistor configuration for a specific pin.
- Parameters
-
| pin | PIO pin |
| resistor | Pull resistor configuration |
- Returns
- Status code