Skip to content

Commit f39dba5

Browse files
avisconticarlescufi
authored andcommitted
drivers/sensor: lsm6dsv16x: add in DT both INT1 and INT2 pin
Add in DT the possibility to configure both INT1 and INT2 pin. The driver will then assign one of the two (either 1 or 2, according to what value drdy_pin is set) to a gpio for receiving drdy interrupts. The other pin may be used in the future to receive event interrupts. Signed-off-by: Armando Visconti <[email protected]>
1 parent 016a113 commit f39dba5

File tree

8 files changed

+55
-18
lines changed

8 files changed

+55
-18
lines changed

boards/arm/sensortile_box_pro/sensortile_box_pro.dts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@
175175
compatible = "st,lsm6dsv16x";
176176
spi-max-frequency = <DT_FREQ_M(10)>; /* 10 MHz */
177177
reg = <0>;
178-
irq-gpios = <&gpiod 11 GPIO_ACTIVE_HIGH>;
178+
int1-gpios = <&gpioa 4 GPIO_ACTIVE_HIGH>;
179+
int2-gpios = <&gpiod 11 GPIO_ACTIVE_HIGH>;
180+
179181
drdy-pin = <2>;
180182
};
181183
};

doc/releases/migration-guide-3.6.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ enable all optional modules, and then run ``west update`` again.
3535
Device Drivers and Device Tree
3636
==============================
3737

38+
* The :dtcompatible:`st,lsm6dsv16x` sensor driver has been changed to support
39+
configuration of both int1 and int2 pins. The DT attribute ``irq-gpios`` has been
40+
removed and substituted by two new attributes, ``int1-gpios`` and ``int2-gpios``.
41+
These attributes must be configured in the Device Tree similarly to the following
42+
example:
43+
44+
.. code-block:: devicetree
45+
46+
/ {
47+
lsm6dsv16x@0 {
48+
compatible = "st,lsm6dsv16x";
49+
50+
int1-gpios = <&gpioa 4 GPIO_ACTIVE_HIGH>;
51+
int2-gpios = <&gpiod 11 GPIO_ACTIVE_HIGH>;
52+
drdy-pin = <2>;
53+
};
54+
};
55+
3856
Power Management
3957
================
4058

drivers/sensor/lsm6dsv16x/lsm6dsv16x.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -919,9 +919,10 @@ static int lsm6dsv16x_init(const struct device *dev)
919919
*/
920920

921921
#ifdef CONFIG_LSM6DSV16X_TRIGGER
922-
#define LSM6DSV16X_CFG_IRQ(inst) \
922+
#define LSM6DSV16X_CFG_IRQ(inst) \
923923
.trig_enabled = true, \
924-
.gpio_drdy = GPIO_DT_SPEC_INST_GET(inst, irq_gpios), \
924+
.int1_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, int1_gpios, { 0 }), \
925+
.int2_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, int2_gpios, { 0 }), \
925926
.drdy_pin = DT_INST_PROP(inst, drdy_pin)
926927
#else
927928
#define LSM6DSV16X_CFG_IRQ(inst)
@@ -938,8 +939,7 @@ static int lsm6dsv16x_init(const struct device *dev)
938939
.gyro_odr = DT_INST_PROP(inst, gyro_odr), \
939940
.gyro_range = DT_INST_PROP(inst, gyro_range), \
940941
.drdy_pulsed = DT_INST_PROP(inst, drdy_pulsed), \
941-
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
942-
(LSM6DSV16X_CFG_IRQ(inst)), ())
942+
LSM6DSV16X_CFG_IRQ(inst)
943943

944944
#define LSM6DSV16X_CONFIG_SPI(inst) \
945945
{ \

drivers/sensor/lsm6dsv16x/lsm6dsv16x.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ struct lsm6dsv16x_config {
5757
uint8_t gyro_range;
5858
uint8_t drdy_pulsed;
5959
#ifdef CONFIG_LSM6DSV16X_TRIGGER
60-
const struct gpio_dt_spec gpio_drdy;
60+
const struct gpio_dt_spec int1_gpio;
61+
const struct gpio_dt_spec int2_gpio;
6162
uint8_t drdy_pin;
6263
bool trig_enabled;
6364
#endif /* CONFIG_LSM6DSV16X_TRIGGER */
@@ -102,6 +103,8 @@ struct lsm6dsv16x_data {
102103
uint8_t gyro_fs;
103104

104105
#ifdef CONFIG_LSM6DSV16X_TRIGGER
106+
struct gpio_dt_spec *drdy_gpio;
107+
105108
struct gpio_callback gpio_cb;
106109
sensor_trigger_handler_t handler_drdy_acc;
107110
const struct sensor_trigger *trig_drdy_acc;

drivers/sensor/lsm6dsv16x/lsm6dsv16x_trigger.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static void lsm6dsv16x_handle_interrupt(const struct device *dev)
233233
#endif
234234
}
235235

236-
gpio_pin_interrupt_configure_dt(&cfg->gpio_drdy,
236+
gpio_pin_interrupt_configure_dt(lsm6dsv16x->drdy_gpio,
237237
GPIO_INT_EDGE_TO_ACTIVE);
238238
}
239239

@@ -242,11 +242,10 @@ static void lsm6dsv16x_gpio_callback(const struct device *dev,
242242
{
243243
struct lsm6dsv16x_data *lsm6dsv16x =
244244
CONTAINER_OF(cb, struct lsm6dsv16x_data, gpio_cb);
245-
const struct lsm6dsv16x_config *cfg = lsm6dsv16x->dev->config;
246245

247246
ARG_UNUSED(pins);
248247

249-
gpio_pin_interrupt_configure_dt(&cfg->gpio_drdy, GPIO_INT_DISABLE);
248+
gpio_pin_interrupt_configure_dt(lsm6dsv16x->drdy_gpio, GPIO_INT_DISABLE);
250249

251250
#if defined(CONFIG_LSM6DSV16X_TRIGGER_OWN_THREAD)
252251
k_sem_give(&lsm6dsv16x->gpio_sem);
@@ -287,8 +286,12 @@ int lsm6dsv16x_init_interrupt(const struct device *dev)
287286
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx;
288287
int ret;
289288

289+
lsm6dsv16x->drdy_gpio = (cfg->drdy_pin == 1) ?
290+
(struct gpio_dt_spec *)&cfg->int1_gpio :
291+
(struct gpio_dt_spec *)&cfg->int2_gpio;
292+
290293
/* setup data ready gpio interrupt (INT1 or INT2) */
291-
if (!gpio_is_ready_dt(&cfg->gpio_drdy)) {
294+
if (!gpio_is_ready_dt(lsm6dsv16x->drdy_gpio)) {
292295
LOG_ERR("Cannot get pointer to drdy_gpio device");
293296
return -EINVAL;
294297
}
@@ -306,17 +309,17 @@ int lsm6dsv16x_init_interrupt(const struct device *dev)
306309
lsm6dsv16x->work.handler = lsm6dsv16x_work_cb;
307310
#endif /* CONFIG_LSM6DSV16X_TRIGGER_OWN_THREAD */
308311

309-
ret = gpio_pin_configure_dt(&cfg->gpio_drdy, GPIO_INPUT);
312+
ret = gpio_pin_configure_dt(lsm6dsv16x->drdy_gpio, GPIO_INPUT);
310313
if (ret < 0) {
311314
LOG_DBG("Could not configure gpio");
312315
return ret;
313316
}
314317

315318
gpio_init_callback(&lsm6dsv16x->gpio_cb,
316319
lsm6dsv16x_gpio_callback,
317-
BIT(cfg->gpio_drdy.pin));
320+
BIT(lsm6dsv16x->drdy_gpio->pin));
318321

319-
if (gpio_add_callback(cfg->gpio_drdy.port, &lsm6dsv16x->gpio_cb) < 0) {
322+
if (gpio_add_callback(lsm6dsv16x->drdy_gpio->port, &lsm6dsv16x->gpio_cb) < 0) {
320323
LOG_DBG("Could not set gpio callback");
321324
return -EIO;
322325
}
@@ -333,6 +336,6 @@ int lsm6dsv16x_init_interrupt(const struct device *dev)
333336
return ret;
334337
}
335338

336-
return gpio_pin_interrupt_configure_dt(&cfg->gpio_drdy,
339+
return gpio_pin_interrupt_configure_dt(lsm6dsv16x->drdy_gpio,
337340
GPIO_INT_EDGE_TO_ACTIVE);
338341
}

dts/bindings/sensor/st,lsm6dsv16x-common.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@
44
include: sensor-device.yaml
55

66
properties:
7-
irq-gpios:
7+
int1-gpios:
88
type: phandle-array
99
description: |
10-
DRDY pin
10+
INT1 pin
11+
12+
This pin defaults to active high when produced by the sensor.
13+
The property value should ensure the flags properly describe
14+
the signal that is presented to the driver.
15+
16+
int2-gpios:
17+
type: phandle-array
18+
description: |
19+
INT2 pin
1120
1221
This pin defaults to active high when produced by the sensor.
1322
The property value should ensure the flags properly describe

tests/drivers/build_all/sensor/i2c.dtsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,8 @@ test_i2c_lsm6dso16is: lsm6dso16is@68 {
695695
test_i2c_lsm6dsv16x: lsm6dsv16x@69 {
696696
compatible = "st,lsm6dsv16x";
697697
reg = <0x69>;
698-
irq-gpios = <&test_gpio 0 0>;
698+
int1-gpios = <&test_gpio 0 0>;
699+
int2-gpios = <&test_gpio 0 0>;
699700
};
700701

701702
test_i2c_mcp9600: mcp9600@6a {

tests/drivers/build_all/sensor/spi.dtsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ test_spi_lsm6dsv16x: lsm6dsv16x@22 {
261261
compatible = "st,lsm6dsv16x";
262262
reg = <0x22>;
263263
spi-max-frequency = <0>;
264-
irq-gpios = <&test_gpio 0 0>;
264+
int1-gpios = <&test_gpio 0 0>;
265+
int2-gpios = <&test_gpio 0 0>;
265266
};
266267

267268
test_spi_bmi08x_accel: bmi08x@23 {

0 commit comments

Comments
 (0)