Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / drivers / uart_inverter.c
blobb815883df79d263a9a7d3796b8ba4b9985f85c83
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
21 #include "platform.h"
23 #include "drivers/io.h"
24 #include "drivers/io_impl.h"
25 #include "drivers/uart_inverter.h"
27 #if defined(USE_UART_INVERTER)
29 static void inverterPinSet(IO_t pin, bool on)
31 IOWrite(pin, on);
34 static void initInverter(ioTag_t ioTag)
36 IO_t pin = IOGetByTag(ioTag);
37 IOInit(pin, OWNER_INVERTER, RESOURCE_OUTPUT, 0);
38 IOConfigGPIO(pin, IOCFG_OUT_PP);
40 inverterPinSet(pin, false);
43 void uartInverterInit(void)
46 // UART1
47 #ifdef INVERTER_PIN_UART1_RX
48 initInverter(IO_TAG(INVERTER_PIN_UART1_RX));
49 #endif
51 #ifdef INVERTER_PIN_UART1_TX
52 initInverter(IO_TAG(INVERTER_PIN_UART1_TX));
53 #endif
55 // UART2
56 #ifdef INVERTER_PIN_UART2_RX
57 initInverter(IO_TAG(INVERTER_PIN_UART2_RX));
58 #endif
60 #ifdef INVERTER_PIN_UART2_TX
61 initInverter(IO_TAG(INVERTER_PIN_UART2_TX));
62 #endif
64 // UART3
65 #ifdef INVERTER_PIN_UART3_RX
66 initInverter(IO_TAG(INVERTER_PIN_UART3_RX));
67 #endif
69 #ifdef INVERTER_PIN_UART3_TX
70 initInverter(IO_TAG(INVERTER_PIN_UART3_TX));
71 #endif
73 // UART4
74 #ifdef INVERTER_PIN_UART4_RX
75 initInverter(IO_TAG(INVERTER_PIN_UART4_RX));
76 #endif
78 #ifdef INVERTER_PIN_UART4_TX
79 initInverter(IO_TAG(INVERTER_PIN_UART4_TX));
80 #endif
82 // UART5
83 #ifdef INVERTER_PIN_UART5_RX
84 initInverter(IO_TAG(INVERTER_PIN_UART5_RX));
85 #endif
87 #ifdef INVERTER_PIN_UART5_TX
88 initInverter(IO_TAG(INVERTER_PIN_UART5_TX));
89 #endif
91 // UART6
92 #ifdef INVERTER_PIN_UART6_RX
93 initInverter(IO_TAG(INVERTER_PIN_UART6_RX));
94 #endif
96 #ifdef INVERTER_PIN_UART6_TX
97 initInverter(IO_TAG(INVERTER_PIN_UART6_TX));
98 #endif
101 #if defined(AT32F43x)
102 void uartInverterSet(usart_type *USARTx, uartInverterLine_e line, bool enable)
103 #else
104 void uartInverterSet(USART_TypeDef *USARTx, uartInverterLine_e line, bool enable)
105 #endif
107 IO_t rx_pin = IO_NONE;
108 IO_t tx_pin = IO_NONE;
110 // UART1
111 #if defined(INVERTER_PIN_UART1_RX) || defined(INVERTER_PIN_UART1_TX)
112 if (USARTx == USART1) {
113 #if defined(INVERTER_PIN_UART1_RX)
114 rx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART1_RX));
115 #endif
116 #if defined(INVERTER_PIN_UART1_TX)
117 tx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART1_TX));
118 #endif
120 #endif
122 // UART2
123 #if defined(INVERTER_PIN_UART2_RX) || defined(INVERTER_PIN_UART2_TX)
124 if (USARTx == USART2) {
125 #if defined(INVERTER_PIN_UART2_RX)
126 rx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART2_RX));
127 #endif
128 #if defined(INVERTER_PIN_UART2_TX)
129 tx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART2_TX));
130 #endif
132 #endif
134 // UART3
135 #if defined(INVERTER_PIN_UART3_RX) || defined(INVERTER_PIN_UART3_TX)
136 if (USARTx == USART3) {
137 #if defined(INVERTER_PIN_UART3_RX)
138 rx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART3_RX));
139 #endif
140 #if defined(INVERTER_PIN_UART3_TX)
141 tx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART3_TX));
142 #endif
144 #endif
146 // UART4
147 #if defined(INVERTER_PIN_UART4_RX) || defined(INVERTER_PIN_UART4_TX)
148 if (USARTx == USART4) {
149 #if defined(INVERTER_PIN_UART4_RX)
150 rx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART4_RX));
151 #endif
152 #if defined(INVERTER_PIN_UART4_TX)
153 tx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART4_TX));
154 #endif
156 #endif
158 // UART5
159 #if defined(INVERTER_PIN_UART5_RX) || defined(INVERTER_PIN_UART5_TX)
160 if (USARTx == USART5) {
161 #if defined(INVERTER_PIN_UART5_RX)
162 rx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART5_RX));
163 #endif
164 #if defined(INVERTER_PIN_UART5_TX)
165 tx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART5_TX));
166 #endif
168 #endif
170 // UART6
171 #if defined(INVERTER_PIN_UART6_RX) || defined(INVERTER_PIN_UART6_TX)
172 if (USARTx == USART6) {
173 #if defined(INVERTER_PIN_UART6_RX)
174 rx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART6_RX));
175 #endif
176 #if defined(INVERTER_PIN_UART6_TX)
177 tx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART6_TX));
178 #endif
180 #endif
182 // Now do the actual work
183 if (rx_pin != IO_NONE && (line & UART_INVERTER_LINE_RX)) {
184 inverterPinSet(rx_pin, enable);
186 if (tx_pin != IO_NONE && (line & UART_INVERTER_LINE_TX)) {
187 inverterPinSet(tx_pin, enable);
191 #endif