Skip to content

Commit

Permalink
drivers: sensors: bmi08x: add initial support for bmi08x
Browse files Browse the repository at this point in the history
This adds support for the bosch bmi085 and bmi088. This also includes
support for data sync mode.

Signed-off-by: Ryan McClelland <[email protected]>
  • Loading branch information
XenuIsWatching authored and MaureenHelm committed Jul 12, 2023
1 parent f977385 commit f1a992c
Show file tree
Hide file tree
Showing 22 changed files with 3,029 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/sensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_subdirectory_ifdef(CONFIG_BMC150_MAGN bmc150_magn)
add_subdirectory_ifdef(CONFIG_BME280 bme280)
add_subdirectory_ifdef(CONFIG_BME680 bme680)
add_subdirectory_ifdef(CONFIG_BMG160 bmg160)
add_subdirectory_ifdef(CONFIG_BMI08X bmi08x)
add_subdirectory_ifdef(CONFIG_BMI160 bmi160)
add_subdirectory_ifdef(CONFIG_BMI270 bmi270)
add_subdirectory_ifdef(CONFIG_BMI323 bmi323)
Expand Down
1 change: 1 addition & 0 deletions drivers/sensor/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ source "drivers/sensor/bmc150_magn/Kconfig"
source "drivers/sensor/bme280/Kconfig"
source "drivers/sensor/bme680/Kconfig"
source "drivers/sensor/bmg160/Kconfig"
source "drivers/sensor/bmi08x/Kconfig"
source "drivers/sensor/bmi160/Kconfig"
source "drivers/sensor/bmi270/Kconfig"
source "drivers/sensor/bmi323/Kconfig"
Expand Down
9 changes: 9 additions & 0 deletions drivers/sensor/bmi08x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_library()

zephyr_library_sources_ifdef(CONFIG_BMI08X bmi08x_accel.c)
zephyr_library_sources_ifdef(CONFIG_BMI08X bmi08x_gyro.c)
zephyr_library_sources_ifdef(CONFIG_BMI08X bmi08x.c)
zephyr_library_sources_ifdef(CONFIG_BMI08X_ACCEL_TRIGGER bmi08x_accel_trigger.c)
zephyr_library_sources_ifdef(CONFIG_BMI08X_GYRO_TRIGGER bmi08x_gyro_trigger.c)
95 changes: 95 additions & 0 deletions drivers/sensor/bmi08x/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Bosch BMI08X inertial measurement configuration options

# Copyright (c) 2022 Meta Platforms, Inc. and its affiliates
# SPDX-License-Identifier: Apache-2.0

menuconfig BMI08X
bool "Bosch BMI08X inertial measurement unit"
default y
depends on DT_HAS_BOSCH_BMI08X_ACCEL_ENABLED || DT_HAS_BOSCH_BMI08X_GYRO_ENABLED
select I2C if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI08X_ACCEL),i2c) \
|| $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI08X_GYRO),i2c)
select SPI if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI08X_ACCEL),spi) \
|| $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI08X_GYRO),spi)
help
Enable Bosch BMI08X inertial measurement unit that provides acceleration
and angular rate measurements.

if BMI08X

choice BMI08X_ACCEL_TRIGGER_MODE
prompt "Accelerometer trigger mode"
default BMI08X_ACCEL_TRIGGER_GLOBAL_THREAD
help
Specify the type of triggering to be used by the driver.

config BMI08X_ACCEL_TRIGGER_NONE
bool "No trigger"

config BMI08X_ACCEL_TRIGGER_GLOBAL_THREAD
bool "Use global thread"
select BMI08X_ACCEL_TRIGGER

config BMI08X_ACCEL_TRIGGER_OWN_THREAD
bool "Use own thread"
select BMI08X_ACCEL_TRIGGER
endchoice

config BMI08X_ACCEL_TRIGGER
bool

