Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Peripheral Parallel Input/Output (PIO) Controller

Purpose

The Parallel Input/Output Controller (PIO) manages up to 32 fully programmable input/output lines. Each I/O line may be dedicated as a general-purpose I/O or be assigned to a function of an embedded peripheral. This assures effective optimization of the pins of a product.

Modules

 
 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the Peripheral Parallel Input/Output (PIO) Controller.
 

Macros

#define FREQ_SLOW_CLOCK_EXT   32768
 

Functions

void pio_clear (Pio *p_pio, const uint32_t ul_mask)
 Set a low output level on all the PIOs defined in ul_mask. More...
 
uint32_t pio_configure (Pio *p_pio, const pio_type_t ul_type, const uint32_t ul_mask, const uint32_t ul_attribute)
 Perform complete pin(s) configuration; general attributes and PIO init if necessary. More...
 
void pio_configure_interrupt (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_attr)
 Configure the given interrupt source. More...
 
uint32_t pio_configure_pin (uint32_t ul_pin, const uint32_t ul_flags)
 Perform complete pin(s) configuration; general attributes and PIO init if necessary. More...
 
uint32_t pio_configure_pin_group (Pio *p_pio, uint32_t ul_mask, const uint32_t ul_flags)
 Perform complete pin(s) configuration; general attributes and PIO init if necessary. More...
 
void pio_disable_interrupt (Pio *p_pio, const uint32_t ul_mask)
 Disable a given interrupt source, with no added side effects. More...
 
void pio_disable_output_write (Pio *p_pio, const uint32_t ul_mask)
 Disable PIO output write. More...
 
void pio_disable_pin_interrupt (uint32_t ul_pin)
 Disable interrupt for a GPIO pin. More...
 
void pio_enable_interrupt (Pio *p_pio, const uint32_t ul_mask)
 Enable the given interrupt source. More...
 
void pio_enable_output_write (Pio *p_pio, const uint32_t ul_mask)
 Enable PIO output write for synchronous data output. More...
 
void pio_enable_pin_interrupt (uint32_t ul_pin)
 Enable interrupt for a GPIO pin. More...
 
uint32_t pio_get (Pio *p_pio, const pio_type_t ul_type, const uint32_t ul_mask)
 Return 1 if one or more PIOs of the given Pin instance currently have a high level; otherwise returns 0. More...
 
uint32_t pio_get_interrupt_mask (const Pio *p_pio)
 Read PIO interrupt mask. More...
 
uint32_t pio_get_interrupt_status (const Pio *p_pio)
 Read and clear PIO interrupt status. More...
 
uint32_t pio_get_multi_driver_status (const Pio *p_pio)
 Get multi-driver status. More...
 
uint32_t pio_get_output_data_status (const Pio *p_pio, const uint32_t ul_mask)
 Return 1 if one or more PIOs of the given Pin are configured to output a high level (even if they are not output). More...
 
uint32_t pio_get_output_write_status (const Pio *p_pio)
 Read PIO output write status. More...
 
Pio * pio_get_pin_group (uint32_t ul_pin)
 Return GPIO port for a GPIO pin. More...
 
uint32_t pio_get_pin_group_id (uint32_t ul_pin)
 Return GPIO port peripheral ID for a GPIO pin. More...
 
uint32_t pio_get_pin_group_mask (uint32_t ul_pin)
 Return GPIO port pin mask for a GPIO pin. More...
 
uint32_t pio_get_pin_value (uint32_t ul_pin)
 Return the value of a pin. More...
 
uint32_t pio_get_writeprotect_status (const Pio *p_pio)
 Read write protect status. More...
 
void pio_pull_up (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_pull_up_enable)
 Configure PIO internal pull-up. More...
 
void pio_set (Pio *p_pio, const uint32_t ul_mask)
 Set a high output level on all the PIOs defined in ul_mask. More...
 
void pio_set_additional_interrupt_mode (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_attribute)
 Set additional interrupt mode. More...
 
void pio_set_debounce_filter (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_cut_off)
 Configure Glitch or Debouncing filter for the specified input(s). More...
 
void pio_set_input (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_attribute)
 Configure one or more pin(s) or a PIO controller as inputs. More...
 
void pio_set_multi_driver (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_multi_driver_enable)
 Configure PIO pin multi-driver. More...
 
void pio_set_output (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_default_level, const uint32_t ul_multidrive_enable, const uint32_t ul_pull_up_enable)
 Configure one or more pin(s) of a PIO controller as outputs, with the given default value. More...
 
void pio_set_peripheral (Pio *p_pio, const pio_type_t ul_type, const uint32_t ul_mask)
 Configure IO of a PIO controller as being controlled by a specific peripheral. More...
 
void pio_set_pin_group_high (Pio *p_pio, uint32_t ul_mask)
 Drive a GPIO port to 1. More...
 
void pio_set_pin_group_low (Pio *p_pio, uint32_t ul_mask)
 Drive a GPIO port to 0. More...
 
void pio_set_pin_high (uint32_t ul_pin)
 Drive a GPIO pin to 1. More...
 
void pio_set_pin_low (uint32_t ul_pin)
 Drive a GPIO pin to 0. More...
 
void pio_set_writeprotect (Pio *p_pio, const uint32_t ul_enable)
 Enable or disable write protect of PIO registers. More...
 
void pio_sync_output_write (Pio *p_pio, const uint32_t ul_mask)
 Synchronously write on output pins. More...
 
void pio_toggle_pin (uint32_t ul_pin)
 Toggle a GPIO pin. More...
 
void pio_toggle_pin_group (Pio *p_pio, uint32_t ul_mask)
 Toggle a GPIO group. More...
 

#define FREQ_SLOW_CLOCK_EXT   32768

Referenced by pio_set_debounce_filter().

void pio_clear ( Pio *  p_pio,
const uint32_t  ul_mask 
)

Set a low output level on all the PIOs defined in ul_mask.

This has no immediate effects on PIOs that are not output, but the PIO controller will save the value if they are changed to outputs.

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s) to configure.

Referenced by ov_power(), and ov_reset().

uint32_t pio_configure ( Pio *  p_pio,
const pio_type_t  ul_type,
const uint32_t  ul_mask,
const uint32_t  ul_attribute 
)

Perform complete pin(s) configuration; general attributes and PIO init if necessary.

Parameters
p_pioPointer to a PIO instance.
ul_typePIO type.
ul_maskBitmask of one or more pin(s) to configure.
ul_attributePins attributes.
Returns
Whether the pin(s) have been configured properly.

References PIO_INPUT, PIO_OPENDRAIN, PIO_OUTPUT_0, PIO_OUTPUT_1, PIO_PERIPH_A, PIO_PERIPH_B, pio_pull_up(), PIO_PULLUP, pio_set_input(), pio_set_output(), and pio_set_peripheral().

Referenced by configure_button(), and configure_led().

void pio_configure_interrupt ( Pio *  p_pio,
const uint32_t  ul_mask,
const uint32_t  ul_attr 
)

Configure the given interrupt source.

Interrupt can be configured to trigger on rising edge, falling edge, high level, low level or simply on level change.

Parameters
p_pioPointer to a PIO instance.
ul_maskInterrupt source bit map.
ul_attrInterrupt source attributes.

References PIO_IT_AIME, PIO_IT_EDGE, and PIO_IT_RE_OR_HL.

uint32_t pio_configure_pin ( uint32_t  ul_pin,
const uint32_t  ul_flags 
)

Perform complete pin(s) configuration; general attributes and PIO init if necessary.

Parameters
ul_pinThe pin index.
ul_flagsPins attributes.
Returns
Whether the pin(s) have been configured properly.

References pio_get_pin_group(), PIO_OPENDRAIN, PIO_PERIPH_A, PIO_PERIPH_B, pio_pull_up(), PIO_PULLUP, pio_set_input(), pio_set_output(), pio_set_peripheral(), PIO_TYPE_Msk, PIO_TYPE_PIO_INPUT, PIO_TYPE_PIO_OUTPUT_0, PIO_TYPE_PIO_OUTPUT_1, PIO_TYPE_PIO_PERIPH_A, PIO_TYPE_PIO_PERIPH_B, PIO_TYPE_PIO_PERIPH_C, and PIO_TYPE_PIO_PERIPH_D.

