1 /* 2 * Copyright (c) 2016 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_SENSOR_TMP007_TMP007_H_ 8 #define ZEPHYR_DRIVERS_SENSOR_TMP007_TMP007_H_ 9 10 #include <zephyr/device.h> 11 #include <zephyr/drivers/i2c.h> 12 #include <zephyr/drivers/gpio.h> 13 #include <zephyr/sys/util.h> 14 15 #define TMP007_REG_CONFIG 0x02 16 #define TMP007_ALERT_EN_BIT BIT(8) 17 18 #define TMP007_REG_TOBJ 0x03 19 #define TMP007_DATA_INVALID_BIT BIT(0) 20 21 #define TMP007_REG_STATUS 0x04 22 #define TMP007_DATA_READY_INT_BIT BIT(14) 23 #define TMP007_TOBJ_TH_HIGH_INT_BIT BIT(13) 24 #define TMP007_TOBJ_TH_LOW_INT_BIT BIT(12) 25 #define TMP007_TOBJ_TH_INT_BITS \ 26 (TMP007_TOBJ_TH_HIGH_INT_BIT | TMP007_TOBJ_TH_LOW_INT_BIT) 27 28 #define TMP007_REG_TOBJ_TH_HIGH 0x06 29 #define TMP007_REG_TOBJ_TH_LOW 0x07 30 31 /* scale in micro degrees Celsius */ 32 #define TMP007_TEMP_SCALE 31250 33 #define TMP007_TEMP_TH_SCALE 500000 34 35 struct tmp007_config { 36 struct i2c_dt_spec i2c; 37 #ifdef CONFIG_TMP007_TRIGGER 38 struct gpio_dt_spec int_gpio; 39 #endif 40 }; 41 42 struct tmp007_data { 43 int16_t sample; 44 45 #ifdef CONFIG_TMP007_TRIGGER 46 struct gpio_callback gpio_cb; 47 const struct device *dev; 48 49 sensor_trigger_handler_t drdy_handler; 50 const struct sensor_trigger *drdy_trigger; 51 52 sensor_trigger_handler_t th_handler; 53 const struct sensor_trigger *th_trigger; 54 55 #if defined(CONFIG_TMP007_TRIGGER_OWN_THREAD) 56 K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_TMP007_THREAD_STACK_SIZE); 57 struct k_sem gpio_sem; 58 struct k_thread thread; 59 #elif defined(CONFIG_TMP007_TRIGGER_GLOBAL_THREAD) 60 struct k_work work; 61 #endif 62 63 #endif /* CONFIG_TMP007_TRIGGER */ 64 }; 65 66 #ifdef CONFIG_TMP007_TRIGGER 67 int tmp007_reg_read(const struct i2c_dt_spec *i2c, uint8_t reg, uint16_t *val); 68 69 int tmp007_reg_write(const struct i2c_dt_spec *i2c, uint8_t reg, uint16_t val); 70 71 int tmp007_reg_update(const struct i2c_dt_spec *i2c, uint8_t reg, 72 uint16_t mask, uint16_t val); 73 74 int tmp007_attr_set(const struct device *dev, 75 enum sensor_channel chan, 76 enum sensor_attribute attr, 77 const struct sensor_value *val); 78 79 int tmp007_trigger_set(const struct device *dev, 80 const struct sensor_trigger *trig, 81 sensor_trigger_handler_t handler); 82 83 int tmp007_init_interrupt(const struct device *dev); 84 #endif 85 86 #endif /* _SENSOR_TMP007_ */ 87