Update cloud build defines (#14080)
[betaflight.git] / src / main / rx / msp.c
blobf42477f6c6d568a2883f11f24753dc5503e55940
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/>.
21 #include <stdbool.h>
22 #include <stdint.h>
24 #include "platform.h"
26 #ifdef USE_RX_MSP
28 #include "common/utils.h"
30 #include "drivers/io.h"
31 #include "pg/rx.h"
32 #include "rx/rx.h"
33 #include "rx/msp.h"
35 static uint16_t mspFrame[MAX_SUPPORTED_RC_CHANNEL_COUNT];
36 static bool rxMspFrameDone = false;
37 static bool rxMspOverrideFrameDone = false;
39 float rxMspReadRawRC(const rxRuntimeState_t *rxRuntimeState, uint8_t chan)
41 UNUSED(rxRuntimeState);
42 return mspFrame[chan];
46 * Called from MSP command handler - mspFcProcessCommand
48 void rxMspFrameReceive(const uint16_t *frame, int channelCount)
50 for (int i = 0; i < channelCount; i++) {
51 mspFrame[i] = frame[i];
54 // Any channels not provided will be reset to zero
55 for (int i = channelCount; i < MAX_SUPPORTED_RC_CHANNEL_COUNT; i++) {
56 mspFrame[i] = 0;
59 rxMspFrameDone = true;
60 rxMspOverrideFrameDone = true;
63 static uint8_t rxMspFrameStatus(rxRuntimeState_t *rxRuntimeState)
65 UNUSED(rxRuntimeState);
67 if (!rxMspFrameDone) {
68 return RX_FRAME_PENDING;
71 rxMspFrameDone = false;
72 return RX_FRAME_COMPLETE;
75 #if defined(USE_RX_MSP_OVERRIDE)
76 uint8_t rxMspOverrideFrameStatus(void)
78 if (!rxMspOverrideFrameDone) {
79 return RX_FRAME_PENDING;
82 rxMspOverrideFrameDone = false;
83 return RX_FRAME_COMPLETE;
85 #endif
87 void rxMspInit(const rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState)
89 UNUSED(rxConfig);
91 rxRuntimeState->channelCount = MAX_SUPPORTED_RC_CHANNEL_COUNT;
92 rxRuntimeState->rcReadRawFn = rxMspReadRawRC;
93 rxRuntimeState->rcFrameStatusFn = rxMspFrameStatus;
95 #endif