STM32 serial: use uart_name instead of uart_base

pull/5962/head
bcostm 2018-01-25 15:23:14 +01:00
parent 7256af0d5b
commit e446c26584
2 changed files with 30 additions and 28 deletions

View File

@ -56,9 +56,10 @@ int8_t get_uart_index(int uart_base);
* INTERRUPTS HANDLING
******************************************************************************/
static void uart_irq(int uart_base)
static void uart_irq(UARTName uart_name)
{
int8_t id = get_uart_index(uart_base);
int8_t id = get_uart_index(uart_name);
if (id >= 0) {
UART_HandleTypeDef * huart = &uart_handlers[id];
if (serial_irq_ids[id] != 0) {
@ -85,70 +86,70 @@ static void uart_irq(int uart_base)
#if defined(USART1_BASE)
static void uart1_irq(void)
{
uart_irq(USART1_BASE);
uart_irq(UART_1);
}
#endif
#if defined(USART2_BASE)
static void uart2_irq(void)
{
uart_irq(USART2_BASE);
uart_irq(UART_2);
}
#endif
#if defined(USART3_BASE)
static void uart3_irq(void)
{
uart_irq(USART3_BASE);
uart_irq(UART_3);
}
#endif
#if defined(UART4_BASE)
static void uart4_irq(void)
{
uart_irq(UART4_BASE);
uart_irq(UART_4);
}
#endif
#if defined(UART5_BASE)
static void uart5_irq(void)
{
uart_irq(UART5_BASE);
uart_irq(UART_5);
}
#endif
#if defined(USART6_BASE)
static void uart6_irq(void)
{
uart_irq(USART6_BASE);
uart_irq(UART_6);
}
#endif
#if defined(UART7_BASE)
static void uart7_irq(void)
{
uart_irq(UART7_BASE);
uart_irq(UART_7);
}
#endif
#if defined(UART8_BASE)
static void uart8_irq(void)
{
uart_irq(UART8_BASE);
uart_irq(UART_8);
}
#endif
#if defined(UART9_BASE)
static void uart9_irq(void)
{
uart_irq(UART9_BASE);
uart_irq(UART_9);
}
#endif
#if defined(UART10_BASE)
static void uart10_irq(void)
{
uart_irq(UART10_BASE);
uart_irq(UART_10);
}
#endif

View File

@ -558,81 +558,82 @@ HAL_StatusTypeDef init_uart(serial_t *obj)
// Warning: the list of UART/USART in this function must be aligned with the list
// written in serial_init function.
inline int8_t get_uart_index(int uart_base)
inline int8_t get_uart_index(UARTName uart_name)
{
uint8_t index = 0;
#if defined(USART1_BASE)
if (uart_base == USART1_BASE) return index;
if (uart_name == UART_1) return index;
index++;
#endif
#if defined(USART2_BASE)
if (uart_base == USART2_BASE) return index;
if (uart_name == UART_2) return index;
index++;
#endif
#if defined(USART3_BASE)
if (uart_base == USART3_BASE) return index;
if (uart_name == UART_3) return index;
index++;
#endif
#if defined(UART4_BASE)
if (uart_base == UART4_BASE) return index;
if (uart_name == UART_4) return index;
index++;
#endif
#if defined(USART4_BASE)
if (uart_base == USART4_BASE) return index;
if (uart_name == UART_4) return index;
index++;
#endif
#if defined(UART5_BASE)
if (uart_base == UART5_BASE) return index;
if (uart_name == UART_5) return index;
index++;
#endif
#if defined(USART5_BASE)
if (uart_base == USART5_BASE) return index;
if (uart_name == UART_5) return index;
index++;
#endif
#if defined(USART6_BASE)
if (uart_base == USART6_BASE) return index;
if (uart_name == UART_6) return index;
index++;
#endif
#if defined(UART7_BASE)
if (uart_base == UART7_BASE) return index;
if (uart_name == UART_7) return index;
index++;
#endif
#if defined(USART7_BASE)
if (uart_base == USART7_BASE) return index;
if (uart_name == UART_7) return index;
index++;
#endif
#if defined(UART8_BASE)
if (uart_base == UART8_BASE) return index;
if (uart_name == UART_8) return index;
index++;
#endif
#if defined(USART8_BASE)
if (uart_base == USART8_BASE) return index;
if (uart_name == UART_8) return index;
index++;
#endif
#if defined(UART9_BASE)
if (uart_base == UART9_BASE) return index;
if (uart_name == UART_9) return index;
index++;
#endif
#if defined(UART10_BASE)
if (uart_base == UART10_BASE) return index;
if (uart_name == UART_10) return index;
index++;
#endif
#if defined(LPUART1_BASE)
if (uart_base == LPUART1_BASE) return index;
if (uart_name == LPUART_1) return index;
index++;
#endif