diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2012-06-03 02:23:27 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2012-06-03 02:23:27 -0400 |
commit | 7277d15c68641b4f840240aa4f0557b5f69d727d (patch) | |
tree | 17188d4b75661cb935b55e3ad0c2de4abdaddeb1 | |
parent | 4723f6525215ee5bce550ceb615326f05f8fbc3f (diff) | |
download | librambutan-7277d15c68641b4f840240aa4f0557b5f69d727d.tar.gz librambutan-7277d15c68641b4f840240aa4f0557b5f69d727d.zip |
F2: Add usart_get_af().
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
-rw-r--r-- | libmaple/stm32f2/include/series/usart.h | 8 | ||||
-rw-r--r-- | libmaple/stm32f2/usart.c | 39 |
2 files changed, 30 insertions, 17 deletions
diff --git a/libmaple/stm32f2/include/series/usart.h b/libmaple/stm32f2/include/series/usart.h index 805a2b2..8936efa 100644 --- a/libmaple/stm32f2/include/series/usart.h +++ b/libmaple/stm32f2/include/series/usart.h @@ -37,6 +37,8 @@ extern "C"{ #endif +#include <libmaple/gpio.h> /* for gpio_af */ + /* * Register map base pointers. */ @@ -96,6 +98,12 @@ extern struct usart_dev *UART4; extern struct usart_dev *UART5; extern struct usart_dev *USART6; +/* + * Routines + */ + +gpio_af usart_get_af(struct usart_dev *dev); + #ifdef __cplusplus } #endif diff --git a/libmaple/stm32f2/usart.c b/libmaple/stm32f2/usart.c index 9a1acf3..1472d13 100644 --- a/libmaple/stm32f2/usart.c +++ b/libmaple/stm32f2/usart.c @@ -111,23 +111,7 @@ void usart_config_gpios_async(usart_dev *udev, gpio_dev *rx_dev, uint8 rx, gpio_dev *tx_dev, uint8 tx, unsigned flags) { - gpio_af af; - /* TODO: break this out into a user-facing function. */ - switch (udev->clk_id) { - case RCC_USART1: - case RCC_USART2: - case RCC_USART3: - af = GPIO_AF_USART_1_2_3; - break; - case RCC_UART4: - case RCC_UART5: - case RCC_USART6: - af = GPIO_AF_USART_4_5_6; - break; - default: - ASSERT(0); - return; - } + gpio_af af = usart_get_af(udev); gpio_set_modef(rx_dev, rx, GPIO_MODE_AF, 0); gpio_set_modef(tx_dev, tx, GPIO_MODE_AF, 0); gpio_set_af(rx_dev, rx, af); @@ -170,6 +154,27 @@ void usart_foreach(void (*fn)(usart_dev*)) { fn(USART6); } +/** + * @brief Get GPIO alternate function mode for a USART. + * @param dev USART whose gpio_af to get. + * @return gpio_af corresponding to dev. + */ +gpio_af usart_get_af(usart_dev *dev) { + switch (dev->clk_id) { + case RCC_USART1: + case RCC_USART2: + case RCC_USART3: + return GPIO_AF_USART_1_2_3; + case RCC_UART4: + case RCC_UART5: + case RCC_USART6: + return GPIO_AF_USART_4_5_6; + default: + ASSERT(0); /* Can't happen */ + return (gpio_af)-1; + } +} + /* * Interrupt handlers. */ |