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)
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/>.
25 #include "common/time.h"
30 PWM_TYPE_STANDARD
= 0,
38 // PWM_TYPE_DSHOT1200, removed
42 } motorPwmProtocolTypes_e
;
45 typedef struct motorVTable_s
{
47 void (*postInit
)(void);
48 float (*convertExternalToMotor
)(uint16_t externalValue
);
49 uint16_t (*convertMotorToExternal
)(float motorValue
);
51 void (*disable
)(void);
52 bool (*isMotorEnabled
)(uint8_t index
);
53 bool (*telemetryWait
)(void);
54 bool (*decodeTelemetry
)(void);
55 void (*updateInit
)(void);
56 void (*write
)(uint8_t index
, float value
);
57 void (*writeInt
)(uint8_t index
, uint16_t value
);
58 void (*updateComplete
)(void);
59 void (*shutdown
)(void);
65 typedef struct motorDevice_s
{
70 timeMs_t motorEnableTimeMs
;
73 void motorPostInitNull();
74 void motorWriteNull(uint8_t index
, float value
);
75 bool motorDecodeTelemetryNull(void);
76 void motorUpdateCompleteNull(void);
79 void motorWriteAll(float *values
);
81 void motorInitEndpoints(const motorConfig_t
*motorConfig
, float outputLimit
, float *outputLow
, float *outputHigh
, float *disarm
, float *deadbandMotor3DHigh
, float *deadbandMotor3DLow
);
83 float motorConvertFromExternal(uint16_t externalValue
);
84 uint16_t motorConvertToExternal(float motorValue
);
86 struct motorDevConfig_s
; // XXX Shouldn't be needed once pwm_output* is really cleaned up.
87 void motorDevInit(const struct motorDevConfig_s
*motorConfig
, uint16_t idlePulse
, uint8_t motorCount
);
88 unsigned motorDeviceCount(void);
89 motorVTable_t
motorGetVTable(void);
90 bool checkMotorProtocolEnabled(const motorDevConfig_t
*motorConfig
, bool *protocolIsDshot
);
91 bool isMotorProtocolDshot(void);
92 bool isMotorProtocolEnabled(void);
94 void motorDisable(void);
95 void motorEnable(void);
96 bool motorIsEnabled(void);
97 bool motorIsMotorEnabled(uint8_t index
);
98 timeMs_t
motorGetMotorEnableTimeMs(void);
99 void motorShutdown(void); // Replaces stopPwmAllMotors
101 #ifdef USE_DSHOT_BITBANG
102 struct motorDevConfig_s
;
103 typedef struct motorDevConfig_s motorDevConfig_t
;
104 bool isDshotBitbangActive(const motorDevConfig_t
*motorConfig
);
107 float getDigitalIdleOffset(const motorConfig_t
*motorConfig
);