SAM4SD32 (SAM4S-EK2)
Loading...
Searching...
No Matches
Peripheral Parallel Input/Output (PIO) Controller

Topics

 Legacy PIO group alias

Macros

#define FREQ_SLOW_CLOCK_EXT   32768

Functions

void pio_capture_disable (Pio *p_pio)
 Disable PIO capture mode.
void pio_capture_disable_interrupt (Pio *p_pio, const uint32_t ul_mask)
 Disable a given interrupt source of PIO capture.
void pio_capture_enable (Pio *p_pio)
 Enable PIO capture mode.
void pio_capture_enable_interrupt (Pio *p_pio, const uint32_t ul_mask)
 Enable the given interrupt source of PIO capture.
uint32_t pio_capture_get_interrupt_mask (const Pio *p_pio)
 Read PIO interrupt mask of PIO capture.
uint32_t pio_capture_get_interrupt_status (const Pio *p_pio)
 Read PIO interrupt status of PIO capture.
Pdc * pio_capture_get_pdc_base (const Pio *p_pio)
 Get PDC registers base address.
uint32_t pio_capture_read (const Pio *p_pio, uint32_t *pul_data)
 Read from Capture Reception Holding Register.
void pio_capture_set_mode (Pio *p_pio, uint32_t ul_mode)
 Configure PIO capture mode.
void pio_clear (Pio *p_pio, const uint32_t ul_mask)
 Set a low output level on all the PIOs defined in ul_mask.
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.
void pio_configure_interrupt (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_attr)
 Configure the given interrupt source.
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.
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.
void pio_disable_interrupt (Pio *p_pio, const uint32_t ul_mask)
 Disable a given interrupt source, with no added side effects.
void pio_disable_output_write (Pio *p_pio, const uint32_t ul_mask)
 Disable PIO output write.
void pio_disable_pin_interrupt (uint32_t ul_pin)
 Disable interrupt for a GPIO pin.
void pio_enable_interrupt (Pio *p_pio, const uint32_t ul_mask)
 Enable the given interrupt source.
void pio_enable_output_write (Pio *p_pio, const uint32_t ul_mask)
 Enable PIO output write for synchronous data output.
void pio_enable_pin_interrupt (uint32_t ul_pin)
 Enable interrupt for a GPIO pin.
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.
uint32_t pio_get_interrupt_mask (const Pio *p_pio)
 Read PIO interrupt mask.
uint32_t pio_get_interrupt_status (const Pio *p_pio)
 Read and clear PIO interrupt status.
uint32_t pio_get_multi_driver_status (const Pio *p_pio)
 Get multi-driver status.
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).
uint32_t pio_get_output_write_status (const Pio *p_pio)
 Read PIO output write status.
Piopio_get_pin_group (uint32_t ul_pin)
 Return GPIO port for a GPIO pin.
uint32_t pio_get_pin_group_id (uint32_t ul_pin)
 Return GPIO port peripheral ID for a GPIO pin.
uint32_t pio_get_pin_group_mask (uint32_t ul_pin)
 Return GPIO port pin mask for a GPIO pin.
uint32_t pio_get_pin_value (uint32_t ul_pin)
 Return the value of a pin.
uint32_t pio_get_schmitt_trigger (const Pio *p_pio)
 Get PIO pin schmitt trigger status.
uint32_t pio_get_writeprotect_status (const Pio *p_pio)
 Read write protect status.
void pio_pull_down (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_pull_down_enable)
 Configure PIO pin internal pull-down.
void pio_pull_up (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_pull_up_enable)
 Configure PIO internal pull-up.
void pio_set (Pio *p_pio, const uint32_t ul_mask)
 Set a high output level on all the PIOs defined in ul_mask.
void pio_set_additional_interrupt_mode (Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_attribute)
 Set additional interrupt mode.
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).
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.
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.
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.
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.
void pio_set_pin_group_high (Pio *p_pio, uint32_t ul_mask)
 Drive a GPIO port to 1.
void pio_set_pin_group_low (Pio *p_pio, uint32_t ul_mask)
 Drive a GPIO port to 0.
void pio_set_pin_high (uint32_t ul_pin)
 Drive a GPIO pin to 1.
void pio_set_pin_low (uint32_t ul_pin)
 Drive a GPIO pin to 0.
void pio_set_schmitt_trigger (Pio *p_pio, const uint32_t ul_mask)
 Configure PIO pin schmitt trigger.
void pio_set_writeprotect (Pio *p_pio, const uint32_t ul_enable)
 Enable or disable write protect of PIO registers.
void pio_sync_output_write (Pio *p_pio, const uint32_t ul_mask)
 Synchronously write on output pins.
void pio_toggle_pin (uint32_t ul_pin)
 Toggle a GPIO pin.
void pio_toggle_pin_group (Pio *p_pio, uint32_t ul_mask)
 Toggle a GPIO group.

Variables

uint32_t pio_capture_enable_flag

Detailed Description

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.

Macro Definition Documentation

◆ FREQ_SLOW_CLOCK_EXT

#define FREQ_SLOW_CLOCK_EXT   32768

Definition at line 58 of file pio.c.

Referenced by pio_set_debounce_filter().

Function Documentation

◆ pio_capture_disable()

void pio_capture_disable ( Pio * p_pio)

Disable PIO capture mode.

Parameters
p_pioPointer to a PIO instance.

Definition at line 1064 of file pio.c.

1065{
1066 p_pio->PIO_PCMR &= (~PIO_PCMR_PCEN);
1068}
#define PIO_PCMR_PCEN
(PIO_PCMR) Parallel Capture Mode Enable
uint32_t pio_capture_enable_flag
Definition pio.c:1033
__IO uint32_t PIO_PCMR
(Pio Offset: 0x150) Parallel Capture Mode Register

