Lines Matching +full:reg +full:- +full:rc
4 * SPDX-License-Identifier: Apache-2.0
72 const struct dht20_config *cfg = dev->config; in read_status()
73 int rc; in read_status() local
78 rc = i2c_write_dt(&cfg->bus, tx_buf, sizeof(tx_buf)); in read_status()
79 if (rc < 0) { in read_status()
81 return rc; in read_status()
84 rc = i2c_read_dt(&cfg->bus, rx_buf, sizeof(rx_buf)); in read_status()
85 if (rc < 0) { in read_status()
87 return rc; in read_status()
92 return rc; in read_status()
95 static inline int reset_register(const struct device *dev, uint8_t reg) in reset_register() argument
97 const struct dht20_config *cfg = dev->config; in reset_register()
98 int rc; in reset_register() local
99 uint8_t tx_buf[] = {reg, 0, 0}; in reset_register()
103 rc = i2c_write_read_dt(&cfg->bus, tx_buf, sizeof(tx_buf), rx_buf, sizeof(rx_buf)); in reset_register()
104 if (rc < 0) { in reset_register()
106 return rc; in reset_register()
110 tx_buf[0] = DHT20_MASK_RESET_REGISTER | reg; in reset_register()
113 rc = i2c_write_dt(&cfg->bus, tx_buf, sizeof(tx_buf)); in reset_register()
114 if (rc < 0) { in reset_register()
116 return rc; in reset_register()
119 return rc; in reset_register()
124 int rc; in reset_sensor() local
127 rc = read_status(dev, &status); in reset_sensor()
128 if (rc < 0) { in reset_sensor()
130 return rc; in reset_sensor()
138 rc = reset_register(dev, DHT20_RESET_REGISTER_0); in reset_sensor()
139 if (rc < 0) { in reset_sensor()
140 return rc; in reset_sensor()
142 rc = reset_register(dev, DHT20_RESET_REGISTER_1); in reset_sensor()
143 if (rc < 0) { in reset_sensor()
144 return rc; in reset_sensor()
146 rc = reset_register(dev, DHT20_RESET_REGISTER_2); in reset_sensor()
147 if (rc < 0) { in reset_sensor()
148 return rc; in reset_sensor()
159 const struct dht20_config *cfg = dev->config; in dht20_read_sample()
163 * +------+----------------------------------------+ in dht20_read_sample()
165 * +------+----------------------------------------+ in dht20_read_sample()
173 * +------+----------------------------------------+ in dht20_read_sample()
176 int rc; in dht20_read_sample() local
179 rc = i2c_read_dt(&cfg->bus, rx_buf, sizeof(rx_buf)); in dht20_read_sample()
180 if (rc < 0) { in dht20_read_sample()
182 return rc; in dht20_read_sample()
196 rc = -EIO; in dht20_read_sample()
200 return rc; in dht20_read_sample()
205 struct dht20_data *data = dev->data; in dht20_sample_fetch()
206 const struct dht20_config *cfg = dev->config; in dht20_sample_fetch()
207 int rc; in dht20_sample_fetch() local
214 return -ENOTSUP; in dht20_sample_fetch()
221 rc = i2c_write_dt(&cfg->bus, tx_buf, sizeof(tx_buf)); in dht20_sample_fetch()
222 if (rc < 0) { in dht20_sample_fetch()
224 return rc; in dht20_sample_fetch()
236 rc = read_status(dev, &status); in dht20_sample_fetch()
237 if (rc < 0) { in dht20_sample_fetch()
239 return rc; in dht20_sample_fetch()
243 rc = dht20_read_sample(dev, &data->t_sample, &data->rh_sample); in dht20_sample_fetch()
244 if (rc < 0) { in dht20_sample_fetch()
246 return rc; in dht20_sample_fetch()
258 * DegCT = (S / 2^20) * 200 - 50 in dht20_temp_convert()
259 * uDegCT = (S * 1e6 * 200 - 50 * 1e6) / (1 << 20) in dht20_temp_convert()
261 micro_c = ((int64_t)raw * 1000000 * 200) / BIT(20) - 50 * 1000000; in dht20_temp_convert()
263 val->val1 = micro_c / 1000000; in dht20_temp_convert()
264 val->val2 = micro_c % 1000000; in dht20_temp_convert()
278 val->val1 = micro_rh / 1000000; in dht20_rh_convert()
279 val->val2 = micro_rh % 1000000; in dht20_rh_convert()
285 const struct dht20_data *data = dev->data; in dht20_channel_get()
288 dht20_temp_convert(val, data->t_sample); in dht20_channel_get()
290 dht20_rh_convert(val, data->rh_sample); in dht20_channel_get()
292 return -ENOTSUP; in dht20_channel_get()
300 const struct dht20_config *cfg = dev->config; in dht20_init()
302 if (!i2c_is_ready_dt(&cfg->bus)) { in dht20_init()
303 LOG_ERR("I2C dev %s not ready", cfg->bus.bus->name); in dht20_init()
304 return -ENODEV; in dht20_init()