Line data Source code
1 1 : /*
2 : * Copyright (c) 2020 Hubert Miś
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @brief FT8XX display list commands
10 : */
11 :
12 : #ifndef ZEPHYR_DRIVERS_MISC_FT8XX_FT8XX_DL_H_
13 : #define ZEPHYR_DRIVERS_MISC_FT8XX_FT8XX_DL_H_
14 :
15 : #include <stdint.h>
16 :
17 : #ifdef __cplusplus
18 : extern "C" {
19 : #endif
20 :
21 : /**
22 : * @brief FT8xx display list commands
23 : * @defgroup ft8xx_dl FT8xx display list
24 : * @ingroup ft8xx_interface
25 : * @{
26 : */
27 :
28 : /** Rectangular pixel arrays, in various color formats */
29 1 : #define FT8XX_BITMAPS 1U
30 : /** Anti-aliased points, point radius is 1-256 pixels */
31 1 : #define FT8XX_POINTS 2U
32 : /**
33 : * Anti-aliased lines, with width from 0 to 4095 1/16th of pixel units.
34 : * (width is from center of the line to boundary)
35 : */
36 1 : #define FT8XX_LINES 3U
37 : /** Anti-aliased lines, connected head-to-tail */
38 1 : #define FT8XX_LINE_STRIP 4U
39 : /** Edge strips for right */
40 1 : #define FT8XX_EDGE_STRIP_R 5U
41 : /** Edge strips for left */
42 1 : #define FT8XX_EDGE_STRIP_L 6U
43 : /** Edge strips for above */
44 1 : #define FT8XX_EDGE_STRIP_A 7U
45 : /** Edge strips for below */
46 1 : #define FT8XX_EDGE_STRIP_B 8U
47 : /**
48 : * Round-cornered rectangles, curvature of the corners can be adjusted using
49 : * FT8XX_LINE_WIDTH
50 : */
51 1 : #define FT8XX_RECTS 9U
52 :
53 : /**
54 : * @brief Begin drawing a graphics primitive
55 : *
56 : * The valid primitives are defined as:
57 : * - @ref FT8XX_BITMAPS
58 : * - @ref FT8XX_POINTS
59 : * - @ref FT8XX_LINES
60 : * - @ref FT8XX_LINE_STRIP
61 : * - @ref FT8XX_EDGE_STRIP_R
62 : * - @ref FT8XX_EDGE_STRIP_L
63 : * - @ref FT8XX_EDGE_STRIP_A
64 : * - @ref FT8XX_EDGE_STRIP_B
65 : * - @ref FT8XX_RECTS
66 : *
67 : * The primitive to be drawn is selected by the @ref FT8XX_BEGIN command. Once
68 : * the primitive is selected, it will be valid till the new primitive is
69 : * selected by the @ref FT8XX_BEGIN command.
70 : *
71 : * @note The primitive drawing operation will not be performed until
72 : * @ref FT8XX_VERTEX2II or @ref FT8XX_VERTEX2F is executed.
73 : *
74 : * @param prim Graphics primitive
75 : */
76 1 : #define FT8XX_BEGIN(prim) (0x1f000000 | ((prim) & 0x0f))
77 :
78 : /**
79 : * @brief Clear buffers to preset values
80 : *
81 : * Setting @p c to true will clear the color buffer of the FT8xx to the preset
82 : * value. Setting this bit to false will maintain the color buffer of the FT8xx
83 : * with an unchanged value. The preset value is defined in command
84 : * @ref FT8XX_CLEAR_COLOR_RGB for RGB channel and FT8XX_CLEAR_COLOR_A for alpha
85 : * channel.
86 : *
87 : * Setting @p s to true will clear the stencil buffer of the FT8xx to the preset
88 : * value. Setting this bit to false will maintain the stencil buffer of the
89 : * FT8xx with an unchanged value. The preset value is defined in command
90 : * FT8XX_CLEAR_STENCIL.
91 : *
92 : * Setting @p t to true will clear the tag buffer of the FT8xx to the preset
93 : * value. Setting this bit to false will maintain the tag buffer of the FT8xx
94 : * with an unchanged value. The preset value is defined in command
95 : * FT8XX_CLEAR_TAG.
96 : *
97 : * @param c Clear color buffer
98 : * @param s Clear stencil buffer
99 : * @param t Clear tag buffer
100 : */
101 1 : #define FT8XX_CLEAR(c, s, t) (0x26000000 | \
102 : ((c) ? 0x04 : 0) | ((s) ? 0x02 : 0) | ((t) ? 0x01 : 0))
103 :
104 : /**
105 : * @brief Specify clear values for red, green and blue channels
106 : *
107 : * Sets the color values used by a following @ref FT8XX_CLEAR.
108 : *
109 : * @param red Red value used when the color buffer is cleared
110 : * @param green Green value used when the color buffer is cleared
111 : * @param blue Blue value used when the color buffer is cleared
112 : */
113 1 : #define FT8XX_CLEAR_COLOR_RGB(red, green, blue) (0x02000000 | \
114 : (((uint32_t)(red) & 0xff) << 16) | \
115 : (((uint32_t)(green) & 0xff) << 8) | \
116 : ((uint32_t)(blue) & 0xff))
117 :
118 : /**
119 : * @brief Set the current color red, green and blue
120 : *
121 : * Sets red, green and blue values of the FT8xx color buffer which will be
122 : * applied to the following draw operation.
123 : *
124 : * @param red Red value for the current color
125 : * @param green Green value for the current color
126 : * @param blue Blue value for the current color
127 : */
128 1 : #define FT8XX_COLOR_RGB(red, green, blue) (0x04000000 | \
129 : (((uint32_t)(red) & 0xff) << 16) | \
130 : (((uint32_t)(green) & 0xff) << 8) | \
131 : ((uint32_t)(blue) & 0xff))
132 :
133 : /**
134 : * @brief End the display list
135 : *
136 : * FT8xx will ignore all the commands following this command.
137 : */
138 1 : #define FT8XX_DISPLAY() 0
139 :
140 : /**
141 : * @brief End drawing a graphics primitive
142 : *
143 : * It is recommended to have an @ref FT8XX_END for each @ref FT8XX_BEGIN.
144 : * Whereas advanced users can avoid the usage of @ref FT8XX_END in order to
145 : * save extra graphics instructions in the display list RAM.
146 : */
147 1 : #define FT8XX_END() 0x21000000
148 :
149 : /**
150 : * @brief Specify the width of lines to be drawn with primitive @ref FT8XX_LINES
151 : *
152 : * Sets the width of drawn lines. The width is the distance from the center of
153 : * the line to the outermost drawn pixel, in units of 1/16 pixel. The valid
154 : * range is from 16 to 4095 in terms of 1/16th pixel units.
155 : *
156 : * @note The @ref FT8XX_LINE_WIDTH command will affect the @ref FT8XX_LINES,
157 : * @ref FT8XX_LINE_STRIP, @ref FT8XX_RECTS, @ref FT8XX_EDGE_STRIP_A /B/R/L
158 : * primitives.
159 : *
160 : * @param width Line width in 1/16 pixel
161 : */
162 1 : #define FT8XX_LINE_WIDTH(width) (0x0e000000 | ((uint32_t)(width) & 0xfff))
163 :
164 : /**
165 : * @brief Attach the tag value for the following graphics objects.
166 : *
167 : * The initial value of the tag buffer of the FT8xx is specified by command
168 : * FT8XX_CLEAR_TAG and taken effect by command @ref FT8XX_CLEAR. @ref FT8XX_TAG
169 : * command can specify the value of the tag buffer of the FT8xx that applies to
170 : * the graphics objects when they are drawn on the screen. This tag value will
171 : * be assigned to all the following objects, unless the FT8XX_TAG_MASK command
172 : * is used to disable it. Once the following graphics objects are drawn, they
173 : * are attached with the tag value successfully. When the graphics objects
174 : * attached with the tag value are touched, the register
175 : * @ref FT800_REG_TOUCH_TAG or @ref FT810_REG_TOUCH_TAG will be updated with the
176 : * tag value of the graphics object being touched. If there is no @ref FT8XX_TAG
177 : * commands in one display list, all the graphics objects rendered by the
178 : * display list will report tag value as 255 in @ref FT800_REG_TOUCH_TAG or
179 : * @ref FT810_REG_TOUCH_TAG when they were touched.
180 : *
181 : * @param s Tag value 1-255
182 : */
183 1 : #define FT8XX_TAG(s) (0x03000000 | (uint8_t)(s))
184 :
185 : /**
186 : * @brief Start the operation of graphics primitives at the specified coordinate
187 : *
188 : * The range of coordinates is from -16384 to +16383 in terms of 1/16th pixel
189 : * units. The negative x coordinate value means the coordinate in the left
190 : * virtual screen from (0, 0), while the negative y coordinate value means the
191 : * coordinate in the upper virtual screen from (0, 0). If drawing on the
192 : * negative coordinate position, the drawing operation will not be visible.
193 : *
194 : * @param x Signed x-coordinate in 1/16 pixel precision
195 : * @param y Signed y-coordinate in 1/16 pixel precision
196 : */
197 1 : #define FT8XX_VERTEX2F(x, y) (0x40000000 | \
198 : (((int32_t)(x) & 0x7fff) << 15) | \
199 : ((int32_t)(y) & 0x7fff))
200 :
201 : /**
202 : * @brief Start the operation of graphics primitive at the specified coordinates
203 : *
204 : * The valid range of @p handle is from 0 to 31. From 16 to 31 the bitmap handle
205 : * is dedicated to the FT8xx built-in font.
206 : *
207 : * Cell number is the index of bitmap with same bitmap layout and format.
208 : * For example, for handle 31, the cell 65 means the character "A" in the
209 : * largest built in font.
210 : *
211 : * @param x x-coordinate in pixels, from 0 to 511
212 : * @param y y-coordinate in pixels, from 0 to 511
213 : * @param handle Bitmap handle
214 : * @param cell Cell number
215 : */
216 1 : #define FT8XX_VERTEX2II(x, y, handle, cell) (0x80000000 | \
217 : (((uint32_t)(x) & 0x01ff) << 21) | \
218 : (((uint32_t)(y) & 0x01ff) << 12) | \
219 : (((uint32_t)(handle) & 0x1f) << 7) | \
220 : ((uint32_t)(cell) & 0x7f))
221 :
222 : /**
223 : * @}
224 : */
225 :
226 : #ifdef __cplusplus
227 : }
228 : #endif
229 :
230 : #endif /* ZEPHYR_DRIVERS_MISC_FT8XX_FT8XX_DL_H_ */
|