PORT Peripheral driver
Port Control and Interrupts (PORT)
Collaboration diagram for PORT Peripheral driver:

## Data Structures

struct | port_digital_filter_config_t
| PORT digital filter feature configuration definition. More...
struct | port_pin_config_t
| PORT pin config structure. More...

## Enumerations

enum | _port_pull { kPORT_PullDisable = 0U, kPORT_PullDown = 2U, kPORT_PullUp = 3U }
| Internal resistor pull feature selection. More...
enum | _port_slew_rate { kPORT_FastSlewRate = 0U, kPORT_SlowSlewRate = 1U }
| Slew rate selection. More...
enum | _port_open_drain_enable { kPORT_OpenDrainDisable = 0U, kPORT_OpenDrainEnable = 1U }
| Internal resistor pull feature enable/disable. More...
enum | _port_passive_filter_enable { kPORT_PassiveFilterDisable = 0U, kPORT_PassiveFilterEnable = 1U }
| Passive filter feature enable/disable. More...
enum | _port_drive_strength { kPORT_LowDriveStrength = 0U, kPORT_HighDriveStrength = 1U }
| Configures the drive strength. More...
enum | _port_lock_register { kPORT_UnLockRegister = 0U, kPORT_LockRegister = 1U }
| unlock/lock the pin control register field[15:0] More...
enum | port_mux_t { kPORT_PinDisabledOrAnalog = 0U, kPORT_MuxAsGpio = 1U, kPORT_MuxAlt2 = 2U, kPORT_MuxAlt3 = 3U, kPORT_MuxAlt4 = 4U, kPORT_MuxAlt5 = 5U, kPORT_MuxAlt6 = 6U, kPORT_MuxAlt7 = 7U }
| Pin mux selection. More...

enum

port_interrupt_t {
kPORT_InterruptOrDMADisabled = 0x0U,
kPORT_DmaRisingEdge = 0x1U,
kPORT_DmaFallingEdge = 0x2U,
kPORT_DmaEitherEdge = 0x3U,
kPORT_InterruptLogicZero = 0x8U,
kPORT_InterruptRisingEdge = 0x9U,
kPORT_InterruptFallingEdge = 0xAU,
kPORT_InterruptEitherEdge = 0xBU,
kPORT_InterruptLogicOne = 0xCU,
kPORT_ActiveHighTriggerOutputEnable = 0xDU,
kPORT_ActiveLowTriggerOutputEnable = 0xEU
}

| Configures the interrupt generation condition. More...
enum | port_digital_filter_clock_source_t { kPORT_BusClock = 0U, kPORT_LpoClock = 1U }
| Digital filter clock source selection. More...

## Configuration

static void | PORT_SetPinConfig (PORT_Type *base, uint32_t pin, const port_pin_config_t *config)
| Sets the port PCR register. More...
static void | PORT_SetMultiplePinsConfig (PORT_Type *base, uint32_t mask, const port_pin_config_t *config)
| Sets the port PCR register. More...
static void | PORT_SetPinMux (PORT_Type *base, uint32_t pin, port_mux_t mux)
| Configures the pin muxing. More...
static void | PORT_EnablePinsDigitalFilter (PORT_Type *base, uint32_t mask, bool enable)
| Enables the digital filter in one port. Each bit of the 32-bit register represents one pin. More...
static void | PORT_SetDigitalFilterConfig (PORT_Type *base, const port_digital_filter_config_t *config)
| set the digital filter in one port. Each bit of the 32-bit register represents one pin. More...

## Interrupt

static void | PORT_SetPinInterruptConfig (PORT_Type *base, uint32_t pin, const port_interrupt_t config)
| Configures the port pin interrupt/DMA request. More...
static uint32_t | PORT_GetPinsInterruptFlags (PORT_Type *base)
| Reads the whole port status flag. More...
static void | PORT_ClearPinsInterruptFlags (PORT_Type *base, uint32_t mask)
| Clears the multiple pins' interrupt status flag. More...

## Usage Information

This section describes the programming interface of the PORT Peripheral driver. The PORT driver configures PORT module to support other IPs.

# Function groups

## PORT Configuration

This function group configures the PORT PCR of a pin.

## PORT Interrupt

This function sets the PORT pin interrupt configuration and gets and clears the interrupt status of a PORT.

# Typical configuration case

## Input PORT Configuration

/* Input pin PORT configuration */
port_pin_config_t config = {
kPORT_PullUp,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_MuxAsGpio,
kPORT_UnLockRegister,
};
/* Sets the configuration */
PORT_SetPinConfig(PORTA, 4, &config);

