Add OSD_STATE_GROUP_ELEMENTS state to osdUpdate() and optimise DMA vs polled MAX7456...
[betaflight.git] / src / main / flight / servos.h
blob365074b89d4a75e7513e12e221c48308caf7d0ff
1 /*
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)
8 * any later version.
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/>.
21 #pragma once
23 #include "pg/pg.h"
24 #include "drivers/io_types.h"
25 #include "drivers/pwm_output.h"
27 // These must be consecutive, see 'reversedSources'
28 enum {
29 INPUT_STABILIZED_ROLL = 0,
30 INPUT_STABILIZED_PITCH,
31 INPUT_STABILIZED_YAW,
32 INPUT_STABILIZED_THROTTLE,
33 INPUT_RC_ROLL,
34 INPUT_RC_PITCH,
35 INPUT_RC_YAW,
36 INPUT_RC_THROTTLE,
37 INPUT_RC_AUX1,
38 INPUT_RC_AUX2,
39 INPUT_RC_AUX3,
40 INPUT_RC_AUX4,
41 INPUT_GIMBAL_PITCH,
42 INPUT_GIMBAL_ROLL,
43 INPUT_SOURCE_COUNT
46 // target servo channels
47 typedef enum {
48 SERVO_GIMBAL_PITCH = 0,
49 SERVO_GIMBAL_ROLL = 1,
50 SERVO_FLAPS = 2,
51 SERVO_FLAPPERON_1 = 3,
52 SERVO_FLAPPERON_2 = 4,
53 SERVO_RUDDER = 5,
54 SERVO_ELEVATOR = 6,
55 SERVO_THROTTLE = 7, // for internal combustion (IC) planes
57 SERVO_BICOPTER_LEFT = 4,
58 SERVO_BICOPTER_RIGHT = 5,
60 SERVO_DUALCOPTER_LEFT = 4,
61 SERVO_DUALCOPTER_RIGHT = 5,
63 SERVO_SINGLECOPTER_1 = 3,
64 SERVO_SINGLECOPTER_2 = 4,
65 SERVO_SINGLECOPTER_3 = 5,
66 SERVO_SINGLECOPTER_4 = 6,
68 SERVO_HELI_LEFT = 0,
69 SERVO_HELI_RIGHT = 1,
70 SERVO_HELI_TOP = 2,
71 SERVO_HELI_RUD = 3
73 } servoIndex_e; // FIXME rename to servoChannel_e
75 #define SERVO_PLANE_INDEX_MIN SERVO_FLAPS
76 #define SERVO_PLANE_INDEX_MAX SERVO_THROTTLE
78 #define SERVO_DUALCOPTER_INDEX_MIN SERVO_DUALCOPTER_LEFT
79 #define SERVO_DUALCOPTER_INDEX_MAX SERVO_DUALCOPTER_RIGHT
81 #define SERVO_SINGLECOPTER_INDEX_MIN SERVO_SINGLECOPTER_1
82 #define SERVO_SINGLECOPTER_INDEX_MAX SERVO_SINGLECOPTER_4
84 #define SERVO_FLAPPERONS_MIN SERVO_FLAPPERON_1
85 #define SERVO_FLAPPERONS_MAX SERVO_FLAPPERON_2
87 #define MAX_SERVO_RULES (2 * MAX_SUPPORTED_SERVOS)
89 typedef struct servoMixer_s {
90 uint8_t targetChannel; // servo that receives the output of the rule
91 uint8_t inputSource; // input channel for this rule
92 int8_t rate; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
93 uint8_t speed; // reduces the speed of the rule, 0=unlimited speed
94 int8_t min; // lower bound of rule range [0;100]% of servo max-min
95 int8_t max; // lower bound of rule range [0;100]% of servo max-min
96 uint8_t box; // active rule if box is enabled, range [0;3], 0=no box, 1=BOXSERVO1, 2=BOXSERVO2, 3=BOXSERVO3
97 } servoMixer_t;
99 PG_DECLARE_ARRAY(servoMixer_t, MAX_SERVO_RULES, customServoMixers);
101 #define MAX_SERVO_SPEED UINT8_MAX
102 #define MAX_SERVO_BOXES 3
104 // Custom mixer configuration
105 typedef struct mixerRules_s {
106 uint8_t servoRuleCount;
107 const servoMixer_t *rule;
108 } mixerRules_t;
110 extern const mixerRules_t servoMixers[];
112 typedef struct servoParam_s {
113 uint32_t reversedSources; // the direction of servo movement for each input source of the servo mixer, bit set=inverted
114 int16_t min; // servo min
115 int16_t max; // servo max
116 int16_t middle; // servo middle
117 int8_t rate; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
118 int8_t forwardFromChannel; // RX channel index, 0 based. See CHANNEL_FORWARDING_DISABLED
119 } servoParam_t;
121 PG_DECLARE_ARRAY(servoParam_t, MAX_SUPPORTED_SERVOS, servoParams);
123 typedef struct servoConfig_s {
124 servoDevConfig_t dev;
125 uint16_t servo_lowpass_freq; // lowpass servo filter frequency selection; 1/1000ths of loop freq
126 uint8_t tri_unarmed_servo; // send tail servo correction pulses even when unarmed
127 uint8_t channelForwardingStartChannel;
128 } servoConfig_t;
130 PG_DECLARE(servoConfig_t, servoConfig);
132 typedef struct servoProfile_s {
133 servoParam_t servoConf[MAX_SUPPORTED_SERVOS];
134 } servoProfile_t;
136 extern int16_t servo[MAX_SUPPORTED_SERVOS];
138 bool isMixerUsingServos(void);
139 void writeServos(void);
140 void servoMixerLoadMix(int index);
141 void loadCustomServoMixer(void);
142 int servoDirection(int servoIndex, int fromChannel);
143 void servosInit(void);
144 void servosFilterInit(void);
145 void servoMixer(void);
146 // tricopter specific
147 void servosTricopterInit(void);
148 void servosTricopterMixer(void);
149 bool servosTricopterIsEnabledServoUnarmed(void);