drivers/sensor: lsm6dso: (FIX) enable interrupt selectively
In a multi-instance driver it may happen that on some h/w one device should use interrupts and a second device should use polling mode. So, CONFIG_LSM6DSO_TRIGGER is not enough to discriminmate if interrupt inizialization routine should be called or not; the choice is now based whether the "irq-gpios" property is present in the DT for that particular instance or not. Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
cacee210ad
commit
2f01479b56
3 changed files with 18 additions and 5 deletions
|
@ -769,14 +769,19 @@ static int lsm6dso_init_chip(const struct device *dev)
|
||||||
|
|
||||||
static int lsm6dso_init(const struct device *dev)
|
static int lsm6dso_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_LSM6DSO_TRIGGER
|
||||||
|
const struct lsm6dso_config *cfg = dev->config;
|
||||||
|
#endif
|
||||||
struct lsm6dso_data *data = dev->data;
|
struct lsm6dso_data *data = dev->data;
|
||||||
|
|
||||||
data->dev = dev;
|
data->dev = dev;
|
||||||
|
|
||||||
#ifdef CONFIG_LSM6DSO_TRIGGER
|
#ifdef CONFIG_LSM6DSO_TRIGGER
|
||||||
if (lsm6dso_init_interrupt(dev) < 0) {
|
if (cfg->trig_enabled) {
|
||||||
LOG_ERR("Failed to initialize interrupt.");
|
if (lsm6dso_init_interrupt(dev) < 0) {
|
||||||
return -EIO;
|
LOG_ERR("Failed to initialize interrupt.");
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -819,8 +824,9 @@ static int lsm6dso_init(const struct device *dev)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_LSM6DSO_TRIGGER
|
#ifdef CONFIG_LSM6DSO_TRIGGER
|
||||||
#define LSM6DSO_CFG_IRQ(inst) \
|
#define LSM6DSO_CFG_IRQ(inst) \
|
||||||
.gpio_drdy = GPIO_DT_SPEC_INST_GET(inst, irq_gpios), \
|
.trig_enabled = true, \
|
||||||
|
.gpio_drdy = GPIO_DT_SPEC_INST_GET(inst, irq_gpios), \
|
||||||
.int_pin = DT_INST_PROP(inst, int_pin)
|
.int_pin = DT_INST_PROP(inst, int_pin)
|
||||||
#else
|
#else
|
||||||
#define LSM6DSO_CFG_IRQ(inst)
|
#define LSM6DSO_CFG_IRQ(inst)
|
||||||
|
|
|
@ -113,6 +113,7 @@ struct lsm6dso_config {
|
||||||
#ifdef CONFIG_LSM6DSO_TRIGGER
|
#ifdef CONFIG_LSM6DSO_TRIGGER
|
||||||
const struct gpio_dt_spec gpio_drdy;
|
const struct gpio_dt_spec gpio_drdy;
|
||||||
uint8_t int_pin;
|
uint8_t int_pin;
|
||||||
|
bool trig_enabled;
|
||||||
#endif /* CONFIG_LSM6DSO_TRIGGER */
|
#endif /* CONFIG_LSM6DSO_TRIGGER */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -126,8 +126,14 @@ int lsm6dso_trigger_set(const struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler)
|
sensor_trigger_handler_t handler)
|
||||||
{
|
{
|
||||||
|
const struct lsm6dso_config *cfg = dev->config;
|
||||||
struct lsm6dso_data *lsm6dso = dev->data;
|
struct lsm6dso_data *lsm6dso = dev->data;
|
||||||
|
|
||||||
|
if (!cfg->trig_enabled) {
|
||||||
|
LOG_ERR("trigger_set op not supported");
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
if (trig->chan == SENSOR_CHAN_ACCEL_XYZ) {
|
if (trig->chan == SENSOR_CHAN_ACCEL_XYZ) {
|
||||||
lsm6dso->handler_drdy_acc = handler;
|
lsm6dso->handler_drdy_acc = handler;
|
||||||
if (handler) {
|
if (handler) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue