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:
parent
ab859fabc1
commit
ff4294a7fe
5 changed files with 44 additions and 18 deletions
|
@ -94,7 +94,7 @@
|
||||||
compatible = "st,hts221";
|
compatible = "st,hts221";
|
||||||
reg = <0x5f>;
|
reg = <0x5f>;
|
||||||
label = "HTS221";
|
label = "HTS221";
|
||||||
drdy-gpios = <&gpioa 2 GPIO_ACTIVE_LOW>;
|
drdy-gpios = <&gpioa 2 GPIO_ACTIVE_HIGH>;
|
||||||
};
|
};
|
||||||
|
|
||||||
lps22hb-press@5d {
|
lps22hb-press@5d {
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
compatible = "st,hts221";
|
compatible = "st,hts221";
|
||||||
reg = <0x5f>;
|
reg = <0x5f>;
|
||||||
label = "HTS221";
|
label = "HTS221";
|
||||||
drdy-gpios = <&gpio0 24 0>;
|
drdy-gpios = <&gpio0 24 GPIO_ACTIVE_HIGH>;
|
||||||
};
|
};
|
||||||
|
|
||||||
ccs811: ccs811@5a {
|
ccs811: ccs811@5a {
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
compatible = "st,hts221";
|
compatible = "st,hts221";
|
||||||
reg = <0x5f>;
|
reg = <0x5f>;
|
||||||
label = "HTS221";
|
label = "HTS221";
|
||||||
drdy-gpios = <&gpiod 13 GPIO_ACTIVE_LOW>;
|
drdy-gpios = <&gpiod 13 GPIO_ACTIVE_HIGH>;
|
||||||
};
|
};
|
||||||
|
|
||||||
lps22hh@5d {
|
lps22hh@5d {
|
||||||
|
|
|
@ -15,6 +15,29 @@
|
||||||
|
|
||||||
LOG_MODULE_DECLARE(HTS221, CONFIG_SENSOR_LOG_LEVEL);
|
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,
|
int hts221_trigger_set(struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler)
|
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);
|
__ASSERT_NO_MSG(trig->type == SENSOR_TRIG_DATA_READY);
|
||||||
|
|
||||||
gpio_pin_disable_callback(drv_data->gpio,
|
setup_drdy(drv_data, false);
|
||||||
DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN);
|
|
||||||
|
|
||||||
drv_data->data_ready_handler = handler;
|
drv_data->data_ready_handler = handler;
|
||||||
if (handler == NULL) {
|
if (handler == NULL) {
|
||||||
|
@ -33,8 +55,15 @@ int hts221_trigger_set(struct device *dev,
|
||||||
|
|
||||||
drv_data->data_ready_trigger = *trig;
|
drv_data->data_ready_trigger = *trig;
|
||||||
|
|
||||||
gpio_pin_enable_callback(drv_data->gpio,
|
setup_drdy(drv_data, true);
|
||||||
DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN);
|
|
||||||
|
/* 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -47,13 +76,7 @@ static void hts221_gpio_callback(struct device *dev,
|
||||||
|
|
||||||
ARG_UNUSED(pins);
|
ARG_UNUSED(pins);
|
||||||
|
|
||||||
gpio_pin_disable_callback(dev, DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN);
|
handle_drdy(drv_data);
|
||||||
|
|
||||||
#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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hts221_thread_cb(void *arg)
|
static void hts221_thread_cb(void *arg)
|
||||||
|
@ -66,7 +89,7 @@ static void hts221_thread_cb(void *arg)
|
||||||
&drv_data->data_ready_trigger);
|
&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
|
#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_pin_configure(drv_data->gpio, DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN,
|
||||||
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
|
GPIO_INPUT | DT_INST_0_ST_HTS221_DRDY_GPIOS_FLAGS);
|
||||||
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
|
|
||||||
|
|
||||||
gpio_init_callback(&drv_data->gpio_cb,
|
gpio_init_callback(&drv_data->gpio_cb,
|
||||||
hts221_gpio_callback,
|
hts221_gpio_callback,
|
||||||
|
@ -140,7 +162,7 @@ int hts221_init_interrupt(struct device *dev)
|
||||||
drv_data->dev = dev;
|
drv_data->dev = dev;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gpio_pin_enable_callback(drv_data->gpio, DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN);
|
setup_drdy(drv_data, true);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,3 +12,7 @@ properties:
|
||||||
type: phandle-array
|
type: phandle-array
|
||||||
required: false
|
required: false
|
||||||
description: DRDY pin
|
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.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue