drivers: sensor: hts221: update to new GPIO API

Correct DRDY active level to default active-high, switch to new
interrupt configuration.

Also fix a common bug where an already-active DRDY signal is not
properly handled.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2019-10-15 08:53:18 -05:00 committed by Carles Cufí
commit ff4294a7fe
5 changed files with 44 additions and 18 deletions

View file

@ -94,7 +94,7 @@
compatible = "st,hts221";
reg = <0x5f>;
label = "HTS221";
drdy-gpios = <&gpioa 2 GPIO_ACTIVE_LOW>;
drdy-gpios = <&gpioa 2 GPIO_ACTIVE_HIGH>;
};
lps22hb-press@5d {

View file

@ -111,7 +111,7 @@
compatible = "st,hts221";
reg = <0x5f>;
label = "HTS221";
drdy-gpios = <&gpio0 24 0>;
drdy-gpios = <&gpio0 24 GPIO_ACTIVE_HIGH>;
};
ccs811: ccs811@5a {

View file

@ -55,7 +55,7 @@
compatible = "st,hts221";
reg = <0x5f>;
label = "HTS221";
drdy-gpios = <&gpiod 13 GPIO_ACTIVE_LOW>;
drdy-gpios = <&gpiod 13 GPIO_ACTIVE_HIGH>;
};
lps22hh@5d {

View file

@ -15,6 +15,29 @@
LOG_MODULE_DECLARE(HTS221, CONFIG_SENSOR_LOG_LEVEL);
static inline void setup_drdy(struct hts221_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_ST_HTS221_DRDY_GPIOS_PIN,
flags);
}
static inline void handle_drdy(struct hts221_data *drv_data)
{
setup_drdy(drv_data, false);
#if defined(CONFIG_HTS221_TRIGGER_OWN_THREAD)
k_sem_give(&drv_data->gpio_sem);
#elif defined(CONFIG_HTS221_TRIGGER_GLOBAL_THREAD)
k_work_submit(&drv_data->work);
#endif
}
int hts221_trigger_set(struct device *dev,
const struct sensor_trigger *trig,
sensor_trigger_handler_t handler)
@ -23,8 +46,7 @@ int hts221_trigger_set(struct device *dev,
__ASSERT_NO_MSG(trig->type == SENSOR_TRIG_DATA_READY);
gpio_pin_disable_callback(drv_data->gpio,
DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN);
setup_drdy(drv_data, false);
drv_data->data_ready_handler = handler;
if (handler == NULL) {
@ -33,8 +55,15 @@ int hts221_trigger_set(struct device *dev,
drv_data->data_ready_trigger = *trig;
gpio_pin_enable_callback(drv_data->gpio,
DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN);
setup_drdy(drv_data, true);
/* If DRDY is active we probably won't get the rising edge, so
* invoke the callback manually.
*/
if (gpio_pin_get(drv_data->gpio,
DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN) > 0) {
handle_drdy(drv_data);
}
return 0;
}
@ -47,13 +76,7 @@ static void hts221_gpio_callback(struct device *dev,
ARG_UNUSED(pins);
gpio_pin_disable_callback(dev, DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN);
#if defined(CONFIG_HTS221_TRIGGER_OWN_THREAD)
k_sem_give(&drv_data->gpio_sem);
#elif defined(CONFIG_HTS221_TRIGGER_GLOBAL_THREAD)
k_work_submit(&drv_data->work);
#endif
handle_drdy(drv_data);
}
static void hts221_thread_cb(void *arg)
@ -66,7 +89,7 @@ static void hts221_thread_cb(void *arg)
&drv_data->data_ready_trigger);
}
gpio_pin_enable_callback(drv_data->gpio, DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN);
setup_drdy(drv_data, true);
}
#ifdef CONFIG_HTS221_TRIGGER_OWN_THREAD
@ -108,8 +131,7 @@ int hts221_init_interrupt(struct device *dev)
}
gpio_pin_configure(drv_data->gpio, DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
GPIO_INPUT | DT_INST_0_ST_HTS221_DRDY_GPIOS_FLAGS);
gpio_init_callback(&drv_data->gpio_cb,
hts221_gpio_callback,
@ -140,7 +162,7 @@ int hts221_init_interrupt(struct device *dev)
drv_data->dev = dev;
#endif
gpio_pin_enable_callback(drv_data->gpio, DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN);
setup_drdy(drv_data, true);
return 0;
}

View file

@ -12,3 +12,7 @@ properties:
type: phandle-array
required: false
description: DRDY pin
This pin defaults to active high when produced by the sensor.
The property value should ensure the flags properly describe
the signal that is presented to the driver.