If RSSI Channel is set to Disabled when using S.Bus then generate RSS… (#5090)
[betaflight.git] / src / main / msp / msp_serial.h
blob784cc72fc96ac7b5ec891023cb8a84b226d81b9e
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 #pragma once
20 #include "drivers/time.h"
21 #include "interface/msp.h"
23 // Each MSP port requires state and a receive buffer, revisit this default if someone needs more than 3 MSP ports.
24 #define MAX_MSP_PORT_COUNT 3
26 typedef enum {
27 MSP_IDLE,
28 MSP_HEADER_START,
29 MSP_HEADER_M,
30 MSP_HEADER_X,
32 MSP_HEADER_V1,
33 MSP_PAYLOAD_V1,
34 MSP_CHECKSUM_V1,
36 MSP_HEADER_V2_OVER_V1,
37 MSP_PAYLOAD_V2_OVER_V1,
38 MSP_CHECKSUM_V2_OVER_V1,
40 MSP_HEADER_V2_NATIVE,
41 MSP_PAYLOAD_V2_NATIVE,
42 MSP_CHECKSUM_V2_NATIVE,
44 MSP_COMMAND_RECEIVED
45 } mspState_e;
47 typedef enum {
48 MSP_PACKET_COMMAND,
49 MSP_PACKET_REPLY
50 } mspPacketType_e;
52 typedef enum {
53 MSP_EVALUATE_NON_MSP_DATA,
54 MSP_SKIP_NON_MSP_DATA
55 } mspEvaluateNonMspData_e;
57 typedef enum {
58 MSP_PENDING_NONE,
59 MSP_PENDING_BOOTLOADER,
60 MSP_PENDING_CLI
61 } mspPendingSystemRequest_e;
63 #define MSP_PORT_INBUF_SIZE 192
64 #ifdef USE_FLASHFS
65 #ifdef STM32F1
66 #define MSP_PORT_DATAFLASH_BUFFER_SIZE 1024
67 #else
68 #define MSP_PORT_DATAFLASH_BUFFER_SIZE 4096
69 #endif
70 #define MSP_PORT_DATAFLASH_INFO_SIZE 16
71 #define MSP_PORT_OUTBUF_SIZE (MSP_PORT_DATAFLASH_BUFFER_SIZE + MSP_PORT_DATAFLASH_INFO_SIZE)
72 #else
73 #define MSP_PORT_OUTBUF_SIZE 256
74 #endif
76 typedef struct __attribute__((packed)) {
77 uint8_t size;
78 uint8_t cmd;
79 } mspHeaderV1_t;
81 typedef struct __attribute__((packed)) {
82 uint16_t size;
83 } mspHeaderJUMBO_t;
85 typedef struct __attribute__((packed)) {
86 uint8_t flags;
87 uint16_t cmd;
88 uint16_t size;
89 } mspHeaderV2_t;
91 #define MSP_MAX_HEADER_SIZE 9
93 struct serialPort_s;
94 typedef struct mspPort_s {
95 struct serialPort_s *port; // null when port unused.
96 timeMs_t lastActivityMs;
97 mspPendingSystemRequest_e pendingRequest;
98 mspState_e c_state;
99 mspPacketType_e packetType;
100 uint8_t inBuf[MSP_PORT_INBUF_SIZE];
101 uint16_t cmdMSP;
102 uint8_t cmdFlags;
103 mspVersion_e mspVersion;
104 uint_fast16_t offset;
105 uint_fast16_t dataSize;
106 uint8_t checksum1;
107 uint8_t checksum2;
108 } mspPort_t;
110 void mspSerialInit(void);
111 bool mspSerialWaiting(void);
112 void mspSerialProcess(mspEvaluateNonMspData_e evaluateNonMspData, mspProcessCommandFnPtr mspProcessCommandFn, mspProcessReplyFnPtr mspProcessReplyFn);
113 void mspSerialAllocatePorts(void);
114 void mspSerialReleasePortIfAllocated(struct serialPort_s *serialPort);
115 int mspSerialPush(uint8_t cmd, uint8_t *data, int datalen, mspDirection_e direction);
116 uint32_t mspSerialTxBytesFree(void);