forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: sensors: bmi08x: add initial support for bmi08x
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
1 parent
f977385
commit f1a992c
Showing
22 changed files
with
3,029 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.