1 /*
2  * Copyright (c) 2020 Hubert Miś
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief FT8XX coprocessor functions
10  */
11 
12 #ifndef ZEPHYR_DRIVERS_MISC_FT8XX_FT8XX_COPRO_H_
13 #define ZEPHYR_DRIVERS_MISC_FT8XX_FT8XX_COPRO_H_
14 
15 #include <stdint.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /**
22  * @brief FT8xx co-processor engine functions
23  * @defgroup ft8xx_copro FT8xx co-processor
24  * @ingroup ft8xx_interface
25  * @{
26  */
27 
28 /** Co-processor widget is drawn in 3D effect */
29 #define FT8XX_OPT_3D        0
30 /** Co-processor option to decode the JPEG image to RGB565 format */
31 #define FT8XX_OPT_RGB565    0
32 /** Co-processor option to decode the JPEG image to L8 format, i.e., monochrome */
33 #define FT8XX_OPT_MONO      1
34 /** No display list commands generated for bitmap decoded from JPEG image */
35 #define FT8XX_OPT_NODL      2
36 /** Co-processor widget is drawn without 3D effect */
37 #define FT8XX_OPT_FLAT      256
38 /** The number is treated as 32 bit signed integer */
39 #define FT8XX_OPT_SIGNED    256
40 /** Co-processor widget centers horizontally */
41 #define FT8XX_OPT_CENTERX   512
42 /** Co-processor widget centers vertically */
43 #define FT8XX_OPT_CENTERY   1024
44 /** Co-processor widget centers horizontally and vertically */
45 #define FT8XX_OPT_CENTER    1536
46 /** The label on the Coprocessor widget is right justified */
47 #define FT8XX_OPT_RIGHTX    2048
48 /** Co-processor widget has no background drawn */
49 #define FT8XX_OPT_NOBACK    4096
50 /** Co-processor clock widget is drawn without hour ticks.
51  *  Gauge widget is drawn without major and minor ticks.
52  */
53 #define FT8XX_OPT_NOTICKS   8192
54 /** Co-processor clock widget is drawn without hour and minutes hands,
55  * only seconds hand is drawn
56  */
57 #define FT8XX_OPT_NOHM      16384
58 /** The Co-processor gauge has no pointer */
59 #define FT8XX_OPT_NOPOINTER 16384
60 /** Co-processor clock widget is drawn without seconds hand */
61 #define FT8XX_OPT_NOSECS    32768
62 /** Co-processor clock widget is drawn without hour, minutes and seconds hands */
63 #define FT8XX_OPT_NOHANDS   49152
64 
65 /**
66  * @brief Execute a display list command by co-processor engine
67  *
68  * @param cmd Display list command to execute
69  */
70 void ft8xx_copro_cmd(uint32_t cmd);
71 
72 /**
73  * @brief Start a new display list
74  */
75 void ft8xx_copro_cmd_dlstart(void);
76 
77 /**
78  * @brief Swap the current display list
79  */
80 void ft8xx_copro_cmd_swap(void);
81 
82 /**
83  * @brief Draw text
84  *
85  * By default (@p x, @p y) is the top-left pixel of the text and the value of
86  * @p options is zero. @ref FT8XX_OPT_CENTERX centers the text horizontally,
87  * @ref FT8XX_OPT_CENTERY centers it vertically. @ref FT8XX_OPT_CENTER centers
88  * the text in both directions. @ref FT8XX_OPT_RIGHTX right-justifies the text,
89  * so that the @p x is the rightmost pixel.
90  *
91  * @param x x-coordinate of text base, in pixels
92  * @param y y-coordinate of text base, in pixels
93  * @param font Font to use for text, 0-31. 16-31 are ROM fonts
94  * @param options Options to apply
95  * @param s Character string to display, terminated with a null character
96  */
97 void ft8xx_copro_cmd_text(int16_t x,
98 			   int16_t y,
99 			   int16_t font,
100 			   uint16_t options,
101 			   const char *s);
102 
103 /**
104  * @brief Draw a decimal number
105  *
106  * By default (@p x, @p y) is the top-left pixel of the text.
107  * @ref FT8XX_OPT_CENTERX centers the text horizontally, @ref FT8XX_OPT_CENTERY
108  * centers it vertically. @ref FT8XX_OPT_CENTER centers the text in both
109  * directions. @ref FT8XX_OPT_RIGHTX right-justifies the text, so that the @p x
110  * is the rightmost pixel. By default the number is displayed with no leading
111  * zeroes, but if a width 1-9 is specified in the @p options, then the number
112  * is padded if necessary with leading zeroes so that it has the given width.
113  * If @ref FT8XX_OPT_SIGNED is given, the number is treated as signed, and
114  * prefixed by a minus sign if negative.
115  *
116  * @param x x-coordinate of text base, in pixels
117  * @param y y-coordinate of text base, in pixels
118  * @param font Font to use for text, 0-31. 16-31 are ROM fonts
119  * @param options Options to apply
120  * @param n The number to display.
121  */
122 void ft8xx_copro_cmd_number(int16_t x,
123 			     int16_t y,
124 			     int16_t font,
125 			     uint16_t options,
126 			     int32_t n);
127 
128 /**
129  * @brief Execute the touch screen calibration routine
130  *
131  * The calibration procedure collects three touches from the touch screen, then
132  * computes and loads an appropriate matrix into REG_TOUCH_TRANSFORM_A-F. To
133  * use it, create a display list and then use CMD_CALIBRATE. The co-processor
134  * engine overlays the touch targets on the current display list, gathers the
135  * calibration input and updates REG_TOUCH_TRANSFORM_A-F.
136  *
137  * @param result Calibration result, written with 0 on failure of calibration
138  */
139 void ft8xx_copro_cmd_calibrate(uint32_t *result);
140 
141 /**
142  * @}
143  */
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif /* ZEPHYR_DRIVERS_MISC_FT8XX_FT8XX_COPRO_H_ */
150