SAMV71 Xplained Ultra Software Package 1.3

pio.h File Reference

#include "chip.h"
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  Pin

Defines

#define PIO_PERIPH_A   0
#define PIO_PERIPH_B   1
#define PIO_PERIPH_C   2
#define PIO_PERIPH_D   3
#define PIO_INPUT   4
#define PIO_OUTPUT_0   5
#define PIO_OUTPUT_1   6
#define PIO_DEFAULT   (0 << 0)
#define PIO_PULLUP   (1 << 0)
#define PIO_DEGLITCH   (1 << 1)
#define PIO_OPENDRAIN   (1 << 2)
#define PIO_DEBOUNCE   (1 << 3)
#define PIO_IT_AIME   (1 << 4)
#define PIO_IT_RE_OR_HL   (1 << 5)
#define PIO_IT_EDGE   (1 << 6)
#define PIO_IT_LOW_LEVEL   (0 | 0 | PIO_IT_AIME)
#define PIO_IT_HIGH_LEVEL   (PIO_IT_RE_OR_HL | 0 | PIO_IT_AIME)
#define PIO_IT_FALL_EDGE   (0 | PIO_IT_EDGE | PIO_IT_AIME)
#define PIO_IT_RISE_EDGE   (PIO_IT_RE_OR_HL | PIO_IT_EDGE | PIO_IT_AIME)
#define PIO_WPMR_WPEN_EN   ( 0x01 << 0 )
#define PIO_WPMR_WPEN_DIS   ( 0x00 << 0 )
#define PIO_WPMR_WPKEY_VALID   ( 0x50494F << 8 )
#define PIO_LISTSIZE(pPins)   (sizeof(pPins) / sizeof(Pin))

Functions

uint8_t PIO_Configure (const Pin *list, uint32_t size)
 Configures a list of Pin instances, each of which can either hold a single pin or a group of pins, depending on the mask value; all pins are configured by this function. The size of the array must also be provided and is easily computed using PIO_LISTSIZE whenever its length is not known in advance.
void PIO_Set (const Pin *pin)
 Sets a high output level on all the PIOs defined in the given Pin instance. This has no immediate effects on PIOs that are not output, but the PIO controller will memorize the value they are changed to outputs.
void PIO_Clear (const Pin *pin)
 Sets a low output level on all the PIOs defined in the given Pin instance. This has no immediate effects on PIOs that are not output, but the PIO controller will memorize the value they are changed to outputs.
uint8_t PIO_Get (const Pin *pin)
 Returns 1 if one or more PIO 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_GetOutputDataStatus() instead.
uint8_t PIO_GetOutputDataStatus (const Pin *pin)
 Returns 1 if one or more PIO 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.
void PIO_SetDebounceFilter (const Pin *pin, uint32_t cuttoff)
 Configures Glitch or Denouncing filter for input.
void PIO_EnableWriteProtect (const Pin *pin)
 Enable write protect.
void PIO_DisableWriteProtect (const Pin *pin)
 Disable write protect.
void PIO_SetPinType (Pin *pin, uint8_t pinType)
 Set pin type the pin is controlled by the corresponding peripheral (A, B, C, D,E).
uint32_t PIO_GetWriteProtectViolationInfo (const Pin *pin)
 Get write protect violation information.

Detailed Description

Purpose

This file provides a basic API for PIO configuration and usage of user-controlled pins. Please refer to the board.h file for a list of available pin definitions.

Usage

  1. Define a constant pin description array such as the following one, using the existing definitions provided by the board.h file if possible:
            const Pin pPins[] = {PIN_USART0_TXD, PIN_USART0_RXD};
    
    Alternatively, it is possible to add new pins by provided the full Pin structure:
         // Pin instance to configure PA10 & PA11 as inputs with the internal
         // pull-up enabled.
         const Pin pPins = {
              (1 << 10) | (1 << 11),
              REG_PIOA,
              ID_PIOA,
              PIO_INPUT,
              PIO_PULLUP
         };
    
  2. Configure a pin array by calling PIO_Configure() with a pointer to the array and its size (which is computed using the PIO_LISTSIZE macro).
  3. Change and get the value of a user-controlled pin using the PIO_Set, PIO_Clear and PIO_Get methods.
  4. Get the level being currently output by a user-controlled pin configured as an output using PIO_GetOutputDataStatus().

Definition in file pio.h.


Define Documentation

#define PIO_DEBOUNCE   (1 << 3)

The internal debouncing filter is active.

Definition at line 107 of file pio.h.

#define PIO_DEFAULT   (0 << 0)

Default pin configuration (no attribute).

Definition at line 98 of file pio.h.

#define PIO_DEGLITCH   (1 << 1)

The internal glitch filter is active.

Definition at line 102 of file pio.h.

#define PIO_INPUT   4

The pin is an input.

Definition at line 91 of file pio.h.

#define PIO_IT_AIME   (1 << 4)

Enable additional interrupt modes.

Definition at line 110 of file pio.h.

#define PIO_IT_EDGE   (1 << 6)

Interrupt Edge detection is active.

Definition at line 115 of file pio.h.

#define PIO_IT_FALL_EDGE   (0 | PIO_IT_EDGE | PIO_IT_AIME)

Falling edge interrupt is active

Definition at line 122 of file pio.h.

#define PIO_IT_HIGH_LEVEL   (PIO_IT_RE_OR_HL | 0 | PIO_IT_AIME)

High level interrupt is active

Definition at line 120 of file pio.h.

