summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2021-12-01 16:14:17 -0700
committerCommit Bot <commit-bot@chromium.org>2021-12-08 19:43:21 +0000
commita5b613c19c958454cd2365dd3bdd1169a60ce945 (patch)
tree9ffb06f572caff8b55417cbf4c19627444ecfd10
parentd8018d1e5fb4fb17289cd06355112fab18227858 (diff)
downloadchrome-ec-a5b613c19c958454cd2365dd3bdd1169a60ce945.tar.gz
zephyr: lis2dw12: Add convenience functions to emulator
Add some functions for peeking at the registers in the LIS2DW12 emulator and helpers for accessing the ODR, MODE, and LPMODE bits in the control register. These will be used for an upcoming driver test BRANCH=None BUG=b:200046770 TEST=zmake -D configure --test test-drivers; make runhosttests Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: Ia4134c3a8b2edac1f9929bb3fca52f37d3fc8496 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3311182 Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r--zephyr/emul/emul_lis2dw12.c42
-rw-r--r--zephyr/include/emul/emul_lis2dw12.h35
2 files changed, 77 insertions, 0 deletions
diff --git a/zephyr/emul/emul_lis2dw12.c b/zephyr/emul/emul_lis2dw12.c
index 2cc1a25622..3a29b74816 100644
--- a/zephyr/emul/emul_lis2dw12.c
+++ b/zephyr/emul/emul_lis2dw12.c
@@ -110,6 +110,48 @@ static int lis2dw12_emul_read_byte(struct i2c_emul *emul, int reg, uint8_t *val,
return 0;
}
+uint8_t lis2dw12_emul_peek_reg(struct i2c_emul *emul, int reg)
+{
+ __ASSERT(emul, "emul is NULL");
+
+ uint8_t val;
+ int rv;
+
+ rv = lis2dw12_emul_read_byte(emul, reg, &val, 0);
+ __ASSERT(rv == 0, "Read function returned non-zero: %d", rv);
+
+ return val;
+}
+
+uint8_t lis2dw12_emul_peek_odr(struct i2c_emul *emul)
+{
+ __ASSERT(emul, "emul is NULL");
+
+ uint8_t reg = lis2dw12_emul_peek_reg(emul, LIS2DW12_ACC_ODR_ADDR);
+
+ return (reg & LIS2DW12_ACC_ODR_MASK) >>
+ __builtin_ctz(LIS2DW12_ACC_ODR_MASK);
+}
+
+uint8_t lis2dw12_emul_peek_mode(struct i2c_emul *emul)
+{
+ __ASSERT(emul, "emul is NULL");
+
+ uint8_t reg = lis2dw12_emul_peek_reg(emul, LIS2DW12_ACC_MODE_ADDR);
+
+ return (reg & LIS2DW12_ACC_MODE_MASK) >>
+ __builtin_ctz(LIS2DW12_ACC_MODE_MASK);
+}
+
+uint8_t lis2dw12_emul_peek_lpmode(struct i2c_emul *emul)
+{
+ __ASSERT(emul, "emul is NULL");
+
+ uint8_t reg = lis2dw12_emul_peek_reg(emul, LIS2DW12_ACC_LPMODE_ADDR);
+
+ return (reg & LIS2DW12_ACC_LPMODE_MASK);
+}
+
static int lis2dw12_emul_write_byte(struct i2c_emul *emul, int reg, uint8_t val,
int bytes)
{
diff --git a/zephyr/include/emul/emul_lis2dw12.h b/zephyr/include/emul/emul_lis2dw12.h
index b136e24f0a..91ad5c0948 100644
--- a/zephyr/include/emul/emul_lis2dw12.h
+++ b/zephyr/include/emul/emul_lis2dw12.h
@@ -45,4 +45,39 @@ void lis2dw12_emul_set_who_am_i(const struct emul *emul, uint8_t who_am_i);
*/
uint32_t lis2dw12_emul_get_soft_reset_count(const struct emul *emul);
+/**
+ * @brief Peeks at the value of a register without doing any I2C transaction.
+ * If the register is unsupported, or `emul` is NULL, this function
+ * asserts.
+ *
+ * @param emul The emulator to query
+ * @param reg The register to access
+ * @return The value of the register
+ */
+uint8_t lis2dw12_emul_peek_reg(struct i2c_emul *emul, int reg);
+
+/**
+ * @brief Retrieves the ODR[3:0] bits from CRTL1 register
+ *
+ * @param emul The emulator to query
+ * @return The ODR bits, right-aligned
+ */
+uint8_t lis2dw12_emul_peek_odr(struct i2c_emul *emul);
+
+/**
+ * @brief Retrieves the MODE[1:0] bits from CRTL1 register
+ *
+ * @param emul The emulator to query
+ * @return The MODE bits, right-aligned
+ */
+uint8_t lis2dw12_emul_peek_mode(struct i2c_emul *emul);
+
+/**
+ * @brief Retrieves the LPMODE[1:0] bits from CRTL1 register
+ *
+ * @param emul The emulator to query
+ * @return The LPMODE bits, right-aligned
+ */
+uint8_t lis2dw12_emul_peek_lpmode(struct i2c_emul *emul);
+
#endif /* ZEPHYR_INCLUDE_EMUL_EMUL_LIS2DW12_H_ */