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/>.
21 PORTSHARING_UNUSED
= 0,
22 PORTSHARING_NOT_SHARED
,
28 FUNCTION_MSP
= (1 << 0),
29 FUNCTION_GPS
= (1 << 1),
30 FUNCTION_FRSKY_TELEMETRY
= (1 << 2),
31 FUNCTION_HOTT_TELEMETRY
= (1 << 3),
32 FUNCTION_MSP_TELEMETRY
= (1 << 4),
33 FUNCTION_SMARTPORT_TELEMETRY
= (1 << 5),
34 FUNCTION_SERIAL_RX
= (1 << 6),
35 FUNCTION_BLACKBOX
= (1 << 7)
36 } serialPortFunction_e
;
38 // serial port identifiers are now fixed, these values are used by MSP commands.
40 SERIAL_PORT_USART1
= 0,
44 SERIAL_PORT_USB_VCP
= 20,
45 SERIAL_PORT_SOFTSERIAL1
= 30,
46 SERIAL_PORT_SOFTSERIAL2
,
47 SERIAL_PORT_IDENTIFIER_MAX
= SERIAL_PORT_SOFTSERIAL2
48 } serialPortIdentifier_e
;
50 serialPortIdentifier_e serialPortIdentifiers
[SERIAL_PORT_COUNT
];
55 typedef struct serialPortUsage_s
{
56 serialPortIdentifier_e identifier
;
57 serialPort_t
*serialPort
;
58 serialPortFunction_e function
;
61 serialPort_t
*findSharedSerialPort(uint16_t functionMask
, serialPortFunction_e sharedWithFunction
);
62 serialPort_t
*findNextSharedSerialPort(uint16_t functionMask
, serialPortFunction_e sharedWithFunction
);
68 typedef struct serialPortConfig_s
{
69 serialPortIdentifier_e identifier
;
70 uint16_t functionMask
;
71 uint32_t baudrate
; // not used for all functions, e.g. HoTT only works at 19200.
74 typedef struct serialConfig_s
{
75 uint8_t reboot_character
; // which byte is used to reboot. Default 'R', could be changed carefully to something else.
76 serialPortConfig_t portConfigs
[SERIAL_PORT_COUNT
];
83 bool isSerialConfigValid(serialConfig_t
*serialConfig
);
84 bool doesConfigurationUsePort(serialPortIdentifier_e portIdentifier
);
85 serialPortConfig_t
*findSerialPortConfig(serialPortFunction_e function
);
86 serialPortConfig_t
*findNextSerialPortConfig(serialPortFunction_e function
);
88 portSharing_e
determinePortSharing(serialPortConfig_t
*portConfig
, serialPortFunction_e function
);
89 bool isSerialPortShared(serialPortConfig_t
*portConfig
, uint16_t functionMask
, serialPortFunction_e sharedWithFunction
);
96 serialPort_t
*openSerialPort(
97 serialPortIdentifier_e identifier
,
98 serialPortFunction_e function
,
99 serialReceiveCallbackPtr callback
,
102 serialInversion_e inversion
104 void closeSerialPort(serialPort_t
*serialPort
);
106 void waitForSerialPortToFinishTransmitting(serialPort_t
*serialPort
);
109 // msp/cli/bootloader
111 void evaluateOtherData(serialPort_t
*serialPort
, uint8_t receivedChar
);
112 void handleSerial(void);