Implement Stopwatch (#12623)
[betaflight.git] / src / main / flight / mixer.h
blob11a6befad864f73231ea25fe0b4661e9d12d845f
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 "platform.h"
25 #include "common/time.h"
26 #include "pg/pg.h"
27 #include "drivers/io_types.h"
28 #include "drivers/pwm_output.h"
30 #define QUAD_MOTOR_COUNT 4
32 // Note: this is called MultiType/MULTITYPE_* in baseflight.
33 typedef enum mixerMode
35 MIXER_TRI = 1,
36 MIXER_QUADP = 2,
37 MIXER_QUADX = 3,
38 MIXER_BICOPTER = 4,
39 MIXER_GIMBAL = 5,
40 MIXER_Y6 = 6,
41 MIXER_HEX6 = 7,
42 MIXER_FLYING_WING = 8,
43 MIXER_Y4 = 9,
44 MIXER_HEX6X = 10,
45 MIXER_OCTOX8 = 11,
46 MIXER_OCTOFLATP = 12,
47 MIXER_OCTOFLATX = 13,
48 MIXER_AIRPLANE = 14, // airplane / singlecopter / dualcopter (not yet properly supported)
49 MIXER_HELI_120_CCPM = 15,
50 MIXER_HELI_90_DEG = 16,
51 MIXER_VTAIL4 = 17,
52 MIXER_HEX6H = 18,
53 MIXER_PPM_TO_SERVO = 19, // PPM -> servo relay
54 MIXER_DUALCOPTER = 20,
55 MIXER_SINGLECOPTER = 21,
56 MIXER_ATAIL4 = 22,
57 MIXER_CUSTOM = 23,
58 MIXER_CUSTOM_AIRPLANE = 24,
59 MIXER_CUSTOM_TRI = 25,
60 MIXER_QUADX_1234 = 26,
61 MIXER_OCTOX8P = 27
62 } mixerMode_e;
64 typedef enum mixerType
66 MIXER_LEGACY = 0,
67 MIXER_LINEAR = 1,
68 MIXER_DYNAMIC = 2,
69 } mixerType_e;
71 // Custom mixer data per motor
72 typedef struct motorMixer_s {
73 float throttle;
74 float roll;
75 float pitch;
76 float yaw;
77 } motorMixer_t;
79 PG_DECLARE_ARRAY(motorMixer_t, MAX_SUPPORTED_MOTORS, customMotorMixer);
81 // Custom mixer configuration
82 typedef struct mixer_s {
83 uint8_t motorCount;
84 uint8_t useServo;
85 const motorMixer_t *motor;
86 } mixer_t;
88 typedef struct mixerConfig_s {
89 uint8_t mixerMode;
90 bool yaw_motors_reversed;
91 uint8_t crashflip_motor_percent;
92 uint8_t crashflip_expo;
93 uint8_t mixer_type;
94 } mixerConfig_t;
96 PG_DECLARE(mixerConfig_t, mixerConfig);
98 #define CHANNEL_FORWARDING_DISABLED (uint8_t)0xFF
100 extern const mixer_t mixers[];
101 extern float motor[MAX_SUPPORTED_MOTORS];
102 extern float motor_disarmed[MAX_SUPPORTED_MOTORS];
103 struct rxConfig_s;
105 uint8_t getMotorCount(void);
106 float getMotorMixRange(void);
107 bool areMotorsRunning(void);
109 void mixerLoadMix(int index, motorMixer_t *customMixers);
110 void initEscEndpoints(void);
111 void mixerInit(mixerMode_e mixerMode);
112 void mixerInitProfile(void);
114 void mixerResetDisarmedMotors(void);
115 void mixTable(timeUs_t currentTimeUs);
116 void stopMotors(void);
117 void writeMotors(void);
119 bool mixerIsTricopter(void);
121 void mixerSetThrottleAngleCorrection(int correctionValue);
122 float mixerGetThrottle(void);
123 mixerMode_e getMixerMode(void);
124 bool mixerModeIsFixedWing(mixerMode_e mixerMode);
125 bool isFixedWing(void);
127 float getMotorOutputLow(void);
128 float getMotorOutputHigh(void);