1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 #ifndef __DA1469X_LCDC_H
21 #define __DA1469X_LCDC_H
22
23 #include <stdint.h>
24 #include <DA1469xAB.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /* Pixel (output) color formats supported by the display controller */
31
32 /** 0 0 R G B R' G' B' */
33 #define LCDC_SMARTBOND_OCM_8RGB111_1 0x06
34 /** R G B 0 R' G' B' 0 */
35 #define LCDC_SMARTBOND_OCM_8RGB111_2 0x07
36 /** R G B R' G' B' ... */
37 #define LCDC_SMARTBOND_OCM_RGB111 0x08
38 /** D D' D'' ... */
39 #define LCDC_SMARTBOND_OCM_L1 0x09
40 /** R[2-0]G[2-0]B[1-0] */
41 #define LCDC_SMARTBOND_OCM_RGB332 0x10
42 /** R[3-0]G[3-0] - B[3-0]R'[3-0] - G'[3-0]B'[3-0] */
43 #define LCDC_SMARTBOND_OCM_RGB444 0x11
44 /** R[4-0]G[5-3] - G[2-0]B[4-0] */
45 #define LCDC_SMARTBOND_OCM_RGB565 0x12
46 /** R[5-0]00 - G[5-0]00 - B[5-0]00 */
47 #define LCDC_SMARTBOND_OCM_RGB666 0x13
48 /** R[7-0] - G[7-0] - B[7-0] */
49 #define LCDC_SMARTBOND_OCM_RGB888 0x14
50 /* RGB and JDI Parallel Interface */
51 #define LCDC_SMARTBOND_OCM_RGB222 0x0A
52
53 /* Layer (input) color formats supported by the display controller */
54
55 /** R[4-0]G[4-0]B[4-0]A0 */
56 #define LCDC_SMARTBOND_L0_RGBA5551 0x01
57 /** R[7-0]G[7-0]B[7-0]A[7-0] */
58 #define LCDC_SMARTBOND_L0_RGBA8888 0x02
59 /** R[2-0]G[2-0]B[1-0] */
60 #define LCDC_SMARTBOND_L0_RGB332 0x04
61 /** R[4-0]G[5-0]B[4-0] */
62 #define LCDC_SMARTBOND_L0_RGB565 0x05
63 /** A[7-0]R[7-0]G[7-0]B[7-0] */
64 #define LCDC_SMARTBOND_L0_ARGB8888 0x06
65 /** L[7-0] - Grayscale */
66 #define LCDC_SMARTBOND_L0_L8 0x07
67 /** L - Black and white, 1 = black, 0 = white */
68 #define LCDC_SMARTBOND_L0_L1 0x08
69 /** L[3-0] - Grayscale */
70 #define LCDC_SMARTBOND_L0_L4 0x09
71 /** A[7-0]B[7-0]G[7-0]R[7-0] */
72 #define LCDC_SMARTBOND_L0_ABGR8888 0x0D
73 /** B[7-0]G[7-0]R[7-0]A[7-0] */
74 #define LCDC_SMARTBOND_L0_BGRA8888 0x0E
75
76 #define LCDC_SMARTBOND_MODE_SPI3 BIT(0)
77 #define LCDC_SMARTBOND_MODE_SPI4 BIT(1)
78
79 typedef struct {
80 uint16_t vsync_len;
81 uint16_t hsync_len;
82 uint16_t hfront_porch;
83 uint16_t vfront_porch;
84 uint16_t vback_porch;
85 uint16_t hback_porch;
86 } lcdc_smartbond_timing_cfg;
87
88 typedef struct {
89 bool vsync_pol;
90 bool hsync_pol;
91 bool de_pol;
92 bool pixelclk_pol;
93 } lcdc_smartbond_mode_cfg;
94
95 typedef struct {
96 bool cpha;
97 bool cpol;
98 bool cs_active_high;
99 uint8_t line_mode;
100 uint8_t color_mode;
101 } lcdc_smartbond_mipi_dbi_cfg;
102
103 typedef struct {
104 /*
105 * Base address of the frame to be displayed. Should first be translated
106 * to its physical address.
107 */
108 uint32_t frame_buf;
109 /*
110 * X/Y coordinates of the top-left corner of the layer.
111 * (0, 0) is the top-left corner of the screen.
112 */
113 int16_t start_x;
114 int16_t start_y;
115 /* X/Y resolution of layer in pixels */
116 uint16_t size_x;
117 uint16_t size_y;
118 /* Frame color format */
119 uint8_t color_format;
120 /* Line to line disctance in bytes of frame in memory */
121 int32_t stride;
122 } lcdc_smartbond_layer_cfg;
123
124 typedef struct {
125 uint8_t red;
126 uint8_t green;
127 uint8_t blue;
128 uint8_t alpha;
129 } lcdc_smartbond_bgcolor_cfg;
130
131 /*
132 * Min. timing settings required by the timing generator. For the MIPI DBI
133 * inferface all timing setting can be safely ignored.
134 */
135 #define LCDC_SMARTBOND_VSYN_MIN_LEN 1
136 #define LCDC_SMARTBOND_HSYN_MIN_LEN 2
137
138 #define LCDC_SMARTBOND_ID 0x87452365
139
140 #define LCDC_STATUS_REG_GET_FIELD(_field) \
141 ((LCDC->LCDC_STATUS_REG & LCDC_LCDC_STATUS_REG_ ## _field ## _Msk) >> \
142 LCDC_LCDC_STATUS_REG_ ## _field ## _Pos)
143
144 /* Helper macro to setup the later configuration container */
145 #define LCDC_SMARTBOND_LAYER_CONFIG(_layer, _buf, _x_start, _y_start, _x_size, _y_size, \
146 _color, _stride) \
147 (_layer)->frame_buf = (uint32_t)_buf; \
148 (_layer)->start_x = _x_start; \
149 (_layer)->start_y = _y_start; \
150 (_layer)->size_x = _x_size; \
151 (_layer)->size_y = _y_size; \
152 (_layer)->color_format = _color; \
153 (_layer)->stride = _stride;
154
155 /**
156 * LCDC stride calculation
157 *
158 * @param lcm Layer color format supported by LCDC
159 * @param x_res X resolution in pixels
160 *
161 * @return Stride value in bytes
162 */
163 uint16_t
164 da1469x_lcdc_stride_calculation(uint8_t lcm, uint16_t x_res);
165
166 /**
167 * LCDC layer configuration
168 *
169 * @param layer Pointer to structure that contains layer settings
170 *
171 * @return Zero for success or a negative value indicating the reason of failure
172 */
173 int
174 da1469x_lcdc_layer_configure(lcdc_smartbond_layer_cfg *layer);
175
176 /**
177 * DBIB interface to send command or data in SPI3/SPI4 serial interface
178 *
179 * @param cmd True if data represents a command, false otherwise
180 * @param buf Buffer with the command or data to be sent
181 * @param len Number of command or data in bytes to be sent
182 *
183 */
184 void
185 da1469x_lcdc_send_cmd_data(bool cmd, const uint8_t *buf, size_t len);
186
187 /**
188 * LCDC background layer configuration
189 *
190 * @param bgcolor Pointer to structure that contains background color settings
191 *
192 */
193 void
194 da1469x_lcdc_bgcolor_configure(lcdc_smartbond_bgcolor_cfg *bgcolor);
195
196 /**
197 * LCDC set status
198 *
199 * @param enable True to enable and false to disable clocking LCDC
200 * @param div1 If true DIV1 clock path is used (follows system clocking).
201 * Otherwise, DIVN clock paths is used (follows the external
202 * crystal frequency).
203 *
204 */
205 void
206 da1469x_lcdc_set_status(bool enable, bool div1, uint8_t clk_div);
207
208 /**
209 * LCDC timing generator configuration
210 *
211 * @param x_res X resolution in pixels of active window
212 * @param y_res Y resolution in pixels of active window
213 * @param timing Pointer to structure that contains timings settings
214 *
215 * @return Zero for success or a negative value indicating the reason of failure
216 *
217 */
218 int
219 da1469x_lcdc_timings_configure(uint16_t x_res, uint16_t y_res, lcdc_smartbond_timing_cfg *timing);
220
221 /**
222 * Tearing effect (TE) set status
223 *
224 * @param enable True to enable TE signaling and false to disble it.
225 * @param inversion True to invert TE signaling false otherwise.
226 *
227 */
228 void
229 da1469x_lcdc_te_set_status(bool enable, bool inversion);
230
231 /**
232 * LCDC configure RGB interface
233 *
234 * Configure the RGB interface without enabling continous mode.
235 *
236 * @param mode Pointer to structure that contains RGB related settings
237 *
238 */
239 void
240 da1469x_lcdc_parallel_interface_configure(lcdc_smartbond_mode_cfg *mode);
241
242 /**
243 * LCDC configure serial (MIPI DBI Type-B) interface
244 *
245 * @param spi Pointer to structure that contains SPI related settings
246 *
247 * @return Zero for success or a negative value indicating the reason of failure
248 *
249 */
250 int
251 da1469x_lcdc_mipi_dbi_interface_configure(lcdc_smartbond_mipi_dbi_cfg *mipi_dbi);
252
253 /**
254 * LCDC force #CS line in SPI interface
255 *
256 * @param force True to force #CS line to \p cs_level, false otherwise.
257 * @param cs_level True to drive #CS to high level, false otherwise. This
258 * value also defined the active level of #CS line when is
259 * not drived forcefully.
260 *
261 */
262 void
263 da1469x_lcdc_force_cs_line(bool force, bool cs_level);
264
265 /**
266 * Check if LCDC is busy
267 *
268 * @return True if LCDC is busy generating pixel data or sending DBIB commands/data
269 * false otherwise.
270 *
271 */
272 static inline bool
da1469x_lcdc_is_busy(void)273 da1469x_lcdc_is_busy(void)
274 {
275 bool ret = false;
276
277 ret |= LCDC_STATUS_REG_GET_FIELD(LCDC_FRAMEGEN_BUSY);
278 ret |= LCDC_STATUS_REG_GET_FIELD(LCDC_DBIB_CMD_FIFO_EMPTY_N);
279
280 return ret;
281 }
282
283 /**
284 * Check if LCDC has the correct ID
285 *
286 * @return True if LCDC has the correct magic value false otherwise.
287 *
288 */
289 static inline bool
da1469x_lcdc_check_id(void)290 da1469x_lcdc_check_id(void)
291 {
292 return (LCDC->LCDC_IDREG_REG == LCDC_SMARTBOND_ID);
293 }
294
295 #ifdef __cplusplus
296 }
297 #endif
298
299 #endif /* __DA1469X_LCDC_H */
300