drivers: sensor: Fix device instance const qualifier loss

It is necessary to wrap the device pointer into data.
Which was done already on most of them when global trigger is enabled.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2020-07-09 09:13:48 +02:00 committed by Carles Cufí
commit d00d86972a
76 changed files with 350 additions and 546 deletions

View file

@ -77,16 +77,11 @@ static void adt7420_gpio_callback(const struct device *dev,
}
#if defined(CONFIG_ADT7420_TRIGGER_OWN_THREAD)
static void adt7420_thread(int dev_ptr, int unused)
static void adt7420_thread(struct adt7420_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct adt7420_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (true) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
process_int(dev);
process_int(drv_data->dev);
}
}
@ -165,8 +160,8 @@ int adt7420_init_interrupt(const struct device *dev)
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_ADT7420_THREAD_STACK_SIZE,
(k_thread_entry_t)adt7420_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_ADT7420_THREAD_PRIORITY),
(k_thread_entry_t)adt7420_thread, drv_data,
NULL, NULL, K_PRIO_COOP(CONFIG_ADT7420_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_ADT7420_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = adt7420_work_cb;

View file

@ -201,6 +201,7 @@ struct adxl362_data {
uint8_t selected_range;
#if defined(CONFIG_ADXL362_TRIGGER)
const struct device *dev;
const struct device *gpio;
struct gpio_callback gpio_cb;
struct k_mutex trigger_mutex;
@ -216,7 +217,6 @@ struct adxl362_data {
struct k_thread thread;
#elif defined(CONFIG_ADXL362_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif
#endif /* CONFIG_ADXL362_TRIGGER */
};

View file

@ -17,9 +17,8 @@
#include <logging/log.h>
LOG_MODULE_DECLARE(ADXL362, CONFIG_SENSOR_LOG_LEVEL);
static void adxl362_thread_cb(void *arg)
static void adxl362_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct adxl362_data *drv_data = dev->data;
uint8_t status_buf;
@ -58,16 +57,11 @@ static void adxl362_gpio_callback(const struct device *dev,
}
#if defined(CONFIG_ADXL362_TRIGGER_OWN_THREAD)
static void adxl362_thread(int dev_ptr, int unused)
static void adxl362_thread(struct adxl362_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct adxl362_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (true) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
adxl362_thread_cb(dev);
adxl362_thread_cb(drv_data->dev);
}
}
#elif defined(CONFIG_ADXL362_TRIGGER_GLOBAL_THREAD)
@ -153,17 +147,18 @@ int adxl362_init_interrupt(const struct device *dev)
return -EIO;
}
drv_data->dev = dev;
#if defined(CONFIG_ADXL362_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_ADXL362_THREAD_STACK_SIZE,
(k_thread_entry_t)adxl362_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_ADXL362_THREAD_PRIORITY),
(k_thread_entry_t)adxl362_thread, drv_data,
NULL, NULL, K_PRIO_COOP(CONFIG_ADXL362_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_ADXL362_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = adxl362_work_cb;
drv_data->dev = dev;
#endif
gpio_pin_interrupt_configure(drv_data->gpio, cfg->int_gpio,

View file

@ -16,9 +16,8 @@
#include <logging/log.h>
LOG_MODULE_DECLARE(ADXL372, CONFIG_SENSOR_LOG_LEVEL);
static void adxl372_thread_cb(void *arg)
static void adxl372_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct adxl372_data *drv_data = dev->data;
const struct adxl372_dev_config *cfg = dev->config;
uint8_t status1, status2;
@ -69,16 +68,11 @@ static void adxl372_gpio_callback(const struct device *dev,
}
#if defined(CONFIG_ADXL372_TRIGGER_OWN_THREAD)
static void adxl372_thread(int dev_ptr, int unused)
static void adxl372_thread(struct adxl372_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct adxl372_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (true) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
adxl372_thread_cb(dev);
adxl372_thread_cb(drv_data->dev);
}
}
@ -168,8 +162,8 @@ int adxl372_init_interrupt(const struct device *dev)
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_ADXL372_THREAD_STACK_SIZE,
(k_thread_entry_t)adxl372_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_ADXL372_THREAD_PRIORITY),
(k_thread_entry_t)adxl372_thread, drv_data,
NULL, NULL, K_PRIO_COOP(CONFIG_ADXL372_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_ADXL372_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = adxl372_work_cb;

View file

@ -81,6 +81,7 @@ struct amg88xx_data {
int16_t sample[64];
#ifdef CONFIG_AMG88XX_TRIGGER
const struct device *dev;
const struct device *gpio;
uint8_t gpio_pin;
struct gpio_callback gpio_cb;
@ -97,7 +98,6 @@ struct amg88xx_data {
struct k_thread thread;
#elif defined(CONFIG_AMG88XX_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif
#endif /* CONFIG_AMG88XX_TRIGGER */

View file

@ -88,9 +88,8 @@ static void amg88xx_gpio_callback(const struct device *dev,
#endif
}
static void amg88xx_thread_cb(void *arg)
static void amg88xx_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct amg88xx_data *drv_data = dev->data;
const struct amg88xx_config *config = dev->config;
uint8_t status;
@ -112,16 +111,11 @@ static void amg88xx_thread_cb(void *arg)
}
#ifdef CONFIG_AMG88XX_TRIGGER_OWN_THREAD
static void amg88xx_thread(int dev_ptr, int unused)
static void amg88xx_thread(struct amg88xx_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct amg88xx_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (42) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
amg88xx_thread_cb(dev);
amg88xx_thread_cb(drv_data->dev);
}
}
#endif
@ -194,17 +188,18 @@ int amg88xx_init_interrupt(const struct device *dev)
return -EIO;
}
drv_data->dev = dev;
#if defined(CONFIG_AMG88XX_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_AMG88XX_THREAD_STACK_SIZE,
(k_thread_entry_t)amg88xx_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_AMG88XX_THREAD_PRIORITY),
(k_thread_entry_t)amg88xx_thread, drv_data,
NULL, NULL, K_PRIO_COOP(CONFIG_AMG88XX_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_AMG88XX_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = amg88xx_work_cb;
drv_data->dev = dev;
#endif
amg88xx_setup_int(drv_data, true);

View file

@ -84,9 +84,8 @@ static void bma280_gpio_callback(const struct device *dev,
#endif
}
static void bma280_thread_cb(void *arg)
static void bma280_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct bma280_data *drv_data = dev->data;
uint8_t status = 0U;
int err = 0;
@ -126,16 +125,11 @@ static void bma280_thread_cb(void *arg)
}
#ifdef CONFIG_BMA280_TRIGGER_OWN_THREAD
static void bma280_thread(int dev_ptr, int unused)
static void bma280_thread(struct bma280_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct bma280_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
bma280_thread_cb(dev);
bma280_thread_cb(drv_data->dev);
}
}
#endif
@ -285,8 +279,8 @@ int bma280_init_interrupt(const struct device *dev)
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_BMA280_THREAD_STACK_SIZE,
(k_thread_entry_t)bma280_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_BMA280_THREAD_PRIORITY),
(k_thread_entry_t)bma280_thread, drv_data,
NULL, NULL, K_PRIO_COOP(CONFIG_BMA280_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = bma280_work_cb;

View file

@ -82,11 +82,9 @@ static void bmc150_magn_gpio_drdy_callback(const struct device *dev,
k_sem_give(&data->sem);
}
static void bmc150_magn_thread_main(void *arg1, void *arg2, void *arg3)
static void bmc150_magn_thread_main(struct bmc150_magn_data *data)
{
const struct device *dev = (const struct device *) arg1;
struct bmc150_magn_data *data = dev->data;
const struct bmc150_magn_config *config = dev->config;
const struct bmc150_magn_config *config = data->dev->config;
uint8_t reg_val;
while (1) {
@ -100,10 +98,10 @@ static void bmc150_magn_thread_main(void *arg1, void *arg2, void *arg3)
}
if (data->handler_drdy) {
data->handler_drdy(dev, &data->trigger_drdy);
data->handler_drdy(data->dev, &data->trigger_drdy);
}
setup_drdy(dev, true);
setup_drdy(data->dev, true);
}
}
@ -150,7 +148,8 @@ int bmc150_magn_init_interrupt(const struct device *dev)
k_thread_create(&data->thread, data->thread_stack,
CONFIG_BMC150_MAGN_TRIGGER_THREAD_STACK,
bmc150_magn_thread_main, dev, NULL, NULL,
(k_thread_entry_t)bmc150_magn_thread_main,
data, NULL, NULL,
K_PRIO_COOP(10), 0, K_NO_WAIT);
data->gpio_drdy = device_get_binding(config->gpio_drdy_dev_name);

View file