References pio_capture_enable_flag, Pio::PIO_PCMR, and PIO_PCMR_PCEN.

◆ pio_capture_disable_interrupt()

void pio_capture_disable_interrupt ( Pio * p_pio,
const uint32_t ul_mask )

Disable a given interrupt source of PIO capture.

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

Definition at line 1112 of file pio.c.

1113{
1114 p_pio->PIO_PCIDR = ul_mask;
1115}
__O uint32_t PIO_PCIDR
(Pio Offset: 0x158) Parallel Capture Interrupt Disable Register

References Pio::PIO_PCIDR.

◆ pio_capture_enable()

void pio_capture_enable ( Pio * p_pio)

Enable PIO capture mode.

Parameters
p_pioPointer to a PIO instance.

Definition at line 1053 of file pio.c.

1054{
1055 p_pio->PIO_PCMR |= PIO_PCMR_PCEN;
1057}

References pio_capture_enable_flag, Pio::PIO_PCMR, and PIO_PCMR_PCEN.

◆ pio_capture_enable_interrupt()

void pio_capture_enable_interrupt ( Pio * p_pio,
const uint32_t ul_mask )

Enable the given interrupt source of PIO capture.

The status register of the corresponding PIO capture controller is cleared prior to enabling the interrupt.

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

Definition at line 1100 of file pio.c.

1101{
1102 p_pio->PIO_PCISR;
1103 p_pio->PIO_PCIER = ul_mask;
1104}
__I uint32_t PIO_PCISR
(Pio Offset: 0x160) Parallel Capture Interrupt Status Register
__O uint32_t PIO_PCIER
(Pio Offset: 0x154) Parallel Capture Interrupt Enable Register

References Pio::PIO_PCIER, and Pio::PIO_PCISR.

◆ pio_capture_get_interrupt_mask()

uint32_t pio_capture_get_interrupt_mask ( const Pio * p_pio)

Read PIO interrupt mask of PIO capture.

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

Definition at line 1136 of file pio.c.

1137{
1138 return p_pio->PIO_PCIMR;
1139}
__I uint32_t PIO_PCIMR
(Pio Offset: 0x15C) Parallel Capture Interrupt Mask Register

References Pio::PIO_PCIMR.

◆ pio_capture_get_interrupt_status()

uint32_t pio_capture_get_interrupt_status ( const Pio * p_pio)

Read PIO interrupt status of PIO capture.

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

Definition at line 1124 of file pio.c.

1125{
1126 return p_pio->PIO_PCISR;
1127}

References Pio::PIO_PCISR.

◆ pio_capture_get_pdc_base()

Pdc * pio_capture_get_pdc_base ( const Pio * p_pio)

Get PDC registers base address.

Parameters
p_pioPointer to an PIO peripheral.
Returns
PIOA PDC register base address.

Definition at line 1148 of file pio.c.

1149{
1150 UNUSED(p_pio); /* Stop warning */
1151 return PDC_PIOA;
1152}
#define PDC_PIOA
(PDC_PIOA ) Base Address
Definition sam4sd32c.h:448

References PDC_PIOA.

◆ pio_capture_read()

uint32_t pio_capture_read ( const Pio * p_pio,
uint32_t * pul_data )

Read from Capture Reception Holding Register.

Note
Data presence should be tested before any read attempt.
Parameters
p_pioPointer to a PIO instance.
pul_dataPointer to store the data.
Return values
0Success.
1I/O Failure, Capture data is not ready.

Definition at line 1080 of file pio.c.

1081{
1082 /* Check if the data is ready */
1083 if ((p_pio->PIO_PCISR & PIO_PCISR_DRDY) == 0) {
1084 return 1;
1085 }
1086
1087 /* Read data */
1088 *pul_data = p_pio->PIO_PCRHR;
1089 return 0;
1090}
#define PIO_PCISR_DRDY
(PIO_PCISR) Parallel Capture Mode Data Ready
__I uint32_t PIO_PCRHR
(Pio Offset: 0x164) Parallel Capture Reception Holding Register

References Pio::PIO_PCISR, PIO_PCISR_DRDY, and Pio::PIO_PCRHR.

◆ pio_capture_set_mode()

void pio_capture_set_mode ( Pio * p_pio,
uint32_t ul_mode )

Configure PIO capture mode.

Note
PIO capture mode will be disabled automatically.
Parameters
p_pioPointer to a PIO instance.
ul_modeBitmask of one or more modes.

Definition at line 1042 of file pio.c.

1043{
1044 ul_mode &= (~PIO_PCMR_PCEN); /* Disable PIO capture mode */
1045 p_pio->PIO_PCMR = ul_mode;
1046}

References Pio::PIO_PCMR, and PIO_PCMR_PCEN.

◆ pio_clear()

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.

Definition at line 130 of file pio.c.

131{
132 p_pio->PIO_CODR = ul_mask;
133}
__O uint32_t PIO_CODR
(Pio Offset: 0x0034) Clear Output Data Register

References Pio::PIO_CODR.

◆ pio_configure()

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.

Definition at line 348 of file pio.c.

350{
351 /* Configure pins */
352 switch (ul_type) {
353 case PIO_PERIPH_A:
354 case PIO_PERIPH_B:
355#if (SAM3S || SAM3N || SAM4S || SAM4E || SAM4N || SAM4C || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
356 case PIO_PERIPH_C:
357 case PIO_PERIPH_D:
358#endif
359 pio_set_peripheral(p_pio, ul_type, ul_mask);
360 pio_pull_up(p_pio, ul_mask, (ul_attribute & PIO_PULLUP));
361 break;
362
363 case PIO_INPUT:
364 pio_set_input(p_pio, ul_mask, ul_attribute);
365 break;
366
367 case PIO_OUTPUT_0:
368 case PIO_OUTPUT_1:
369 pio_set_output(p_pio, ul_mask, (ul_type == PIO_OUTPUT_1),
370 (ul_attribute & PIO_OPENDRAIN) ? 1 : 0,
371 (ul_attribute & PIO_PULLUP) ? 1 : 0);
372 break;
373
374 default:
375 return 0;
376 }
377
378 return 1;
379}
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.
Definition pio.c:174
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.
Definition pio.c:257
void pio_pull_up(Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_pull_up_enable)
Configure PIO internal pull-up.
Definition pio.c:69
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.
Definition pio.c:310
@ PIO_OUTPUT_0
Definition pio.h:79
@ PIO_OUTPUT_1
Definition pio.h:80
@ PIO_PERIPH_B
Definition pio.h:73
@ PIO_PERIPH_A
Definition pio.h:72
@ PIO_PERIPH_C
Definition pio.h:75
@ PIO_INPUT
Definition pio.h:78
@ PIO_PERIPH_D
Definition pio.h:76
#define PIO_OPENDRAIN
Definition pio.h:90
#define PIO_PULLUP
Definition pio.h:86

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

◆ pio_configure_interrupt()

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.

Definition at line 538 of file pio.c.

540{
541 /* Configure additional interrupt mode registers. */
542 if (ul_attr & PIO_IT_AIME) {
543 /* Enable additional interrupt mode. */
544 p_pio->PIO_AIMER = ul_mask;
545
546 /* If bit field of the selected pin is 1, set as
547 Rising Edge/High level detection event. */
548 if (ul_attr & PIO_IT_RE_OR_HL) {
549 /* Rising Edge or High Level */
550 p_pio->PIO_REHLSR = ul_mask;
551 } else {
552 /* Falling Edge or Low Level */
553 p_pio->PIO_FELLSR = ul_mask;
554 }
555
556 /* If bit field of the selected pin is 1, set as
557 edge detection source. */
558 if (ul_attr & PIO_IT_EDGE) {
559 /* Edge select */
560 p_pio->PIO_ESR = ul_mask;
561 } else {
562 /* Level select */
563 p_pio->PIO_LSR = ul_mask;
564 }
565 } else {
566 /* Disable additional interrupt mode. */
567 p_pio->PIO_AIMDR = ul_mask;
568 }
569}
#define PIO_IT_RE_OR_HL
Definition pio.h:99
#define PIO_IT_AIME
Definition pio.h:96
#define PIO_IT_EDGE
Definition pio.h:101
__O uint32_t PIO_ESR
(Pio Offset: 0x00C0) Edge Select Register
__O uint32_t PIO_REHLSR
(Pio Offset: 0x00D4) Rising Edge/ High Level Select Register
__O uint32_t PIO_LSR
(Pio Offset: 0x00C4) Level Select Register
__O uint32_t PIO_AIMER
(Pio Offset: 0x00B0) Additional Interrupt Modes Enable Register
__O uint32_t PIO_AIMDR
(Pio Offset: 0x00B4) Additional Interrupt Modes Disables Register
__O uint32_t PIO_FELLSR
(Pio Offset: 0x00D0) Falling Edge/Low Level Select Register

References Pio::PIO_AIMDR, Pio::PIO_AIMER, Pio::PIO_ESR, Pio::PIO_FELLSR, PIO_IT_AIME, PIO_IT_EDGE, PIO_IT_RE_OR_HL, Pio::PIO_LSR, and Pio::PIO_REHLSR.

Referenced by pio_handler_set().

◆ pio_configure_pin()

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.

Definition at line 763 of file pio.c.

764{
765 Pio *p_pio = pio_get_pin_group(ul_pin);
766
767 /* Configure pins */
768 switch (ul_flags & PIO_TYPE_Msk) {
770 pio_set_peripheral(p_pio, PIO_PERIPH_A, (1 << (ul_pin & 0x1F)));
771 pio_pull_up(p_pio, (1 << (ul_pin & 0x1F)),
772 (ul_flags & PIO_PULLUP));
773 break;
775 pio_set_peripheral(p_pio, PIO_PERIPH_B, (1 << (ul_pin & 0x1F)));
776 pio_pull_up(p_pio, (1 << (ul_pin & 0x1F)),
777 (ul_flags & PIO_PULLUP));
778 break;
779#if (SAM3S || SAM3N || SAM4S || SAM4E || SAM4N || SAM4C || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
781 pio_set_peripheral(p_pio, PIO_PERIPH_C, (1 << (ul_pin & 0x1F)));
782 pio_pull_up(p_pio, (1 << (ul_pin & 0x1F)),
783 (ul_flags & PIO_PULLUP));
784 break;
786 pio_set_peripheral(p_pio, PIO_PERIPH_D, (1 << (ul_pin & 0x1F)));
787 pio_pull_up(p_pio, (1 << (ul_pin & 0x1F)),
788 (ul_flags & PIO_PULLUP));
789 break;
790#endif
791
793 pio_set_input(p_pio, (1 << (ul_pin & 0x1F)), ul_flags);
794 break;
795
798 pio_set_output(p_pio, (1 << (ul_pin & 0x1F)),
799 ((ul_flags & PIO_TYPE_PIO_OUTPUT_1)
800 == PIO_TYPE_PIO_OUTPUT_1) ? 1 : 0,
801 (ul_flags & PIO_OPENDRAIN) ? 1 : 0,
802 (ul_flags & PIO_PULLUP) ? 1 : 0);
803 break;
804
805 default:
806 return 0;
807 }
808
809 return 1;
810}
Pio * pio_get_pin_group(uint32_t ul_pin)
Return GPIO port for a GPIO pin.
Definition pio.c:944
#define PIO_TYPE_PIO_OUTPUT_0
Definition pio.h:66
#define PIO_TYPE_PIO_OUTPUT_1
Definition pio.h:68
#define PIO_TYPE_PIO_PERIPH_B
Definition pio.h:58
#define PIO_TYPE_PIO_PERIPH_A
Definition pio.h:56
#define PIO_TYPE_PIO_INPUT
Definition pio.h:64
#define PIO_TYPE_PIO_PERIPH_C
Definition pio.h:60
#define PIO_TYPE_PIO_PERIPH_D
Definition pio.h:62
#define PIO_TYPE_Msk
Definition pio.h:52
Pio hardware registers.

