diff options
-rw-r--r-- | include/pwm.h | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c | 47 |
2 files changed, 49 insertions, 0 deletions
diff --git a/include/pwm.h b/include/pwm.h index 03e424ee05..48963d9d3c 100644 --- a/include/pwm.h +++ b/include/pwm.h @@ -8,6 +8,8 @@ #include <inttypes.h> +#include "util.h" + #define PWM_RAW_TO_PERCENT(v) DIV_ROUND_NEAREST((uint32_t)(v)*100, UINT16_MAX) #define PWM_PERCENT_TO_RAW(v) ((uint32_t)(v)*UINT16_MAX / 100) diff --git a/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c b/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c index 5fc7344b75..847326c0ba 100644 --- a/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c +++ b/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c @@ -16,6 +16,53 @@ #include "pwm.h" #include "test/drivers/test_state.h" +ZTEST(shim_pwm_hc, test_pwm_set_duty_hc__kblight) +{ + struct ec_params_pwm_set_duty p = { + .index = DT_REG_ADDR(DT_NODELABEL(pwm_kblight)), + .pwm_type = EC_PWM_TYPE_KB_LIGHT, + /* Arbitrary 56% */ + .duty = PWM_PERCENT_TO_RAW(56), + }; + + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_PWM_SET_DUTY, 0, p); + + zassert_ok(host_command_process(&args)); + zassert_equal(kblight_get(), PWM_RAW_TO_PERCENT(p.duty)); +} + +ZTEST(shim_pwm_hc, test_pwm_set_duty_hc__displight) +{ + struct ec_params_pwm_set_duty p = { + p.index = DT_REG_ADDR(DT_NODELABEL(pwm_displight)), + p.pwm_type = EC_PWM_TYPE_DISPLAY_LIGHT, + /* Arbitrary 72% */ + .duty = PWM_PERCENT_TO_RAW(72) + }; + + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_PWM_SET_DUTY, 0, p); + + zassert_ok(host_command_process(&args)); + zassert_equal(displight_get(), PWM_RAW_TO_PERCENT(p.duty)); +} + +ZTEST(shim_pwm_hc, test_pwm_set_duty_hc__bad_pwm_type) +{ + struct ec_params_pwm_set_duty p = { + /* Arbitrary, don't care */ + p.index = 0, + /* PWM Type doesn't actually exist */ + p.pwm_type = EC_PWM_TYPE_COUNT, + }; + + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_PWM_SET_DUTY, 0, p); + + zassert_equal(EC_RES_INVALID_PARAM, host_command_process(&args)); +} + ZTEST(shim_pwm_hc, test_pwm_get_duty_hc__kblight) { struct ec_params_pwm_get_duty p = { |