[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / drivers / accgyro / accgyro_spi_lsm6dso.c
blob0bfdbc09b93cb858844bfb6cd03805c051711f1d
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 #include <stdbool.h>
22 #include <stdint.h>
24 #include "platform.h"
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 void lsm6dsoExtiHandler(extiCallbackRec_t *cb)
37 gyroDev_t *gyro = container_of(cb, gyroDev_t, exti);
38 gyro->dataReady = true;
41 bool lsm6dsoAccRead(accDev_t *acc)
43 enum {
44 IDX_ACCEL_XOUT_L,
45 IDX_ACCEL_XOUT_H,
46 IDX_ACCEL_YOUT_L,
47 IDX_ACCEL_YOUT_H,
48 IDX_ACCEL_ZOUT_L,
49 IDX_ACCEL_ZOUT_H,
50 BUFFER_SIZE,
53 uint8_t lsm6dso_rx_buf[BUFFER_SIZE];
55 extDevice_t *dev = &acc->gyro->dev;
56 busReadRegisterBuffer(dev, LSM6DSO_REG_OUTX_L_A, lsm6dso_rx_buf, BUFFER_SIZE);
58 acc->ADCRaw[X] = (int16_t)((lsm6dso_rx_buf[IDX_ACCEL_XOUT_H] << 8) | lsm6dso_rx_buf[IDX_ACCEL_XOUT_L]);
59 acc->ADCRaw[Y] = (int16_t)((lsm6dso_rx_buf[IDX_ACCEL_YOUT_H] << 8) | lsm6dso_rx_buf[IDX_ACCEL_YOUT_L]);
60 acc->ADCRaw[Z] = (int16_t)((lsm6dso_rx_buf[IDX_ACCEL_ZOUT_H] << 8) | lsm6dso_rx_buf[IDX_ACCEL_ZOUT_L]);
62 return true;
65 bool lsm6dsoGyroRead(gyroDev_t *gyro)
67 enum {
68 IDX_GYRO_XOUT_L,
69 IDX_GYRO_XOUT_H,
70 IDX_GYRO_YOUT_L,
71 IDX_GYRO_YOUT_H,
72 IDX_GYRO_ZOUT_L,
73 IDX_GYRO_ZOUT_H,
74 BUFFER_SIZE,
77 uint8_t lsm6dso_rx_buf[BUFFER_SIZE];
79 extDevice_t *dev = &gyro->dev;
80 busReadRegisterBuffer(dev, LSM6DSO_REG_OUTX_L_G, lsm6dso_rx_buf, BUFFER_SIZE);
82 gyro->gyroADCRaw[X] = (int16_t)((lsm6dso_rx_buf[IDX_GYRO_XOUT_H] << 8) | lsm6dso_rx_buf[IDX_GYRO_XOUT_L]);
83 gyro->gyroADCRaw[Y] = (int16_t)((lsm6dso_rx_buf[IDX_GYRO_YOUT_H] << 8) | lsm6dso_rx_buf[IDX_GYRO_YOUT_L]);
84 gyro->gyroADCRaw[Z] = (int16_t)((lsm6dso_rx_buf[IDX_GYRO_ZOUT_H] << 8) | lsm6dso_rx_buf[IDX_GYRO_ZOUT_L]);
86 return true;
88 #endif