Add RANGEFINDER and OPTICALFLOW MT build option (#14042)
[betaflight.git] / src / main / drivers / motor.h
blob2203ce7c2be2bddebe2472e121354b2843fbaacd
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/>.
20 * Author: jflyper
23 #pragma once
25 #include "common/time.h"
27 #include "pg/motor.h"
29 typedef enum {
30 PWM_TYPE_STANDARD = 0,
31 PWM_TYPE_ONESHOT125,
32 PWM_TYPE_ONESHOT42,
33 PWM_TYPE_MULTISHOT,
34 PWM_TYPE_BRUSHED,
35 PWM_TYPE_DSHOT150,
36 PWM_TYPE_DSHOT300,
37 PWM_TYPE_DSHOT600,
38 // PWM_TYPE_DSHOT1200, removed
39 PWM_TYPE_PROSHOT1000,
40 PWM_TYPE_DISABLED,
41 PWM_TYPE_MAX
42 } motorPwmProtocolTypes_e;
44 typedef struct motorVTable_s {
45 // Common
46 void (*postInit)(void);
47 float (*convertExternalToMotor)(uint16_t externalValue);
48 uint16_t (*convertMotorToExternal)(float motorValue);
49 bool (*enable)(void);
50 void (*disable)(void);
51 bool (*isMotorEnabled)(uint8_t index);
52 bool (*telemetryWait)(void);
53 bool (*decodeTelemetry)(void);
54 void (*updateInit)(void);
55 void (*write)(uint8_t index, float value);
56 void (*writeInt)(uint8_t index, uint16_t value);
57 void (*updateComplete)(void);
58 void (*shutdown)(void);
60 // Digital commands
62 } motorVTable_t;
64 typedef struct motorDevice_s {
65 motorVTable_t vTable;
66 uint8_t count;
67 bool initialized;
68 bool enabled;
69 timeMs_t motorEnableTimeMs;
70 } motorDevice_t;
72 void motorPostInitNull();
73 void motorWriteNull(uint8_t index, float value);
74 bool motorDecodeTelemetryNull(void);
75 void motorUpdateCompleteNull(void);
77 void motorPostInit();
78 void motorWriteAll(float *values);
80 void motorInitEndpoints(const motorConfig_t *motorConfig, float outputLimit, float *outputLow, float *outputHigh, float *disarm, float *deadbandMotor3DHigh, float *deadbandMotor3DLow);
82 float motorConvertFromExternal(uint16_t externalValue);
83 uint16_t motorConvertToExternal(float motorValue);
85 struct motorDevConfig_s; // XXX Shouldn't be needed once pwm_output* is really cleaned up.
86 void motorDevInit(const struct motorDevConfig_s *motorConfig, uint16_t idlePulse, uint8_t motorCount);
87 unsigned motorDeviceCount(void);
88 motorVTable_t *motorGetVTable(void);
89 bool checkMotorProtocolEnabled(const motorDevConfig_t *motorConfig, bool *protocolIsDshot);
90 bool isMotorProtocolDshot(void);
91 bool isMotorProtocolBidirDshot(void);
92 bool isMotorProtocolEnabled(void);
94 void motorDisable(void);
95 void motorEnable(void);
96 float motorEstimateMaxRpm(void);
97 bool motorIsEnabled(void);
98 bool motorIsMotorEnabled(uint8_t index);
99 timeMs_t motorGetMotorEnableTimeMs(void);
100 void motorShutdown(void); // Replaces stopPwmAllMotors
102 #ifdef USE_DSHOT_BITBANG
103 struct motorDevConfig_s;
104 typedef struct motorDevConfig_s motorDevConfig_t;
105 bool isDshotBitbangActive(const motorDevConfig_t *motorConfig);
106 #endif