SAM4SD32 (SAM4S-EK2)
Loading...
Searching...
No Matches
Common IOPORT API

See Quick start guide for the common IOPORT service. More...

Macros

#define IOPORT_CREATE_PIN(port, pin)
 Create IOPORT pin number.

Enumerations

enum  ioport_direction {
  IOPORT_DIR_INPUT ,
  IOPORT_DIR_OUTPUT
}
 IOPORT pin directions. More...
enum  ioport_sense {
  IOPORT_SENSE_BOTHEDGES ,
  IOPORT_SENSE_FALLING ,
  IOPORT_SENSE_RISING ,
  IOPORT_SENSE_LEVEL_LOW ,
  IOPORT_SENSE_LEVEL_HIGH
}
 IOPORT edge sense modes. More...
enum  ioport_value {
  IOPORT_PIN_LEVEL_LOW ,
  IOPORT_PIN_LEVEL_HIGH
}
 IOPORT levels. More...

Functions

static void ioport_disable_pin (ioport_pin_t pin)
 Disable IOPORT pin, based on a pin created with IOPORT_CREATE_PIN().
static void ioport_disable_port (ioport_port_t port, ioport_port_mask_t mask)
 Disable multiple pins in a single IOPORT port.
static void ioport_enable_pin (ioport_pin_t pin)
 Enable an IOPORT pin, based on a pin created with IOPORT_CREATE_PIN().
static void ioport_enable_port (ioport_port_t port, ioport_port_mask_t mask)
 Enable multiple pins in a single IOPORT port.
static bool ioport_get_pin_level (ioport_pin_t pin)
 Get current value of an IOPORT pin, which has been configured as an input.
static ioport_port_mask_t ioport_get_port_level (ioport_pin_t port, ioport_port_mask_t mask)
 Get current value of several IOPORT pins in a single port, which have been configured as an inputs.
static void ioport_init (void)
 Initializes the IOPORT service, ready for use.
static ioport_port_mask_t ioport_pin_to_mask (ioport_pin_t pin)
 Convert a pin ID into a bitmask mask for the given pin on its port.
static ioport_port_t ioport_pin_to_port_id (ioport_pin_t pin)
 Convert a pin ID into a its port ID.
static void ioport_reset_pin_mode (ioport_pin_t pin)
 Reset pin mode configuration for a single IOPORT pin.
static void ioport_reset_port_mode (ioport_port_t port, ioport_port_mask_t mask)
 Reset multiple pin modes in a specified IOPORT port to defaults.
static void ioport_set_pin_dir (ioport_pin_t pin, enum ioport_direction dir)
 Set direction for a single IOPORT pin.
static void ioport_set_pin_level (ioport_pin_t pin, bool level)
 Set an IOPORT pin to a specified logical value.
static void ioport_set_pin_mode (ioport_pin_t pin, ioport_mode_t mode)
 Set pin mode for one single IOPORT pin.
static void ioport_set_pin_sense_mode (ioport_pin_t pin, enum ioport_sense pin_sense)
 Set the pin sense mode of a single IOPORT pin.
static void ioport_set_port_dir (ioport_port_t port, ioport_port_mask_t mask, enum ioport_direction dir)
 Set I/O direction for a group of pins in a single IOPORT.
static void ioport_set_port_level (ioport_port_t port, ioport_port_mask_t mask, enum ioport_value level)
 Set a group of IOPORT pins in a single port to a specified logical value.
static void ioport_set_port_mode (ioport_port_t port, ioport_port_mask_t mask, ioport_mode_t mode)
 Set multiple pin modes in a single IOPORT port, such as pull-up, pull-down, etc.
static void ioport_set_port_sense_mode (ioport_port_t port, ioport_port_mask_t mask, enum ioport_sense pin_sense)
 Set the pin sense mode of a multiple IOPORT pins on a single port.
static void ioport_toggle_pin_level (ioport_pin_t pin)
 Toggle the value of an IOPORT pin, which has previously configured as an output.
static void ioport_toggle_port_level (ioport_port_t port, ioport_port_mask_t mask)
 Toggle the values of several IOPORT pins located in a single port.

IOPORT Mode bit definitions

#define IOPORT_MODE_MUX_MASK   (0x7 << 0)
#define IOPORT_MODE_MUX_BIT0   ( 1 << 0)
#define IOPORT_MODE_MUX_BIT1   ( 1 << 1)
#define IOPORT_MODE_MUX_A   ( 0 << 0)
#define IOPORT_MODE_MUX_B   ( 1 << 0)
#define IOPORT_MODE_MUX_C   ( 2 << 0)
#define IOPORT_MODE_MUX_D   ( 3 << 0)
#define IOPORT_MODE_PULLUP   ( 1 << 3)
#define IOPORT_MODE_PULLDOWN   ( 1 << 4)
#define IOPORT_MODE_OPEN_DRAIN   ( 1 << 5)
#define IOPORT_MODE_GLITCH_FILTER   ( 1 << 6)
#define IOPORT_MODE_DEBOUNCE   ( 1 << 7)

Detailed Description

See Quick start guide for the common IOPORT service.

This is common IOPORT service for GPIO pin configuration and control in a standardized manner across the MEGA, MEGA_RF, XMEGA, UC3 and ARM devices.

Port pin control code is optimized for each platform, and should produce both compact and fast execution times when used with constant values.

Dependencies

This driver depends on the following modules:

IOPORT Modes

For details on these please see the SAM Manual.

Macro Definition Documentation

◆ IOPORT_CREATE_PIN

#define IOPORT_CREATE_PIN ( port,
pin )
Value:
((IOPORT_ ## port) * 32 + (pin))

Create IOPORT pin number.

Create a IOPORT pin number for use with the IOPORT functions.

Parameters
portIOPORT port (e.g. PORTA, PA or PIOA depending on chosen architecture)
pinIOPORT zero-based index of the I/O pin

Definition at line 41 of file ioport_pio.h.

◆ IOPORT_MODE_DEBOUNCE

#define IOPORT_MODE_DEBOUNCE   ( 1 << 7)

Input debounce

Definition at line 87 of file ioport_pio.h.

Referenced by arch_ioport_set_port_mode().

◆ IOPORT_MODE_GLITCH_FILTER

#define IOPORT_MODE_GLITCH_FILTER   ( 1 << 6)

Glitch filter

Definition at line 86 of file ioport_pio.h.

Referenced by arch_ioport_set_port_mode().

◆ IOPORT_MODE_MUX_A

#define IOPORT_MODE_MUX_A   ( 0 << 0)

MUX function A

Definition at line 70 of file ioport_pio.h.

◆ IOPORT_MODE_MUX_B

#define IOPORT_MODE_MUX_B   ( 1 << 0)

MUX function B

Definition at line 71 of file ioport_pio.h.

◆ IOPORT_MODE_MUX_BIT0

#define IOPORT_MODE_MUX_BIT0   ( 1 << 0)

MUX BIT0 mask

Definition at line 64 of file ioport_pio.h.

Referenced by arch_ioport_set_port_mode().

◆ IOPORT_MODE_MUX_BIT1

#define IOPORT_MODE_MUX_BIT1   ( 1 << 1)

MUX BIT1 mask

Definition at line 67 of file ioport_pio.h.

Referenced by arch_ioport_set_port_mode().

◆ IOPORT_MODE_MUX_C

#define IOPORT_MODE_MUX_C   ( 2 << 0)

MUX function C

Definition at line 74 of file ioport_pio.h.

◆ IOPORT_MODE_MUX_D

#define IOPORT_MODE_MUX_D   ( 3 << 0)

MUX function D

Definition at line 75 of file ioport_pio.h.

◆ IOPORT_MODE_MUX_MASK

#define IOPORT_MODE_MUX_MASK   (0x7 << 0)

MUX bits mask

Definition at line 63 of file ioport_pio.h.

◆ IOPORT_MODE_OPEN_DRAIN

#define IOPORT_MODE_OPEN_DRAIN   ( 1 << 5)

Open drain

Definition at line 84 of file ioport_pio.h.

Referenced by arch_ioport_set_port_mode().

◆ IOPORT_MODE_PULLDOWN

#define IOPORT_MODE_PULLDOWN   ( 1 << 4)

Pull-down

Definition at line 81 of file ioport_pio.h.

Referenced by arch_ioport_set_port_mode().

◆ IOPORT_MODE_PULLUP

#define IOPORT_MODE_PULLUP   ( 1 << 3)

Pull-up

Definition at line 78 of file ioport_pio.h.

Referenced by arch_ioport_set_port_mode().

Enumeration Type Documentation

◆ ioport_direction

IOPORT pin directions.

Enumerator
IOPORT_DIR_INPUT 

IOPORT input direction

IOPORT_DIR_OUTPUT 

IOPORT output direction

Definition at line 76 of file ioport.h.

76 {
79};
@ IOPORT_DIR_OUTPUT
Definition ioport.h:78
@ IOPORT_DIR_INPUT
Definition ioport.h:77

◆ ioport_sense

IOPORT edge sense modes.

Enumerator
IOPORT_SENSE_BOTHEDGES 

IOPORT sense both rising and falling edges

IOPORT_SENSE_FALLING 

IOPORT sense falling edges

IOPORT_SENSE_RISING 

IOPORT sense rising edges

IOPORT_SENSE_LEVEL_LOW 

IOPORT sense low level

IOPORT_SENSE_LEVEL_HIGH 

IOPORT sense High level

Definition at line 97 of file ioport.h.

97 {
103};
@ IOPORT_SENSE_LEVEL_HIGH
Definition ioport.h:102
@ IOPORT_SENSE_BOTHEDGES
Definition ioport.h:98
@ IOPORT_SENSE_RISING
Definition ioport.h:100
@ IOPORT_SENSE_LEVEL_LOW
Definition ioport.h:101
@ IOPORT_SENSE_FALLING
Definition ioport.h:99

◆ ioport_value

IOPORT levels.

Enumerator
IOPORT_PIN_LEVEL_LOW 

IOPORT pin value low

IOPORT_PIN_LEVEL_HIGH 

IOPORT pin value high

Definition at line 82 of file ioport.h.

82 {
85};
@ IOPORT_PIN_LEVEL_LOW
Definition ioport.h:83
@ IOPORT_PIN_LEVEL_HIGH
Definition ioport.h:84

Function Documentation

◆ ioport_disable_pin()

void ioport_disable_pin ( ioport_pin_t pin)
inlinestatic

Disable IOPORT pin, based on a pin created with IOPORT_CREATE_PIN().

Parameters
pinIOPORT pin to disable

Definition at line 179 of file ioport.h.

180{
182}
static __always_inline void arch_ioport_disable_pin(ioport_pin_t pin)
Definition ioport_pio.h:171

References arch_ioport_disable_pin().

◆ ioport_disable_port()

void ioport_disable_port ( ioport_port_t port,
ioport_port_mask_t mask )
inlinestatic

Disable multiple pins in a single IOPORT port.

Parameters
portIOPORT port to disable
maskPin mask of pins to disable

Definition at line 190 of file ioport.h.

192{
193 arch_ioport_disable_port(port, mask);
194}
static __always_inline void arch_ioport_disable_port(ioport_port_t port, ioport_port_mask_t mask)
Definition ioport_pio.h:159

References arch_ioport_disable_port().

◆ ioport_enable_pin()

void ioport_enable_pin ( ioport_pin_t pin)
inlinestatic

Enable an IOPORT pin, based on a pin created with IOPORT_CREATE_PIN().

Parameters
pinIOPORT pin to enable

Definition at line 156 of file ioport.h.

157{
159}
static __always_inline void arch_ioport_enable_pin(ioport_pin_t pin)
Definition ioport_pio.h:165

References arch_ioport_enable_pin().

◆ ioport_enable_port()

void ioport_enable_port ( ioport_port_t port,
ioport_port_mask_t mask )
inlinestatic

Enable multiple pins in a single IOPORT port.

Parameters
portIOPORT port to enable
maskMask of pins within the port to enable

Definition at line 167 of file ioport.h.

169{
170 arch_ioport_enable_port(port, mask);
171}
static __always_inline void arch_ioport_enable_port(ioport_port_t port, ioport_port_mask_t mask)
Definition ioport_pio.h:153

References arch_ioport_enable_port().

◆ ioport_get_pin_level()

bool ioport_get_pin_level ( ioport_pin_t pin)
inlinestatic

Get current value of an IOPORT pin, which has been configured as an input.

Parameters
pinIOPORT pin to read
Returns
Current logical value of the specified pin

Definition at line 301 of file ioport.h.

302{
303 return arch_ioport_get_pin_level(pin);
304}
static __always_inline bool arch_ioport_get_pin_level(ioport_pin_t pin)
Definition ioport_pio.h:302

References arch_ioport_get_pin_level().

◆ ioport_get_port_level()

ioport_port_mask_t ioport_get_port_level ( ioport_pin_t port,
ioport_port_mask_t mask )
inlinestatic

Get current value of several IOPORT pins in a single port, which have been configured as an inputs.

Parameters
portIOPORT port to read
maskPin mask of pins to read
Returns
Logical levels of the specified pins from the read port, returned as a mask.

Definition at line 315 of file ioport.h.

317{
318 return arch_ioport_get_port_level(port, mask);
319}
static __always_inline ioport_port_mask_t arch_ioport_get_port_level(ioport_port_t port, ioport_port_mask_t mask)
Definition ioport_pio.h:307

References arch_ioport_get_port_level().

◆ ioport_init()

void ioport_init ( void )
inlinestatic

Initializes the IOPORT service, ready for use.

This function must be called before using any other functions in the IOPORT service.

Definition at line 145 of file ioport.h.

146{
148}
static __always_inline void arch_ioport_init(void)
Definition ioport_pio.h:131

References arch_ioport_init().

◆ ioport_pin_to_mask()

ioport_port_mask_t ioport_pin_to_mask ( ioport_pin_t pin)
inlinestatic

Convert a pin ID into a bitmask mask for the given pin on its port.

Parameters
pinIOPORT pin ID to convert
Return values
Bitmaskwith a bit set that corresponds to the given pin ID in its port

Definition at line 387 of file ioport.h.

388{
389 return arch_ioport_pin_to_mask(pin);
390}
static __always_inline ioport_port_mask_t arch_ioport_pin_to_mask(ioport_pin_t pin)
Definition ioport_pio.h:126

References arch_ioport_pin_to_mask().

◆ ioport_pin_to_port_id()

ioport_port_t ioport_pin_to_port_id ( ioport_pin_t pin)
inlinestatic

Convert a pin ID into a its port ID.

Parameters
pinIOPORT pin ID to convert
Return values
PortID for the given pin ID

Definition at line 376 of file ioport.h.

377{
378 return arch_ioport_pin_to_port_id(pin);
379}
static __always_inline ioport_port_t arch_ioport_pin_to_port_id(ioport_pin_t pin)
Definition ioport_pio.h:97

References arch_ioport_pin_to_port_id().

◆ ioport_reset_pin_mode()

void ioport_reset_pin_mode ( ioport_pin_t pin)
inlinestatic

Reset pin mode configuration for a single IOPORT pin.

Parameters
pinIOPORT pin to configure

Definition at line 239 of file ioport.h.

240{
242}
static __always_inline void arch_ioport_set_pin_mode(ioport_pin_t pin, ioport_mode_t mode)
Definition ioport_pio.h:243

References arch_ioport_set_pin_mode().

◆ ioport_reset_port_mode()

void ioport_reset_port_mode ( ioport_port_t port,
ioport_port_mask_t mask )
inlinestatic

Reset multiple pin modes in a specified IOPORT port to defaults.

Parameters
portIOPORT port to configure
maskMask of pins whose mode configuration is to be reset

Definition at line 228 of file ioport.h.

230{
231 arch_ioport_set_port_mode(port, mask, 0);
232}
static __always_inline void arch_ioport_set_port_mode(ioport_port_t port, ioport_port_mask_t mask, ioport_mode_t mode)
Definition ioport_pio.h:177

References arch_ioport_set_port_mode().

◆ ioport_set_pin_dir()

void ioport_set_pin_dir ( ioport_pin_t pin,
enum ioport_direction dir )
inlinestatic

Set direction for a single IOPORT pin.

Parameters
pinIOPORT pin to configure
dirDirection to set for the specified pin (ioport_direction)

Definition at line 263 of file ioport.h.

265{
266 arch_ioport_set_pin_dir(pin, dir);
267}
static __always_inline void arch_ioport_set_pin_dir(ioport_pin_t pin, enum ioport_direction dir)
Definition ioport_pio.h:264

References arch_ioport_set_pin_dir().

◆ ioport_set_pin_level()

void ioport_set_pin_level ( ioport_pin_t pin,
bool level )
inlinestatic

Set an IOPORT pin to a specified logical value.

Parameters
pinIOPORT pin to configure
levelLogical value of the pin

Definition at line 275 of file ioport.h.

276{
277 arch_ioport_set_pin_level(pin, level);
278}
static __always_inline void arch_ioport_set_pin_level(ioport_pin_t pin, bool level)
Definition ioport_pio.h:278

References arch_ioport_set_pin_level().

◆ ioport_set_pin_mode()

void ioport_set_pin_mode ( ioport_pin_t pin,
ioport_mode_t mode )
inlinestatic

Set pin mode for one single IOPORT pin.

Parameters
pinIOPORT pin to configure
modeMode masks to configure for the specified pin (IOPORT Modes)

Definition at line 217 of file ioport.h.

218{
219 arch_ioport_set_pin_mode(pin, mode);
220}

References arch_ioport_set_pin_mode().

◆ ioport_set_pin_sense_mode()

void ioport_set_pin_sense_mode ( ioport_pin_t pin,
enum ioport_sense pin_sense )
inlinestatic

Set the pin sense mode of a single IOPORT pin.

Parameters
pinIOPORT pin to configure
pin_senseEdge to sense for the pin (ioport_sense)

Definition at line 350 of file ioport.h.

352{
353 arch_ioport_set_pin_sense_mode(pin, pin_sense);
354}
static __always_inline void arch_ioport_set_pin_sense_mode(ioport_pin_t pin, enum ioport_sense pin_sense)
Definition ioport_pio.h:366

References arch_ioport_set_pin_sense_mode().

◆ ioport_set_port_dir()

void ioport_set_port_dir ( ioport_port_t port,
ioport_port_mask_t mask,
enum ioport_direction dir )
inlinestatic

Set I/O direction for a group of pins in a single IOPORT.

Parameters
portIOPORT port to configure
maskPin mask of pins to configure
dirDirection to set for the specified pins (ioport_direction)

Definition at line 251 of file ioport.h.

253{
254 arch_ioport_set_port_dir(port, mask, dir);
255}
static __always_inline void arch_ioport_set_port_dir(ioport_port_t port, ioport_port_mask_t mask, enum ioport_direction group_direction)
Definition ioport_pio.h:250

References arch_ioport_set_port_dir().

◆ ioport_set_port_level()

void ioport_set_port_level ( ioport_port_t port,
ioport_port_mask_t mask,
enum ioport_value level )
inlinestatic

Set a group of IOPORT pins in a single port to a specified logical value.

Parameters
portIOPORT port to write to
maskPin mask of pins to modify
levelLevel of the pins to be modified

Definition at line 288 of file ioport.h.

290{
291 arch_ioport_set_port_level(port, mask, level);
292}
static __always_inline void arch_ioport_set_port_level(ioport_port_t port, ioport_port_mask_t mask, enum ioport_value level)
Definition ioport_pio.h:290

References arch_ioport_set_port_level().

◆ ioport_set_port_mode()

void ioport_set_port_mode ( ioport_port_t port,
ioport_port_mask_t mask,
ioport_mode_t mode )
inlinestatic

Set multiple pin modes in a single IOPORT port, such as pull-up, pull-down, etc.

configuration.

Parameters
portIOPORT port to configure
maskPin mask of pins to configure
modeMode masks to configure for the specified pins (IOPORT Modes)

Definition at line 205 of file ioport.h.

207{
208 arch_ioport_set_port_mode(port, mask, mode);
209}

References arch_ioport_set_port_mode().

◆ ioport_set_port_sense_mode()

void ioport_set_port_sense_mode ( ioport_port_t port,
ioport_port_mask_t mask,
enum ioport_sense pin_sense )
inlinestatic

Set the pin sense mode of a multiple IOPORT pins on a single port.

Parameters
portIOPORT port to configure
maskBitmask if pins whose edge sense is to be configured
pin_senseEdge to sense for the pins (ioport_sense)

Definition at line 363 of file ioport.h.

366{
367 arch_ioport_set_port_sense_mode(port, mask, pin_sense);
368}
static __always_inline void arch_ioport_set_port_sense_mode(ioport_port_t port, ioport_port_mask_t mask, enum ioport_sense pin_sense)
Definition ioport_pio.h:331

References arch_ioport_set_port_sense_mode().

◆ ioport_toggle_pin_level()

void ioport_toggle_pin_level ( ioport_pin_t pin)
inlinestatic

Toggle the value of an IOPORT pin, which has previously configured as an output.

Parameters
pinIOPORT pin to toggle

Definition at line 327 of file ioport.h.

328{
330}
static __always_inline void arch_ioport_toggle_pin_level(ioport_pin_t pin)
Definition ioport_pio.h:313

References arch_ioport_toggle_pin_level().

◆ ioport_toggle_port_level()

void ioport_toggle_port_level ( ioport_port_t port,
ioport_port_mask_t mask )
inlinestatic

Toggle the values of several IOPORT pins located in a single port.

Parameters
portIOPORT port to modify
maskPin mask of pins to toggle

Definition at line 338 of file ioport.h.

340{
342}
static __always_inline void arch_ioport_toggle_port_level(ioport_port_t port, ioport_port_mask_t mask)
Definition ioport_pio.h:325

References arch_ioport_toggle_port_level().