1 /* 2 * Copyright (c) 2021 Thomas Stranger 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_SENSOR_SHTCX_SHTCX_H_ 8 #define ZEPHYR_DRIVERS_SENSOR_SHTCX_SHTCX_H_ 9 10 #include <zephyr/device.h> 11 #include <zephyr/devicetree.h> 12 #include <zephyr/kernel.h> 13 #include <zephyr/drivers/i2c.h> 14 #include <zephyr/drivers/gpio.h> 15 16 /* common cmds */ 17 #define SHTCX_CMD_READ_ID 0xEFC8 18 #define SHTCX_CMD_SOFT_RESET 0x805D 19 /* shtc3 only: */ 20 #define SHTCX_CMD_SLEEP 0xB098 21 #define SHTCX_CMD_WAKEUP 0x3517 22 23 #define SHTCX_POWER_UP_TIME_US 240U 24 /* Soft reset time is 230us for shtc1 and 240us for shtc3 */ 25 #define SHTCX_SOFT_RESET_TIME_US 240U 26 27 #define SHTCX_MAX_READ_LEN 6 28 #define SHTCX_WORD_LEN 2 29 #define SHTCX_CRC8_LEN 1 30 31 #define SHTC3_ID_MASK 0x083F 32 #define SHTC3_ID_VALUE 0x0807 33 #define SHTC1_ID_MASK 0x083F 34 #define SHTC1_ID_VALUE 0x0007 35 36 /* defines matching the related enums DT_ENUM_IDX: */ 37 #define CHIP_SHTC1 0 38 #define CHIP_SHTC3 1 39 #define MEASURE_MODE_NORMAL 0 40 #define MEASURE_MODE_LOW_POWER 1 41 42 enum shtcx_chip { 43 SHTC1 = CHIP_SHTC1, 44 SHTC3 = CHIP_SHTC3, 45 }; 46 47 enum shtcx_measure_mode { 48 NORMAL = MEASURE_MODE_NORMAL, 49 LOW_POWER = MEASURE_MODE_LOW_POWER, 50 }; 51 52 struct shtcx_sample { 53 uint16_t temp; 54 uint16_t humidity; 55 } __packed __aligned(2); 56 57 struct shtcx_config { 58 struct i2c_dt_spec i2c; 59 enum shtcx_chip chip; 60 enum shtcx_measure_mode measure_mode; 61 bool clock_stretching; 62 }; 63 64 struct shtcx_data { 65 struct shtcx_sample sample; 66 }; 67 68 #endif /* ZEPHYR_DRIVERS_SENSOR_SHTCX_SHTCX_H_ */ 69