1 /* 2 * Copyright (c) 2022 Würth Elektronik eiSos GmbH & Co. KG 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_SENSOR_WSEN_TIDS_WSEN_TIDS_H_ 8 #define ZEPHYR_DRIVERS_SENSOR_WSEN_TIDS_WSEN_TIDS_H_ 9 10 #include <zephyr/drivers/gpio.h> 11 #include <zephyr/drivers/sensor.h> 12 13 #include <weplatform.h> 14 15 #include "WSEN_TIDS_2521020222501.h" 16 17 #include <zephyr/drivers/i2c.h> 18 19 struct tids_data { 20 /* WE sensor interface configuration */ 21 WE_sensorInterface_t sensor_interface; 22 23 /* Last temperature sample */ 24 int16_t temperature; 25 26 #ifdef CONFIG_WSEN_TIDS_TRIGGER 27 const struct device *dev; 28 29 /* Callback for high/low limit interrupts */ 30 struct gpio_callback threshold_cb; 31 32 const struct sensor_trigger *threshold_trigger; 33 sensor_trigger_handler_t threshold_handler; 34 35 #if defined(CONFIG_WSEN_TIDS_TRIGGER_OWN_THREAD) 36 K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_WSEN_TIDS_THREAD_STACK_SIZE); 37 struct k_thread thread; 38 struct k_sem threshold_sem; 39 #elif defined(CONFIG_WSEN_TIDS_TRIGGER_GLOBAL_THREAD) 40 struct k_work work; 41 #endif 42 #endif /* CONFIG_WSEN_TIDS_TRIGGER */ 43 }; 44 45 struct tids_config { 46 union { 47 const struct i2c_dt_spec i2c; 48 } bus_cfg; 49 50 /* Output data rate */ 51 const TIDS_outputDataRate_t odr; 52 53 #ifdef CONFIG_WSEN_TIDS_TRIGGER 54 /* Interrupt pin used for high and low limit interrupt events */ 55 const struct gpio_dt_spec gpio_threshold; 56 57 /* High temperature interrupt threshold */ 58 const int high_threshold; 59 60 /* Low temperature interrupt threshold */ 61 const int low_threshold; 62 #endif 63 }; 64 65 #ifdef CONFIG_WSEN_TIDS_TRIGGER 66 int tids_trigger_set(const struct device *dev, const struct sensor_trigger *trig, 67 sensor_trigger_handler_t handler); 68 69 int tids_threshold_set(const struct device *dev, const struct sensor_value *thresh_value, 70 bool upper); 71 72 int tids_init_interrupt(const struct device *dev); 73 #endif 74 75 int tids_i2c_init(const struct device *dev); 76 77 #endif /* ZEPHYR_DRIVERS_SENSOR_WSEN_TIDS_WSEN_TIDS_H_ */ 78