Referenced by func_receiver(), func_transmitter(), init_chip_pins(), main(), and nm_bsp_register_isr().

uint32_t pio_configure_pin_group ( Pio *  p_pio,
uint32_t  ul_mask,
const uint32_t  ul_flags 
)

Perform complete pin(s) configuration; general attributes and PIO init if necessary.

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s) to configure.
ul_flagsPin(s) attributes.
Returns
Whether the pin(s) have been configured properly.

References PIO_OPENDRAIN, PIO_PERIPH_A, PIO_PERIPH_B, pio_pull_up(), PIO_PULLUP, pio_set_input(), pio_set_output(), pio_set_peripheral(), PIO_TYPE_Msk, PIO_TYPE_PIO_INPUT, PIO_TYPE_PIO_OUTPUT_0, PIO_TYPE_PIO_OUTPUT_1, PIO_TYPE_PIO_PERIPH_A, PIO_TYPE_PIO_PERIPH_B, PIO_TYPE_PIO_PERIPH_C, and PIO_TYPE_PIO_PERIPH_D.

Referenced by configure_console(), main(), and reconfigure_console().

void pio_disable_interrupt ( Pio *  p_pio,
const uint32_t  ul_mask 
)

Disable a given interrupt source, with no added side effects.

Parameters
p_pioPointer to a PIO instance.
ul_maskInterrupt sources bit map.

Referenced by Int1Handler(), Int2Handler(), main(), nm_bsp_interrupt_ctrl(), ov7740_test_capture_process_run(), pio_set_input(), pio_set_output(), and start_capture().

void pio_disable_output_write ( Pio *  p_pio,
const uint32_t  ul_mask 
)

Disable PIO output write.

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s) to configure.
void pio_disable_pin_interrupt ( uint32_t  ul_pin)

Disable interrupt for a GPIO pin.

Parameters
ul_pinThe pin index.
Note
The function gpio_configure_pin must be called before.

References pio_get_pin_group().

Referenced by ads7843_disable_interrupt(), and ads7843_get_raw_point().

void pio_enable_interrupt ( Pio *  p_pio,
const uint32_t  ul_mask 
)

Enable the given interrupt source.

The PIO must be configured as an NVIC interrupt source as well.

Parameters
p_pioPointer to a PIO instance.
ul_maskInterrupt sources bit map.

Referenced by configure_button(), configure_buttons(), configure_intn(), Int1Handler(), Int2Handler(), main(), nm_bsp_btn_init(), nm_bsp_interrupt_ctrl(), nm_bsp_register_isr(), ov7740_test_capture_process_run(), pplc_if_init(), and start_capture().

void pio_enable_output_write ( Pio *  p_pio,
const uint32_t  ul_mask 
)

Enable PIO output write for synchronous data output.

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s) to configure.

Referenced by main().

void pio_enable_pin_interrupt ( uint32_t  ul_pin)

Enable interrupt for a GPIO pin.

Parameters
ul_pinThe pin index.
Note
The function gpio_configure_pin must be called before.

References pio_get_pin_group().

Referenced by ads7843_enable_interrupt(), ads7843_get_raw_point(), ads7843_set_handler(), and io_pin_init().

uint32_t pio_get ( Pio *  p_pio,
const pio_type_t  ul_type,
const uint32_t  ul_mask 
)

Return 1 if one or more PIOs of the given Pin instance currently have a high level; otherwise returns 0.

This method returns the actual value that is being read on the pin. To return the supposed output value of a pin, use pio_get_output_data_status() instead.

Parameters
p_pioPointer to a PIO instance.
ul_typePIO type.
ul_maskBitmask of one or more pin(s) to configure.
Return values
1at least one PIO currently has a high level.
0all PIOs have a low level.

References PIO_OUTPUT_0, and PIO_OUTPUT_1.

uint32_t pio_get_interrupt_mask ( const Pio *  p_pio)

Read PIO interrupt mask.

Parameters
p_pioPointer to a PIO instance.
Returns
The interrupt mask value.
uint32_t pio_get_interrupt_status ( const Pio *  p_pio)

Read and clear PIO interrupt status.

Parameters
p_pioPointer to a PIO instance.
Returns
The interrupt status value.

