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 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
)
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
]);
65 bool lsm6dsoGyroRead(gyroDev_t
*gyro
)
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
]);