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/>.
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 // Backward compatibility for existing targets
39 // Default pin (NONE).
42 # if !defined(UART1_RX_PIN)
43 # define UART1_RX_PIN NONE
45 # if !defined(UART1_TX_PIN)
46 # define UART1_TX_PIN NONE
48 # if !defined(INVERTER_PIN_UART1)
49 # define INVERTER_PIN_UART1 NONE
54 # if !defined(UART2_RX_PIN)
55 # define UART2_RX_PIN NONE
57 # if !defined(UART2_TX_PIN)
58 # define UART2_TX_PIN NONE
60 # if !defined(INVERTER_PIN_UART2)
61 # define INVERTER_PIN_UART2 NONE
66 # if !defined(UART3_RX_PIN)
67 # define UART3_RX_PIN NONE
69 # if !defined(UART3_TX_PIN)
70 # define UART3_TX_PIN NONE
72 # if !defined(INVERTER_PIN_UART3)
73 # define INVERTER_PIN_UART3 NONE
78 # if !defined(UART4_RX_PIN)
79 # define UART4_RX_PIN NONE
81 # if !defined(UART4_TX_PIN)
82 # define UART4_TX_PIN NONE
84 # if !defined(INVERTER_PIN_UART4)
85 # define INVERTER_PIN_UART4 NONE
90 # if !defined(UART5_RX_PIN)
91 # define UART5_RX_PIN NONE
93 # if !defined(UART5_TX_PIN)
94 # define UART5_TX_PIN NONE
96 # if !defined(INVERTER_PIN_UART5)
97 # define INVERTER_PIN_UART5 NONE
102 # if !defined(UART6_RX_PIN)
103 # define UART6_RX_PIN NONE
105 # if !defined(UART6_TX_PIN)
106 # define UART6_TX_PIN NONE
108 # if !defined(INVERTER_PIN_UART6)
109 # define INVERTER_PIN_UART6 NONE
114 # if !defined(UART7_RX_PIN)
115 # define UART7_RX_PIN NONE
117 # if !defined(UART7_TX_PIN)
118 # define UART7_TX_PIN NONE
120 # if !defined(INVERTER_PIN_UART7)
121 # define INVERTER_PIN_UART7 NONE
126 # if !defined(UART8_RX_PIN)
127 # define UART8_RX_PIN NONE
129 # if !defined(UART8_TX_PIN)
130 # define UART8_TX_PIN NONE
132 # if !defined(INVERTER_PIN_UART8)
133 # define INVERTER_PIN_UART8 NONE
138 # if !defined(UART9_RX_PIN)
139 # define UART9_RX_PIN NONE
141 # if !defined(UART9_TX_PIN)
142 # define UART9_TX_PIN NONE
144 # if !defined(INVERTER_PIN_UART9)
145 # define INVERTER_PIN_UART9 NONE
150 # if !defined(UART10_RX_PIN)
151 # define UART10_RX_PIN NONE
153 # if !defined(UART10_TX_PIN)
154 # define UART10_TX_PIN NONE
156 # if !defined(INVERTER_PIN_UART10)
157 # define INVERTER_PIN_UART10 NONE
162 # if !defined(LPUART1_RX_PIN)
163 # define LPUART1_RX_PIN NONE
165 # if !defined(LPUART1_TX_PIN)
166 # define LPUART1_TX_PIN NONE
168 # if !defined(INVERTER_PIN_LPUART1)
169 # define INVERTER_PIN_LPUART1 NONE
173 #ifdef USE_SOFTSERIAL1
174 # if !defined(SOFTSERIAL1_RX_PIN)
175 # define SOFTSERIAL1_RX_PIN NONE
177 # if !defined(SOFTSERIAL1_TX_PIN)
178 # define SOFTSERIAL1_TX_PIN NONE
182 #ifdef USE_SOFTSERIAL2
183 # if !defined(SOFTSERIAL2_RX_PIN)
184 # define SOFTSERIAL2_RX_PIN NONE
186 # if !defined(SOFTSERIAL2_TX_PIN)
187 # define SOFTSERIAL2_TX_PIN NONE
191 #if defined(USE_UART) || defined(USE_SOFTSERIAL1) || defined(USE_SOFTSERIAL1)
192 typedef struct serialDefaultPin_s
{
193 serialPortIdentifier_e ident
;
194 ioTag_t rxIO
, txIO
, inverterIO
;
195 } serialDefaultPin_t
;
197 static const serialDefaultPin_t serialDefaultPin
[] = {
199 { SERIAL_PORT_USART1
, IO_TAG(UART1_RX_PIN
), IO_TAG(UART1_TX_PIN
), IO_TAG(INVERTER_PIN_UART1
) },
202 { SERIAL_PORT_USART2
, IO_TAG(UART2_RX_PIN
), IO_TAG(UART2_TX_PIN
), IO_TAG(INVERTER_PIN_UART2
) },
205 { SERIAL_PORT_USART3
, IO_TAG(UART3_RX_PIN
), IO_TAG(UART3_TX_PIN
), IO_TAG(INVERTER_PIN_UART3
) },
208 { SERIAL_PORT_UART4
, IO_TAG(UART4_RX_PIN
), IO_TAG(UART4_TX_PIN
), IO_TAG(INVERTER_PIN_UART4
) },
211 { SERIAL_PORT_UART5
, IO_TAG(UART5_RX_PIN
), IO_TAG(UART5_TX_PIN
), IO_TAG(INVERTER_PIN_UART5
) },
214 { SERIAL_PORT_USART6
, IO_TAG(UART6_RX_PIN
), IO_TAG(UART6_TX_PIN
), IO_TAG(INVERTER_PIN_UART6
) },
217 { SERIAL_PORT_USART7
, IO_TAG(UART7_RX_PIN
), IO_TAG(UART7_TX_PIN
), IO_TAG(INVERTER_PIN_UART7
) },
220 { SERIAL_PORT_USART8
, IO_TAG(UART8_RX_PIN
), IO_TAG(UART8_TX_PIN
), IO_TAG(INVERTER_PIN_UART8
) },
223 { SERIAL_PORT_UART9
, IO_TAG(UART9_RX_PIN
), IO_TAG(UART9_TX_PIN
), IO_TAG(INVERTER_PIN_UART9
) },
226 { SERIAL_PORT_USART10
, IO_TAG(UART10_RX_PIN
), IO_TAG(UART10_TX_PIN
), IO_TAG(INVERTER_PIN_UART10
) },
229 { SERIAL_PORT_LPUART1
, IO_TAG(LPUART1_RX_PIN
), IO_TAG(LPUART1_TX_PIN
), IO_TAG(INVERTER_PIN_LPUART1
) },
231 #ifdef USE_SOFTSERIAL1
232 { SERIAL_PORT_SOFTSERIAL1
, IO_TAG(SOFTSERIAL1_RX_PIN
), IO_TAG(SOFTSERIAL1_TX_PIN
), IO_TAG(NONE
) },
234 #ifdef USE_SOFTSERIAL2
235 { SERIAL_PORT_SOFTSERIAL2
, IO_TAG(SOFTSERIAL2_RX_PIN
), IO_TAG(SOFTSERIAL2_TX_PIN
), IO_TAG(NONE
) },
239 PG_REGISTER_WITH_RESET_FN(serialPinConfig_t
, serialPinConfig
, PG_SERIAL_PIN_CONFIG
, 0);
241 void pgResetFn_serialPinConfig(serialPinConfig_t
*serialPinConfig
)
243 for (size_t index
= 0 ; index
< ARRAYLEN(serialDefaultPin
) ; index
++) {
244 const serialDefaultPin_t
*defpin
= &serialDefaultPin
[index
];
245 serialPinConfig
->ioTagRx
[SERIAL_PORT_IDENTIFIER_TO_INDEX(defpin
->ident
)] = defpin
->rxIO
;
246 serialPinConfig
->ioTagTx
[SERIAL_PORT_IDENTIFIER_TO_INDEX(defpin
->ident
)] = defpin
->txIO
;
247 serialPinConfig
->ioTagInverter
[SERIAL_PORT_IDENTIFIER_TO_INDEX(defpin
->ident
)] = defpin
->inverterIO
;