diff options
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/shim/src/led_driver/led_pwm.c | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/CMakeLists.txt | 4 | ||||
-rw-r--r-- | zephyr/test/drivers/Kconfig | 3 | ||||
-rw-r--r-- | zephyr/test/drivers/pwm_led_driver/CMakeLists.txt | 10 | ||||
-rw-r--r-- | zephyr/test/drivers/pwm_led_driver/led_pins.dts | 108 | ||||
-rw-r--r-- | zephyr/test/drivers/pwm_led_driver/prj.conf | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/pwm_led_driver/src/led.c | 91 | ||||
-rw-r--r-- | zephyr/test/drivers/testcase.yaml | 6 |
8 files changed, 229 insertions, 1 deletions
diff --git a/zephyr/shim/src/led_driver/led_pwm.c b/zephyr/shim/src/led_driver/led_pwm.c index 0b95248d81..a8244be67d 100644 --- a/zephyr/shim/src/led_driver/led_pwm.c +++ b/zephyr/shim/src/led_driver/led_pwm.c @@ -95,6 +95,8 @@ void led_set_color(enum led_color color, enum ec_led_id led_id) void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) { + memset(brightness_range, 0, EC_LED_COLOR_COUNT); + for (int i = 0; i < ARRAY_SIZE(pins_node); i++) { int br_color = pins_node[i]->br_color; diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt index 37353b59f8..05782e1e44 100644 --- a/zephyr/test/drivers/CMakeLists.txt +++ b/zephyr/test/drivers/CMakeLists.txt @@ -28,6 +28,9 @@ elseif("${ZMAKE_PROJECT_NAME}" STREQUAL "test-drivers-isl923x") elseif("${ZMAKE_PROJECT_NAME}" STREQUAL "test-drivers-led_driver") set(CONFIG_LINK_TEST_SUITE_LED_DRIVER TRUE) add_compile_definitions(CONFIG_LINK_TEST_SUITE_LED_DRIVER=1) +elseif("${ZMAKE_PROJECT_NAME}" STREQUAL "test-drivers-pwm_led_driver") + set(CONFIG_LINK_TEST_SUITE_PWM_LED_DRIVER TRUE) + add_compile_definitions(CONFIG_LINK_TEST_SUITE_PWM_LED_DRIVER=1) elseif("${ZMAKE_PROJECT_NAME}" STREQUAL "test-drivers-usbc_alt_mode") set(CONFIG_LINK_TEST_SUITE_USBC_ALT_MODE TRUE) add_compile_definitions(CONFIG_LINK_TEST_SUITE_USBC_ALT_MODE=1) @@ -39,6 +42,7 @@ add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_AP_MUX_CONTROL ap_mux_control) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_CHARGESPLASH chargesplash) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_ISL923X isl923x) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_LED_DRIVER led_driver) +add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_PWM_LED_DRIVER pwm_led_driver) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USB_MALFUNCTION_SINK usb_malfunction_sink) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USBC_ALT_MODE usbc_alt_mode) diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig index d3fc101968..5243c333f8 100644 --- a/zephyr/test/drivers/Kconfig +++ b/zephyr/test/drivers/Kconfig @@ -17,6 +17,9 @@ config LINK_TEST_SUITE_ISL923X config LINK_TEST_SUITE_LED_DRIVER bool "Link and test the led_driver tests" +config LINK_TEST_SUITE_PWM_LED_DRIVER + bool "Link and test the pwm_led_driver tests" + config LINK_TEST_SUITE_USB_MALFUNCTION_SINK bool "Link and test the usb_malfunction_sink tests" diff --git a/zephyr/test/drivers/pwm_led_driver/CMakeLists.txt b/zephyr/test/drivers/pwm_led_driver/CMakeLists.txt new file mode 100644 index 0000000000..3e4f48724d --- /dev/null +++ b/zephyr/test/drivers/pwm_led_driver/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright 2022 The ChromiumOS Authors. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Add include paths +target_include_directories(app PRIVATE + "${PLATFORM_EC}/zephyr/shim/src/led_driver") + +# Add source files +target_sources(app PRIVATE src/led.c) diff --git a/zephyr/test/drivers/pwm_led_driver/led_pins.dts b/zephyr/test/drivers/pwm_led_driver/led_pins.dts new file mode 100644 index 0000000000..5455a21bef --- /dev/null +++ b/zephyr/test/drivers/pwm_led_driver/led_pins.dts @@ -0,0 +1,108 @@ +/* Copyright 2022 The ChromiumOS Authors. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/dt-bindings/pwm/pwm.h> + +/ { + pwms { + #address-cells = <1>; + #size-cells = <1>; + + pwm_blue_left: pwm@0 { + compatible = "cros,pwm-mock"; + reg = <0 1>; + #pwm-cells = <2>; + status = "okay"; + }; + pwm_white_left: pwm@1 { + compatible = "cros,pwm-mock"; + reg = <1 1>; + #pwm-cells = <2>; + status = "okay"; + }; + pwm_amber_right: pwm@2 { + compatible = "cros,pwm-mock"; + reg = <2 1>; + #pwm-cells = <2>; + status = "okay"; + }; + pwm_white_right: pwm@3 { + compatible = "cros,pwm-mock"; + reg = <3 1>; + #pwm-cells = <2>; + status = "okay"; + }; + }; + + pwmleds { + compatible = "cros-ec,pwm-pin-config"; + + pwmled_blue_left: pwmled_b_left { + #led-pin-cells = <1>; + pwms = <&pwm_blue_left 0 1000000>; + }; + pwmled_white_left: pwmled_w_left { + #led-pin-cells = <1>; + pwms = <&pwm_white_left 0 1000000>; + }; + pwmled_amber_right: pwmled_y_right { + #led-pin-cells = <1>; + pwms = <&pwm_amber_right 0 1000000>; + }; + pwmled_white_right: pwmled_w_right { + #led-pin-cells = <1>; + pwms = <&pwm_white_right 0 1000000>; + }; + }; + + pwm-led-pins { + compatible = "cros-ec,pwm-led-pins"; + + color_off_left: color-off-left { + led-color = "LED_OFF"; + led-id = "EC_LED_ID_LEFT_LED"; + led-pins = <&pwmled_blue_left 0>, + <&pwmled_white_left 0>; + }; + color_off_right: color-off-right { + led-color = "LED_OFF"; + led-id = "EC_LED_ID_RIGHT_LED"; + led-pins = <&pwmled_amber_right 0>, + <&pwmled_white_right 0>; + }; + color_blue_left: color-blue-left { + led-color = "LED_BLUE"; + led-id = "EC_LED_ID_LEFT_LED"; + br-color = "EC_LED_COLOR_BLUE"; + led-pins = <&pwmled_blue_left 100>, + <&pwmled_white_left 0>; + }; + color_amber_right: color-amber-right { + led-color = "LED_AMBER"; + led-id = "EC_LED_ID_RIGHT_LED"; + br-color = "EC_LED_COLOR_AMBER"; + led-pins = <&pwmled_amber_right 100>, + <&pwmled_white_right 0>; + }; + color_white_left: color-white-left { + led-color = "LED_WHITE"; + led-id = "EC_LED_ID_LEFT_LED"; + br-color = "EC_LED_COLOR_WHITE"; + led-pins = <&pwmled_blue_left 0>, + <&pwmled_white_left 100>; + }; + color_white_right: color-white-right { + led-color = "LED_WHITE"; + led-id = "EC_LED_ID_RIGHT_LED"; + br-color = "EC_LED_COLOR_WHITE"; + led-pins = <&pwmled_amber_right 0>, + <&pwmled_white_right 100>; + }; + }; + + led-colors { + compatible = "cros-ec,led-policy"; + }; +}; diff --git a/zephyr/test/drivers/pwm_led_driver/prj.conf b/zephyr/test/drivers/pwm_led_driver/prj.conf new file mode 100644 index 0000000000..9556721725 --- /dev/null +++ b/zephyr/test/drivers/pwm_led_driver/prj.conf @@ -0,0 +1,6 @@ +# Copyright 2022 The ChromiumOS Authors. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +CONFIG_PLATFORM_EC_LED_DT=y +CONFIG_PWM_MOCK=y diff --git a/zephyr/test/drivers/pwm_led_driver/src/led.c b/zephyr/test/drivers/pwm_led_driver/src/led.c new file mode 100644 index 0000000000..95a183cebe --- /dev/null +++ b/zephyr/test/drivers/pwm_led_driver/src/led.c @@ -0,0 +1,91 @@ +/* Copyright 2022 The ChromiumOS Authors. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/ztest.h> +#include <zephyr/ztest_assert.h> + +#include <zephyr/device.h> +#include <zephyr/drivers/pwm.h> + +#include "ec_commands.h" +#include "led.h" +#include "led_common.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +ZTEST_SUITE(pwm_led_driver, drivers_predicate_post_main, NULL, NULL, NULL, + NULL); + +ZTEST(pwm_led_driver, test_led_set_brightness) +{ + const uint8_t brightness_off[EC_LED_COLOR_COUNT] = {}; + const uint8_t brightness_white[EC_LED_COLOR_COUNT] = { + [EC_LED_COLOR_WHITE] = 1 + }; + const uint8_t brightness_amber[EC_LED_COLOR_COUNT] = { + [EC_LED_COLOR_AMBER] = 1 + }; + const struct device *pwm_blue_left = + DEVICE_DT_GET(DT_NODELABEL(pwm_blue_left)); + const struct device *pwm_white_left = + DEVICE_DT_GET(DT_NODELABEL(pwm_white_left)); + const struct device *pwm_amber_right = + DEVICE_DT_GET(DT_NODELABEL(pwm_amber_right)); + const struct device *pwm_white_right = + DEVICE_DT_GET(DT_NODELABEL(pwm_white_right)); + + /* Turn off all LEDs */ + led_set_brightness(EC_LED_ID_LEFT_LED, brightness_off); + led_set_brightness(EC_LED_ID_RIGHT_LED, brightness_off); + zassert_equal(pwm_mock_get_duty(pwm_blue_left, 0), 0, NULL); + zassert_equal(pwm_mock_get_duty(pwm_white_left, 0), 0, NULL); + zassert_equal(pwm_mock_get_duty(pwm_amber_right, 0), 0, NULL); + zassert_equal(pwm_mock_get_duty(pwm_white_right, 0), 0, NULL); + + /* Call led_set_color(LED_WHITE, LEFT_LED) */ + led_set_brightness(EC_LED_ID_LEFT_LED, brightness_white); + zassert_equal(pwm_mock_get_duty(pwm_blue_left, 0), 0, NULL); + zassert_equal(pwm_mock_get_duty(pwm_white_left, 0), 100, NULL); + zassert_equal(pwm_mock_get_duty(pwm_amber_right, 0), 0, NULL); + zassert_equal(pwm_mock_get_duty(pwm_white_right, 0), 0, NULL); + + /* Unsupporte, call led_set_color(LED_OFF, LEFT_LED) */ + led_set_brightness(EC_LED_ID_LEFT_LED, brightness_amber); + zassert_equal(pwm_mock_get_duty(pwm_blue_left, 0), 0, NULL); + zassert_equal(pwm_mock_get_duty(pwm_white_left, 0), 0, NULL); + zassert_equal(pwm_mock_get_duty(pwm_amber_right, 0), 0, NULL); + zassert_equal(pwm_mock_get_duty(pwm_white_right, 0), 0, NULL); + + /* Call led_set_color(AMBER, RIGHT_LED) */ + led_set_brightness(EC_LED_ID_RIGHT_LED, brightness_amber); + zassert_equal(pwm_mock_get_duty(pwm_blue_left, 0), 0, NULL); + zassert_equal(pwm_mock_get_duty(pwm_white_left, 0), 0, NULL); + zassert_equal(pwm_mock_get_duty(pwm_amber_right, 0), 100, NULL); + zassert_equal(pwm_mock_get_duty(pwm_white_right, 0), 0, NULL); +} + +ZTEST(pwm_led_driver, test_led_get_brightness) +{ + uint8_t brightness[EC_LED_COLOR_COUNT]; + const uint8_t expected_left[EC_LED_COLOR_COUNT] = { + [EC_LED_COLOR_BLUE] = 100, + [EC_LED_COLOR_WHITE] = 100, + }; + const uint8_t expected_right[EC_LED_COLOR_COUNT] = { + [EC_LED_COLOR_WHITE] = 100, + [EC_LED_COLOR_AMBER] = 100, + }; + + /* Verify LED colors defined in device tree are reflected in the + * brightness array. + */ + memset(brightness, 255, sizeof(brightness)); + led_get_brightness_range(EC_LED_ID_LEFT_LED, brightness); + zassert_mem_equal(brightness, expected_left, sizeof(brightness), NULL); + + memset(brightness, 255, sizeof(brightness)); + led_get_brightness_range(EC_LED_ID_RIGHT_LED, brightness); + zassert_mem_equal(brightness, expected_right, sizeof(brightness), NULL); +} diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index 941d60a12b..c365b564cd 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -20,6 +20,10 @@ tests: extra_args: CONF_FILE="prj.conf;led_driver/prj.conf" DTC_OVERLAY_FILE="./boards/native_posix.overlay;./led_driver/led_pins.dts;./led_driver/led_policy.dts" extra_configs: - CONFIG_LINK_TEST_SUITE_LED_DRIVER=y + drivers.pwm_led_driver: + extra_args: CONF_FILE="prj.conf;pwm_led_driver/prj.conf" DTC_OVERLAY_FILE="./boards/native_posix.overlay;./pwm_led_driver/led_pins.dts" + extra_configs: + - CONFIG_LINK_TEST_SUITE_PWM_LED_DRIVER=y drivers.usbc_alt_mode: extra_configs: - - CONFIG_LINK_TEST_SUITE_USBC_ALT_MODE=y
\ No newline at end of file + - CONFIG_LINK_TEST_SUITE_USBC_ALT_MODE=y |