1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017, 2020 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #ifndef _FSL_ISI_H_
10 #define _FSL_ISI_H_
11
12 #include "fsl_common.h"
13
14 #define ISI_ROI_NUM 4U /* The Number of "Region Of Interest (ROI)" */
15
16 /*!
17 * @addtogroup isi
18 * @{
19 */
20
21 /*******************************************************************************
22 * Definitions
23 ******************************************************************************/
24
25 /*! @name Driver version */
26 /*@{*/
27 /*! @brief ISI driver version */
28 #define FSL_ISI_DRIVER_VERSION (MAKE_VERSION(2, 0, 1)) /*!< Version 2.0.1. */
29 /*@}*/
30
31 /*! @brief ISI interrupts. */
32 enum _isi_interrupt
33 {
34 kISI_MemReadCompletedInterrupt = ISI_CHNL_IER_MEM_RD_DONE_EN_MASK, /*!< Input memory read completed. */
35 kISI_LineReceivedInterrupt = ISI_CHNL_IER_LINE_RCVD_EN_MASK, /*!< Line received. */
36 kISI_FrameReceivedInterrupt = ISI_CHNL_IER_FRM_RCVD_EN_MASK, /*!< Frame received. */
37 kISI_AxiWriteErrorVInterrupt =
38 ISI_CHNL_IER_AXI_WR_ERR_V_EN_MASK, /*!< AXI Bus write error when storing V data to memory. */
39 kISI_AxiWriteErrorUInterrupt =
40 ISI_CHNL_IER_AXI_WR_ERR_U_EN_MASK, /*!< AXI Bus write error when storing U data to memory. */
41 kISI_AxiWriteErrorYInterrupt =
42 ISI_CHNL_IER_AXI_WR_ERR_Y_EN_MASK, /*!< AXI Bus write error when storing Y data to memory. */
43 kISI_AxiReadErrorInterrupt = ISI_CHNL_IER_AXI_RD_ERR_EN_MASK, /*!< AXI Bus error when reading the input memory. */
44 kISI_OverflowAlertVInterrupt =
45 ISI_CHNL_IER_OFLW_PANIC_V_BUF_EN_MASK, /*!< V output buffer overflow threshold accrossed. */
46 kISI_ExcessOverflowVInterrupt =
47 ISI_CHNL_IER_EXCS_OFLW_V_BUF_EN_MASK, /*!< V output buffer excess overflow interrupt. */
48 kISI_OverflowVInterrupt = ISI_CHNL_IER_OFLW_V_BUF_EN_MASK, /*!< V output buffer overflow interrupt. */
49 kISI_OverflowAlertUInterrupt =
50 ISI_CHNL_IER_OFLW_PANIC_U_BUF_EN_MASK, /*!< U output buffer overflow threshold accrossed. */
51 kISI_ExcessOverflowUInterrupt =
52 ISI_CHNL_IER_EXCS_OFLW_U_BUF_EN_MASK, /*!< U output buffer excess overflow interrupt. */
53 kISI_OverflowUInterrupt = ISI_CHNL_IER_OFLW_U_BUF_EN_MASK, /*!< U output buffer overflow interrupt. */
54 kISI_OverflowAlertYInterrupt =
55 ISI_CHNL_IER_OFLW_PANIC_Y_BUF_EN_MASK, /*!< V output buffer overflow threshold accrossed. */
56 kISI_ExcessOverflowYInterrupt =
57 ISI_CHNL_IER_EXCS_OFLW_Y_BUF_EN_MASK, /*!< V output buffer excess overflow interrupt. */
58 kISI_OverflowYInterrupt = ISI_CHNL_IER_OFLW_Y_BUF_EN_MASK, /*!< V output buffer overflow interrupt. */
59 };
60
61 /*! @brief ISI output image format. */
62 typedef enum _isi_output_format
63 {
64 kISI_OutputRGBA8888 = 0U, /*!< RGBA8888. */
65 kISI_OutputABGR8888 = 1U, /*!< ABGR8888. */
66 kISI_OutputARGB8888 = 2U, /*!< ARGB8888. */
67 kISI_OutputRGBX8888 = 3U, /*!< RGBX8888 unpacked and MSB aligned in 32-bit. */
68 kISI_OutputXBGR8888 = 4U, /*!< XBGR8888 unpacked and LSB aligned in 32-bit. */
69 kISI_OutputXRGB8888 = 5U, /*!< XRGB8888 unpacked and LSB aligned in 32-bit. */
70 kISI_OutputRGB888 = 6U, /*!< RGB888 packed into 32-bit. */
71 kISI_OutputBGR888 = 7U, /*!< BGR888 packed into 32-bit. */
72 kISI_OutputA2BGR10 = 8U, /*!< BGR format with 2-bits alpha in MSB; 10-bits per color component. */
73 kISI_OutputA2RGB10 = 9U, /*!< RGB format with 2-bits alpha in MSB; 10-bits per color component. */
74 kISI_OutputRGB565 = 10U, /*!< RGB565 packed into 32-bit. */
75 kISI_OutputRaw8 = 11U, /*!< 8-bit raw data packed into 32-bit. */
76 kISI_OutputRaw10 = 12U, /*!< 10-bit raw data packed into 16-bit with 6 LSBs wasted. */
77 kISI_OutputRaw10P = 13U, /*!< 10-bit raw data packed into 32-bit. */
78 kISI_OutputRaw12P = 14U, /*!< 16-bit raw data packed into 16-bit with 4 LSBs wasted. */
79 kISI_OutputRaw16P = 15U, /*!< 16-bit raw data packed into 32-bit. */
80 kISI_OutputYUV444_1P8P = 16U, /*!< 8-bits per color component; 1-plane, YUV interleaved packed bytes. */
81 kISI_OutputYUV444_2P8P = 17U, /*!< 8-bits per color component; 2-plane, UV interleaved packed bytes. */
82 kISI_OutputYUV444_3P8P = 18U, /*!< 8-bits per color component; 3-plane, non-interleaved packed bytes. */
83 kISI_OutputYUV444_1P8 = 19U, /*!< 8-bits per color component; 1-plane YUV interleaved unpacked bytes (8 MSBs waste
84 bits in 32-bit DWORD). */
85 kISI_OutputYUV444_1P10 = 20U, /*!< 10-bits per color component; 1-plane, YUV interleaved unpacked bytes (6 LSBs
86 waste bits in 16-bit WORD). */
87 kISI_OutputYUV444_2P10 = 21U, /*!< 10-bits per color component; 2-plane, UV interleaved unpacked bytes (6 LSBs
88 waste bits in 16-bit WORD). */
89 kISI_OutputYUV444_3P10 = 22U, /*!< 10-bits per color component; 3-plane, non-interleaved unpacked bytes (6 LSBs
90 waste bits in 16-bit WORD). */
91 kISI_OutputYUV444_1P10P = 24U, /*!< 10-bits per color component; 1-plane, YUV interleaved packed bytes (2 MSBs
92 waste bits in 32-bit DWORD). */
93 kISI_OutputYUV444_2P10P = 25U, /*!< 10-bits per color component; 2-plane, UV interleaved packed bytes (2 MSBs waste
94 bits in 32-bit DWORD). */
95 kISI_OutputYUV444_3P10P = 26U, /*!< 10-bits per color component; 3-plane, non-interleaved packed bytes (2 MSBs
96 waste bits in 32-bit DWORD). */
97 kISI_OutputYUV444_1P12 = 28U, /*!< 12-bits per color component; 1-plane, YUV interleaved unpacked bytes (4 LSBs
98 waste bits in 16-bit WORD). */
99 kISI_OutputYUV444_2P12 = 29U, /*!< 12-bits per color component; 2-plane, UV interleaved unpacked bytes (4 LSBs
100 waste bits in 16-bit WORD). */
101 kISI_OutputYUV444_3P12 = 30U, /*!< 12-bits per color component; 3-plane, non-interleaved unpacked bytes (4 LSBs
102 waste bits in 16-bit WORD). */
103 kISI_OutputYUV422_1P8P = 32U, /*!< 8-bits per color component; 1-plane, YUV interleaved packed bytes. */
104 kISI_OutputYUV422_2P8P = 33U, /*!< 8-bits per color component; 2-plane, UV interleaved packed bytes. */
105 kISI_OutputYUV422_3P8P = 34U, /*!< 8-bits per color component; 3-plane, non-interleaved packed bytes. */
106 kISI_OutputYUV422_1P10 = 36U, /*!< 10-bits per color component; 1-plane, YUV interleaved unpacked bytes (6 LSBs
107 waste bits in 16-bit WORD). */
108 kISI_OutputYUV422_2P10 = 37U, /*!< 10-bits per color component; 2-plane, UV interleaved unpacked bytes (6 LSBs
109 waste bits in 16-bit WORD). */
110 kISI_OutputYUV422_3P10 = 38U, /*!< 10-bits per color component; 3-plane, non-interleaved unpacked bytes (6 LSBs
111 waste bits in 16-bit WORD). */
112 kISI_OutputYUV422_1P10P = 40U, /*!< 10-bits per color component; 1-plane, YUV interleaved packed bytes (2 MSBs
113 waste bits in 32-bit DWORD). */
114 kISI_OutputYUV422_2P10P = 41U, /*!< 10-bits per color component; 2-plane, UV interleaved packed bytes (2 MSBs waste
115 bits in 32-bit DWORD). */
116 kISI_OutputYUV422_3P10P = 42U, /*!< 10-bits per color component; 3-plane, non-interleaved packed bytes (2 MSBs
117 waste bits in 32-bit DWORD). */
118 kISI_OutputYUV422_1P12 = 44U, /*!< 12-bits per color component; 1-plane, YUV interleaved unpacked bytes (4 LSBs
119 waste bits in 16-bit WORD). */
120 kISI_OutputYUV422_2P12 = 45U, /*!< 12-bits per color component; 2-plane, UV interleaved unpacked bytes (4 LSBs
121 waste bits in 16-bit WORD). */
122 kISI_OutputYUV422_3P12 = 46U, /*!< 12-bits per color component; 3-plane, non-interleaved unpacked bytes (4 LSBs
123 waste bits in 16-bit WORD). */
124 kISI_OutputYUV420_2P8P = 49U, /*!< 8-bits per color component; 2-plane, UV interleaved packed bytes. */
125 kISI_OutputYUV420_3P8P = 50U, /*!< 8-bits per color component; 3-plane, non-interleaved packed bytes. */
126 kISI_OutputYUV420_2P10 = 53U, /*!< 10-bits per color component; 2-plane, UV interleaved unpacked bytes (6 LSBs
127 waste bits in 16-bit WORD). */
128 kISI_OutputYUV420_3P10 = 54U, /*!< 10-bits per color component; 3-plane, non-interleaved unpacked bytes (6 LSBs
129 waste bits in 16-bit WORD). */
130 kISI_OutputYUV420_2P10P = 57U, /*!< 10-bits per color component; 2-plane, UV interleaved packed bytes (2 MSBs waste
131 bits in 32-bit DWORD). */
132 kISI_OutputYUV420_3P10P = 58U, /*!< 10-bits per color component; 3-plane, non-interleaved packed bytes (2 MSBs
133 waste bits in 32-bit DWORD). */
134 kISI_OutputYUV420_2P12 = 61U, /*!< 12-bits per color component; 2-plane, UV interleaved unpacked bytes (4 LSBs
135 waste bits in 16-bit WORD). */
136 kISI_OutputYUV420_3P12 = 62U, /*!< 12-bits per color component; 3-plane, non-interleaved unpacked bytes (4 LSBs
137 waste bits in 16-bit WORD). */
138
139 } isi_output_format_t;
140
141 /*! @brief ISI line buffer chain mode. */
142 typedef enum _isi_chain_mode
143 {
144 kISI_ChainDisable = 0U, /*!< No line buffers chained, for 2048 or less horizontal resolution. */
145 kISI_ChainTwo = 1U, /*!< Line buffers of channel n and n+1 chained, for 4096 horizontal resolution. */
146 } isi_chain_mode_t;
147
148 /*! @brief ISI de-interlacing mode. */
149 typedef enum _isi_deint_mode
150 {
151 kISI_DeintDisable = 0U, /*!< No de-interlacing. */
152 kISI_DeintWeaveOddOnTop = 2U, /*!< Weave de-interlacing (Odd, Even) method used. */
153 kISI_DeintWeaveEvenOnTop = 3U, /*!< Weave de-interlacing (Even, Odd) method used. */
154 kISI_DeintBlendingOddFirst = 4U, /*!< Blending or linear interpolation (Odd + Even). */
155 kISI_DeintBlendingEvenFirst = 5U, /*!< Blending or linear interpolation (Even + Odd). */
156 kISI_DeintDoublingOdd = 6U, /*!< Doubling odd frame and discard even frame. */
157 kISI_DeintDoublingEven = 7U, /*!< Doubling even frame and discard odd frame. */
158 } isi_deint_mode_t;
159
160 /*! @brief ISI overflow panic alert threshold. */
161 typedef enum _isi_threshold
162 {
163 kISI_ThresholdDisable = 0U, /*!< No panic alert will be asserted. */
164 kISI_Threshold25Percent = 1U, /*!< Panic will assert when the buffers are 25% full. */
165 kISI_Threshold50Percent = 2U, /*!< Panic will assert when the buffers are 50% full. */
166 kISI_Threshold75Percent = 3U /*!< Panic will assert when the buffers are 75% full. */
167 } isi_threshold_t;
168
169 /*! @brief ISI basic configuration. */
170 typedef struct _isi_config
171 {
172 bool isChannelBypassed; /*!< Bypass the channel, if bypassed, the scaling and
173 color space conversion could not work. */
174 bool isSourceMemory; /*!< Whether the input source is memory or not. */
175 bool isYCbCr; /*!< Whether the input source is YCbCr mode or not. */
176 isi_chain_mode_t chainMode; /*!< The line buffer chain mode. */
177 isi_deint_mode_t deintMode; /*!< The de-interlacing mode. */
178 uint8_t blankPixel; /*!< The pixel to insert into image when overflow occors. */
179 uint8_t sourcePort; /*!< Input source port selection. */
180 uint8_t mipiChannel; /*!< MIPI virtual channel, ignored if input source is not MIPI CSI. */
181 uint16_t inputHeight; /*!< Input image height(lines). */
182 uint16_t inputWidth; /*!< Input image width(pixels). */
183 isi_output_format_t outputFormat; /*!< Output image format. */
184 uint16_t outputLinePitchBytes; /*< Output buffer pitch in bytes. */
185 isi_threshold_t thresholdY; /*!< Panic alert threshold for RGB or Luma (Y) buffer. */
186 isi_threshold_t thresholdU; /*!< Panic alert threshold for Chroma (U/Cb/UV/CbCr) buffer. */
187 isi_threshold_t thresholdV; /*!< Panic alert threshold for Chroma (V/Cr) buffer. */
188 } isi_config_t;
189
190 /*! @brief ISI color space conversion mode. */
191 typedef enum _isi_csc_mode
192 {
193 kISI_CscYUV2RGB, /*!< Convert YUV to RGB. */
194 kISI_CscYCbCr2RGB, /*!< Convert YCbCr to RGB. */
195 kISI_CscRGB2YUV, /*!< Convert RGB to YUV. */
196 kISI_CscRGB2YCbCr /*!< Convert RGB to YCbCr. */
197 } isi_csc_mode_t;
198
199 /*!
200 * @brief ISI color space conversion configurations.
201 *
202 * (a) RGB to YUV (or YCbCr) conversion
203 * - Y = (A1 x R) + (A2 x G) + (A3 x B) + D1
204 * - U = (B1 x R) + (B2 x G) + (B3 x B) + D2
205 * - V = (C1 x R) + (C2 x G) + (C3 x B) + D3
206 *
207 * (b) YUV (or YCbCr) to RGB conversion
208 * - R = (A1 x (Y + D1)) + (A2 x (U + D2)) + (A3 x (V + D3))
209 * - G = (B1 x (Y + D1)) + (B2 x (U + D2)) + (B3 x (V + D3))
210 * - B = (C1 x (Y + D1)) + (C2 x (U + D2)) + (C3 x (V + D3))
211 *
212 * Overflow for the three channels are saturated at 0x255 and underflow is saturated at 0x00.
213 */
214 typedef struct _isi_csc_config
215 {
216 isi_csc_mode_t mode; /*!< Convertion mode. */
217 float A1; /*!< Must be in the range of [-3.99609375, 3.99609375]. */
218 float A2; /*!< Must be in the range of [-3.99609375, 3.99609375]. */
219 float A3; /*!< Must be in the range of [-3.99609375, 3.99609375]. */
220 float B1; /*!< Must be in the range of [-3.99609375, 3.99609375]. */
221 float B2; /*!< Must be in the range of [-3.99609375, 3.99609375]. */
222 float B3; /*!< Must be in the range of [-3.99609375, 3.99609375]. */
223 float C1; /*!< Must be in the range of [-3.99609375, 3.99609375]. */
224 float C2; /*!< Must be in the range of [-3.99609375, 3.99609375]. */
225 float C3; /*!< Must be in the range of [-3.99609375, 3.99609375]. */
226 int16_t D1; /*!< Must be in the range of [-256, 255]. */
227 int16_t D2; /*!< Must be in the range of [-256, 255]. */
228 int16_t D3; /*!< Must be in the range of [-256, 255]. */
229 } isi_csc_config_t;
230
231 /*! @brief ISI flipping mode. */
232 typedef enum _isi_flip_mode
233 {
234 kISI_FlipDisable = 0U, /*!< Flip disabled. */
235 kISI_FlipHorizontal = ISI_CHNL_IMG_CTRL_HFLIP_EN_MASK, /*!< Horizontal flip. */
236 kISI_FlipVertical = ISI_CHNL_IMG_CTRL_VFLIP_EN_MASK, /*!< Vertical flip. */
237 kISI_FlipBoth = ISI_CHNL_IMG_CTRL_VFLIP_EN_MASK | ISI_CHNL_IMG_CTRL_HFLIP_EN_MASK /*!< Flip both direction. */
238 } isi_flip_mode_t;
239
240 /*! @brief ISI cropping configurations. */
241 typedef struct _isi_crop_config
242 {
243 uint16_t upperLeftX; /*!< X of upper left corner. */
244 uint16_t upperLeftY; /*!< Y of upper left corner. */
245 uint16_t lowerRightX; /*!< X of lower right corner. */
246 uint16_t lowerRightY; /*!< Y of lower right corner. */
247 } isi_crop_config_t;
248
249 /*! @brief ISI regional region alpha configurations. */
250 typedef struct _isi_regoin_alpha_config
251 {
252 uint16_t upperLeftX; /*!< X of upper left corner. */
253 uint16_t upperLeftY; /*!< Y of upper left corner. */
254 uint16_t lowerRightX; /*!< X of lower right corner. */
255 uint16_t lowerRightY; /*!< Y of lower right corner. */
256 uint8_t alpha; /*!< Alpha value. */
257 } isi_region_alpha_config_t;
258
259 /*! @brief ISI image format of the input memory. */
260 typedef enum _isi_input_mem_format
261 {
262 kISI_InputMemBGR888 = 0U, /*!< BGR format with 8-bits per color component,
263 packed into 32-bit, 24 bits per pixel. */
264 kISI_InputMemRGB888 = 1U, /*!< RGB format with 8-bits per color component,
265 packed into 32-bit, 24 bits per pixel. */
266 kISI_InputMemXRGB8888 = 2U, /*!< RGB format with 8-bits per color component,
267 unpacked and LSB aligned in 32-bit, 32 bits per pixel. */
268 kISI_InputMemRGBX8888 = 3U, /*!< RGB format with 8-bits per color component,
269 unpacked and MSB alinged in 32-bit, 32 bits per pixel. */
270 kISI_InputMemXBGR8888 = 4U, /*!< BGR format with 8-bits per color component,
271 unpacked and LSB aligned in 32-bit, 32 bits per pixel. */
272 kISI_InputMemRGB565 = 5U, /*!< RGB format with 5-bits of R, B; 6-bits of G (packed into 32-bit) */
273 kISI_InputMemA2BGR10 = 6U, /*!< BGR format with 2-bits alpha in MSB; 10-bits per color component. */
274 kISI_InputMemA2RGB10 = 7U, /*!< RGB format with 2-bits alpha in MSB; 10-bits per color component. */
275 kISI_InputMemYUV444_1P8P = 8U, /*!< 8-bits per color component; 1-plane, YUV interleaved packed bytes. */
276 kISI_InputMemYUV444_1P10 = 9U, /*!< 10-bits per color component; 1-plane, YUV interleaved unpacked bytes (6 LSBs
277 waste bits in 16-bit WORD). */
278 kISI_InputMemYUV444_1P10P = 10U, /*!< 10-bits per color component; 1-plane, YUV interleaved packed bytes (2 MSBs
279 waste bits in 32-bit WORD). */
280 kISI_InputMemYUV444_1P12 = 11U, /*!< 12-bits per color component; 1-plane, YUV interleaved unpacked bytes (4 LSBs
281 waste bits in 16-bit WORD). */
282 kISI_InputMemYUV444_1P8 = 12U, /*!< 8-bits per color component; 1-plane YUV interleaved unpacked bytes
283 (8 MSBs waste bits in 32-bit DWORD). */
284 kISI_InputMemYUV422_1P8P = 13U, /*!< 8-bits per color component; 1-plane YUV interleaved packed bytes. */
285 kISI_InputMemYUV422_1P10 = 14U, /*!< 10-bits per color component; 1-plane, YUV interleaved unpacked bytes (6 LSBs
286 waste bits in 16-bit WORD). */
287 kISI_InputMemYUV422_1P12 = 15U, /*!< 12-bits per color component; 1-plane, YUV interleaved packed bytes (4 MSBs
288 waste bits in 16-bit WORD). */
289 } isi_input_mem_format_t;
290
291 /*! @brief ISI input memory configurations. */
292 typedef struct _isi_input_mem_config
293 {
294 uint32_t adddr; /*!< Address of the input memory. */
295 uint16_t linePitchBytes; /*!< Line phtch in bytes. */
296 uint16_t framePitchBytes; /*!< Frame phtch in bytes. */
297 isi_input_mem_format_t format; /*!< Image format of the input memory. */
298 } isi_input_mem_config_t;
299
300 /*******************************************************************************
301 * APIs
302 ******************************************************************************/
303 #if defined(__cplusplus)
304 extern "C" {
305 #endif /* __cplusplus */
306
307 /*!
308 * @name ISI initialization and de-initialization
309 * @{
310 */
311
312 /*!
313 * @brief Initializes the ISI peripheral.
314 *
315 * This function ungates the ISI clock, it should be called before any other
316 * ISI functions.
317 *
318 * @param base ISI peripheral base address.
319 */
320 void ISI_Init(ISI_Type *base);
321
322 /*!
323 * @brief Deinitializes the ISI peripheral.
324 *
325 * This function gates the ISI clock.
326 *
327 * @param base ISI peripheral base address.
328 */
329 void ISI_Deinit(ISI_Type *base);
330
331 /*!
332 * @brief Reset the ISI peripheral.
333 *
334 * This function resets the ISI channel processing pipeline similar to a hardware
335 * reset. The channel will need to be reconfigured after reset before it can be used.
336 *
337 * @param base ISI peripheral base address.
338 */
339 void ISI_Reset(ISI_Type *base);
340
341 /* @} */
342
343 /*!
344 * @name ISI interrupts
345 * @{
346 */
347
348 /*!
349 * @brief Enables ISI interrupts.
350 *
351 * @param base ISI peripheral base address
352 * @param mask Interrupt source, OR'ed value of @ref _isi_interrupt.
353 * @return OR'ed value of the enabled interrupts before calling this function.
354 */
ISI_EnableInterrupts(ISI_Type * base,uint32_t mask)355 static inline uint32_t ISI_EnableInterrupts(ISI_Type *base, uint32_t mask)
356 {
357 uint32_t reg = base->CHNL_IER;
358 base->CHNL_IER = reg | mask;
359 return reg;
360 }
361
362 /*!
363 * @brief Disables ISI interrupts.
364 *
365 * @param base ISI peripheral base address
366 * @param mask Interrupt source, OR'ed value of @ref _isi_interrupt.
367 * @return OR'ed value of the enabled interrupts before calling this function.
368 */
ISI_DisableInterrupts(ISI_Type * base,uint32_t mask)369 static inline uint32_t ISI_DisableInterrupts(ISI_Type *base, uint32_t mask)
370 {
371 uint32_t reg = base->CHNL_IER;
372 base->CHNL_IER = reg & ~mask;
373 return reg;
374 }
375
376 /*!
377 * @brief Get the ISI interrupt pending flags.
378 *
379 * All interrupt pending flags are returned, upper layer could compare with the
380 * OR'ed value of @ref _isi_interrupt. For example, to check whether memory read
381 * completed, use like this:
382 * @code
383 uint32_t mask = ISI_GetInterruptStatus(ISI);
384 if (mask & kISI_MemReadCompletedInterrupt)
385 {
386 memory read completed
387 }
388 @endcode
389 *
390 * @param base ISI peripheral base address
391 * @return The OR'ed value of the pending interrupt flags. of @ref _isi_interrupt.
392 */
ISI_GetInterruptStatus(ISI_Type * base)393 static inline uint32_t ISI_GetInterruptStatus(ISI_Type *base)
394 {
395 return base->CHNL_STS & ~ISI_CHNL_STS_OFLW_BYTES_MASK;
396 }
397
398 /*!
399 * @brief Clear ISI interrupt pending flags.
400 *
401 * This function could clear one or more flags at one time, the flags to clear
402 * are passed in as an OR'ed value of @ref _isi_interrupt. For example, to clear
403 * both line received interrupt flag and frame received flag, use like this:
404 * @code
405 ISI_ClearInterruptStatus(ISI, kISI_LineReceivedInterrupt | kISI_FrameReceivedInterrupt);
406 @endcode
407 *
408 * @param base ISI peripheral base address
409 * @param mask The flags to clear, it is OR'ed value of @ref _isi_interrupt.
410 */
ISI_ClearInterruptStatus(ISI_Type * base,uint32_t mask)411 static inline void ISI_ClearInterruptStatus(ISI_Type *base, uint32_t mask)
412 {
413 base->CHNL_STS = mask;
414 }
415
416 /* @} */
417
418 /*!
419 * @brief Gets the number of valid pixel bytes lost due to overflow.
420 *
421 * If multiple output buffers overflow, then this function only returns the
422 * status of the buffer with highest priority. The buffer priority is:
423 * Y output buffer > U output buffer > V output buffer.
424 *
425 * @param base ISI peripheral base address
426 * @return The number of valid pixel bytes lost due to overflow.
427 */
ISI_GetOverflowBytes(ISI_Type * base)428 static inline uint8_t ISI_GetOverflowBytes(ISI_Type *base)
429 {
430 return (uint8_t)(base->CHNL_STS & ISI_CHNL_STS_OFLW_BYTES_MASK);
431 }
432
433 /*!
434 * @brief Set the ISI channel basic configurations.
435 *
436 * This function sets the basic configurations, generally the channel could be
437 * started to work after this function. To enable other features such as croping,
438 * flipping, please call the functions accordingly.
439 *
440 * @param base ISI peripheral base address
441 * @param config Pointer to the configuration structure.
442 */
443 void ISI_SetConfig(ISI_Type *base, const isi_config_t *config);
444
445 /*!
446 * @brief Get the ISI channel default basic configurations.
447 *
448 * The default value is:
449 * @code
450 config->isChannelBypassed = false;
451 config->isSourceMemory = false;
452 config->isYCbCr = false;
453 config->chainMode = kISI_ChainDisable;
454 config->deintMode = kISI_DeintDisable;
455 config->blankPixel = 0xFFU;
456 config->sourcePort = 0U;
457 config->mipiChannel = 0U;
458 config->inputHeight = 1080U;
459 config->inputWidth = 1920U;
460 config->outputFormat = kISI_OutputRGBA8888;
461 config->outputLinePitchBytes = 0U;
462 config->thresholdY = kISI_ThresholdDisable;
463 config->thresholdU = kISI_ThresholdDisable;
464 config->thresholdV = kISI_ThresholdDisable;
465 @endcode
466 *
467 * @param config Pointer to the configuration structure.
468 */
469 void ISI_GetDefaultConfig(isi_config_t *config);
470
471 /*!
472 * @name ISI scaler
473 * @{
474 */
475
476 /*!
477 * @brief Set the ISI channel scaler configurations.
478 *
479 * This function sets the scaling configurations. If the ISI channel is bypassed,
480 * then the scaling feature could not be used.
481 *
482 * ISI only supports down scaling but not up scaling.
483 *
484 * @param base ISI peripheral base address
485 * @param inputWidth Input image width.
486 * @param inputHeight Input image height.
487 * @param outputWidth Output image width.
488 * @param outputHeight Output image height.
489 * @note Total bytes in one line after down scaling must be more than 256 bytes.
490 */
491 void ISI_SetScalerConfig(
492 ISI_Type *base, uint16_t inputWidth, uint16_t inputHeight, uint16_t outputWidth, uint16_t outputHeight);
493
494 /* @} */
495
496 /*!
497 * @name ISI color space conversion
498 * @{
499 */
500
501 /*!
502 * @brief Set the ISI color space conversion configurations.
503 *
504 * This function sets the color space conversion configurations. After setting
505 * the configuration, use the function @ref ISI_EnableColorSpaceConversion to
506 * enable this feature. If the ISI channel is bypassed, then the color space
507 * conversion feature could not be used.
508 *
509 * @param base ISI peripheral base address
510 * @param config Pointer to the configuration structure.
511 */
512 void ISI_SetColorSpaceConversionConfig(ISI_Type *base, const isi_csc_config_t *config);
513
514 /*!
515 * @brief Get the ISI color space conversion default configurations.
516 *
517 * The default value is:
518 * @code
519 config->mode = kISI_CscYUV2RGB;
520 config->A1 = 0.0;
521 config->A2 = 0.0;
522 config->A3 = 0.0;
523 config->B1 = 0.0;
524 config->B2 = 0.0;
525 config->B3 = 0.0;
526 config->C1 = 0.0;
527 config->C2 = 0.0;
528 config->C3 = 0.0;
529 config->D1 = 0;
530 config->D2 = 0;
531 config->D3 = 0;
532 @endcode
533 *
534 * @param config Pointer to the configuration structure.
535 */
536 void ISI_ColorSpaceConversionGetDefaultConfig(isi_csc_config_t *config);
537
538 /*!
539 * @brief Enable or disable the ISI color space conversion.
540 *
541 * If the ISI channel is bypassed, then the color space conversion feature could not
542 * be used even enable using this function.
543 *
544 * @param base ISI peripheral base address
545 * @param enable True to enable, false to disable.
546 * @note The CSC is enabled by default. Disable it if it is not required.
547 */
ISI_EnableColorSpaceConversion(ISI_Type * base,bool enable)548 static inline void ISI_EnableColorSpaceConversion(ISI_Type *base, bool enable)
549 {
550 if (enable)
551 {
552 base->CHNL_IMG_CTRL &= ~ISI_CHNL_IMG_CTRL_CSC_BYP_MASK;
553 }
554 else
555 {
556 base->CHNL_IMG_CTRL |= ISI_CHNL_IMG_CTRL_CSC_BYP_MASK;
557 }
558 }
559
560 /* @} */
561
562 /*!
563 * @name ISI cropping
564 * @{
565 */
566
567 /*!
568 * @brief Set the ISI cropping configurations.
569 *
570 * This function sets the cropping configurations. After setting the configuration,
571 * use the function @ref ISI_EnableCrop to enable the feature. Cropping still
572 * works when the ISI channel is bypassed.
573 *
574 * @param base ISI peripheral base address
575 * @param config Pointer to the configuration structure.
576 * @note The upper left corner and lower right corner should be configured base on
577 * the image resolution output from the scaler.
578 */
579 void ISI_SetCropConfig(ISI_Type *base, const isi_crop_config_t *config);
580
581 /*!
582 * @brief Get the ISI cropping default configurations.
583 *
584 * The default value is:
585 * @code
586 config->upperLeftX = 0U;
587 config->upperLeftY = 0U;
588 config->lowerRightX = 0U;
589 config->lowerRightY = 0U;
590 @endcode
591 *
592 * @param config Pointer to the configuration structure.
593 */
594 void ISI_CropGetDefaultConfig(isi_crop_config_t *config);
595
596 /*!
597 * @brief Enable or disable the ISI cropping.
598 *
599 * If the ISI channel is bypassed, the cropping still works.
600 *
601 * @param base ISI peripheral base address
602 * @param enable True to enable, false to disable.
603 */
ISI_EnableCrop(ISI_Type * base,bool enable)604 static inline void ISI_EnableCrop(ISI_Type *base, bool enable)
605 {
606 if (enable)
607 {
608 base->CHNL_IMG_CTRL |= ISI_CHNL_IMG_CTRL_CROP_EN_MASK;
609 }
610 else
611 {
612 base->CHNL_IMG_CTRL &= ~ISI_CHNL_IMG_CTRL_CROP_EN_MASK;
613 }
614 }
615
616 /* @} */
617
618 /*!
619 * @name ISI alpha
620 * @{
621 */
622
623 /*!
624 * @brief Set the global alpha value.
625 *
626 * @param base ISI peripheral base address
627 * @param alpha The global alpha value.
628 */
ISI_SetGlobalAlpha(ISI_Type * base,uint8_t alpha)629 static inline void ISI_SetGlobalAlpha(ISI_Type *base, uint8_t alpha)
630 {
631 base->CHNL_IMG_CTRL =
632 (base->CHNL_IMG_CTRL & ~ISI_CHNL_IMG_CTRL_GBL_ALPHA_VAL_MASK) | ISI_CHNL_IMG_CTRL_GBL_ALPHA_VAL(alpha);
633 }
634
635 /*!
636 * @brief Enable the global alpha insertion.
637 *
638 * Alpha still works when channel bypassed.
639 *
640 * @param base ISI peripheral base address
641 * @param enable True to enable, false to disable.
642 */
ISI_EnableGlobalAlpha(ISI_Type * base,bool enable)643 static inline void ISI_EnableGlobalAlpha(ISI_Type *base, bool enable)
644 {
645 if (enable)
646 {
647 base->CHNL_IMG_CTRL |= ISI_CHNL_IMG_CTRL_GBL_ALPHA_EN_MASK;
648 }
649 else
650 {
651 base->CHNL_IMG_CTRL &= ~ISI_CHNL_IMG_CTRL_GBL_ALPHA_EN_MASK;
652 }
653 }
654
655 /*!
656 * @brief Set the alpha value for region of interest.
657 *
658 * Set the alpha insertion configuration for specific region of interest.
659 * The function @ref ISI_EnableRegionAlpha could be used to enable the alpha
660 * insertion. Alpha insertion still works when channel bypassed.
661 *
662 * @param base ISI peripheral base address
663 * @param index Index of the region of interest, Could be 0, 1, 2, and 3.
664 * @param config Pointer to the configuration structure.
665 * @note The upper left corner and lower right corner should be configured base on
666 * the image resolution output from the scaler.
667 */
668 void ISI_SetRegionAlphaConfig(ISI_Type *base, uint8_t index, const isi_region_alpha_config_t *config);
669
670 /*!
671 * @brief Get the regional alpha insertion default configurations.
672 *
673 * The default configuration is:
674 * @code
675 config->upperLeftX = 0U;
676 config->upperLeftY = 0U;
677 config->lowerRightX = 0U;
678 config->lowerRightY = 0U;
679 config->alpha = 0U;
680 @endcode
681 *
682 * @param config Pointer to the configuration structure.
683 */
684 void ISI_RegionAlphaGetDefaultConfig(isi_region_alpha_config_t *config);
685
686 /*!
687 * @brief Enable or disable the alpha value insertion for region of interest.
688 *
689 * Alpha insertion still works when channel bypassed.
690 *
691 * @param base ISI peripheral base address
692 * @param index Index of the region of interest, Could be 0, 1, 2, and 3.
693 * @param enable True to enable, false to disable.
694 */
695 void ISI_EnableRegionAlpha(ISI_Type *base, uint8_t index, bool enable);
696
697 /* @} */
698
699 /*!
700 * @name ISI input memory.
701 * @{
702 */
703
704 /*!
705 * @brief Set the input memory configuration.
706 *
707 * @param base ISI peripheral base address
708 * @param config Pointer to the configuration structure.
709 */
710 void ISI_SetInputMemConfig(ISI_Type *base, const isi_input_mem_config_t *config);
711
712 /*!
713 * @brief Get the input memory default configurations.
714 *
715 * The default configuration is:
716 * @code
717 config->adddr = 0U;
718 config->linePitchBytes = 0U;
719 config->framePitchBytes = 0U;
720 config->format = kISI_InputMemBGR8P;
721 @endcode
722 *
723 * @param config Pointer to the configuration structure.
724 */
725 void ISI_InputMemGetDefaultConfig(isi_input_mem_config_t *config);
726
727 /*!
728 * @brief Set the input memory address.
729 *
730 * This function only sets the input memory address, it is used for fast run-time setting.
731 *
732 * @param base ISI peripheral base address
733 * @param addr Input memory address.
734 */
ISI_SetInputMemAddr(ISI_Type * base,uint32_t addr)735 static inline void ISI_SetInputMemAddr(ISI_Type *base, uint32_t addr)
736 {
737 base->CHNL_IN_BUF_ADDR = addr;
738 }
739
740 /*!
741 * @brief Trigger the ISI pipeline to read the input memory.
742 *
743 * @param base ISI peripheral base address
744 */
745 void ISI_TriggerInputMemRead(ISI_Type *base);
746
747 /* @} */
748
749 /*!
750 * @name ISI misc control.
751 * @{
752 */
753
754 /*!
755 * @brief Set the ISI channel flipping mode.
756 *
757 * @param base ISI peripheral base address
758 * @param mode Flipping mode.
759 */
ISI_SetFlipMode(ISI_Type * base,isi_flip_mode_t mode)760 static inline void ISI_SetFlipMode(ISI_Type *base, isi_flip_mode_t mode)
761 {
762 base->CHNL_IMG_CTRL =
763 (base->CHNL_IMG_CTRL & ~(ISI_CHNL_IMG_CTRL_VFLIP_EN_MASK | ISI_CHNL_IMG_CTRL_HFLIP_EN_MASK)) | (uint32_t)mode;
764 }
765
766 /*!
767 * @brief Set the ISI output buffer address.
768 *
769 * This function sets the output buffer address and trigger the ISI to shadow the
770 * address, it is used for fast run-time setting.
771 *
772 * @param base ISI peripheral base address
773 * @param index Index of output buffer, could be 0 and 1.
774 * @param addrY RGB or Luma (Y) output buffer address.
775 * @param addrU Chroma (U/Cb/UV/CbCr) output buffer address.
776 * @param addrV Chroma (V/Cr) output buffer address.
777 */
778 void ISI_SetOutputBufferAddr(ISI_Type *base, uint8_t index, uint32_t addrY, uint32_t addrU, uint32_t addrV);
779
780 /*!
781 * @brief Start the ISI channel.
782 *
783 * Start the ISI channel to work, this function should be called after all channel
784 * configuration finished.
785 *
786 * @param base ISI peripheral base address
787 */
ISI_Start(ISI_Type * base)788 static inline void ISI_Start(ISI_Type *base)
789 {
790 base->CHNL_CTRL |= ISI_CHNL_CTRL_CHNL_EN_MASK;
791 }
792
793 /*!
794 * @brief Stop the ISI channel.
795 *
796 * @param base ISI peripheral base address
797 */
ISI_Stop(ISI_Type * base)798 static inline void ISI_Stop(ISI_Type *base)
799 {
800 base->CHNL_CTRL &= ~ISI_CHNL_CTRL_CHNL_EN_MASK;
801 }
802
803 /* @} */
804
805 #if defined(__cplusplus)
806 }
807 #endif /* __cplusplus */
808
809 /* @} */
810
811 #endif /*_FSL_ISI_H_*/
812