1 /*
2  * Copyright (c) 2017 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/sys/printk.h>
9 #include <zephyr/device.h>
10 
11 #include <zephyr/display/mb_display.h>
12 
13 static struct mb_image smiley = MB_IMAGE({ 0, 1, 0, 1, 0 },
14 					 { 0, 1, 0, 1, 0 },
15 					 { 0, 0, 0, 0, 0 },
16 					 { 1, 0, 0, 0, 1 },
17 					 { 0, 1, 1, 1, 0 });
18 
19 static const struct mb_image scroll[] = {
20 	MB_IMAGE({ 1, 0, 0, 0, 0 },
21 		 { 1, 0, 0, 0, 1 },
22 		 { 1, 0, 0, 1, 0 },
23 		 { 1, 0, 1, 0, 0 },
24 		 { 1, 1, 0, 0, 0 }),
25 	MB_IMAGE({ 1, 0, 0, 0, 0 },
26 		 { 0, 1, 0, 0, 0 },
27 		 { 0, 0, 1, 0, 0 },
28 		 { 0, 0, 0, 1, 0 },
29 		 { 0, 0, 0, 0, 1 }),
30 	MB_IMAGE({ 0, 0, 0, 0, 1 },
31 		 { 0, 0, 1, 0, 1 },
32 		 { 0, 1, 0, 1, 1 },
33 		 { 1, 0, 0, 0, 1 },
34 		 { 0, 0, 0, 0, 1 }),
35 };
36 
37 static const struct mb_image animation[] = {
38 	MB_IMAGE({ 0, 0, 0, 0, 0 },
39 		 { 0, 0, 0, 0, 0 },
40 		 { 0, 0, 1, 0, 0 },
41 		 { 0, 0, 0, 0, 0 },
42 		 { 0, 0, 0, 0, 0 }),
43 	MB_IMAGE({ 0, 0, 0, 0, 0 },
44 		 { 0, 1, 1, 1, 0 },
45 		 { 0, 1, 1, 1, 0 },
46 		 { 0, 1, 1, 1, 0 },
47 		 { 0, 0, 0, 0, 0 }),
48 	MB_IMAGE({ 1, 1, 1, 1, 1 },
49 		 { 1, 1, 1, 1, 1 },
50 		 { 1, 1, 0, 1, 1 },
51 		 { 1, 1, 1, 1, 1 },
52 		 { 1, 1, 1, 1, 1 }),
53 	MB_IMAGE({ 1, 1, 1, 1, 1 },
54 		 { 1, 0, 0, 0, 1 },
55 		 { 1, 0, 0, 0, 1 },
56 		 { 1, 0, 0, 0, 1 },
57 		 { 1, 1, 1, 1, 1 }),
58 };
59 
main(void)60 int main(void)
61 {
62 	struct mb_display *disp = mb_display_get();
63 	int x, y;
64 
65 	/* Note: the k_sleep() calls after mb_display_print() and
66 	 * mb_display_image() are not normally needed since the APIs
67 	 * are used in an asynchronous manner. The k_sleep() calls
68 	 * are used here so the APIs can be sequentially demonstrated
69 	 * through this single main function.
70 	 */
71 
72 	/* Display countdown from '9' to '0' */
73 	mb_display_print(disp, MB_DISPLAY_MODE_SINGLE,
74 			 1 * MSEC_PER_SEC, "9876543210");
75 	k_sleep(K_SECONDS(11));
76 
77 	/* Iterate through all pixels one-by-one */
78 	for (y = 0; y < 5; y++) {
79 		for (x = 0; x < 5; x++) {
80 			struct mb_image pixel = {};
81 			pixel.row[y] = BIT(x);
82 			mb_display_image(disp, MB_DISPLAY_MODE_SINGLE, 250,
83 					 &pixel, 1);
84 			k_sleep(K_MSEC(300));
85 		}
86 	}
87 
88 	/* Show a smiley-face */
89 	mb_display_image(disp, MB_DISPLAY_MODE_SINGLE, 2 * MSEC_PER_SEC,
90 			 &smiley, 1);
91 	k_sleep(K_SECONDS(2));
92 
93 	/* Show a short scrolling animation */
94 	mb_display_image(disp, MB_DISPLAY_MODE_SCROLL, 1 * MSEC_PER_SEC,
95 			 scroll, ARRAY_SIZE(scroll));
96 	k_sleep(K_SECONDS((ARRAY_SIZE(scroll) + 2)));
97 
98 	/* Show a sequential animation */
99 	mb_display_image(disp, MB_DISPLAY_MODE_DEFAULT | MB_DISPLAY_FLAG_LOOP,
100 			 150, animation, ARRAY_SIZE(animation));
101 	k_sleep(K_MSEC(150 * ARRAY_SIZE(animation) * 5));
102 
103 	/* Show some scrolling text ("Hello Zephyr!") */
104 	mb_display_print(disp, MB_DISPLAY_MODE_DEFAULT | MB_DISPLAY_FLAG_LOOP,
105 			 500, "Hello Zephyr!");
106 	return 0;
107 }
108