diff --git a/chip/stm32/gpio-stm32f100.c b/chip/stm32/gpio-stm32f100.c index e1a28b8d7a..50c732bc27 100644 --- a/chip/stm32/gpio-stm32f100.c +++ b/chip/stm32/gpio-stm32f100.c @@ -174,6 +174,13 @@ void gpio_set_alternate_function(int port, int mask, int func) } +uint16_t *gpio_get_level_reg(enum gpio_signal signal, uint32_t *mask) +{ + *mask = gpio_list[signal].mask; + return (uint16_t *)&STM32_GPIO_IDR_OFF(gpio_list[signal].port); +} + + int gpio_get_level(enum gpio_signal signal) { return !!(STM32_GPIO_IDR_OFF(gpio_list[signal].port) & diff --git a/include/gpio.h b/include/gpio.h index b70e40f9a1..e03acfb0c9 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -65,6 +65,18 @@ int gpio_pre_init(void); /* Get the current value of a signal (0=low, 1=hi). */ int gpio_get_level(enum gpio_signal signal); +/** + * Get faster access to a GPIO level + * + * Use this function to find out the register address and mask for a GPIO + * value. Then you can just check that instead of calling gpio_get_level(). + * + * @param signal Signal to return details for + * @param mask Mask value to use + * @return pointer to register to read to get GPIO value + */ +uint16_t *gpio_get_level_reg(enum gpio_signal signal, uint32_t *mask); + /** * Returns the name of a given GPIO signal. *