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)
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/>.
28 #include "common/utils.h"
30 #include "drivers/io.h"
36 static uint16_t mspFrame
[MAX_SUPPORTED_RC_CHANNEL_COUNT
];
37 static bool rxMspFrameDone
= 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(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
++) {
59 rxMspFrameDone
= true;
62 static uint8_t rxMspFrameStatus(rxRuntimeState_t
*rxRuntimeState
)
64 UNUSED(rxRuntimeState
);
66 if (!rxMspFrameDone
) {
67 return RX_FRAME_PENDING
;
70 rxMspFrameDone
= false;
71 return RX_FRAME_COMPLETE
;
74 void rxMspInit(const rxConfig_t
*rxConfig
, rxRuntimeState_t
*rxRuntimeState
)
78 rxRuntimeState
->channelCount
= MAX_SUPPORTED_RC_CHANNEL_COUNT
;
79 rxRuntimeState
->rxRefreshRate
= 20000;
81 rxRuntimeState
->rcReadRawFn
= rxMspReadRawRC
;
82 rxRuntimeState
->rcFrameStatusFn
= rxMspFrameStatus
;