1 /*
2  * Copyright (c) 2024 TDK Invensense
3  * Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 /*
9  * Bus-specific functionality for ICM42670 accessed via I2C.
10  */
11 
12 #include "icm42670.h"
13 
14 #if CONFIG_I2C
icm42670_bus_check_i2c(const union icm42670_bus * bus)15 static int icm42670_bus_check_i2c(const union icm42670_bus *bus)
16 {
17 	return device_is_ready(bus->i2c.bus) ? 0 : -ENODEV;
18 }
19 
icm42670_reg_read_i2c(const union icm42670_bus * bus,uint8_t reg,uint8_t * buf,uint32_t size)20 static int icm42670_reg_read_i2c(const union icm42670_bus *bus, uint8_t reg, uint8_t *buf,
21 				 uint32_t size)
22 {
23 	return i2c_burst_read_dt(&bus->i2c, reg, buf, size);
24 }
25 
icm42670_reg_write_i2c(const union icm42670_bus * bus,uint8_t reg,uint8_t * buf,uint32_t size)26 static int icm42670_reg_write_i2c(const union icm42670_bus *bus, uint8_t reg, uint8_t *buf,
27 				  uint32_t size)
28 {
29 	return i2c_burst_write_dt(&bus->i2c, reg, buf, size);
30 }
31 
32 const struct icm42670_bus_io icm42670_bus_io_i2c = {
33 	.check = icm42670_bus_check_i2c,
34 	.read = icm42670_reg_read_i2c,
35 	.write = icm42670_reg_write_i2c,
36 };
37 #endif /* CONFIG_I2C */
38