-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsht3x.h
161 lines (143 loc) · 4.38 KB
/
sht3x.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef __SHT3X_H__
#define __SHT3X_H__
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#define SHT3X_REPETABILITY_LOW 0
#define SHT3X_REPETABILITY_MEDIUM 1
#define SHT3X_REPETABILITY_HIGH 2
/* sht3x commands define */
// read serial number:
#define CMD_READ_SERIALNBR 0x3780
// read status register:
#define CMD_READ_STATUS 0xF32D
// clear status register:
#define CMD_CLEAR_STATUS 0x3041
// enabled heater:
#define CMD_HEATER_ENABLE 0x306D
// disable heater
#define CMD_HEATER_DISABLE 0x3066
// soft reset
#define CMD_SOFT_RESET 0x30A2
// accelerated response time
#define CMD_ART 0x2B32
// break, stop periodic data acquisition mode
#define CMD_BREAK 0x3093
// measurement: polling, high repeatability
#define CMD_MEAS_POLLING_H 0x2400
// measurement: polling, medium repeatability
#define CMD_MEAS_POLLING_M 0x240B
// measurement: polling, low repeatability
#define CMD_MEAS_POLLING_L 0x2416
#define SHT3X_ADDR_PD 0x44 // addr pin pulled down: 0x44
#define SHT3X_ADDR_PU 0x45 // addr pin pulled down: 0x45
typedef union sht3x_status_word
{
rt_uint16_t status_word;
struct status_bits
{
rt_uint16_t checksum_ok : 1 ;
rt_uint16_t command_ok : 1 ;
rt_uint16_t reserved_3 : 2 ;
rt_uint16_t reset_detected : 1 ;
rt_uint16_t reserved_2 : 5 ;
rt_uint16_t T_tracking_alert : 1 ;
rt_uint16_t RH_tracking_alert : 1 ;
rt_uint16_t reserved_1 : 1 ;
rt_uint16_t heater : 1 ;
rt_uint16_t reserved_0 : 1 ;
rt_uint16_t alert_pending: 1 ;
} bits;
}sht3x_status;
struct sht3x_device
{
struct rt_i2c_bus_device *i2c;
rt_uint8_t sht3x_addr ;
rt_mutex_t lock;
float temperature ;
float humidity ;
/* the command for data readout: change it as you need */
rt_uint16_t cmd_readout;
sht3x_status status ;
};
typedef struct sht3x_device *sht3x_device_t;
/**
* This function read temperature and humidity by single shot mode
* Attention:
* - rt_thread_mdelay() is called to wait for SHT3x to be ready to read
* - the temperature and humidity is stored in the device driver structure
*
* @param dev the pointer of device driver structure
*
* @return the status of read data from SHT3x, RT_EOK means success.
*/
rt_err_t sht3x_read_singleshot(sht3x_device_t dev);
/**
* This function resets all parameter with default
*
* @param dev the pointer of device driver structure
*
* @return the softreset status,RT_EOK reprensents setting successfully.
*/
rt_err_t sht3x_softreset(sht3x_device_t dev);
/**
* This function clear the status register in SHT3x
*
* @param dev the pointer of device driver structure
*
* @return the command transfer status, RT_EOK means success.
*/
rt_err_t sht3x_clear_status(sht3x_device_t dev);
/**
* This function read the status register from SHT3x
* Attention:
* - the status word is stored in device driver structure
*
* @param dev the pointer of device driver structure
*
* @return the command transfer status, RT_EOK means success.
*/
rt_err_t sht3x_read_status(sht3x_device_t dev);
/**
* This function enable heater
* @param dev the pointer of device driver structure
*
* @return the command transfer status, RT_EOK means success.
*/
rt_err_t sht3x_enable_heater(sht3x_device_t dev);
/**
* This function disable heater
* @param dev the pointer of device driver structure
*
* @return the command transfer status, RT_EOK means success.
*/
rt_err_t sht3x_disable_heater(sht3x_device_t dev);
/**
* This function write accelerated response time command to SHT3x
* @param dev the pointer of device driver structure
*
* @return the command transfer status, RT_EOK means success.
*/
rt_err_t sht3x_acc_resp_time(sht3x_device_t dev);
/**
* This function write break command to SHT3x to break out of continuous readout mode
* @param dev the pointer of device driver structure
*
* @return the command transfer status, RT_EOK means success.
*/
rt_err_t sht3x_break(sht3x_device_t dev);
/**
* This function initializes sht3x registered device driver
*
* @param dev the name of sht3x device
*
* @return the sht3x device.
*/
sht3x_device_t sht3x_init(const char *i2c_bus_name, rt_uint8_t sht3x_addr);
/**
* This function releases memory and deletes mutex lock
*
* @param dev the pointer of device driver structure
*/
void sht3x_deinit(sht3x_device_t dev);
#endif /* _SHT30_H__ */