Use the cached value of useDshotTelemetry to ensure consistent runtime use if dshot_b...
[betaflight.git] / src / main / drivers / serial_uart.h
blob1213d64a5168d17b0d06c79b4f665e89a991031f
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "drivers/dma.h" // For dmaResource_t
25 // Since serial ports can be used for any function these buffer sizes should be equal
26 // The two largest things that need to be sent are: 1, MSP responses, 2, UBLOX SVINFO packet.
28 // Size must be a power of two due to various optimizations which use 'and' instead of 'mod'
29 // Various serial routines return the buffer occupied size as uint8_t which would need to be extended in order to
30 // increase size further.
32 typedef enum {
33 UARTDEV_1 = 0,
34 UARTDEV_2 = 1,
35 UARTDEV_3 = 2,
36 UARTDEV_4 = 3,
37 UARTDEV_5 = 4,
38 UARTDEV_6 = 5,
39 UARTDEV_7 = 6,
40 UARTDEV_8 = 7,
41 UARTDEV_9 = 8,
42 UARTDEV_10 = 9,
43 LPUARTDEV_1 = 10,
44 UARTDEV_COUNT
45 } UARTDevice_e;
47 STATIC_ASSERT(UARTDEV_COUNT == SERIAL_PORT_MAX_INDEX, serial_pinconfig_does_not_match_uartdevs);
49 typedef struct uartPort_s {
50 serialPort_t port;
52 #ifdef USE_DMA
53 #ifdef USE_HAL_DRIVER
54 DMA_HandleTypeDef rxDMAHandle;
55 DMA_HandleTypeDef txDMAHandle;
56 #endif
58 dmaResource_t *rxDMAResource;
59 dmaResource_t *txDMAResource;
60 uint32_t rxDMAChannel;
61 uint32_t txDMAChannel;
62 #if defined(USE_ATBSP_DRIVER)
63 uint32_t rxDMAMuxId;
64 uint32_t txDMAMuxId;
65 #endif
67 uint32_t rxDMAIrq;
68 uint32_t txDMAIrq;
70 uint32_t rxDMAPos;
72 uint32_t txDMAPeripheralBaseAddr;
73 uint32_t rxDMAPeripheralBaseAddr;
74 #endif // USE_DMA
76 #ifdef USE_HAL_DRIVER
77 // All USARTs can also be used as UART, and we use them only as UART.
78 UART_HandleTypeDef Handle;
79 #endif
80 USART_TypeDef *USARTx;
81 bool txDMAEmpty;
83 bool (* checkUsartTxOutput)(struct uartPort_s *s);
84 } uartPort_t;
86 void uartPinConfigure(const serialPinConfig_t *pSerialPinConfig);
87 serialPort_t *uartOpen(UARTDevice_e device, serialReceiveCallbackPtr rxCallback, void *rxCallbackData, uint32_t baudRate, portMode_e mode, portOptions_e options);