## I2C PORT Configuration

/* I2C pin PORTconfiguration */
port_pin_config_t config = {
kPORT_PullUp,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainEnable,
kPORT_LowDriveStrength,
kPORT_MuxAlt5,
kPORT_UnLockRegister,
};
PORT_SetPinConfig(PORTE,24u,&config);
PORT_SetPinConfig(PORTE,25u,&config);

## Data Structure Documentation

struct port_digital_filter_config_t

PORT digital filter feature configuration definition.

Data Fields
port_digital_filter_clock_source_t | clockSource | Set digital filter clockSource
uint32_t | digitalFilterWidth | Set digital filter width

struct port_pin_config_t

PORT pin config structure.

Data Fields
uint16_t | __pad0__: 1 |
uint16_t | __pad1__: 1 |
uint16_t | __pad2__: 1 |
uint16_t | __pad3__: 4 |
uint16_t | __pad4__: 1 |
uint16_t | driveStrength: 1 | fast/slow drive strength configure
uint16_t | lockRegister: 1 | lock/unlock the pcr field[15:0]
uint16_t | mux: 3 | pin mux Configure
uint16_t | openDrainEnable: 1 | open drain enable/disable
uint16_t | passiveFilterEnable: 1 | passive filter enable/disable
uint16_t | pullSelect: 2 | no-pull/pull-down/pull-up select
uint16_t | slewRate: 1 | fast/slow slew rate Configure

## Enumeration Type Documentation

enum _port_drive_strength

Configures the drive strength.

Enumerator
kPORT_LowDriveStrength | low drive strength is configured.
kPORT_HighDriveStrength | high drive strength is configured.

enum _port_lock_register

unlock/lock the pin control register field[15:0]

Enumerator
kPORT_UnLockRegister | Pin Control Register fields [15:0] are not locked.
kPORT_LockRegister | Pin Control Register fields [15:0] are locked.

enum _port_open_drain_enable

Internal resistor pull feature enable/disable.

Enumerator
kPORT_OpenDrainDisable | internal pull-down resistor is disabled.
kPORT_OpenDrainEnable | internal pull-up resistor is enabled.

enum _port_passive_filter_enable

Passive filter feature enable/disable.

Enumerator
kPORT_PassiveFilterDisable | fast slew rate is configured.
kPORT_PassiveFilterEnable | slow slew rate is configured.

enum _port_pull

Internal resistor pull feature selection.

Enumerator
kPORT_PullDisable | internal pull-up/down resistor is disabled.
kPORT_PullDown | internal pull-down resistor is enabled.
kPORT_PullUp | internal pull-up resistor is enabled.

enum _port_slew_rate

Slew rate selection.

Enumerator
kPORT_FastSlewRate | fast slew rate is configured.
kPORT_SlowSlewRate | slow slew rate is configured.

enum port_digital_filter_clock_source_t

Digital filter clock source selection.

Enumerator
kPORT_BusClock | Digital filters are clocked by the bus clock.
kPORT_LpoClock | Digital filters are clocked by the 1 kHz LPO clock.

enum port_interrupt_t

Configures the interrupt generation condition.

Enumerator
kPORT_InterruptOrDMADisabled | Interrupt/DMA request is disabled.
kPORT_DmaRisingEdge | DMA request on rising edge.
kPORT_DmaFallingEdge | DMA request on falling edge.
kPORT_DmaEitherEdge | DMA request on either edge.
kPORT_InterruptLogicZero | Interrupt when logic zero.
kPORT_InterruptRisingEdge | Interrupt on rising edge.
kPORT_InterruptFallingEdge | Interrupt on falling edge.
kPORT_InterruptEitherEdge | Interrupt on either edge.
kPORT_InterruptLogicOne | Interrupt when logic one.
kPORT_ActiveHighTriggerOutputEnable | Enable active high trigger output.
kPORT_ActiveLowTriggerOutputEnable | Enable active low trigger output.

enum port_mux_t

Pin mux selection.

Enumerator
kPORT_PinDisabledOrAnalog | corresponding pin is disabled, but is used as an analog pin.
kPORT_MuxAsGpio | corresponding pin is configured as GPIO.
kPORT_MuxAlt2 | chip-specific
kPORT_MuxAlt3 | chip-specific
kPORT_MuxAlt4 | chip-specific
kPORT_MuxAlt5 | chip-specific
kPORT_MuxAlt6 | chip-specific
kPORT_MuxAlt7 | chip-specific

## Function Documentation

