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 BMP388s accessed via I2C.
11  */
12 
13 #include "bmp388.h"
14 
15 #if BMP388_BUS_I2C
bmp388_bus_check_i2c(const union bmp388_bus * bus)16 static int bmp388_bus_check_i2c(const union bmp388_bus *bus)
17 {
18 	return i2c_is_ready_dt(&bus->i2c) ? 0 : -ENODEV;
19 }
20 
bmp388_reg_read_i2c(const union bmp388_bus * bus,uint8_t start,uint8_t * buf,int size)21 static int bmp388_reg_read_i2c(const union bmp388_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 
bmp388_reg_write_i2c(const union bmp388_bus * bus,uint8_t reg,uint8_t val)27 static int bmp388_reg_write_i2c(const union bmp388_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 bmp388_bus_io bmp388_bus_io_i2c = {
34 	.check = bmp388_bus_check_i2c,
35 	.read = bmp388_reg_read_i2c,
36 	.write = bmp388_reg_write_i2c,
37 };
38 #endif /* BMP388_BUS_I2C */
39