1 /*
2  * Copyright (c) 2018 PHYTEC Messtechnik GmbH
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/display/cfb.h>
10 #include <stdio.h>
11 
main(void)12 int main(void)
13 {
14 	const struct device *dev;
15 	uint16_t x_res;
16 	uint16_t y_res;
17 	uint16_t rows;
18 	uint8_t ppt;
19 	uint8_t font_width;
20 	uint8_t font_height;
21 
22 	dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
23 	if (!device_is_ready(dev)) {
24 		printf("Device %s not ready\n", dev->name);
25 		return 0;
26 	}
27 
28 	if (display_set_pixel_format(dev, PIXEL_FORMAT_MONO10) != 0) {
29 		if (display_set_pixel_format(dev, PIXEL_FORMAT_MONO01) != 0) {
30 			printf("Failed to set required pixel format");
31 			return 0;
32 		}
33 	}
34 
35 	printf("Initialized %s\n", dev->name);
36 
37 	if (cfb_framebuffer_init(dev)) {
38 		printf("Framebuffer initialization failed!\n");
39 		return 0;
40 	}
41 
42 	cfb_framebuffer_clear(dev, true);
43 
44 	display_blanking_off(dev);
45 
46 	x_res = cfb_get_display_parameter(dev, CFB_DISPLAY_WIDTH);
47 	y_res = cfb_get_display_parameter(dev, CFB_DISPLAY_HEIGH);
48 	rows = cfb_get_display_parameter(dev, CFB_DISPLAY_ROWS);
49 	ppt = cfb_get_display_parameter(dev, CFB_DISPLAY_PPT);
50 
51 	for (int idx = 0; idx < 42; idx++) {
52 		if (cfb_get_font_size(dev, idx, &font_width, &font_height)) {
53 			break;
54 		}
55 		cfb_framebuffer_set_font(dev, idx);
56 		printf("font width %d, font height %d\n",
57 		       font_width, font_height);
58 	}
59 
60 	printf("x_res %d, y_res %d, ppt %d, rows %d, cols %d\n",
61 	       x_res,
62 	       y_res,
63 	       ppt,
64 	       rows,
65 	       cfb_get_display_parameter(dev, CFB_DISPLAY_COLS));
66 
67 	cfb_framebuffer_invert(dev);
68 
69 	cfb_set_kerning(dev, 3);
70 
71 	while (1) {
72 		for (int i = 0; i < MIN(x_res, y_res); i++) {
73 			cfb_framebuffer_clear(dev, false);
74 			if (cfb_print(dev,
75 				      "0123456789mMgj!\"§$%&/()=",
76 				      i, i)) {
77 				printf("Failed to print a string\n");
78 				continue;
79 			}
80 
81 			cfb_framebuffer_finalize(dev);
82 #if defined(CONFIG_ARCH_POSIX)
83 			k_sleep(K_MSEC(20));
84 #endif
85 		}
86 	}
87 	return 0;
88 }
89