Im trying to detect freefall with lsm sensor. Interupt is set, and it fires but after some 7 times, It locks up the device. Also, I added a reRoute part to the int handler but im getting -5 error code.
Am I doing this correctly or am I missing a piece?
Regards,
#define INT2_NODE DT_ALIAS(int2) #define INT2_GPIO_CONTROLLER DEVICE_DT_GET(DT_GPIO_CTLR(INT2_NODE, gpios)) #define INT2_GPIO_PIN DT_GPIO_PIN(INT2_NODE, gpios) #define INT2_GPIO_FLAGS (DT_GPIO_FLAGS(INT2_NODE, gpios) | GPIO_INPUT) const struct i2c_dt_spec* gdev; int initialize_lsm6dso32x(const struct i2c_dt_spec* dev) { gdev = dev; uint8_t whoamI; lsm6dso32x_device_id_get(dev, &whoamI); lsm6dso32x_irq_init(gdev); return 0; } /* Declare the GPIO callbacks */ struct gpio_callback int2_cb_data; void int2_callback(const struct device* dev, struct gpio_callback* cb, uint32_t pins) { lsm6dso32x_all_sources_t int_status; lsm6dso32x_pin_int2_route_t int2_route; lsm6dso32x_all_sources_get(gdev, &int_status); // Check the free-fall interrupt status if (int_status.free_fall) { printk("Free-fall detected\n"); } int2_route = (lsm6dso32x_pin_int2_route_t){0}; int2_route.free_fall = PROPERTY_ENABLE; int status = lsm6dso32x_pin_int2_route_set(gdev, int2_route); if (status != 0) { printk("Failed to reRoute:%d\n", status); } } int lsm6dso32x_irq_init(const struct i2c_dt_spec* dev) { // Configure interrupt mode settings lsm6dso32x_int_mode_t int_mode_settings = { .active_low = 0, .base_latched = 0, .emb_latched = 0 }; int32_t status = lsm6dso32x_interrupt_mode_set(dev, int_mode_settings); if (status != 0) { printk("Failed to set interrupt mode\n"); return status; } lsm6dso32x_ff_threshold_set(dev, LSM6DSO32X_FF_TSH_312mg); lsm6dso32x_ff_dur_set(dev, 10); // Configure INT2 route for freefall detection lsm6dso32x_pin_int2_route_t int2_route; int2_route = (lsm6dso32x_pin_int2_route_t){0}; int2_route.free_fall = PROPERTY_ENABLE; status = lsm6dso32x_pin_int2_route_set(dev, int2_route); if (status != 0) { printk("Failed to route freefall to INT2\n"); return status; } /* Ensure the GPIO device is ready */ if (!device_is_ready(INT2_GPIO_CONTROLLER)) { printk("Error: %s device not ready\n", INT2_GPIO_CONTROLLER->name); return -1; } /* Configure the GPIOs and initialize the callbacks */ gpio_pin_configure(INT2_GPIO_CONTROLLER, INT2_GPIO_PIN, INT2_GPIO_FLAGS); gpio_pin_interrupt_configure(INT2_GPIO_CONTROLLER, INT2_GPIO_PIN, GPIO_INT_EDGE_TO_ACTIVE); gpio_init_callback(&int2_cb_data, int2_callback, BIT(INT2_GPIO_PIN)); gpio_add_callback(INT2_GPIO_CONTROLLER, &int2_cb_data); return 0; // Success }