Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions cpu/sam0_common/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,33 @@
int pin_mask = _pin_mask(pin);

/* make sure pin mode is applicable */
if (mode > 0x7) {
if (mode & ~MODE_PINCFG_MASK) {
return -1;
}

/* set pin direction */
if (mode & 0x2) {
if (mode & PORT_PINCFG_INEN) {
/* input */
if (IS_ACTIVE(MODULE_PERIPH_GPIO_FAST_READ)) {
port->CTRL.reg |= pin_mask;
}
port->DIRCLR.reg = pin_mask;
}
else {
/* output */
if (IS_ACTIVE(MODULE_PERIPH_GPIO_FAST_READ)) {
port->CTRL.reg &= ~pin_mask;
}
port->DIRSET.reg = pin_mask;

/* enable input to read back output level */
if (IS_ACTIVE(MODULE_PERIPH_GPIO_READ_OUTPUT)) {
mode |= PORT_PINCFG_INEN;
}
}

/* configure the pin cfg */
port->PINCFG[pin_pos].reg = (mode & MODE_PINCFG_MASK);
port->PINCFG[pin_pos].reg = mode;

/* and set pull-up/pull-down if applicable */
if (mode == GPIO_IN_PU) {
Expand All @@ -207,11 +214,11 @@
port = _port(pin);
}

if (port->DIR.reg & mask) {
return (port->OUT.reg & mask) ? 1 : 0;
}
else {
return (port->IN.reg & mask) ? 1 : 0;
if (IS_ACTIVE(MODULE_PERIPH_GPIO_READ_OUTPUT) ||
!(port->DIR.reg & mask)) {
return port->IN.reg & mask;
} else {
return port->OUT.reg & mask;
}
}

Expand Down Expand Up @@ -244,10 +251,10 @@
#ifdef CPU_COMMON_SAMD21
#define EIC_SYNC() while (_EIC->STATUS.reg & EIC_STATUS_SYNCBUSY)
#else
#define EIC_SYNC() while (_EIC->SYNCBUSY.reg & EIC_SYNCBUSY_ENABLE)

Check warning on line 254 in cpu/sam0_common/periph/gpio.c

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure
#endif

static int _exti(gpio_t pin)

Check warning on line 257 in cpu/sam0_common/periph/gpio.c

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure
{
unsigned port_num = ((pin >> 7) & 0x03);

Expand Down
1 change: 1 addition & 0 deletions cpu/samd21/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CPU_CORE = cortex-m0plus

FEATURES_PROVIDED += periph_gpio_fast_read
FEATURES_PROVIDED += periph_gpio_read_output

ifeq (,$(filter samd20%,$(CPU_MODEL)))
FEATURES_PROVIDED += periph_uart_collision
Expand Down
1 change: 1 addition & 0 deletions cpu/samd5x/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CPU_CORE = cortex-m4f
FEATURES_PROVIDED += periph_hwrng
FEATURES_PROVIDED += backup_ram
FEATURES_PROVIDED += cortexm_mpu
FEATURES_PROVIDED += periph_gpio_read_output
FEATURES_PROVIDED += periph_gpio_tamper_wake
FEATURES_PROVIDED += periph_rtc_mem
FEATURES_PROVIDED += periph_spi_on_qspi
Expand Down
1 change: 1 addition & 0 deletions cpu/saml1x/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CPU_CORE = cortex-m23

FEATURES_PROVIDED += periph_hwrng
FEATURES_PROVIDED += periph_gpio_fast_read
FEATURES_PROVIDED += periph_gpio_read_output
FEATURES_PROVIDED += periph_uart_collision

include $(RIOTCPU)/sam0_common/Makefile.features
1 change: 1 addition & 0 deletions cpu/saml21/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CPU_CORE = cortex-m0plus
CPU_MODELS_WITHOUT_HWRNG += samr30%

FEATURES_PROVIDED += periph_gpio_fast_read
FEATURES_PROVIDED += periph_gpio_read_output
FEATURES_PROVIDED += periph_uart_collision

# Low Power SRAM is *not* retained during Backup Sleep.
Expand Down
7 changes: 7 additions & 0 deletions features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ groups:
Enabling this feature reduces read latency for an increase in power
consumption. It affects both the classic GPIO API driver and the
GPIO LL driver.
- name: periph_gpio_read_output
help: This feature is currently implemented on Microchip SAM0 based MCUs only.
Enabling this feature makes `gpio_read()` read back the actual pin level
of an output GPIO (instead of just returning the configured level).
This can be used to detect hardware problems (e.g. if a pin is set HIGH but
reads low).
The feature comes at the cost of slightly higher power consumption.

groups:
- title: Pin Level Peripheral GPIO API
Expand Down
1 change: 1 addition & 0 deletions makefiles/features_existing.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ FEATURES_EXISTING := \
periph_gpio_ll_open_source \
periph_gpio_ll_open_source_pull_down \
periph_gpio_ll_switch_dir \
periph_gpio_read_output \
periph_gpio_tamper_wake \
periph_hash_md5 \
periph_hash_sha3_256 \
Expand Down
1 change: 1 addition & 0 deletions tests/periph/gpio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include ../Makefile.periph_common
FEATURES_REQUIRED += periph_gpio
FEATURES_OPTIONAL += periph_gpio_irq
FEATURES_OPTIONAL += periph_gpio_fast_read
FEATURES_OPTIONAL += periph_gpio_read_output
FEATURES_OPTIONAL += periph_gpio_tamper_wake

USEMODULE += shell_cmds_default
Expand Down
Loading