summaryrefslogtreecommitdiff
path: root/zephyr/emul/emul_bmi.c
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/emul/emul_bmi.c')
-rw-r--r--zephyr/emul/emul_bmi.c255
1 files changed, 131 insertions, 124 deletions
diff --git a/zephyr/emul/emul_bmi.c b/zephyr/emul/emul_bmi.c
index 37dba43e6d..fe46428f01 100644
--- a/zephyr/emul/emul_bmi.c
+++ b/zephyr/emul/emul_bmi.c
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -13,18 +13,16 @@ LOG_MODULE_REGISTER(emul_bmi);
#include <zephyr/drivers/emul.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/drivers/i2c_emul.h>
+#include <zephyr/sys/__assert.h>
#include "emul/emul_common_i2c.h"
#include "emul/emul_bmi.h"
+#include "emul/emul_stub_device.h"
#include "driver/accelgyro_bmi160.h"
#include "driver/accelgyro_bmi260.h"
#include "driver/accelgyro_bmi_common.h"
-#define BMI_DATA_FROM_I2C_EMUL(_emul) \
- CONTAINER_OF(CONTAINER_OF(_emul, struct i2c_common_emul_data, emul), \
- struct bmi_emul_data, common)
-
/** Run-time data used by the emulator */
struct bmi_emul_data {
/** Common I2C data */
@@ -87,7 +85,7 @@ struct bmi_emul_data {
};
/** Check description in emul_bmi.h */
-void bmi_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val)
+void bmi_emul_set_reg(const struct emul *emul, int reg, uint8_t val)
{
struct bmi_emul_data *data;
@@ -95,12 +93,12 @@ void bmi_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val)
return;
}
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
data->reg[reg] = val;
}
/** Check description in emul_bmi.h */
-uint8_t bmi_emul_get_reg(struct i2c_emul *emul, int reg)
+uint8_t bmi_emul_get_reg(const struct emul *emul, int reg)
{
struct bmi_emul_data *data;
@@ -108,7 +106,7 @@ uint8_t bmi_emul_get_reg(struct i2c_emul *emul, int reg)
return 0;
}
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
return data->reg[reg];
}
@@ -258,11 +256,11 @@ static uint16_t bmi_emul_gyr_off_to_nvm(int16_t off)
}
/** Check description in emul_bmi.h */
-int16_t bmi_emul_get_off(struct i2c_emul *emul, enum bmi_emul_axis axis)
+int16_t bmi_emul_get_off(const struct emul *emul, enum bmi_emul_axis axis)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
switch (axis) {
case BMI_EMUL_ACC_X:
@@ -283,30 +281,30 @@ int16_t bmi_emul_get_off(struct i2c_emul *emul, enum bmi_emul_axis axis)
}
/** Check description in emul_bmi.h */
-void bmi_emul_set_off(struct i2c_emul *emul, enum bmi_emul_axis axis,
+void bmi_emul_set_off(const struct emul *emul, enum bmi_emul_axis axis,
int16_t val)
{
struct bmi_emul_data *data;
uint16_t gyr_off;
uint8_t gyr98_shift;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
switch (axis) {
case BMI_EMUL_ACC_X:
data->off_acc_x = val;
data->reg[data->type_data->acc_off_reg] =
- bmi_emul_acc_off_to_nvm(data->off_acc_x);
+ bmi_emul_acc_off_to_nvm(data->off_acc_x);
break;
case BMI_EMUL_ACC_Y:
data->off_acc_y = val;
data->reg[data->type_data->acc_off_reg + 1] =
- bmi_emul_acc_off_to_nvm(data->off_acc_y);
+ bmi_emul_acc_off_to_nvm(data->off_acc_y);
break;
case BMI_EMUL_ACC_Z:
data->off_acc_z = val;
data->reg[data->type_data->acc_off_reg + 2] =
- bmi_emul_acc_off_to_nvm(data->off_acc_z);
+ bmi_emul_acc_off_to_nvm(data->off_acc_z);
break;
case BMI_EMUL_GYR_X:
data->off_gyr_x = val;
@@ -314,9 +312,9 @@ void bmi_emul_set_off(struct i2c_emul *emul, enum bmi_emul_axis axis,
data->reg[data->type_data->gyr_off_reg] = gyr_off & 0xff;
gyr98_shift = 0;
data->reg[data->type_data->gyr98_off_reg] &=
- ~(0x3 << gyr98_shift);
+ ~(0x3 << gyr98_shift);
data->reg[data->type_data->gyr98_off_reg] |=
- (gyr_off & 0x300) >> (8 - gyr98_shift);
+ (gyr_off & 0x300) >> (8 - gyr98_shift);
break;
case BMI_EMUL_GYR_Y:
data->off_gyr_y = val;
@@ -324,9 +322,9 @@ void bmi_emul_set_off(struct i2c_emul *emul, enum bmi_emul_axis axis,
data->reg[data->type_data->gyr_off_reg + 1] = gyr_off & 0xff;
gyr98_shift = 2;
data->reg[data->type_data->gyr98_off_reg] &=
- ~(0x3 << gyr98_shift);
+ ~(0x3 << gyr98_shift);
data->reg[data->type_data->gyr98_off_reg] |=
- (gyr_off & 0x300) >> (8 - gyr98_shift);
+ (gyr_off & 0x300) >> (8 - gyr98_shift);
break;
case BMI_EMUL_GYR_Z:
data->off_gyr_z = val;
@@ -334,19 +332,19 @@ void bmi_emul_set_off(struct i2c_emul *emul, enum bmi_emul_axis axis,
data->reg[data->type_data->gyr_off_reg + 2] = gyr_off & 0xff;
gyr98_shift = 4;
data->reg[data->type_data->gyr98_off_reg] &=
- ~(0x3 << gyr98_shift);
+ ~(0x3 << gyr98_shift);
data->reg[data->type_data->gyr98_off_reg] |=
- (gyr_off & 0x300) >> (8 - gyr98_shift);
+ (gyr_off & 0x300) >> (8 - gyr98_shift);
break;
}
}
/** Check description in emul_bmi.h */
-int32_t bmi_emul_get_value(struct i2c_emul *emul, enum bmi_emul_axis axis)
+int32_t bmi_emul_get_value(const struct emul *emul, enum bmi_emul_axis axis)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
switch (axis) {
case BMI_EMUL_ACC_X:
@@ -367,12 +365,12 @@ int32_t bmi_emul_get_value(struct i2c_emul *emul, enum bmi_emul_axis axis)
}
/** Check description in emul_bmi.h */
-void bmi_emul_set_value(struct i2c_emul *emul, enum bmi_emul_axis axis,
+void bmi_emul_set_value(const struct emul *emul, enum bmi_emul_axis axis,
int32_t val)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
switch (axis) {
case BMI_EMUL_ACC_X:
@@ -397,47 +395,47 @@ void bmi_emul_set_value(struct i2c_emul *emul, enum bmi_emul_axis axis,
}
/** Check description in emul_bmi.h */
-void bmi_emul_set_err_on_ro_write(struct i2c_emul *emul, bool set)
+void bmi_emul_set_err_on_ro_write(const struct emul *emul, bool set)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
data->error_on_ro_write = set;
}
/** Check description in emul_bmi.h */
-void bmi_emul_set_err_on_rsvd_write(struct i2c_emul *emul, bool set)
+void bmi_emul_set_err_on_rsvd_write(const struct emul *emul, bool set)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
data->error_on_rsvd_write = set;
}
/** Check description in emul_bmi.h */
-void bmi_emul_set_err_on_wo_read(struct i2c_emul *emul, bool set)
+void bmi_emul_set_err_on_wo_read(const struct emul *emul, bool set)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
data->error_on_wo_read = set;
}
/** Check description in emul_bmi.h */
-void bmi_emul_simulate_cmd_exec_time(struct i2c_emul *emul, bool set)
+void bmi_emul_simulate_cmd_exec_time(const struct emul *emul, bool set)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
data->simulate_command_exec_time = set;
}
/** Check description in emul_bmi.h */
-void bmi_emul_set_skipped_frames(struct i2c_emul *emul, uint8_t skip)
+void bmi_emul_set_skipped_frames(const struct emul *emul, uint8_t skip)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
data->fifo_skip = skip;
}
@@ -460,13 +458,13 @@ static int64_t bmi_emul_get_sensortime(void)
* @param reg Pointer to 3 byte array, where current sensor time should be
* stored
*/
-static void bmi_emul_set_sensortime_reg(struct i2c_emul *emul, uint8_t *reg)
+static void bmi_emul_set_sensortime_reg(const struct emul *emul, uint8_t *reg)
{
struct bmi_emul_data *data;
uint32_t twos_comp_val;
int64_t time;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
time = bmi_emul_get_sensortime();
@@ -487,13 +485,13 @@ static void bmi_emul_set_sensortime_reg(struct i2c_emul *emul, uint8_t *reg)
* @param reg Pointer to 2 byte array, where sensor value should be stored
* @param shift How many bits should be shift to the right
*/
-static void bmi_emul_set_data_reg(struct i2c_emul *emul, int32_t val,
+static void bmi_emul_set_data_reg(const struct emul *emul, int32_t val,
uint8_t *reg, int shift)
{
struct bmi_emul_data *data;
uint32_t twos_comp_val;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
twos_comp_val = bmi_emul_val_to_twos_comp(val);
@@ -515,14 +513,14 @@ static void bmi_emul_set_data_reg(struct i2c_emul *emul, int32_t val,
*
* @return length of frame
*/
-static uint8_t bmi_emul_get_frame_len(struct i2c_emul *emul,
+static uint8_t bmi_emul_get_frame_len(const struct emul *emul,
struct bmi_emul_frame *frame,
bool tag_time, bool header)
{
struct bmi_emul_data *data;
int len;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
/* Empty FIFO frame */
if (frame == NULL) {
@@ -584,7 +582,7 @@ static uint8_t bmi_emul_get_frame_len(struct i2c_emul *emul,
* data
* @param gyr_shift How many bits should be right shifted from gyroscope data
*/
-static void bmi_emul_set_current_frame(struct i2c_emul *emul,
+static void bmi_emul_set_current_frame(const struct emul *emul,
struct bmi_emul_frame *frame,
bool tag_time, bool header,
int acc_shift, int gyr_shift)
@@ -592,11 +590,11 @@ static void bmi_emul_set_current_frame(struct i2c_emul *emul,
struct bmi_emul_data *data;
int i = 0;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
data->fifo_frame_byte = 0;
- data->fifo_frame_len = bmi_emul_get_frame_len(emul, frame, tag_time,
- header);
+ data->fifo_frame_len =
+ bmi_emul_get_frame_len(emul, frame, tag_time, header);
/* Empty FIFO frame */
if (frame == NULL) {
if (tag_time && header) {
@@ -628,11 +626,14 @@ static void bmi_emul_set_current_frame(struct i2c_emul *emul,
if (header) {
data->fifo[0] = BMI_EMUL_FIFO_HEAD_DATA;
data->fifo[0] |= frame->type & BMI_EMUL_FRAME_MAG ?
- BMI_EMUL_FIFO_HEAD_DATA_MAG : 0;
+ BMI_EMUL_FIFO_HEAD_DATA_MAG :
+ 0;
data->fifo[0] |= frame->type & BMI_EMUL_FRAME_GYR ?
- BMI_EMUL_FIFO_HEAD_DATA_GYR : 0;
+ BMI_EMUL_FIFO_HEAD_DATA_GYR :
+ 0;
data->fifo[0] |= frame->type & BMI_EMUL_FRAME_ACC ?
- BMI_EMUL_FIFO_HEAD_DATA_ACC : 0;
+ BMI_EMUL_FIFO_HEAD_DATA_ACC :
+ 0;
data->fifo[0] |= frame->tag & BMI_EMUL_FIFO_HEAD_DATA_TAG_MASK;
i = 1;
}
@@ -679,20 +680,20 @@ static void bmi_emul_set_current_frame(struct i2c_emul *emul,
*
* @param emul Pointer to BMI emulator
*/
-static void bmi_emul_updata_int_off(struct i2c_emul *emul)
+static void bmi_emul_updata_int_off(const struct emul *emul)
{
struct bmi_emul_data *data;
uint16_t gyr_nvm;
uint8_t gyr98;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
data->off_acc_x = bmi_emul_acc_nvm_to_off(
- data->reg[data->type_data->acc_off_reg]);
+ data->reg[data->type_data->acc_off_reg]);
data->off_acc_y = bmi_emul_acc_nvm_to_off(
- data->reg[data->type_data->acc_off_reg + 1]);
+ data->reg[data->type_data->acc_off_reg + 1]);
data->off_acc_z = bmi_emul_acc_nvm_to_off(
- data->reg[data->type_data->acc_off_reg + 2]);
+ data->reg[data->type_data->acc_off_reg + 2]);
gyr98 = data->reg[data->type_data->gyr98_off_reg];
@@ -713,14 +714,14 @@ static void bmi_emul_updata_int_off(struct i2c_emul *emul)
*
* @param emul Pointer to BMI emulator
*/
-static void bmi_emul_restore_nvm(struct i2c_emul *emul)
+static void bmi_emul_restore_nvm(const struct emul *emul)
{
struct bmi_emul_data *data;
int i;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
- ASSERT(data->type_data->nvm_len <= BMI_EMUL_MAX_NVM_REGS);
+ __ASSERT_NO_MSG(data->type_data->nvm_len <= BMI_EMUL_MAX_NVM_REGS);
/* Restore registers values */
for (i = 0; i < data->type_data->nvm_len; i++) {
@@ -731,11 +732,11 @@ static void bmi_emul_restore_nvm(struct i2c_emul *emul)
}
/** Check description in emul_bmi.h */
-void bmi_emul_flush_fifo(struct i2c_emul *emul, bool tag_time, bool header)
+void bmi_emul_flush_fifo(const struct emul *emul, bool tag_time, bool header)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
data->fifo_skip = 0;
data->fifo_frame = NULL;
@@ -747,11 +748,11 @@ void bmi_emul_flush_fifo(struct i2c_emul *emul, bool tag_time, bool header)
}
/** Check description in emul_bmi.h */
-void bmi_emul_reset_common(struct i2c_emul *emul, bool tag_time, bool header)
+void bmi_emul_reset_common(const struct emul *emul, bool tag_time, bool header)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
/* Restore registers backed in NVM */
bmi_emul_restore_nvm(emul);
@@ -764,21 +765,21 @@ void bmi_emul_reset_common(struct i2c_emul *emul, bool tag_time, bool header)
}
/** Check description in emul_bmi.h */
-void bmi_emul_set_cmd_end_time(struct i2c_emul *emul, int time)
+void bmi_emul_set_cmd_end_time(const struct emul *emul, int time)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
data->cmd_end_time = k_uptime_get_32() + time;
}
/** Check description in emul_bmi.h */
-bool bmi_emul_is_cmd_end(struct i2c_emul *emul)
+bool bmi_emul_is_cmd_end(const struct emul *emul)
{
struct bmi_emul_data *data;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
/* We are simulating command execution time and it doesn't expired */
if (data->simulate_command_exec_time &&
@@ -803,14 +804,14 @@ bool bmi_emul_is_cmd_end(struct i2c_emul *emul)
* @return 0 on success
* @return -EIO on error
*/
-static int bmi_emul_handle_write(struct i2c_emul *emul, int reg, uint8_t val,
+static int bmi_emul_handle_write(const struct emul *emul, int reg, uint8_t val,
int byte)
{
struct bmi_emul_data *data;
uint8_t rsvd_mask;
int ret;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
ret = data->type_data->handle_write(data->reg, emul, reg, byte, val);
reg = data->type_data->access_reg(emul, reg, byte, false /* = read */);
@@ -855,16 +856,15 @@ static int bmi_emul_handle_write(struct i2c_emul *emul, int reg, uint8_t val,
}
/** Check description in emul_bmi.h */
-void bmi_emul_state_to_reg(struct i2c_emul *emul, int acc_shift,
+void bmi_emul_state_to_reg(const struct emul *emul, int acc_shift,
int gyr_shift, int acc_reg, int gyr_reg,
- int sensortime_reg, bool acc_off_en,
- bool gyr_off_en)
+ int sensortime_reg, bool acc_off_en, bool gyr_off_en)
{
struct bmi_emul_data *data;
int32_t val[3];
int i;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
if (gyr_off_en) {
val[0] = data->gyr_x - data->off_gyr_x;
@@ -900,12 +900,13 @@ void bmi_emul_state_to_reg(struct i2c_emul *emul, int acc_shift,
}
/** Check description in emul_bmi.h */
-void bmi_emul_append_frame(struct i2c_emul *emul, struct bmi_emul_frame *frame)
+void bmi_emul_append_frame(const struct emul *emul,
+ struct bmi_emul_frame *frame)
{
struct bmi_emul_data *data;
struct bmi_emul_frame *tmp_frame;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
if (data->fifo_frame == NULL) {
data->fifo_frame = frame;
@@ -919,13 +920,13 @@ void bmi_emul_append_frame(struct i2c_emul *emul, struct bmi_emul_frame *frame)
}
/** Check description in emul_bmi.h */
-uint16_t bmi_emul_fifo_len(struct i2c_emul *emul, bool tag_time, bool header)
+uint16_t bmi_emul_fifo_len(const struct emul *emul, bool tag_time, bool header)
{
struct bmi_emul_frame *frame;
struct bmi_emul_data *data;
uint16_t len = 0;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
if (data->fifo_skip != 0 && header) {
len += 2;
@@ -945,14 +946,13 @@ uint16_t bmi_emul_fifo_len(struct i2c_emul *emul, bool tag_time, bool header)
}
/** Check description in emul_bmi.h */
-uint8_t bmi_emul_get_fifo_data(struct i2c_emul *emul, int byte,
- bool tag_time, bool header, int acc_shift,
- int gyr_shift)
+uint8_t bmi_emul_get_fifo_data(const struct emul *emul, int byte, bool tag_time,
+ bool header, int acc_shift, int gyr_shift)
{
struct bmi_emul_data *data;
int ret;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
if (byte == 0) {
/* Repeat uncompleated read of frame */
@@ -967,6 +967,7 @@ uint8_t bmi_emul_get_fifo_data(struct i2c_emul *emul, int byte,
if (data->fifo_skip != 0 && byte == 1 && header) {
/* Return number of skipped frames */
+
ret = data->fifo_skip;
data->fifo_skip = 0;
@@ -999,13 +1000,13 @@ uint8_t bmi_emul_get_fifo_data(struct i2c_emul *emul, int byte,
* @return 0 on success
* @return -EIO on error
*/
-static int bmi_emul_handle_read(struct i2c_emul *emul, int reg, uint8_t *buf,
+static int bmi_emul_handle_read(const struct emul *emul, int reg, uint8_t *buf,
int byte)
{
struct bmi_emul_data *data;
int ret;
- data = BMI_DATA_FROM_I2C_EMUL(emul);
+ data = emul->data;
ret = data->type_data->handle_read(data->reg, emul, reg, byte, buf);
reg = data->type_data->access_reg(emul, reg, byte, true /* = read */);
@@ -1018,6 +1019,31 @@ static int bmi_emul_handle_read(struct i2c_emul *emul, int reg, uint8_t *buf,
return 0;
}
+/**
+ * @brief Called at the end of I2C read message.
+ *
+ * @param target Pointer to emulator
+ * @param reg Address which is now accessed by read command (first byte of last
+ * I2C write message)
+ * @param bytes Number of bytes responeded to the I2C read message
+ *
+ * @return 0 on success
+ * @return -EIO on error
+ */
+static int bmi_emul_finish_read(const struct emul *emul, int reg, int bytes)
+{
+ struct bmi_emul_data *data;
+ int ret;
+
+ data = emul->data;
+
+ if (data->type_data->finish_read == NULL) {
+ return 0;
+ }
+ ret = data->type_data->finish_read(data->reg, emul, reg, bytes);
+ return ret;
+}
+
/* Device instantiation */
/**
@@ -1031,42 +1057,31 @@ static int bmi_emul_handle_read(struct i2c_emul *emul, int reg, uint8_t *buf,
*
* @return 0 indicating success (always)
*/
-static int bmi_emul_init(const struct emul *emul,
- const struct device *parent)
+static int bmi_emul_init(const struct emul *emul, const struct device *parent)
{
- const struct i2c_common_emul_cfg *cfg = emul->cfg;
- struct i2c_common_emul_data *data = cfg->data;
- struct bmi_emul_data *bmi_data;
- int ret;
-
- data->emul.api = &i2c_common_emul_api;
- data->emul.addr = cfg->addr;
- data->i2c = parent;
- data->cfg = cfg;
- i2c_common_emul_init(data);
+ struct bmi_emul_data *data = emul->data;
- bmi_data = CONTAINER_OF(data, struct bmi_emul_data, common);
+ data->common.i2c = parent;
+ i2c_common_emul_init(&data->common);
- switch (bmi_data->type) {
+ switch (data->type) {
case BMI_EMUL_160:
- bmi_data->type_data = get_bmi160_emul_type_data();
+ data->type_data = get_bmi160_emul_type_data();
break;
case BMI_EMUL_260:
- bmi_data->type_data = get_bmi260_emul_type_data();
+ data->type_data = get_bmi260_emul_type_data();
break;
}
/* Set callback access_reg to type specific function */
- data->access_reg = bmi_data->type_data->access_reg;
+ data->common.access_reg = data->type_data->access_reg;
- ret = i2c_emul_register(parent, emul->dev_label, &data->emul);
+ data->type_data->reset(data->reg, emul);
- bmi_data->type_data->reset(bmi_data->reg, &data->emul);
-
- return ret;
+ return 0;
}
-#define BMI_EMUL(n) \
+#define BMI_EMUL(n) \
static struct bmi_emul_data bmi_emul_data_##n = { \
.error_on_ro_write = DT_INST_PROP(n, error_on_ro_write),\
.error_on_wo_read = DT_INST_PROP(n, error_on_wo_read), \
@@ -1081,32 +1096,24 @@ static int bmi_emul_init(const struct emul *emul,
.finish_write = NULL, \
.start_read = NULL, \
.read_byte = bmi_emul_handle_read, \
- .finish_read = NULL, \
+ .finish_read = bmi_emul_finish_read, \
.access_reg = NULL, \
}, \
- }; \
- \
- static const struct i2c_common_emul_cfg bmi_emul_cfg_##n = { \
- .i2c_label = DT_INST_BUS_LABEL(n), \
- .dev_label = DT_INST_LABEL(n), \
- .data = &bmi_emul_data_##n.common, \
- .addr = DT_INST_REG_ADDR(n), \
- }; \
- EMUL_DEFINE(bmi_emul_init, DT_DRV_INST(n), &bmi_emul_cfg_##n, \
- &bmi_emul_data_##n)
+ }; \
+ static const struct i2c_common_emul_cfg bmi_emul_cfg_##n = { \
+ .dev_label = DT_NODE_FULL_NAME(DT_DRV_INST(n)), \
+ .data = &bmi_emul_data_##n.common, \
+ .addr = DT_INST_REG_ADDR(n), \
+ }; \
+ EMUL_DT_INST_DEFINE(n, bmi_emul_init, &bmi_emul_data_##n, \
+ &bmi_emul_cfg_##n, &i2c_common_emul_api)
DT_INST_FOREACH_STATUS_OKAY(BMI_EMUL)
-#define BMI_EMUL_CASE(n) \
- case DT_INST_DEP_ORD(n): return &bmi_emul_data_##n.common.emul;
+DT_INST_FOREACH_STATUS_OKAY(EMUL_STUB_DEVICE);
-/** Check description in emul_bmi.h */
-struct i2c_emul *bmi_emul_get(int ord)
+struct i2c_common_emul_data *
+emul_bmi_get_i2c_common_data(const struct emul *emul)
{
- switch (ord) {
- DT_INST_FOREACH_STATUS_OKAY(BMI_EMUL_CASE)
-
- default:
- return NULL;
- }
+ return emul->data;
}