Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Common IOPORT API

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 device datasheet.

Modules

 
 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the Common IOPORT API.
 

Macros

#define IOPORT_CREATE_PIN(port, pin)   ((port) * 32 + (pin))
 Create IOPORT pin number. More...
 

Enumerations

enum  ioport_direction {
  IOPORT_DIR_INPUT,
  IOPORT_DIR_OUTPUT
}
 IOPORT pin directions. More...
 
enum  ioport_sense {
  IOPORT_SENSE_BOTHEDGES,
  IOPORT_SENSE_RISING,
  IOPORT_SENSE_FALLING
}
 
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(). More...
 
static void ioport_disable_port (ioport_port_t port, ioport_port_mask_t mask)
 Disable multiple pins in a single IOPORT port. More...
 
static void ioport_enable_pin (ioport_pin_t pin)
 Enable an IOPORT pin, based on a pin created with IOPORT_CREATE_PIN(). More...
 
static void ioport_enable_port (ioport_port_t port, ioport_port_mask_t mask)
 Enable multiple pins in a single IOPORT port. More...
 
static bool ioport_get_pin_level (ioport_pin_t pin)
 Get current value of an IOPORT pin, which has been configured as an input. More...
 
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. More...
 
static void ioport_init (void)
 Initializes the IOPORT service, ready for use. More...
 
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. More...
 
static ioport_port_t ioport_pin_to_port_id (ioport_pin_t pin)
 Convert a pin ID into a its port ID. More...
 
static void ioport_reset_pin_mode (ioport_pin_t pin)
 Reset pin mode configuration for a single IOPORT pin. More...
 
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. More...
 
static void ioport_set_pin_dir (ioport_pin_t pin, enum ioport_direction dir)
 Set direction for a single IOPORT pin. More...
 
static void ioport_set_pin_level (ioport_pin_t pin, bool level)
 Set an IOPORT pin to a specified logical value. More...
 
static void ioport_set_pin_mode (ioport_pin_t pin, ioport_mode_t mode)
 Set pin mode for one single IOPORT pin. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static void ioport_toggle_pin_level (ioport_pin_t pin)
 Toggle the value of an IOPORT pin, which has previously configured as an output. More...
 
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. More...
 

IOPORT Mode bit definitions

#define IOPORT_MODE_MUX_MASK   (7 << 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_MUX_BIT2   (1 << 2)
 
#define IOPORT_MODE_MUX_E   (4 << 0)
 
#define IOPORT_MODE_MUX_F   (5 << 0)
 
#define IOPORT_MODE_MUX_G   (6 << 0)
 
#define IOPORT_MODE_MUX_H   (7 << 0)
 
#define IOPORT_MODE_PULLUP   (1 << 3)
 
#define IOPORT_MODE_PULLDOWN   (1 << 4)
 
#define IOPORT_MODE_GLITCH_FILTER   (1 << 6)
 
#define IOPORT_MODE_DRIVE_STRENGTH   (1 << 7)
 

#define IOPORT_CREATE_PIN (   port,
  pin 
)    ((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
#define IOPORT_MODE_DRIVE_STRENGTH   (1 << 7)

Extra drive strength

Referenced by arch_ioport_set_port_mode().

#define IOPORT_MODE_GLITCH_FILTER   (1 << 6)

Glitch filter

Referenced by arch_ioport_set_port_mode(), main(), and run_gpio_int_test().

#define IOPORT_MODE_MUX_A   (0 << 0)

MUX function A

#define IOPORT_MODE_MUX_B   (1 << 0)

MUX function B

#define IOPORT_MODE_MUX_BIT0   (1 << 0)

MUX BIT0 mask

Referenced by arch_ioport_set_port_mode().

#define IOPORT_MODE_MUX_BIT1   (1 << 1)

MUX BIT1 mask

Referenced by arch_ioport_set_port_mode().

#define IOPORT_MODE_MUX_BIT2   (1 << 2)

MUX BIT2 mask

Referenced by arch_ioport_set_port_mode().

#define IOPORT_MODE_MUX_C   (2 << 0)

MUX function C

Referenced by main().

#define IOPORT_MODE_MUX_D   (3 << 0)

MUX function D

#define IOPORT_MODE_MUX_E   (4 << 0)

MUX function E

#define IOPORT_MODE_MUX_F   (5 << 0)

MUX function F

#define IOPORT_MODE_MUX_G   (6 << 0)

MUX function G

#define IOPORT_MODE_MUX_H   (7 << 0)

MUX function H

#define IOPORT_MODE_MUX_MASK   (7 << 0)

MUX bits mask

#define IOPORT_MODE_PULLDOWN   (1 << 4)

Pull-down

Referenced by arch_ioport_set_port_mode().

#define IOPORT_MODE_PULLUP   (1 << 3)

IOPORT pin directions.

Enumerator
IOPORT_DIR_INPUT 

IOPORT input direction

IOPORT_DIR_OUTPUT 

IOPORT output direction

Enumerator
IOPORT_SENSE_BOTHEDGES 

IOPORT sense both rising and falling edges

IOPORT_SENSE_RISING 

IOPORT sense rising edges

IOPORT_SENSE_FALLING 

IOPORT sense falling edges

IOPORT levels.

Enumerator
IOPORT_PIN_LEVEL_LOW 

IOPORT pin value low

IOPORT_PIN_LEVEL_HIGH 

IOPORT pin value high

static 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

References arch_ioport_disable_pin().

Referenced by main(), and run_eic_test().

static 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

References arch_ioport_disable_port().

static 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

References arch_ioport_enable_pin().

static 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

References arch_ioport_enable_port().

static 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

References arch_ioport_get_pin_level().

Referenced by button_pressed(), eic_pad_init(), key_state_read(), main(), qt_is_change_line_low(), run_gloc_4inputs_xor_test(), sd_mmc_is_write_protected(), sd_mmc_select_slot(), wait_for_pushbutton(), and wait_for_switches().

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

References arch_ioport_get_port_level().

Referenced by main().

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

References arch_ioport_init().

Referenced by main().

static 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

References arch_ioport_pin_to_mask().

Referenced by gpio_clear_pin_interrupt_flag(), gpio_common_handler(), gpio_disable_pin_interrupt(), gpio_disable_pin_periph_event(), gpio_enable_pin_interrupt(), gpio_enable_pin_periph_event(), gpio_get_pin_interrupt_flag(), and gpio_set_pin_callback().

static 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

References arch_ioport_pin_to_port_id().

Referenced by gpio_clear_pin_interrupt_flag(), gpio_common_handler(), gpio_disable_pin_interrupt(), gpio_disable_pin_periph_event(), gpio_enable_pin_interrupt(), gpio_enable_pin_periph_event(), gpio_get_pin_interrupt_flag(), and gpio_set_pin_callback().

static void ioport_reset_pin_mode ( ioport_pin_t  pin)
inlinestatic

Reset pin mode configuration for a single IOPORT pin.

Parameters
pinIOPORT pin to configure

References arch_ioport_set_pin_mode().

static 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

References arch_ioport_set_port_mode().

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

References arch_ioport_set_pin_dir().

Referenced by main(), run_eic_test(), run_gloc_4inputs_xor_test(), run_gpio_int_test(), and sio2ncp_init().

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

References arch_ioport_set_pin_mode().

Referenced by io_pad_init(), main(), run_eic_test(), and run_gpio_int_test().

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

References arch_ioport_set_pin_sense_mode().

Referenced by io_pad_init(), main(), and run_gpio_int_test().

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

References arch_ioport_set_port_dir().

Referenced by main().

static 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

References arch_ioport_set_port_level().

Referenced by main().

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

References arch_ioport_set_port_mode().

Referenced by main().

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

References arch_ioport_set_port_sense_mode().

static 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

References arch_ioport_toggle_pin_level().

Referenced by main(), SysTick_Handler(), and TC00_Handler().

static 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

References arch_ioport_toggle_port_level().

Referenced by main().