1 /*
2 * Copyright (c) 2016, 2017 Intel Corporation
3 * Copyright (c) 2017 IpTronix S.r.l.
4 * Copyright (c) 2021 Nordic Semiconductor ASA
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 /*
10 * Bus-specific functionality for BME280s accessed via I2C.
11 */
12
13 #include "bme280.h"
14
15 #if BME280_BUS_I2C
bme280_bus_check_i2c(const union bme280_bus * bus)16 static int bme280_bus_check_i2c(const union bme280_bus *bus)
17 {
18 return device_is_ready(bus->i2c.bus) ? 0 : -ENODEV;
19 }
20
bme280_reg_read_i2c(const union bme280_bus * bus,uint8_t start,uint8_t * buf,int size)21 static int bme280_reg_read_i2c(const union bme280_bus *bus,
22 uint8_t start, uint8_t *buf, int size)
23 {
24 return i2c_burst_read_dt(&bus->i2c, start, buf, size);
25 }
26
bme280_reg_write_i2c(const union bme280_bus * bus,uint8_t reg,uint8_t val)27 static int bme280_reg_write_i2c(const union bme280_bus *bus,
28 uint8_t reg, uint8_t val)
29 {
30 return i2c_reg_write_byte_dt(&bus->i2c, reg, val);
31 }
32
33 const struct bme280_bus_io bme280_bus_io_i2c = {
34 .check = bme280_bus_check_i2c,
35 .read = bme280_reg_read_i2c,
36 .write = bme280_reg_write_i2c,
37 };
38 #endif /* BME280_BUS_I2C */
39