Referenced by INTN_Handler(), nm_bsp_interrupt_ctrl(), and nm_bsp_register_isr().

uint32_t pio_get_multi_driver_status ( const Pio *  p_pio)

Get multi-driver status.

Parameters
p_pioPointer to a PIO instance.
Returns
The multi-driver mask value.
uint32_t pio_get_output_data_status ( const Pio *  p_pio,
const uint32_t  ul_mask 
)

Return 1 if one or more PIOs of the given Pin are configured to output a high level (even if they are not output).

To get the actual value of the pin, use PIO_Get() instead.

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s).
Return values
1At least one PIO is configured to output a high level.
0All PIOs are configured to output a low level.
uint32_t pio_get_output_write_status ( const Pio *  p_pio)

Read PIO output write status.

Parameters
p_pioPointer to a PIO instance.
Returns
The output write mask value.
Pio* pio_get_pin_group ( uint32_t  ul_pin)

Return GPIO port for a GPIO pin.

Parameters
ul_pinThe pin index.
Returns
Pointer to Pio struct for GPIO port.

References PIO_DELTA.

Referenced by pio_configure_pin(), pio_disable_pin_interrupt(), pio_enable_pin_interrupt(), pio_get_pin_value(), pio_set_pin_high(), pio_set_pin_low(), and pio_toggle_pin().

uint32_t pio_get_pin_group_id ( uint32_t  ul_pin)

Return GPIO port peripheral ID for a GPIO pin.

Parameters
ul_pinThe pin index.
Returns
GPIO port peripheral ID.
uint32_t pio_get_pin_group_mask ( uint32_t  ul_pin)

Return GPIO port pin mask for a GPIO pin.

Parameters
ul_pinThe pin index.
Returns
GPIO port pin mask.
uint32_t pio_get_pin_value ( uint32_t  ul_pin)

Return the value of a pin.

Parameters
ul_pinThe pin number.
Returns
The pin value.
Note
If pin is output: a pull-up or pull-down could hide the actual value. The function pio_get can be called to get the actual pin output level.
If pin is input: PIOx must be clocked to sample the signal. See PMC driver.

References pio_get_pin_group().

uint32_t pio_get_writeprotect_status ( const Pio *  p_pio)

Read write protect status.

Parameters
p_pioPointer to a PIO instance.
Returns
Return write protect status.
void pio_pull_up ( Pio *  p_pio,
const uint32_t  ul_mask,
const uint32_t  ul_pull_up_enable 
)

Configure PIO internal pull-up.

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s) to configure.
ul_pull_up_enableIndicates if the pin(s) internal pull-up shall be configured.

Referenced by nm_bsp_register_isr(), pio_configure(), pio_configure_pin(), pio_configure_pin_group(), pio_set_input(), pio_set_output(), and serial_bridge_init().

void pio_set ( Pio *  p_pio,
const uint32_t  ul_mask 
)

Set a high output level on all the PIOs defined in ul_mask.

This has no immediate effects on PIOs that are not output, but the PIO controller will save the value if they are changed to outputs.

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s) to configure.

Referenced by ov_power().

void pio_set_additional_interrupt_mode ( Pio *  p_pio,
const uint32_t  ul_mask,
const uint32_t  ul_attribute 
)

Set additional interrupt mode.

Parameters
p_pioPointer to a PIO instance.
ul_maskInterrupt sources bit map.
ul_attributePin(s) attributes.

References PIO_IT_AIME, PIO_IT_EDGE, and PIO_IT_RE_OR_HL.

void pio_set_debounce_filter ( Pio *  p_pio,
const uint32_t  ul_mask,
const uint32_t  ul_cut_off 
)

Configure Glitch or Debouncing filter for the specified input(s).

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s) to configure.
ul_cut_offCuts off frequency for debouncing filter.

References FREQ_SLOW_CLOCK_EXT.

Referenced by configure_button(), configure_buttons(), configure_intn(), and nm_bsp_btn_init().

void pio_set_input ( Pio *  p_pio,
const uint32_t  ul_mask,
const uint32_t  ul_attribute 
)

Configure one or more pin(s) or a PIO controller as inputs.