#define PIO_IT_LOW_LEVEL   (0 | 0 | PIO_IT_AIME)

Low level interrupt is active

Definition at line 118 of file pio.h.

#define PIO_IT_RE_OR_HL   (1 << 5)

Interrupt High Level/Rising Edge detection is active.

Definition at line 113 of file pio.h.

#define PIO_IT_RISE_EDGE   (PIO_IT_RE_OR_HL | PIO_IT_EDGE | PIO_IT_AIME)

Rising edge interrupt is active

Definition at line 124 of file pio.h.

#define PIO_LISTSIZE (   pPins  )     (sizeof(pPins) / sizeof(Pin))

Calculates the size of an array of Pin instances. The array must be defined locally (i.e. not a pointer), otherwise the computation will not be correct.

Parameters:
pPins Local array of Pin instances.
Returns:
Number of elements in array.

Definition at line 145 of file pio.h.

#define PIO_OPENDRAIN   (1 << 2)

The pin is open-drain.

Definition at line 104 of file pio.h.

#define PIO_OUTPUT_0   5

The pin is an output and has a default level of 0.

Definition at line 93 of file pio.h.

#define PIO_OUTPUT_1   6

The pin is an output and has a default level of 1.

Definition at line 95 of file pio.h.

#define PIO_PERIPH_A   0

The pin is controlled by the associated signal of peripheral A.

Definition at line 83 of file pio.h.

#define PIO_PERIPH_B   1

The pin is controlled by the associated signal of peripheral B.

Definition at line 85 of file pio.h.

#define PIO_PERIPH_C   2

The pin is controlled by the associated signal of peripheral C.

Definition at line 87 of file pio.h.

#define PIO_PERIPH_D   3

The pin is controlled by the associated signal of peripheral D.

Definition at line 89 of file pio.h.

#define PIO_PULLUP   (1 << 0)

The internal pin pull-up is active.

Definition at line 100 of file pio.h.

#define PIO_WPMR_WPEN_DIS   ( 0x00 << 0 )

The WP is disable

Definition at line 128 of file pio.h.

#define PIO_WPMR_WPEN_EN   ( 0x01 << 0 )

The WP is enable

Definition at line 126 of file pio.h.

#define PIO_WPMR_WPKEY_VALID   ( 0x50494F << 8 )

Valid WP key

Definition at line 130 of file pio.h.


Function Documentation

void PIO_Clear ( const Pin pin  ) 

Sets a low output level on all the PIOs defined in the given Pin instance. This has no immediate effects on PIOs that are not output, but the PIO controller will memorize the value they are changed to outputs.

Parameters:
pin Pointer to a Pin instance describing one or more pins.

Definition at line 355 of file pio.c.

uint8_t PIO_Configure ( const Pin list,
uint32_t  size 
)

Configures a list of Pin instances, each of which can either hold a single pin or a group of pins, depending on the mask value; all pins are configured by this function. The size of the array must also be provided and is easily computed using PIO_LISTSIZE whenever its length is not known in advance.

Parameters:
list Pointer to a list of Pin instances.
size Size of the Pin list (calculated using PIO_LISTSIZE).
Returns:
1 if the pins have been configured properly; otherwise 0.

Definition at line 280 of file pio.c.

Here is the call graph for this function:

void PIO_DisableWriteProtect ( const Pin pin  ) 

Disable write protect.

Parameters:
pin Pointer to a Pin instance describing one or more pins.

Definition at line 440 of file pio.c.

void PIO_EnableWriteProtect ( const Pin pin  ) 

Enable write protect.

Parameters:
pin Pointer to a Pin instance describing one or more pins.

Definition at line 427 of file pio.c.

uint8_t PIO_Get ( const Pin pin  ) 

Returns 1 if one or more PIO 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_GetOutputDataStatus() instead.

Parameters:
pin Pointer to a Pin instance describing one or more pins.
Returns:
1 if the Pin instance contains at least one PIO that currently has a high level; otherwise 0.

Definition at line 371 of file pio.c.

uint8_t PIO_GetOutputDataStatus ( const Pin pin  ) 

Returns 1 if one or more PIO 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:
pin Pointer to a Pin instance describing one or more pins.
Returns:
1 if the Pin instance contains at least one PIO that is configured to output a high level; otherwise 0.

Definition at line 398 of file pio.c.

uint32_t PIO_GetWriteProtectViolationInfo ( const Pin pin  ) 

Get write protect violation information.

Parameters:
pin Pointer to a Pin instance describing one or more pins.

Definition at line 452 of file pio.c.

void PIO_Set ( const Pin pin  ) 

Sets a high output level on all the PIOs defined in the given Pin instance. This has no immediate effects on PIOs that are not output, but the PIO controller will memorize the value they are changed to outputs.

Parameters:
pin Pointer to a Pin instance describing one or more pins.

Definition at line 342 of file pio.c.

void PIO_SetDebounceFilter ( const Pin pin,
uint32_t  cuttoff 
)

Configures Glitch or Denouncing filter for input.

Parameters:
pin Pointer to a Pin instance describing one or more pins.
cuttoff Cut off frequency for denounce filter.

Definition at line 413 of file pio.c.

void PIO_SetPinType ( Pin pin,
uint8_t  pinType 
)

Set pin type the pin is controlled by the corresponding peripheral (A, B, C, D,E).

Parameters:
pin Pointer to a Pin instance describing one or more pins.
pinType PIO_PERIPH_A, PIO_PERIPH_B, ...

Definition at line 464 of file pio.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines