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