Clarified the name of the 'clear to send' function in SmartPort.
[betaflight.git] / src / main / telemetry / smartport.h
blob929119cf3bb6cf2f1a93180a5931286dd4761d65
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 * smartport.h
24 * Created on: 25 October 2014
25 * Author: Frank26080115
28 #pragma once
30 #include <stdbool.h>
31 #include <stdint.h>
33 #define SMARTPORT_MSP_TX_BUF_SIZE 256
34 #define SMARTPORT_MSP_RX_BUF_SIZE 64
36 enum
38 FSSP_START_STOP = 0x7E,
40 FSSP_DLE = 0x7D,
41 FSSP_DLE_XOR = 0x20,
43 FSSP_DATA_FRAME = 0x10,
44 FSSP_MSPC_FRAME_SMARTPORT = 0x30, // MSP client frame
45 FSSP_MSPC_FRAME_FPORT = 0x31, // MSP client frame
46 FSSP_MSPS_FRAME = 0x32, // MSP server frame
48 // ID of sensor. Must be something that is polled by FrSky RX
49 FSSP_SENSOR_ID1 = 0x1B,
50 FSSP_SENSOR_ID2 = 0x0D,
51 FSSP_SENSOR_ID3 = 0x34,
52 FSSP_SENSOR_ID4 = 0x67
53 // there are 32 ID's polled by smartport master
54 // remaining 3 bits are crc (according to comments in openTx code)
57 typedef struct smartPortPayload_s {
58 uint8_t frameId;
59 uint16_t valueId;
60 uint32_t data;
61 } __attribute__((packed)) smartPortPayload_t;
63 typedef void smartPortWriteFrameFn(const smartPortPayload_t *payload);
64 typedef bool smartPortReadyToSendFn(void);
66 bool initSmartPortTelemetry(void);
67 void checkSmartPortTelemetryState(void);
68 bool initSmartPortTelemetryExternal(smartPortWriteFrameFn *smartPortWriteFrameExternal);
70 void handleSmartPortTelemetry(void);
71 void processSmartPortTelemetry(smartPortPayload_t *payload, volatile bool *hasRequest, const uint32_t *requestTimeout);
73 smartPortPayload_t *smartPortDataReceive(uint16_t c, bool *clearToSend, smartPortReadyToSendFn *checkQueueEmpty, bool withChecksum);
75 struct serialPort_s;
76 void smartPortWriteFrameSerial(const smartPortPayload_t *payload, struct serialPort_s *port, uint16_t checksum);
77 void smartPortSendByte(uint8_t c, uint16_t *checksum, struct serialPort_s *port);
78 bool smartPortPayloadContainsMSP(const smartPortPayload_t *payload);