diff options
Diffstat (limited to 'zephyr/emul')
-rw-r--r-- | zephyr/emul/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/emul/Kconfig | 1 | ||||
-rw-r--r-- | zephyr/emul/Kconfig.lis2dw12 | 23 | ||||
-rw-r--r-- | zephyr/emul/emul_lis2dw12.c | 69 | ||||
-rw-r--r-- | zephyr/emul/emul_ln9310.c | 1 |
5 files changed, 95 insertions, 0 deletions
diff --git a/zephyr/emul/CMakeLists.txt b/zephyr/emul/CMakeLists.txt index 5c5a69eb35..b46c51c8b6 100644 --- a/zephyr/emul/CMakeLists.txt +++ b/zephyr/emul/CMakeLists.txt @@ -13,3 +13,4 @@ zephyr_library_sources_ifdef(CONFIG_EMUL_BMI emul_bmi260.c) zephyr_library_sources_ifdef(CONFIG_EMUL_TCS3400 emul_tcs3400.c) zephyr_library_sources_ifdef(CONFIG_EMUL_BB_RETIMER emul_bb_retimer.c) zephyr_library_sources_ifdef(CONFIG_EMUL_LN9310 emul_ln9310.c) +zephyr_library_sources_ifdef(CONFIG_EMUL_LIS2DW12 emul_lis2dw12.c) diff --git a/zephyr/emul/Kconfig b/zephyr/emul/Kconfig index f52c27349b..c108caea4b 100644 --- a/zephyr/emul/Kconfig +++ b/zephyr/emul/Kconfig @@ -68,3 +68,4 @@ config EMUL_BB_RETIMER available in zephyr/include/emul/emul_bb_retimer.h rsource "Kconfig.ln9310" +rsource "Kconfig.lis2dw12" diff --git a/zephyr/emul/Kconfig.lis2dw12 b/zephyr/emul/Kconfig.lis2dw12 new file mode 100644 index 0000000000..2263255418 --- /dev/null +++ b/zephyr/emul/Kconfig.lis2dw12 @@ -0,0 +1,23 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +DT_COMPAT_LIS2DW12_EMUL := cros,lis2dw12-emul + +menuconfig EMUL_LIS2DW12 + bool "LIS2DW12 accelerometer emulator" + default $(dt_compat_enabled,$(DT_COMPAT_LIS2DW12_EMUL)) + depends on I2C_EMUL + select PLATFORM_EC_ACCEL_LIS2DW12 + help + Enable the LIS2DW12 emulator. This driver uses the emulated I2C bus. + It is used to test the lis2dw12 driver. Emulator API is available in + zephyr/include/emul/emul_lis2dw12.h + +if EMUL_LIS2DW12 + +module = LIS2DW12_EMUL +module-str = lis2dw12_emul +source "subsys/logging/Kconfig.template.log_config" + +endif # EMUL_LIS2DW12 diff --git a/zephyr/emul/emul_lis2dw12.c b/zephyr/emul/emul_lis2dw12.c new file mode 100644 index 0000000000..e775bdbb20 --- /dev/null +++ b/zephyr/emul/emul_lis2dw12.c @@ -0,0 +1,69 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#define DT_DRV_COMPAT cros_lis2dw12_emul + +#include <device.h> +#include <drivers/i2c.h> +#include <drivers/i2c_emul.h> +#include <emul.h> +#include <errno.h> +#include <sys/__assert.h> + +#include "driver/accel_lis2dw12.h" +#include "emul/emul_common_i2c.h" +#include "emul/emul_lis2dw12.h" +#include "i2c.h" + +#include <logging/log.h> +LOG_MODULE_REGISTER(lis2dw12_emul, CONFIG_LIS2DW12_EMUL_LOG_LEVEL); + +struct lis2dw12_emul_data { + /** Common I2C data */ + struct i2c_common_emul_data common; +}; + +struct lis2dw12_emul_cfg { + /** Common I2C config */ + struct i2c_common_emul_cfg common; +}; + +static struct i2c_emul_api lis2dw12_emul_api_i2c = { + .transfer = i2c_common_emul_transfer, +}; + +static int emul_lis2dw12_init(const struct emul *emul, + const struct device *parent) +{ + const struct lis2dw12_emul_cfg *lis2dw12_cfg = emul->cfg; + const struct i2c_common_emul_cfg *cfg = &(lis2dw12_cfg->common); + struct lis2dw12_emul_data *data = emul->data; + + data->common.emul.api = &lis2dw12_emul_api_i2c; + data->common.emul.addr = cfg->addr; + data->common.emul.parent = emul; + data->common.i2c = parent; + data->common.cfg = cfg; + i2c_common_emul_init(&data->common); + + return i2c_emul_register(parent, emul->dev_label, &data->common.emul); +} + +#define INIT_LIS2DW12(n) \ + static struct lis2dw12_emul_data lis2dw12_emul_data_##n = { \ + .common = { \ + }, \ + }; \ + static const struct lis2dw12_emul_cfg lis2dw12_emul_cfg_##n = { \ + .common = { \ + .i2c_label = DT_INST_BUS_LABEL(n), \ + .dev_label = DT_INST_LABEL(n), \ + .addr = DT_INST_REG_ADDR(n), \ + }, \ + }; \ + EMUL_DEFINE(emul_lis2dw12_init, DT_DRV_INST(n), \ + &lis2dw12_emul_cfg_##n, &lis2dw12_emul_data_##n) + +DT_INST_FOREACH_STATUS_OKAY(INIT_LIS2DW12) diff --git a/zephyr/emul/emul_ln9310.c b/zephyr/emul/emul_ln9310.c index 19e3fc7276..9298767d67 100644 --- a/zephyr/emul/emul_ln9310.c +++ b/zephyr/emul/emul_ln9310.c @@ -14,6 +14,7 @@ #include "driver/ln9310.h" #include "emul/emul_common_i2c.h" +#include "emul/emul_ln9310.h" #include "i2c.h" #include <logging/log.h> |