1 /*
2  * Copyright 2023 Google LLC
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef TEST_DRIVERS_SENSOR_ACCEL_INCLUDE_CHECKS_H_
8 #define TEST_DRIVERS_SENSOR_ACCEL_INCLUDE_CHECKS_H_
9 
10 #include <zephyr/drivers/i2c.h>
11 #include <zephyr/drivers/spi.h>
12 
13 #include "bmi160.h"
14 
bmi160_i2c_is_touching_reg(struct i2c_msg * msgs,int num_msgs,int reg)15 static inline bool bmi160_i2c_is_touching_reg(struct i2c_msg *msgs, int num_msgs, int reg)
16 {
17 	__ASSERT_NO_MSG(num_msgs == 2);
18 	__ASSERT_NO_MSG(msgs[0].len == 1);
19 
20 	uint8_t start_reg = msgs[0].buf[0];
21 
22 	return (start_reg <= reg) && (reg < start_reg + msgs[1].len);
23 }
24 
bmi160_spi_is_touching_reg(const struct spi_buf_set * tx_bufs,const struct spi_buf_set * rx_bufs,int reg)25 static inline bool bmi160_spi_is_touching_reg(const struct spi_buf_set *tx_bufs,
26 					      const struct spi_buf_set *rx_bufs, int reg)
27 {
28 	__ASSERT_NO_MSG(tx_bufs->count == 2);
29 	const struct spi_buf *tx = &tx_bufs->buffers[0];
30 	const struct spi_buf *tx_data = &tx_bufs->buffers[1];
31 	uint32_t start_reg = ((uint8_t *)(tx->buf))[0] & BMI160_REG_MASK;
32 
33 	return (start_reg <= reg) && (reg < start_reg + tx_data->len);
34 }
35 
36 #endif /* TEST_DRIVERS_SENSOR_ACCEL_INCLUDE_CHECKS_H_ */
37