1 /*
2  * Copyright (c) 2016, 2017 Intel Corporation
3  * Copyright (c) 2017 IpTronix S.r.l.
4  * Copyright (c) 2021 Nordic Semiconductor ASA
5  * Copyright (c) 2022, Leonard Pollak
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 
10 /*
11  * Bus-specific functionality for BME680s accessed via I2C.
12  */
13 
14 #include "bme680.h"
15 
16 #if BME680_BUS_I2C
bme680_bus_check_i2c(const union bme680_bus * bus)17 static int bme680_bus_check_i2c(const union bme680_bus *bus)
18 {
19 	return device_is_ready(bus->i2c.bus) ? 0 : -ENODEV;
20 }
21 
bme680_reg_read_i2c(const struct device * dev,uint8_t start,uint8_t * buf,int size)22 static int bme680_reg_read_i2c(const struct device *dev,
23 			       uint8_t start, uint8_t *buf, int size)
24 {
25 	const struct bme680_config *config = dev->config;
26 
27 	return i2c_burst_read_dt(&config->bus.i2c, start, buf, size);
28 }
29 
bme680_reg_write_i2c(const struct device * dev,uint8_t reg,uint8_t val)30 static int bme680_reg_write_i2c(const struct device *dev,
31 				uint8_t reg, uint8_t val)
32 {
33 	const struct bme680_config *config = dev->config;
34 
35 	return i2c_reg_write_byte_dt(&config->bus.i2c, reg, val);
36 }
37 
38 const struct bme680_bus_io bme680_bus_io_i2c = {
39 	.check = bme680_bus_check_i2c,
40 	.read = bme680_reg_read_i2c,
41 	.write = bme680_reg_write_i2c,
42 };
43 #endif /* BME680_BUS_I2C */
44