diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2021-01-11 15:56:27 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-12 04:51:25 +0000 |
commit | 32b90cdae2520c2bb8e4f68da50575621dc270c2 (patch) | |
tree | 056e7b32246ed97f8a06927116027bab78556701 /zephyr/test/i2c_dts | |
parent | fab5311de6366c28acf7f86ff0c52c764cacc060 (diff) | |
download | chrome-ec-32b90cdae2520c2bb8e4f68da50575621dc270c2.tar.gz |
zephyr: copy zephyr-chrome/tests/dts/bindings/i2c to platform/ec
Previous Git history can be found here:
https://chromium.googlesource.com/chromiumos/platform/zephyr-chrome/+log/cc6e5d19939c03ac091b5e91d1a3b511ba99b68a/tests/dts/bindings/i2c
BUG=b:177157241
BRANCH=none
TEST=zmake testall
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: I6a0d774f8400a9fd2d7a8ce7f96943b3601debe4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2622899
Commit-Queue: Yuval Peress <peress@chromium.org>
Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'zephyr/test/i2c_dts')
-rw-r--r-- | zephyr/test/i2c_dts/CMakeLists.txt | 12 | ||||
-rw-r--r-- | zephyr/test/i2c_dts/boards/native_posix.overlay | 22 | ||||
-rw-r--r-- | zephyr/test/i2c_dts/prj.conf | 14 | ||||
-rw-r--r-- | zephyr/test/i2c_dts/src/main.c | 30 | ||||
-rw-r--r-- | zephyr/test/i2c_dts/zmake.yaml | 10 |
5 files changed, 88 insertions, 0 deletions
diff --git a/zephyr/test/i2c_dts/CMakeLists.txt b/zephyr/test/i2c_dts/CMakeLists.txt new file mode 100644 index 0000000000..1537267349 --- /dev/null +++ b/zephyr/test/i2c_dts/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright 2020 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. + +cmake_minimum_required(VERSION 3.13.1) +set(BOARD native_posix) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(i2c_test) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/zephyr/test/i2c_dts/boards/native_posix.overlay b/zephyr/test/i2c_dts/boards/native_posix.overlay new file mode 100644 index 0000000000..272be85361 --- /dev/null +++ b/zephyr/test/i2c_dts/boards/native_posix.overlay @@ -0,0 +1,22 @@ +/* Copyright 2020 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. + */ + +/ { + named-i2c-ports { + compatible = "i2c-keys"; + accel-0 { + i2c-port = <&bmi_i2c>; + label = "ACCEL_0"; + }; + }; +}; + +&i2c0 { + bmi_i2c: bmi@68 { + compatible = "bosch,bmi160"; + reg = <0x68>; + label = "accel-i2c"; + }; +}; diff --git a/zephyr/test/i2c_dts/prj.conf b/zephyr/test/i2c_dts/prj.conf new file mode 100644 index 0000000000..a08cdbb7fb --- /dev/null +++ b/zephyr/test/i2c_dts/prj.conf @@ -0,0 +1,14 @@ +CONFIG_ZTEST=y +CONFIG_LOG=y + +CONFIG_EMUL=y +CONFIG_I2C=y +CONFIG_I2C_EMUL=y +CONFIG_BMI160=y +CONFIG_EMUL_BMI160=y +CONFIG_SENSOR=y +CONFIG_BMI160_TRIGGER_NONE=y + +# TODO(b/173711210) figure out why SPI is required here when we're not using it. +CONFIG_SPI=y +CONFIG_SPI_EMUL=y diff --git a/zephyr/test/i2c_dts/src/main.c b/zephyr/test/i2c_dts/src/main.c new file mode 100644 index 0000000000..359808776b --- /dev/null +++ b/zephyr/test/i2c_dts/src/main.c @@ -0,0 +1,30 @@ +/* Copyright 2020 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. + */ + +#include <device.h> +#include <devicetree.h> +#include <ztest.h> + +static void test_i2c_get_device(void) +{ + const struct device *accel0 = device_get_binding( + DT_PROP_BY_PHANDLE(DT_PATH(named_i2c_ports, accel_0), i2c_port, + label)); + const struct device *bmi_i2c = device_get_binding( + DT_LABEL(DT_NODELABEL(bmi_i2c))); + + zassert_not_null(accel0, "accel0 was NULL"); + zassert_not_null(bmi_i2c, "bmi_i2c was NULL"); + zassert_equal(accel0, bmi_i2c, + "named_i2c_ports/accel0 and bmi_i2c should resolve to the same device"); +} + +/* test case main entry */ +void test_main(void) +{ + ztest_test_suite(test_i2c_bindings, + ztest_user_unit_test(test_i2c_get_device)); + ztest_run_test_suite(test_i2c_bindings); +} diff --git a/zephyr/test/i2c_dts/zmake.yaml b/zephyr/test/i2c_dts/zmake.yaml new file mode 100644 index 0000000000..d0d40dd473 --- /dev/null +++ b/zephyr/test/i2c_dts/zmake.yaml @@ -0,0 +1,10 @@ +# Copyright 2020 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. + +board: native_posix +supported-zephyr-versions: + - v2.4 +output-type: elf +toolchain: llvm +is-test: true |