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.
Modules | |
Quick Start Guide(s) | |
In this section you can find a list of all Quick Start guides related to the SAM Port (PORT) Driver. | |
Data Structures | |
struct | port_config |
Port pin configuration structure. More... | |
struct | port_input_event_config |
Port input event configuration structure. More... | |
Enumerations | |
enum | port_input_event { PORT_INPUT_EVENT_0 = 0, PORT_INPUT_EVENT_1 = 1, PORT_INPUT_EVENT_2 = 2, PORT_INPUT_EVENT_3 = 3 } |
Port input event. More... | |
enum | port_input_event_action { PORT_INPUT_EVENT_ACTION_OUT = 0, PORT_INPUT_EVENT_ACTION_SET, PORT_INPUT_EVENT_ACTION_CLR, PORT_INPUT_EVENT_ACTION_TGL } |
Port input event action. More... | |
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... | |
Driver Feature Definition | |
Define port features set according to different device family. | |
#define | FEATURE_PORT_INPUT_EVENT |
Event input control feature support for PORT group. 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... | |
Port Input Event | |
static enum status_code | port_enable_input_event (const uint8_t gpio_pin, const enum port_input_event n) |
Enable the port event input. More... | |
static enum status_code | port_disable_input_event (const uint8_t gpio_pin, const enum port_input_event n) |
Disable the port event input. More... | |
static void | port_input_event_get_config_defaults (struct port_input_event_config *const config) |
Retrieve the default configuration for port input event. More... | |
static enum status_code | port_input_event_set_config (const enum port_input_event n, struct port_input_event_config *const config) |
Configure port input event. More... | |
#define FEATURE_PORT_INPUT_EVENT |
Event input control feature support for PORT group.
#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_input_event |
Port input event action.
List of port input events action on pin.
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 |
Disable the port event input.
Disable the port event input with the given pin and event.
[in] | gpio_pin | Index of the GPIO pin |
[in] | gpio_pin | Port input event |
STATUS_ERR_INVALID_ARG | Invalid parameter |
STATUS_OK | Successfully |
References Assert, port_get_group_from_gpio_pin(), PORT_INPUT_EVENT_0, PORT_INPUT_EVENT_1, PORT_INPUT_EVENT_2, PORT_INPUT_EVENT_3, STATUS_ERR_INVALID_ARG, and STATUS_OK.
|
inlinestatic |
Enable the port event input.
Enable the port event input with the given pin and event.
[in] | gpio_pin | Index of the GPIO pin |
[in] | n | Port input event |
STATUS_ERR_INVALID_ARG | Invalid parameter |
STATUS_OK | Successfully |
References Assert, port_get_group_from_gpio_pin(), PORT_INPUT_EVENT_0, PORT_INPUT_EVENT_1, PORT_INPUT_EVENT_2, PORT_INPUT_EVENT_3, STATUS_ERR_INVALID_ARG, and STATUS_OK.
|
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 at24mac602_arch_init(), at25dfx_chip_init(), bootloader_system_init(), button_sensor_init(), config_led(), config_port_pins(), configure_button_led(), configure_port_pins(), configure_trigger(), init_buttons(), init_chip_pins(), io1_board_init(), ksz8851snl_interface_init(), led_init(), leds_arch_init(), main(), nm_bsp_btn_init(), nm_bsp_deinit(), nm_bus_deinit(), oled1_init(), port_input_event_set_config(), run_faultn_test(), run_faultx_test(), setup_extint_callback_mode_test(), setup_extint_polled_mode_test(), spi_attach_slave(), ssd1306_interface_init(), and 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_disable_input_event(), port_enable_input_event(), port_input_event_set_config(), 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 |
Retrieve the default configuration for port input event.
Fills a configuration structure with the default configuration for port input event:
[out] | config | Configuration structure to fill with default values |
References port_input_event_config::action, Assert, port_input_event_config::gpio_pin, and PORT_INPUT_EVENT_ACTION_OUT.
|
inlinestatic |
Configure port input event.
Configures port input event with the given configuration settings.
[in] | config | Port input even configuration structure containing the new config |
STATUS_ERR_INVALID_ARG | Invalid parameter |
STATUS_OK | Successfully |
References port_input_event_config::action, Assert, port_config::direction, port_input_event_config::gpio_pin, port_get_config_defaults(), port_get_group_from_gpio_pin(), PORT_INPUT_EVENT_0, PORT_INPUT_EVENT_1, PORT_INPUT_EVENT_2, PORT_INPUT_EVENT_3, PORT_PIN_DIR_OUTPUT, port_pin_set_config(), STATUS_ERR_INVALID_ARG, and STATUS_OK.
|
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().
Referenced by btn_init(), btn_poll(), button_pressed(), button_sensor_value(), check_boot_mode(), demo_start(), eic_callback_to_clear_halt(), extint_detection_callback(), get_button(), main(), oled1_get_button_state(), oled1_get_led_state(), run_profiling_app(), run_sample_test_app(), sd_mmc_is_write_protected(), sd_mmc_select_slot(), and update_led_state().
|
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().
Referenced by cgi_GetStaus(), demo_start(), iso7816_get_reset_statuts(), leds_arch_get(), and main().
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 at24mac602_arch_init(), at25dfx_chip_init(), bootloader_system_init(), button_sensor_init(), config_led(), config_port_pins(), configure_button_led(), configure_port_pins(), configure_trigger(), init_buttons(), init_chip_pins(), io1_board_init(), ksz8851snl_interface_init(), led_init(), leds_arch_init(), mac_init(), main(), nm_bsp_btn_init(), nm_bsp_deinit(), nm_bus_deinit(), oled1_init(), port_input_event_set_config(), run_faultn_test(), run_faultx_test(), set_sda_input(), set_sda_output(), setup_extint_callback_mode_test(), setup_extint_polled_mode_test(), spi_attach_slave(), ssd1306_interface_init(), and 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().
Referenced by _at25dfx_chip_deselect(), _at25dfx_chip_select(), adc_window_monitor(), at24mac602_arch_init(), at25dfx_chip_init(), ble_bat_handle_timer_event(), ble_heart_rate_handle_timer_event(), cgi_SetLed(), config_led(), configure_button_led(), configure_trigger(), control_cmd_handler(), demo_start(), demo_wifi_socket_handler(), demo_wifi_state(), execute_state_machine(), extint_detection_callback(), goto_sleep(), handle_tcp_socket_cb(), init_chip_pins(), io1_board_set_led(), iso7816_icc_power_off(), iso7816_icc_power_on(), ksz8851snl_hard_reset(), led_clear(), led_init(), leds_arch_init(), leds_arch_set(), m2m_wifi_socket_handler(), m2m_wifi_state(), mac_t_gts_cb(), main(), mqtt_event(), MQTTcallbackHandler(), nm_bsp_deinit(), nm_bsp_reset(), oled1_init(), oled1_set_led_state(), process_data_ind_not_transient(), program_memory(), rf212_init(), rf233_init(), rtc_overflow_callback(), run_extint_callback_mode_test(), run_extint_polled_mode_test(), run_faultn_test(), run_faultx_test(), set_sda_output(), setup_extint_callback_mode_test(), setup_extint_polled_mode_test(), socket_cb(), spi_attach_slave(), spi_select_slave(), ssd1306_hard_reset(), ssd1306_init(), ssd1306_write_command(), ssd1306_write_data(), start_application(), store_file_packet(), update_led_state(), wake_from_sleep(), xosc32k_fail_callback(), and xosc32k_ok_callback().
|
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().
Referenced by ble_bat_handle_timer_event(), ble_heart_rate_handle_timer_event(), demo_start(), event_counter(), handle_gts_data_tx_end(), led_toggle(), mac_process_data_frame(), main(), oled1_toggle_led_state(), process_data_ind_not_transient(), rtc_match_callback(), SysTick_Handler(), tc_callback_to_toggle_led(), tcc_callback_to_toggle_led(), test_init(), trigger_generation(), usart_write_callback(), watchdog_early_warning_callback(), and wifi_cb().