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/>.
28 #include "io/serial.h" // For SERIAL_PORT_IDENTIFIER_TO_INDEX
29 #include "drivers/io.h"
30 #include "drivers/serial.h"
34 static const serialPinConfig_t
*pSerialPinConfig
;
36 static void inverterSet(int identifier
, bool on
)
38 IO_t pin
= IOGetByTag(pSerialPinConfig
->ioTagInverter
[SERIAL_PORT_IDENTIFIER_TO_INDEX(identifier
)]);
45 static void initInverter(int identifier
)
47 int uartIndex
= SERIAL_PORT_IDENTIFIER_TO_INDEX(identifier
);
48 IO_t pin
= IOGetByTag(pSerialPinConfig
->ioTagInverter
[uartIndex
]);
51 IOInit(pin
, OWNER_INVERTER
, RESOURCE_INDEX(uartIndex
));
52 IOConfigGPIO(pin
, IOCFG_OUT_PP
);
54 inverterSet(identifier
, false);
58 void initInverters(const serialPinConfig_t
*serialPinConfigToUse
)
60 pSerialPinConfig
= serialPinConfigToUse
;
63 initInverter(SERIAL_PORT_USART1
);
67 initInverter(SERIAL_PORT_USART2
);
71 initInverter(SERIAL_PORT_USART3
);
75 initInverter(SERIAL_PORT_UART4
);
79 initInverter(SERIAL_PORT_UART5
);
83 initInverter(SERIAL_PORT_USART6
);
87 void enableInverter(USART_TypeDef
*USARTx
, bool on
)
89 int identifier
= SERIAL_PORT_NONE
;
92 if (USARTx
== USART1
) {
93 identifier
= SERIAL_PORT_USART1
;
98 if (USARTx
== USART2
) {
99 identifier
= SERIAL_PORT_USART2
;
104 if (USARTx
== USART3
) {
105 identifier
= SERIAL_PORT_USART3
;
110 if (USARTx
== UART4
) {
111 identifier
= SERIAL_PORT_UART4
;
116 if (USARTx
== UART5
) {
117 identifier
= SERIAL_PORT_UART5
;
122 if (USARTx
== USART6
) {
123 identifier
= SERIAL_PORT_USART6
;
127 if (identifier
!= SERIAL_PORT_NONE
) {
128 inverterSet(identifier
, on
);
131 #endif // USE_INVERTER