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/>.
25 #include "common/utils.h"
27 #include "drivers/io.h"
31 static uint16_t mspFrame
[MAX_SUPPORTED_RC_CHANNEL_COUNT
];
32 static bool rxMspFrameDone
= false;
34 static uint16_t rxMspReadRawRC(const rxRuntimeConfig_t
*rxRuntimeConfig
, uint8_t chan
)
36 UNUSED(rxRuntimeConfig
);
37 return mspFrame
[chan
];
41 * Called from MSP command handler - mspFcProcessCommand
43 void rxMspFrameReceive(uint16_t *frame
, int channelCount
)
45 for (int i
= 0; i
< channelCount
; i
++) {
46 mspFrame
[i
] = frame
[i
];
49 // Any channels not provided will be reset to zero
50 for (int i
= channelCount
; i
< MAX_SUPPORTED_RC_CHANNEL_COUNT
; i
++) {
54 rxMspFrameDone
= true;
57 static uint8_t rxMspFrameStatus(rxRuntimeConfig_t
*rxRuntimeConfig
)
59 UNUSED(rxRuntimeConfig
);
61 if (!rxMspFrameDone
) {
62 return RX_FRAME_PENDING
;
65 rxMspFrameDone
= false;
66 return RX_FRAME_COMPLETE
;
69 void rxMspInit(const rxConfig_t
*rxConfig
, rxRuntimeConfig_t
*rxRuntimeConfig
)
73 rxRuntimeConfig
->channelCount
= MAX_SUPPORTED_RC_CHANNEL_COUNT
;
74 rxRuntimeConfig
->rxRefreshRate
= 20000;
76 rxRuntimeConfig
->rcReadRawFn
= rxMspReadRawRC
;
77 rxRuntimeConfig
->rcFrameStatusFn
= rxMspFrameStatus
;