icm42688: Follow st's devicetree bindings

Fix the devicetree bindings to actually be used as the default
configuration, following the example set by various ST sensor devices.

This requires sadly dropping enums and using #defines for various
options as well as repeating many numbers, but presumably is the way to
do it given the precedent set by ST with sensors like the lsm6dso.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
This commit is contained in:
Tom Burdick 2024-06-13 13:30:01 -05:00 committed by Anas Nashif
commit 058253b4b6
9 changed files with 407 additions and 348 deletions

View file

@ -241,6 +241,8 @@
};
};
#include <zephyr/dt-bindings/sensor/icm42688.h>
&lpspi1 {
status = "okay";
cs-gpios =<&gpio2 11 GPIO_ACTIVE_LOW>;
@ -250,10 +252,12 @@
reg = <0>;
int-gpios = <&gpio3 19 GPIO_ACTIVE_HIGH>;
spi-max-frequency = <24000000>;
accel-hz = <1000>;
accel-fs = <16>;
gyro-hz = <1000>;
gyro-fs = <2000>;
accel-pwr-mode = <ICM42688_DT_ACCEL_LN>;
accel-odr = <ICM42688_DT_ACCEL_ODR_1000>;
accel-fs = <ICM42688_DT_ACCEL_FS_16>;
gyro-pwr-mode = <ICM42688_DT_GYRO_LN>;
gyro-odr = <ICM42688_DT_GYRO_ODR_1000>;
gyro-fs = <ICM42688_DT_GYRO_FS_2000>;
};
};
@ -266,10 +270,12 @@
reg = <0>;
int-gpios = <&gpio2 7 GPIO_ACTIVE_HIGH>;
spi-max-frequency = <24000000>;
accel-hz = <1000>;
accel-fs = <16>;
gyro-hz = <1000>;
gyro-fs = <2000>;
accel-pwr-mode = <ICM42688_DT_ACCEL_LN>;
accel-odr = <ICM42688_DT_ACCEL_ODR_1000>;
accel-fs = <ICM42688_DT_ACCEL_FS_16>;
gyro-pwr-mode = <ICM42688_DT_GYRO_LN>;
gyro-odr = <ICM42688_DT_GYRO_ODR_1000>;
gyro-fs = <ICM42688_DT_GYRO_FS_2000>;
};
};

View file

