1 /* 2 * Copyright (c) 2016 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_SENSOR_HTS221_HTS221_H_ 8 #define ZEPHYR_DRIVERS_SENSOR_HTS221_HTS221_H_ 9 10 #include <zephyr/device.h> 11 #include <zephyr/sys/util.h> 12 #include <zephyr/types.h> 13 #include <stmemsc.h> 14 #include <zephyr/drivers/gpio.h> 15 #include <zephyr/drivers/sensor.h> 16 17 #include "hts221_reg.h" 18 19 #define HTS221_AUTOINCREMENT_ADDR BIT(7) 20 21 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) 22 #include <zephyr/drivers/spi.h> 23 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */ 24 25 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) 26 #include <zephyr/drivers/i2c.h> 27 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */ 28 29 struct hts221_data { 30 int16_t rh_sample; 31 int16_t t_sample; 32 33 uint8_t h0_rh_x2; 34 uint8_t h1_rh_x2; 35 uint16_t t0_degc_x8; 36 uint16_t t1_degc_x8; 37 int16_t h0_t0_out; 38 int16_t h1_t0_out; 39 int16_t t0_out; 40 int16_t t1_out; 41 42 #ifdef CONFIG_HTS221_TRIGGER 43 const struct device *dev; 44 struct gpio_callback drdy_cb; 45 46 const struct sensor_trigger *data_ready_trigger; 47 sensor_trigger_handler_t data_ready_handler; 48 49 #if defined(CONFIG_HTS221_TRIGGER_OWN_THREAD) 50 K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_HTS221_THREAD_STACK_SIZE); 51 struct k_thread thread; 52 struct k_sem drdy_sem; 53 #elif defined(CONFIG_HTS221_TRIGGER_GLOBAL_THREAD) 54 struct k_work work; 55 #endif 56 #endif /* CONFIG_HTS221_TRIGGER */ 57 }; 58 59 struct hts221_config { 60 stmdev_ctx_t ctx; 61 union { 62 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) 63 const struct i2c_dt_spec i2c; 64 #endif 65 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) 66 const struct spi_dt_spec spi; 67 #endif 68 } stmemsc_cfg; 69 70 #ifdef CONFIG_HTS221_TRIGGER 71 const struct gpio_dt_spec gpio_drdy; 72 const struct gpio_dt_spec gpio_int; 73 #endif /* CONFIG_HTS221_TRIGGER */ 74 }; 75 76 #ifdef CONFIG_HTS221_TRIGGER 77 int hts221_trigger_set(const struct device *dev, 78 const struct sensor_trigger *trig, 79 sensor_trigger_handler_t handler); 80 81 int hts221_init_interrupt(const struct device *dev); 82 #endif /* CONFIG_HTS221_TRIGGER */ 83 84 int hts221_spi_init(const struct device *dev); 85 int hts221_i2c_init(const struct device *dev); 86 87 #endif /* ZEPHYR_DRIVERS_SENSOR_HTS221_HTS221_H_ */ 88