mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 21:05:35 +03:00
Added idle interrupt callback to UART driver
This commit is contained in:
parent
0f230c42a1
commit
38013a8253
7 changed files with 49 additions and 8 deletions
|
@ -59,6 +59,7 @@ typedef enum {
|
||||||
#define CTRL_LINE_STATE_RTS (1 << 1)
|
#define CTRL_LINE_STATE_RTS (1 << 1)
|
||||||
|
|
||||||
typedef void (*serialReceiveCallbackPtr)(uint16_t data, void *rxCallbackData); // used by serial drivers to return frames to app
|
typedef void (*serialReceiveCallbackPtr)(uint16_t data, void *rxCallbackData); // used by serial drivers to return frames to app
|
||||||
|
typedef void (*serialIdleCallbackPtr)();
|
||||||
|
|
||||||
typedef struct serialPort_s {
|
typedef struct serialPort_s {
|
||||||
|
|
||||||
|
@ -81,6 +82,8 @@ typedef struct serialPort_s {
|
||||||
serialReceiveCallbackPtr rxCallback;
|
serialReceiveCallbackPtr rxCallback;
|
||||||
void *rxCallbackData;
|
void *rxCallbackData;
|
||||||
|
|
||||||
|
serialIdleCallbackPtr idleCallback;
|
||||||
|
|
||||||
uint8_t identifier;
|
uint8_t identifier;
|
||||||
} serialPort_t;
|
} serialPort_t;
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,6 @@ void uartReconfigure(uartPort_t *uartPort)
|
||||||
HAL_UART_Receive_DMA(&uartPort->Handle, (uint8_t*)uartPort->port.rxBuffer, uartPort->port.rxBufferSize);
|
HAL_UART_Receive_DMA(&uartPort->Handle, (uint8_t*)uartPort->port.rxBuffer, uartPort->port.rxBufferSize);
|
||||||
|
|
||||||
uartPort->rxDMAPos = __HAL_DMA_GET_COUNTER(&uartPort->rxDMAHandle);
|
uartPort->rxDMAPos = __HAL_DMA_GET_COUNTER(&uartPort->rxDMAHandle);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
@ -159,6 +158,9 @@ void uartReconfigure(uartPort_t *uartPort)
|
||||||
|
|
||||||
/* Enable the UART Data Register not empty Interrupt */
|
/* Enable the UART Data Register not empty Interrupt */
|
||||||
SET_BIT(uartPort->USARTx->CR1, USART_CR1_RXNEIE);
|
SET_BIT(uartPort->USARTx->CR1, USART_CR1_RXNEIE);
|
||||||
|
|
||||||
|
/* Enable Idle Line detection */
|
||||||
|
SET_BIT(uartPort->USARTx->CR1, USART_CR1_IDLEIE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,6 +189,7 @@ serialPort_t *uartOpen(UARTDevice_e device, serialReceiveCallbackPtr rxCallback,
|
||||||
} else {
|
} else {
|
||||||
USART_ClearITPendingBit(s->USARTx, USART_IT_RXNE);
|
USART_ClearITPendingBit(s->USARTx, USART_IT_RXNE);
|
||||||
USART_ITConfig(s->USARTx, USART_IT_RXNE, ENABLE);
|
USART_ITConfig(s->USARTx, USART_IT_RXNE, ENABLE);
|
||||||
|
USART_ITConfig(s->USARTx, USART_IT_IDLE, ENABLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,5 +214,13 @@ void uartIrqHandler(uartPort_t *s)
|
||||||
USART_ITConfig(s->USARTx, USART_IT_TXE, DISABLE);
|
USART_ITConfig(s->USARTx, USART_IT_TXE, DISABLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (SR & USART_FLAG_IDLE) {
|
||||||
|
if (s->port.idleCallback) {
|
||||||
|
s->port.idleCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint32_t read_to_clear = s->USARTx->DR;
|
||||||
|
(void) read_to_clear;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif // USE_UART
|
#endif // USE_UART
|
||||||
|
|
|
@ -285,7 +285,15 @@ void uartIrqHandler(uartPort_t *s)
|
||||||
|
|
||||||
if (ISR & USART_FLAG_ORE)
|
if (ISR & USART_FLAG_ORE)
|
||||||
{
|
{
|
||||||
USART_ClearITPendingBit (s->USARTx, USART_IT_ORE);
|
USART_ClearITPendingBit(s->USARTx, USART_IT_ORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ISR & USART_FLAG_IDLE) {
|
||||||
|
if (s->port.idleCallback) {
|
||||||
|
s->port.idleCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
USART_ClearITPendingBit(s->USARTx, USART_IT_IDLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // USE_UART
|
#endif // USE_UART
|
||||||
|
|
|
@ -289,9 +289,18 @@ void uartIrqHandler(uartPort_t *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (USART_GetITStatus(s->USARTx, USART_IT_ORE) == SET)
|
if (USART_GetITStatus(s->USARTx, USART_IT_ORE) == SET) {
|
||||||
{
|
USART_ClearITPendingBit(s->USARTx, USART_IT_ORE);
|
||||||
USART_ClearITPendingBit (s->USARTx, USART_IT_ORE);
|
}
|
||||||
|
|
||||||
|
if (USART_GetITStatus(s->USARTx, USART_IT_IDLE) == SET) {
|
||||||
|
if (s->port.idleCallback) {
|
||||||
|
s->port.idleCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear
|
||||||
|
(void) s->USARTx->SR;
|
||||||
|
(void) s->USARTx->DR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
#include "drivers/serial_uart.h"
|
#include "drivers/serial_uart.h"
|
||||||
#include "drivers/serial_uart_impl.h"
|
#include "drivers/serial_uart_impl.h"
|
||||||
|
|
||||||
|
#include "stm32f7xx_ll_usart.h"
|
||||||
|
|
||||||
static void handleUsartTxDma(uartPort_t *s);
|
static void handleUsartTxDma(uartPort_t *s);
|
||||||
|
|
||||||
const uartHardware_t uartHardware[UARTDEV_COUNT] = {
|
const uartHardware_t uartHardware[UARTDEV_COUNT] = {
|
||||||
|
@ -372,6 +374,14 @@ void uartIrqHandler(uartPort_t *s)
|
||||||
handleUsartTxDma(s);
|
handleUsartTxDma(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (__HAL_UART_GET_IT(huart, UART_IT_IDLE)) {
|
||||||
|
if (s->port.idleCallback) {
|
||||||
|
s->port.idleCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
__HAL_UART_CLEAR_IDLEFLAG(huart);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleUsartTxDma(uartPort_t *s)
|
static void handleUsartTxDma(uartPort_t *s)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue