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)
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/>.
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
;
42 static const serialDefaultPin_t serialDefaultPin
[] = {
44 { SERIAL_PORT_USART1
, IO_TAG(UART1_RX_PIN
), IO_TAG(UART1_TX_PIN
), IO_TAG(INVERTER_PIN_UART1
) },
47 { SERIAL_PORT_USART2
, IO_TAG(UART2_RX_PIN
), IO_TAG(UART2_TX_PIN
), IO_TAG(INVERTER_PIN_UART2
) },
50 { SERIAL_PORT_USART3
, IO_TAG(UART3_RX_PIN
), IO_TAG(UART3_TX_PIN
), IO_TAG(INVERTER_PIN_UART3
) },
53 { SERIAL_PORT_UART4
, IO_TAG(UART4_RX_PIN
), IO_TAG(UART4_TX_PIN
), IO_TAG(INVERTER_PIN_UART4
) },
56 { SERIAL_PORT_UART5
, IO_TAG(UART5_RX_PIN
), IO_TAG(UART5_TX_PIN
), IO_TAG(INVERTER_PIN_UART5
) },
59 { SERIAL_PORT_USART6
, IO_TAG(UART6_RX_PIN
), IO_TAG(UART6_TX_PIN
), IO_TAG(INVERTER_PIN_UART6
) },
62 { SERIAL_PORT_USART7
, IO_TAG(UART7_RX_PIN
), IO_TAG(UART7_TX_PIN
), IO_TAG(INVERTER_PIN_UART7
) },
65 { SERIAL_PORT_USART8
, IO_TAG(UART8_RX_PIN
), IO_TAG(UART8_TX_PIN
), IO_TAG(INVERTER_PIN_UART8
) },
68 { SERIAL_PORT_UART9
, IO_TAG(UART9_RX_PIN
), IO_TAG(UART9_TX_PIN
), IO_TAG(INVERTER_PIN_UART9
) },
71 { SERIAL_PORT_USART10
, IO_TAG(UART10_RX_PIN
), IO_TAG(UART10_TX_PIN
), IO_TAG(INVERTER_PIN_UART10
) },
74 { SERIAL_PORT_LPUART1
, IO_TAG(LPUART1_RX_PIN
), IO_TAG(LPUART1_TX_PIN
), IO_TAG(NONE
) },
76 #ifdef USE_SOFTSERIAL1
77 { SERIAL_PORT_SOFTSERIAL1
, IO_TAG(SOFTSERIAL1_RX_PIN
), IO_TAG(SOFTSERIAL1_TX_PIN
), IO_TAG(NONE
) },
79 #ifdef USE_SOFTSERIAL2
80 { SERIAL_PORT_SOFTSERIAL2
, IO_TAG(SOFTSERIAL2_RX_PIN
), IO_TAG(SOFTSERIAL2_TX_PIN
), IO_TAG(NONE
) },
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
;