[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / drivers / serial_pinconfig.c
blobf63fed69e158ae395b7d785263f27262273e53c7
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 #ifdef USE_UART
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).
41 #ifdef USE_UART1
42 # if !defined(UART1_RX_PIN)
43 # define UART1_RX_PIN NONE
44 # endif
45 # if !defined(UART1_TX_PIN)
46 # define UART1_TX_PIN NONE
47 # endif
48 # if !defined(INVERTER_PIN_UART1)
49 # define INVERTER_PIN_UART1 NONE
50 # endif
51 #endif
53 #ifdef USE_UART2
54 # if !defined(UART2_RX_PIN)
55 # define UART2_RX_PIN NONE
56 # endif
57 # if !defined(UART2_TX_PIN)
58 # define UART2_TX_PIN NONE
59 # endif
60 # if !defined(INVERTER_PIN_UART2)
61 # define INVERTER_PIN_UART2 NONE
62 # endif
63 #endif
65 #ifdef USE_UART3
66 # if !defined(UART3_RX_PIN)
67 # define UART3_RX_PIN NONE
68 # endif
69 # if !defined(UART3_TX_PIN)
70 # define UART3_TX_PIN NONE
71 # endif
72 # if !defined(INVERTER_PIN_UART3)
73 # define INVERTER_PIN_UART3 NONE
74 # endif
75 #endif
77 #ifdef USE_UART4
78 # if !defined(UART4_RX_PIN)
79 # define UART4_RX_PIN NONE
80 # endif
81 # if !defined(UART4_TX_PIN)
82 # define UART4_TX_PIN NONE
83 # endif
84 # if !defined(INVERTER_PIN_UART4)
85 # define INVERTER_PIN_UART4 NONE
86 # endif
87 #endif
89 #ifdef USE_UART5
90 # if !defined(UART5_RX_PIN)
91 # define UART5_RX_PIN NONE
92 # endif
93 # if !defined(UART5_TX_PIN)
94 # define UART5_TX_PIN NONE
95 # endif
96 # if !defined(INVERTER_PIN_UART5)
97 # define INVERTER_PIN_UART5 NONE
98 # endif
99 #endif
101 #ifdef USE_UART6
102 # if !defined(UART6_RX_PIN)
103 # define UART6_RX_PIN NONE
104 # endif
105 # if !defined(UART6_TX_PIN)
106 # define UART6_TX_PIN NONE
107 # endif
108 # if !defined(INVERTER_PIN_UART6)
109 # define INVERTER_PIN_UART6 NONE
110 # endif
111 #endif
113 #ifdef USE_UART7
114 # if !defined(UART7_RX_PIN)
115 # define UART7_RX_PIN NONE
116 # endif
117 # if !defined(UART7_TX_PIN)
118 # define UART7_TX_PIN NONE
119 # endif
120 # if !defined(INVERTER_PIN_UART7)
121 # define INVERTER_PIN_UART7 NONE
122 # endif
123 #endif
125 #ifdef USE_UART8
126 # if !defined(UART8_RX_PIN)
127 # define UART8_RX_PIN NONE
128 # endif
129 # if !defined(UART8_TX_PIN)
130 # define UART8_TX_PIN NONE
131 # endif
132 # if !defined(INVERTER_PIN_UART8)
133 # define INVERTER_PIN_UART8 NONE
134 # endif
135 #endif
137 #ifdef USE_UART9
138 # if !defined(UART9_RX_PIN)
139 # define UART9_RX_PIN NONE
140 # endif
141 # if !defined(UART9_TX_PIN)
142 # define UART9_TX_PIN NONE
143 # endif
144 # if !defined(INVERTER_PIN_UART9)
145 # define INVERTER_PIN_UART9 NONE
146 # endif
147 #endif
149 #ifdef USE_UART10
150 # if !defined(UART10_RX_PIN)
151 # define UART10_RX_PIN NONE
152 # endif
153 # if !defined(UART10_TX_PIN)
154 # define UART10_TX_PIN NONE
155 # endif
156 # if !defined(INVERTER_PIN_UART10)
157 # define INVERTER_PIN_UART10 NONE
158 # endif
159 #endif
161 #ifdef USE_LPUART1
162 # if !defined(LPUART1_RX_PIN)
163 # define LPUART1_RX_PIN NONE
164 # endif
165 # if !defined(LPUART1_TX_PIN)
166 # define LPUART1_TX_PIN NONE
167 # endif
168 # if !defined(INVERTER_PIN_LPUART1)
169 # define INVERTER_PIN_LPUART1 NONE
170 # endif
171 #endif
173 #ifdef USE_SOFTSERIAL1
174 # if !defined(SOFTSERIAL1_RX_PIN)
175 # define SOFTSERIAL1_RX_PIN NONE
176 # endif
177 # if !defined(SOFTSERIAL1_TX_PIN)
178 # define SOFTSERIAL1_TX_PIN NONE
179 # endif
180 #endif
182 #ifdef USE_SOFTSERIAL2
183 # if !defined(SOFTSERIAL2_RX_PIN)
184 # define SOFTSERIAL2_RX_PIN NONE
185 # endif
186 # if !defined(SOFTSERIAL2_TX_PIN)
187 # define SOFTSERIAL2_TX_PIN NONE
188 # endif
189 #endif
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[] = {
198 #ifdef USE_UART1
199 { SERIAL_PORT_USART1, IO_TAG(UART1_RX_PIN), IO_TAG(UART1_TX_PIN), IO_TAG(INVERTER_PIN_UART1) },
200 #endif
201 #ifdef USE_UART2
202 { SERIAL_PORT_USART2, IO_TAG(UART2_RX_PIN), IO_TAG(UART2_TX_PIN), IO_TAG(INVERTER_PIN_UART2) },
203 #endif
204 #ifdef USE_UART3
205 { SERIAL_PORT_USART3, IO_TAG(UART3_RX_PIN), IO_TAG(UART3_TX_PIN), IO_TAG(INVERTER_PIN_UART3) },
206 #endif
207 #ifdef USE_UART4
208 { SERIAL_PORT_UART4, IO_TAG(UART4_RX_PIN), IO_TAG(UART4_TX_PIN), IO_TAG(INVERTER_PIN_UART4) },
209 #endif
210 #ifdef USE_UART5
211 { SERIAL_PORT_UART5, IO_TAG(UART5_RX_PIN), IO_TAG(UART5_TX_PIN), IO_TAG(INVERTER_PIN_UART5) },
212 #endif
213 #ifdef USE_UART6
214 { SERIAL_PORT_USART6, IO_TAG(UART6_RX_PIN), IO_TAG(UART6_TX_PIN), IO_TAG(INVERTER_PIN_UART6) },
215 #endif
216 #ifdef USE_UART7
217 { SERIAL_PORT_USART7, IO_TAG(UART7_RX_PIN), IO_TAG(UART7_TX_PIN), IO_TAG(INVERTER_PIN_UART7) },
218 #endif
219 #ifdef USE_UART8
220 { SERIAL_PORT_USART8, IO_TAG(UART8_RX_PIN), IO_TAG(UART8_TX_PIN), IO_TAG(INVERTER_PIN_UART8) },
221 #endif
222 #ifdef USE_UART9
223 { SERIAL_PORT_UART9, IO_TAG(UART9_RX_PIN), IO_TAG(UART9_TX_PIN), IO_TAG(INVERTER_PIN_UART9) },
224 #endif
225 #ifdef USE_UART10
226 { SERIAL_PORT_USART10, IO_TAG(UART10_RX_PIN), IO_TAG(UART10_TX_PIN), IO_TAG(INVERTER_PIN_UART10) },
227 #endif
228 #ifdef USE_LPUART1
229 { SERIAL_PORT_LPUART1, IO_TAG(LPUART1_RX_PIN), IO_TAG(LPUART1_TX_PIN), IO_TAG(INVERTER_PIN_LPUART1) },
230 #endif
231 #ifdef USE_SOFTSERIAL1
232 { SERIAL_PORT_SOFTSERIAL1, IO_TAG(SOFTSERIAL1_RX_PIN), IO_TAG(SOFTSERIAL1_TX_PIN), IO_TAG(NONE) },
233 #endif
234 #ifdef USE_SOFTSERIAL2
235 { SERIAL_PORT_SOFTSERIAL2, IO_TAG(SOFTSERIAL2_RX_PIN), IO_TAG(SOFTSERIAL2_TX_PIN), IO_TAG(NONE) },
236 #endif
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;
250 #endif
251 #endif