@ -191,6 +191,7 @@ struct bmg160_device_config {
struct bmg160_device_data {
const struct device *i2c;
#ifdef CONFIG_BMG160_TRIGGER
const struct device *dev;
const struct device *gpio;
struct gpio_callback gpio_cb;
#endif
@ -200,7 +201,6 @@ struct bmg160_device_data {
struct k_sem sem;
#ifdef CONFIG_BMG160_TRIGGER_GLOBAL_THREAD
struct k_work work;
const struct device *dev;
#endif
#ifdef CONFIG_BMG160_TRIGGER
sensor_trigger_handler_t anymotion_handler;

View file

@ -165,9 +165,8 @@ static int bmg160_handle_dataready_int(const struct device *dev)
return 0;
}
static void bmg160_handle_int(void *arg)
static void bmg160_handle_int(const struct device *dev)
{
const struct device *dev = (const struct device *)arg;
uint8_t status_int[4];
if (bmg160_read(dev, BMG160_REG_INT_STATUS0, status_int, 4) < 0) {
@ -185,15 +184,12 @@ static void bmg160_handle_int(void *arg)
static K_KERNEL_STACK_DEFINE(bmg160_thread_stack, CONFIG_BMG160_THREAD_STACK_SIZE);
static struct k_thread bmg160_thread;
static void bmg160_thread_main(void *arg1, void *arg2, void *arg3)
static void bmg160_thread_main(struct bmg160_device_data *bmg160)
{
const struct device *dev = (const struct device *)arg1;
struct bmg160_device_data *bmg160 = dev->data;
while (true) {
k_sem_take(&bmg160->trig_sem, K_FOREVER);
bmg160_handle_int(dev);
bmg160_handle_int(bmg160->dev);
}
}
#endif
@ -246,17 +242,19 @@ int bmg160_trigger_init(const struct device *dev)
return -EINVAL;
}
bmg160->dev = dev;
#if defined(CONFIG_BMG160_TRIGGER_OWN_THREAD)
k_sem_init(&bmg160->trig_sem, 0, UINT_MAX);
k_thread_create(&bmg160_thread, bmg160_thread_stack,
CONFIG_BMG160_THREAD_STACK_SIZE, bmg160_thread_main,
dev, NULL, NULL,
CONFIG_BMG160_THREAD_STACK_SIZE,
(k_thread_entry_t)bmg160_thread_main,
bmg160, NULL, NULL,
K_PRIO_COOP(CONFIG_BMG160_THREAD_PRIORITY), 0,
K_NO_WAIT);
#elif defined(CONFIG_BMG160_TRIGGER_GLOBAL_THREAD)
bmg160->work.handler = bmg160_work_cb;
bmg160->dev = dev;
#endif
gpio_pin_configure(bmg160->gpio, cfg->int_pin,

View file

@ -431,6 +431,7 @@ struct bmi160_device_data {
const struct device *spi;
struct spi_config spi_cfg;
#if defined(CONFIG_BMI160_TRIGGER)
const struct device *dev;
const struct device *gpio;
struct gpio_callback gpio_cb;
#endif
@ -444,7 +445,6 @@ struct bmi160_device_data {
#ifdef CONFIG_BMI160_TRIGGER_GLOBAL_THREAD
struct k_work work;
const struct device *dev;
#endif
#ifdef CONFIG_BMI160_TRIGGER

View file

@ -49,10 +49,8 @@ static void bmi160_handle_drdy(const struct device *dev, uint8_t status)
#endif
}
static void bmi160_handle_interrupts(void *arg)
static void bmi160_handle_interrupts(const struct device *dev)
{
const struct device *dev = (const struct device *)arg;
union {
uint8_t raw[6];
struct {
@ -83,16 +81,11 @@ static void bmi160_handle_interrupts(void *arg)
static K_KERNEL_STACK_DEFINE(bmi160_thread_stack, CONFIG_BMI160_THREAD_STACK_SIZE);
static struct k_thread bmi160_thread;
static void bmi160_thread_main(void *arg1, void *unused1, void *unused2)
static void bmi160_thread_main(struct bmi160_device_data *bmi160)
{
ARG_UNUSED(unused1);
ARG_UNUSED(unused2);
const struct device *dev = (const struct device *)arg1;
struct bmi160_device_data *bmi160 = dev->data;
while (1) {
k_sem_take(&bmi160->sem, K_FOREVER);
bmi160_handle_interrupts(dev);
bmi160_handle_interrupts(bmi160->dev);
}
}
#endif
@ -283,16 +276,19 @@ int bmi160_trigger_mode_init(const struct device *dev)
return -EINVAL;
}
bmi160->dev = dev;
#if defined(CONFIG_BMI160_TRIGGER_OWN_THREAD)
k_sem_init(&bmi160->sem, 0, UINT_MAX);
k_thread_create(&bmi160_thread, bmi160_thread_stack,
CONFIG_BMI160_THREAD_STACK_SIZE,
bmi160_thread_main, dev, NULL, NULL,
K_PRIO_COOP(CONFIG_BMI160_THREAD_PRIORITY), 0, K_NO_WAIT);
(k_thread_entry_t)bmi160_thread_main,
bmi160, NULL, NULL,
K_PRIO_COOP(CONFIG_BMI160_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_BMI160_TRIGGER_GLOBAL_THREAD)
bmi160->work.handler = bmi160_work_handler;
bmi160->dev = dev;
#endif
/* map all interrupts to INT1 pin */

View file

@ -95,16 +95,11 @@ static void gpio_callback(const struct device *dev,
}
#ifdef CONFIG_CCS811_TRIGGER_OWN_THREAD
static void irq_thread(int dev_ptr, int unused)
static void irq_thread(struct ccs811_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct ccs811_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
process_irq(dev);
process_irq(drv_data->dev);
}
}
#elif defined(CONFIG_CCS811_TRIGGER_GLOBAL_THREAD)
@ -189,8 +184,8 @@ int ccs811_init_interrupt(const struct device *dev)
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_CCS811_THREAD_STACK_SIZE,
(k_thread_entry_t)irq_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_CCS811_THREAD_PRIORITY),
(k_thread_entry_t)irq_thread, drv_data,
NULL, NULL, K_PRIO_COOP(CONFIG_CCS811_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_CCS811_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = work_cb;

View file

@ -73,6 +73,7 @@ struct fxas21002_data {
const struct device *i2c;
struct k_sem sem;
#ifdef CONFIG_FXAS21002_TRIGGER
const struct device *dev;
const struct device *gpio;
uint8_t gpio_pin;
struct gpio_callback gpio_cb;
@ -85,7 +86,6 @@ struct fxas21002_data {
#endif
#ifdef CONFIG_FXAS21002_TRIGGER_GLOBAL_THREAD
struct k_work work;
const struct device *dev;
#endif
int16_t raw[FXAS21002_MAX_NUM_CHANNELS];
};

View file

@ -47,9 +47,8 @@ static int fxas21002_handle_drdy_int(const struct device *dev)
return 0;
}
static void fxas21002_handle_int(void *arg)
static void fxas21002_handle_int(const struct device *dev)
{
const struct device *dev = (const struct device *)arg;
const struct fxas21002_config *config = dev->config;
struct fxas21002_data *data = dev->data;
uint8_t int_source;
@ -74,17 +73,11 @@ static void fxas21002_handle_int(void *arg)
}
#ifdef CONFIG_FXAS21002_TRIGGER_OWN_THREAD
static void fxas21002_thread_main(void *arg1, void *unused1, void *unused2)
static void fxas21002_thread_main(struct fxas21002_data *data)
{
const struct device *dev = (const struct device *)arg1;
struct fxas21002_data *data = dev->data;
ARG_UNUSED(unused1);
ARG_UNUSED(unused2);
while (true) {
k_sem_take(&data->trig_sem, K_FOREVER);
fxas21002_handle_int(dev);
fxas21002_handle_int(data->dev);
}
}
#endif
@ -175,15 +168,17 @@ int fxas21002_trigger_init(const struct device *dev)
struct fxas21002_data *data = dev->data;
uint8_t ctrl_reg2;
data->dev = dev;
#if defined(CONFIG_FXAS21002_TRIGGER_OWN_THREAD)
k_sem_init(&data->trig_sem, 0, UINT_MAX);
k_thread_create(&data->thread, data->thread_stack,
CONFIG_FXAS21002_THREAD_STACK_SIZE,
fxas21002_thread_main, dev, 0, NULL,
K_PRIO_COOP(CONFIG_FXAS21002_THREAD_PRIORITY), 0, K_NO_WAIT);
(k_thread_entry_t)fxas21002_thread_main, data, 0, NULL,
K_PRIO_COOP(CONFIG_FXAS21002_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_FXAS21002_TRIGGER_GLOBAL_THREAD)
data->work.handler = fxas21002_work_handler;
data->dev = dev;
#endif
/* Route the interrupts to INT1/INT2 pins */

View file

@ -164,6 +164,7 @@ struct fxos8700_data {
const struct device *i2c;
struct k_sem sem;
#ifdef CONFIG_FXOS8700_TRIGGER
const struct device *dev;
const struct device *gpio;
uint8_t gpio_pin;
struct gpio_callback gpio_cb;
@ -186,7 +187,6 @@ struct fxos8700_data {
#endif
#ifdef CONFIG_FXOS8700_TRIGGER_GLOBAL_THREAD
struct k_work work;
const struct device *dev;
#endif
int16_t raw[FXOS8700_MAX_NUM_CHANNELS];
#ifdef CONFIG_FXOS8700_TEMP

View file

@ -134,9 +134,8 @@ static int fxos8700_handle_m_vecm_int(const struct device *dev)
}
#endif
static void fxos8700_handle_int(void *arg)
static void fxos8700_handle_int(const struct device *dev)
{
const struct device *dev = (const struct device *)arg;
const struct fxos8700_config *config = dev->config;
struct fxos8700_data *data = dev->data;
uint8_t int_source;
@ -189,17 +188,11 @@ static void fxos8700_handle_int(void *arg)
}
#ifdef CONFIG_FXOS8700_TRIGGER_OWN_THREAD
static void fxos8700_thread_main(void *arg1, void *unused1, void *unused2)
static void fxos8700_thread_main(struct fxos8700_data *data)
{
const struct device *dev = (const struct device *)arg1;
struct fxos8700_data *data = dev->data;
ARG_UNUSED(unused1);
ARG_UNUSED(unused2);
while (true) {
k_sem_take(&data->trig_sem, K_FOREVER);
fxos8700_handle_int(dev);
fxos8700_handle_int(data->dev);
}
}
#endif
@ -416,15 +409,18 @@ int fxos8700_trigger_init(const struct device *dev)
struct fxos8700_data *data = dev->data;
uint8_t ctrl_reg5;
data->dev = dev;
#if defined(CONFIG_FXOS8700_TRIGGER_OWN_THREAD)
k_sem_init(&data->trig_sem, 0, UINT_MAX);
k_thread_create(&data->thread, data->thread_stack,
CONFIG_FXOS8700_THREAD_STACK_SIZE,
fxos8700_thread_main, dev, 0, NULL,
K_PRIO_COOP(CONFIG_FXOS8700_THREAD_PRIORITY), 0, K_NO_WAIT);
(k_thread_entry_t)fxos8700_thread_main,
data, NULL, NULL,
K_PRIO_COOP(CONFIG_FXOS8700_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_FXOS8700_TRIGGER_GLOBAL_THREAD)
data->work.handler = fxos8700_work_handler;
data->dev = dev;
#endif
/* Route the interrupts to INT1/INT2 pins */

View file

@ -48,6 +48,7 @@ struct hmc5883l_data {
uint8_t gain_idx;
#ifdef CONFIG_HMC5883L_TRIGGER
const struct device *dev;
const struct device *gpio;
struct gpio_callback gpio_cb;
@ -60,7 +61,6 @@ struct hmc5883l_data {
struct k_sem gpio_sem;
#elif defined(CONFIG_HMC5883L_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif
#endif /* CONFIG_HMC5883L_TRIGGER */

View file

@ -62,9 +62,8 @@ static void hmc5883l_gpio_callback(const struct device *dev,
#endif
}
static void hmc5883l_thread_cb(void *arg)
static void hmc5883l_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct hmc5883l_data *drv_data = dev->data;
if (drv_data->data_ready_handler != NULL) {
@ -78,16 +77,11 @@ static void hmc5883l_thread_cb(void *arg)
}
#ifdef CONFIG_HMC5883L_TRIGGER_OWN_THREAD
static void hmc5883l_thread(int dev_ptr, int unused)
static void hmc5883l_thread(struct hmc5883l_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct hmc5883l_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
hmc5883l_thread_cb(dev);
hmc5883l_thread_cb(drv_data->dev);
}
}
#endif
@ -129,17 +123,19 @@ int hmc5883l_init_interrupt(const struct device *dev)
return -EIO;
}
drv_data->dev = dev;
#if defined(CONFIG_HMC5883L_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_HMC5883L_THREAD_STACK_SIZE,
(k_thread_entry_t)hmc5883l_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_HMC5883L_THREAD_PRIORITY),
(k_thread_entry_t)hmc5883l_thread,
drv_data, NULL, NULL,
K_PRIO_COOP(CONFIG_HMC5883L_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_HMC5883L_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = hmc5883l_work_cb;
drv_data->dev = dev;
#endif
gpio_pin_interrupt_configure(drv_data->gpio,

View file

@ -95,16 +95,11 @@ static void hts221_drdy_callback(const struct device *dev,
}
#ifdef CONFIG_HTS221_TRIGGER_OWN_THREAD
static void hts221_thread(int dev_ptr, int unused)
static void hts221_thread(struct hts221_data *data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct hts221_data *data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&data->drdy_sem, K_FOREVER);
process_drdy(dev);
process_drdy(data->dev);
}
}
#endif
@ -157,8 +152,8 @@ int hts221_init_interrupt(const struct device *dev)
k_thread_create(&data->thread, data->thread_stack,
CONFIG_HTS221_THREAD_STACK_SIZE,
(k_thread_entry_t)hts221_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_HTS221_THREAD_PRIORITY),
(k_thread_entry_t)hts221_thread, data,
NULL, NULL, K_PRIO_COOP(CONFIG_HTS221_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_HTS221_TRIGGER_GLOBAL_THREAD)
data->work.handler = hts221_work_cb;

View file

@ -64,6 +64,7 @@ struct iis2dh_data {
stmdev_ctx_t *ctx;
#ifdef CONFIG_IIS2DH_TRIGGER
const struct device *dev;
const struct device *gpio;
uint8_t gpio_pin;
struct gpio_callback gpio_cb;
@ -74,7 +75,6 @@ struct iis2dh_data {
struct k_sem gpio_sem;
#elif defined(CONFIG_IIS2DH_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif /* CONFIG_IIS2DH_TRIGGER_GLOBAL_THREAD */
#endif /* CONFIG_IIS2DH_TRIGGER */
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)

View file

@ -79,9 +79,8 @@ static int iis2dh_handle_drdy_int(const struct device *dev)
* iis2dh_handle_interrupt - handle the drdy event
* read data and call handler if registered any
*/
static void iis2dh_handle_interrupt(void *arg)
static void iis2dh_handle_interrupt(const struct device *dev)
{
const struct device *dev = (const struct device *)arg;
struct iis2dh_data *iis2dh = dev->data;
const struct iis2dh_device_config *cfg = dev->config;
@ -112,16 +111,11 @@ static void iis2dh_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_IIS2DH_TRIGGER_OWN_THREAD
static void iis2dh_thread(int dev_ptr, int unused)
static void iis2dh_thread(struct iis2dh_data *iis2dh)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct iis2dh_data *iis2dh = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&iis2dh->gpio_sem, K_FOREVER);
iis2dh_handle_interrupt(dev);
iis2dh_handle_interrupt(iis2dh->dev);
}
}
#endif /* CONFIG_IIS2DH_TRIGGER_OWN_THREAD */
@ -150,17 +144,18 @@ int iis2dh_init_interrupt(const struct device *dev)
return -EINVAL;
}
iis2dh->dev = dev;
#if defined(CONFIG_IIS2DH_TRIGGER_OWN_THREAD)
k_sem_init(&iis2dh->gpio_sem, 0, UINT_MAX);
k_thread_create(&iis2dh->thread, iis2dh->thread_stack,
CONFIG_IIS2DH_THREAD_STACK_SIZE,
(k_thread_entry_t)iis2dh_thread, dev,
(k_thread_entry_t)iis2dh_thread, iis2dh,
0, NULL, K_PRIO_COOP(CONFIG_IIS2DH_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_IIS2DH_TRIGGER_GLOBAL_THREAD)
iis2dh->work.handler = iis2dh_work_cb;
iis2dh->dev = dev;
#endif /* CONFIG_IIS2DH_TRIGGER_OWN_THREAD */
iis2dh->gpio_pin = cfg->int_gpio_pin;

View file

@ -114,6 +114,7 @@ struct iis2dlpc_data {
stmdev_ctx_t *ctx;
#ifdef CONFIG_IIS2DLPC_TRIGGER
const struct device *dev;
const struct device *gpio;
uint8_t gpio_pin;
struct gpio_callback gpio_cb;
@ -128,7 +129,6 @@ struct iis2dlpc_data {
struct k_sem gpio_sem;
#elif defined(CONFIG_IIS2DLPC_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif /* CONFIG_IIS2DLPC_TRIGGER_GLOBAL_THREAD */
#endif /* CONFIG_IIS2DLPC_TRIGGER */
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)

View file

@ -161,9 +161,8 @@ static int iis2dlpc_handle_double_tap_int(const struct device *dev)
* iis2dlpc_handle_interrupt - handle the drdy event
* read data and call handler if registered any
*/
static void iis2dlpc_handle_interrupt(void *arg)
static void iis2dlpc_handle_interrupt(const struct device *dev)
{
const struct device *dev = (const struct device *)arg;
struct iis2dlpc_data *iis2dlpc = dev->data;
const struct iis2dlpc_device_config *cfg = dev->config;
iis2dlpc_all_sources_t sources;
@ -207,16 +206,11 @@ static void iis2dlpc_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_IIS2DLPC_TRIGGER_OWN_THREAD
static void iis2dlpc_thread(int dev_ptr, int unused)
static void iis2dlpc_thread(struct iis2dlpc_data *iis2dlpc)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct iis2dlpc_data *iis2dlpc = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&iis2dlpc->gpio_sem, K_FOREVER);
iis2dlpc_handle_interrupt(dev);
iis2dlpc_handle_interrupt(iis2dlpc->dev);
}
}
#endif /* CONFIG_IIS2DLPC_TRIGGER_OWN_THREAD */
@ -245,17 +239,18 @@ int iis2dlpc_init_interrupt(const struct device *dev)
return -EINVAL;
}
iis2dlpc->dev = dev;
#if defined(CONFIG_IIS2DLPC_TRIGGER_OWN_THREAD)
k_sem_init(&iis2dlpc->gpio_sem, 0, UINT_MAX);
k_thread_create(&iis2dlpc->thread, iis2dlpc->thread_stack,
CONFIG_IIS2DLPC_THREAD_STACK_SIZE,
(k_thread_entry_t)iis2dlpc_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_IIS2DLPC_THREAD_PRIORITY),
(k_thread_entry_t)iis2dlpc_thread, iis2dlpc,
NULL, NULL, K_PRIO_COOP(CONFIG_IIS2DLPC_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_IIS2DLPC_TRIGGER_GLOBAL_THREAD)
iis2dlpc->work.handler = iis2dlpc_work_cb;
iis2dlpc->dev = dev;
#endif /* CONFIG_IIS2DLPC_TRIGGER_OWN_THREAD */
iis2dlpc->gpio_pin = cfg->int_gpio_pin;

View file

@ -295,6 +295,8 @@ static int iis2mdc_init(const struct device *dev)
struct iis2mdc_data *iis2mdc = dev->data;
uint8_t wai;
iis2mdc->dev = dev;
if (iis2mdc_init_interface(dev)) {
return -EINVAL;
}

View file

@ -49,6 +49,7 @@ struct iis2mdc_config {
/* Sensor data */
struct iis2mdc_data {
const struct device *dev;
const struct device *bus;
uint16_t i2c_addr;
int16_t mag[3];
@ -67,7 +68,6 @@ struct iis2mdc_data {
struct gpio_callback gpio_cb;
sensor_trigger_handler_t handler_drdy;
const struct device *dev;
#if defined(CONFIG_IIS2MDC_TRIGGER_OWN_THREAD)
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_IIS2MDC_THREAD_STACK_SIZE);

View file

@ -21,21 +21,18 @@
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
LOG_MODULE_DECLARE(IIS2MDC);
static int iis2mdc_i2c_read(const struct device *dev, uint8_t reg_addr,
uint8_t *value, uint16_t len)
{
struct iis2mdc_data *data = dev->data;
const struct iis2mdc_config *cfg = dev->config;
static int iis2mdc_i2c_read(struct iis2mdc_data *data, uint8_t reg_addr,
uint8_t *value, uint16_t len)
{ const struct iis2mdc_config *cfg = data->dev->config;
return i2c_burst_read(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
}
static int iis2mdc_i2c_write(const struct device *dev, uint8_t reg_addr,
uint8_t *value, uint16_t len)
static int iis2mdc_i2c_write(struct iis2mdc_data *data, uint8_t reg_addr,
uint8_t *value, uint16_t len)
{
struct iis2mdc_data *data = dev->data;
const struct iis2mdc_config *cfg = dev->config;
const struct iis2mdc_config *cfg = data->dev->config ;
return i2c_burst_write(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
@ -49,7 +46,7 @@ int iis2mdc_i2c_init(const struct device *dev)
data->ctx_i2c.write_reg = (stmdev_write_ptr) iis2mdc_i2c_write;
data->ctx = &data->ctx_i2c;
data->ctx->handle = dev;
data->ctx->handle = data;
return 0;
}

View file

@ -21,11 +21,10 @@
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
LOG_MODULE_DECLARE(IIS2MDC);
static int iis2mdc_spi_read(const struct device *dev, uint8_t reg_addr,
static int iis2mdc_spi_read(struct iis2mdc_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct iis2mdc_data *data = dev->data;
const struct iis2mdc_config *cfg = dev->config;
const struct iis2mdc_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[2] = { reg_addr | IIS2MDC_SPI_READ, 0 };
const struct spi_buf tx_buf = {
@ -63,11 +62,10 @@ static int iis2mdc_spi_read(const struct device *dev, uint8_t reg_addr,
return 0;
}
static int iis2mdc_spi_write(const struct device *dev, uint8_t reg_addr,
static int iis2mdc_spi_write(struct iis2mdc_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct iis2mdc_data *data = dev->data;
const struct iis2mdc_config *cfg = dev->config;
const struct iis2mdc_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[1] = { reg_addr & ~IIS2MDC_SPI_READ };
const struct spi_buf tx_buf[2] = {
@ -105,7 +103,7 @@ int iis2mdc_spi_init(const struct device *dev)
data->ctx_spi.write_reg = (stmdev_write_ptr) iis2mdc_spi_write;
data->ctx = &data->ctx_spi;
data->ctx->handle = dev;
data->ctx->handle = data;
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
const struct iis2mdc_config *cfg = dev->config;

View file

@ -50,9 +50,8 @@ int iis2mdc_trigger_set(const struct device *dev,
}
/* handle the drdy event: read data and call handler if registered any */
static void iis2mdc_handle_interrupt(void *arg)
static void iis2mdc_handle_interrupt(const struct device *dev)
{
const struct device *dev = arg;
struct iis2mdc_data *iis2mdc = dev->data;
const struct iis2mdc_config *const config = dev->config;
struct sensor_trigger drdy_trigger = {
@ -86,16 +85,11 @@ static void iis2mdc_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_IIS2MDC_TRIGGER_OWN_THREAD
static void iis2mdc_thread(int dev_ptr, int unused)
static void iis2mdc_thread(struct iis2mdc_data *iis2mdc)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct iis2mdc_data *iis2mdc = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&iis2mdc->gpio_sem, K_FOREVER);
iis2mdc_handle_interrupt(dev);
iis2mdc_handle_interrupt(iis2mdc->dev);
}
}
#endif
@ -122,14 +116,13 @@ int iis2mdc_init_interrupt(const struct device *dev)
config->drdy_port);
return -EINVAL;
}
iis2mdc->dev = dev;
#if defined(CONFIG_IIS2MDC_TRIGGER_OWN_THREAD)
k_sem_init(&iis2mdc->gpio_sem, 0, UINT_MAX);
k_thread_create(&iis2mdc->thread, iis2mdc->thread_stack,
CONFIG_IIS2MDC_THREAD_STACK_SIZE,
(k_thread_entry_t)iis2mdc_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_IIS2MDC_THREAD_PRIORITY),
(k_thread_entry_t)iis2mdc_thread, iis2mdc,
NULL, NULL, K_PRIO_COOP(CONFIG_IIS2MDC_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_IIS2MDC_TRIGGER_GLOBAL_THREAD)
iis2mdc->work.handler = iis2mdc_work_cb;

View file

@ -62,9 +62,8 @@ int iis3dhhc_trigger_set(const struct device *dev,
* iis3dhhc_handle_interrupt - handle the drdy event
* read data and call handler if registered any
*/
static void iis3dhhc_handle_interrupt(void *arg)
static void iis3dhhc_handle_interrupt(const struct device *dev)
{
const struct device *dev = arg;
struct iis3dhhc_data *iis3dhhc = dev->data;
struct sensor_trigger drdy_trigger = {
.type = SENSOR_TRIG_DATA_READY,
@ -99,16 +98,11 @@ static void iis3dhhc_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_IIS3DHHC_TRIGGER_OWN_THREAD
static void iis3dhhc_thread(int dev_ptr, int unused)
static void iis3dhhc_thread(struct iis3dhhc_data *iis3dhhc)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct iis3dhhc_data *iis3dhhc = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&iis3dhhc->gpio_sem, K_FOREVER);
iis3dhhc_handle_interrupt(dev);
iis3dhhc_handle_interrupt(iis3dhhc->dev);
}
}
#endif /* CONFIG_IIS3DHHC_TRIGGER_OWN_THREAD */
@ -142,8 +136,8 @@ int iis3dhhc_init_interrupt(const struct device *dev)
k_thread_create(&iis3dhhc->thread, iis3dhhc->thread_stack,
CONFIG_IIS3DHHC_THREAD_STACK_SIZE,
(k_thread_entry_t)iis3dhhc_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_IIS3DHHC_THREAD_PRIORITY),
(k_thread_entry_t)iis3dhhc_thread, iis3dhhc,
NULL, NULL, K_PRIO_COOP(CONFIG_IIS3DHHC_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_IIS3DHHC_TRIGGER_GLOBAL_THREAD)
iis3dhhc->work.handler = iis3dhhc_work_cb;

View file

@ -115,6 +115,7 @@ struct isl29035_driver_data {
uint16_t data_sample;
#if CONFIG_ISL29035_TRIGGER
const struct device *dev;
const struct device *gpio;
struct gpio_callback gpio_cb;
@ -127,7 +128,6 @@ struct isl29035_driver_data {
struct k_sem gpio_sem;
#elif defined(CONFIG_ISL29035_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif
#endif /* CONFIG_ISL29035_TRIGGER */

View file

@ -115,16 +115,11 @@ static void isl29035_thread_cb(const struct device *dev)
}
#ifdef CONFIG_ISL29035_TRIGGER_OWN_THREAD
static void isl29035_thread(int ptr, int unused)
static void isl29035_thread(struct isl29035_driver_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(ptr);
struct isl29035_driver_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
isl29035_thread_cb(dev);
isl29035_thread_cb(drv_data->dev);
}
}
#endif
@ -194,17 +189,19 @@ int isl29035_init_interrupt(const struct device *dev)
return -EIO;
}
drv_data->dev = dev;
#if defined(CONFIG_ISL29035_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_ISL29035_THREAD_STACK_SIZE,
(k_thread_entry_t)isl29035_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_ISL29035_THREAD_PRIORITY),
(k_thread_entry_t)isl29035_thread,
drv_data, NULL, NULL,
K_PRIO_COOP(CONFIG_ISL29035_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_ISL29035_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = isl29035_work_cb;
drv_data->dev = dev;
#endif
setup_int(drv_data, true);

View file

@ -694,6 +694,8 @@ static int ism330dhcx_init_chip(const struct device *dev)
struct ism330dhcx_data *ism330dhcx = dev->data;
uint8_t chip_id;
ism330dhcx->dev = dev;
if (ism330dhcx_device_id_get(ism330dhcx->ctx, &chip_id) < 0) {
LOG_DBG("Failed reading chip id");
return -EIO;

View file

@ -138,6 +138,7 @@ struct ism330dhcx_tf {
#define ISM330DHCX_SHUB_MAX_NUM_SLVS 2
struct ism330dhcx_data {
const struct device *dev;
const struct device *bus;
int16_t acc[3];
uint32_t acc_gain;
@ -178,8 +179,6 @@ struct ism330dhcx_data {
sensor_trigger_handler_t handler_drdy_gyr;
sensor_trigger_handler_t handler_drdy_temp;
const struct device *dev;
#if defined(CONFIG_ISM330DHCX_TRIGGER_OWN_THREAD)
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_ISM330DHCX_THREAD_STACK_SIZE);
struct k_thread thread;

View file

@ -20,21 +20,19 @@
LOG_MODULE_DECLARE(ISM330DHCX, CONFIG_SENSOR_LOG_LEVEL);
static int ism330dhcx_i2c_read(const struct device *dev, uint8_t reg_addr,
static int ism330dhcx_i2c_read(struct ism330dhcx_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct ism330dhcx_data *data = dev->data;
const struct ism330dhcx_config *cfg = dev->config;
const struct ism330dhcx_config *cfg = data->dev->config;
return i2c_burst_read(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
}
static int ism330dhcx_i2c_write(const struct device *dev, uint8_t reg_addr,
static int ism330dhcx_i2c_write(struct ism330dhcx_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct ism330dhcx_data *data = dev->data;
const struct ism330dhcx_config *cfg = dev->config;
const struct ism330dhcx_config *cfg = data->dev->config;
return i2c_burst_write(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
@ -48,7 +46,7 @@ int ism330dhcx_i2c_init(const struct device *dev)
data->ctx_i2c.write_reg = (stmdev_write_ptr) ism330dhcx_i2c_write,
data->ctx = &data->ctx_i2c;
data->ctx->handle = dev;
data->ctx->handle = data;
return 0;
}

View file

@ -20,11 +20,10 @@
LOG_MODULE_DECLARE(ISM330DHCX, CONFIG_SENSOR_LOG_LEVEL);
static int ism330dhcx_spi_read(const struct device *dev, uint8_t reg_addr,
static int ism330dhcx_spi_read(struct ism330dhcx_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct ism330dhcx_data *data = dev->data;
const struct ism330dhcx_config *cfg = dev->config;
const struct ism330dhcx_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[2] = { reg_addr | ISM330DHCX_SPI_READ, 0 };
const struct spi_buf tx_buf = {
@ -62,11 +61,10 @@ static int ism330dhcx_spi_read(const struct device *dev, uint8_t reg_addr,
return 0;
}
static int ism330dhcx_spi_write(const struct device *dev, uint8_t reg_addr,
static int ism330dhcx_spi_write(struct ism330dhcx_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct ism330dhcx_data *data = dev->data;
const struct ism330dhcx_config *cfg = dev->config;
const struct ism330dhcx_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[1] = { reg_addr & ~ISM330DHCX_SPI_READ };
const struct spi_buf tx_buf[2] = {
@ -104,7 +102,7 @@ int ism330dhcx_spi_init(const struct device *dev)
data->ctx_spi.write_reg = (stmdev_write_ptr) ism330dhcx_spi_write,
data->ctx = &data->ctx_spi;
data->ctx->handle = dev;
data->ctx->handle = data;
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
const struct ism330dhcx_config *cfg = dev->config;

View file

@ -161,9 +161,8 @@ int ism330dhcx_trigger_set(const struct device *dev,
* ism330dhcx_handle_interrupt - handle the drdy event
* read data and call handler if registered any
*/
static void ism330dhcx_handle_interrupt(void *arg)
static void ism330dhcx_handle_interrupt(const struct device *dev)
{
const struct device *dev = arg;
struct ism330dhcx_data *ism330dhcx = dev->data;
struct sensor_trigger drdy_trigger = {
.type = SENSOR_TRIG_DATA_READY,
@ -224,16 +223,11 @@ static void ism330dhcx_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_ISM330DHCX_TRIGGER_OWN_THREAD
static void ism330dhcx_thread(int dev_ptr, int unused)
static void ism330dhcx_thread(struct ism330dhcx_data *ism330dhcx)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct ism330dhcx_data *ism330dhcx = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&ism330dhcx->gpio_sem, K_FOREVER);
ism330dhcx_handle_interrupt(dev);
ism330dhcx_handle_interrupt(ism330dhcx->dev);
}
}
#endif /* CONFIG_ISM330DHCX_TRIGGER_OWN_THREAD */
@ -260,15 +254,15 @@ int ism330dhcx_init_interrupt(const struct device *dev)
LOG_ERR("Cannot get pointer to %s device", cfg->int_gpio_port);
return -EINVAL;
}
ism330dhcx->dev = dev;
#if defined(CONFIG_ISM330DHCX_TRIGGER_OWN_THREAD)
k_sem_init(&ism330dhcx->gpio_sem, 0, UINT_MAX);
k_thread_create(&ism330dhcx->thread, ism330dhcx->thread_stack,
CONFIG_ISM330DHCX_THREAD_STACK_SIZE,
(k_thread_entry_t)ism330dhcx_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_ISM330DHCX_THREAD_PRIORITY),
(k_thread_entry_t)ism330dhcx_thread,
ism330dhcx, NULL, NULL,
K_PRIO_COOP(CONFIG_ISM330DHCX_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_ISM330DHCX_TRIGGER_GLOBAL_THREAD)
ism330dhcx->work.handler = ism330dhcx_work_cb;

View file

@ -235,6 +235,7 @@ struct lis2dh_data {
uint32_t scale;
#ifdef CONFIG_LIS2DH_TRIGGER
const struct device *dev;
const struct device *gpio_int1;
const struct device *gpio_int2;
struct gpio_callback gpio_int1_cb;
@ -251,7 +252,6 @@ struct lis2dh_data {
struct k_sem gpio_sem;
#elif defined(CONFIG_LIS2DH_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif
#endif /* CONFIG_LIS2DH_TRIGGER */

View file

@ -274,9 +274,8 @@ static void lis2dh_gpio_int2_callback(const struct device *dev,
}
#endif /* DT_INST_PROP_HAS_IDX(0, irq_gpios, 1) */
static void lis2dh_thread_cb(void *arg)
static void lis2dh_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct lis2dh_data *lis2dh = dev->data;
int status;
@ -346,17 +345,11 @@ static void lis2dh_thread_cb(void *arg)
}
#ifdef CONFIG_LIS2DH_TRIGGER_OWN_THREAD
static void lis2dh_thread(void *arg1, void *unused2, void *unused3)
static void lis2dh_thread(struct lis2dh_data *lis2dh)
{
const struct device *dev = arg1;
struct lis2dh_data *lis2dh = dev->data;
ARG_UNUSED(unused2);
ARG_UNUSED(unused3);
while (1) {
k_sem_take(&lis2dh->gpio_sem, K_FOREVER);
lis2dh_thread_cb(dev);
lis2dh_thread_cb(lis2dh->dev);
}
}
#endif
@ -387,17 +380,18 @@ int lis2dh_init_interrupt(const struct device *dev)
return -EINVAL;
}
lis2dh->dev = dev;
#if defined(CONFIG_LIS2DH_TRIGGER_OWN_THREAD)
k_sem_init(&lis2dh->gpio_sem, 0, UINT_MAX);
k_thread_create(&lis2dh->thread, lis2dh->thread_stack,
CONFIG_LIS2DH_THREAD_STACK_SIZE,
(k_thread_entry_t)lis2dh_thread, dev, NULL, NULL,
(k_thread_entry_t)lis2dh_thread, lis2dh, NULL, NULL,
K_PRIO_COOP(CONFIG_LIS2DH_THREAD_PRIORITY), 0,
K_NO_WAIT);
#elif defined(CONFIG_LIS2DH_TRIGGER_GLOBAL_THREAD)
lis2dh->work.handler = lis2dh_work_cb;
lis2dh->dev = dev;
#endif
/* data ready int1 gpio configuration */

View file

@ -184,13 +184,17 @@ static int lis2ds12_sample_fetch(const struct device *dev,
break;
#if defined(CONFIG_LIS2DS12_ENABLE_TEMP)
case SENSOR_CHAN_DIE_TEMP:
lis2ds12_sample_fetch_temp(dev);
/* ToDo:
lis2ds12_sample_fetch_temp(dev)
*/
break;
#endif
case SENSOR_CHAN_ALL:
lis2ds12_sample_fetch_accel(dev);
#if defined(CONFIG_LIS2DS12_ENABLE_TEMP)
lis2ds12_sample_fetch_temp(dev);
/* ToDo:
lis2ds12_sample_fetch_temp(dev)
*/
#endif
break;
default:

View file

@ -47,9 +47,8 @@ static void lis2ds12_handle_drdy_int(const struct device *dev)
}
}
static void lis2ds12_handle_int(void *arg)
static void lis2ds12_handle_int(const struct device *dev)
{
const struct device *dev = arg;
struct lis2ds12_data *data = dev->data;
const struct lis2ds12_config *cfg = dev->config;
uint8_t status;
@ -68,16 +67,11 @@ static void lis2ds12_handle_int(void *arg)
}
#ifdef CONFIG_LIS2DS12_TRIGGER_OWN_THREAD
static void lis2ds12_thread(int dev_ptr, int unused)
static void lis2ds12_thread(struct lis2ds12_data *data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct lis2ds12_data *data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&data->trig_sem, K_FOREVER);
lis2ds12_handle_int(dev);
lis2ds12_handle_int(data->dev);
}
}
#endif
@ -147,8 +141,9 @@ int lis2ds12_trigger_init(const struct device *dev)
k_thread_create(&data->thread, data->thread_stack,
CONFIG_LIS2DS12_THREAD_STACK_SIZE,
(k_thread_entry_t)lis2ds12_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_LIS2DS12_THREAD_PRIORITY),
(k_thread_entry_t)lis2ds12_thread,
data, NULL, NULL,
K_PRIO_COOP(CONFIG_LIS2DS12_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_LIS2DS12_TRIGGER_GLOBAL_THREAD)
data->work.handler = lis2ds12_work_cb;

View file

@ -117,6 +117,7 @@ struct lis2dw12_data {
stmdev_ctx_t *ctx;
#ifdef CONFIG_LIS2DW12_TRIGGER
const struct device *dev;
const struct device *gpio;
uint8_t gpio_pin;
struct gpio_callback gpio_cb;
@ -131,7 +132,6 @@ struct lis2dw12_data {
struct k_sem gpio_sem;
#elif defined(CONFIG_LIS2DW12_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif /* CONFIG_LIS2DW12_TRIGGER_GLOBAL_THREAD */
#endif /* CONFIG_LIS2DW12_TRIGGER */
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)

View file

@ -164,9 +164,8 @@ static int lis2dw12_handle_double_tap_int(const struct device *dev)
* lis2dw12_handle_interrupt - handle the drdy event
* read data and call handler if registered any
*/
static void lis2dw12_handle_interrupt(void *arg)
static void lis2dw12_handle_interrupt(const struct device *dev)
{
const struct device *dev = (const struct device *)arg;
struct lis2dw12_data *lis2dw12 = dev->data;
const struct lis2dw12_device_config *cfg = dev->config;
lis2dw12_all_sources_t sources;
@ -210,16 +209,11 @@ static void lis2dw12_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_LIS2DW12_TRIGGER_OWN_THREAD
static void lis2dw12_thread(int dev_ptr, int unused)
static void lis2dw12_thread(struct lis2dw12_data *lis2dw12)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct lis2dw12_data *lis2dw12 = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&lis2dw12->gpio_sem, K_FOREVER);
lis2dw12_handle_interrupt(dev);
lis2dw12_handle_interrupt(lis2dw12->dev);
}
}
#endif /* CONFIG_LIS2DW12_TRIGGER_OWN_THREAD */
@ -248,17 +242,18 @@ int lis2dw12_init_interrupt(const struct device *dev)
return -EINVAL;
}
lis2dw12->dev = dev;
#if defined(CONFIG_LIS2DW12_TRIGGER_OWN_THREAD)
k_sem_init(&lis2dw12->gpio_sem, 0, UINT_MAX);
k_thread_create(&lis2dw12->thread, lis2dw12->thread_stack,
CONFIG_LIS2DW12_THREAD_STACK_SIZE,
(k_thread_entry_t)lis2dw12_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_LIS2DW12_THREAD_PRIORITY),
(k_thread_entry_t)lis2dw12_thread, lis2dw12,
NULL, NULL, K_PRIO_COOP(CONFIG_LIS2DW12_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_LIS2DW12_TRIGGER_GLOBAL_THREAD)
lis2dw12->work.handler = lis2dw12_work_cb;
lis2dw12->dev = dev;
#endif /* CONFIG_LIS2DW12_TRIGGER_OWN_THREAD */
lis2dw12->gpio_pin = cfg->int_gpio_pin;

View file

@ -295,6 +295,8 @@ static int lis2mdl_init(const struct device *dev)
struct lis2mdl_data *lis2mdl = dev->data;
uint8_t wai;
lis2mdl->dev = dev;
if (lis2mdl_init_interface(dev)) {
return -EINVAL;
}

View file

@ -49,6 +49,7 @@ struct lis2mdl_config {
/* Sensor data */
struct lis2mdl_data {
const struct device *dev;
const struct device *bus;
uint16_t i2c_addr;
int16_t mag[3];
@ -67,7 +68,6 @@ struct lis2mdl_data {
struct gpio_callback gpio_cb;
sensor_trigger_handler_t handler_drdy;
const struct device *dev;
#if defined(CONFIG_LIS2MDL_TRIGGER_OWN_THREAD)
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_LIS2MDL_THREAD_STACK_SIZE);

View file

@ -21,21 +21,19 @@
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
LOG_MODULE_DECLARE(LIS2MDL);
static int lis2mdl_i2c_read(const struct device *dev, uint8_t reg_addr,
uint8_t *value, uint16_t len)
static int lis2mdl_i2c_read(struct lis2mdl_data *data, uint8_t reg_addr,
uint8_t *value, uint16_t len)
{
struct lis2mdl_data *data = dev->data;
const struct lis2mdl_config *cfg = dev->config;
const struct lis2mdl_config *cfg = data->dev->config;
return i2c_burst_read(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
}
static int lis2mdl_i2c_write(const struct device *dev, uint8_t reg_addr,
uint8_t *value, uint16_t len)
static int lis2mdl_i2c_write(struct lis2mdl_data *data, uint8_t reg_addr,
uint8_t *value, uint16_t len)
{
struct lis2mdl_data *data = dev->data;
const struct lis2mdl_config *cfg = dev->config;
const struct lis2mdl_config *cfg = data->dev->config;
return i2c_burst_write(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
@ -49,7 +47,7 @@ int lis2mdl_i2c_init(const struct device *dev)
data->ctx_i2c.write_reg = (stmdev_write_ptr) lis2mdl_i2c_write;
data->ctx = &data->ctx_i2c;
data->ctx->handle = dev;
data->ctx->handle = data;
return 0;
}

View file

@ -21,11 +21,10 @@
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
LOG_MODULE_DECLARE(LIS2MDL);
static int lis2mdl_spi_read(const struct device *dev, uint8_t reg_addr,
static int lis2mdl_spi_read(struct lis2mdl_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lis2mdl_data *data = dev->data;
const struct lis2mdl_config *cfg = dev->config;
const struct lis2mdl_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[2] = { reg_addr | LIS2MDL_SPI_READ, 0 };
const struct spi_buf tx_buf = {
@ -63,11 +62,10 @@ static int lis2mdl_spi_read(const struct device *dev, uint8_t reg_addr,
return 0;
}
static int lis2mdl_spi_write(const struct device *dev, uint8_t reg_addr,
static int lis2mdl_spi_write(struct lis2mdl_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lis2mdl_data *data = dev->data;
const struct lis2mdl_config *cfg = dev->config;
const struct lis2mdl_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[1] = { reg_addr & ~LIS2MDL_SPI_READ };
const struct spi_buf tx_buf[2] = {
@ -105,7 +103,7 @@ int lis2mdl_spi_init(const struct device *dev)
data->ctx_spi.write_reg = (stmdev_write_ptr) lis2mdl_spi_write;
data->ctx = &data->ctx_spi;
data->ctx->handle = dev;
data->ctx->handle = data;
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
const struct lis2mdl_config *cfg = dev->config;

View file

@ -50,9 +50,8 @@ int lis2mdl_trigger_set(const struct device *dev,
}
/* handle the drdy event: read data and call handler if registered any */
static void lis2mdl_handle_interrupt(void *arg)
static void lis2mdl_handle_interrupt(const struct device *dev)
{
const struct device *dev = arg;
struct lis2mdl_data *lis2mdl = dev->data;
const struct lis2mdl_config *const config = dev->config;
struct sensor_trigger drdy_trigger = {
@ -86,16 +85,11 @@ static void lis2mdl_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_LIS2MDL_TRIGGER_OWN_THREAD
static void lis2mdl_thread(int dev_ptr, int unused)
static void lis2mdl_thread(struct lis2mdl_data *lis2mdl)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct lis2mdl_data *lis2mdl = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&lis2mdl->gpio_sem, K_FOREVER);
lis2mdl_handle_interrupt(dev);
lis2mdl_handle_interrupt(lis2mdl->dev);
}
}
#endif
@ -122,14 +116,13 @@ int lis2mdl_init_interrupt(const struct device *dev)
config->gpio_name);
return -EINVAL;
}
lis2mdl->dev = dev;
#if defined(CONFIG_LIS2MDL_TRIGGER_OWN_THREAD)
k_sem_init(&lis2mdl->gpio_sem, 0, UINT_MAX);
k_thread_create(&lis2mdl->thread, lis2mdl->thread_stack,
CONFIG_LIS2MDL_THREAD_STACK_SIZE,
(k_thread_entry_t)lis2mdl_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_LIS2MDL_THREAD_PRIORITY),
(k_thread_entry_t)lis2mdl_thread, lis2mdl,
NULL, NULL, K_PRIO_COOP(CONFIG_LIS2MDL_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_LIS2MDL_TRIGGER_GLOBAL_THREAD)
lis2mdl->work.handler = lis2mdl_work_cb;

View file

@ -118,6 +118,7 @@ struct lis3mdl_data {
int16_t temp_sample;
#ifdef CONFIG_LIS3MDL_TRIGGER
const struct device *dev;
const struct device *gpio;
struct gpio_callback gpio_cb;
@ -130,7 +131,6 @@ struct lis3mdl_data {
struct k_thread thread;
#elif defined(CONFIG_LIS3MDL_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif
#endif /* CONFIG_LIS3MDL_TRIGGER */

View file

@ -71,9 +71,8 @@ static void lis3mdl_gpio_callback(const struct device *dev,
#endif
}
static void lis3mdl_thread_cb(void *arg)
static void lis3mdl_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct lis3mdl_data *drv_data = dev->data;
if (drv_data->data_ready_handler != NULL) {
@ -87,16 +86,11 @@ static void lis3mdl_thread_cb(void *arg)
}
#ifdef CONFIG_LIS3MDL_TRIGGER_OWN_THREAD
static void lis3mdl_thread(int dev_ptr, int unused)
static void lis3mdl_thread(struct lis3mdl_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct lis3mdl_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
lis3mdl_thread_cb(dev);
lis3mdl_thread_cb(drv_data->dev);
}
}
#endif
@ -144,17 +138,18 @@ int lis3mdl_init_interrupt(const struct device *dev)
return -EIO;
}
drv_data->dev = dev;
#if defined(CONFIG_LIS3MDL_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_LIS3MDL_THREAD_STACK_SIZE,
(k_thread_entry_t)lis3mdl_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_LIS3MDL_THREAD_PRIORITY),
(k_thread_entry_t)lis3mdl_thread, drv_data,
NULL, NULL, K_PRIO_COOP(CONFIG_LIS3MDL_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_LIS3MDL_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = lis3mdl_work_cb;
drv_data->dev = dev;
#endif
gpio_pin_interrupt_configure(drv_data->gpio,

View file

@ -176,6 +176,8 @@ static int lps22hh_init(const struct device *dev)
const struct lps22hh_config * const config = dev->config;
struct lps22hh_data *data = dev->data;
data->dev = dev;
data->bus = device_get_binding(config->master_dev_name);
if (!data->bus) {
LOG_DBG("bus master not found: %s", config->master_dev_name);

View file

@ -51,6 +51,7 @@ struct lps22hh_config {
};
struct lps22hh_data {
const struct device *dev;
const struct device *bus;
int32_t sample_press;
int16_t sample_temp;
@ -70,7 +71,6 @@ struct lps22hh_data {
struct sensor_trigger data_ready_trigger;
sensor_trigger_handler_t handler_drdy;
const struct device *dev;
#if defined(CONFIG_LPS22HH_TRIGGER_OWN_THREAD)
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_LPS22HH_THREAD_STACK_SIZE);

View file

@ -20,21 +20,19 @@
LOG_MODULE_DECLARE(LPS22HH, CONFIG_SENSOR_LOG_LEVEL);
static int lps22hh_i2c_read(const struct device *dev, uint8_t reg_addr,
uint8_t *value, uint16_t len)
static int lps22hh_i2c_read(struct lps22hh_data *data, uint8_t reg_addr,
uint8_t *value, uint16_t len)
{
struct lps22hh_data *data = dev->data;
const struct lps22hh_config *cfg = dev->config;
const struct lps22hh_config *cfg = data->dev->config;
return i2c_burst_read(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
}
static int lps22hh_i2c_write(const struct device *dev, uint8_t reg_addr,
uint8_t *value, uint16_t len)
static int lps22hh_i2c_write(struct lps22hh_data *data, uint8_t reg_addr,
uint8_t *value, uint16_t len)
{
struct lps22hh_data *data = dev->data;
const struct lps22hh_config *cfg = dev->config;
const struct lps22hh_config *cfg = data->dev->config;
return i2c_burst_write(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
@ -48,7 +46,7 @@ int lps22hh_i2c_init(const struct device *dev)
data->ctx_i2c.write_reg = (stmdev_write_ptr) lps22hh_i2c_write;
data->ctx = &data->ctx_i2c;
data->ctx->handle = dev;
data->ctx->handle = data;
return 0;
}

View file

@ -21,11 +21,10 @@
LOG_MODULE_DECLARE(LPS22HH, CONFIG_SENSOR_LOG_LEVEL);
static int lps22hh_spi_read(const struct device *dev, uint8_t reg_addr,
static int lps22hh_spi_read(struct lps22hh_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lps22hh_data *data = dev->data;
const struct lps22hh_config *cfg = dev->config;
const struct lps22hh_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[2] = { reg_addr | LPS22HH_SPI_READ, 0 };
const struct spi_buf tx_buf = {
@ -63,11 +62,10 @@ static int lps22hh_spi_read(const struct device *dev, uint8_t reg_addr,
return 0;
}
static int lps22hh_spi_write(const struct device *dev, uint8_t reg_addr,
static int lps22hh_spi_write(struct lps22hh_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lps22hh_data *data = dev->data;
const struct lps22hh_config *cfg = dev->config;
const struct lps22hh_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[1] = { reg_addr & ~LPS22HH_SPI_READ };
const struct spi_buf tx_buf[2] = {
@ -105,7 +103,7 @@ int lps22hh_spi_init(const struct device *dev)
data->ctx_spi.write_reg = (stmdev_write_ptr) lps22hh_spi_write;
data->ctx = &data->ctx_spi;
data->ctx->handle = dev;
data->ctx->handle = data;
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
const struct lps22hh_config *cfg = dev->config;

View file

@ -67,9 +67,8 @@ int lps22hh_trigger_set(const struct device *dev,
* lps22hh_handle_interrupt - handle the drdy event
* read data and call handler if registered any
*/
static void lps22hh_handle_interrupt(void *arg)
static void lps22hh_handle_interrupt(const struct device *dev)
{
const struct device *dev = arg;
struct lps22hh_data *lps22hh = dev->data;
const struct lps22hh_config *cfg = dev->config;
struct sensor_trigger drdy_trigger = {
@ -104,16 +103,11 @@ static void lps22hh_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_LPS22HH_TRIGGER_OWN_THREAD
static void lps22hh_thread(int dev_ptr, int unused)
static void lps22hh_thread(struct lps22hh_data *lps22hh)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct lps22hh_data *lps22hh = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&lps22hh->gpio_sem, K_FOREVER);
lps22hh_handle_interrupt(dev);
lps22hh_handle_interrupt(lps22hh->dev);
}
}
#endif /* CONFIG_LPS22HH_TRIGGER_OWN_THREAD */
@ -140,15 +134,14 @@ int lps22hh_init_interrupt(const struct device *dev)
LOG_DBG("Cannot get pointer to %s device", cfg->drdy_port);
return -EINVAL;
}
lps22hh->dev = dev;
#if defined(CONFIG_LPS22HH_TRIGGER_OWN_THREAD)
k_sem_init(&lps22hh->gpio_sem, 0, UINT_MAX);
k_thread_create(&lps22hh->thread, lps22hh->thread_stack,
CONFIG_LPS22HH_THREAD_STACK_SIZE,
(k_thread_entry_t)lps22hh_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_LPS22HH_THREAD_PRIORITY),
(k_thread_entry_t)lps22hh_thread, lps22hh,
NULL, NULL, K_PRIO_COOP(CONFIG_LPS22HH_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_LPS22HH_TRIGGER_GLOBAL_THREAD)
lps22hh->work.handler = lps22hh_work_cb;

View file

@ -650,6 +650,7 @@ struct lsm6dsl_data {
uint8_t gyro_fs;
#ifdef CONFIG_LSM6DSL_TRIGGER
const struct device *dev;
const struct device *gpio;
struct gpio_callback gpio_cb;
@ -662,7 +663,6 @@ struct lsm6dsl_data {
struct k_sem gpio_sem;
#elif defined(CONFIG_LSM6DSL_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif
#endif /* CONFIG_LSM6DSL_TRIGGER */

View file

@ -76,9 +76,8 @@ static void lsm6dsl_gpio_callback(const struct device *dev,
handle_irq(drv_data);
}
static void lsm6dsl_thread_cb(void *arg)
static void lsm6dsl_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct lsm6dsl_data *drv_data = dev->data;
if (drv_data->data_ready_handler != NULL) {
@ -90,16 +89,11 @@ static void lsm6dsl_thread_cb(void *arg)
}
#ifdef CONFIG_LSM6DSL_TRIGGER_OWN_THREAD
static void lsm6dsl_thread(int dev_ptr, int unused)
static void lsm6dsl_thread(struct lsm6dsl_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct lsm6dsl_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
lsm6dsl_thread_cb(dev);
lsm6dsl_thread_cb(drv_data->dev);
}
}
#endif
@ -149,17 +143,18 @@ int lsm6dsl_init_interrupt(const struct device *dev)
return -EIO;
}
drv_data->dev = dev;
#if defined(CONFIG_LSM6DSL_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_LSM6DSL_THREAD_STACK_SIZE,
(k_thread_entry_t)lsm6dsl_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_LSM6DSL_THREAD_PRIORITY),
(k_thread_entry_t)lsm6dsl_thread, drv_data,
NULL, NULL, K_PRIO_COOP(CONFIG_LSM6DSL_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_LSM6DSL_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = lsm6dsl_work_cb;
drv_data->dev = dev;
#endif
setup_irq(drv_data, true);

View file

@ -796,6 +796,8 @@ static int lsm6dso_init(const struct device *dev)
const struct lsm6dso_config * const config = dev->config;
struct lsm6dso_data *data = dev->data;
data->dev = dev;
data->bus = device_get_binding(config->bus_name);
if (!data->bus) {
LOG_DBG("master not found: %s",

View file

@ -138,6 +138,7 @@ struct lsm6dso_tf {
#define LSM6DSO_SHUB_MAX_NUM_SLVS 2
struct lsm6dso_data {
const struct device *dev;
const struct device *bus;
int16_t acc[3];
uint32_t acc_gain;
@ -177,7 +178,6 @@ struct lsm6dso_data {
sensor_trigger_handler_t handler_drdy_acc;
sensor_trigger_handler_t handler_drdy_gyr;
sensor_trigger_handler_t handler_drdy_temp;
const struct device *dev;
#if defined(CONFIG_LSM6DSO_TRIGGER_OWN_THREAD)
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_LSM6DSO_THREAD_STACK_SIZE);

View file

@ -20,21 +20,19 @@
LOG_MODULE_DECLARE(LSM6DSO, CONFIG_SENSOR_LOG_LEVEL);
static int lsm6dso_i2c_read(const struct device *dev, uint8_t reg_addr,
static int lsm6dso_i2c_read(struct lsm6dso_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lsm6dso_data *data = dev->data;
const struct lsm6dso_config *cfg = dev->config;
const struct lsm6dso_config *cfg = data->dev->config;
return i2c_burst_read(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
}
static int lsm6dso_i2c_write(const struct device *dev, uint8_t reg_addr,
static int lsm6dso_i2c_write(struct lsm6dso_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lsm6dso_data *data = dev->data;
const struct lsm6dso_config *cfg = dev->config;
const struct lsm6dso_config *cfg = data->dev->config;
return i2c_burst_write(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
@ -48,7 +46,7 @@ int lsm6dso_i2c_init(const struct device *dev)
data->ctx_i2c.write_reg = (stmdev_write_ptr) lsm6dso_i2c_write,
data->ctx = &data->ctx_i2c;
data->ctx->handle = dev;
data->ctx->handle = data;
return 0;
}

View file

@ -20,11 +20,10 @@
LOG_MODULE_DECLARE(LSM6DSO, CONFIG_SENSOR_LOG_LEVEL);
static int lsm6dso_spi_read(const struct device *dev, uint8_t reg_addr,
static int lsm6dso_spi_read(struct lsm6dso_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lsm6dso_data *data = dev->data;
const struct lsm6dso_config *cfg = dev->config;
const struct lsm6dso_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[2] = { reg_addr | LSM6DSO_SPI_READ, 0 };
const struct spi_buf tx_buf = {
@ -62,11 +61,10 @@ static int lsm6dso_spi_read(const struct device *dev, uint8_t reg_addr,
return 0;
}
static int lsm6dso_spi_write(const struct device *dev, uint8_t reg_addr,
static int lsm6dso_spi_write(struct lsm6dso_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lsm6dso_data *data = dev->data;
const struct lsm6dso_config *cfg = dev->config;
const struct lsm6dso_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[1] = { reg_addr & ~LSM6DSO_SPI_READ };
const struct spi_buf tx_buf[2] = {
@ -104,7 +102,7 @@ int lsm6dso_spi_init(const struct device *dev)
data->ctx_spi.write_reg = (stmdev_write_ptr) lsm6dso_spi_write,
data->ctx = &data->ctx_spi;
data->ctx->handle = dev;
data->ctx->handle = data;
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
const struct lsm6dso_config *cfg = dev->config;

View file

@ -161,9 +161,8 @@ int lsm6dso_trigger_set(const struct device *dev,
* lsm6dso_handle_interrupt - handle the drdy event
* read data and call handler if registered any
*/
static void lsm6dso_handle_interrupt(void *arg)
static void lsm6dso_handle_interrupt(const struct device *dev)
{
const struct device *dev = arg;
struct lsm6dso_data *lsm6dso = dev->data;
struct sensor_trigger drdy_trigger = {
.type = SENSOR_TRIG_DATA_READY,
@ -224,16 +223,11 @@ static void lsm6dso_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_LSM6DSO_TRIGGER_OWN_THREAD
static void lsm6dso_thread(int dev_ptr, int unused)
static void lsm6dso_thread(struct lsm6dso_data *lsm6dso)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct lsm6dso_data *lsm6dso = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&lsm6dso->gpio_sem, K_FOREVER);
lsm6dso_handle_interrupt(dev);
lsm6dso_handle_interrupt(lsm6dso->dev);
}
}
#endif /* CONFIG_LSM6DSO_TRIGGER_OWN_THREAD */
@ -261,15 +255,14 @@ int lsm6dso_init_interrupt(const struct device *dev)
cfg->int_gpio_port);
return -EINVAL;
}
lsm6dso->dev = dev;
#if defined(CONFIG_LSM6DSO_TRIGGER_OWN_THREAD)
k_sem_init(&lsm6dso->gpio_sem, 0, UINT_MAX);
k_thread_create(&lsm6dso->thread, lsm6dso->thread_stack,
CONFIG_LSM6DSO_THREAD_STACK_SIZE,
(k_thread_entry_t)lsm6dso_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_LSM6DSO_THREAD_PRIORITY),
(k_thread_entry_t)lsm6dso_thread, lsm6dso,
NULL, NULL, K_PRIO_COOP(CONFIG_LSM6DSO_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD)
lsm6dso->work.handler = lsm6dso_work_cb;

View file

@ -338,8 +338,6 @@ static int lsm9ds0_gyro_init(const struct device *dev)
LOG_DBG("failed to initialize interrupts");
return -EIO;
}
data->dev = dev;
#endif
return 0;

View file

@ -81,19 +81,16 @@ static void lsm9ds0_gyro_gpio_drdy_callback(const struct device *dev,
k_sem_give(&data->sem);
}
static void lsm9ds0_gyro_thread_main(void *arg1, void *arg2, void *arg3)
static void lsm9ds0_gyro_thread_main(struct lsm9ds0_gyro_data *data)
{
const struct device *dev = (const struct device *) arg1;
struct lsm9ds0_gyro_data *data = dev->data;
while (1) {
k_sem_take(&data->sem, K_FOREVER);
if (data->handler_drdy) {
data->handler_drdy(dev, &data->trigger_drdy);
data->handler_drdy(data->dev, &data->trigger_drdy);
}
setup_drdy(dev, true);
setup_drdy(data->dev, true);
}
}
@ -103,12 +100,13 @@ int lsm9ds0_gyro_init_interrupt(const struct device *dev)
dev->config;
struct lsm9ds0_gyro_data *data = dev->data;
data->dev = dev;
k_sem_init(&data->sem, 0, UINT_MAX);
k_thread_create(&data->thread, data->thread_stack,
CONFIG_LSM9DS0_GYRO_THREAD_STACK_SIZE,
lsm9ds0_gyro_thread_main, dev, NULL, NULL,
K_PRIO_COOP(10), 0, K_NO_WAIT);
(k_thread_entry_t)lsm9ds0_gyro_thread_main,
data, NULL, NULL, K_PRIO_COOP(10), 0, K_NO_WAIT);
data->gpio_drdy = device_get_binding(config->gpio_drdy_dev_name);
if (!data->gpio_drdy) {

View file

@ -135,16 +135,11 @@ static void alert_cb(const struct device *dev, struct gpio_callback *cb,
#ifdef CONFIG_MCP9808_TRIGGER_OWN_THREAD
static void mcp9808_thread_main(int arg1, int arg2)
static void mcp9808_thread_main(struct mcp9808_data *data)
{
const struct device *dev = INT_TO_POINTER(arg1);
struct mcp9808_data *data = dev->data;
ARG_UNUSED(arg2);
while (true) {
k_sem_take(&data->sem, K_FOREVER);
process_int(dev);
process_int(data->dev);
}
}
@ -181,8 +176,9 @@ int mcp9808_setup_interrupt(const struct device *dev)
k_thread_create(&mcp9808_thread, mcp9808_thread_stack,
CONFIG_MCP9808_THREAD_STACK_SIZE,
(k_thread_entry_t)mcp9808_thread_main, dev, 0, NULL,
K_PRIO_COOP(CONFIG_MCP9808_THREAD_PRIORITY), 0, K_NO_WAIT);
(k_thread_entry_t)mcp9808_thread_main, data, NULL, NULL,
K_PRIO_COOP(CONFIG_MCP9808_THREAD_PRIORITY),
0, K_NO_WAIT);
#else /* CONFIG_MCP9808_TRIGGER_GLOBAL_THREAD */
data->work.handler = mcp9808_gpio_thread_cb;
#endif /* trigger type */

View file

@ -60,9 +60,8 @@ static void mpu6050_gpio_callback(const struct device *dev,
#endif
}
static void mpu6050_thread_cb(void *arg)
static void mpu6050_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct mpu6050_data *drv_data = dev->data;
const struct mpu6050_config *cfg = dev->config;
@ -77,16 +76,11 @@ static void mpu6050_thread_cb(void *arg)
}
#ifdef CONFIG_MPU6050_TRIGGER_OWN_THREAD
static void mpu6050_thread(int dev_ptr, int unused)
static void mpu6050_thread(struct mpu6050_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct mpu6050_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
mpu6050_thread_cb(dev);
mpu6050_thread_cb(drv_data->dev);
}
}
#endif
@ -140,8 +134,8 @@ int mpu6050_init_interrupt(const struct device *dev)
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_MPU6050_THREAD_STACK_SIZE,
(k_thread_entry_t)mpu6050_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_MPU6050_THREAD_PRIORITY),
(k_thread_entry_t)mpu6050_thread, drv_data,
NULL, NULL, K_PRIO_COOP(CONFIG_MPU6050_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_MPU6050_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = mpu6050_work_cb;

View file

@ -151,9 +151,8 @@ static void sht3xd_gpio_callback(const struct device *dev,
handle_alert(data->dev);
}
static void sht3xd_thread_cb(void *arg)
static void sht3xd_thread_cb(const struct device *dev)
{
const struct device *dev = (const struct device *)arg;
struct sht3xd_data *data = (struct sht3xd_data *)dev->data;
if (data->handler != NULL) {
@ -164,16 +163,11 @@ static void sht3xd_thread_cb(void *arg)
}
#ifdef CONFIG_SHT3XD_TRIGGER_OWN_THREAD
static void sht3xd_thread(int dev_ptr, int unused)
static void sht3xd_thread(struct sht3xd_data *data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct sht3xd_data *data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&data->gpio_sem, K_FOREVER);
sht3xd_thread_cb(dev);
sht3xd_thread_cb(data->dev);
}
}
#endif
@ -250,8 +244,8 @@ int sht3xd_init_interrupt(const struct device *dev)
k_thread_create(&data->thread, data->thread_stack,
CONFIG_SHT3XD_THREAD_STACK_SIZE,
(k_thread_entry_t)sht3xd_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_SHT3XD_THREAD_PRIORITY),
(k_thread_entry_t)sht3xd_thread, data,
NULL, NULL, K_PRIO_COOP(CONFIG_SHT3XD_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_SHT3XD_TRIGGER_GLOBAL_THREAD)
data->work.handler = sht3xd_work_cb;

View file

@ -61,9 +61,8 @@ static void sm351lt_gpio_callback(const struct device *dev,
#endif
}
static void sm351lt_thread_cb(void *arg)
static void sm351lt_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct sm351lt_data *data = dev->data;
struct sensor_trigger mag_trigger = {
@ -81,15 +80,14 @@ static void sm351lt_thread_cb(void *arg)
#if defined(CONFIG_SM351LT_TRIGGER_OWN_THREAD)
static void sm351lt_thread(void *arg1, void *unused2, void *unused3)
{
const struct device *dev = arg1;
struct sm351lt_data *data = dev->data;
struct sm351lt_data *data = arg1;
ARG_UNUSED(unused2);
ARG_UNUSED(unused3);
while (1) {
k_sem_take(&data->gpio_sem, K_FOREVER);
sm351lt_thread_cb(dev);
sm351lt_thread_cb(data->dev);
}
}
#endif
@ -212,11 +210,13 @@ static int sm351lt_init(const struct device *dev)
#if defined(CONFIG_SM351LT_TRIGGER)
#if defined(CONFIG_SM351LT_TRIGGER_OWN_THREAD)
data->dev = dev;
k_sem_init(&data->gpio_sem, 0, UINT_MAX);
k_thread_create(&data->thread, data->thread_stack,
CONFIG_SM351LT_THREAD_STACK_SIZE,
(k_thread_entry_t)sm351lt_thread, dev, NULL,
(k_thread_entry_t)sm351lt_thread, data, NULL,
NULL, K_PRIO_COOP(CONFIG_SM351LT_THREAD_PRIORITY),
0, K_NO_WAIT);
@ -227,7 +227,6 @@ static int sm351lt_init(const struct device *dev)
#elif defined(CONFIG_SM351LT_TRIGGER_GLOBAL_THREAD)
data->work.handler = sm351lt_work_cb;
data->dev = dev;
#endif
data->trigger_type = GPIO_INT_DISABLE;

View file

@ -24,6 +24,7 @@ struct sm351lt_data {
bool sample_status;
#ifdef CONFIG_SM351LT_TRIGGER
const struct device *dev;
struct gpio_callback gpio_cb;
uint32_t trigger_type;
@ -35,7 +36,6 @@ struct sm351lt_data {
struct k_sem gpio_sem;
#elif defined(CONFIG_SM351LT_TRIGGER_GLOBAL_THREAD)
struct k_work work;
const struct device *dev;
#endif
#endif /* CONFIG_SM351LT_TRIGGER */

View file

@ -173,6 +173,8 @@ static int stts751_init(const struct device *dev)
const struct stts751_config * const config = dev->config;
struct stts751_data *data = dev->data;
data->dev = dev;
data->bus = device_get_binding(config->master_dev_name);
if (!data->bus) {
LOG_DBG("bus master not found: %s", config->master_dev_name);

View file

@ -38,6 +38,7 @@ struct stts751_config {
};
struct stts751_data {
const struct device *dev;
const struct device *bus;
int16_t sample_temp;
@ -54,7 +55,6 @@ struct stts751_data {
struct sensor_trigger data_ready_trigger;
sensor_trigger_handler_t thsld_handler;
const struct device *dev;
#if defined(CONFIG_STTS751_TRIGGER_OWN_THREAD)
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_STTS751_THREAD_STACK_SIZE);

View file

@ -20,21 +20,19 @@
LOG_MODULE_DECLARE(STTS751, CONFIG_SENSOR_LOG_LEVEL);
static int stts751_i2c_read(const struct device *dev, uint8_t reg_addr,
uint8_t *value, uint16_t len)
static int stts751_i2c_read(struct stts751_data *data, uint8_t reg_addr,
uint8_t *value, uint16_t len)
{
struct stts751_data *data = dev->data;
const struct stts751_config *cfg = dev->config;
const struct stts751_config *cfg = data->dev->config;
return i2c_burst_read(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
}
static int stts751_i2c_write(const struct device *dev, uint8_t reg_addr,
uint8_t *value, uint16_t len)
static int stts751_i2c_write(struct stts751_data *data, uint8_t reg_addr,
uint8_t *value, uint16_t len)
{
struct stts751_data *data = dev->data;
const struct stts751_config *cfg = dev->config;
const struct stts751_config *cfg = data->dev->config;
return i2c_burst_write(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
@ -48,7 +46,7 @@ int stts751_i2c_init(const struct device *dev)
data->ctx_i2c.write_reg = (stmdev_write_ptr) stts751_i2c_write;
data->ctx = &data->ctx_i2c;
data->ctx->handle = dev;
data->ctx->handle = data;
return 0;
}

View file

@ -55,9 +55,8 @@ int stts751_trigger_set(const struct device *dev,
* stts751_handle_interrupt - handle the thsld event
* read data and call handler if registered any
*/
static void stts751_handle_interrupt(void *arg)
static void stts751_handle_interrupt(const struct device *dev)
{
const struct device *dev = arg;
struct stts751_data *stts751 = dev->data;
const struct stts751_config *cfg = dev->config;
struct sensor_trigger thsld_trigger = {
@ -95,16 +94,11 @@ static void stts751_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_STTS751_TRIGGER_OWN_THREAD
static void stts751_thread(int dev_ptr, int unused)
static void stts751_thread(struct stts751_data *stts751)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct stts751_data *stts751 = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&stts751->gpio_sem, K_FOREVER);
stts751_handle_interrupt(dev);
stts751_handle_interrupt(stts751->dev);
}
}
#endif /* CONFIG_STTS751_TRIGGER_OWN_THREAD */
@ -131,16 +125,15 @@ int stts751_init_interrupt(const struct device *dev)
LOG_DBG("Cannot get pointer to %s device", cfg->event_port);
return -EINVAL;
}
stts751->dev = dev;
#if defined(CONFIG_STTS751_TRIGGER_OWN_THREAD)
k_sem_init(&stts751->gpio_sem, 0, UINT_MAX);
k_thread_create(&stts751->thread, stts751->thread_stack,
CONFIG_STTS751_THREAD_STACK_SIZE,
(k_thread_entry_t)stts751_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_STTS751_THREAD_PRIORITY),
0, K_NO_WAIT);
CONFIG_STTS751_THREAD_STACK_SIZE,
(k_thread_entry_t)stts751_thread, stts751,
NULL, NULL, K_PRIO_COOP(CONFIG_STTS751_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_STTS751_TRIGGER_GLOBAL_THREAD)
stts751->work.handler = stts751_work_cb;
#endif /* CONFIG_STTS751_TRIGGER_OWN_THREAD */

View file

@ -37,10 +37,10 @@ struct sx9500_data {
#ifdef CONFIG_SX9500_TRIGGER_GLOBAL_THREAD
struct k_work work;
const struct device *dev;
#endif
#ifdef CONFIG_SX9500_TRIGGER
const struct device *dev;
struct sensor_trigger trigger_drdy;
struct sensor_trigger trigger_near_far;

View file

@ -62,62 +62,8 @@ int sx9500_trigger_set(const struct device *dev,
return 0;
}
#ifdef CONFIG_SX9500_TRIGGER_OWN_THREAD
static void sx9500_gpio_cb(const struct device *port,
struct gpio_callback *cb, uint32_t pins)
static void sx9500_gpio_thread_cb(const struct device *dev)
{
struct sx9500_data *data =
CONTAINER_OF(cb, struct sx9500_data, gpio_cb);
ARG_UNUSED(pins);
k_sem_give(&data->sem);
}
static void sx9500_thread_main(int arg1, int unused)
{
const struct device *dev = INT_TO_POINTER(arg1);
struct sx9500_data *data = dev->data;
uint8_t reg_val;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&data->sem, K_FOREVER);
if (i2c_reg_read_byte(data->i2c_master, data->i2c_slave_addr,
SX9500_REG_IRQ_SRC, &reg_val) < 0) {
LOG_DBG("sx9500: error reading IRQ source register");
continue;
}
if ((reg_val & SX9500_CONV_DONE_IRQ) && data->handler_drdy) {
data->handler_drdy(dev, &data->trigger_drdy);
}
if ((reg_val & SX9500_NEAR_FAR_IRQ) && data->handler_near_far) {
data->handler_near_far(dev, &data->trigger_near_far);
}
}
}
#else /* CONFIG_SX9500_TRIGGER_GLOBAL_THREAD */
static void sx9500_gpio_cb(const struct device *port,
struct gpio_callback *cb, uint32_t pins)
{
struct sx9500_data *data =
CONTAINER_OF(cb, struct sx9500_data, gpio_cb);
ARG_UNUSED(pins);
k_work_submit(&data->work);
}
static void sx9500_gpio_thread_cb(void *arg)
{
const struct device *dev = arg;
struct sx9500_data *data = dev->data;
uint8_t reg_val;
@ -135,6 +81,40 @@ static void sx9500_gpio_thread_cb(void *arg)
data->handler_near_far(dev, &data->trigger_near_far);
}
}
#ifdef CONFIG_SX9500_TRIGGER_OWN_THREAD
static void sx9500_gpio_cb(const struct device *port,
struct gpio_callback *cb, uint32_t pins)
{
struct sx9500_data *data =
CONTAINER_OF(cb, struct sx9500_data, gpio_cb);
ARG_UNUSED(pins);
k_sem_give(&data->sem);
}
static void sx9500_thread_main(struct sx9500_data *data)
{
while (1) {
k_sem_take(&data->sem, K_FOREVER);
sx9500_gpio_thread_cb(data->dev);
}
}
#else /* CONFIG_SX9500_TRIGGER_GLOBAL_THREAD */
static void sx9500_gpio_cb(const struct device *port,
struct gpio_callback *cb, uint32_t pins)
{
struct sx9500_data *data =
CONTAINER_OF(cb, struct sx9500_data, gpio_cb);
ARG_UNUSED(pins);
k_work_submit(&data->work);
}
#endif /* CONFIG_SX9500_TRIGGER_GLOBAL_THREAD */
#ifdef CONFIG_SX9500_TRIGGER_GLOBAL_THREAD
@ -156,9 +136,10 @@ int sx9500_setup_interrupt(const struct device *dev)
k_sem_init(&data->sem, 0, UINT_MAX);
#else
data->work.handler = sx9500_work_cb;
data->dev = dev;
#endif
data->dev = dev;
gpio = device_get_binding(DT_INST_GPIO_LABEL(0, int_gpios));
if (!gpio) {
LOG_DBG("sx9500: gpio controller %s not found",
@ -180,8 +161,9 @@ int sx9500_setup_interrupt(const struct device *dev)
#ifdef CONFIG_SX9500_TRIGGER_OWN_THREAD
k_thread_create(&sx9500_thread, sx9500_thread_stack,
CONFIG_SX9500_THREAD_STACK_SIZE,
(k_thread_entry_t)sx9500_thread_main, dev, 0, NULL,
K_PRIO_COOP(CONFIG_SX9500_THREAD_PRIORITY), 0, K_NO_WAIT);
(k_thread_entry_t)sx9500_thread_main, data, 0, NULL,
K_PRIO_COOP(CONFIG_SX9500_THREAD_PRIORITY),
0, K_NO_WAIT);
#endif
return 0;

View file

@ -78,9 +78,8 @@ static void tmp007_gpio_callback(const struct device *dev,
#endif
}
static void tmp007_thread_cb(void *arg)
static void tmp007_thread_cb(const struct device *dev)
{
const struct device *dev = arg;
struct tmp007_data *drv_data = dev->data;
uint16_t status;
@ -102,16 +101,11 @@ static void tmp007_thread_cb(void *arg)
}
#ifdef CONFIG_TMP007_TRIGGER_OWN_THREAD
static void tmp007_thread(int dev_ptr, int unused)
static void tmp007_thread(struct tmp007_data *drv_data)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct tmp007_data *drv_data = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&drv_data->gpio_sem, K_FOREVER);
tmp007_thread_cb(dev);
tmp007_thread_cb(drv_data->dev);
}
}
#endif
@ -185,8 +179,8 @@ int tmp007_init_interrupt(const struct device *dev)
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_TMP007_THREAD_STACK_SIZE,
(k_thread_entry_t)tmp007_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_TMP007_THREAD_PRIORITY),
(k_thread_entry_t)tmp007_thread, drv_data,
NULL, NULL, K_PRIO_COOP(CONFIG_TMP007_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_TMP007_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = tmp007_work_cb;