vrahane commented on a change in pull request #1024: lis2dw12: Support sleep 
change event for notifications
URL: https://github.com/apache/mynewt-core/pull/1024#discussion_r181849591
 
 

 ##########
 File path: hw/drivers/sensors/lis2dw12/src/lis2dw12.c
 ##########
 @@ -1946,89 +1943,106 @@ init_intpin(struct lis2dw12 * lis2dw12, 
hal_gpio_irq_handler_t handler,
     if (rc != 0) {
         LIS2DW12_ERR("Failed to initialise interrupt pin %d\n", pin);
         return rc;
-    } 
+    }
 
     return 0;
 }
 
 static int
-enable_interrupt(struct sensor * sensor, uint8_t int_to_enable)
+enable_interrupt(struct sensor *sensor, uint8_t int_to_enable, uint8_t int_num)
 {
     struct lis2dw12 *lis2dw12;
-    struct lis2dw12_private_driver_data *pdd;
+    struct lis2dw12_pdd *pdd;
     struct sensor_itf *itf;
     uint8_t reg;
     int rc;
 
+    if (!int_to_enable) {
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
     lis2dw12 = (struct lis2dw12 *)SENSOR_GET_DEVICE(sensor);
     itf = SENSOR_GET_ITF(sensor);
     pdd = &lis2dw12->pdd;
 
     rc = lis2dw12_clear_int(itf, &reg);
     if (rc) {
-        return rc;
+        goto err;
     }
-    
+
     /* if no interrupts are currently in use enable int pin */
-    if (pdd->int_enable == 0) {
-        hal_gpio_irq_enable(itf->si_ints[pdd->int_num].host_pin);
+    if (!pdd->int_enable) {
+        hal_gpio_irq_enable(itf->si_ints[int_num].host_pin);
 
         rc = lis2dw12_set_int_enable(itf, 1);
         if (rc) {
-            return rc;
+            goto err;
         }
     }
 
-    /*update which interrupts are enabled */
-    pdd->int_enable |= int_to_enable;
-    
+    pdd->int_enable++;
+
     /* enable interrupt in device */
-    rc = lis2dw12_set_int1_pin_cfg(itf, pdd->int_enable);
+    if (int_num == 0) {
+        rc = lis2dw12_set_int1_pin_cfg(itf, int_to_enable);
+    } else {
+        rc = lis2dw12_set_int2_pin_cfg(itf, int_to_enable);
+    }
+
     if (rc) {
-        return rc;
+        disable_interrupt(sensor, int_to_enable, int_num);
 
 Review comment:
   I see your point here. Surprisingly, I am not seeing an error which both 
troubles and confuses me. Anyways, I will move it to be above it's reference. A 
good catch.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to