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/>.
26 #ifdef USE_ACCGYRO_LSM6DSO
28 #include "drivers/accgyro/accgyro.h"
29 #include "drivers/accgyro/accgyro_spi_lsm6dso.h"
30 #include "drivers/bus_spi.h"
31 #include "drivers/exti.h"
32 #include "drivers/io.h"
33 #include "drivers/io_impl.h"
35 #if defined(USE_GYRO_EXTI) && defined(USE_MPU_DATA_READY_SIGNAL)
36 void lsm6dsoExtiHandler(extiCallbackRec_t
*cb
)
38 gyroDev_t
*gyro
= container_of(cb
, gyroDev_t
, exti
);
39 gyro
->dataReady
= true;
43 bool lsm6dsoAccRead(accDev_t
*acc
)
55 uint8_t lsm6dso_rx_buf
[BUFFER_SIZE
];
57 extDevice_t
*dev
= &acc
->gyro
->dev
;
58 busReadRegisterBuffer(dev
, LSM6DSO_REG_OUTX_L_A
, lsm6dso_rx_buf
, BUFFER_SIZE
);
60 acc
->ADCRaw
[X
] = (int16_t)((lsm6dso_rx_buf
[IDX_ACCEL_XOUT_H
] << 8) | lsm6dso_rx_buf
[IDX_ACCEL_XOUT_L
]);
61 acc
->ADCRaw
[Y
] = (int16_t)((lsm6dso_rx_buf
[IDX_ACCEL_YOUT_H
] << 8) | lsm6dso_rx_buf
[IDX_ACCEL_YOUT_L
]);
62 acc
->ADCRaw
[Z
] = (int16_t)((lsm6dso_rx_buf
[IDX_ACCEL_ZOUT_H
] << 8) | lsm6dso_rx_buf
[IDX_ACCEL_ZOUT_L
]);
67 bool lsm6dsoGyroRead(gyroDev_t
*gyro
)
79 uint8_t lsm6dso_rx_buf
[BUFFER_SIZE
];
81 extDevice_t
*dev
= &gyro
->dev
;
82 busReadRegisterBuffer(dev
, LSM6DSO_REG_OUTX_L_G
, lsm6dso_rx_buf
, BUFFER_SIZE
);
84 gyro
->gyroADCRaw
[X
] = (int16_t)((lsm6dso_rx_buf
[IDX_GYRO_XOUT_H
] << 8) | lsm6dso_rx_buf
[IDX_GYRO_XOUT_L
]);
85 gyro
->gyroADCRaw
[Y
] = (int16_t)((lsm6dso_rx_buf
[IDX_GYRO_YOUT_H
] << 8) | lsm6dso_rx_buf
[IDX_GYRO_YOUT_L
]);
86 gyro
->gyroADCRaw
[Z
] = (int16_t)((lsm6dso_rx_buf
[IDX_GYRO_ZOUT_H
] << 8) | lsm6dso_rx_buf
[IDX_GYRO_ZOUT_L
]);