@ -89,6 +89,8 @@
};
};
#include <zephyr/dt-bindings/sensor/icm42688.h>
&spi0 {
pinctrl-0 = <&spi0_default>;
pinctrl-names = "default";
@ -103,10 +105,12 @@
reg = <0>;
int-gpios = <&pioc 5 GPIO_ACTIVE_HIGH>;
spi-max-frequency = <24000000>;
accel-hz = <32000>;
accel-fs = <16>;
gyro-hz = <32000>;
gyro-fs = <2000>;
accel-pwr-mode = <ICM42688_DT_ACCEL_LN>;
accel-odr = <ICM42688_DT_ACCEL_ODR_2000>;
accel-fs = <ICM42688_DT_ACCEL_FS_16>;
gyro-pwr-mode = <ICM42688_DT_GYRO_LN>;
gyro-odr = <ICM42688_DT_GYRO_ODR_2000>;
gyro-fs = <ICM42688_DT_GYRO_FS_2000>;
};
spi_adc: adc@1 {
compatible = "ti,ads7052";

View file

@ -271,20 +271,6 @@ int icm42688_init(const struct device *dev)
}
#endif
data->cfg.accel_mode = ICM42688_ACCEL_LN;
data->cfg.accel_fs = ICM42688_ACCEL_FS_2G;
data->cfg.accel_odr = ICM42688_ACCEL_ODR_1000;
data->cfg.gyro_mode = ICM42688_GYRO_LN;
data->cfg.gyro_fs = ICM42688_GYRO_FS_125;
data->cfg.gyro_odr = ICM42688_GYRO_ODR_1000;
data->cfg.temp_dis = false;
data->cfg.fifo_en = IS_ENABLED(CONFIG_ICM42688_STREAM);
data->cfg.batch_ticks = 0;
data->cfg.fifo_hires = 0;
data->cfg.interrupt1_drdy = 0;
data->cfg.interrupt1_fifo_ths = 0;
data->cfg.interrupt1_fifo_full = 0;
res = icm42688_configure(dev, &data->cfg);
if (res != 0) {
LOG_ERR("Failed to configure");
@ -313,11 +299,30 @@ void icm42688_unlock(const struct device *dev)
SPI_DT_IODEV_DEFINE(icm42688_spi_iodev_##inst, DT_DRV_INST(inst), ICM42688_SPI_CFG, 0U); \
RTIO_DEFINE(icm42688_rtio_##inst, 8, 4);
#define ICM42688_DT_CONFIG_INIT(inst) \
{ \
.accel_pwr_mode = DT_INST_PROP(inst, accel_pwr_mode), \
.accel_fs = DT_INST_PROP(inst, accel_fs), \
.accel_odr = DT_INST_PROP(inst, accel_odr), \
.gyro_pwr_mode = DT_INST_PROP(inst, gyro_pwr_mode), \
.gyro_fs = DT_INST_PROP(inst, gyro_fs), \
.gyro_odr = DT_INST_PROP(inst, gyro_odr), \
.temp_dis = false, \
.fifo_en = IS_ENABLED(CONFIG_ICM42688_STREAM), \
.batch_ticks = 0, \
.fifo_hires = false, \
.interrupt1_drdy = false, \
.interrupt1_fifo_ths = false, \
.interrupt1_fifo_full = false \
}
#define ICM42688_DEFINE_DATA(inst) \
IF_ENABLED(CONFIG_ICM42688_STREAM, (ICM42688_RTIO_DEFINE(inst))); \
static struct icm42688_dev_data icm42688_driver_##inst = { \
.cfg = ICM42688_DT_CONFIG_INIT(inst), \
IF_ENABLED(CONFIG_ICM42688_STREAM, (.r = &icm42688_rtio_##inst, \
.spi_iodev = &icm42688_spi_iodev_##inst,))};
.spi_iodev = &icm42688_spi_iodev_##inst,)) \
};
#define ICM42688_INIT(inst) \
ICM42688_DEFINE_DATA(inst); \

View file

@ -11,349 +11,269 @@
#include <zephyr/drivers/sensor.h>
#include <zephyr/drivers/spi.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/dt-bindings/sensor/icm42688.h>
#include <stdlib.h>
/**
* @brief Accelerometer power modes
*/
enum icm42688_accel_mode {
ICM42688_ACCEL_OFF,
ICM42688_ACCEL_LP = 2,
ICM42688_ACCEL_LN = 3,
};
/**
* @brief Gyroscope power modes
*/
enum icm42688_gyro_mode {
ICM42688_GYRO_OFF,
ICM42688_GYRO_STANDBY,
ICM42688_GYRO_LN = 3,
};
/**
* @brief Accelerometer scale options
*/
enum icm42688_accel_fs {
ICM42688_ACCEL_FS_16G,
ICM42688_ACCEL_FS_8G,
ICM42688_ACCEL_FS_4G,
ICM42688_ACCEL_FS_2G,
};
static inline enum icm42688_accel_fs icm42688_accel_fs_to_reg(uint8_t g)
static inline uint8_t icm42688_accel_fs_to_reg(uint8_t g)
{
if (g >= 16) {
return ICM42688_ACCEL_FS_16G;
return ICM42688_DT_ACCEL_FS_16;
} else if (g >= 8) {
return ICM42688_ACCEL_FS_8G;
return ICM42688_DT_ACCEL_FS_8;
} else if (g >= 4) {
return ICM42688_ACCEL_FS_4G;
return ICM42688_DT_ACCEL_FS_4;
} else {
return ICM42688_ACCEL_FS_2G;
return ICM42688_DT_ACCEL_FS_2;
}
}
static inline void icm42688_accel_reg_to_fs(enum icm42688_accel_fs fs, struct sensor_value *out)
static inline void icm42688_accel_reg_to_fs(uint8_t fs, struct sensor_value *out)
{
switch (fs) {
case ICM42688_ACCEL_FS_16G:
case ICM42688_DT_ACCEL_FS_16:
sensor_g_to_ms2(16, out);
return;
case ICM42688_ACCEL_FS_8G:
case ICM42688_DT_ACCEL_FS_8:
sensor_g_to_ms2(8, out);
return;
case ICM42688_ACCEL_FS_4G:
case ICM42688_DT_ACCEL_FS_4:
sensor_g_to_ms2(4, out);
return;
case ICM42688_ACCEL_FS_2G:
case ICM42688_DT_ACCEL_FS_2:
sensor_g_to_ms2(2, out);
return;
}
}
/**
* @brief Gyroscope scale options
*/
enum icm42688_gyro_fs {
ICM42688_GYRO_FS_2000,
ICM42688_GYRO_FS_1000,
ICM42688_GYRO_FS_500,
ICM42688_GYRO_FS_250,
ICM42688_GYRO_FS_125,
ICM42688_GYRO_FS_62_5,
ICM42688_GYRO_FS_31_25,
ICM42688_GYRO_FS_15_625,
};
static inline enum icm42688_gyro_fs icm42688_gyro_fs_to_reg(uint16_t dps)
static inline uint8_t icm42688_gyro_fs_to_reg(uint16_t dps)
{
if (dps >= 2000) {
return ICM42688_GYRO_FS_2000;
return ICM42688_DT_GYRO_FS_2000;
} else if (dps >= 1000) {
return ICM42688_GYRO_FS_1000;
return ICM42688_DT_GYRO_FS_1000;
} else if (dps >= 500) {
return ICM42688_GYRO_FS_500;
return ICM42688_DT_GYRO_FS_500;
} else if (dps >= 250) {
return ICM42688_GYRO_FS_250;
return ICM42688_DT_GYRO_FS_250;
} else if (dps >= 125) {
return ICM42688_GYRO_FS_125;
return ICM42688_DT_GYRO_FS_125;
} else if (dps >= 62) {
return ICM42688_GYRO_FS_62_5;
return ICM42688_DT_GYRO_FS_62_5;
} else if (dps >= 31) {
return ICM42688_GYRO_FS_31_25;
return ICM42688_DT_GYRO_FS_31_25;
} else {
return ICM42688_GYRO_FS_15_625;
return ICM42688_DT_GYRO_FS_15_625;
}
}
static inline void icm42688_gyro_reg_to_fs(enum icm42688_gyro_fs fs, struct sensor_value *out)
static inline void icm42688_gyro_reg_to_fs(uint8_t fs, struct sensor_value *out)
{
switch (fs) {
case ICM42688_GYRO_FS_2000:
case ICM42688_DT_GYRO_FS_2000:
sensor_degrees_to_rad(2000, out);
return;
case ICM42688_GYRO_FS_1000:
case ICM42688_DT_GYRO_FS_1000:
sensor_degrees_to_rad(1000, out);
return;
case ICM42688_GYRO_FS_500:
case ICM42688_DT_GYRO_FS_500:
sensor_degrees_to_rad(500, out);
return;
case ICM42688_GYRO_FS_250:
case ICM42688_DT_GYRO_FS_250:
sensor_degrees_to_rad(250, out);
return;
case ICM42688_GYRO_FS_125:
case ICM42688_DT_GYRO_FS_125:
sensor_degrees_to_rad(125, out);
return;
case ICM42688_GYRO_FS_62_5:
case ICM42688_DT_GYRO_FS_62_5:
sensor_10udegrees_to_rad(6250000, out);
return;
case ICM42688_GYRO_FS_31_25:
case ICM42688_DT_GYRO_FS_31_25:
sensor_10udegrees_to_rad(3125000, out);
return;
case ICM42688_GYRO_FS_15_625:
case ICM42688_DT_GYRO_FS_15_625:
sensor_10udegrees_to_rad(1562500, out);
return;
}
}
/**
* @brief Accelerometer data rate options
*/
enum icm42688_accel_odr {
ICM42688_ACCEL_ODR_32000 = 1,
ICM42688_ACCEL_ODR_16000,
ICM42688_ACCEL_ODR_8000,
ICM42688_ACCEL_ODR_4000,
ICM42688_ACCEL_ODR_2000,
ICM42688_ACCEL_ODR_1000,
ICM42688_ACCEL_ODR_200,
ICM42688_ACCEL_ODR_100,
ICM42688_ACCEL_ODR_50,
ICM42688_ACCEL_ODR_25,
ICM42688_ACCEL_ODR_12_5,
ICM42688_ACCEL_ODR_6_25,
ICM42688_ACCEL_ODR_3_125,
ICM42688_ACCEL_ODR_1_5625,
ICM42688_ACCEL_ODR_500,
};
static inline enum icm42688_accel_odr icm42688_accel_hz_to_reg(uint16_t hz)
static inline uint8_t icm42688_accel_hz_to_reg(uint16_t hz)
{
if (hz >= 32000) {
return ICM42688_ACCEL_ODR_32000;
return ICM42688_DT_ACCEL_ODR_32000;
} else if (hz >= 16000) {
return ICM42688_ACCEL_ODR_16000;
return ICM42688_DT_ACCEL_ODR_16000;
} else if (hz >= 8000) {
return ICM42688_ACCEL_ODR_8000;
return ICM42688_DT_ACCEL_ODR_8000;
} else if (hz >= 4000) {
return ICM42688_ACCEL_ODR_4000;
return ICM42688_DT_ACCEL_ODR_4000;
} else if (hz >= 2000) {
return ICM42688_ACCEL_ODR_2000;
return ICM42688_DT_ACCEL_ODR_2000;
} else if (hz >= 1000) {
return ICM42688_ACCEL_ODR_1000;
return ICM42688_DT_ACCEL_ODR_1000;
} else if (hz >= 500) {
return ICM42688_ACCEL_ODR_500;
return ICM42688_DT_ACCEL_ODR_500;
} else if (hz >= 200) {
return ICM42688_ACCEL_ODR_200;
return ICM42688_DT_ACCEL_ODR_200;
} else if (hz >= 100) {
return ICM42688_ACCEL_ODR_100;
return ICM42688_DT_ACCEL_ODR_100;
} else if (hz >= 50) {
return ICM42688_ACCEL_ODR_50;
return ICM42688_DT_ACCEL_ODR_50;
} else if (hz >= 25) {
return ICM42688_ACCEL_ODR_25;
return ICM42688_DT_ACCEL_ODR_25;
} else if (hz >= 12) {
return ICM42688_ACCEL_ODR_12_5;
return ICM42688_DT_ACCEL_ODR_12_5;
} else if (hz >= 6) {
return ICM42688_ACCEL_ODR_6_25;
return ICM42688_DT_ACCEL_ODR_6_25;
} else if (hz >= 3) {
return ICM42688_ACCEL_ODR_3_125;
return ICM42688_DT_ACCEL_ODR_3_125;
} else {
return ICM42688_ACCEL_ODR_1_5625;
return ICM42688_DT_ACCEL_ODR_1_5625;
}
}
static inline void icm42688_accel_reg_to_hz(enum icm42688_accel_odr odr, struct sensor_value *out)
static inline void icm42688_accel_reg_to_hz(uint8_t odr, struct sensor_value *out)
{
switch (odr) {
case ICM42688_ACCEL_ODR_32000:
case ICM42688_DT_ACCEL_ODR_32000:
out->val1 = 32000;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_16000:
case ICM42688_DT_ACCEL_ODR_16000:
out->val1 = 1600;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_8000:
case ICM42688_DT_ACCEL_ODR_8000:
out->val1 = 8000;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_4000:
case ICM42688_DT_ACCEL_ODR_4000:
out->val1 = 4000;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_2000:
case ICM42688_DT_ACCEL_ODR_2000:
out->val1 = 2000;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_1000:
case ICM42688_DT_ACCEL_ODR_1000:
out->val1 = 1000;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_500:
case ICM42688_DT_ACCEL_ODR_500:
out->val1 = 500;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_200:
case ICM42688_DT_ACCEL_ODR_200:
out->val1 = 200;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_100:
case ICM42688_DT_ACCEL_ODR_100:
out->val1 = 100;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_50:
case ICM42688_DT_ACCEL_ODR_50:
out->val1 = 50;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_25:
case ICM42688_DT_ACCEL_ODR_25:
out->val1 = 25;
out->val2 = 0;
return;
case ICM42688_ACCEL_ODR_12_5:
case ICM42688_DT_ACCEL_ODR_12_5:
out->val1 = 12;
out->val2 = 500000;
return;
case ICM42688_ACCEL_ODR_6_25:
case ICM42688_DT_ACCEL_ODR_6_25:
out->val1 = 6;
out->val2 = 250000;
return;
case ICM42688_ACCEL_ODR_3_125:
case ICM42688_DT_ACCEL_ODR_3_125:
out->val1 = 3;
out->val2 = 125000;
return;
case ICM42688_ACCEL_ODR_1_5625:
case ICM42688_DT_ACCEL_ODR_1_5625:
out->val1 = 1;
out->val2 = 562500;
return;
}
}
/**
* @brief Gyroscope data rate options
*/
enum icm42688_gyro_odr {
ICM42688_GYRO_ODR_32000 = 1,
ICM42688_GYRO_ODR_16000,
ICM42688_GYRO_ODR_8000,
ICM42688_GYRO_ODR_4000,
ICM42688_GYRO_ODR_2000,
ICM42688_GYRO_ODR_1000,
ICM42688_GYRO_ODR_200,
ICM42688_GYRO_ODR_100,
ICM42688_GYRO_ODR_50,
ICM42688_GYRO_ODR_25,
ICM42688_GYRO_ODR_12_5,
ICM42688_GYRO_ODR_500 = 0xF
};
static inline enum icm42688_gyro_odr icm42688_gyro_odr_to_reg(uint16_t hz)
static inline uint8_t icm42688_gyro_odr_to_reg(uint16_t hz)
{
if (hz >= 32000) {
return ICM42688_GYRO_ODR_32000;
return ICM42688_DT_GYRO_ODR_32000;
} else if (hz >= 16000) {
return ICM42688_GYRO_ODR_16000;
return ICM42688_DT_GYRO_ODR_16000;
} else if (hz >= 8000) {
return ICM42688_GYRO_ODR_8000;
return ICM42688_DT_GYRO_ODR_8000;
} else if (hz >= 4000) {
return ICM42688_GYRO_ODR_4000;
return ICM42688_DT_GYRO_ODR_4000;
} else if (hz >= 2000) {
return ICM42688_GYRO_ODR_2000;
return ICM42688_DT_GYRO_ODR_2000;
} else if (hz >= 1000) {
return ICM42688_GYRO_ODR_1000;
return ICM42688_DT_GYRO_ODR_1000;
} else if (hz >= 500) {
return ICM42688_GYRO_ODR_500;
return ICM42688_DT_GYRO_ODR_500;
} else if (hz >= 200) {
return ICM42688_GYRO_ODR_200;
return ICM42688_DT_GYRO_ODR_200;
} else if (hz >= 100) {
return ICM42688_GYRO_ODR_100;
return ICM42688_DT_GYRO_ODR_100;
} else if (hz >= 50) {
return ICM42688_GYRO_ODR_50;
return ICM42688_DT_GYRO_ODR_50;
} else if (hz >= 25) {
return ICM42688_GYRO_ODR_25;
return ICM42688_DT_GYRO_ODR_25;
} else {
return ICM42688_GYRO_ODR_12_5;
return ICM42688_DT_GYRO_ODR_12_5;
}
}
static inline void icm42688_gyro_reg_to_odr(enum icm42688_gyro_odr odr, struct sensor_value *out)
static inline void icm42688_gyro_reg_to_odr(uint8_t odr, struct sensor_value *out)
{
switch (odr) {
case ICM42688_GYRO_ODR_32000:
case ICM42688_DT_GYRO_ODR_32000:
out->val1 = 32000;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_16000:
case ICM42688_DT_GYRO_ODR_16000:
out->val1 = 16000;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_8000:
case ICM42688_DT_GYRO_ODR_8000:
out->val1 = 8000;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_4000:
case ICM42688_DT_GYRO_ODR_4000:
out->val1 = 4000;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_2000:
case ICM42688_DT_GYRO_ODR_2000:
out->val1 = 2000;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_1000:
case ICM42688_DT_GYRO_ODR_1000:
out->val1 = 1000;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_500:
case ICM42688_DT_GYRO_ODR_500:
out->val1 = 500;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_200:
case ICM42688_DT_GYRO_ODR_200:
out->val1 = 200;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_100:
case ICM42688_DT_GYRO_ODR_100:
out->val1 = 100;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_50:
case ICM42688_DT_GYRO_ODR_50:
out->val1 = 50;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_25:
case ICM42688_DT_GYRO_ODR_25:
out->val1 = 25;
out->val2 = 0;
return;
case ICM42688_GYRO_ODR_12_5:
case ICM42688_DT_GYRO_ODR_12_5:
out->val1 = 12;
out->val2 = 500000;
return;
@ -364,14 +284,14 @@ static inline void icm42688_gyro_reg_to_odr(enum icm42688_gyro_odr odr, struct s
* @brief All sensor configuration options
*/
struct icm42688_cfg {
enum icm42688_accel_mode accel_mode;
enum icm42688_accel_fs accel_fs;
enum icm42688_accel_odr accel_odr;
uint8_t accel_pwr_mode;
uint8_t accel_fs;
uint8_t accel_odr;
/* TODO accel signal processing options */
enum icm42688_gyro_mode gyro_mode;
enum icm42688_gyro_fs gyro_fs;
enum icm42688_gyro_odr gyro_odr;
uint8_t gyro_pwr_mode;
uint8_t gyro_fs;
uint8_t gyro_odr;
/* TODO gyro signal processing options */
bool temp_dis;
@ -500,16 +420,16 @@ static inline void icm42688_accel_g(struct icm42688_cfg *cfg, int32_t in, int32_
int32_t sensitivity = 0; /* value equivalent for 1g */
switch (cfg->accel_fs) {
case ICM42688_ACCEL_FS_2G:
case ICM42688_DT_ACCEL_FS_2:
sensitivity = 16384;
break;
case ICM42688_ACCEL_FS_4G:
case ICM42688_DT_ACCEL_FS_4:
sensitivity = 8192;
break;
case ICM42688_ACCEL_FS_8G:
case ICM42688_DT_ACCEL_FS_8:
sensitivity = 4096;
break;
case ICM42688_ACCEL_FS_16G:
case ICM42688_DT_ACCEL_FS_16:
sensitivity = 2048;
break;
}
@ -535,28 +455,28 @@ static inline void icm42688_gyro_dps(const struct icm42688_cfg *cfg, int32_t in,
int64_t sensitivity = 0; /* value equivalent for 10x gyro reading deg/s */
switch (cfg->gyro_fs) {
case ICM42688_GYRO_FS_2000:
case ICM42688_DT_GYRO_FS_2000:
sensitivity = 164;
break;
case ICM42688_GYRO_FS_1000:
case ICM42688_DT_GYRO_FS_1000:
sensitivity = 328;
break;
case ICM42688_GYRO_FS_500:
case ICM42688_DT_GYRO_FS_500:
sensitivity = 655;
break;
case ICM42688_GYRO_FS_250:
case ICM42688_DT_GYRO_FS_250:
sensitivity = 1310;
break;
case ICM42688_GYRO_FS_125:
case ICM42688_DT_GYRO_FS_125:
sensitivity = 2620;
break;
case ICM42688_GYRO_FS_62_5:
case ICM42688_DT_GYRO_FS_62_5:
sensitivity = 5243;
break;
case ICM42688_GYRO_FS_31_25:
case ICM42688_DT_GYRO_FS_31_25:
sensitivity = 10486;
break;
case ICM42688_GYRO_FS_15_625:
case ICM42688_DT_GYRO_FS_15_625:
sensitivity = 20972;
break;
}
@ -585,16 +505,16 @@ static inline void icm42688_accel_ms(const struct icm42688_cfg *cfg, int32_t in,
int64_t sensitivity = 0; /* value equivalent for 1g */
switch (cfg->accel_fs) {
case ICM42688_ACCEL_FS_2G:
case ICM42688_DT_ACCEL_FS_2:
sensitivity = 16384;
break;
case ICM42688_ACCEL_FS_4G:
case ICM42688_DT_ACCEL_FS_4:
sensitivity = 8192;
break;
case ICM42688_ACCEL_FS_8G:
case ICM42688_DT_ACCEL_FS_8:
sensitivity = 4096;
break;
case ICM42688_ACCEL_FS_16G:
case ICM42688_DT_ACCEL_FS_16:
sensitivity = 2048;
break;
}
@ -623,28 +543,28 @@ static inline void icm42688_gyro_rads(const struct icm42688_cfg *cfg, int32_t in
int64_t sensitivity = 0; /* value equivalent for 10x gyro reading deg/s */
switch (cfg->gyro_fs) {
case ICM42688_GYRO_FS_2000:
case ICM42688_DT_GYRO_FS_2000:
sensitivity = 164;
break;
case ICM42688_GYRO_FS_1000:
case ICM42688_DT_GYRO_FS_1000:
sensitivity = 328;
break;
case ICM42688_GYRO_FS_500:
case ICM42688_DT_GYRO_FS_500:
sensitivity = 655;
break;
case ICM42688_GYRO_FS_250:
case ICM42688_DT_GYRO_FS_250:
sensitivity = 1310;
break;
case ICM42688_GYRO_FS_125:
case ICM42688_DT_GYRO_FS_125:
sensitivity = 2620;
break;
case ICM42688_GYRO_FS_62_5:
case ICM42688_DT_GYRO_FS_62_5:
sensitivity = 5243;
break;
case ICM42688_GYRO_FS_31_25:
case ICM42688_DT_GYRO_FS_31_25:
sensitivity = 10486;
break;
case ICM42688_GYRO_FS_15_625:
case ICM42688_DT_GYRO_FS_15_625:
sensitivity = 20972;
break;
}

View file

@ -64,8 +64,8 @@ int icm42688_reset(const struct device *dev)
static uint16_t icm42688_compute_fifo_wm(const struct icm42688_cfg *cfg)
{
const bool accel_enabled = cfg->accel_mode != ICM42688_ACCEL_OFF;
const bool gyro_enabled = cfg->gyro_mode != ICM42688_GYRO_OFF;
const bool accel_enabled = cfg->accel_pwr_mode != ICM42688_DT_ACCEL_OFF;
const bool gyro_enabled = cfg->gyro_pwr_mode != ICM42688_DT_GYRO_OFF;
const int pkt_size = cfg->fifo_hires ? 20 : (accel_enabled && gyro_enabled ? 16 : 8);
int accel_modr = 0;
int gyro_modr = 0;
@ -149,8 +149,8 @@ int icm42688_configure(const struct device *dev, struct icm42688_cfg *cfg)
/* TODO maybe do the next few steps intelligently by checking current config */
/* Power management to set gyro/accel modes */
uint8_t pwr_mgmt0 = FIELD_PREP(MASK_GYRO_MODE, cfg->gyro_mode) |
FIELD_PREP(MASK_ACCEL_MODE, cfg->accel_mode) |
uint8_t pwr_mgmt0 = FIELD_PREP(MASK_GYRO_MODE, cfg->gyro_pwr_mode) |
FIELD_PREP(MASK_ACCEL_MODE, cfg->accel_pwr_mode) |
FIELD_PREP(BIT_TEMP_DIS, cfg->temp_dis);
LOG_DBG("PWR_MGMT0 (0x%x) 0x%x", REG_PWR_MGMT0, pwr_mgmt0);
@ -235,8 +235,8 @@ int icm42688_configure(const struct device *dev, struct icm42688_cfg *cfg)
uint8_t int_config1 = 0;
if ((cfg->accel_odr <= ICM42688_ACCEL_ODR_4000 ||
cfg->gyro_odr <= ICM42688_GYRO_ODR_4000)) {
if ((cfg->accel_odr <= ICM42688_DT_ACCEL_ODR_4000 ||
cfg->gyro_odr <= ICM42688_DT_GYRO_ODR_4000)) {
int_config1 = FIELD_PREP(BIT_INT_TPULSE_DURATION, 1) |
FIELD_PREP(BIT_INT_TDEASSERT_DISABLE, 1);
}

View file

@ -22,16 +22,16 @@ static int icm42688_get_shift(enum sensor_channel channel, int accel_fs, int gyr
case SENSOR_CHAN_ACCEL_Y:
case SENSOR_CHAN_ACCEL_Z:
switch (accel_fs) {
case ICM42688_ACCEL_FS_2G:
case ICM42688_DT_ACCEL_FS_2:
*shift = 5;
return 0;
case ICM42688_ACCEL_FS_4G:
case ICM42688_DT_ACCEL_FS_4:
*shift = 6;
return 0;
case ICM42688_ACCEL_FS_8G:
case ICM42688_DT_ACCEL_FS_8:
*shift = 7;
return 0;
case ICM42688_ACCEL_FS_16G:
case ICM42688_DT_ACCEL_FS_16:
*shift = 8;
return 0;
default:
@ -42,28 +42,28 @@ static int icm42688_get_shift(enum sensor_channel channel, int accel_fs, int gyr
case SENSOR_CHAN_GYRO_Y:
case SENSOR_CHAN_GYRO_Z:
switch (gyro_fs) {
case ICM42688_GYRO_FS_15_625:
case ICM42688_DT_GYRO_FS_15_625:
*shift = -1;
return 0;
case ICM42688_GYRO_FS_31_25:
case ICM42688_DT_GYRO_FS_31_25:
*shift = 0;
return 0;
case ICM42688_GYRO_FS_62_5:
case ICM42688_DT_GYRO_FS_62_5:
*shift = 1;
return 0;
case ICM42688_GYRO_FS_125:
case ICM42688_DT_GYRO_FS_125:
*shift = 2;
return 0;
case ICM42688_GYRO_FS_250:
case ICM42688_DT_GYRO_FS_250:
*shift = 3;
return 0;
case ICM42688_GYRO_FS_500:
case ICM42688_DT_GYRO_FS_500:
*shift = 4;
return 0;
case ICM42688_GYRO_FS_1000:
case ICM42688_DT_GYRO_FS_1000:
*shift = 5;
return 0;
case ICM42688_GYRO_FS_2000:
case ICM42688_DT_GYRO_FS_2000:
*shift = 6;
return 0;
default:
@ -241,43 +241,43 @@ static int icm42688_read_imu_from_packet(const uint8_t *pkt, bool is_accel, int
if (is_accel) {
switch (fs) {
case ICM42688_ACCEL_FS_2G:
case ICM42688_DT_ACCEL_FS_2:
scale = INT64_C(2) * BIT(31 - 5) * 9.80665;
break;
case ICM42688_ACCEL_FS_4G:
case ICM42688_DT_ACCEL_FS_4:
scale = INT64_C(4) * BIT(31 - 6) * 9.80665;
break;
case ICM42688_ACCEL_FS_8G:
case ICM42688_DT_ACCEL_FS_8:
scale = INT64_C(8) * BIT(31 - 7) * 9.80665;
break;
case ICM42688_ACCEL_FS_16G:
case ICM42688_DT_ACCEL_FS_16:
scale = INT64_C(16) * BIT(31 - 8) * 9.80665;
break;
}
} else {
switch (fs) {
case ICM42688_GYRO_FS_2000:
case ICM42688_DT_GYRO_FS_2000:
scale = 164;
break;
case ICM42688_GYRO_FS_1000:
case ICM42688_DT_GYRO_FS_1000:
scale = 328;
break;
case ICM42688_GYRO_FS_500:
case ICM42688_DT_GYRO_FS_500:
scale = 655;
break;
case ICM42688_GYRO_FS_250:
case ICM42688_DT_GYRO_FS_250:
scale = 1310;
break;
case ICM42688_GYRO_FS_125:
case ICM42688_DT_GYRO_FS_125:
scale = 2620;
break;
case ICM42688_GYRO_FS_62_5:
case ICM42688_DT_GYRO_FS_62_5:
scale = 5243;
break;
case ICM42688_GYRO_FS_31_25:
case ICM42688_DT_GYRO_FS_31_25:
scale = 10486;
break;
case ICM42688_GYRO_FS_15_625:
case ICM42688_DT_GYRO_FS_15_625:
scale = 20972;
break;
}
@ -313,36 +313,36 @@ static int icm42688_read_imu_from_packet(const uint8_t *pkt, bool is_accel, int
}
static uint32_t accel_period_ns[] = {
[ICM42688_ACCEL_ODR_1_5625] = UINT32_C(10000000000000) / 15625,
[ICM42688_ACCEL_ODR_3_125] = UINT32_C(10000000000000) / 31250,
[ICM42688_ACCEL_ODR_6_25] = UINT32_C(10000000000000) / 62500,
[ICM42688_ACCEL_ODR_12_5] = UINT32_C(10000000000000) / 12500,
[ICM42688_ACCEL_ODR_25] = UINT32_C(1000000000) / 25,
[ICM42688_ACCEL_ODR_50] = UINT32_C(1000000000) / 50,
[ICM42688_ACCEL_ODR_100] = UINT32_C(1000000000) / 100,
[ICM42688_ACCEL_ODR_200] = UINT32_C(1000000000) / 200,
[ICM42688_ACCEL_ODR_500] = UINT32_C(1000000000) / 500,
[ICM42688_ACCEL_ODR_1000] = UINT32_C(1000000),
[ICM42688_ACCEL_ODR_2000] = UINT32_C(1000000) / 2,
[ICM42688_ACCEL_ODR_4000] = UINT32_C(1000000) / 4,
[ICM42688_ACCEL_ODR_8000] = UINT32_C(1000000) / 8,
[ICM42688_ACCEL_ODR_16000] = UINT32_C(1000000) / 16,
[ICM42688_ACCEL_ODR_32000] = UINT32_C(1000000) / 32,
[ICM42688_DT_ACCEL_ODR_1_5625] = UINT32_C(10000000000000) / 15625,
[ICM42688_DT_ACCEL_ODR_3_125] = UINT32_C(10000000000000) / 31250,
[ICM42688_DT_ACCEL_ODR_6_25] = UINT32_C(10000000000000) / 62500,
[ICM42688_DT_ACCEL_ODR_12_5] = UINT32_C(10000000000000) / 12500,
[ICM42688_DT_ACCEL_ODR_25] = UINT32_C(1000000000) / 25,
[ICM42688_DT_ACCEL_ODR_50] = UINT32_C(1000000000) / 50,
[ICM42688_DT_ACCEL_ODR_100] = UINT32_C(1000000000) / 100,
[ICM42688_DT_ACCEL_ODR_200] = UINT32_C(1000000000) / 200,
[ICM42688_DT_ACCEL_ODR_500] = UINT32_C(1000000000) / 500,
[ICM42688_DT_ACCEL_ODR_1000] = UINT32_C(1000000),
[ICM42688_DT_ACCEL_ODR_2000] = UINT32_C(1000000) / 2,
[ICM42688_DT_ACCEL_ODR_4000] = UINT32_C(1000000) / 4,
[ICM42688_DT_ACCEL_ODR_8000] = UINT32_C(1000000) / 8,
[ICM42688_DT_ACCEL_ODR_16000] = UINT32_C(1000000) / 16,
[ICM42688_DT_ACCEL_ODR_32000] = UINT32_C(1000000) / 32,
};
static uint32_t gyro_period_ns[] = {
[ICM42688_GYRO_ODR_12_5] = UINT32_C(10000000000000) / 12500,
[ICM42688_GYRO_ODR_25] = UINT32_C(1000000000) / 25,
[ICM42688_GYRO_ODR_50] = UINT32_C(1000000000) / 50,
[ICM42688_GYRO_ODR_100] = UINT32_C(1000000000) / 100,
[ICM42688_GYRO_ODR_200] = UINT32_C(1000000000) / 200,
[ICM42688_GYRO_ODR_500] = UINT32_C(1000000000) / 500,
[ICM42688_GYRO_ODR_1000] = UINT32_C(1000000),
[ICM42688_GYRO_ODR_2000] = UINT32_C(1000000) / 2,
[ICM42688_GYRO_ODR_4000] = UINT32_C(1000000) / 4,
[ICM42688_GYRO_ODR_8000] = UINT32_C(1000000) / 8,
[ICM42688_GYRO_ODR_16000] = UINT32_C(1000000) / 16,
[ICM42688_GYRO_ODR_32000] = UINT32_C(1000000) / 32,
[ICM42688_DT_GYRO_ODR_12_5] = UINT32_C(10000000000000) / 12500,
[ICM42688_DT_GYRO_ODR_25] = UINT32_C(1000000000) / 25,
[ICM42688_DT_GYRO_ODR_50] = UINT32_C(1000000000) / 50,
[ICM42688_DT_GYRO_ODR_100] = UINT32_C(1000000000) / 100,
[ICM42688_DT_GYRO_ODR_200] = UINT32_C(1000000000) / 200,
[ICM42688_DT_GYRO_ODR_500] = UINT32_C(1000000000) / 500,
[ICM42688_DT_GYRO_ODR_1000] = UINT32_C(1000000),
[ICM42688_DT_GYRO_ODR_2000] = UINT32_C(1000000) / 2,
[ICM42688_DT_GYRO_ODR_4000] = UINT32_C(1000000) / 4,
[ICM42688_DT_GYRO_ODR_8000] = UINT32_C(1000000) / 8,
[ICM42688_DT_GYRO_ODR_16000] = UINT32_C(1000000) / 16,
[ICM42688_DT_GYRO_ODR_32000] = UINT32_C(1000000) / 32,
};
static int icm42688_fifo_decode(const uint8_t *buffer, struct sensor_chan_spec chan_spec,

View file

@ -1,12 +1,28 @@
# Copyright (c) 2022 Intel Corporation
# Copyright (c) 2024 Intel Corporation
# Copyright (c) 2022 Esco Medical ApS
# Copyright (c) 2020 TDK Invensense
# SPDX-License-Identifier: Apache-2.0
description: ICM-42688 motion tracking device
description: |
ICM-42688 motion tracking device
When setting the accel-pm, accel-range, accel-odr, gyro-pm, gyro-range,
gyro-odr properties in a .dts or .dtsi file you may include icm42688.h
and use the macros defined there.
Example:
#include <zephyr/dt-bindings/sensor/icm42688.h>
icm42688: icm42688@0 {
...
accel-pwr-mode = <ICM42688_ACCEL_LN>;
accel-fs = <ICM42688_ACCEL_FS_16G>;
accel-odr = <ICM42688_ACCEL_ODR_2000>;
gyro-pwr-mode= <ICM42688_GYRO_LN>;
gyro-fs = <ICM42688_GYRO_FS_2000>;
gyro-odr = <ICM42688_GYRO_ODR_2000>;
};
compatible: "invensense,icm42688"
include: [sensor-device.yaml, spi-device.yaml]
properties:
@ -17,80 +33,95 @@ properties:
property value should ensure the flags properly describe the
signal that is presented to the driver.
accel-hz:
accel-pwr-mode:
type: int
default: 0
description: |
Default frequency of accelerometer. (Unit - Hz)
Maps to ACCEL_ODR field in ACCEL_CONFIG0 setting
Power-on reset value is 1000.
default: 1000
Specify the default accelerometer power mode.
Default is power-up configuration.
enum:
- 1
- 3
- 6
- 12
- 25
- 50
- 100
- 200
- 500
- 1000
- 2000
- 4000
- 8000
- 16000
- 32000
- 0 # ICM42688_DT_ACCEL_OFF
- 2 # ICM42688_DT_ACCEL_LP
- 3 # ICM42688_DT_ACCEL_LN
gyro-hz:
accel-odr:
type: int
default: 6
description: |
Default frequency of gyroscope. (Unit - Hz)
Maps to GYRO_ODR field in GYRO_CONFIG0 setting
Power-on reset value is 1000.
default: 1000
Specify the default accelerometer output data rate expressed in samples per second (Hz).
Default is power-up configuration.
enum:
- 1
- 3
- 6
- 12
- 25
- 50
- 100
- 200
- 500
- 1000
- 2000
- 4000
- 8000
- 16000
- 32000
- 1 # ICM42688_DT_ACCEL_ODR_32000
- 2 # ICM42688_DT_ACCEL_ODR_16000
- 3 # ICM42688_DT_ACCEL_ODR_8000
- 4 # ICM42688_DT_ACCEL_ODR_4000
- 5 # ICM42688_DT_ACCEL_ODR_2000
- 6 # ICM42688_DT_ACCEL_ODR_1000
- 7 # ICM42688_DT_ACCEL_ODR_200
- 8 # ICM42688_DT_ACCEL_ODR_100
- 9 # ICM42688_DT_ACCEL_ODR_50
- 10 # ICM42688_DT_ACCEL_ODR_25
- 11 # ICM42688_DT_ACCEL_ODR_12_5
- 12 # ICM42688_DT_ACCEL_ODR_6_25
- 13 # ICM42688_DT_ACCEL_ODR_3_125
- 14 # ICM42688_DT_ACCEL_ODR_1_5625
- 15 # ICM42688_DT_ACCEL_ODR_500
accel-fs:
type: int
default: 0
description: |
Default full scale of accelerometer. (Unit - g)
Maps to ACCEL_FS_SEL field in ACCEL_CONFIG0 setting
Power-on reset value is 16
default: 16
Specify the accelerometer range in g.
Default is power-up configuration.
enum:
- 16
- 8
- 4
- 2
- 0 # ICM42688_DT_ACCEL_FS_16G
- 1 # ICM42688_DT_ACCEL_FS_8G
- 2 # ICM42688_DT_ACCEL_FS_4G
- 3 # ICM42688_DT_ACCEL_FS_2G
gyro-pwr-mode:
type: int
default: 0
description: |
Specify the default gyro power mode.
Default is power-up configuration.
enum:
- 0 # ICM42688_DT_GYRO_OFF
- 1 # ICM42688_DT_GYRO_STANDBY
- 3 # ICM42688_DT_GYRO_LN
gyro-odr:
type: int
default: 6
description: |
Specify the default gyro output data rate expressed in samples per second (Hz).
Default is power-up configuration.
enum:
- 1 # ICM42688_DT_GYRO_ODR_32000
- 2 # ICM42688_DT_GYRO_ODR_16000
- 3 # ICM42688_DT_GYRO_ODR_8000
- 4 # ICM42688_DT_GYRO_ODR_4000
- 5 # ICM42688_DT_GYRO_ODR_2000
- 6 # ICM42688_DT_GYRO_ODR_1000
- 7 # ICM42688_DT_GYRO_ODR_200
- 8 # ICM42688_DT_GYRO_ODR_100
- 9 # ICM42688_DT_GYRO_ODR_50
- 10 # ICM42688_DT_GYRO_ODR_25
- 11 # ICM42688_DT_GYRO_ODR_12_5
- 15 # ICM42688_DT_GYRO_ODR_500
gyro-fs:
type: int
default: 0
description: |
Default full scale of gyroscope. (Unit - DPS)
Maps to GYRO_FS_SEL field in GYRO_CONFIG0 setting
Power-on reset value is 2000
default: 2000
Specify the gyro range in degrees per second.
Default is power-up configuration.
enum:
- 2000
- 1000
- 500
- 250
- 125
- 63
- 31
- 16
- 0 # ICM42688_DT_GYRO_FS_2000
- 1 # ICM42688_DT_GYRO_FS_1000
- 2 # ICM42688_DT_GYRO_FS_500
- 3 # ICM42688_DT_GYRO_FS_250
- 4 # ICM42688_DT_GYRO_FS_125
- 5 # ICM42688_DT_GYRO_FS_62_5
- 6 # ICM42688_DT_GYRO_FS_31_25
- 7 # ICM42688_DT_GYRO_FS_15_625

View file

@ -0,0 +1,97 @@
/*
* Copyright (c) 2024 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_TDK_ICM42688P_H_
#define ZEPHYR_INCLUDE_DT_BINDINGS_TDK_ICM42688P_H_
/**
* @defgroup ICM42688 Invensense (TDK) ICM42688 DT Options
* @{
*/
/**
* @defgroup ICM42688_ACCEL_POWER_MODES Accelerometer power modes
* @{
*/
#define ICM42688_DT_ACCEL_OFF 0
#define ICM42688_DT_ACCEL_LP 2
#define ICM42688_DT_ACCEL_LN 3
/** @} */
/**
* @defgroup ICM42688_GYRO_POWER_MODES Gyroscope power modes
* @{
*/
#define ICM42688_DT_GYRO_OFF 0
#define ICM42688_DT_GYRO_STANDBY 1
#define ICM42688_DT_GYRO_LN 3
/** @} */
/**
* @defgroup ICM42688_ACCEL_SCALE Accelerometer scale options
* @{
*/
#define ICM42688_DT_ACCEL_FS_16 0
#define ICM42688_DT_ACCEL_FS_8 1
#define ICM42688_DT_ACCEL_FS_4 2
#define ICM42688_DT_ACCEL_FS_2 3
/** @} */
/**
* @defgroup ICM42688_GYRO_SCALE Gyroscope scale options
* @{
*/
#define ICM42688_DT_GYRO_FS_2000 0
#define ICM42688_DT_GYRO_FS_1000 1
#define ICM42688_DT_GYRO_FS_500 2
#define ICM42688_DT_GYRO_FS_250 3
#define ICM42688_DT_GYRO_FS_125 4
#define ICM42688_DT_GYRO_FS_62_5 5
#define ICM42688_DT_GYRO_FS_31_25 6
#define ICM42688_DT_GYRO_FS_15_625 7
/** @} */
/**
* @defgroup ICM42688_ACCEL_DATA_RATE Accelerometer data rate options
* @{
*/
#define ICM42688_DT_ACCEL_ODR_32000 1
#define ICM42688_DT_ACCEL_ODR_16000 2
#define ICM42688_DT_ACCEL_ODR_8000 3
#define ICM42688_DT_ACCEL_ODR_4000 4
#define ICM42688_DT_ACCEL_ODR_2000 5
#define ICM42688_DT_ACCEL_ODR_1000 6
#define ICM42688_DT_ACCEL_ODR_200 7
#define ICM42688_DT_ACCEL_ODR_100 8
#define ICM42688_DT_ACCEL_ODR_50 9
#define ICM42688_DT_ACCEL_ODR_25 10
#define ICM42688_DT_ACCEL_ODR_12_5 11
#define ICM42688_DT_ACCEL_ODR_6_25 12
#define ICM42688_DT_ACCEL_ODR_3_125 13
#define ICM42688_DT_ACCEL_ODR_1_5625 14
#define ICM42688_DT_ACCEL_ODR_500 15
/** @} */
/**
* @defgroup ICM42688_GYRO_DATA_RATE Gyroscope data rate options
* @{
*/
#define ICM42688_DT_GYRO_ODR_32000 1
#define ICM42688_DT_GYRO_ODR_16000 2
#define ICM42688_DT_GYRO_ODR_8000 3
#define ICM42688_DT_GYRO_ODR_4000 4
#define ICM42688_DT_GYRO_ODR_2000 5
#define ICM42688_DT_GYRO_ODR_1000 6
#define ICM42688_DT_GYRO_ODR_200 7
#define ICM42688_DT_GYRO_ODR_100 8
#define ICM42688_DT_GYRO_ODR_50 9
#define ICM42688_DT_GYRO_ODR_25 10
#define ICM42688_DT_GYRO_ODR_12_5 11
#define ICM42688_DT_GYRO_ODR_500 15
/** @} */
/** @} */
#endif /*ZEPHYR_INCLUDE_DT_BINDINGS_TDK_ICM42688P_H_ */

View file

@ -199,10 +199,6 @@ test_spi_icm426888: icm42688@1a {
compatible = "invensense,icm42688";
reg = <0x1a>;
spi-max-frequency = <24000000>;
accel-hz = <32000>;
accel-fs = <16>;
gyro-hz = <32000>;
gyro-fs = <2000>;
};
test_spi_max31855: max31855@1b {