Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TOPIC-GPIO] drivers: sensor: isl29035: update to new GPIO API #21523

Merged
merged 1 commit into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions drivers/sensor/isl29035/isl29035_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ extern struct isl29035_driver_data isl29035_data;

LOG_MODULE_DECLARE(ISL29035, CONFIG_SENSOR_LOG_LEVEL);

static inline void setup_int(struct isl29035_driver_data *drv_data,
bool enable)
{
unsigned int flags = enable
? GPIO_INT_EDGE_TO_ACTIVE
: GPIO_INT_DISABLE;

gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN,
flags);
}

static inline void handle_int(struct isl29035_driver_data *drv_data)
{
setup_int(drv_data, false);

#if defined(CONFIG_ISL29035_TRIGGER_OWN_THREAD)
k_sem_give(&drv_data->gpio_sem);
#elif defined(CONFIG_ISL29035_TRIGGER_GLOBAL_THREAD)
k_work_submit(&drv_data->work);
#endif
}

static u16_t isl29035_lux_processed_to_raw(struct sensor_value const *val)
{
u64_t raw_val;
Expand Down Expand Up @@ -65,15 +88,9 @@ static void isl29035_gpio_callback(struct device *dev,
struct isl29035_driver_data *drv_data =
CONTAINER_OF(cb, struct isl29035_driver_data, gpio_cb);

ARG_UNUSED(pins);

gpio_pin_disable_callback(dev, DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);

#if defined(CONFIG_ISL29035_TRIGGER_OWN_THREAD)
k_sem_give(&drv_data->gpio_sem);
#elif defined(CONFIG_ISL29035_TRIGGER_GLOBAL_THREAD)
k_work_submit(&drv_data->work);
#endif
ARG_UNUSED(pins);
handle_int(drv_data);
}

static void isl29035_thread_cb(struct device *dev)
Expand All @@ -92,8 +109,7 @@ static void isl29035_thread_cb(struct device *dev)
drv_data->th_handler(dev, &drv_data->th_trigger);
}

gpio_pin_enable_callback(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);
setup_int(drv_data, true);
}

#ifdef CONFIG_ISL29035_TRIGGER_OWN_THREAD
Expand Down Expand Up @@ -128,15 +144,17 @@ int isl29035_trigger_set(struct device *dev,
struct isl29035_driver_data *drv_data = dev->driver_data;

/* disable interrupt callback while changing parameters */
gpio_pin_disable_callback(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);
setup_int(drv_data, false);

drv_data->th_handler = handler;
drv_data->th_trigger = *trig;

/* enable interrupt callback */
gpio_pin_enable_callback(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);
setup_int(drv_data, true);
if (gpio_pin_get(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN) > 0) {
handle_int(drv_data);
}

return 0;
}
Expand All @@ -162,10 +180,8 @@ int isl29035_init_interrupt(struct device *dev)
return -EINVAL;
}

gpio_pin_configure(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL |
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);
gpio_pin_configure(drv_data->gpio, DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN,
GPIO_INPUT | DT_INST_0_ISIL_ISL29035_INT_GPIOS_FLAGS);

gpio_init_callback(&drv_data->gpio_cb,
isl29035_gpio_callback,
Expand All @@ -189,5 +205,7 @@ int isl29035_init_interrupt(struct device *dev)
drv_data->dev = dev;
#endif

setup_int(drv_data, true);

return 0;
}
4 changes: 4 additions & 0 deletions dts/bindings/sensor/isil,isl29035.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ properties:
int-gpios:
type: phandle-array
required: false
description: |
The INT pin defaults to active low when produced by the sensor.
The property value should ensure the flags properly describe the
signal that is presented to the driver.
2 changes: 1 addition & 1 deletion samples/sensor/isl29035/boards/nrf52_pca10040.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
compatible = "isil,isl29035";
reg = <0x44>;
label = "ISL29035";
int-gpios = <&gpio0 11 GPIO_INT_ACTIVE_HIGH>;
int-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
};
};
4 changes: 2 additions & 2 deletions samples/sensor/isl29035/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
static volatile bool alerted;
struct k_sem sem;

#ifdef CONFIG_ISL29035_TRIGGER
static void trigger_handler(struct device *dev,
struct sensor_trigger *trig)
{
#ifdef CONFIG_ISL29035_TRIGGER
alerted = !alerted;
k_sem_give(&sem);
}
#endif /* CONFIG_ISL29035_TRIGGER */
}

static const char *now_str(void)
{
Expand Down