summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2021-11-04 11:28:02 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-05 18:25:37 +0000
commitc1c881e4c88b298f34a5e776ec2bb1291a4c3d4d (patch)
tree46236dd7e1abdc628ed4642aa726a304eedcd128
parenta49f7d49b68297790ba3c1b174d51b3c07e47b6f (diff)
downloadchrome-ec-c1c881e4c88b298f34a5e776ec2bb1291a4c3d4d.tar.gz
zephyr: Add tests for bmi160_sec_raw_{read|write}8()
Add tests for the secondary i2c bus read/write functions. These are for accessing a separate magnetometer chip through the BMI160 in a sort of proxy/passthrough configuration. BRANCH=None BUG=b:184856157 TEST=zmake -D configure --test test-drivers Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: I637c4aab571aeaa80ace24596d65838bfd51b658 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3262102 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/test/drivers/src/bmi160.c70
1 files changed, 69 insertions, 1 deletions
diff --git a/zephyr/test/drivers/src/bmi160.c b/zephyr/test/drivers/src/bmi160.c
index ceb55896eb..68971028d9 100644
--- a/zephyr/test/drivers/src/bmi160.c
+++ b/zephyr/test/drivers/src/bmi160.c
@@ -1848,6 +1848,72 @@ static void test_bmi_gyr_fifo(void)
NULL);
}
+/** Test reading from compass via `bmi160_sec_raw_read8()` */
+static void test_bmi_sec_raw_read8(void)
+{
+ struct motion_sensor_t *ms = &motion_sensors[BMI_ACC_SENSOR_ID];
+ struct i2c_emul *emul = bmi_emul_get(BMI_ORD);
+
+ uint8_t expected_read_value = 0xAA;
+ uint8_t requested_reg_addr = 0x55;
+ uint8_t actual_reg_addr;
+ int actual_read_value;
+ int ret;
+
+ bmi_emul_set_reg(emul, BMI160_MAG_I2C_READ_DATA, expected_read_value);
+
+ ret = bmi160_sec_raw_read8(ms->port, ms->i2c_spi_addr_flags,
+ requested_reg_addr, &actual_read_value);
+
+ /* Verify return value */
+ zassert_equal(ret, EC_RES_SUCCESS, "Expected return code %d but got %d",
+ EC_RES_SUCCESS, ret);
+
+ /* Verify the correct value was read */
+ zassert_equal(expected_read_value, actual_read_value,
+ "Read value $%02x but expected to read $%02x",
+ actual_read_value, expected_read_value);
+
+ /* Verify the intended register address was read */
+ actual_reg_addr = bmi_emul_get_reg(emul, BMI160_MAG_I2C_READ_ADDR);
+ zassert_equal(requested_reg_addr, actual_reg_addr,
+ "Read reg $%02x but expected to read $%02x",
+ actual_reg_addr, requested_reg_addr);
+}
+
+/** Test writing to compass via `bmi160_sec_raw_write8()` */
+static void test_bmi_sec_raw_write8(void)
+{
+ struct motion_sensor_t *ms = &motion_sensors[BMI_ACC_SENSOR_ID];
+ struct i2c_emul *emul = bmi_emul_get(BMI_ORD);
+
+ uint8_t expected_write_value = 0xAB;
+ uint8_t requested_reg_addr = 0x56;
+ uint8_t actual_reg_addr;
+ int actual_written_value;
+ int ret;
+
+ ret = bmi160_sec_raw_write8(ms->port, ms->i2c_spi_addr_flags,
+ requested_reg_addr, expected_write_value);
+
+ /* Verify return value */
+ zassert_equal(ret, EC_RES_SUCCESS, "Expected return code %d but got %d",
+ EC_RES_SUCCESS, ret);
+
+ /* Verify the correct value was written */
+ actual_written_value =
+ bmi_emul_get_reg(emul, BMI160_MAG_I2C_WRITE_DATA);
+ zassert_equal(expected_write_value, actual_written_value,
+ "Wrote value $%02x but expected to write $%02x",
+ actual_written_value, expected_write_value);
+
+ /* Verify the intended register address was used */
+ actual_reg_addr = bmi_emul_get_reg(emul, BMI160_MAG_I2C_WRITE_ADDR);
+ zassert_equal(requested_reg_addr, actual_reg_addr,
+ "Wrote reg $%02x but expected to write $%02x",
+ actual_reg_addr, requested_reg_addr);
+}
+
void test_suite_bmi160(void)
{
ztest_test_suite(bmi160,
@@ -1868,6 +1934,8 @@ void test_suite_bmi160(void)
ztest_user_unit_test(test_bmi_gyr_perform_calib),
ztest_user_unit_test(test_bmi_init),
ztest_user_unit_test(test_bmi_acc_fifo),
- ztest_user_unit_test(test_bmi_gyr_fifo));
+ ztest_user_unit_test(test_bmi_gyr_fifo),
+ ztest_user_unit_test(test_bmi_sec_raw_read8),
+ ztest_user_unit_test(test_bmi_sec_raw_write8));
ztest_run_test_suite(bmi160);
}