1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/sam0_common/periph_gpio_ll: fix gpio_get_port()

It turns out that the legacy GPIO API and GPIO LL may disagree on what
the GPIO base address is: GPIO LL will use the IOBUS as base address
no matter what, the legacy GPIO API will use the APB as base address
unless `periph_gpio_fast_read` is used.

If the APIs disagree, we need to do impedance matching.
This commit is contained in:
Marian Buschsieweke 2024-11-18 12:50:25 +01:00
parent aee4c1ef9c
commit 72d0b2b180
No known key found for this signature in database
GPG Key ID: 758BD52517F79C41

View File

@ -159,7 +159,15 @@ static inline void gpio_ll_switch_dir_input(gpio_port_t port, uword_t inputs)
static inline gpio_port_t gpio_get_port(gpio_t pin)
{
return (gpio_port_t)(pin & ~(0x1f));
/* GPIO LL and legacy GPIO API may disagree on what is the GPIO base
* address if one is using the IOBUS and the other is using the APB for
* access. In this case, we need to do impedance matching by adding the
* offset. */
const uintptr_t gpio_ll_base = GPIO_PORT_0;
const uintptr_t gpio_legacy_base = GPIO_PIN(0, 0) & ~(0x1f);
uintptr_t addr = (pin & ~(0x1f));
return addr + (gpio_ll_base - gpio_legacy_base);
}
static inline uint8_t gpio_get_pin_num(gpio_t pin)