drivers/sensor: lis2dw12: Move range Kconfig property into dts
Converts lis2dw12 range options (2g, 4g, 8g, 16g) from Kconfigs to Device Tree. Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
a783a062f8
commit
344e06025d
4 changed files with 27 additions and 42 deletions
|
@ -59,26 +59,6 @@ config LIS2DW12_TAP
|
|||
|
||||
endif # LIS2DW12_TRIGGER
|
||||
|
||||
choice
|
||||
prompt "Accelerometer Full-scale range setting"
|
||||
default LIS2DW12_ACCEL_RANGE_RUNTIME
|
||||
|
||||
config LIS2DW12_ACCEL_RANGE_RUNTIME
|
||||
bool "Set at runtime (Default 2G)"
|
||||
|
||||
config LIS2DW12_ACCEL_RANGE_2G
|
||||
bool "2G"
|
||||
|
||||
config LIS2DW12_ACCEL_RANGE_4G
|
||||
bool "4G"
|
||||
|
||||
config LIS2DW12_ACCEL_RANGE_8G
|
||||
bool "8G"
|
||||
|
||||
config LIS2DW12_ACCEL_RANGE_16G
|
||||
bool "16G"
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "Accelerometer sampling frequency (ODR)"
|
||||
default LIS2DW12_ODR_RUNTIME
|
||||
|
|
|
@ -31,13 +31,12 @@ LOG_MODULE_REGISTER(LIS2DW12, CONFIG_SENSOR_LOG_LEVEL);
|
|||
* @dev: Pointer to instance of struct device (I2C or SPI)
|
||||
* @range: Full scale range (2, 4, 8 and 16 G)
|
||||
*/
|
||||
static int lis2dw12_set_range(const struct device *dev, uint16_t range)
|
||||
static int lis2dw12_set_range(const struct device *dev, uint8_t fs)
|
||||
{
|
||||
int err;
|
||||
struct lis2dw12_data *lis2dw12 = dev->data;
|
||||
const struct lis2dw12_device_config *cfg = dev->config;
|
||||
uint8_t shift_gain = 0U;
|
||||
uint8_t fs = LIS2DW12_FS_TO_REG(range);
|
||||
|
||||
err = lis2dw12_full_scale_set(lis2dw12->ctx, fs);
|
||||
|
||||
|
@ -48,8 +47,7 @@ static int lis2dw12_set_range(const struct device *dev, uint16_t range)
|
|||
if (!err) {
|
||||
/* save internally gain for optimization */
|
||||
lis2dw12->gain =
|
||||
LIS2DW12_FS_TO_GAIN(LIS2DW12_FS_TO_REG(range),
|
||||
shift_gain);
|
||||
LIS2DW12_FS_TO_GAIN(fs, shift_gain);
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -146,7 +144,8 @@ static int lis2dw12_config(const struct device *dev, enum sensor_channel chan,
|
|||
{
|
||||
switch (attr) {
|
||||
case SENSOR_ATTR_FULL_SCALE:
|
||||
return lis2dw12_set_range(dev, sensor_ms2_to_g(val));
|
||||
return lis2dw12_set_range(dev,
|
||||
LIS2DW12_FS_TO_REG(sensor_ms2_to_g(val)));
|
||||
case SENSOR_ATTR_SAMPLING_FREQUENCY:
|
||||
return lis2dw12_set_odr(dev, val->val1);
|
||||
default:
|
||||
|
@ -298,15 +297,12 @@ static int lis2dw12_init(const struct device *dev)
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
if (lis2dw12_full_scale_set(lis2dw12->ctx, LIS2DW12_ACC_FS) < 0) {
|
||||
LOG_DBG("range is %d", cfg->range);
|
||||
if (lis2dw12_set_range(dev, LIS2DW12_FS_TO_REG(cfg->range)) < 0) {
|
||||
LOG_ERR("range init error %d", cfg->range);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
lis2dw12->gain =
|
||||
LIS2DW12_FS_TO_GAIN(LIS2DW12_ACC_FS,
|
||||
cfg->pm == LIS2DW12_CONT_LOW_PWR_12bit ?
|
||||
LIS2DW12_SHFT_GAIN_NOLP1 : 0);
|
||||
|
||||
#ifdef CONFIG_LIS2DW12_TRIGGER
|
||||
if (lis2dw12_init_interrupt(dev) < 0) {
|
||||
LOG_ERR("Failed to initialize interrupts");
|
||||
|
@ -320,6 +316,7 @@ static int lis2dw12_init(const struct device *dev)
|
|||
const struct lis2dw12_device_config lis2dw12_cfg = {
|
||||
.bus_name = DT_INST_BUS_LABEL(0),
|
||||
.pm = DT_INST_PROP(0, power_mode),
|
||||
.range = DT_INST_PROP(0, range),
|
||||
#ifdef CONFIG_LIS2DW12_TRIGGER
|
||||
.gpio_int = GPIO_DT_SPEC_INST_GET_OR(0, irq_gpios, {0}),
|
||||
.int_pin = DT_INST_PROP(0, int_pin),
|
||||
|
|
|
@ -47,17 +47,6 @@
|
|||
/* FS reg value from Full Scale */
|
||||
#define LIS2DW12_FS_TO_REG(_fs) (30 - __builtin_clz(_fs))
|
||||
|
||||
#if defined(CONFIG_LIS2DW12_ACCEL_RANGE_RUNTIME) || \
|
||||
defined(CONFIG_LIS2DW12_ACCEL_RANGE_2G)
|
||||
#define LIS2DW12_ACC_FS LIS2DW12_2g
|
||||
#elif defined(CONFIG_LIS2DW12_ACCEL_RANGE_4G)
|
||||
#define LIS2DW12_ACC_FS LIS2DW12_4g
|
||||
#elif defined(CONFIG_LIS2DW12_ACCEL_RANGE_8G)
|
||||
#define LIS2DW12_ACC_FS LIS2DW12_8g
|
||||
#elif defined(CONFIG_LIS2DW12_ACCEL_RANGE_16G)
|
||||
#define LIS2DW12_ACC_FS LIS2DW12_16g
|
||||
#endif
|
||||
|
||||
/* Acc Gain value in ug/LSB in High Perf mode */
|
||||
#define LIS2DW12_FS_2G_GAIN 244
|
||||
#define LIS2DW12_FS_4G_GAIN 488
|
||||
|
@ -82,6 +71,7 @@
|
|||
struct lis2dw12_device_config {
|
||||
const char *bus_name;
|
||||
lis2dw12_mode_t pm;
|
||||
uint8_t range;
|
||||
#ifdef CONFIG_LIS2DW12_TRIGGER
|
||||
struct gpio_dt_spec gpio_int;
|
||||
uint8_t int_pin;
|
||||
|
|
|
@ -30,6 +30,24 @@ properties:
|
|||
mandatory and if not present it defaults to 1 which is the
|
||||
configuration at power-up.
|
||||
|
||||
range:
|
||||
type: int
|
||||
required: false
|
||||
default: 2
|
||||
description: |
|
||||
Range in g. Default is power-up configuration.
|
||||
|
||||
16 # 16g (1.952 mg/LSB)
|
||||
8 # 8g (0.976 mg/LSB)
|
||||
4 # 4g (0.488 mg/LSB)
|
||||
2 # 2g (0.244 mg/LSB)
|
||||
|
||||
enum:
|
||||
- 16
|
||||
- 8
|
||||
- 4
|
||||
- 2
|
||||
|
||||
power-mode:
|
||||
type: int
|
||||
required: false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue