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_PROVIDER_MAX
= SERIALRX_IBUS
58 #define SERIALRX_PROVIDER_COUNT (SERIALRX_PROVIDER_MAX + 1)
60 #define MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT 12
61 #define MAX_SUPPORTED_RC_PARALLEL_PWM_CHANNEL_COUNT 8
62 #define MAX_SUPPORTED_RC_CHANNEL_COUNT (18)
64 #define NON_AUX_CHANNEL_COUNT 4
65 #define MAX_AUX_CHANNEL_COUNT (MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT)
69 #if MAX_SUPPORTED_RC_PARALLEL_PWM_CHANNEL_COUNT > MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT
70 #define MAX_SUPPORTED_RX_PARALLEL_PWM_OR_PPM_CHANNEL_COUNT MAX_SUPPORTED_RC_PARALLEL_PWM_CHANNEL_COUNT
72 #define MAX_SUPPORTED_RX_PARALLEL_PWM_OR_PPM_CHANNEL_COUNT MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT
75 extern const char rcChannelLetters
[];
77 extern int16_t rcData
[MAX_SUPPORTED_RC_CHANNEL_COUNT
]; // interval [1000;2000]
79 #define MAX_MAPPABLE_RX_INPUTS 8
81 #define RSSI_SCALE_MIN 1
82 #define RSSI_SCALE_MAX 255
83 #define RSSI_SCALE_DEFAULT 30
86 RX_FAILSAFE_MODE_AUTO
= 0,
87 RX_FAILSAFE_MODE_HOLD
,
89 RX_FAILSAFE_MODE_INVALID
,
90 } rxFailsafeChannelMode_e
;
92 #define RX_FAILSAFE_MODE_COUNT 3
95 RX_FAILSAFE_TYPE_FLIGHT
= 0,
97 } rxFailsafeChannelType_e
;
99 #define RX_FAILSAFE_TYPE_COUNT 2
101 typedef struct rxFailsafeChannelConfiguration_s
{
102 uint8_t mode
; // See rxFailsafeChannelMode_e
104 } rxFailsafeChannelConfiguration_t
;
106 typedef struct rxChannelRangeConfiguration_s
{
109 } rxChannelRangeConfiguration_t
;
111 typedef struct rxConfig_s
{
112 uint8_t rcmap
[MAX_MAPPABLE_RX_INPUTS
]; // mapping of radio channels to internal RPYTA+ order
113 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.
114 uint8_t spektrum_sat_bind
; // number of bind pulses for Spektrum satellite receivers
115 uint8_t rssi_channel
;
117 uint8_t rssi_ppm_invert
;
118 uint8_t rcSmoothing
; // Enable/Disable RC filtering
119 uint16_t midrc
; // Some radios have not a neutral point centered on 1500. can be changed here
120 uint16_t mincheck
; // minimum rc end
121 uint16_t maxcheck
; // maximum rc end
123 uint16_t rx_min_usec
;
124 uint16_t rx_max_usec
;
125 rxFailsafeChannelConfiguration_t failsafe_channel_configurations
[MAX_SUPPORTED_RC_CHANNEL_COUNT
];
127 rxChannelRangeConfiguration_t channelRanges
[NON_AUX_CHANNEL_COUNT
];
130 #define REMAPPABLE_CHANNEL_COUNT (sizeof(((rxConfig_t *)0)->rcmap) / sizeof(((rxConfig_t *)0)->rcmap[0]))
132 typedef struct rxRuntimeConfig_s
{
133 uint8_t channelCount
; // number of rc channels as reported by current input driver
134 uint8_t auxChannelCount
;
137 extern rxRuntimeConfig_t rxRuntimeConfig
;
139 void useRxConfig(rxConfig_t
*rxConfigToUse
);
141 typedef uint16_t (*rcReadRawDataPtr
)(rxRuntimeConfig_t
*rxRuntimeConfig
, uint8_t chan
); // used by receiver driver to return channel data
143 void updateRx(uint32_t currentTime
);
144 bool rxIsReceivingSignal(void);
145 bool rxAreFlightChannelsValid(void);
146 bool shouldProcessRx(uint32_t currentTime
);
147 void calculateRxChannelsAndUpdateFailsafe(uint32_t currentTime
);
149 void parseRcChannels(const char *input
, rxConfig_t
*rxConfig
);
150 uint8_t serialRxFrameStatus(rxConfig_t
*rxConfig
);
152 void updateRSSI(uint32_t currentTime
);
153 void resetAllRxChannelRangeConfigurations(rxChannelRangeConfiguration_t
*rxChannelRangeConfiguration
);
155 void suspendRxSignal(void);
156 void resumeRxSignal(void);
158 void initRxRefreshRate(uint16_t *rxRefreshRatePtr
);