Skip to content

Commit

Permalink
Add Bosch BMI088 gyro/acc driver (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
NightHawk32 authored Dec 27, 2024
1 parent cdda4bc commit c06de51
Show file tree
Hide file tree
Showing 20 changed files with 520 additions and 10 deletions.
1 change: 1 addition & 0 deletions make/source.mk
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
drivers/accgyro/accgyro_mpu3050.c \
drivers/accgyro/accgyro_spi_bmi160.c \
drivers/accgyro/accgyro_spi_bmi270.c \
drivers/accgyro/accgyro_spi_bmi088.c \
drivers/accgyro/accgyro_spi_lsm6dso.c \
drivers/accgyro_legacy/accgyro_adxl345.c \
drivers/accgyro_legacy/accgyro_bma280.c \
Expand Down
1 change: 1 addition & 0 deletions src/main/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -5097,6 +5097,7 @@ const cliResourceValue_t resourceTable[] = {
#endif
DEFW( OWNER_GYRO_EXTI, PG_GYRO_DEVICE_CONFIG, gyroDeviceConfig_t, extiTag, MAX_GYRODEV_COUNT ),
DEFW( OWNER_GYRO_CS, PG_GYRO_DEVICE_CONFIG, gyroDeviceConfig_t, csnTag, MAX_GYRODEV_COUNT ),
DEFW( OWNER_ACC_CS, PG_GYRO_DEVICE_CONFIG, gyroDeviceConfig_t, csnAccTag, MAX_GYRODEV_COUNT),
#ifdef USE_USB_DETECT
DEFS( OWNER_USB_DETECT, PG_USB_CONFIG, usbDev_t, detectPin ),
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/main/cli/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@
const char * const lookupTableAccHardware[] = {
"AUTO", "NONE", "ADXL345", "MPU6050", "MMA8452", "BMA280", "LSM303DLHC",
"MPU6000", "MPU6500", "MPU9250", "ICM20601", "ICM20602", "ICM20608G", "ICM20649", "ICM20689", "ICM42605", "ICM42688P",
"BMI160", "BMI270", "LSM6DSO", "FAKE"
"BMI160", "BMI270", "LSM6DSO", "BMI088", "FAKE"
};

// sync with gyroHardware_e
const char * const lookupTableGyroHardware[] = {
"AUTO", "NONE", "MPU6050", "L3G4200D", "MPU3050", "L3GD20",
"MPU6000", "MPU6500", "MPU9250", "ICM20601", "ICM20602", "ICM20608G", "ICM20649", "ICM20689", "ICM42605", "ICM42688P",
"BMI160", "BMI270", "LSM6SDO", "FAKE"
"BMI160", "BMI270", "LSM6SDO", "BMI088", "FAKE"
};

#if defined(USE_SENSOR_NAMES) || defined(USE_BARO)
Expand Down
4 changes: 4 additions & 0 deletions src/main/drivers/accgyro/accgyro.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef enum {
GYRO_BMI160,
GYRO_BMI270,
GYRO_LSM6DSO,
GYRO_BMI088,
GYRO_FAKE
} gyroHardware_e;

Expand All @@ -75,6 +76,7 @@ typedef enum {
typedef enum {
GYRO_RATE_1_kHz,
GYRO_RATE_1100_Hz,
GYRO_RATE_2000_Hz,
GYRO_RATE_3200_Hz,
GYRO_RATE_6400_Hz,
GYRO_RATE_6664_Hz,
Expand All @@ -99,6 +101,7 @@ typedef struct gyroDev_s {
sensorGyroReadDataFuncPtr temperatureFn; // read temperature if available
extiCallbackRec_t exti;
extDevice_t dev;
IO_t csnAccPin;
float scale; // scalefactor
float gyroZero[XYZ_AXIS_COUNT];
float gyroADC[XYZ_AXIS_COUNT]; // gyro data after calibration and alignment
Expand Down Expand Up @@ -143,6 +146,7 @@ typedef struct accDev_s {
sensor_align_e accAlign;
bool dataReady;
gyroDev_t *gyro;
extDevice_t dev;
bool acc_high_fsr;
char revisionCode; // a revision code for the sensor, if known
uint8_t filler[2];
Expand Down
15 changes: 15 additions & 0 deletions src/main/drivers/accgyro/accgyro_mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "drivers/accgyro/accgyro_mpu6500.h"
#include "drivers/accgyro/accgyro_spi_bmi160.h"
#include "drivers/accgyro/accgyro_spi_bmi270.h"
#include "drivers/accgyro/accgyro_spi_bmi088.h"
#include "drivers/accgyro/accgyro_spi_icm20649.h"
#include "drivers/accgyro/accgyro_spi_icm20689.h"
#include "drivers/accgyro/accgyro_spi_icm426xx.h"
Expand Down Expand Up @@ -360,6 +361,9 @@ static gyroSpiDetectFn_t gyroSpiDetectFnTable[] = {
#ifdef USE_ACCGYRO_BMI270
bmi270Detect,
#endif
#ifdef USE_ACCGYRO_SPI_BMI088
bmi088SpiDetect,
#endif
#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P)
icm426xxSpiDetect,
#endif
Expand All @@ -384,6 +388,14 @@ static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro, const gyro
IOConfigGPIO(gyro->dev.busType_u.spi.csnPin, SPI_IO_CS_CFG);
IOHi(gyro->dev.busType_u.spi.csnPin); // Ensure device is disabled, important when two devices are on the same bus.

// for BMI088 which has two CS pins
if(config->csnAccTag) {
gyro->csnAccPin = IOGetByTag(config->csnAccTag);
IOInit(gyro->csnAccPin, OWNER_ACC_CS, RESOURCE_INDEX(config->index));
IOConfigGPIO(gyro->csnAccPin, SPI_IO_CS_CFG);
IOHi(gyro->csnAccPin); // Ensure device is disabled, important when two devices are on the same bus.
}

uint8_t sensor = MPU_NONE;

// Allow 100ms before attempting to access gyro's SPI bus
Expand All @@ -409,6 +421,9 @@ static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro, const gyro
// Detection failed, disable CS pin again

spiPreinitByTag(config->csnTag);
if(config->csnAccTag) {
spiPreinitByTag(config->csnAccTag);
}

return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/drivers/accgyro/accgyro_mpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ typedef enum {
BMI_270_SPI,
LSM6DSO_SPI,
L3GD20_SPI,
BMI_088_SPI
} mpuSensor_e;

typedef enum {
Expand Down
Loading

0 comments on commit c06de51

Please sign in to comment.