References pio_get_pin_group(), PIO_OPENDRAIN, PIO_PERIPH_A, PIO_PERIPH_B, PIO_PERIPH_C, PIO_PERIPH_D, 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.

◆ pio_configure_pin_group()

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.

Definition at line 863 of file pio.c.

865{
866 /* Configure pins */
867 switch (ul_flags & PIO_TYPE_Msk) {
869 pio_set_peripheral(p_pio, PIO_PERIPH_A, ul_mask);
870 pio_pull_up(p_pio, ul_mask, (ul_flags & PIO_PULLUP));
871 break;
873 pio_set_peripheral(p_pio, PIO_PERIPH_B, ul_mask);
874 pio_pull_up(p_pio, ul_mask, (ul_flags & PIO_PULLUP));
875 break;
876#if (SAM3S || SAM3N || SAM4S || SAM4E || SAM4N || SAM4C || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
878 pio_set_peripheral(p_pio, PIO_PERIPH_C, ul_mask);
879 pio_pull_up(p_pio, ul_mask, (ul_flags & PIO_PULLUP));
880 break;
882 pio_set_peripheral(p_pio, PIO_PERIPH_D, ul_mask);
883 pio_pull_up(p_pio, ul_mask, (ul_flags & PIO_PULLUP));
884 break;
885#endif
886
888 pio_set_input(p_pio, ul_mask, ul_flags);
889 break;
890
893 pio_set_output(p_pio, ul_mask,
894 ((ul_flags & PIO_TYPE_PIO_OUTPUT_1)
895 == PIO_TYPE_PIO_OUTPUT_1) ? 1 : 0,
896 (ul_flags & PIO_OPENDRAIN) ? 1 : 0,
897 (ul_flags & PIO_PULLUP) ? 1 : 0);
898 break;
899
900 default:
901 return 0;
902 }
903
904 return 1;
905}

References PIO_OPENDRAIN, PIO_PERIPH_A, PIO_PERIPH_B, PIO_PERIPH_C, PIO_PERIPH_D, 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.

◆ pio_disable_interrupt()

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.

Definition at line 589 of file pio.c.

590{
591 p_pio->PIO_IDR = ul_mask;
592}
__O uint32_t PIO_IDR
(Pio Offset: 0x0044) Interrupt Disable Register

References Pio::PIO_IDR.

Referenced by pio_handler_set_priority(), pio_set_input(), and pio_set_output().

◆ pio_disable_output_write()

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.

Definition at line 472 of file pio.c.

473{
474 p_pio->PIO_OWDR = ul_mask;
475}
__O uint32_t PIO_OWDR
(Pio Offset: 0x00A4) Output Write Disable

References Pio::PIO_OWDR.

◆ pio_disable_pin_interrupt()

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.

Definition at line 929 of file pio.c.

930{
931 Pio *p_pio = pio_get_pin_group(ul_pin);
932
933 p_pio->PIO_IDR = 1 << (ul_pin & 0x1F);
934}

References pio_get_pin_group(), and Pio::PIO_IDR.

◆ pio_enable_interrupt()

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.

Definition at line 578 of file pio.c.

579{
580 p_pio->PIO_IER = ul_mask;
581}
__O uint32_t PIO_IER
(Pio Offset: 0x0040) Interrupt Enable Register

References Pio::PIO_IER.

Referenced by pio_handler_set_priority().

◆ pio_enable_output_write()

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.

Definition at line 461 of file pio.c.

462{
463 p_pio->PIO_OWER = ul_mask;
464}
__O uint32_t PIO_OWER
(Pio Offset: 0x00A0) Output Write Enable

References Pio::PIO_OWER.

◆ pio_enable_pin_interrupt()

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.

Definition at line 914 of file pio.c.

915{
916 Pio *p_pio = pio_get_pin_group(ul_pin);
917
918 p_pio->PIO_IER = 1 << (ul_pin & 0x1F);
919}

References pio_get_pin_group(), and Pio::PIO_IER.

◆ pio_get()

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.

Definition at line 148 of file pio.c.

150{
151 uint32_t ul_reg;
152
153 if ((ul_type == PIO_OUTPUT_0) || (ul_type == PIO_OUTPUT_1)) {
154 ul_reg = p_pio->PIO_ODSR;
155 } else {
156 ul_reg = p_pio->PIO_PDSR;
157 }
158
159 if ((ul_reg & ul_mask) == 0) {
160 return 0;
161 } else {
162 return 1;
163 }
164}
__I uint32_t PIO_PDSR
(Pio Offset: 0x003C) Pin Data Status Register
__IO uint32_t PIO_ODSR
(Pio Offset: 0x0038) Output Data Status Register

References Pio::PIO_ODSR, PIO_OUTPUT_0, PIO_OUTPUT_1, and Pio::PIO_PDSR.

