[FLYWOOF411] add board documentation
[inav/snaewe.git] / src / main / rx / pwm.c
blobfa90e3b476ce1e8a6e1cc629641da9444aba78c9
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 #include <stdbool.h>
19 #include <stdint.h>
20 #include <stdlib.h>
22 #include <string.h>
24 #include "platform.h"
26 #if defined(USE_RX_PPM)
28 #include "build/debug.h"
29 #include "common/utils.h"
31 #include "config/feature.h"
33 #include "drivers/timer.h"
34 #include "drivers/rx_pwm.h"
35 #include "drivers/time.h"
37 #include "fc/config.h"
39 #include "rx/rx.h"
40 #include "rx/pwm.h"
42 #define RC_PWM_50HZ_UPDATE (20 * 1000) // 50Hz update rate period
44 static uint16_t channelData[MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT];
46 static uint16_t readRawRC(const rxRuntimeConfig_t *rxRuntimeConfig, uint8_t channel)
48 UNUSED(rxRuntimeConfig);
49 return channelData[channel];
52 static uint8_t ppmFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
54 UNUSED(rxRuntimeConfig);
56 // PPM receiver counts received frames so we actually know if new data is available
57 if (isPPMDataBeingReceived()) {
58 for (int channel = 0; channel < MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT; channel++) {
59 channelData[channel] = ppmRead(channel);
62 resetPPMDataReceivedState();
63 return RX_FRAME_COMPLETE;
66 return RX_FRAME_PENDING;
69 bool rxPpmInit(rxRuntimeConfig_t *rxRuntimeConfig)
71 const timerHardware_t * timHw = timerGetByUsageFlag(TIM_USE_PPM);
73 if (timHw == NULL) {
74 return false;
77 if (!ppmInConfig(timHw)) {
78 return false;
81 rxRuntimeConfig->rxRefreshRate = RC_PWM_50HZ_UPDATE;
82 rxRuntimeConfig->requireFiltering = true;
83 rxRuntimeConfig->channelCount = MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT;
84 rxRuntimeConfig->rcReadRawFn = readRawRC;
85 rxRuntimeConfig->rcFrameStatusFn = ppmFrameStatus;
87 return true;
89 #endif