diff options
-rw-r--r-- | zephyr/emul/emul_ln9310.c | 17 | ||||
-rw-r--r-- | zephyr/include/emul/emul_ln9310.h | 10 | ||||
-rw-r--r-- | zephyr/test/drivers/src/ln9310.c | 2 |
3 files changed, 29 insertions, 0 deletions
diff --git a/zephyr/emul/emul_ln9310.c b/zephyr/emul/emul_ln9310.c index 9298767d67..d4eaa8e38d 100644 --- a/zephyr/emul/emul_ln9310.c +++ b/zephyr/emul/emul_ln9310.c @@ -29,6 +29,8 @@ struct ln9310_emul_data { struct i2c_common_emul_data common; /** The current emulated battery cell type */ enum battery_cell_type battery_cell_type; + /** Emulated INT1 MSK register */ + uint8_t int1_msk_reg; /** Emulated Lion control register */ uint8_t lion_ctrl_reg; /** Emulated startup control register */ @@ -122,6 +124,13 @@ void ln9310_emul_set_vin_gt_10v(const struct emul *emulator, bool is_gt_10v) data->bc_sts_b_reg &= ~LN9310_BC_STS_B_INFET_OUT_SWITCH_OK; } +bool ln9310_emul_is_init(const struct emul *emulator) +{ + struct ln9310_emul_data *data = emulator->data; + + return (data->int1_msk_reg & LN9310_INT1_MODE) == 0; +} + enum battery_cell_type board_get_battery_cell_type(void) { struct ln9310_emul_data *data = singleton->data; @@ -149,6 +158,10 @@ static int ln9310_emul_write_byte(struct i2c_emul *emul, int reg, uint8_t val, struct ln9310_emul_data *data = LN9310_DATA_FROM_I2C_EMUL(emul); switch (reg) { + case LN9310_REG_INT1_MSK: + __ASSERT_NO_MSG(bytes == 1); + data->int1_msk_reg = val; + break; case LN9310_REG_STARTUP_CTRL: __ASSERT_NO_MSG(bytes == 1); data->startup_ctrl_reg = val; @@ -242,6 +255,10 @@ static int ln9310_emul_read_byte(struct i2c_emul *emul, int reg, uint8_t *val, struct ln9310_emul_data *data = LN9310_DATA_FROM_I2C_EMUL(emul); switch (reg) { + case LN9310_REG_INT1_MSK: + __ASSERT_NO_MSG(bytes == 0); + *val = data->int1_msk_reg; + break; case LN9310_REG_STARTUP_CTRL: __ASSERT_NO_MSG(bytes == 0); *val = data->startup_ctrl_reg; diff --git a/zephyr/include/emul/emul_ln9310.h b/zephyr/include/emul/emul_ln9310.h index 8c9101dfab..dfa03eaa28 100644 --- a/zephyr/include/emul/emul_ln9310.h +++ b/zephyr/include/emul/emul_ln9310.h @@ -14,6 +14,7 @@ #include <emul.h> #include "driver/ln9310.h" +#include <stdbool.h> /** * @brief Select the current emulator to use. @@ -60,4 +61,13 @@ void ln9310_emul_set_version(const struct emul *emulator, int version); */ void ln9310_emul_set_vin_gt_10v(const struct emul *emulator, bool is_gt_10v); +/** + * @brief Get whether or not the LN9310 is initialized. + * + * @param emulator The LN9310 emulator to read. + * + * @return true if the LN9310 was correctly initialized. + */ +bool ln9310_emul_is_init(const struct emul *emulator); + #endif /* ZEPHYR_INCLUDE_EMUL_EMUL_LN9310_H_ */ diff --git a/zephyr/test/drivers/src/ln9310.c b/zephyr/test/drivers/src/ln9310.c index d41625f98f..0033931039 100644 --- a/zephyr/test/drivers/src/ln9310.c +++ b/zephyr/test/drivers/src/ln9310.c @@ -21,6 +21,7 @@ void test_ln9310_2s_no_startup__passes_init(void) ln9310_emul_set_version(emulator, LN9310_BC_STS_C_CHIP_REV_FIXED); zassert_ok(ln9310_init(), NULL); + zassert_true(ln9310_emul_is_init(emulator), NULL); } void test_ln9310_3s_no_startup__passes_init(void) @@ -36,6 +37,7 @@ void test_ln9310_3s_no_startup__passes_init(void) ln9310_emul_set_version(emulator, LN9310_BC_STS_C_CHIP_REV_FIXED); zassert_ok(ln9310_init(), NULL); + zassert_true(ln9310_emul_is_init(emulator), NULL); } void test_suite_ln9310(void) |