drivers/sensor: iis2dlpc: Move range Kconfig property into dts
Converts iis2dlpc 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
cb6f665717
commit
e8bbcb9284
4 changed files with 20 additions and 42 deletions
|
@ -156,26 +156,6 @@ endif # IIS2DLPC_PULSE
|
|||
|
||||
endif # IIS2DLPC_TRIGGER
|
||||
|
||||
choice
|
||||
prompt "Accelerometer Full-scale range setting"
|
||||
default IIS2DLPC_ACCEL_RANGE_RUNTIME
|
||||
|
||||
config IIS2DLPC_ACCEL_RANGE_RUNTIME
|
||||
bool "Set at runtime (Default 2G)"
|
||||
|
||||
config IIS2DLPC_ACCEL_RANGE_2G
|
||||
bool "2G"
|
||||
|
||||
config IIS2DLPC_ACCEL_RANGE_4G
|
||||
bool "4G"
|
||||
|
||||
config IIS2DLPC_ACCEL_RANGE_8G
|
||||
bool "8G"
|
||||
|
||||
config IIS2DLPC_ACCEL_RANGE_16G
|
||||
bool "16G"
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "Accelerometer sampling frequency (ODR)"
|
||||
default IIS2DLPC_ODR_RUNTIME
|
||||
|
|
|
@ -31,13 +31,12 @@ LOG_MODULE_REGISTER(IIS2DLPC, 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 iis2dlpc_set_range(const struct device *dev, uint16_t range)
|
||||
static int iis2dlpc_set_range(const struct device *dev, uint8_t fs)
|
||||
{
|
||||
int err;
|
||||
struct iis2dlpc_data *iis2dlpc = dev->data;
|
||||
const struct iis2dlpc_device_config *cfg = dev->config;
|
||||
uint8_t shift_gain = 0U;
|
||||
uint8_t fs = IIS2DLPC_FS_TO_REG(range);
|
||||
|
||||
err = iis2dlpc_full_scale_set(iis2dlpc->ctx, fs);
|
||||
|
||||
|
@ -48,8 +47,7 @@ static int iis2dlpc_set_range(const struct device *dev, uint16_t range)
|
|||
if (!err) {
|
||||
/* save internally gain for optimization */
|
||||
iis2dlpc->gain =
|
||||
IIS2DLPC_FS_TO_GAIN(IIS2DLPC_FS_TO_REG(range),
|
||||
shift_gain);
|
||||
IIS2DLPC_FS_TO_GAIN(fs, shift_gain);
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -146,7 +144,8 @@ static int iis2dlpc_config(const struct device *dev, enum sensor_channel chan,
|
|||
{
|
||||
switch (attr) {
|
||||
case SENSOR_ATTR_FULL_SCALE:
|
||||
return iis2dlpc_set_range(dev, sensor_ms2_to_g(val));
|
||||
return iis2dlpc_set_range(dev,
|
||||
IIS2DLPC_FS_TO_REG(sensor_ms2_to_g(val)));
|
||||
case SENSOR_ATTR_SAMPLING_FREQUENCY:
|
||||
return iis2dlpc_set_odr(dev, val->val1);
|
||||
default:
|
||||
|
@ -297,15 +296,12 @@ static int iis2dlpc_init(const struct device *dev)
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
if (iis2dlpc_full_scale_set(iis2dlpc->ctx, IIS2DLPC_ACC_FS) < 0) {
|
||||
LOG_INF("range is %d", cfg->range);
|
||||
if (iis2dlpc_set_range(dev, IIS2DLPC_FS_TO_REG(cfg->range)) < 0) {
|
||||
LOG_ERR("range init error %d", cfg->range);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
iis2dlpc->gain =
|
||||
IIS2DLPC_FS_TO_GAIN(IIS2DLPC_ACC_FS,
|
||||
cfg->pm == IIS2DLPC_CONT_LOW_PWR_12bit ?
|
||||
IIS2DLPC_SHFT_GAIN_NOLP1 : 0);
|
||||
|
||||
#ifdef CONFIG_IIS2DLPC_TRIGGER
|
||||
if (iis2dlpc_init_interrupt(dev) < 0) {
|
||||
LOG_ERR("Failed to initialize interrupts");
|
||||
|
@ -377,6 +373,7 @@ static int iis2dlpc_init(const struct device *dev)
|
|||
const struct iis2dlpc_device_config iis2dlpc_cfg = {
|
||||
.bus_name = DT_INST_BUS_LABEL(0),
|
||||
.pm = CONFIG_IIS2DLPC_POWER_MODE,
|
||||
.range = DT_INST_PROP(0, range),
|
||||
#ifdef CONFIG_IIS2DLPC_TRIGGER
|
||||
.int_gpio_port = DT_INST_GPIO_LABEL(0, drdy_gpios),
|
||||
.int_gpio_pin = DT_INST_GPIO_PIN(0, drdy_gpios),
|
||||
|
|
|
@ -52,17 +52,6 @@ union axis3bit16_t {
|
|||
/* FS reg value from Full Scale */
|
||||
#define IIS2DLPC_FS_TO_REG(_fs) (30 - __builtin_clz(_fs))
|
||||
|
||||
#if defined(CONFIG_IIS2DLPC_ACCEL_RANGE_RUNTIME) || \
|
||||
defined(CONFIG_IIS2DLPC_ACCEL_RANGE_2G)
|
||||
#define IIS2DLPC_ACC_FS IIS2DLPC_2g
|
||||
#elif defined(CONFIG_IIS2DLPC_ACCEL_RANGE_4G)
|
||||
#define IIS2DLPC_ACC_FS IIS2DLPC_4g
|
||||
#elif defined(CONFIG_IIS2DLPC_ACCEL_RANGE_8G)
|
||||
#define IIS2DLPC_ACC_FS IIS2DLPC_8g
|
||||
#elif defined(CONFIG_IIS2DLPC_ACCEL_RANGE_16G)
|
||||
#define IIS2DLPC_ACC_FS IIS2DLPC_16g
|
||||
#endif
|
||||
|
||||
/* Acc Gain value in ug/LSB in High Perf mode */
|
||||
#define IIS2DLPC_FS_2G_GAIN 244
|
||||
#define IIS2DLPC_FS_4G_GAIN 488
|
||||
|
@ -89,6 +78,7 @@ union axis3bit16_t {
|
|||
struct iis2dlpc_device_config {
|
||||
const char *bus_name;
|
||||
iis2dlpc_mode_t pm;
|
||||
uint8_t range;
|
||||
#ifdef CONFIG_IIS2DLPC_TRIGGER
|
||||
const char *int_gpio_port;
|
||||
uint8_t int_gpio_pin;
|
||||
|
|
|
@ -10,3 +10,14 @@ properties:
|
|||
This pin defaults to active high when produced by the sensor.
|
||||
The property value should ensure the flags properly describe
|
||||
the signal that is presented to the driver.
|
||||
|
||||
range:
|
||||
type: int
|
||||
required: false
|
||||
default: 2
|
||||
description: Range in g. Default is power-up configuration.
|
||||
enum:
|
||||
- 16 # 16g (1.952 mg/LSB)
|
||||
- 8 # 8g (0.976 mg/LSB)
|
||||
- 4 # 4g (0.488 mg/LSB)
|
||||
- 2 # 2g (0.244 mg/LSB)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue