Add RANGEFINDER and OPTICALFLOW MT build option (#14042)
[betaflight.git] / src / main / drivers / serial_pinconfig.c
blob71a1bf57eaee97c00617836a0a28328f440a6a51
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 #include <stdbool.h>
22 #include <stdint.h>
23 #include <string.h>
25 #include "platform.h"
27 #if defined(USE_UART) || defined(USE_LPUART) || defined(USE_SOFTSERIAL)
29 #include "build/build_config.h"
31 #include "io/serial.h"
32 #include "drivers/serial.h"
33 #include "drivers/serial_uart.h"
35 #include "pg/pg_ids.h"
37 typedef struct serialDefaultPin_s {
38 serialPortIdentifier_e ident;
39 ioTag_t rxIO, txIO, inverterIO;
40 } serialDefaultPin_t;
42 static const serialDefaultPin_t serialDefaultPin[] = {
43 #ifdef USE_UART1
44 { SERIAL_PORT_USART1, IO_TAG(UART1_RX_PIN), IO_TAG(UART1_TX_PIN), IO_TAG(INVERTER_PIN_UART1) },
45 #endif
46 #ifdef USE_UART2
47 { SERIAL_PORT_USART2, IO_TAG(UART2_RX_PIN), IO_TAG(UART2_TX_PIN), IO_TAG(INVERTER_PIN_UART2) },
48 #endif
49 #ifdef USE_UART3
50 { SERIAL_PORT_USART3, IO_TAG(UART3_RX_PIN), IO_TAG(UART3_TX_PIN), IO_TAG(INVERTER_PIN_UART3) },
51 #endif
52 #ifdef USE_UART4
53 { SERIAL_PORT_UART4, IO_TAG(UART4_RX_PIN), IO_TAG(UART4_TX_PIN), IO_TAG(INVERTER_PIN_UART4) },
54 #endif
55 #ifdef USE_UART5
56 { SERIAL_PORT_UART5, IO_TAG(UART5_RX_PIN), IO_TAG(UART5_TX_PIN), IO_TAG(INVERTER_PIN_UART5) },
57 #endif
58 #ifdef USE_UART6
59 { SERIAL_PORT_USART6, IO_TAG(UART6_RX_PIN), IO_TAG(UART6_TX_PIN), IO_TAG(INVERTER_PIN_UART6) },
60 #endif
61 #ifdef USE_UART7
62 { SERIAL_PORT_USART7, IO_TAG(UART7_RX_PIN), IO_TAG(UART7_TX_PIN), IO_TAG(INVERTER_PIN_UART7) },
63 #endif
64 #ifdef USE_UART8
65 { SERIAL_PORT_USART8, IO_TAG(UART8_RX_PIN), IO_TAG(UART8_TX_PIN), IO_TAG(INVERTER_PIN_UART8) },
66 #endif
67 #ifdef USE_UART9
68 { SERIAL_PORT_UART9, IO_TAG(UART9_RX_PIN), IO_TAG(UART9_TX_PIN), IO_TAG(INVERTER_PIN_UART9) },
69 #endif
70 #ifdef USE_UART10
71 { SERIAL_PORT_USART10, IO_TAG(UART10_RX_PIN), IO_TAG(UART10_TX_PIN), IO_TAG(INVERTER_PIN_UART10) },
72 #endif
73 #ifdef USE_LPUART1
74 { SERIAL_PORT_LPUART1, IO_TAG(LPUART1_RX_PIN), IO_TAG(LPUART1_TX_PIN), IO_TAG(NONE) },
75 #endif
76 #ifdef USE_SOFTSERIAL1
77 { SERIAL_PORT_SOFTSERIAL1, IO_TAG(SOFTSERIAL1_RX_PIN), IO_TAG(SOFTSERIAL1_TX_PIN), IO_TAG(NONE) },
78 #endif
79 #ifdef USE_SOFTSERIAL2
80 { SERIAL_PORT_SOFTSERIAL2, IO_TAG(SOFTSERIAL2_RX_PIN), IO_TAG(SOFTSERIAL2_TX_PIN), IO_TAG(NONE) },
81 #endif
84 PG_REGISTER_WITH_RESET_FN(serialPinConfig_t, serialPinConfig, PG_SERIAL_PIN_CONFIG, 0);
86 void pgResetFn_serialPinConfig(serialPinConfig_t *serialPinConfig)
88 for (const serialDefaultPin_t *defpin = serialDefaultPin; defpin < ARRAYEND(serialDefaultPin); defpin++) {
89 const int resourceIndex = serialResourceIndex(defpin->ident);
90 if (resourceIndex >= 0) {
91 serialPinConfig->ioTagRx[resourceIndex] = defpin->rxIO;
92 serialPinConfig->ioTagTx[resourceIndex] = defpin->txIO;
93 #if defined(USE_INVERTER)
94 // LPUART/SOFTSERIAL do not need/support inverter
95 if (resourceIndex < (int)ARRAYLEN(serialPinConfig->ioTagInverter)) {
96 serialPinConfig->ioTagInverter[resourceIndex] = defpin->inverterIO;
98 #endif
103 #endif