drivers: sensor: lsm6dso: Fix issue lsm6dso32 cannot enabled
The lsm6dso driver does not correctly reflect the status of the node in dt. So the driver didn't compile even if `st,lsm6dso32` node exists. I fixed it to correctly go through ithe compile. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
This commit is contained in:
parent
95896bf17c
commit
f41195f922
3 changed files with 35 additions and 29 deletions
|
@ -6,10 +6,12 @@
|
||||||
menuconfig LSM6DSO
|
menuconfig LSM6DSO
|
||||||
bool "LSM6DSO I2C/SPI accelerometer and gyroscope Chip"
|
bool "LSM6DSO I2C/SPI accelerometer and gyroscope Chip"
|
||||||
default y
|
default y
|
||||||
depends on DT_HAS_ST_LSM6DSO_ENABLED
|
depends on DT_HAS_ST_LSM6DSO_ENABLED || DT_HAS_ST_LSM6DSO32_ENABLED
|
||||||
depends on ZEPHYR_HAL_ST_MODULE
|
depends on ZEPHYR_HAL_ST_MODULE
|
||||||
select I2C if $(dt_compat_on_bus,$(DT_COMPAT_ST_LSM6DSO),i2c)
|
select I2C if $(dt_compat_on_bus,$(DT_COMPAT_ST_LSM6DSO),i2c) || \
|
||||||
select SPI if $(dt_compat_on_bus,$(DT_COMPAT_ST_LSM6DSO),spi)
|
$(dt_compat_on_bus,$(DT_COMPAT_ST_LSM6DSO32),i2c)
|
||||||
|
select SPI if $(dt_compat_on_bus,$(DT_COMPAT_ST_LSM6DSO),spi) || \
|
||||||
|
$(dt_compat_on_bus,$(DT_COMPAT_ST_LSM6DSO32),spi)
|
||||||
select HAS_STMEMSC
|
select HAS_STMEMSC
|
||||||
select USE_STDC_LSM6DSO
|
select USE_STDC_LSM6DSO
|
||||||
help
|
help
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
* https://www.st.com/resource/en/datasheet/lsm6dso.pdf
|
* https://www.st.com/resource/en/datasheet/lsm6dso.pdf
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DT_DRV_COMPAT st_lsm6dso
|
|
||||||
|
|
||||||
#include <zephyr/drivers/sensor.h>
|
#include <zephyr/drivers/sensor.h>
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
|
@ -867,21 +865,17 @@ static int lsm6dso_init(const struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 0
|
|
||||||
#warning "LSM6DSO driver enabled without any devices"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Device creation macro, shared by LSM6DSO_DEFINE_SPI() and
|
* Device creation macro, shared by LSM6DSO_DEFINE_SPI() and
|
||||||
* LSM6DSO_DEFINE_I2C().
|
* LSM6DSO_DEFINE_I2C().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LSM6DSO_DEVICE_INIT(inst) \
|
#define LSM6DSO_DEVICE_INIT(inst, model) \
|
||||||
SENSOR_DEVICE_DT_INST_DEFINE(inst, \
|
SENSOR_DEVICE_DT_INST_DEFINE(inst, \
|
||||||
lsm6dso_init, \
|
lsm6dso_init, \
|
||||||
NULL, \
|
NULL, \
|
||||||
&lsm6dso_data_##inst, \
|
&model##_data_##inst, \
|
||||||
&lsm6dso_config_##inst, \
|
&model##_config_##inst, \
|
||||||
POST_KERNEL, \
|
POST_KERNEL, \
|
||||||
CONFIG_SENSOR_INIT_PRIORITY, \
|
CONFIG_SENSOR_INIT_PRIORITY, \
|
||||||
&lsm6dso_driver_api);
|
&lsm6dso_driver_api);
|
||||||
|
@ -917,9 +911,9 @@ static int lsm6dso_init(const struct device *dev)
|
||||||
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
|
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
|
||||||
(LSM6DSO_CFG_IRQ(inst)), ())
|
(LSM6DSO_CFG_IRQ(inst)), ())
|
||||||
|
|
||||||
#define LSM6DSO_CONFIG_SPI(inst) \
|
#define LSM6DSO_CONFIG_SPI(inst, model) \
|
||||||
{ \
|
{ \
|
||||||
STMEMSC_CTX_SPI(&lsm6dso_config_##inst.stmemsc_cfg), \
|
STMEMSC_CTX_SPI(&model##_config_##inst.stmemsc_cfg), \
|
||||||
.stmemsc_cfg = { \
|
.stmemsc_cfg = { \
|
||||||
.spi = SPI_DT_SPEC_INST_GET(inst, \
|
.spi = SPI_DT_SPEC_INST_GET(inst, \
|
||||||
LSM6DSO_SPI_OP, \
|
LSM6DSO_SPI_OP, \
|
||||||
|
@ -932,9 +926,9 @@ static int lsm6dso_init(const struct device *dev)
|
||||||
* Instantiation macros used when a device is on an I2C bus.
|
* Instantiation macros used when a device is on an I2C bus.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LSM6DSO_CONFIG_I2C(inst) \
|
#define LSM6DSO_CONFIG_I2C(inst, model) \
|
||||||
{ \
|
{ \
|
||||||
STMEMSC_CTX_I2C(&lsm6dso_config_##inst.stmemsc_cfg), \
|
STMEMSC_CTX_I2C(&model##_config_##inst.stmemsc_cfg), \
|
||||||
.stmemsc_cfg = { \
|
.stmemsc_cfg = { \
|
||||||
.i2c = I2C_DT_SPEC_INST_GET(inst), \
|
.i2c = I2C_DT_SPEC_INST_GET(inst), \
|
||||||
}, \
|
}, \
|
||||||
|
@ -946,12 +940,18 @@ static int lsm6dso_init(const struct device *dev)
|
||||||
* bus-specific macro at preprocessor time.
|
* bus-specific macro at preprocessor time.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LSM6DSO_DEFINE(inst) \
|
#define LSM6DSO_DEFINE(inst, model) \
|
||||||
static struct lsm6dso_data lsm6dso_data_##inst; \
|
static struct lsm6dso_data model##_data_##inst; \
|
||||||
static const struct lsm6dso_config lsm6dso_config_##inst = \
|
static const struct lsm6dso_config model##_config_##inst = \
|
||||||
COND_CODE_1(DT_INST_ON_BUS(inst, spi), \
|
COND_CODE_1(DT_INST_ON_BUS(inst, spi), \
|
||||||
(LSM6DSO_CONFIG_SPI(inst)), \
|
(LSM6DSO_CONFIG_SPI(inst, model)), \
|
||||||
(LSM6DSO_CONFIG_I2C(inst))); \
|
(LSM6DSO_CONFIG_I2C(inst, model))); \
|
||||||
LSM6DSO_DEVICE_INIT(inst)
|
LSM6DSO_DEVICE_INIT(inst, model)
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(LSM6DSO_DEFINE)
|
#define DT_DRV_COMPAT st_lsm6dso
|
||||||
|
DT_INST_FOREACH_STATUS_OKAY_VARGS(LSM6DSO_DEFINE, lsm6dso)
|
||||||
|
#undef DT_DRV_COMPAT
|
||||||
|
|
||||||
|
#define DT_DRV_COMPAT st_lsm6dso32
|
||||||
|
DT_INST_FOREACH_STATUS_OKAY_VARGS(LSM6DSO_DEFINE, lsm6dso32)
|
||||||
|
#undef DT_DRV_COMPAT
|
||||||
|
|
|
@ -19,13 +19,15 @@
|
||||||
#include <stmemsc.h>
|
#include <stmemsc.h>
|
||||||
#include "lsm6dso_reg.h"
|
#include "lsm6dso_reg.h"
|
||||||
|
|
||||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
#if DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(st_lsm6dso, spi) || \
|
||||||
|
DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(st_lsm6dso32, spi)
|
||||||
#include <zephyr/drivers/spi.h>
|
#include <zephyr/drivers/spi.h>
|
||||||
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */
|
#endif
|
||||||
|
|
||||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
#if DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(st_lsm6dso, i2c) || \
|
||||||
|
DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(st_lsm6dso32, i2c)
|
||||||
#include <zephyr/drivers/i2c.h>
|
#include <zephyr/drivers/i2c.h>
|
||||||
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */
|
#endif
|
||||||
|
|
||||||
#define LSM6DSO_EN_BIT 0x01
|
#define LSM6DSO_EN_BIT 0x01
|
||||||
#define LSM6DSO_DIS_BIT 0x00
|
#define LSM6DSO_DIS_BIT 0x00
|
||||||
|
@ -39,10 +41,12 @@
|
||||||
struct lsm6dso_config {
|
struct lsm6dso_config {
|
||||||
stmdev_ctx_t ctx;
|
stmdev_ctx_t ctx;
|
||||||
union {
|
union {
|
||||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
#if DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(st_lsm6dso, i2c) || \
|
||||||
|
DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(st_lsm6dso32, i2c)
|
||||||
const struct i2c_dt_spec i2c;
|
const struct i2c_dt_spec i2c;
|
||||||
#endif
|
#endif
|
||||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
#if DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(st_lsm6dso, spi) || \
|
||||||
|
DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(st_lsm6dso32, spi)
|
||||||
const struct spi_dt_spec spi;
|
const struct spi_dt_spec spi;
|
||||||
#endif
|
#endif
|
||||||
} stmemsc_cfg;
|
} stmemsc_cfg;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue