Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sensors: test: Add attribute support to sensor emulator backend #65278

Merged
merged 7 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions drivers/i2c/i2c_emul.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ static int i2c_emul_transfer(const struct device *dev, struct i2c_msg *msgs, uin
__ASSERT_NO_MSG(emul->api);
__ASSERT_NO_MSG(emul->api->transfer);

ret = api->transfer(emul->target, msgs, num_msgs, addr);
if (ret) {
return ret;
if (emul->mock_api != NULL && emul->mock_api->transfer != NULL) {
ret = emul->mock_api->transfer(emul->target, msgs, num_msgs, addr);
if (ret != -ENOSYS) {
return ret;
}
}

return 0;
return api->transfer(emul->target, msgs, num_msgs, addr);
}

/**
Expand Down Expand Up @@ -125,7 +127,7 @@ int i2c_emul_register(const struct device *dev, struct i2c_emul *emul)

sys_slist_append(&data->emuls, &emul->node);

LOG_INF("Register emulator '%s' at I2C addr %02x\n", name, emul->addr);
LOG_INF("Register emulator '%s' at I2C addr %02x", name, emul->addr);
yperess marked this conversation as resolved.
Show resolved Hide resolved

return 0;
}
Expand Down
7 changes: 4 additions & 3 deletions drivers/sensor/akm09918c/akm09918c_emul.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static int akm09918c_emul_init(const struct emul *target, const struct device *p
}

static int akm09918c_emul_backend_set_channel(const struct emul *target, enum sensor_channel ch,
q31_t value, int8_t shift)
const q31_t *value, int8_t shift)
{
if (!target || !target->data) {
return -EINVAL;
Expand Down Expand Up @@ -162,8 +162,9 @@ static int akm09918c_emul_backend_set_channel(const struct emul *target, enum se
data->reg[AKM09918C_REG_ST1] |= AKM09918C_ST1_DRDY;

/* Convert fixed-point Gauss values into microgauss and then into its bit representation */
int32_t microgauss = (shift < 0 ? ((int64_t)value >> -shift) : ((int64_t)value << shift)) *
1000000 / ((int64_t)INT32_MAX + 1);
int32_t microgauss =
(shift < 0 ? ((int64_t)*value >> -shift) : ((int64_t)*value << shift)) * 1000000 /
((int64_t)INT32_MAX + 1);
yperess marked this conversation as resolved.
Show resolved Hide resolved

int16_t reg_val =
CLAMP(microgauss, AKM09918C_MAGN_MIN_MICRO_GAUSS, AKM09918C_MAGN_MAX_MICRO_GAUSS) /
Expand Down
4 changes: 2 additions & 2 deletions drivers/sensor/amd_sb_tsi/sb_tsi_emul.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static int sb_tsi_emul_init(const struct emul *target, const struct device *pare
}

static int sb_tsi_emul_set_channel(const struct emul *target, enum sensor_channel chan,
q31_t value, int8_t shift)
const q31_t *value, int8_t shift)
{
struct sb_tsi_emul_data *data = target->data;
int64_t scaled_value;
Expand All @@ -111,7 +111,7 @@ static int sb_tsi_emul_set_channel(const struct emul *target, enum sensor_channe
return -ENOTSUP;
}

scaled_value = (int64_t)value << shift;
scaled_value = (int64_t)*value << shift;
millicelsius = scaled_value * 1000 / ((int64_t)INT32_MAX + 1);
reg_value = CLAMP(millicelsius / 125, 0, 0x7ff);

Expand Down
Loading
Loading