You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/03/20 20:27:09 UTC
[GitHub] sterlinghughes commented on a change in pull request #926: Add Driver for LIS2DW12
sterlinghughes commented on a change in pull request #926: Add Driver for LIS2DW12
URL: https://github.com/apache/mynewt-core/pull/926#discussion_r175911134
##########
File path: hw/drivers/sensors/lis2dw12/src/lis2dw12.c
##########
@@ -1136,45 +1310,78 @@ init_intpin(struct lis2dw12 * lis2dw12, hal_gpio_irq_handler_t handler,
}
static int
-enable_interrupt(struct sensor * sensor, uint8_t int_cfg)
+enable_interrupt(struct sensor * sensor, uint8_t int_to_enable)
{
struct lis2dw12 *lis2dw12;
+ struct lis2dw12_private_driver_data *pdd;
struct sensor_itf *itf;
uint8_t reg;
int rc;
lis2dw12 = (struct lis2dw12 *)SENSOR_GET_DEVICE(sensor);
itf = SENSOR_GET_ITF(sensor);
-
- /* enable int pin */
- hal_gpio_irq_enable(lis2dw12->sensor.s_itf.si_ints[lis2dw12->pdd.int_num]
- .host_pin);
+ pdd = &lis2dw12->pdd;
+
+ rc = lis2dw12_clear_int(itf, ®);
+ if (rc) {
+ return rc;
+ }
+
+ /* if no interrupts are currently in use enable int pin */
+ if (pdd->int_enable == 0) {
+ hal_gpio_irq_enable(lis2dw12->sensor.s_itf.si_ints[lis2dw12->pdd.int_num]
+ .host_pin);
+
+ rc = lis2dw12_set_int_enable(itf, 1);
+ if (rc) {
+ return rc;
+ }
+ }
+ /*update which interrupts are enabled */
+ pdd->int_enable |= int_to_enable;
+
/* enable interrupt in device */
- rc = lis2dw12_set_int1_pin_cfg(itf, int_cfg);
+ rc = lis2dw12_set_int1_pin_cfg(itf, pdd->int_enable);
if (rc) {
return rc;
}
- return lis2dw12_clear_int(itf, ®);
+ return 0;
}
static int
-disable_interrupt(struct sensor * sensor, uint8_t int_cfg)
+disable_interrupt(struct sensor * sensor, uint8_t int_to_disable)
{
struct lis2dw12 *lis2dw12;
+ struct lis2dw12_private_driver_data *pdd;
struct sensor_itf *itf;
+ int rc;
+ if (int_to_disable == 0) {
+ return SYS_EINVAL;
+ }
+
lis2dw12 = (struct lis2dw12 *)SENSOR_GET_DEVICE(sensor);
itf = SENSOR_GET_ITF(sensor);
+ pdd = &lis2dw12->pdd;
+
+ pdd->int_enable &= ~int_to_disable;
/* disable int pin */
- hal_gpio_irq_disable(lis2dw12->sensor.s_itf.si_ints[lis2dw12->pdd.int_num]
- .host_pin);
+ if (pdd->int_enable == 0) {
+ hal_gpio_irq_disable(lis2dw12->sensor.s_itf.si_ints[lis2dw12->pdd.int_num]
Review comment:
can't this be taken directly off of itf, assigned above? that would also solve the wrap around structure access?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services