Don't handle non-MSP characters on VTX MSP port (#14091)
[betaflight.git] / src / main / drivers / serial_uart_pinconfig.c
blob8d9b348354cd585af2fd049a98c07b1ac734c3e8
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/>.
22 * UART pin configuration common to all MCUs.
26 * Authors:
27 * jflyper - Created as a part of configurable UART/refactoring.
30 #include <stdbool.h>
31 #include <stdint.h>
33 #include "platform.h"
35 #ifdef USE_UART
37 #include "build/build_config.h"
39 #include "drivers/rcc.h"
40 #include "drivers/serial.h"
41 #include "drivers/serial_uart.h"
42 #include "drivers/serial_uart_impl.h"
44 void uartPinConfigure(const serialPinConfig_t *pSerialPinConfig)
46 for (const uartHardware_t* hardware = uartHardware; hardware < ARRAYEND(uartHardware); hardware++) {
47 const serialPortIdentifier_e identifier = hardware->identifier;
48 uartDevice_t* uartdev = uartDeviceFromIdentifier(identifier);
49 const int resourceIndex = serialResourceIndex(identifier);
50 if (uartdev == NULL || resourceIndex < 0) {
51 // malformed uartHardware
52 continue;
54 const ioTag_t cfgRx = pSerialPinConfig->ioTagRx[resourceIndex];
55 const ioTag_t cfgTx = pSerialPinConfig->ioTagTx[resourceIndex];
56 #if UART_TRAIT_PINSWAP
57 bool swap = false;
58 #endif
59 for (unsigned pindex = 0; pindex < UARTHARDWARE_MAX_PINS; pindex++) {
60 if (cfgRx && cfgRx == hardware->rxPins[pindex].pin) {
61 uartdev->rx = hardware->rxPins[pindex];
64 if (cfgTx && cfgTx == hardware->txPins[pindex].pin) {
65 uartdev->tx = hardware->txPins[pindex];
67 #if UART_TRAIT_PINSWAP
68 // Check for swapped pins
69 if (cfgTx && cfgTx == hardware->rxPins[pindex].pin) {
70 uartdev->tx = hardware->rxPins[pindex];
71 swap = true;
74 if (cfgRx && cfgRx == hardware->txPins[pindex].pin) {
75 uartdev->rx = hardware->txPins[pindex];
76 swap = true;
78 #endif
80 if (uartdev->rx.pin || uartdev->tx.pin ) {
81 uartdev->hardware = hardware;
82 #if UART_TRAIT_PINSWAP
83 uartdev->pinSwap = swap;
84 #endif
88 #endif