From 0197157a295d848bac65cf7f4457dd5a99af24e3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 3 Apr 2017 11:37:21 -0700 Subject: [PATCH] stm: Add a few more GPIO functions to make dealing with the 1802 easier ao_gpio_set_mask and ao_gpio_get_all Signed-off-by: Keith Packard --- src/stm/ao_arch_funcs.h | 3 +++ src/stm/stm32l.h | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/stm/ao_arch_funcs.h b/src/stm/ao_arch_funcs.h index b294c379..15741505 100644 --- a/src/stm/ao_arch_funcs.h +++ b/src/stm/ao_arch_funcs.h @@ -202,8 +202,11 @@ ao_spi_try_get_mask(struct stm_gpio *reg, uint16_t mask, uint8_t bus, uint32_t s #define ao_gpio_set_bits(port, bits) stm_gpio_set_bits(port, bits) +#define ao_gpio_set_mask(port, bits, mask) stm_gpio_set_mask(port, bits, mask) + #define ao_gpio_clr_bits(port, bits) stm_gpio_clr_bits(port, bits); +#define ao_gpio_get_all(port) stm_gpio_get_all(port) #define ao_enable_output(port,bit,pin,v) do { \ ao_enable_port(port); \ diff --git a/src/stm/stm32l.h b/src/stm/stm32l.h index a20efa8a..4f966e3e 100644 --- a/src/stm/stm32l.h +++ b/src/stm/stm32l.h @@ -167,6 +167,12 @@ stm_gpio_set(struct stm_gpio *gpio, int pin, uint8_t value) { gpio->bsrr = ((uint32_t) (value ^ 1) << (pin + 16)) | ((uint32_t) value << pin); } +static inline void +stm_gpio_set_mask(struct stm_gpio *gpio, uint16_t bits, uint16_t mask) { + /* Use the bit set/reset register to do this atomically */ + gpio->bsrr = ((uint32_t) (~bits & mask) << 16) | ((uint32_t) (bits & mask)); +} + static inline void stm_gpio_set_bits(struct stm_gpio *gpio, uint16_t bits) { gpio->bsrr = bits; -- 2.30.2