refactor motor idle, rename dshot_idle_value to motor_idle (#13936)
[betaflight.git] / src / main / sensors / acceleration.h
blobcd2de0f585e13e244f0c9416bec8912d24662747
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 "common/time.h"
24 #include "pg/pg.h"
25 #include "drivers/accgyro/accgyro.h"
26 #include "sensors/sensors.h"
28 // Type of accelerometer used/detected
29 typedef enum {
30 ACC_DEFAULT,
31 ACC_NONE,
32 ACC_ADXL345,
33 ACC_MPU6050,
34 ACC_MMA8452,
35 ACC_BMA280,
36 ACC_LSM303DLHC,
37 ACC_MPU6000,
38 ACC_MPU6500,
39 ACC_MPU9250,
40 ACC_ICM20601,
41 ACC_ICM20602,
42 ACC_ICM20608G,
43 ACC_ICM20649,
44 ACC_ICM20689,
45 ACC_ICM42605,
46 ACC_ICM42688P,
47 ACC_BMI160,
48 ACC_BMI270,
49 ACC_LSM6DSO,
50 ACC_LSM6DSV16X,
51 ACC_VIRTUAL
52 } accelerationSensor_e;
54 typedef struct acc_s {
55 accDev_t dev;
56 uint16_t sampleRateHz;
57 vector3_t accADC;
58 bool isAccelUpdatedAtLeastOnce;
59 float accMagnitude;
60 float accDelta;
61 } acc_t;
63 extern acc_t acc;
65 typedef struct rollAndPitchTrims_s {
66 int16_t roll;
67 int16_t pitch;
68 } rollAndPitchTrims_t_def;
70 typedef union rollAndPitchTrims_u {
71 int16_t raw[2];
72 rollAndPitchTrims_t_def values;
73 } rollAndPitchTrims_t;
75 #if defined(USE_ACC)
76 typedef struct accelerometerConfig_s {
77 uint16_t acc_lpf_hz; // cutoff frequency for the low pass filter used on the acc z-axis for althold in Hz
78 uint8_t acc_hardware; // Which acc hardware to use on boards with more than one device
79 bool acc_high_fsr;
80 flightDynamicsTrims_t accZero;
81 rollAndPitchTrims_t accelerometerTrims;
82 } accelerometerConfig_t;
84 PG_DECLARE(accelerometerConfig_t, accelerometerConfig);
85 #endif
87 bool accInit(uint16_t accSampleRateHz);
88 bool accIsCalibrationComplete(void);
89 bool accHasBeenCalibrated(void);
90 void accStartCalibration(void);
91 void resetRollAndPitchTrims(rollAndPitchTrims_t *rollAndPitchTrims);
92 void accUpdate(timeUs_t currentTimeUs);
93 union flightDynamicsTrims_u;
94 void setAccelerationTrims(union flightDynamicsTrims_u *accelerationTrimsToUse);
95 void accInitFilters(void);
96 void applyAccelerometerTrimsDelta(union rollAndPitchTrims_u *rollAndPitchTrimsDelta);