1 /*
2  * Copyright 2022, NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/drivers/mipi_dsi.h>
8 #include <zephyr/ztest.h>
9 
10 /**
11  * @addtogroup t_mipi_dsi_driver
12  * @{
13  * @defgroup t_mipi_dsi_api test_mipi_dsi_api
14  * @}
15  */
16 
17 static const struct device *const mipi_dev = DEVICE_DT_GET(DT_ALIAS(mipi_dsi));
18 
19 /**
20  * Test the MIPI generic APIs to test read and write API functionality
21  */
ZTEST(mipi_dsi_api,test_generic)22 ZTEST(mipi_dsi_api, test_generic)
23 {
24 	uint8_t rx_buf[2];
25 	uint8_t param[2];
26 	ssize_t ret;
27 
28 	param[0] = MIPI_DCS_SET_DISPLAY_ON;
29 	ret = mipi_dsi_generic_write(mipi_dev, CONFIG_MIPI_DSI_TEST_CHANNEL, param, 1);
30 	zassert(ret >= 0, "Failed to write", NULL);
31 
32 	param[0] = MIPI_DCS_SET_DISPLAY_BRIGHTNESS;
33 	param[1] = 200;
34 	ret = mipi_dsi_generic_write(mipi_dev, CONFIG_MIPI_DSI_TEST_CHANNEL, param, 2);
35 	zassert(ret >= 0, "Failed to write", NULL);
36 
37 	memset(rx_buf, 0, sizeof(rx_buf));
38 
39 	param[0] = MIPI_DCS_GET_DISPLAY_BRIGHTNESS;
40 	ret = mipi_dsi_generic_read(mipi_dev, CONFIG_MIPI_DSI_TEST_CHANNEL, param, 1, rx_buf, 2);
41 
42 	if (ret != -ENOTSUP) {
43 		zassert(ret >= 0, "Failed to do a generic read", NULL);
44 	}
45 
46 }
47 
48 /**
49  * Test the MIPI DCS APIs to test read and write API functionality
50  */
ZTEST(mipi_dsi_api,test_dcs)51 ZTEST(mipi_dsi_api, test_dcs)
52 {
53 	uint8_t rx_buf[2];
54 	uint8_t param[2];
55 	ssize_t ret;
56 
57 	ret = mipi_dsi_dcs_write(mipi_dev, CONFIG_MIPI_DSI_TEST_CHANNEL,
58 				 MIPI_DCS_SET_DISPLAY_ON, NULL, 0);
59 	zassert(ret >= 0, "Failed to write", NULL);
60 
61 	param[0] = 200;
62 	ret = mipi_dsi_dcs_write(mipi_dev, CONFIG_MIPI_DSI_TEST_CHANNEL,
63 				 MIPI_DCS_SET_DISPLAY_BRIGHTNESS, param, 1);
64 	zassert(ret >= 0, "Failed to write", NULL);
65 
66 	memset(rx_buf, 0, sizeof(rx_buf));
67 
68 	param[0] = MIPI_DCS_GET_DISPLAY_BRIGHTNESS;
69 	ret = mipi_dsi_dcs_read(mipi_dev, CONFIG_MIPI_DSI_TEST_CHANNEL,
70 				MIPI_DCS_GET_DISPLAY_BRIGHTNESS, rx_buf, 2);
71 
72 	if (ret != -ENOTSUP) {
73 		zassert(ret >= 0, "Failed to do a dcs read", NULL);
74 	}
75 }
76 
mipi_dsi_setup(void)77 static void *mipi_dsi_setup(void)
78 {
79 	__ASSERT_NO_MSG(device_is_ready(mipi_dev));
80 
81 	return NULL;
82 }
83 
84 ZTEST_SUITE(mipi_dsi_api, NULL, mipi_dsi_setup, NULL, NULL, NULL);
85