Skip to content

Commit 226a9f2

Browse files
pabigotcarlescufi
authored andcommitted
drivers: sensor: lsm6dsl: update to new GPIO API
Correct IRQ active level to default active-high, switch to new interrupt configuration. Signed-off-by: Peter Bigot <[email protected]>
1 parent 2fa2f8a commit 226a9f2

File tree

6 files changed

+47
-15
lines changed

6 files changed

+47
-15
lines changed

boards/arm/disco_l475_iot1/disco_l475_iot1.dts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
lsm6dsl@6a {
9595
compatible = "st,lsm6dsl";
9696
reg = <0x6a>;
97-
irq-gpios = <&gpiod 11 0>;
97+
irq-gpios = <&gpiod 11 GPIO_ACTIVE_HIGH>;
9898
label = "LSM6DSL";
9999
};
100100

boards/shields/x_nucleo_iks01a2/x_nucleo_iks01a2.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
compatible = "st,lsm6dsl";
2424
reg = <0x6b>;
2525
label = "LSM6DSL";
26-
irq-gpios = <&arduino_header 10 0>; /* D4 */
26+
irq-gpios = <&arduino_header 10 GPIO_ACTIVE_HIGH>; /* D4 */
2727
};
2828

2929
lsm303agr-magn@1e {

drivers/sensor/lsm6dsl/lsm6dsl_trigger.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@
1515

1616
LOG_MODULE_DECLARE(LSM6DSL, CONFIG_SENSOR_LOG_LEVEL);
1717

18+
static inline void setup_irq(struct lsm6dsl_data *drv_data,
19+
bool enable)
20+
{
21+
unsigned int flags = enable
22+
? GPIO_INT_EDGE_TO_ACTIVE
23+
: GPIO_INT_DISABLE;
24+
25+
gpio_pin_interrupt_configure(drv_data->gpio,
26+
DT_INST_0_ST_LSM6DSL_IRQ_GPIOS_PIN,
27+
flags);
28+
}
29+
30+
static inline void handle_irq(struct lsm6dsl_data *drv_data)
31+
{
32+
setup_irq(drv_data, false);
33+
34+
#if defined(CONFIG_LSM6DSL_TRIGGER_OWN_THREAD)
35+
k_sem_give(&drv_data->gpio_sem);
36+
#elif defined(CONFIG_LSM6DSL_TRIGGER_GLOBAL_THREAD)
37+
k_work_submit(&drv_data->work);
38+
#endif
39+
}
40+
1841
int lsm6dsl_trigger_set(struct device *dev,
1942
const struct sensor_trigger *trig,
2043
sensor_trigger_handler_t handler)
@@ -23,7 +46,7 @@ int lsm6dsl_trigger_set(struct device *dev,
2346

2447
__ASSERT_NO_MSG(trig->type == SENSOR_TRIG_DATA_READY);
2548

26-
gpio_pin_disable_callback(drv_data->gpio, DT_INST_0_ST_LSM6DSL_IRQ_GPIOS_PIN);
49+
setup_irq(drv_data, false);
2750

2851
drv_data->data_ready_handler = handler;
2952
if (handler == NULL) {
@@ -32,7 +55,10 @@ int lsm6dsl_trigger_set(struct device *dev,
3255

3356
drv_data->data_ready_trigger = *trig;
3457

35-
gpio_pin_enable_callback(drv_data->gpio, DT_INST_0_ST_LSM6DSL_IRQ_GPIOS_PIN);
58+
setup_irq(drv_data, true);
59+
if (gpio_pin_get(drv_data->gpio, DT_INST_0_ST_LSM6DSL_IRQ_GPIOS_PIN) > 0) {
60+
handle_irq(drv_data);
61+
}
3662

3763
return 0;
3864
}
@@ -45,13 +71,7 @@ static void lsm6dsl_gpio_callback(struct device *dev,
4571

4672
ARG_UNUSED(pins);
4773

48-
gpio_pin_disable_callback(dev, DT_INST_0_ST_LSM6DSL_IRQ_GPIOS_PIN);
49-
50-
#if defined(CONFIG_LSM6DSL_TRIGGER_OWN_THREAD)
51-
k_sem_give(&drv_data->gpio_sem);
52-
#elif defined(CONFIG_LSM6DSL_TRIGGER_GLOBAL_THREAD)
53-
k_work_submit(&drv_data->work);
54-
#endif
74+
handle_irq(drv_data);
5575
}
5676

5777
static void lsm6dsl_thread_cb(void *arg)
@@ -64,7 +84,7 @@ static void lsm6dsl_thread_cb(void *arg)
6484
&drv_data->data_ready_trigger);
6585
}
6686

67-
gpio_pin_enable_callback(drv_data->gpio, DT_INST_0_ST_LSM6DSL_IRQ_GPIOS_PIN);
87+
setup_irq(drv_data, true);
6888
}
6989

7090
#ifdef CONFIG_LSM6DSL_TRIGGER_OWN_THREAD
@@ -105,8 +125,7 @@ int lsm6dsl_init_interrupt(struct device *dev)
105125
}
106126

107127
gpio_pin_configure(drv_data->gpio, DT_INST_0_ST_LSM6DSL_IRQ_GPIOS_PIN,
108-
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
109-
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
128+
GPIO_INPUT | DT_INST_0_ST_LSM6DSL_IRQ_GPIOS_FLAGS);
110129

111130
gpio_init_callback(&drv_data->gpio_cb,
112131
lsm6dsl_gpio_callback,
@@ -141,7 +160,7 @@ int lsm6dsl_init_interrupt(struct device *dev)
141160
drv_data->dev = dev;
142161
#endif
143162

144-
gpio_pin_enable_callback(drv_data->gpio, DT_INST_0_ST_LSM6DSL_IRQ_GPIOS_PIN);
163+
setup_irq(drv_data, true);
145164

146165
return 0;
147166
}

dts/bindings/sensor/st,lsm6dsl-i2c.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ include: i2c-device.yaml
1313

1414
properties:
1515
irq-gpios:
16+
# This signal is active high when produced by the sensor
1617
type: phandle-array
1718
required: false

dts/bindings/sensor/st,lsm6dsl-spi.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ include: spi-device.yaml
1313

1414
properties:
1515
irq-gpios:
16+
# This signal is active high when produced by the sensor
1617
type: phandle-array
1718
required: false

samples/sensor/lsm6dsl/README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ Building on disco_l475_iot1 board
4848
:goals: build
4949
:compact:
5050

51+
Building on nrf52840_pca10056 board with x-nucleo-iks01a2 shield
52+
================================================================
53+
54+
.. zephyr-app-commands::
55+
:zephyr-app: samples/sensor/lsm6dsl
56+
:host-os: unix
57+
:board: nrf52840_pca10056
58+
:shield: x_nucleo_iks01a2
59+
:goals: build
60+
:compact:
61+
5162
Sample Output
5263
=============
5364

0 commit comments

Comments
 (0)