◆ pio_get_interrupt_mask()

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.

Definition at line 613 of file pio.c.

614{
615 return p_pio->PIO_IMR;
616}
__I uint32_t PIO_IMR
(Pio Offset: 0x0048) Interrupt Mask Register

References Pio::PIO_IMR.

Referenced by pio_handler_process(), and pio_handler_set_priority().

◆ pio_get_interrupt_status()

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.

Definition at line 601 of file pio.c.

602{
603 return p_pio->PIO_ISR;
604}
__I uint32_t PIO_ISR
(Pio Offset: 0x004C) Interrupt Status Register

References Pio::PIO_ISR.

Referenced by pio_handler_process(), and pio_handler_set_priority().

◆ pio_get_multi_driver_status()

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.

Definition at line 428 of file pio.c.

429{
430 return p_pio->PIO_MDSR;
431}
__I uint32_t PIO_MDSR
(Pio Offset: 0x0058) Multi-driver Status Register

References Pio::PIO_MDSR.

◆ pio_get_output_data_status()

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.

Definition at line 392 of file pio.c.

394{
395 if ((p_pio->PIO_ODSR & ul_mask) == 0) {
396 return 0;
397 } else {
398 return 1;
399 }
400}

References Pio::PIO_ODSR.

◆ pio_get_output_write_status()

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.

Definition at line 484 of file pio.c.

485{
486 return p_pio->PIO_OWSR;
487}
__I uint32_t PIO_OWSR
(Pio Offset: 0x00A8) Output Write Status Register

References Pio::PIO_OWSR.

◆ pio_get_pin_group()

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.

Definition at line 944 of file pio.c.

945{
946 Pio *p_pio;
947
948#if (SAM4C || SAM4CP)
949# ifdef ID_PIOD
950 if (ul_pin > PIO_PC9_IDX) {
951 p_pio = PIOD;
952 } else if (ul_pin > PIO_PB31_IDX) {
953# else
954 if (ul_pin > PIO_PB31_IDX) {
955# endif
956 p_pio = PIOC;
957 } else {
958 p_pio = (Pio *)((uint32_t)PIOA + (PIO_DELTA * (ul_pin >> 5)));
959 }
960#elif (SAM4CM)
961 if (ul_pin > PIO_PB21_IDX) {
962 p_pio = PIOC;
963 } else {
964 p_pio = (Pio *)((uint32_t)PIOA + (PIO_DELTA * (ul_pin >> 5)));
965 }
966#else
967 p_pio = (Pio *)((uint32_t)PIOA + (PIO_DELTA * (ul_pin >> 5)));
968#endif
969 return p_pio;
970}
#define PIO_DELTA
Definition pio.h:47
#define PIO_PC9_IDX
#define PIOA
(PIOA ) Base Address
Definition sam4sd32c.h:447
#define PIOC
(PIOC ) Base Address
Definition sam4sd32c.h:450

References PIO_DELTA, PIO_PC9_IDX, PIOA, and PIOC.

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().

◆ pio_get_pin_group_id()

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.

Definition at line 979 of file pio.c.

980{
981 uint32_t ul_id;
982
983#if (SAM4C || SAM4CP)
984# ifdef ID_PIOD
985 if (ul_pin > PIO_PC9_IDX) {
986 ul_id = ID_PIOD;
987 } else if (ul_pin > PIO_PB31_IDX) {
988# else
989 if (ul_pin > PIO_PB31_IDX) {
990# endif
991 ul_id = ID_PIOC;
992 } else {
993 ul_id = ID_PIOA + (ul_pin >> 5);
994 }
995#elif (SAM4CM)
996 if (ul_pin > PIO_PB21_IDX) {
997 ul_id = ID_PIOC;
998 } else {
999 ul_id = ID_PIOA + (ul_pin >> 5);
1000 }
1001#elif (SAMV70 || SAMV71 || SAME70 || SAMS70)
1002 ul_id = ID_PIOA + (ul_pin >> 5);
1003
1004 #ifdef ID_PIOD
1005 if (ul_pin >= PIO_PD0_IDX) ul_id = ID_PIOD;
1006 #endif
1007
1008 #ifdef ID_PIOE
1009 if (ul_pin >= PIO_PE0_IDX) ul_id = ID_PIOE;
1010 #endif
1011#else
1012 ul_id = ID_PIOA + (ul_pin >> 5);
1013#endif
1014 return ul_id;
1015}
#define ID_PIOA
Parallel I/O Controller A (PIOA).
Definition sam4sd32c.h:331
#define ID_PIOC
Parallel I/O Controller C (PIOC).
Definition sam4sd32c.h:333

References ID_PIOA, ID_PIOC, and PIO_PC9_IDX.

◆ pio_get_pin_group_mask()

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.

Definition at line 1025 of file pio.c.

1026{
1027 uint32_t ul_mask = 1 << (ul_pin & 0x1F);
1028 return ul_mask;
1029}

◆ pio_get_pin_value()

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.

Definition at line 697 of file pio.c.

698{
699 Pio *p_pio = pio_get_pin_group(ul_pin);
700
701 return (p_pio->PIO_PDSR >> (ul_pin & 0x1F)) & 1;
702}

References pio_get_pin_group(), and Pio::PIO_PDSR.

◆ pio_get_schmitt_trigger()

uint32_t pio_get_schmitt_trigger ( const Pio * p_pio)

Get PIO pin schmitt trigger status.

Parameters
p_pioPointer to a PIO instance.
Returns
The schmitt trigger mask value.

Definition at line 523 of file pio.c.

524{
525 return p_pio->PIO_SCHMITT;
526}
__IO uint32_t PIO_SCHMITT
(Pio Offset: 0x0100) Schmitt Trigger Register

References Pio::PIO_SCHMITT.

◆ pio_get_writeprotect_status()

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.

Definition at line 679 of file pio.c.

680{
681 return p_pio->PIO_WPSR;
682}
__I uint32_t PIO_WPSR
(Pio Offset: 0x00E8) Write Protect Status Register

References Pio::PIO_WPSR.

◆ pio_pull_down()

void pio_pull_down ( Pio * p_pio,
const uint32_t ul_mask,
const uint32_t ul_pull_down_enable )

Configure PIO pin internal pull-down.

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

Definition at line 443 of file pio.c.

445{
446 /* Enable the pull-down if necessary */
447 if (ul_pull_down_enable) {
448 p_pio->PIO_PPDER = ul_mask;
449 } else {
450 p_pio->PIO_PPDDR = ul_mask;
451 }
452}
__O uint32_t PIO_PPDDR
(Pio Offset: 0x0090) Pad Pull-down Disable Register
__O uint32_t PIO_PPDER
(Pio Offset: 0x0094) Pad Pull-down Enable Register

References Pio::PIO_PPDDR, and Pio::PIO_PPDER.

◆ pio_pull_up()

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.

Definition at line 69 of file pio.c.

71{
72 /* Enable the pull-up(s) if necessary */
73 if (ul_pull_up_enable) {
74 p_pio->PIO_PUER = ul_mask;
75 } else {
76 p_pio->PIO_PUDR = ul_mask;
77 }
78}
__O uint32_t PIO_PUDR
(Pio Offset: 0x0060) Pull-up Disable Register
__O uint32_t PIO_PUER
(Pio Offset: 0x0064) Pull-up Enable Register

References Pio::PIO_PUDR, and Pio::PIO_PUER.

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

◆ pio_set()

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.

Definition at line 117 of file pio.c.

118{
119 p_pio->PIO_SODR = ul_mask;
120}
__O uint32_t PIO_SODR
(Pio Offset: 0x0030) Set Output Data Register

References Pio::PIO_SODR.

◆ pio_set_additional_interrupt_mode()

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.

Definition at line 625 of file pio.c.

627{
628 /* Enables additional interrupt mode if needed */
629 if (ul_attribute & PIO_IT_AIME) {
630 /* Enables additional interrupt mode */
631 p_pio->PIO_AIMER = ul_mask;
632
633 /* Configures the Polarity of the event detection */
634 /* (Rising/Falling Edge or High/Low Level) */
635 if (ul_attribute & PIO_IT_RE_OR_HL) {
636 /* Rising Edge or High Level */
637 p_pio->PIO_REHLSR = ul_mask;
638 } else {
639 /* Falling Edge or Low Level */
640 p_pio->PIO_FELLSR = ul_mask;
641 }
642
643 /* Configures the type of event detection (Edge or Level) */
644 if (ul_attribute & PIO_IT_EDGE) {
645 /* Edge select */
646 p_pio->PIO_ESR = ul_mask;
647 } else {
648 /* Level select */
649 p_pio->PIO_LSR = ul_mask;
650 }
651 } else {
652 /* Disable additional interrupt mode */
653 p_pio->PIO_AIMDR = ul_mask;
654 }
655}

References Pio::PIO_AIMDR, Pio::PIO_AIMER, Pio::PIO_ESR, Pio::PIO_FELLSR, PIO_IT_AIME, PIO_IT_EDGE, PIO_IT_RE_OR_HL, Pio::PIO_LSR, and Pio::PIO_REHLSR.

◆ pio_set_debounce_filter()

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.

Definition at line 87 of file pio.c.

89{
90#if (SAM3S || SAM3N || SAM4S || SAM4E || SAM4N || SAM4C || SAMG || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
91 /* Set Debouncing, 0 bit field no effect */
92 p_pio->PIO_IFSCER = ul_mask;
93#elif (SAM3XA || SAM3U)
94 /* Set Debouncing, 0 bit field no effect */
95 p_pio->PIO_DIFSR = ul_mask;
96#else
97#error "Unsupported device"
98#endif
99
100 /*
101 * The debouncing filter can filter a pulse of less than 1/2 Period of a
102 * programmable Divided Slow Clock:
103 * Tdiv_slclk = ((DIV+1)*2).Tslow_clock
104 */
106 (2 * (ul_cut_off))) - 1);
107}
#define PIO_SCDR_DIV(value)
#define FREQ_SLOW_CLOCK_EXT
Definition pio.c:58
__IO uint32_t PIO_SCDR
(Pio Offset: 0x008C) Slow Clock Divider Debouncing Register
__O uint32_t PIO_IFSCER
(Pio Offset: 0x0084) Input Filter Slow Clock Enable Register

References FREQ_SLOW_CLOCK_EXT, Pio::PIO_IFSCER, Pio::PIO_SCDR, and PIO_SCDR_DIV.

◆ pio_set_input()

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).

Definition at line 257 of file pio.c.

259{
260 pio_disable_interrupt(p_pio, ul_mask);
261 pio_pull_up(p_pio, ul_mask, ul_attribute & PIO_PULLUP);
262
263 /* Enable Input Filter if necessary */
264 if (ul_attribute & (PIO_DEGLITCH | PIO_DEBOUNCE)) {
265 p_pio->PIO_IFER = ul_mask;
266 } else {
267 p_pio->PIO_IFDR = ul_mask;
268 }
269
270#if (SAM3S || SAM3N || SAM4S || SAM4E || SAM4N || SAM4C || SAMG || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
271 /* Enable de-glitch or de-bounce if necessary */
272 if (ul_attribute & PIO_DEGLITCH) {
273 p_pio->PIO_IFSCDR = ul_mask;
274 } else {
275 if (ul_attribute & PIO_DEBOUNCE) {
276 p_pio->PIO_IFSCER = ul_mask;
277 }
278 }
279#elif (SAM3XA|| SAM3U)
280 /* Enable de-glitch or de-bounce if necessary */
281 if (ul_attribute & PIO_DEGLITCH) {
282 p_pio->PIO_SCIFSR = ul_mask;
283 } else {
284 if (ul_attribute & PIO_DEBOUNCE) {
285 p_pio->PIO_DIFSR = ul_mask;
286 }
287 }
288#else
289#error "Unsupported device"
290#endif
291
292 /* Configure pin as input */
293 p_pio->PIO_ODR = ul_mask;
294 p_pio->PIO_PER = ul_mask;
295}
void pio_disable_interrupt(Pio *p_pio, const uint32_t ul_mask)
Disable a given interrupt source, with no added side effects.
Definition pio.c:589
#define PIO_DEBOUNCE
Definition pio.h:93
#define PIO_DEGLITCH
Definition pio.h:88
__O uint32_t PIO_IFDR
(Pio Offset: 0x0024) Glitch Input Filter Disable Register
__O uint32_t PIO_ODR
(Pio Offset: 0x0014) Output Disable Register
__O uint32_t PIO_PER
(Pio Offset: 0x0000) PIO Enable Register
__O uint32_t PIO_IFSCDR
(Pio Offset: 0x0080) Input Filter Slow Clock Disable Register
__O uint32_t PIO_IFER
(Pio Offset: 0x0020) Glitch Input Filter Enable Register

References PIO_DEBOUNCE, PIO_DEGLITCH, pio_disable_interrupt(), Pio::PIO_IFDR, Pio::PIO_IFER, Pio::PIO_IFSCDR, Pio::PIO_IFSCER, Pio::PIO_ODR, Pio::PIO_PER, pio_pull_up(), and PIO_PULLUP.

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

◆ pio_set_multi_driver()

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.

Definition at line 410 of file pio.c.

412{
413 /* Enable the multi-driver if necessary */
414 if (ul_multi_driver_enable) {
415 p_pio->PIO_MDER = ul_mask;
416 } else {
417 p_pio->PIO_MDDR = ul_mask;
418 }
419}
__O uint32_t PIO_MDDR
(Pio Offset: 0x0054) Multi-driver Disable Register
__O uint32_t PIO_MDER
(Pio Offset: 0x0050) Multi-driver Enable Register

References Pio::PIO_MDDR, and Pio::PIO_MDER.

◆ pio_set_output()

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.

Definition at line 310 of file pio.c.

314{
315 pio_disable_interrupt(p_pio, ul_mask);
316 pio_pull_up(p_pio, ul_mask, ul_pull_up_enable);
317
318 /* Enable multi-drive if necessary */
319 if (ul_multidrive_enable) {
320 p_pio->PIO_MDER = ul_mask;
321 } else {
322 p_pio->PIO_MDDR = ul_mask;
323 }
324
325 /* Set default value */
326 if (ul_default_level) {
327 p_pio->PIO_SODR = ul_mask;
328 } else {
329 p_pio->PIO_CODR = ul_mask;
330 }
331
332 /* Configure pin(s) as output(s) */
333 p_pio->PIO_OER = ul_mask;
334 p_pio->PIO_PER = ul_mask;
335}
__O uint32_t PIO_OER
(Pio Offset: 0x0010) Output Enable Register

References Pio::PIO_CODR, pio_disable_interrupt(), Pio::PIO_MDDR, Pio::PIO_MDER, Pio::PIO_OER, Pio::PIO_PER, pio_pull_up(), and Pio::PIO_SODR.

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

◆ pio_set_peripheral()

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.

Definition at line 174 of file pio.c.

176{
177 uint32_t ul_sr;
178
179 /* Disable interrupts on the pin(s) */
180 p_pio->PIO_IDR = ul_mask;
181
182#if (SAM3S || SAM3N || SAM4S || SAM4E || SAM4N || SAM4C || SAMG || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
183 switch (ul_type) {
184 case PIO_PERIPH_A:
185 ul_sr = p_pio->PIO_ABCDSR[0];
186 p_pio->PIO_ABCDSR[0] &= (~ul_mask & ul_sr);
187
188 ul_sr = p_pio->PIO_ABCDSR[1];
189 p_pio->PIO_ABCDSR[1] &= (~ul_mask & ul_sr);
190 break;
191 case PIO_PERIPH_B:
192 ul_sr = p_pio->PIO_ABCDSR[0];
193 p_pio->PIO_ABCDSR[0] = (ul_mask | ul_sr);
194
195 ul_sr = p_pio->PIO_ABCDSR[1];
196 p_pio->PIO_ABCDSR[1] &= (~ul_mask & ul_sr);
197 break;
198#if (!SAMG)
199 case PIO_PERIPH_C:
200 ul_sr = p_pio->PIO_ABCDSR[0];
201 p_pio->PIO_ABCDSR[0] &= (~ul_mask & ul_sr);
202
203 ul_sr = p_pio->PIO_ABCDSR[1];
204 p_pio->PIO_ABCDSR[1] = (ul_mask | ul_sr);
205 break;
206 case PIO_PERIPH_D:
207 ul_sr = p_pio->PIO_ABCDSR[0];
208 p_pio->PIO_ABCDSR[0] = (ul_mask | ul_sr);
209
210 ul_sr = p_pio->PIO_ABCDSR[1];
211 p_pio->PIO_ABCDSR[1] = (ul_mask | ul_sr);
212 break;
213#endif
214 /* Other types are invalid in this function */
215 case PIO_INPUT:
216 case PIO_OUTPUT_0:
217 case PIO_OUTPUT_1:
218 case PIO_NOT_A_PIN:
219 return;
220 }
221#elif (SAM3XA|| SAM3U)
222 switch (ul_type) {
223 case PIO_PERIPH_A:
224 ul_sr = p_pio->PIO_ABSR;
225 p_pio->PIO_ABSR &= (~ul_mask & ul_sr);
226 break;
227
228 case PIO_PERIPH_B:
229 ul_sr = p_pio->PIO_ABSR;
230 p_pio->PIO_ABSR = (ul_mask | ul_sr);
231 break;
232
233 // other types are invalid in this function
234 case PIO_INPUT:
235 case PIO_OUTPUT_0:
236 case PIO_OUTPUT_1:
237 case PIO_NOT_A_PIN:
238 return;
239 }
240#else
241#error "Unsupported device"
242#endif
243
244 /* Remove the pins from under the control of PIO */
245 p_pio->PIO_PDR = ul_mask;
246}
@ PIO_NOT_A_PIN
Definition pio.h:71
__IO uint32_t PIO_ABCDSR[2]
(Pio Offset: 0x0070) Peripheral Select Register
__O uint32_t PIO_PDR
(Pio Offset: 0x0004) PIO Disable Register

References Pio::PIO_ABCDSR, Pio::PIO_IDR, PIO_INPUT, PIO_NOT_A_PIN, PIO_OUTPUT_0, PIO_OUTPUT_1, Pio::PIO_PDR, PIO_PERIPH_A, PIO_PERIPH_B, PIO_PERIPH_C, and PIO_PERIPH_D.

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

◆ pio_set_pin_group_high()

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.

Definition at line 818 of file pio.c.

819{
820 /* Value to be driven on the I/O line: 1. */
821 p_pio->PIO_SODR = ul_mask;
822}

References Pio::PIO_SODR.

◆ pio_set_pin_group_low()

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.

Definition at line 830 of file pio.c.

831{
832 /* Value to be driven on the I/O line: 0. */
833 p_pio->PIO_CODR = ul_mask;
834}

References Pio::PIO_CODR.

◆ pio_set_pin_high()

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.

Definition at line 711 of file pio.c.

712{
713 Pio *p_pio = pio_get_pin_group(ul_pin);
714
715 /* Value to be driven on the I/O line: 1. */
716 p_pio->PIO_SODR = 1 << (ul_pin & 0x1F);
717}

References pio_get_pin_group(), and Pio::PIO_SODR.

◆ pio_set_pin_low()

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.

Definition at line 726 of file pio.c.

727{
728 Pio *p_pio = pio_get_pin_group(ul_pin);
729
730 /* Value to be driven on the I/O line: 0. */
731 p_pio->PIO_CODR = 1 << (ul_pin & 0x1F);
732}

References Pio::PIO_CODR, and pio_get_pin_group().

◆ pio_set_schmitt_trigger()

void pio_set_schmitt_trigger ( Pio * p_pio,
const uint32_t ul_mask )

Configure PIO pin schmitt trigger.

By default the Schmitt trigger is active. Disabling the Schmitt Trigger is requested when using the QTouch Library.

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

Definition at line 511 of file pio.c.

512{
513 p_pio->PIO_SCHMITT = ul_mask;
514}

References Pio::PIO_SCHMITT.

◆ pio_set_writeprotect()

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.

Definition at line 667 of file pio.c.

668{
669 p_pio->PIO_WPMR = PIO_WPMR_WPKEY_PASSWD | (ul_enable & PIO_WPMR_WPEN);
670}
#define PIO_WPMR_WPEN
(PIO_WPMR) Write Protect Enable
#define PIO_WPMR_WPKEY_PASSWD
Definition pio.c:40
__IO uint32_t PIO_WPMR
(Pio Offset: 0x00E4) Write Protect Mode Register

References Pio::PIO_WPMR, PIO_WPMR_WPEN, and PIO_WPMR_WPKEY_PASSWD.

◆ pio_sync_output_write()

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.

Definition at line 497 of file pio.c.

498{
499 p_pio->PIO_ODSR = ul_mask;
500}

References Pio::PIO_ODSR.

◆ pio_toggle_pin()

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.

Definition at line 741 of file pio.c.

742{
743 Pio *p_pio = pio_get_pin_group(ul_pin);
744
745 if (p_pio->PIO_ODSR & (1 << (ul_pin & 0x1F))) {
746 /* Value to be driven on the I/O line: 0. */
747 p_pio->PIO_CODR = 1 << (ul_pin & 0x1F);
748 } else {
749 /* Value to be driven on the I/O line: 1. */
750 p_pio->PIO_SODR = 1 << (ul_pin & 0x1F);
751 }
752}

References Pio::PIO_CODR, pio_get_pin_group(), Pio::PIO_ODSR, and Pio::PIO_SODR.

◆ pio_toggle_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.

Definition at line 842 of file pio.c.

843{
844 if (p_pio->PIO_ODSR & ul_mask) {
845 /* Value to be driven on the I/O line: 0. */
846 p_pio->PIO_CODR = ul_mask;
847 } else {
848 /* Value to be driven on the I/O line: 1. */
849 p_pio->PIO_SODR = ul_mask;
850 }
851}

References Pio::PIO_CODR, Pio::PIO_ODSR, and Pio::PIO_SODR.

Variable Documentation

◆ pio_capture_enable_flag

uint32_t pio_capture_enable_flag

Definition at line 1033 of file pio.c.

Referenced by pio_capture_disable(), pio_capture_enable(), and pio_handler_process().