Optionally, the corresponding internal pull-up(s) and glitch filter(s) can be enabled.

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask indicating which pin(s) to configure as input(s).
ul_attributePIO attribute(s).

References PIO_DEBOUNCE, PIO_DEGLITCH, pio_disable_interrupt(), pio_pull_up(), and PIO_PULLUP.

Referenced by pio_configure(), pio_configure_pin(), and pio_configure_pin_group().

void pio_set_multi_driver ( Pio *  p_pio,
const uint32_t  ul_mask,
const uint32_t  ul_multi_driver_enable 
)

Configure PIO pin multi-driver.

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s) to configure.
ul_multi_driver_enableIndicates if the pin(s) multi-driver shall be configured.
void pio_set_output ( Pio *  p_pio,
const uint32_t  ul_mask,
const uint32_t  ul_default_level,
const uint32_t  ul_multidrive_enable,
const uint32_t  ul_pull_up_enable 
)

Configure one or more pin(s) of a PIO controller as outputs, with the given default value.

Optionally, the multi-drive feature can be enabled on the pin(s).

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask indicating which pin(s) to configure.
ul_default_levelDefault level on the pin(s).
ul_multidrive_enableIndicates if the pin(s) shall be configured as open-drain.
ul_pull_up_enableIndicates if the pin shall have its pull-up activated.

References pio_disable_interrupt(), and pio_pull_up().

Referenced by pio_configure(), pio_configure_pin(), and pio_configure_pin_group().

void pio_set_peripheral ( Pio *  p_pio,
const pio_type_t  ul_type,
const uint32_t  ul_mask 
)

Configure IO of a PIO controller as being controlled by a specific peripheral.

Parameters
p_pioPointer to a PIO instance.
ul_typePIO type.
ul_maskBitmask of one or more pin(s) to configure.

References PIO_INPUT, PIO_NOT_A_PIN, PIO_OUTPUT_0, PIO_OUTPUT_1, PIO_PERIPH_A, and PIO_PERIPH_B.

Referenced by pio_configure(), pio_configure_pin(), and pio_configure_pin_group().

void pio_set_pin_group_high ( Pio *  p_pio,
uint32_t  ul_mask 
)

Drive a GPIO port to 1.

Parameters
p_pioBase address of the PIO port.
ul_maskBitmask of one or more pin(s) to toggle.
void pio_set_pin_group_low ( Pio *  p_pio,
uint32_t  ul_mask 
)

Drive a GPIO port to 0.

Parameters
p_pioBase address of the PIO port.
ul_maskBitmask of one or more pin(s) to toggle.
void pio_set_pin_high ( uint32_t  ul_pin)

Drive a GPIO pin to 1.

Parameters
ul_pinThe pin index.
Note
The function pio_configure_pin must be called beforehand.

References pio_get_pin_group().

Referenced by access_sram_test(), init_chip_pins(), main(), and nm_bsp_reset().

void pio_set_pin_low ( uint32_t  ul_pin)

Drive a GPIO pin to 0.

Parameters
ul_pinThe pin index.
Note
The function pio_configure_pin must be called before.

References pio_get_pin_group().

Referenced by access_sram_test(), func_receiver(), main(), nm_bsp_deinit(), and nm_bsp_reset().

void pio_set_writeprotect ( Pio *  p_pio,
const uint32_t  ul_enable 
)

Enable or disable write protect of PIO registers.

Parameters
p_pioPointer to a PIO instance.
ul_enable1 to enable, 0 to disable.

References PIO_WPMR_WPKEY_PASSWD.

void pio_sync_output_write ( Pio *  p_pio,
const uint32_t  ul_mask 
)

Synchronously write on output pins.

Note
Only bits unmasked by PIO_OWSR (Output Write Status Register) are written.
Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s) to configure.

Referenced by main().

void pio_toggle_pin ( uint32_t  ul_pin)

Toggle a GPIO pin.

Parameters
ul_pinThe pin index.
Note
The function pio_configure_pin must be called before.

References pio_get_pin_group().

void pio_toggle_pin_group ( Pio *  p_pio,
uint32_t  ul_mask 
)

Toggle a GPIO group.

Parameters
p_pioPointer to a PIO instance.
ul_maskBitmask of one or more pin(s) to configure.