1 /*
2  * Copyright (c) 2021 Hubert Miś <hubert.mis@gmail.com>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 
9 #include <zephyr/drivers/misc/ft8xx/ft8xx.h>
10 #include <zephyr/drivers/misc/ft8xx/ft8xx_copro.h>
11 #include <zephyr/drivers/misc/ft8xx/ft8xx_dl.h>
12 
13 /**
14  * @file Display a counter using FT800.
15  */
16 
17 /* sleep time in msec */
18 #define SLEEPTIME  100
19 
20 /* touch tags */
21 #define TAG_PLUS 1
22 #define TAG_MINUS 2
23 
24 static volatile bool process_touch;
25 
touch_irq(void)26 static void touch_irq(void)
27 {
28 	process_touch = true;
29 }
30 
main(void)31 int main(void)
32 {
33 	int cnt;
34 	int val;
35 	struct ft8xx_touch_transform tt;
36 
37 	/* To get touch events calibrate the display */
38 	ft8xx_calibrate(&tt);
39 
40 	/* Get interrupts on touch event */
41 	ft8xx_register_int(touch_irq);
42 
43 	/* Starting counting */
44 	val = 0;
45 	cnt = 0;
46 
47 	while (1) {
48 		/* Start Display List */
49 		ft8xx_copro_cmd_dlstart();
50 		ft8xx_copro_cmd(FT8XX_CLEAR_COLOR_RGB(0x00, 0x00, 0x00));
51 		ft8xx_copro_cmd(FT8XX_CLEAR(1, 1, 1));
52 
53 		/* Set color */
54 		ft8xx_copro_cmd(FT8XX_COLOR_RGB(0xf0, 0xf0, 0xf0));
55 
56 		/* Display the counter */
57 		ft8xx_copro_cmd_number(20, 20, 29, FT8XX_OPT_SIGNED, cnt);
58 		cnt++;
59 
60 		/* Display the hello message */
61 		ft8xx_copro_cmd_text(20, 70, 30, 0, "Hello,");
62 		/* Set Zephyr color */
63 		ft8xx_copro_cmd(FT8XX_COLOR_RGB(0x78, 0x29, 0xd2));
64 		ft8xx_copro_cmd_text(20, 105, 30, 0, "Zephyr!");
65 
66 		/* Display value set with buttons */
67 		ft8xx_copro_cmd(FT8XX_COLOR_RGB(0xff, 0xff, 0xff));
68 		ft8xx_copro_cmd_number(80, 170, 29,
69 					FT8XX_OPT_SIGNED | FT8XX_OPT_RIGHTX,
70 					val);
71 		ft8xx_copro_cmd(FT8XX_TAG(TAG_PLUS));
72 		ft8xx_copro_cmd_text(90, 160, 31, 0, "+");
73 		ft8xx_copro_cmd(FT8XX_TAG(TAG_MINUS));
74 		ft8xx_copro_cmd_text(20, 160, 31, 0, "-");
75 
76 		/* Finish Display List */
77 		ft8xx_copro_cmd(FT8XX_DISPLAY());
78 		/* Display created frame */
79 		ft8xx_copro_cmd_swap();
80 
81 		if (process_touch) {
82 			int tag = ft8xx_get_touch_tag();
83 
84 			if (tag == TAG_PLUS) {
85 				val++;
86 			} else if (tag == TAG_MINUS) {
87 				val--;
88 			}
89 
90 			process_touch = false;
91 		}
92 
93 		/* Wait a while */
94 		k_msleep(SLEEPTIME);
95 	}
96 	return 0;
97 }
98