Add default config option for dshot telemetry (#13184)
[betaflight.git] / src / main / pg / motor.c
blob27fa8e49b628b28b89624390e12fa68920f8a968
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/>.
22 #include <stdbool.h>
23 #include <stdint.h>
25 #include "platform.h"
27 #ifdef USE_MOTOR
29 #include "drivers/pwm_output.h"
31 #include "pg/pg.h"
32 #include "pg/pg_ids.h"
33 #include "pg/motor.h"
35 #if !defined(DEFAULT_DSHOT_BITBANG)
36 #define DEFAULT_DSHOT_BITBANG DSHOT_BITBANG_AUTO
37 #endif
39 #if !defined(DSHOT_BITBANGED_TIMER_DEFAULT)
40 #define DSHOT_BITBANGED_TIMER_DEFAULT DSHOT_BITBANGED_TIMER_AUTO
41 #endif
43 #if !defined(DEFAULT_DSHOT_BURST)
44 #define DEFAULT_DSHOT_BURST DSHOT_DMAR_OFF
45 #endif
47 #if !defined(DEFAULT_DSHOT_TELEMETRY)
48 #define DEFAULT_DSHOT_TELEMETRY DSHOT_TELEMETRY_OFF
49 #endif
51 PG_REGISTER_WITH_RESET_FN(motorConfig_t, motorConfig, PG_MOTOR_CONFIG, 2);
53 void pgResetFn_motorConfig(motorConfig_t *motorConfig)
55 #ifdef BRUSHED_MOTORS
56 motorConfig->minthrottle = 1000;
57 motorConfig->dev.motorPwmRate = BRUSHED_MOTORS_PWM_RATE;
58 motorConfig->dev.motorPwmProtocol = PWM_TYPE_BRUSHED;
59 motorConfig->dev.useUnsyncedPwm = true;
60 #else
61 motorConfig->minthrottle = 1070;
62 motorConfig->dev.motorPwmRate = BRUSHLESS_MOTORS_PWM_RATE;
63 #ifndef USE_DSHOT
64 motorConfig->dev.motorPwmProtocol = PWM_TYPE_DISABLED;
65 #elif defined(DEFAULT_MOTOR_DSHOT_SPEED)
66 motorConfig->dev.motorPwmProtocol = DEFAULT_MOTOR_DSHOT_SPEED;
67 #else
68 motorConfig->dev.motorPwmProtocol = PWM_TYPE_DSHOT600;
69 #endif // USE_DSHOT
70 #endif // BRUSHED_MOTORS
72 motorConfig->maxthrottle = 2000;
73 motorConfig->mincommand = 1000;
74 motorConfig->digitalIdleOffsetValue = 550;
75 motorConfig->kv = 1960;
77 #ifdef USE_TIMER
78 #ifdef MOTOR1_PIN
79 motorConfig->dev.ioTags[0] = IO_TAG(MOTOR1_PIN);
80 #endif
81 #ifdef MOTOR2_PIN
82 motorConfig->dev.ioTags[1] = IO_TAG(MOTOR2_PIN);
83 #endif
84 #ifdef MOTOR3_PIN
85 motorConfig->dev.ioTags[2] = IO_TAG(MOTOR3_PIN);
86 #endif
87 #ifdef MOTOR4_PIN
88 motorConfig->dev.ioTags[3] = IO_TAG(MOTOR4_PIN);
89 #endif
90 #ifdef MOTOR5_PIN
91 motorConfig->dev.ioTags[4] = IO_TAG(MOTOR5_PIN);
92 #endif
93 #ifdef MOTOR6_PIN
94 motorConfig->dev.ioTags[5] = IO_TAG(MOTOR6_PIN);
95 #endif
96 #ifdef MOTOR7_PIN
97 motorConfig->dev.ioTags[6] = IO_TAG(MOTOR7_PIN);
98 #endif
99 #ifdef MOTOR8_PIN
100 motorConfig->dev.ioTags[7] = IO_TAG(MOTOR8_PIN);
101 #endif
102 #endif
104 motorConfig->motorPoleCount = 14; // Most brushless motors that we use are 14 poles
106 for (int i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
107 motorConfig->dev.motorOutputReordering[i] = i;
110 #ifdef USE_DSHOT_DMAR
111 motorConfig->dev.useBurstDshot = DEFAULT_DSHOT_BURST;
112 #endif
114 #ifdef USE_DSHOT_TELEMETRY
115 motorConfig->dev.useDshotTelemetry = DEFAULT_DSHOT_TELEMETRY;
116 #endif
118 #ifdef USE_DSHOT_BITBANG
119 motorConfig->dev.useDshotBitbang = DEFAULT_DSHOT_BITBANG;
120 motorConfig->dev.useDshotBitbangedTimer = DSHOT_BITBANGED_TIMER_DEFAULT;
121 #endif
124 #endif // USE_MOTOR