1 /*
2  * Copyright (c) 2022 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*
8  * Bus-specific functionality for BMI270s accessed via I2C.
9  */
10 
11 #include "bmi270.h"
12 
bmi270_bus_check_i2c(const union bmi270_bus * bus)13 static int bmi270_bus_check_i2c(const union bmi270_bus *bus)
14 {
15 	return device_is_ready(bus->i2c.bus) ? 0 : -ENODEV;
16 }
17 
bmi270_reg_read_i2c(const union bmi270_bus * bus,uint8_t start,uint8_t * data,uint16_t len)18 static int bmi270_reg_read_i2c(const union bmi270_bus *bus,
19 			       uint8_t start, uint8_t *data, uint16_t len)
20 {
21 	return i2c_burst_read_dt(&bus->i2c, start, data, len);
22 }
23 
bmi270_reg_write_i2c(const union bmi270_bus * bus,uint8_t start,const uint8_t * data,uint16_t len)24 static int bmi270_reg_write_i2c(const union bmi270_bus *bus, uint8_t start,
25 				const uint8_t *data, uint16_t len)
26 {
27 	return i2c_burst_write_dt(&bus->i2c, start, data, len);
28 }
29 
bmi270_bus_init_i2c(const union bmi270_bus * bus)30 static int bmi270_bus_init_i2c(const union bmi270_bus *bus)
31 {
32 	/* I2C is used by default
33 	 */
34 	return 0;
35 }
36 
37 const struct bmi270_bus_io bmi270_bus_io_i2c = {
38 	.check = bmi270_bus_check_i2c,
39 	.read = bmi270_reg_read_i2c,
40 	.write = bmi270_reg_write_i2c,
41 	.init = bmi270_bus_init_i2c,
42 };
43