global: rename USART macros
This commit is contained in:
parent
5f889ba8b0
commit
a5c9b3558d
29
global.h
29
global.h
|
@ -181,25 +181,32 @@
|
|||
/** get USART based on USART identifier */
|
||||
#define USART(x) CAT2(USART,x)
|
||||
/** get RCC for USART based on USART identifier */
|
||||
#define USART_RCC(x) CAT2(RCC_USART,x)
|
||||
#define RCC_USART(x) CAT2(RCC_USART,x)
|
||||
/** get NVIC IRQ for USART based on USART identifier */
|
||||
#define USART_IRQ(x) CAT3(NVIC_USART,x,_IRQ)
|
||||
/** get interrupt service routine for USART based on USART identifier */
|
||||
#define USART_ISR(x) CAT3(usart,x,_isr)
|
||||
/** get port for USART based on USART identifier */
|
||||
#define USART_PORT(x) CAT2(USART_PORT,x)
|
||||
#define USART_PORT1 GPIOA /**< USART 1 is on port A */
|
||||
#define USART_PORT2 GPIOA /**< USART 2 is on port A */
|
||||
#define USART_PORT3 GPIOB /**< USART 3 is on port B */
|
||||
/** get port for USART transmit pin based on USART identifier */
|
||||
#define USART_TX_PORT(x) CAT3(GPIO_BANK_USART,x,_TX)
|
||||
/** get port for USART receive pin based on USART identifier */
|
||||
#define USART_RX_PORT(x) CAT3(GPIO_BANK_USART,x,_RX)
|
||||
/** get port for USART RTS pin based on USART identifier */
|
||||
#define USART_RTS_PORT(x) CAT3(GPIO_BANK_USART,x,_RTS)
|
||||
/** get port for USART CTS pin based on USART identifier */
|
||||
#define USART_CTS_PORT(x) CAT3(GPIO_BANK_USART,x,_CTS)
|
||||
/** get pin for USART transmit pin based on USART identifier */
|
||||
#define USART_TX_PIN(x) CAT3(GPIO_USART,x,_TX)
|
||||
/** get pin for USART receive pin based on USART identifier */
|
||||
#define USART_RX_PIN(x) CAT3(GPIO_USART,x,_RX)
|
||||
/** get pin for USART RTS pin based on USART identifier */
|
||||
#define USART_RTS_PIN(x) CAT3(GPIO_USART,x,_RTS)
|
||||
/** get pin for USART CTS pin based on USART identifier */
|
||||
#define USART_CTS_PIN(x) CAT3(GPIO_USART,x,_CTS)
|
||||
/** get RCC for USART port based on USART identifier */
|
||||
#define USART_PORT_RCC(x) CAT2(RCC_USART_PORT,x)
|
||||
#define RCC_USART_PORT(x) CAT2(RCC_USART_PORT,x)
|
||||
#define RCC_USART_PORT1 RCC_GPIOA /**< USART 1 is on port A */
|
||||
#define RCC_USART_PORT2 RCC_GPIOA /**< USART 2 is on port A */
|
||||
#define RCC_USART_PORT3 RCC_GPIOB /**< USART 3 is on port B */
|
||||
/** get transmit pin for USART based on USART identifier */
|
||||
#define USART_PIN_TX(x) CAT3(GPIO_USART,x,_TX)
|
||||
/** get receive pin for USART based on USART identifier */
|
||||
#define USART_PIN_RX(x) CAT3(GPIO_USART,x,_RX)
|
||||
/** get port based on ADC12_IN identifier */
|
||||
#define ADC12_IN_PORT(x) CAT3(ADC12_IN,x,_PORT)
|
||||
#define ADC12_IN0_PORT GPIOA /**< ADC12_IN0 is on PA0 */
|
||||
|
|
10
lib/uart.c
10
lib/uart.c
|
@ -50,12 +50,12 @@ static volatile uint8_t tx_used = 0; /**< how much data needs to be transmitted
|
|||
void uart_setup(void)
|
||||
{
|
||||
/* enable UART I/O peripheral */
|
||||
rcc_periph_clock_enable(USART_PORT_RCC(UART_ID)); // enable clock for UART port peripheral
|
||||
rcc_periph_clock_enable(USART_RCC(UART_ID)); // enable clock for UART peripheral
|
||||
rcc_periph_clock_enable(RCC_USART_PORT(UART_ID)); // enable clock for UART port peripheral
|
||||
rcc_periph_clock_enable(RCC_USART(UART_ID)); // enable clock for UART peripheral
|
||||
rcc_periph_clock_enable(RCC_AFIO); // enable pin alternate function (UART)
|
||||
gpio_set_mode(USART_PORT(UART_ID), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USART_PIN_TX(UART_ID)); // setup GPIO pin UART transmit
|
||||
gpio_set_mode(USART_PORT(UART_ID), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, USART_PIN_RX(UART_ID)); // setup GPIO pin UART receive
|
||||
gpio_set(USART_PORT(UART_ID), USART_PIN_RX(UART_ID)); // pull up to avoid noise when not connected
|
||||
gpio_set_mode(USART_TX_PORT(UART_ID), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USART_TX_PIN(UART_ID)); // setup GPIO pin UART transmit
|
||||
gpio_set_mode(USART_RX_PORT(UART_ID), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, USART_RX_PIN(UART_ID)); // setup GPIO pin UART receive
|
||||
gpio_set(USART_RX_PORT(UART_ID), USART_RX_PIN(UART_ID)); // pull up to avoid noise when not connected
|
||||
|
||||
/* setup UART parameters */
|
||||
usart_set_baudrate(USART(UART_ID), UART_BAUDRATE);
|
||||
|
|
Loading…
Reference in New Issue