diff --git a/drivers/include/periph/uart.h b/drivers/include/periph/uart.h index 26b4142132..92448a3ebe 100644 --- a/drivers/include/periph/uart.h +++ b/drivers/include/periph/uart.h @@ -296,6 +296,48 @@ void uart_rxstart_irq_enable(uart_t uart); void uart_rxstart_irq_disable(uart_t uart); #endif /* MODULE_PERIPH_UART_RXSTART_IRQ */ +#if defined(MODULE_PERIPH_UART_COLLISION) || DOXYGEN +/** + * @brief Enables collision detection check of the UART. + * This assumes the UART is connected to a bus where RX and TX are + * connected. After each sent byte it is checked whether the same + * byte could be received. + * + * This disables the RX interrupt. + * + * @note You have to add the module `periph_uart_rxstart_irq` to your project + * to enable this function + * + * @param[in] uart The device to configure + */ +void uart_collision_detect_enable(uart_t uart); +/** + * @brief Disables collision detection check of the UART. + * + * If an RX interrupt was configured before, it is enabled again. + * + * @note You have to add the module `periph_uart_rxstart_irq` to your project + * to enable this function + * + * @param[in] uart The device to configure + */ +void uart_collision_detect_disable(uart_t uart); + +/** + * @brief Disables collision detection check of the UART. + * + * If an RX interrupt was configured before, it is enabled again. + * + * @note You have to add the module `periph_uart_rxstart_irq` to your project + * to enable this function + * + * @param[in] uart The device to probe + * + * @return true if a collision occurred during the last transder + */ +bool uart_collision_detected(uart_t uart); +#endif /* MODULE_PERIPH_UART_COLLISION */ + /** * @brief Setup parity, data and stop bits for a given UART device * diff --git a/drivers/periph_common/Kconfig.uart b/drivers/periph_common/Kconfig.uart index 8e5402f3fc..f43b873d25 100644 --- a/drivers/periph_common/Kconfig.uart +++ b/drivers/periph_common/Kconfig.uart @@ -28,6 +28,10 @@ config MODULE_PERIPH_LPUART bool "Enable Low Power UART (LPUART)" depends on HAS_PERIPH_LPUART +config MODULE_PERIPH_UART_COLLISION + bool "Enable UART collision detection" + depends on HAS_PERIPH_UART_COLLISION + config MODULE_PERIPH_UART_NONBLOCKING bool "Non-blocking support" depends on HAS_PERIPH_UART_NONBLOCKING diff --git a/kconfigs/Kconfig.features b/kconfigs/Kconfig.features index 537b63b2fc..ed995187e5 100644 --- a/kconfigs/Kconfig.features +++ b/kconfigs/Kconfig.features @@ -323,6 +323,11 @@ config HAS_PERIPH_UART help Indicates that an UART peripheral is present. +config HAS_PERIPH_UART_COLLISION + bool + help + Indicates that the UART peripheral supports hardware collision detection. + config HAS_PERIPH_UART_HW_FC bool help