config BMI08X_ACCEL_THREAD_PRIORITY
int "Accelerometer own thread priority"
depends on BMI08X_ACCEL_TRIGGER_OWN_THREAD
default 10
help
The priority of the thread used for handling interrupts.

config BMI08X_ACCEL_THREAD_STACK_SIZE
int "Accelerometer own thread stack size"
depends on BMI08X_ACCEL_TRIGGER_OWN_THREAD
default 1536
help
The thread stack size.

choice BMI08X_GYRO_TRIGGER_MODE
prompt "Gyroscope trigger mode"
default BMI08X_GYRO_TRIGGER_NONE
default BMI08X_GYRO_TRIGGER_GLOBAL_THREAD
help
Specify the type of triggering to be used by the driver.

config BMI08X_GYRO_TRIGGER_NONE
bool "No trigger"

config BMI08X_GYRO_TRIGGER_GLOBAL_THREAD
bool "Use global thread"
select BMI08X_GYRO_TRIGGER

config BMI08X_GYRO_TRIGGER_OWN_THREAD
bool "Use own thread"
select BMI08X_GYRO_TRIGGER
endchoice

config BMI08X_GYRO_TRIGGER
bool

config BMI08X_GYRO_THREAD_PRIORITY
int "Own thread priority"
depends on BMI08X_GYRO_TRIGGER_OWN_THREAD
default 10
help
The priority of the thread used for handling interrupts.

config BMI08X_GYRO_THREAD_STACK_SIZE
int "Own thread stack size"
depends on BMI08X_GYRO_TRIGGER_OWN_THREAD
default 1536
help
The thread stack size.

config BMI08X_I2C_WRITE_BURST_SIZE
int "Maximum length of single i2c write"
default 16

endif # BMI08X
74 changes: 74 additions & 0 deletions drivers/sensor/bmi08x/bmi08x.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* Bosch BMI08X inertial measurement unit driver
*
* Copyright (c) 2022 Meta Platforms, Inc. and its affiliates
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include "bmi08x.h"

/*
* Output data rate map with allowed frequencies:
* freq = freq_int + freq_milli / 1000
*
* Since we don't need a finer frequency resolution than milliHz, use uint16_t
* to save some flash.
*/
static const struct {
uint16_t freq_int;
uint16_t freq_milli; /* User should convert to uHz before setting the
* SENSOR_ATTR_SAMPLING_FREQUENCY attribute.
*/
} bmi08x_odr_map[] = {
{0, 0}, {0, 780}, {1, 562}, {3, 120}, {6, 250}, {12, 500}, {25, 0},
{50, 0}, {100, 0}, {200, 0}, {400, 0}, {800, 0}, {1600, 0}, {3200, 0},
};

int bmi08x_freq_to_odr_val(uint16_t freq_int, uint16_t freq_milli)
{
size_t i;

/* An ODR of 0 Hz is not allowed */
if (freq_int == 0U && freq_milli == 0U) {
return -EINVAL;
}

for (i = 0; i < ARRAY_SIZE(bmi08x_odr_map); i++) {
if (freq_int < bmi08x_odr_map[i].freq_int ||
(freq_int == bmi08x_odr_map[i].freq_int &&
freq_milli <= bmi08x_odr_map[i].freq_milli)) {
return i;
}
}

return -EINVAL;
}

int32_t bmi08x_range_to_reg_val(uint16_t range, const struct bmi08x_range *range_map,
uint16_t range_map_size)
{
int i;

for (i = 0; i < range_map_size; i++) {
if (range <= range_map[i].range) {
return range_map[i].reg_val;
}
}

return -EINVAL;
}

int32_t bmi08x_reg_val_to_range(uint8_t reg_val, const struct bmi08x_range *range_map,
uint16_t range_map_size)
{
int i;

for (i = 0; i < range_map_size; i++) {
if (reg_val == range_map[i].reg_val) {
return range_map[i].range;
}
}

return -EINVAL;
}
Loading

0 comments on commit f1a992c

Please sign in to comment.