drivers/sensor: ism330dhcx: Move accel/gyro range Kconfig attr into DT
Converts ism330dhcx accel and gyro range attributes from Kconfigs to Device Tree binding properties. Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
a6795f5f9b
commit
404ab86cb5
4 changed files with 48 additions and 88 deletions
|
@ -102,20 +102,6 @@ endif # ISM330DHCX_SENSORHUB
|
||||||
|
|
||||||
menu "Attributes"
|
menu "Attributes"
|
||||||
|
|
||||||
config ISM330DHCX_GYRO_FS
|
|
||||||
int "Gyroscope full-scale range"
|
|
||||||
default 0
|
|
||||||
help
|
|
||||||
Specify the default gyroscope full-scale range.
|
|
||||||
An X value for the config represents a range of +/- X degree per
|
|
||||||
second. Valid values are:
|
|
||||||
0: Full Scale selected at runtime
|
|
||||||
125: +/- 125dps
|
|
||||||
250: +/- 250dps
|
|
||||||
500: +/- 500dps
|
|
||||||
1000: +/- 1000dps
|
|
||||||
2000: +/- 2000dps
|
|
||||||
|
|
||||||
config ISM330DHCX_GYRO_ODR
|
config ISM330DHCX_GYRO_ODR
|
||||||
int "Gyroscope Output data rate frequency"
|
int "Gyroscope Output data rate frequency"
|
||||||
range 0 10
|
range 0 10
|
||||||
|
@ -135,19 +121,6 @@ config ISM330DHCX_GYRO_ODR
|
||||||
9: 3330Hz
|
9: 3330Hz
|
||||||
10: 6660Hz
|
10: 6660Hz
|
||||||
|
|
||||||
config ISM330DHCX_ACCEL_FS
|
|
||||||
int "Accelerometer full-scale range"
|
|
||||||
default 0
|
|
||||||
help
|
|
||||||
Specify the default accelerometer full-scale range.
|
|
||||||
An X value for the config represents a range of +/- X G. Valid values
|
|
||||||
are:
|
|
||||||
0: Full Scale selected at runtime
|
|
||||||
2: +/- 2g
|
|
||||||
4: +/- 4g
|
|
||||||
8: +/- 8g
|
|
||||||
16: +/- 16g
|
|
||||||
|
|
||||||
config ISM330DHCX_ACCEL_ODR
|
config ISM330DHCX_ACCEL_ODR
|
||||||
int "Accelerometer Output data rate frequency"
|
int "Accelerometer Output data rate frequency"
|
||||||
range 0 10
|
range 0 10
|
||||||
|
|
|
@ -52,7 +52,6 @@ static int ism330dhcx_odr_to_freq_val(uint16_t odr)
|
||||||
return ism330dhcx_odr_map[ARRAY_SIZE(ism330dhcx_odr_map) - 1];
|
return ism330dhcx_odr_map[ARRAY_SIZE(ism330dhcx_odr_map) - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ISM330DHCX_ACCEL_FS_RUNTIME
|
|
||||||
static const uint16_t ism330dhcx_accel_fs_map[] = {2, 16, 4, 8};
|
static const uint16_t ism330dhcx_accel_fs_map[] = {2, 16, 4, 8};
|
||||||
static const uint16_t ism330dhcx_accel_fs_sens[] = {1, 8, 2, 4};
|
static const uint16_t ism330dhcx_accel_fs_sens[] = {1, 8, 2, 4};
|
||||||
|
|
||||||
|
@ -68,9 +67,7 @@ static int ism330dhcx_accel_range_to_fs_val(int32_t range)
|
||||||
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ISM330DHCX_GYRO_FS_RUNTIME
|
|
||||||
static const uint16_t ism330dhcx_gyro_fs_map[] = {250, 500, 1000, 2000, 125};
|
static const uint16_t ism330dhcx_gyro_fs_map[] = {250, 500, 1000, 2000, 125};
|
||||||
static const uint16_t ism330dhcx_gyro_fs_sens[] = {2, 4, 8, 16, 1};
|
static const uint16_t ism330dhcx_gyro_fs_sens[] = {2, 4, 8, 16, 1};
|
||||||
|
|
||||||
|
@ -86,7 +83,6 @@ static int ism330dhcx_gyro_range_to_fs_val(int32_t range)
|
||||||
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int ism330dhcx_reboot(const struct device *dev)
|
static inline int ism330dhcx_reboot(const struct device *dev)
|
||||||
{
|
{
|
||||||
|
@ -169,7 +165,6 @@ static int ism330dhcx_accel_odr_set(const struct device *dev, uint16_t freq)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ISM330DHCX_ACCEL_FS_RUNTIME
|
|
||||||
static int ism330dhcx_accel_range_set(const struct device *dev, int32_t range)
|
static int ism330dhcx_accel_range_set(const struct device *dev, int32_t range)
|
||||||
{
|
{
|
||||||
int fs;
|
int fs;
|
||||||
|
@ -188,7 +183,6 @@ static int ism330dhcx_accel_range_set(const struct device *dev, int32_t range)
|
||||||
data->acc_gain = (ism330dhcx_accel_fs_sens[fs] * GAIN_UNIT_XL);
|
data->acc_gain = (ism330dhcx_accel_fs_sens[fs] * GAIN_UNIT_XL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static int ism330dhcx_accel_config(const struct device *dev,
|
static int ism330dhcx_accel_config(const struct device *dev,
|
||||||
enum sensor_channel chan,
|
enum sensor_channel chan,
|
||||||
|
@ -196,10 +190,8 @@ static int ism330dhcx_accel_config(const struct device *dev,
|
||||||
const struct sensor_value *val)
|
const struct sensor_value *val)
|
||||||
{
|
{
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
#ifdef ISM330DHCX_ACCEL_FS_RUNTIME
|
|
||||||
case SENSOR_ATTR_FULL_SCALE:
|
case SENSOR_ATTR_FULL_SCALE:
|
||||||
return ism330dhcx_accel_range_set(dev, sensor_ms2_to_g(val));
|
return ism330dhcx_accel_range_set(dev, sensor_ms2_to_g(val));
|
||||||
#endif
|
|
||||||
#ifdef ISM330DHCX_ACCEL_ODR_RUNTIME
|
#ifdef ISM330DHCX_ACCEL_ODR_RUNTIME
|
||||||
case SENSOR_ATTR_SAMPLING_FREQUENCY:
|
case SENSOR_ATTR_SAMPLING_FREQUENCY:
|
||||||
return ism330dhcx_accel_odr_set(dev, val->val1);
|
return ism330dhcx_accel_odr_set(dev, val->val1);
|
||||||
|
@ -231,7 +223,6 @@ static int ism330dhcx_gyro_odr_set(const struct device *dev, uint16_t freq)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ISM330DHCX_GYRO_FS_RUNTIME
|
|
||||||
static int ism330dhcx_gyro_range_set(const struct device *dev, int32_t range)
|
static int ism330dhcx_gyro_range_set(const struct device *dev, int32_t range)
|
||||||
{
|
{
|
||||||
int fs;
|
int fs;
|
||||||
|
@ -250,7 +241,6 @@ static int ism330dhcx_gyro_range_set(const struct device *dev, int32_t range)
|
||||||
data->gyro_gain = (ism330dhcx_gyro_fs_sens[fs] * GAIN_UNIT_G);
|
data->gyro_gain = (ism330dhcx_gyro_fs_sens[fs] * GAIN_UNIT_G);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static int ism330dhcx_gyro_config(const struct device *dev,
|
static int ism330dhcx_gyro_config(const struct device *dev,
|
||||||
enum sensor_channel chan,
|
enum sensor_channel chan,
|
||||||
|
@ -258,10 +248,8 @@ static int ism330dhcx_gyro_config(const struct device *dev,
|
||||||
const struct sensor_value *val)
|
const struct sensor_value *val)
|
||||||
{
|
{
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
#ifdef ISM330DHCX_GYRO_FS_RUNTIME
|
|
||||||
case SENSOR_ATTR_FULL_SCALE:
|
case SENSOR_ATTR_FULL_SCALE:
|
||||||
return ism330dhcx_gyro_range_set(dev, sensor_rad_to_degrees(val));
|
return ism330dhcx_gyro_range_set(dev, sensor_rad_to_degrees(val));
|
||||||
#endif
|
|
||||||
#ifdef ISM330DHCX_GYRO_ODR_RUNTIME
|
#ifdef ISM330DHCX_GYRO_ODR_RUNTIME
|
||||||
case SENSOR_ATTR_SAMPLING_FREQUENCY:
|
case SENSOR_ATTR_SAMPLING_FREQUENCY:
|
||||||
return ism330dhcx_gyro_odr_set(dev, val->val1);
|
return ism330dhcx_gyro_odr_set(dev, val->val1);
|
||||||
|
@ -490,8 +478,7 @@ static int ism330dhcx_gyro_channel_get(enum sensor_channel chan,
|
||||||
struct sensor_value *val,
|
struct sensor_value *val,
|
||||||
struct ism330dhcx_data *data)
|
struct ism330dhcx_data *data)
|
||||||
{
|
{
|
||||||
return ism330dhcx_gyro_get_channel(chan, val, data,
|
return ism330dhcx_gyro_get_channel(chan, val, data, data->gyro_gain);
|
||||||
ISM330DHCX_DEFAULT_GYRO_SENSITIVITY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_ISM330DHCX_ENABLE_TEMP)
|
#if defined(CONFIG_ISM330DHCX_ENABLE_TEMP)
|
||||||
|
@ -691,6 +678,7 @@ static const struct sensor_driver_api ism330dhcx_api_funcs = {
|
||||||
|
|
||||||
static int ism330dhcx_init_chip(const struct device *dev)
|
static int ism330dhcx_init_chip(const struct device *dev)
|
||||||
{
|
{
|
||||||
|
const struct ism330dhcx_config * const cfg = dev->config;
|
||||||
struct ism330dhcx_data *ism330dhcx = dev->data;
|
struct ism330dhcx_data *ism330dhcx = dev->data;
|
||||||
uint8_t chip_id;
|
uint8_t chip_id;
|
||||||
|
|
||||||
|
@ -715,12 +703,11 @@ static int ism330dhcx_init_chip(const struct device *dev)
|
||||||
|
|
||||||
k_busy_wait(100);
|
k_busy_wait(100);
|
||||||
|
|
||||||
if (ism330dhcx_accel_set_fs_raw(dev,
|
LOG_DBG("accel range is %d", cfg->accel_range);
|
||||||
ISM330DHCX_DEFAULT_ACCEL_FULLSCALE) < 0) {
|
if (ism330dhcx_accel_range_set(dev, cfg->accel_range) < 0) {
|
||||||
LOG_DBG("failed to set accelerometer full-scale");
|
LOG_DBG("failed to set accelerometer full-scale");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
ism330dhcx->acc_gain = ISM330DHCX_DEFAULT_ACCEL_SENSITIVITY;
|
|
||||||
|
|
||||||
ism330dhcx->accel_freq = ism330dhcx_odr_to_freq_val(CONFIG_ISM330DHCX_ACCEL_ODR);
|
ism330dhcx->accel_freq = ism330dhcx_odr_to_freq_val(CONFIG_ISM330DHCX_ACCEL_ODR);
|
||||||
if (ism330dhcx_accel_set_odr_raw(dev, CONFIG_ISM330DHCX_ACCEL_ODR) < 0) {
|
if (ism330dhcx_accel_set_odr_raw(dev, CONFIG_ISM330DHCX_ACCEL_ODR) < 0) {
|
||||||
|
@ -728,11 +715,11 @@ static int ism330dhcx_init_chip(const struct device *dev)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ism330dhcx_gyro_set_fs_raw(dev, ISM330DHCX_DEFAULT_GYRO_FULLSCALE) < 0) {
|
LOG_DBG("gyro range is %d", cfg->gyro_range);
|
||||||
|
if (ism330dhcx_gyro_range_set(dev, cfg->gyro_range) < 0) {
|
||||||
LOG_DBG("failed to set gyroscope full-scale");
|
LOG_DBG("failed to set gyroscope full-scale");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
ism330dhcx->gyro_gain = ISM330DHCX_DEFAULT_GYRO_SENSITIVITY;
|
|
||||||
|
|
||||||
ism330dhcx->gyro_freq = ism330dhcx_odr_to_freq_val(CONFIG_ISM330DHCX_GYRO_ODR);
|
ism330dhcx->gyro_freq = ism330dhcx_odr_to_freq_val(CONFIG_ISM330DHCX_GYRO_ODR);
|
||||||
if (ism330dhcx_gyro_set_odr_raw(dev, CONFIG_ISM330DHCX_GYRO_ODR) < 0) {
|
if (ism330dhcx_gyro_set_odr_raw(dev, CONFIG_ISM330DHCX_GYRO_ODR) < 0) {
|
||||||
|
@ -758,6 +745,8 @@ static struct ism330dhcx_data ism330dhcx_data;
|
||||||
|
|
||||||
static const struct ism330dhcx_config ism330dhcx_config = {
|
static const struct ism330dhcx_config ism330dhcx_config = {
|
||||||
.bus_name = DT_INST_BUS_LABEL(0),
|
.bus_name = DT_INST_BUS_LABEL(0),
|
||||||
|
.accel_range = DT_INST_PROP(0, accel_range),
|
||||||
|
.gyro_range = DT_INST_PROP(0, gyro_range),
|
||||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
||||||
.bus_init = ism330dhcx_spi_init,
|
.bus_init = ism330dhcx_spi_init,
|
||||||
.spi_conf.frequency = DT_INST_PROP(0, spi_max_frequency),
|
.spi_conf.frequency = DT_INST_PROP(0, spi_max_frequency),
|
||||||
|
|
|
@ -41,52 +41,10 @@ union axis1bit16_t {
|
||||||
#define SENSOR_DEG2RAD_DOUBLE (SENSOR_PI_DOUBLE / 180)
|
#define SENSOR_DEG2RAD_DOUBLE (SENSOR_PI_DOUBLE / 180)
|
||||||
#define SENSOR_G_DOUBLE (SENSOR_G / 1000000.0)
|
#define SENSOR_G_DOUBLE (SENSOR_G / 1000000.0)
|
||||||
|
|
||||||
#if CONFIG_ISM330DHCX_ACCEL_FS == 0
|
|
||||||
#define ISM330DHCX_ACCEL_FS_RUNTIME 1
|
|
||||||
#define ISM330DHCX_DEFAULT_ACCEL_FULLSCALE 0
|
|
||||||
#define ISM330DHCX_DEFAULT_ACCEL_SENSITIVITY GAIN_UNIT_XL
|
|
||||||
#elif CONFIG_ISM330DHCX_ACCEL_FS == 2
|
|
||||||
#define ISM330DHCX_DEFAULT_ACCEL_FULLSCALE 0
|
|
||||||
#define ISM330DHCX_DEFAULT_ACCEL_SENSITIVITY GAIN_UNIT_XL
|
|
||||||
#elif CONFIG_ISM330DHCX_ACCEL_FS == 4
|
|
||||||
#define ISM330DHCX_DEFAULT_ACCEL_FULLSCALE 2
|
|
||||||
#define ISM330DHCX_DEFAULT_ACCEL_SENSITIVITY (2.0 * GAIN_UNIT_XL)
|
|
||||||
#elif CONFIG_ISM330DHCX_ACCEL_FS == 8
|
|
||||||
#define ISM330DHCX_DEFAULT_ACCEL_FULLSCALE 3
|
|
||||||
#define ISM330DHCX_DEFAULT_ACCEL_SENSITIVITY (4.0 * GAIN_UNIT_XL)
|
|
||||||
#elif CONFIG_ISM330DHCX_ACCEL_FS == 16
|
|
||||||
#define ISM330DHCX_DEFAULT_ACCEL_FULLSCALE 1
|
|
||||||
#define ISM330DHCX_DEFAULT_ACCEL_SENSITIVITY (8.0 * GAIN_UNIT_XL)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (CONFIG_ISM330DHCX_ACCEL_ODR == 0)
|
#if (CONFIG_ISM330DHCX_ACCEL_ODR == 0)
|
||||||
#define ISM330DHCX_ACCEL_ODR_RUNTIME 1
|
#define ISM330DHCX_ACCEL_ODR_RUNTIME 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GYRO_FULLSCALE_125 4
|
|
||||||
|
|
||||||
#if CONFIG_ISM330DHCX_GYRO_FS == 0
|
|
||||||
#define ISM330DHCX_GYRO_FS_RUNTIME 1
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_FULLSCALE 4
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_SENSITIVITY GAIN_UNIT_G
|
|
||||||
#elif CONFIG_ISM330DHCX_GYRO_FS == 125
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_FULLSCALE 4
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_SENSITIVITY GAIN_UNIT_G
|
|
||||||
#elif CONFIG_ISM330DHCX_GYRO_FS == 250
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_FULLSCALE 0
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_SENSITIVITY (2.0 * GAIN_UNIT_G)
|
|
||||||
#elif CONFIG_ISM330DHCX_GYRO_FS == 500
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_FULLSCALE 1
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_SENSITIVITY (4.0 * GAIN_UNIT_G)
|
|
||||||
#elif CONFIG_ISM330DHCX_GYRO_FS == 1000
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_FULLSCALE 2
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_SENSITIVITY (8.0 * GAIN_UNIT_G)
|
|
||||||
#elif CONFIG_ISM330DHCX_GYRO_FS == 2000
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_FULLSCALE 3
|
|
||||||
#define ISM330DHCX_DEFAULT_GYRO_SENSITIVITY (16.0 * GAIN_UNIT_G)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if (CONFIG_ISM330DHCX_GYRO_ODR == 0)
|
#if (CONFIG_ISM330DHCX_GYRO_ODR == 0)
|
||||||
#define ISM330DHCX_GYRO_ODR_RUNTIME 1
|
#define ISM330DHCX_GYRO_ODR_RUNTIME 1
|
||||||
#endif
|
#endif
|
||||||
|
@ -94,6 +52,8 @@ union axis1bit16_t {
|
||||||
struct ism330dhcx_config {
|
struct ism330dhcx_config {
|
||||||
char *bus_name;
|
char *bus_name;
|
||||||
int (*bus_init)(const struct device *dev);
|
int (*bus_init)(const struct device *dev);
|
||||||
|
uint8_t accel_range;
|
||||||
|
uint16_t gyro_range;
|
||||||
#ifdef CONFIG_ISM330DHCX_TRIGGER
|
#ifdef CONFIG_ISM330DHCX_TRIGGER
|
||||||
const char *int_gpio_port;
|
const char *int_gpio_port;
|
||||||
uint8_t int_gpio_pin;
|
uint8_t int_gpio_pin;
|
||||||
|
|
|
@ -11,3 +11,41 @@ properties:
|
||||||
This pin defaults to active high when produced by the sensor.
|
This pin defaults to active high when produced by the sensor.
|
||||||
The property value should ensure the flags properly describe
|
The property value should ensure the flags properly describe
|
||||||
the signal that is presented to the driver.
|
the signal that is presented to the driver.
|
||||||
|
|
||||||
|
accel-range:
|
||||||
|
type: int
|
||||||
|
required: false
|
||||||
|
default: 2
|
||||||
|
description: |
|
||||||
|
Range in g. Default is power-up configuration.
|
||||||
|
|
||||||
|
Selection
|
||||||
|
16 16g (0.488 mg/LSB)
|
||||||
|
8 8g (0.244 mg/LSB)
|
||||||
|
4 4g (0.122 mg/LSB)
|
||||||
|
2 2g (0.061 mg/LSB)
|
||||||
|
enum:
|
||||||
|
- 16
|
||||||
|
- 8
|
||||||
|
- 4
|
||||||
|
- 2
|
||||||
|
|
||||||
|
gyro-range:
|
||||||
|
type: int
|
||||||
|
required: false
|
||||||
|
default: 125
|
||||||
|
description: |
|
||||||
|
Range in dps. Default is power-up configuration.
|
||||||
|
|
||||||
|
Selection
|
||||||
|
125 +/- 125dps
|
||||||
|
250 +/- 250dps
|
||||||
|
500 +/- 500dps
|
||||||
|
1000 +/- 1000dps
|
||||||
|
2000 +/- 2000dps
|
||||||
|
enum:
|
||||||
|
- 125
|
||||||
|
- 250
|
||||||
|
- 500
|
||||||
|
- 1000
|
||||||
|
- 2000
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue