1 /*
2  * Copyright (c) 2024 TOKITA Hiroshi
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/drivers/display.h>
8 #include <zephyr/ztest.h>
9 #include <zephyr/device.h>
10 #include <zephyr/logging/log.h>
11 #include <zephyr/display/cfb.h>
12 
13 #include "testdata.h"
14 #include "utils.h"
15 
16 LOG_MODULE_REGISTER(invert, CONFIG_DISPLAY_LOG_LEVEL);
17 
18 static const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
19 static const uint32_t display_width = DT_PROP(DT_CHOSEN(zephyr_display), width);
20 static const uint32_t display_height = DT_PROP(DT_CHOSEN(zephyr_display), height);
21 
22 /**
23  * Fill the buffer with 0 before running tests.
24  */
cfb_test_before(void * text_fixture)25 static void cfb_test_before(void *text_fixture)
26 {
27 	struct display_buffer_descriptor desc = {
28 		.height = display_height,
29 		.pitch = display_width,
30 		.width = display_width,
31 		.buf_size = display_height * display_width / 8,
32 	};
33 
34 	memset(read_buffer, 0, sizeof(read_buffer));
35 	zassert_ok(display_write(dev, 0, 0, &desc, read_buffer));
36 
37 	zassert_ok(display_blanking_off(dev));
38 
39 	zassert_ok(cfb_framebuffer_init(dev));
40 }
41 
cfb_test_after(void * test_fixture)42 static void cfb_test_after(void *test_fixture)
43 {
44 	cfb_framebuffer_deinit(dev);
45 }
46 
ZTEST(invert,test_invert)47 ZTEST(invert, test_invert)
48 {
49 	zassert_ok(cfb_framebuffer_invert(dev));
50 	zassert_ok(cfb_framebuffer_finalize(dev));
51 
52 	zassert_true(verify_color_inside_rect(0, 0, 320, 240, 0xFFFFFF));
53 }
54 
ZTEST(invert,test_invert_contents)55 ZTEST(invert, test_invert_contents)
56 {
57 	zassert_ok(cfb_invert_area(dev, 10, 10, 10, 10));
58 	zassert_ok(cfb_framebuffer_finalize(dev));
59 	zassert_true(verify_color_outside_rect(10, 10, 10, 10, 0));
60 	zassert_true(verify_color_inside_rect(10, 10, 10, 10, 0xFFFFFF));
61 
62 	zassert_ok(cfb_framebuffer_invert(dev));
63 	zassert_ok(cfb_framebuffer_finalize(dev));
64 
65 	zassert_true(verify_color_outside_rect(10, 10, 10, 10, 0xFFFFFF));
66 }
67 
68 ZTEST_SUITE(invert, NULL, NULL, cfb_test_before, cfb_test_after, NULL);
69