aboutsummaryrefslogtreecommitdiff
path: root/include/libopencm3/stm32/f2/gpio.h
diff options
context:
space:
mode:
authorFergus Noble2011-09-14 23:57:43 -0700
committerStephen Caudle2011-10-12 22:13:01 -0400
commit60dcacccb7ae8f80ca224e38abdfca1236d1871e (patch)
tree8612ac4a6b98c5fa31c64be535cf049b39035173 /include/libopencm3/stm32/f2/gpio.h
parent95d4532595369b09bd48e9f7706b0ddef3149985 (diff)
Some updates to the F2 GPIO header plus implementation of GPIO convenience functions.
Diffstat (limited to 'include/libopencm3/stm32/f2/gpio.h')
-rw-r--r--include/libopencm3/stm32/f2/gpio.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/include/libopencm3/stm32/f2/gpio.h b/include/libopencm3/stm32/f2/gpio.h
index 3339311..b4fb4f3 100644
--- a/include/libopencm3/stm32/f2/gpio.h
+++ b/include/libopencm3/stm32/f2/gpio.h
@@ -179,7 +179,8 @@
/* --- GPIOx_MODER values -------------------------------------------------- */
-#define GPIO_MODE(n, mode) (mode << (2*n))
+#define GPIO_MODE(n, mode) (mode << (2*(n)))
+#define GPIO_MODE_MASK(n) (0x3 << (2*(n)))
#define GPIO_MODE_INPUT 0x0
#define GPIO_MODE_OUTPUT 0x1
#define GPIO_MODE_AF 0x2
@@ -192,7 +193,8 @@
/* --- GPIOx_OSPEEDR values ------------------------------------------------ */
-#define GPIO_OSPEED(n, speed) (speed << (2*n))
+#define GPIO_OSPEED(n, speed) (speed << (2*(n)))
+#define GPIO_OSPEED_MASK(n) (0x3 << (2*(n)))
#define GPIO_OSPEED_2MHZ 0x0
#define GPIO_OSPEED_25MHZ 0x1
#define GPIO_OSPEED_50MHZ 0x2
@@ -200,7 +202,8 @@
/* --- GPIOx_PUPDR values -------------------------------------------------- */
-#define GPIO_PUPD(n, pupd) (pupd << (2*n))
+#define GPIO_PUPD(n, pupd) (pupd << (2*(n)))
+#define GPIO_PUPD_MASK(n) (0x3 << (2*(n)))
#define GPIO_PUPD_NONE 0x0
#define GPIO_PUPD_PULLUP 0x1
#define GPIO_PUPD_PULLDOWN 0x2
@@ -228,7 +231,8 @@
/* Note: AFRL is used for bits 0..7, AFRH is used for 8..15 */
/* See Datasheet Table 6 (pg. 48) for alternate function mappings. */
-#define GPIO_AFR(n, af) (af << (n*4))
+#define GPIO_AFR(n, af) (af << ((n)*4))
+#define GPIO_AFR_MASK(n) (0xF << ((n)*4))
#define GPIO_AF0 0x0
#define GPIO_AF1 0x1
#define GPIO_AF2 0x2
@@ -262,7 +266,7 @@ void gpio_mode_setup(u32 gpioport, u8 mode, u8 pull_up_down, u16 gpios);
void gpio_set_output_options(u32 gpioport, u8 otype, u8 speed, u16 gpios);
void gpio_set_af(u32 gpioport, u8 alt_func_num, u16 gpios);
-/* This part of the API is compatible with the F1 series */
+/* This part of the API is compatible with the F1 series ------------------- */
void gpio_set(u32 gpioport, u16 gpios);
void gpio_clear(u32 gpioport, u16 gpios);
u16 gpio_get(u32 gpioport, u16 gpios);