1 /* ST Microelectronics STTS751 temperature sensor
2  *
3  * Copyright (c) 2019 STMicroelectronics
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  *
7  * Datasheet:
8  * https://www.st.com/resource/en/datasheet/stts751.pdf
9  */
10 
11 #define DT_DRV_COMPAT st_stts751
12 
13 #include <string.h>
14 #include <zephyr/drivers/i2c.h>
15 #include <zephyr/logging/log.h>
16 
17 #include "stts751.h"
18 
19 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
20 
21 LOG_MODULE_DECLARE(STTS751, CONFIG_SENSOR_LOG_LEVEL);
22 
stts751_i2c_read(const struct device * dev,uint8_t reg_addr,uint8_t * value,uint16_t len)23 static int stts751_i2c_read(const struct device *dev, uint8_t reg_addr, uint8_t *value,
24 			    uint16_t len)
25 {
26 	const struct stts751_config *cfg = dev->config;
27 
28 	return i2c_burst_read_dt(&cfg->i2c, reg_addr, value, len);
29 }
30 
stts751_i2c_write(const struct device * dev,uint8_t reg_addr,uint8_t * value,uint16_t len)31 static int stts751_i2c_write(const struct device *dev, uint8_t reg_addr, uint8_t *value,
32 			     uint16_t len)
33 {
34 	const struct stts751_config *cfg = dev->config;
35 
36 	return i2c_burst_write_dt(&cfg->i2c, reg_addr, value, len);
37 }
38 
stts751_i2c_init(const struct device * dev)39 int stts751_i2c_init(const struct device *dev)
40 {
41 	struct stts751_data *data = dev->data;
42 
43 	data->ctx_i2c.read_reg = (stmdev_read_ptr) stts751_i2c_read;
44 	data->ctx_i2c.write_reg = (stmdev_write_ptr) stts751_i2c_write;
45 	data->ctx_i2c.mdelay = (stmdev_mdelay_ptr) stmemsc_mdelay,
46 
47 	data->ctx = &data->ctx_i2c;
48 	data->ctx->handle = (void *)dev;
49 
50 	return 0;
51 }
52 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */
53