From dbf15673583860a734eb7373a0c1de414781cd49 Mon Sep 17 00:00:00 2001 From: Tristan Honscheid Date: Mon, 3 Oct 2022 19:10:10 -0600 Subject: zephyr: tests: Test motion_lid.c host command Test the motion_lid.c subcommands of the motion_sense host command. BRANCH=None BUG=b:250726941 TEST=./twister Signed-off-by: Tristan Honscheid Change-Id: Ifb496e7e7d1bf91d320b6dce04a4e90c13975954 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3934412 Code-Coverage: Zoss Reviewed-by: Simon Glass --- common/motion_lid.c | 7 +++ .../drivers/common/include/test/drivers/utils.h | 30 +++++++++++++ zephyr/test/drivers/common/src/utils.c | 42 +++++++++++++++++ zephyr/test/drivers/host_cmd/src/motion_sense.c | 52 ++++++++++++++++++++++ zephyr/test/drivers/testcase.yaml | 1 + 5 files changed, 132 insertions(+) diff --git a/common/motion_lid.c b/common/motion_lid.c index 1a254e786d..d8445bb3d4 100644 --- a/common/motion_lid.c +++ b/common/motion_lid.c @@ -499,6 +499,13 @@ void motion_lid_calc(void) /*****************************************************************************/ /* Host commands */ +/** + * @brief This is a "sub"-host command accessed through EC_CMD_MOTION_SENSE_CMD, + * defined in `common/motion_sense.c` + * + * @param args Hot command args + * @return enum ec_status Exit status + */ enum ec_status host_cmd_motion_lid(struct host_cmd_handler_args *args) { const struct ec_params_motion_sense *in = args->params; diff --git a/zephyr/test/drivers/common/include/test/drivers/utils.h b/zephyr/test/drivers/common/include/test/drivers/utils.h index 1b69ac23bd..0acefdbccf 100644 --- a/zephyr/test/drivers/common/include/test/drivers/utils.h +++ b/zephyr/test/drivers/common/include/test/drivers/utils.h @@ -431,6 +431,36 @@ int host_cmd_motion_sense_spoof(uint8_t sensor_num, uint8_t enable, int16_t values2, struct ec_response_motion_sense *response); +/** + * @brief Call the keyboard wake angle motion_sense subcommand + * + * @param data Angle to set + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_kb_wake_angle( + int16_t data, struct ec_response_motion_sense *response); + +/** + * @brief Call the lid angle motion_sense subcommand + * + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_lid_angle(struct ec_response_motion_sense *response); + +/** + * @brief Call the tablet mode lid angle threshold motion_sense subcommand + * + * @param lid_angle Lid angle for transitioning to tablet mode + * @param hys_degree Hysteresis or above transition + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_tablet_mode_lid_angle( + int16_t lid_angle, int16_t hys_degree, + struct ec_response_motion_sense *response); + /** * Run the host command to get the PD discovery responses. * diff --git a/zephyr/test/drivers/common/src/utils.c b/zephyr/test/drivers/common/src/utils.c index f663cd6ae3..1d1ae735da 100644 --- a/zephyr/test/drivers/common/src/utils.c +++ b/zephyr/test/drivers/common/src/utils.c @@ -467,6 +467,48 @@ int host_cmd_motion_sense_spoof(uint8_t sensor_num, uint8_t enable, return host_command_process(&args); } +int host_cmd_motion_sense_kb_wake_angle( + int16_t data, struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_KB_WAKE_ANGLE, + .kb_wake_angle = { + .data = data, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_lid_angle(struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_LID_ANGLE, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_tablet_mode_lid_angle( + int16_t lid_angle, int16_t hys_degree, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense + params = { .cmd = MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE, + .tablet_mode_threshold = { + .lid_angle = lid_angle, + .hys_degree = hys_degree, + } }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + void host_cmd_typec_discovery(int port, enum typec_partner_type partner_type, void *response, size_t response_size) { diff --git a/zephyr/test/drivers/host_cmd/src/motion_sense.c b/zephyr/test/drivers/host_cmd/src/motion_sense.c index c75f327fed..2d20a2db96 100644 --- a/zephyr/test/drivers/host_cmd/src/motion_sense.c +++ b/zephyr/test/drivers/host_cmd/src/motion_sense.c @@ -10,6 +10,8 @@ #include "atomic.h" #include "console.h" #include "driver/accel_bma2x2.h" +#include "lid_angle.h" +#include "motion_lid.h" #include "motion_sense.h" #include "motion_sense_fifo.h" #include "test/drivers/test_state.h" @@ -75,6 +77,9 @@ static void host_cmd_motion_sense_before(void *fixture) atomic_clear(&motion_sensors[0].flush_pending); motion_sensors[0].config[SENSOR_CONFIG_AP].odr = 0; motion_sensors[0].config[SENSOR_CONFIG_AP].ec_rate = 1000 * MSEC; + + /* Reset the lid wake angle to 0 degrees. */ + lid_angle_set_wake_angle(0); } static void host_cmd_motion_sense_after(void *fixture) @@ -866,3 +871,50 @@ ZTEST(host_cmd_motion_sense, test_spoof_invalid_mode) host_cmd_motion_sense_spoof(0, 0xff, 0, 0, 0, &response), NULL); } + +ZTEST(host_cmd_motion_sense, set_kb_wake_lid_angle) +{ + struct ec_response_motion_sense response; + int16_t expected_lid_angle = 45; + int rv; + + rv = host_cmd_motion_sense_kb_wake_angle(expected_lid_angle, &response); + + zassert_ok(rv, "Got %d", rv); + zassert_equal(expected_lid_angle, lid_angle_get_wake_angle()); + zassert_equal(expected_lid_angle, response.kb_wake_angle.ret); +} + +ZTEST(host_cmd_motion_sense, get_lid_angle) +{ + struct ec_response_motion_sense response; + int rv; + + rv = host_cmd_motion_sense_lid_angle(&response); + + zassert_ok(rv, "Got %d", rv); + zassert_equal(motion_lid_get_angle(), response.lid_angle.value); +} + +ZTEST(host_cmd_motion_sense, test_tablet_mode_lid_angle) +{ + struct ec_response_motion_sense response; + int16_t expected_angle = 45; + int16_t expected_hys = 3; + int rv; + + rv = host_cmd_motion_sense_tablet_mode_lid_angle( + expected_angle, expected_hys, &response); + + zassert_ok(rv, "Got %d", rv); + zassert_equal(expected_angle, response.tablet_mode_threshold.lid_angle); + zassert_equal(expected_hys, response.tablet_mode_threshold.hys_degree); +} + +ZTEST(host_cmd_motion_sense, test_tablet_mode_lid_angle__invalid) +{ + struct ec_response_motion_sense response; + + zassert_ok(!host_cmd_motion_sense_tablet_mode_lid_angle(-100, -100, + &response)); +} diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index b3470bf8bd..66e998b69b 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -29,6 +29,7 @@ tests: - CONFIG_LINK_TEST_SUITE_HOST_COMMANDS=y - CONFIG_PLATFORM_EC_BATTERY_CUT_OFF=y - CONFIG_PLATFORM_EC_USB_PD_LOGGING=y + - CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=y drivers.locate_chip: extra_configs: - CONFIG_LINK_TEST_SUITE_LOCATE_CHIP_ALTS=y -- cgit v1.2.1