Adding support for UART0 (#14094)
[betaflight.git] / src / main / drivers / serial_pinconfig.c
blobd72c8dbbff619326bfbed6a607e21371c236a947
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_UART0
44 { SERIAL_PORT_UART0, IO_TAG(UART0_RX_PIN), IO_TAG(UART0_TX_PIN), IO_TAG(INVERTER_PIN_UART0) },
45 #endif
46 #ifdef USE_UART1
47 { SERIAL_PORT_USART1, IO_TAG(UART1_RX_PIN), IO_TAG(UART1_TX_PIN), IO_TAG(INVERTER_PIN_UART1) },
48 #endif
49 #ifdef USE_UART2
50 { SERIAL_PORT_USART2, IO_TAG(UART2_RX_PIN), IO_TAG(UART2_TX_PIN), IO_TAG(INVERTER_PIN_UART2) },
51 #endif
52 #ifdef USE_UART3
53 { SERIAL_PORT_USART3, IO_TAG(UART3_RX_PIN), IO_TAG(UART3_TX_PIN), IO_TAG(INVERTER_PIN_UART3) },
54 #endif
55 #ifdef USE_UART4
56 { SERIAL_PORT_UART4, IO_TAG(UART4_RX_PIN), IO_TAG(UART4_TX_PIN), IO_TAG(INVERTER_PIN_UART4) },
57 #endif
58 #ifdef USE_UART5
59 { SERIAL_PORT_UART5, IO_TAG(UART5_RX_PIN), IO_TAG(UART5_TX_PIN), IO_TAG(INVERTER_PIN_UART5) },
60 #endif
61 #ifdef USE_UART6
62 { SERIAL_PORT_USART6, IO_TAG(UART6_RX_PIN), IO_TAG(UART6_TX_PIN), IO_TAG(INVERTER_PIN_UART6) },
63 #endif
64 #ifdef USE_UART7
65 { SERIAL_PORT_USART7, IO_TAG(UART7_RX_PIN), IO_TAG(UART7_TX_PIN), IO_TAG(INVERTER_PIN_UART7) },
66 #endif
67 #ifdef USE_UART8
68 { SERIAL_PORT_USART8, IO_TAG(UART8_RX_PIN), IO_TAG(UART8_TX_PIN), IO_TAG(INVERTER_PIN_UART8) },
69 #endif
70 #ifdef USE_UART9
71 { SERIAL_PORT_UART9, IO_TAG(UART9_RX_PIN), IO_TAG(UART9_TX_PIN), IO_TAG(INVERTER_PIN_UART9) },
72 #endif
73 #ifdef USE_UART10
74 { SERIAL_PORT_USART10, IO_TAG(UART10_RX_PIN), IO_TAG(UART10_TX_PIN), IO_TAG(INVERTER_PIN_UART10) },
75 #endif
76 #ifdef USE_LPUART1
77 { SERIAL_PORT_LPUART1, IO_TAG(LPUART1_RX_PIN), IO_TAG(LPUART1_TX_PIN), IO_TAG(NONE) },
78 #endif
79 #ifdef USE_SOFTSERIAL1
80 { SERIAL_PORT_SOFTSERIAL1, IO_TAG(SOFTSERIAL1_RX_PIN), IO_TAG(SOFTSERIAL1_TX_PIN), IO_TAG(NONE) },
81 #endif
82 #ifdef USE_SOFTSERIAL2
83 { SERIAL_PORT_SOFTSERIAL2, IO_TAG(SOFTSERIAL2_RX_PIN), IO_TAG(SOFTSERIAL2_TX_PIN), IO_TAG(NONE) },
84 #endif
87 PG_REGISTER_WITH_RESET_FN(serialPinConfig_t, serialPinConfig, PG_SERIAL_PIN_CONFIG, 0);
89 void pgResetFn_serialPinConfig(serialPinConfig_t *serialPinConfig)
91 for (const serialDefaultPin_t *defpin = serialDefaultPin; defpin < ARRAYEND(serialDefaultPin); defpin++) {
92 const int resourceIndex = serialResourceIndex(defpin->ident);
93 if (resourceIndex >= 0) {
94 serialPinConfig->ioTagRx[resourceIndex] = defpin->rxIO;
95 serialPinConfig->ioTagTx[resourceIndex] = defpin->txIO;
96 #if defined(USE_INVERTER)
97 // LPUART/SOFTSERIAL do not need/support inverter
98 if (resourceIndex < (int)ARRAYLEN(serialPinConfig->ioTagInverter)) {
99 serialPinConfig->ioTagInverter[resourceIndex] = defpin->inverterIO;
101 #endif
106 #endif