drivers: sensor: isl29035: update to new GPIO API
Document alert pin behavior, switch to new API. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
664a1cf0db
commit
6afbd053e4
4 changed files with 43 additions and 21 deletions
|
@ -16,6 +16,29 @@ extern struct isl29035_driver_data isl29035_data;
|
||||||
|
|
||||||
LOG_MODULE_DECLARE(ISL29035, CONFIG_SENSOR_LOG_LEVEL);
|
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)
|
static u16_t isl29035_lux_processed_to_raw(struct sensor_value const *val)
|
||||||
{
|
{
|
||||||
u64_t raw_val;
|
u64_t raw_val;
|
||||||
|
@ -65,15 +88,9 @@ static void isl29035_gpio_callback(struct device *dev,
|
||||||
struct isl29035_driver_data *drv_data =
|
struct isl29035_driver_data *drv_data =
|
||||||
CONTAINER_OF(cb, struct isl29035_driver_data, gpio_cb);
|
CONTAINER_OF(cb, struct isl29035_driver_data, gpio_cb);
|
||||||
|
|
||||||
|
|
||||||
ARG_UNUSED(pins);
|
ARG_UNUSED(pins);
|
||||||
|
handle_int(drv_data);
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void isl29035_thread_cb(struct device *dev)
|
static void isl29035_thread_cb(struct device *dev)
|
||||||
|
@ -92,8 +109,7 @@ static void isl29035_thread_cb(struct device *dev)
|
||||||
drv_data->th_handler(dev, &drv_data->th_trigger);
|
drv_data->th_handler(dev, &drv_data->th_trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio_pin_enable_callback(drv_data->gpio,
|
setup_int(drv_data, true);
|
||||||
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_ISL29035_TRIGGER_OWN_THREAD
|
#ifdef CONFIG_ISL29035_TRIGGER_OWN_THREAD
|
||||||
|
@ -128,15 +144,17 @@ int isl29035_trigger_set(struct device *dev,
|
||||||
struct isl29035_driver_data *drv_data = dev->driver_data;
|
struct isl29035_driver_data *drv_data = dev->driver_data;
|
||||||
|
|
||||||
/* disable interrupt callback while changing parameters */
|
/* disable interrupt callback while changing parameters */
|
||||||
gpio_pin_disable_callback(drv_data->gpio,
|
setup_int(drv_data, false);
|
||||||
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);
|
|
||||||
|
|
||||||
drv_data->th_handler = handler;
|
drv_data->th_handler = handler;
|
||||||
drv_data->th_trigger = *trig;
|
drv_data->th_trigger = *trig;
|
||||||
|
|
||||||
/* enable interrupt callback */
|
/* enable interrupt callback */
|
||||||
gpio_pin_enable_callback(drv_data->gpio,
|
setup_int(drv_data, true);
|
||||||
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);
|
if (gpio_pin_get(drv_data->gpio,
|
||||||
|
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN) > 0) {
|
||||||
|
handle_int(drv_data);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -162,10 +180,8 @@ int isl29035_init_interrupt(struct device *dev)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio_pin_configure(drv_data->gpio,
|
gpio_pin_configure(drv_data->gpio, DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN,
|
||||||
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN,
|
GPIO_INPUT | DT_INST_0_ISIL_ISL29035_INT_GPIOS_FLAGS);
|
||||||
GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL |
|
|
||||||
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);
|
|
||||||
|
|
||||||
gpio_init_callback(&drv_data->gpio_cb,
|
gpio_init_callback(&drv_data->gpio_cb,
|
||||||
isl29035_gpio_callback,
|
isl29035_gpio_callback,
|
||||||
|
@ -189,5 +205,7 @@ int isl29035_init_interrupt(struct device *dev)
|
||||||
drv_data->dev = dev;
|
drv_data->dev = dev;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
setup_int(drv_data, true);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,3 +13,7 @@ properties:
|
||||||
int-gpios:
|
int-gpios:
|
||||||
type: phandle-array
|
type: phandle-array
|
||||||
required: false
|
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.
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
compatible = "isil,isl29035";
|
compatible = "isil,isl29035";
|
||||||
reg = <0x44>;
|
reg = <0x44>;
|
||||||
label = "ISL29035";
|
label = "ISL29035";
|
||||||
int-gpios = <&gpio0 11 GPIO_INT_ACTIVE_HIGH>;
|
int-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,14 +15,14 @@
|
||||||
static volatile bool alerted;
|
static volatile bool alerted;
|
||||||
struct k_sem sem;
|
struct k_sem sem;
|
||||||
|
|
||||||
#ifdef CONFIG_ISL29035_TRIGGER
|
|
||||||
static void trigger_handler(struct device *dev,
|
static void trigger_handler(struct device *dev,
|
||||||
struct sensor_trigger *trig)
|
struct sensor_trigger *trig)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_ISL29035_TRIGGER
|
||||||
alerted = !alerted;
|
alerted = !alerted;
|
||||||
k_sem_give(&sem);
|
k_sem_give(&sem);
|
||||||
}
|
|
||||||
#endif /* CONFIG_ISL29035_TRIGGER */
|
#endif /* CONFIG_ISL29035_TRIGGER */
|
||||||
|
}
|
||||||
|
|
||||||
static const char *now_str(void)
|
static const char *now_str(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue