mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #20999 from maribu/cpu/sam0_common/gpio_ll/fix-gpio_get_port
cpu/sam0_common/periph_gpio_ll: fix gpio_get_port() and gpio_ll_query_conf()
This commit is contained in:
commit
387f970b50
@ -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)
|
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)
|
static inline uint8_t gpio_get_pin_num(gpio_t pin)
|
||||||
|
@ -204,7 +204,12 @@ gpio_conf_t gpio_ll_query_conf(gpio_port_t port, uint8_t pin)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.initial_value = iobus->OUT.reg & pin_mask;
|
if (result.state == GPIO_INPUT) {
|
||||||
|
result.initial_value = (gpio_ll_read(port) >> pin) & 1UL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result.initial_value = (gpio_ll_read_output(port) >> pin) & 1UL;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user