From 9194440ead1837dccea6a76fa98c35b48fdf0032 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 27 May 2021 22:19:40 +0200 Subject: [PATCH] drivers/periph/uart: add periph_uart_rx_start feature --- drivers/include/periph/uart.h | 52 +++++++++++++++++++++++++++++- drivers/periph_common/Kconfig.uart | 4 +++ kconfigs/Kconfig.features | 5 +++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/drivers/include/periph/uart.h b/drivers/include/periph/uart.h index d293cab2d1..c7f49b9317 100644 --- a/drivers/include/periph/uart.h +++ b/drivers/include/periph/uart.h @@ -98,13 +98,24 @@ typedef unsigned int uart_t; */ typedef void(*uart_rx_cb_t)(void *arg, uint8_t data); +/** + * @brief Signature for receive start condition interrupt callback + * + * @param[in] arg context to the callback (optional) + */ +typedef void(*uart_rxstart_cb_t)(void *arg); + /** * @brief Interrupt context for a UART device */ #ifndef HAVE_UART_ISR_CTX_T typedef struct { uart_rx_cb_t rx_cb; /**< data received interrupt callback */ - void *arg; /**< argument to both callback routines */ + void *arg; /**< argument to data received callback */ +#ifdef MODULE_PERIPH_UART_RXSTART_IRQ + uart_rxstart_cb_t rxs_cb; /**< start condition received interrupt callback */ + void *rxs_arg; /**< argument to start condition received callback */ +#endif } uart_isr_ctx_t; #endif @@ -243,6 +254,45 @@ gpio_t uart_pin_tx(uart_t uart); #endif /* DOXYGEN */ #endif /* MODULE_PERIPH_UART_RECONFIGURE */ +#if defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN + +/** + * @brief Configure the function that will be called when a start condition + * is detected. + * + * This will not enable / disable the generation of the RX start + * 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 + * @param[in] cb The function called when a start condition is detected + * @param[in] arg Optional function argument + */ +void uart_rxstart_irq_configure(uart_t uart, uart_rxstart_cb_t cb, void *arg); + +/** + * @brief Enable the RX start 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_rxstart_irq_enable(uart_t uart); + +/** + * @brief Disable the RX start 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_rxstart_irq_disable(uart_t uart); +#endif /* MODULE_PERIPH_UART_RXSTART_IRQ */ + /** * @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 2d87dd4818..8e5402f3fc 100644 --- a/drivers/periph_common/Kconfig.uart +++ b/drivers/periph_common/Kconfig.uart @@ -32,6 +32,10 @@ config MODULE_PERIPH_UART_NONBLOCKING bool "Non-blocking support" depends on HAS_PERIPH_UART_NONBLOCKING +config MODULE_PERIPH_UART_RXSTART_IRQ + bool "Enable Start Condition Interrupt" + depends on HAS_PERIPH_UART_RXSTART_IRQ + config MODULE_PERIPH_INIT_UART_MODECFG bool depends on MODULE_PERIPH_UART_MODECFG diff --git a/kconfigs/Kconfig.features b/kconfigs/Kconfig.features index 43b800f18a..c31359934c 100644 --- a/kconfigs/Kconfig.features +++ b/kconfigs/Kconfig.features @@ -333,6 +333,11 @@ config HAS_PERIPH_UART_RECONFIGURE help Indicates that the UART pins can be re-configured as GPIOs. +config HAS_PERIPH_UART_RXSTART_IRQ + bool + help + Indicates that the UART has an Interrupt for Start Condition detected. + config HAS_PERIPH_USBDEV bool help