static void PORT_ClearPinsInterruptFlags | ( | PORT_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Clears the multiple pins' interrupt status flag.

Parameters

  base | PORT peripheral base pointer.
  mask | PORT pins' numbers macro.

static void PORT_EnablePinsDigitalFilter | ( | PORT_Type * | base,
|  | uint32_t | mask,
|  | bool | enable
| ) |  |

inlinestatic

Enables the digital filter in one port. Each bit of the 32-bit register represents one pin.

Parameters

  base | PORT peripheral base pointer.
  mask | PORT pins' numbers macro.

static uint32_t PORT_GetPinsInterruptFlags | ( | PORT_Type * | base | ) |

inlinestatic

Reads the whole port status flag.

If a pin is configured to generate the DMA request, the corresponding flag is cleared automatically at the completion of the requested DMA transfer. Otherwise, the flag remains set until a logic one is written to that flag. If configured for a level sensitive interrupt that remains asserted, the flag is set again immediately.

Parameters

  base | PORT peripheral base pointer.

Return values

  Current | port interrupt status flags, for example, 0x00010001 means the pin 0 and 17 have the interrupt.

static void PORT_SetDigitalFilterConfig | ( | PORT_Type * | base,
|  | const port_digital_filter_config_t * | config
| ) |  |

inlinestatic

set the digital filter in one port. Each bit of the 32-bit register represents one pin.

Parameters

  base | PORT peripheral base pointer.
  config | PORT digital filter configuration structure.

static void PORT_SetMultiplePinsConfig | ( | PORT_Type * | base,
|  | uint32_t | mask,
|  | const port_pin_config_t * | config
| ) |  |

inlinestatic

Sets the port PCR register.

This is an example to define an input pin or output pin PCR configuration:

// Define a digital input pin PCR configuration
port_pin_config_t config = {
kPORT_PullUp ,
kPORT_PullEnable,
kPORT_FastSlewRate,
0,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
0,
kPORT_MuxAsGpio,
0,
kPORT_UnLockRegister,
};

Parameters

  base | PORT peripheral base pointer.
  mask | PORT pin mask.
  config | PORT PCR register configure structure.

static void PORT_SetPinConfig | ( | PORT_Type * | base,
|  | uint32_t | pin,
|  | const port_pin_config_t * | config
| ) |  |

inlinestatic

Sets the port PCR register.

This is an example to define an input pin or output pin PCR configuration:

// Define a digital input pin PCR configuration
port_pin_config_t config = {
kPORT_PullUp,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_MuxAsGpio,
kPORT_UnLockRegister,
};

Parameters

  base | PORT peripheral base pointer.
  pin | PORT pin number.
  config | PORT PCR register configure structure.

static void PORT_SetPinInterruptConfig | ( | PORT_Type * | base,
|  | uint32_t | pin,
|  | const port_interrupt_t | config
| ) |  |

inlinestatic

Configures the port pin interrupt/DMA request.

Parameters

  base | PORT peripheral base pointer.
  pin | PORT pin number.

  config

  PORT pin interrupt configuration.
  - kPORT_InterruptOrDMADisabled: Interrupt/DMA request disabled.
  - kPORT_DmaRisingEdge : DMA request on rising edge.
  - kPORT_DmaFallingEdge: DMA request on falling edge.
  - kPORT_DmaEitherEdge : DMA request on either edge.
  - kPORT_InterruptLogicZero : Interrupt when logic zero.
  - kPORT_InterruptRisingEdge : Interrupt on rising edge.
  - kPORT_InterruptFallingEdge: Interrupt on falling edge.
  - kPORT_InterruptEitherEdge : Interrupt on either edge.
  - kPORT_InterruptLogicOne : Interrupt when logic one.
  - kPORT_ActiveHighTriggerOutputEnable : Enable active high trigger output.
  - kPORT_ActiveLowTriggerOutputEnable : Enable active low trigger output.

static void PORT_SetPinMux | ( | PORT_Type * | base,
|  | uint32_t | pin,
|  | port_mux_t | mux
| ) |  |

inlinestatic

Configures the pin muxing.

Parameters

  base | PORT peripheral base pointer.
  pin | PORT pin number.

  mux

  pin muxing slot selection.
  - kPORT_PinDisabledOrAnalog: Pin disabled or work in analog function.
  - kPORT_MuxAsGpio : Set as GPIO.
  - others : chip-specific.

Note : This function is NOT recommended to use together with the PORT_SetPinsConfig, because the PORT_SetPinsConfig need to configure the pin mux anyway(Otherwise the pin mux will be reset to zero : kPORT_PinDisabledOrAnalog). This function is recommended to use in the case you just need to reset the pin mux