Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / serial_uart.h
blobb9351355a91e1ba5ca846634a008e04be6979b21
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 } UARTDevice_e;
46 typedef struct uartPort_s {
47 serialPort_t port;
49 #ifdef USE_DMA
50 #ifdef USE_HAL_DRIVER
51 DMA_HandleTypeDef rxDMAHandle;
52 DMA_HandleTypeDef txDMAHandle;
53 #endif
55 dmaResource_t *rxDMAResource;
56 dmaResource_t *txDMAResource;
57 uint32_t rxDMAChannel;
58 uint32_t txDMAChannel;
60 uint32_t rxDMAIrq;
61 uint32_t txDMAIrq;
63 uint32_t rxDMAPos;
65 uint32_t txDMAPeripheralBaseAddr;
66 uint32_t rxDMAPeripheralBaseAddr;
67 #endif // USE_DMA
69 #ifdef USE_HAL_DRIVER
70 // All USARTs can also be used as UART, and we use them only as UART.
71 UART_HandleTypeDef Handle;
72 #endif
73 USART_TypeDef *USARTx;
74 bool txDMAEmpty;
75 } uartPort_t;
77 void uartPinConfigure(const serialPinConfig_t *pSerialPinConfig);
78 serialPort_t *uartOpen(UARTDevice_e device, serialReceiveCallbackPtr rxCallback, void *rxCallbackData, uint32_t baudRate, portMode_e mode, portOptions_e options);