This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's General Purpose Input/Output (GPIO) pin functionality, for manual pin state reading and writing.
The following peripheral is used by this module:
The following devices can use this module:
The outline of this documentation is as follows:
There are no prerequisites for this module.
The device GPIO (PORT) module provides an interface between the user application logic and external hardware peripherals, when general pin state manipulation is required. This driver provides an easy-to-use interface to the physical pin input samplers and output drivers, so that pins can be read from or written to for general purpose external hardware control.
Driver Feature Macro | Supported devices |
---|---|
FEATURE_PORT_INPUT_EVENT | SAM L21/L22/C20/C21/R30/R34/R35 |
SAM devices use two naming conventions for the I/O pins in the device; one physical and one logical. Each physical pin on a device package is assigned both a physical port and pin identifier (e.g. "PORTA.0") as well as a monotonically incrementing logical GPIO number (e.g. "GPIO0"). While the former is used to map physical pins to their physical internal device module counterparts, for simplicity the design of this driver uses the logical GPIO numbers instead.
The diagram below shows how this module is interconnected within the device.
The SAM port pin input sampler can be disabled when the pin is configured in pure output mode to save power; reading the pin state of a pin configured in output-only mode will read the logical output state that was last set.
For extra information, see Extra Information for PORT Driver. This includes:
For a list of examples related to this driver, see Examples for PORT Driver.
Data Structures | |
struct | port_config |
Port pin configuration structure. More... | |
Enumerations | |
enum | port_pin_dir { PORT_PIN_DIR_INPUT = SYSTEM_PINMUX_PIN_DIR_INPUT, PORT_PIN_DIR_OUTPUT = SYSTEM_PINMUX_PIN_DIR_OUTPUT, PORT_PIN_DIR_OUTPUT_WTH_READBACK = SYSTEM_PINMUX_PIN_DIR_OUTPUT_WITH_READBACK } |
Port pin direction configuration enum. More... | |
enum | port_pin_pull { PORT_PIN_PULL_NONE = SYSTEM_PINMUX_PIN_PULL_NONE, PORT_PIN_PULL_UP = SYSTEM_PINMUX_PIN_PULL_UP, PORT_PIN_PULL_DOWN = SYSTEM_PINMUX_PIN_PULL_DOWN } |
Port pin input pull configuration enum. More... | |
PORT Alias Macros | |
#define | PORTA PORT->Group[0] |
Convenience definition for GPIO module group A on the device (if available). More... | |
#define | PORTB PORT->Group[1] |
Convenience definition for GPIO module group B on the device (if available). More... | |
#define | PORTC PORT->Group[2] |
Convenience definition for GPIO module group C on the device (if available). More... | |
#define | PORTD PORT->Group[3] |
Convenience definition for GPIO module group D on the device (if available). More... | |
State Reading/Writing (Physical Group Orientated) | |
static PortGroup * | port_get_group_from_gpio_pin (const uint8_t gpio_pin) |
Retrieves the PORT module group instance from a given GPIO pin number. More... | |
static uint32_t | port_group_get_input_level (const PortGroup *const port, const uint32_t mask) |
Retrieves the state of a group of port pins that are configured as inputs. More... | |
static uint32_t | port_group_get_output_level (const PortGroup *const port, const uint32_t mask) |
Retrieves the state of a group of port pins that are configured as outputs. More... | |
static void | port_group_set_output_level (PortGroup *const port, const uint32_t mask, const uint32_t level_mask) |
Sets the state of a group of port pins that are configured as outputs. More... | |
static void | port_group_toggle_output_level (PortGroup *const port, const uint32_t mask) |
Toggles the state of a group of port pins that are configured as an outputs. More... | |
Configuration and Initialization | |
static void | port_get_config_defaults (struct port_config *const config) |
Initializes a Port pin/group configuration structure to defaults. More... | |
void | port_pin_set_config (const uint8_t gpio_pin, const struct port_config *const config) |
Writes a Port pin configuration to the hardware module. More... | |
void | port_group_set_config (PortGroup *const port, const uint32_t mask, const struct port_config *const config) |
Writes a Port group configuration group to the hardware module. More... | |
State Reading/Writing (Logical Pin Orientated) | |
static bool | port_pin_get_input_level (const uint8_t gpio_pin) |
Retrieves the state of a port pin that is configured as an input. More... | |
static bool | port_pin_get_output_level (const uint8_t gpio_pin) |
Retrieves the state of a port pin that is configured as an output. More... | |
static void | port_pin_set_output_level (const uint8_t gpio_pin, const bool level) |
Sets the state of a port pin that is configured as an output. More... | |
static void | port_pin_toggle_output_level (const uint8_t gpio_pin) |
Toggles the state of a port pin that is configured as an output. More... | |
#define PORTA PORT->Group[0] |
Convenience definition for GPIO module group A on the device (if available).
#define PORTB PORT->Group[1] |
Convenience definition for GPIO module group B on the device (if available).
#define PORTC PORT->Group[2] |
Convenience definition for GPIO module group C on the device (if available).
#define PORTD PORT->Group[3] |
Convenience definition for GPIO module group D on the device (if available).
enum port_pin_dir |
Port pin direction configuration enum.
Enum for the possible pin direction settings of the port pin configuration structure, to indicate the direction the pin should use.
enum port_pin_pull |
Port pin input pull configuration enum.
Enum for the possible pin pull settings of the port pin configuration structure, to indicate the type of logic level pull the pin should use.
Enumerator | |
---|---|
PORT_PIN_PULL_NONE |
No logical pull should be applied to the pin. |
PORT_PIN_PULL_UP |
Pin should be pulled up when idle. |
PORT_PIN_PULL_DOWN |
Pin should be pulled down when idle. |
|
inlinestatic |
Initializes a Port pin/group configuration structure to defaults.
Initializes a given Port pin/group configuration structure to a set of known default values. This function should be called on all new instances of these configuration structures before being modified by the user application.
The default configuration is as follows:
[out] | config | Configuration structure to initialize to default values |
References Assert, port_config::direction, port_config::input_pull, PORT_PIN_DIR_INPUT, PORT_PIN_PULL_UP, and port_config::powersave.
Referenced by usb_dual_enable().
|
inlinestatic |
Retrieves the PORT module group instance from a given GPIO pin number.
Retrieves the PORT module group instance associated with a given logical GPIO pin number.
[in] | gpio_pin | Index of the GPIO pin to convert |
References system_pinmux_get_group_from_gpio_pin().
Referenced by port_pin_get_input_level(), port_pin_get_output_level(), port_pin_set_output_level(), and port_pin_toggle_output_level().
|
inlinestatic |
Retrieves the state of a group of port pins that are configured as inputs.
Reads the current logic level of a port module's pins and returns the current levels as a bitmask.
[in] | port | Base of the PORT module to read from |
[in] | mask | Mask of the port pin(s) to read |
References Assert.
|
inlinestatic |
Retrieves the state of a group of port pins that are configured as outputs.
Reads the current logical output level of a port module's pins and returns the current levels as a bitmask.
[in] | port | Base of the PORT module to read from |
[in] | mask | Mask of the port pin(s) to read |
References Assert.
void port_group_set_config | ( | PortGroup *const | port, |
const uint32_t | mask, | ||
const struct port_config *const | config | ||
) |
Writes a Port group configuration group to the hardware module.
Writes out a given configuration of a Port group configuration to the hardware module.
[out] | port | Base of the PORT module to write to |
[in] | mask | Mask of the port pin(s) to configure |
[in] | config | Configuration settings for the pin group |
References Assert, system_pinmux_config::direction, port_config::direction, system_pinmux_config::input_pull, port_config::input_pull, system_pinmux_config::mux_position, system_pinmux_config::powersave, port_config::powersave, system_pinmux_get_config_defaults(), SYSTEM_PINMUX_GPIO, and system_pinmux_group_set_config().
|
inlinestatic |
Sets the state of a group of port pins that are configured as outputs.
Sets the current output level of a port module's pins to a given logic level.
[out] | port | Base of the PORT module to write to |
[in] | mask | Mask of the port pin(s) to change |
[in] | level_mask | Mask of the port level(s) to set |
References Assert.
|
inlinestatic |
Toggles the state of a group of port pins that are configured as an outputs.
Toggles the current output levels of a port module's pins.
[out] | port | Base of the PORT module to write to |
[in] | mask | Mask of the port pin(s) to toggle |
References Assert.
|
inlinestatic |
Retrieves the state of a port pin that is configured as an input.
Reads the current logic level of a port pin and returns the current level as a Boolean value.
[in] | gpio_pin | Index of the GPIO pin to read |
References port_get_group_from_gpio_pin().
|
inlinestatic |
Retrieves the state of a port pin that is configured as an output.
Reads the current logical output level of a port pin and returns the current level as a Boolean value.
[in] | gpio_pin | Index of the GPIO pin to read |
References port_get_group_from_gpio_pin().
void port_pin_set_config | ( | const uint8_t | gpio_pin, |
const struct port_config *const | config | ||
) |
Writes a Port pin configuration to the hardware module.
Writes out a given configuration of a Port pin configuration to the hardware module.
[in] | gpio_pin | Index of the GPIO pin to configure |
[in] | config | Configuration settings for the pin |
References Assert, system_pinmux_config::direction, port_config::direction, system_pinmux_config::input_pull, port_config::input_pull, system_pinmux_config::mux_position, system_pinmux_config::powersave, port_config::powersave, system_pinmux_get_config_defaults(), SYSTEM_PINMUX_GPIO, and system_pinmux_pin_set_config().
Referenced by usb_dual_enable().
|
inlinestatic |
Sets the state of a port pin that is configured as an output.
Sets the current output level of a port pin to a given logic level.
[in] | gpio_pin | Index of the GPIO pin to write to |
[in] | level | Logical level to set the given pin to |
References port_get_group_from_gpio_pin().
|
inlinestatic |
Toggles the state of a port pin that is configured as an output.
Toggles the current output level of a port pin.
[in] | gpio_pin | Index of the GPIO pin to toggle |
References port_get_group_from_gpio_pin().