Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / src / main / drivers / serial_uart.h
blob4c1e6d57508e6b27227317561e475251db1951cc
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #define UART_AF(uart, af) CONCAT3(GPIO_AF, af, _ ## uart)
22 // Since serial ports can be used for any function these buffer sizes should be equal
23 // The two largest things that need to be sent are: 1, MSP responses, 2, UBLOX SVINFO packet.
25 // Size must be a power of two due to various optimizations which use 'and' instead of 'mod'
26 // Various serial routines return the buffer occupied size as uint8_t which would need to be extended in order to
27 // increase size further.
28 #define UART1_RX_BUFFER_SIZE 256
29 #define UART1_TX_BUFFER_SIZE 256
30 #define UART2_RX_BUFFER_SIZE 256
31 #define UART2_TX_BUFFER_SIZE 256
32 #define UART3_RX_BUFFER_SIZE 256
33 #define UART3_TX_BUFFER_SIZE 256
34 #define UART4_RX_BUFFER_SIZE 256
35 #define UART4_TX_BUFFER_SIZE 256
36 #define UART5_RX_BUFFER_SIZE 256
37 #define UART5_TX_BUFFER_SIZE 256
38 #define UART6_RX_BUFFER_SIZE 256
39 #define UART6_TX_BUFFER_SIZE 256
40 #define UART7_RX_BUFFER_SIZE 256
41 #define UART7_TX_BUFFER_SIZE 256
42 #define UART8_RX_BUFFER_SIZE 256
43 #define UART8_TX_BUFFER_SIZE 256
45 typedef enum {
46 UARTDEV_1 = 0,
47 UARTDEV_2 = 1,
48 UARTDEV_3 = 2,
49 UARTDEV_4 = 3,
50 UARTDEV_5 = 4,
51 UARTDEV_6 = 5,
52 UARTDEV_7 = 6,
53 UARTDEV_8 = 7,
54 UARTDEV_MAX
55 } UARTDevice_e;
57 typedef struct {
58 serialPort_t port;
60 #if defined(AT32F43x)
61 usart_type *USARTx;
62 #else
63 #ifdef USE_HAL_DRIVER
64 UART_HandleTypeDef Handle;
65 #endif
66 USART_TypeDef *USARTx;
67 #endif
69 } uartPort_t;
71 void uartGetPortPins(UARTDevice_e device, serialPortPins_t * pins);
72 void uartClearIdleFlag(uartPort_t *s);
73 void uartConfigurePinSwap(uartPort_t *uartPort);
74 #if defined(AT32F43x)
75 serialPort_t *uartOpen(usart_type *USARTx, serialReceiveCallbackPtr rxCallback, void *rxCallbackData, uint32_t baudRate, portMode_t mode, portOptions_t options);
76 #else
77 serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr rxCallback, void *rxCallbackData, uint32_t baudRate, portMode_t mode, portOptions_t options);
78 #endif
79 // serialPort API
80 void uartWrite(serialPort_t *instance, uint8_t ch);
81 uint32_t uartTotalRxBytesWaiting(const serialPort_t *instance);
82 uint32_t uartTotalTxBytesFree(const serialPort_t *instance);
83 uint8_t uartRead(serialPort_t *instance);
84 void uartSetBaudRate(serialPort_t *s, uint32_t baudRate);
85 bool isUartTransmitBufferEmpty(const serialPort_t *s);