STM32 serial: add get_uart_index utility function

pull/5962/head
bcostm 2018-01-25 13:26:36 +01:00
parent 0efd33f010
commit 066da18e0d
1 changed files with 82 additions and 0 deletions

View File

@ -556,5 +556,87 @@ HAL_StatusTypeDef init_uart(serial_t *obj)
return HAL_UART_Init(huart);
}
// 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)
{
uint8_t index = 0;
#if defined(USART1_BASE)
if (uart_base == USART1_BASE) return index;
index++;
#endif
#if defined(USART2_BASE)
if (uart_base == USART2_BASE) return index;
index++;
#endif
#if defined(USART3_BASE)
if (uart_base == USART3_BASE) return index;
index++;
#endif
#if defined(UART4_BASE)
if (uart_base == UART4_BASE) return index;
index++;
#endif
#if defined(USART4_BASE)
if (uart_base == USART4_BASE) return index;
index++;
#endif
#if defined(UART5_BASE)
if (uart_base == UART5_BASE) return index;
index++;
#endif
#if defined(USART5_BASE)
if (uart_base == USART5_BASE) return index;
index++;
#endif
#if defined(USART6_BASE)
if (uart_base == USART6_BASE) return index;
index++;
#endif
#if defined(UART7_BASE)
if (uart_base == UART7_BASE) return index;
index++;
#endif
#if defined(USART7_BASE)
if (uart_base == USART7_BASE) return index;
index++;
#endif
#if defined(UART8_BASE)
if (uart_base == UART8_BASE) return index;
index++;
#endif
#if defined(USART8_BASE)
if (uart_base == USART8_BASE) return index;
index++;
#endif
#if defined(UART9_BASE)
if (uart_base == UART9_BASE) return index;
index++;
#endif
#if defined(UART10_BASE)
if (uart_base == UART10_BASE) return index;
index++;
#endif
#if defined(LPUART1_BASE)
if (uart_base == LPUART1_BASE) return index;
index++;
#endif
return -1;
}
#endif /* DEVICE_SERIAL */