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/>.
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
)
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)
47 #ifdef INVERTER_PIN_UART1_RX
48 initInverter(IO_TAG(INVERTER_PIN_UART1_RX
));
51 #ifdef INVERTER_PIN_UART1_TX
52 initInverter(IO_TAG(INVERTER_PIN_UART1_TX
));
56 #ifdef INVERTER_PIN_UART2_RX
57 initInverter(IO_TAG(INVERTER_PIN_UART2_RX
));
60 #ifdef INVERTER_PIN_UART2_TX
61 initInverter(IO_TAG(INVERTER_PIN_UART2_TX
));
65 #ifdef INVERTER_PIN_UART3_RX
66 initInverter(IO_TAG(INVERTER_PIN_UART3_RX
));
69 #ifdef INVERTER_PIN_UART3_TX
70 initInverter(IO_TAG(INVERTER_PIN_UART3_TX
));
74 #ifdef INVERTER_PIN_UART4_RX
75 initInverter(IO_TAG(INVERTER_PIN_UART4_RX
));
78 #ifdef INVERTER_PIN_UART4_TX
79 initInverter(IO_TAG(INVERTER_PIN_UART4_TX
));
83 #ifdef INVERTER_PIN_UART5_RX
84 initInverter(IO_TAG(INVERTER_PIN_UART5_RX
));
87 #ifdef INVERTER_PIN_UART5_TX
88 initInverter(IO_TAG(INVERTER_PIN_UART5_TX
));
92 #ifdef INVERTER_PIN_UART6_RX
93 initInverter(IO_TAG(INVERTER_PIN_UART6_RX
));
96 #ifdef INVERTER_PIN_UART6_TX
97 initInverter(IO_TAG(INVERTER_PIN_UART6_TX
));
101 #if defined(AT32F43x)
102 void uartInverterSet(usart_type
*USARTx
, uartInverterLine_e line
, bool enable
)
104 void uartInverterSet(USART_TypeDef
*USARTx
, uartInverterLine_e line
, bool enable
)
107 IO_t rx_pin
= IO_NONE
;
108 IO_t tx_pin
= IO_NONE
;
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
));
116 #if defined(INVERTER_PIN_UART1_TX)
117 tx_pin
= IOGetByTag(IO_TAG(INVERTER_PIN_UART1_TX
));
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
));
128 #if defined(INVERTER_PIN_UART2_TX)
129 tx_pin
= IOGetByTag(IO_TAG(INVERTER_PIN_UART2_TX
));
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
));
140 #if defined(INVERTER_PIN_UART3_TX)
141 tx_pin
= IOGetByTag(IO_TAG(INVERTER_PIN_UART3_TX
));
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
));
152 #if defined(INVERTER_PIN_UART4_TX)
153 tx_pin
= IOGetByTag(IO_TAG(INVERTER_PIN_UART4_TX
));
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
));
164 #if defined(INVERTER_PIN_UART5_TX)
165 tx_pin
= IOGetByTag(IO_TAG(INVERTER_PIN_UART5_TX
));
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
));
176 #if defined(INVERTER_PIN_UART6_TX)
177 tx_pin
= IOGetByTag(IO_TAG(INVERTER_PIN_UART6_TX
));
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
);