drivers: sensor: bmg160: Store sensor trigger as a pointer
Fixes the bmg160 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm <maureen.helm@intel.com>
This commit is contained in:
parent
7875025cdb
commit
666a0dffd2
|
@ -198,7 +198,9 @@ struct bmg160_device_data {
|
|||
#endif
|
||||
#ifdef CONFIG_BMG160_TRIGGER
|
||||
sensor_trigger_handler_t anymotion_handler;
|
||||
const struct sensor_trigger *anymotion_trig;
|
||||
sensor_trigger_handler_t drdy_handler;
|
||||
const struct sensor_trigger *drdy_trig;
|
||||
#endif
|
||||
int16_t raw_gyro_xyz[3];
|
||||
uint16_t scale;
|
||||
|
|
|
@ -45,6 +45,7 @@ static void bmg160_gpio_callback(const struct device *port,
|
|||
}
|
||||
|
||||
static int bmg160_anymotion_set(const struct device *dev,
|
||||
const struct sensor_trigger *trig,
|
||||
sensor_trigger_handler_t handler)
|
||||
{
|
||||
struct bmg160_device_data *bmg160 = dev->data;
|
||||
|
@ -62,11 +63,13 @@ static int bmg160_anymotion_set(const struct device *dev,
|
|||
}
|
||||
|
||||
bmg160->anymotion_handler = handler;
|
||||
bmg160->anymotion_trig = trig;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bmg160_drdy_set(const struct device *dev,
|
||||
const struct sensor_trigger *trig,
|
||||
sensor_trigger_handler_t handler)
|
||||
{
|
||||
struct bmg160_device_data *bmg160 = dev->data;
|
||||
|
@ -78,6 +81,7 @@ static int bmg160_drdy_set(const struct device *dev,
|
|||
}
|
||||
|
||||
bmg160->drdy_handler = handler;
|
||||
bmg160->drdy_trig = trig;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -128,9 +132,9 @@ int bmg160_trigger_set(const struct device *dev,
|
|||
}
|
||||
|
||||
if (trig->type == SENSOR_TRIG_DELTA) {
|
||||
return bmg160_anymotion_set(dev, handler);
|
||||
return bmg160_anymotion_set(dev, trig, handler);
|
||||
} else if (trig->type == SENSOR_TRIG_DATA_READY) {
|
||||
return bmg160_drdy_set(dev, handler);
|
||||
return bmg160_drdy_set(dev, trig, handler);
|
||||
}
|
||||
|
||||
return -ENOTSUP;
|
||||
|
@ -139,13 +143,9 @@ int bmg160_trigger_set(const struct device *dev,
|
|||
static int bmg160_handle_anymotion_int(const struct device *dev)
|
||||
{
|
||||
struct bmg160_device_data *bmg160 = dev->data;
|
||||
struct sensor_trigger any_trig = {
|
||||
.type = SENSOR_TRIG_DELTA,
|
||||
.chan = SENSOR_CHAN_GYRO_XYZ,
|
||||
};
|
||||
|
||||
if (bmg160->anymotion_handler) {
|
||||
bmg160->anymotion_handler(dev, &any_trig);
|
||||
bmg160->anymotion_handler(dev, bmg160->anymotion_trig);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -154,13 +154,9 @@ static int bmg160_handle_anymotion_int(const struct device *dev)
|
|||
static int bmg160_handle_dataready_int(const struct device *dev)
|
||||
{
|
||||
struct bmg160_device_data *bmg160 = dev->data;
|
||||
struct sensor_trigger drdy_trig = {
|
||||
.type = SENSOR_TRIG_DATA_READY,
|
||||
.chan = SENSOR_CHAN_GYRO_XYZ,
|
||||
};
|
||||
|
||||
if (bmg160->drdy_handler) {
|
||||
bmg160->drdy_handler(dev, &drdy_trig);
|
||||
bmg160->drdy_handler(dev, bmg160->drdy_trig);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue