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/>.
20 #define STICK_CHANNEL_COUNT 4
22 #define PWM_RANGE_ZERO 0 // FIXME should all usages of this be changed to use PWM_RANGE_MIN?
23 #define PWM_RANGE_MIN 1000
24 #define PWM_RANGE_MAX 2000
25 #define PWM_RANGE_MIDDLE (PWM_RANGE_MIN + ((PWM_RANGE_MAX - PWM_RANGE_MIN) / 2))
27 #define PWM_PULSE_MIN 750 // minimum PWM pulse width which is considered valid
28 #define PWM_PULSE_MAX 2250 // maximum PWM pulse width which is considered valid
30 #define RXFAIL_STEP_TO_CHANNEL_VALUE(step) (PWM_PULSE_MIN + 25 * step)
31 #define CHANNEL_VALUE_TO_RXFAIL_STEP(channelValue) ((constrain(channelValue, PWM_PULSE_MIN, PWM_PULSE_MAX) - PWM_PULSE_MIN) / 25)
32 #define MAX_RXFAIL_RANGE_STEP ((PWM_PULSE_MAX - PWM_PULSE_MIN) / 25)
34 #define DEFAULT_SERVO_MIN 1000
35 #define DEFAULT_SERVO_MIDDLE 1500
36 #define DEFAULT_SERVO_MAX 2000
37 #define DEFAULT_SERVO_MIN_ANGLE 90
38 #define DEFAULT_SERVO_MAX_ANGLE 90
41 SERIAL_RX_FRAME_PENDING
= 0,
42 SERIAL_RX_FRAME_COMPLETE
= (1 << 0),
43 SERIAL_RX_FRAME_FAILSAFE
= (1 << 1)
44 } serialrxFrameState_t
;
47 SERIALRX_SPEKTRUM1024
= 0,
48 SERIALRX_SPEKTRUM2048
= 1,
52 SERIALRX_XBUS_MODE_B
= 5,
53 SERIALRX_XBUS_MODE_B_RJ01
= 6,
55 SERIALRX_JETIEXBUS
= 8,
56 SERIALRX_PROVIDER_MAX
= SERIALRX_JETIEXBUS
59 #define SERIALRX_PROVIDER_COUNT (SERIALRX_PROVIDER_MAX + 1)
61 #define MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT 12
62 #define MAX_SUPPORTED_RC_PARALLEL_PWM_CHANNEL_COUNT 8
63 #define MAX_SUPPORTED_RC_CHANNEL_COUNT (18)
65 #define NON_AUX_CHANNEL_COUNT 4
66 #define MAX_AUX_CHANNEL_COUNT (MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT)
70 #if MAX_SUPPORTED_RC_PARALLEL_PWM_CHANNEL_COUNT > MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT
71 #define MAX_SUPPORTED_RX_PARALLEL_PWM_OR_PPM_CHANNEL_COUNT MAX_SUPPORTED_RC_PARALLEL_PWM_CHANNEL_COUNT
73 #define MAX_SUPPORTED_RX_PARALLEL_PWM_OR_PPM_CHANNEL_COUNT MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT
76 extern const char rcChannelLetters
[];
78 extern int16_t rcData
[MAX_SUPPORTED_RC_CHANNEL_COUNT
]; // interval [1000;2000]
80 #define MAX_MAPPABLE_RX_INPUTS 8
82 #define RSSI_SCALE_MIN 1
83 #define RSSI_SCALE_MAX 255
84 #define RSSI_SCALE_DEFAULT 30
87 RX_FAILSAFE_MODE_AUTO
= 0,
88 RX_FAILSAFE_MODE_HOLD
,
90 RX_FAILSAFE_MODE_INVALID
,
91 } rxFailsafeChannelMode_e
;
93 #define RX_FAILSAFE_MODE_COUNT 3
96 RX_FAILSAFE_TYPE_FLIGHT
= 0,
98 } rxFailsafeChannelType_e
;
100 #define RX_FAILSAFE_TYPE_COUNT 2
102 typedef struct rxFailsafeChannelConfiguration_s
{
103 uint8_t mode
; // See rxFailsafeChannelMode_e
105 } rxFailsafeChannelConfiguration_t
;
107 typedef struct rxChannelRangeConfiguration_s
{
110 } rxChannelRangeConfiguration_t
;
112 typedef struct rxConfig_s
{
113 uint8_t rcmap
[MAX_MAPPABLE_RX_INPUTS
]; // mapping of radio channels to internal RPYTA+ order
114 uint8_t serialrx_provider
; // type of UART-based receiver (0 = spek 10, 1 = spek 11, 2 = sbus). Must be enabled by FEATURE_RX_SERIAL first.
115 uint8_t sbus_inversion
; // default sbus (Futaba, FrSKY) is inverted. Support for uninverted OpenLRS (and modified FrSKY) receivers.
116 uint8_t spektrum_sat_bind
; // number of bind pulses for Spektrum satellite receivers
117 uint8_t spektrum_sat_bind_autoreset
; // whenever we will reset (exit) binding mode after hard reboot
118 uint8_t rssi_channel
;
120 uint8_t rssi_ppm_invert
;
121 uint16_t midrc
; // Some radios have not a neutral point centered on 1500. can be changed here
122 uint16_t mincheck
; // minimum rc end
123 uint16_t maxcheck
; // maximum rc end
125 uint8_t fpvCamAngleDegrees
; // Camera angle to be scaled into rc commands
126 uint8_t max_aux_channel
;
127 uint16_t airModeActivateThreshold
; // Throttle setpoint where airmode gets activated
129 uint16_t rx_min_usec
;
130 uint16_t rx_max_usec
;
131 rxFailsafeChannelConfiguration_t failsafe_channel_configurations
[MAX_SUPPORTED_RC_CHANNEL_COUNT
];
133 rxChannelRangeConfiguration_t channelRanges
[NON_AUX_CHANNEL_COUNT
];
136 #define REMAPPABLE_CHANNEL_COUNT (sizeof(((rxConfig_t *)0)->rcmap) / sizeof(((rxConfig_t *)0)->rcmap[0]))
138 typedef struct rxRuntimeConfig_s
{
139 uint8_t channelCount
; // number of rc channels as reported by current input driver
140 uint8_t auxChannelCount
;
143 extern rxRuntimeConfig_t rxRuntimeConfig
;
145 void useRxConfig(rxConfig_t
*rxConfigToUse
);
147 typedef uint16_t (*rcReadRawDataPtr
)(rxRuntimeConfig_t
*rxRuntimeConfig
, uint8_t chan
); // used by receiver driver to return channel data
149 void updateRx(uint32_t currentTime
);
150 bool rxIsReceivingSignal(void);
151 bool rxAreFlightChannelsValid(void);
152 bool shouldProcessRx(uint32_t currentTime
);
153 void calculateRxChannelsAndUpdateFailsafe(uint32_t currentTime
);
155 void parseRcChannels(const char *input
, rxConfig_t
*rxConfig
);
156 uint8_t serialRxFrameStatus(rxConfig_t
*rxConfig
);
158 void updateRSSI(uint32_t currentTime
);
159 void resetAllRxChannelRangeConfigurations(rxChannelRangeConfiguration_t
*rxChannelRangeConfiguration
);
161 void initRxRefreshRate(uint16_t *rxRefreshRatePtr
);
162 void suspendRxSignal(void);
163 void resumeRxSignal(void);
165 void initRxRefreshRate(uint16_t *rxRefreshRatePtr
);