stm: Add a few more GPIO functions to make dealing with the 1802 easier
[fw/altos] / src / stm / stm32l.h
index a20efa8a1b0c31f52bfa5536752f607d36ad4b3a..4f966e3e71f3661d01ce9afd370549ad38803c55 100644 (file)
@@ -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;