aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/components/video/fsl_video_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/components/video/fsl_video_common.h')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/components/video/fsl_video_common.h276
1 files changed, 276 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/components/video/fsl_video_common.h b/lib/chibios-contrib/ext/mcux-sdk/components/video/fsl_video_common.h
new file mode 100644
index 000000000..a2129fadd
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/components/video/fsl_video_common.h
@@ -0,0 +1,276 @@
1/*
2 * Copyright 2017, 2020 NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _FSL_VIDEO_COMMON_H_
10#define _FSL_VIDEO_COMMON_H_
11
12#include "fsl_common.h"
13
14/*
15 * Change log:
16 *
17 * 1.0.2
18 * - Fixed MISRA-C 2012 issues.
19 *
20 * 1.0.1
21 * - Update the VIDEO_DelayMs for bare metal.
22 *
23 * 1.0.0
24 * - Initial version
25 */
26
27/*******************************************************************************
28 * Definitions
29 ******************************************************************************/
30
31/*! @brief Pixel format FOURCC. */
32#define FSL_VIDEO_FOURCC(a, b, c, d) \
33 ((uint32_t)(a) | ((uint32_t)(b) << 8U) | ((uint32_t)(c) << 16U) | ((uint32_t)(d) << 24U))
34
35/*! @brief Macro to define resolution. */
36#define FSL_VIDEO_RESOLUTION(width, height) ((uint32_t)(width) | ((uint32_t)(height) << 16U))
37
38#define FSL_VIDEO_EXTRACT_WIDTH(resolution) ((uint16_t)((resolution)&0xFFFFU))
39#define FSL_VIDEO_EXTRACT_HEIGHT(resolution) ((uint16_t)((resolution) >> 16U))
40
41/*! @brief Pixel format definition. */
42typedef enum _video_pixel_format
43{
44 /* RGB */
45 kVIDEO_PixelFormatXRGB8888 = FSL_VIDEO_FOURCC('X', 'R', '2', '4'), /*!< 32-bit XRGB8888. */
46 kVIDEO_PixelFormatRGBX8888 = FSL_VIDEO_FOURCC('R', 'X', '2', '4'), /*!< 32-bit RGBX8888. */
47 kVIDEO_PixelFormatXBGR8888 = FSL_VIDEO_FOURCC('X', 'B', '2', '4'), /*!< 32-bit XBGR8888. */
48 kVIDEO_PixelFormatBGRX8888 = FSL_VIDEO_FOURCC('B', 'X', '2', '4'), /*!< 32-bit BGRX8888. */
49
50 kVIDEO_PixelFormatRGB888 = FSL_VIDEO_FOURCC('R', 'G', '2', '4'), /*!< 24-bit RGB888. */
51 kVIDEO_PixelFormatBGR888 = FSL_VIDEO_FOURCC('B', 'G', '2', '4'), /*!< 24-bit BGR888. */
52
53 kVIDEO_PixelFormatRGB565 = FSL_VIDEO_FOURCC('R', 'G', '1', '6'), /*!< 16-bit RGB565. */
54 kVIDEO_PixelFormatBGR565 = FSL_VIDEO_FOURCC('B', 'G', '1', '6'), /*!< 16-bit BGR565. */
55
56 kVIDEO_PixelFormatXRGB1555 = FSL_VIDEO_FOURCC('X', 'R', '1', '5'), /*!< 16-bit XRGB1555. */
57 kVIDEO_PixelFormatRGBX5551 = FSL_VIDEO_FOURCC('R', 'X', '1', '5'), /*!< 16-bit RGBX5551. */
58 kVIDEO_PixelFormatXBGR1555 = FSL_VIDEO_FOURCC('X', 'B', '1', '5'), /*!< 16-bit XBGR1555. */
59 kVIDEO_PixelFormatBGRX5551 = FSL_VIDEO_FOURCC('B', 'X', '1', '5'), /*!< 16-bit BGRX5551. */
60
61 kVIDEO_PixelFormatXRGB4444 = FSL_VIDEO_FOURCC('X', 'R', '1', '2'), /*!< 16-bit XRGB4444. */
62 kVIDEO_PixelFormatRGBX4444 = FSL_VIDEO_FOURCC('R', 'X', '1', '2'), /*!< 16-bit RGBX4444. */
63 kVIDEO_PixelFormatXBGR4444 = FSL_VIDEO_FOURCC('X', 'B', '1', '2'), /*!< 16-bit XBGR4444. */
64 kVIDEO_PixelFormatBGRX4444 = FSL_VIDEO_FOURCC('B', 'X', '1', '2'), /*!< 16-bit BGRX4444. */
65
66 /* YUV. */
67 kVIDEO_PixelFormatYUYV = FSL_VIDEO_FOURCC('Y', 'U', 'Y', 'V'), /*!< YUV422, Y-U-Y-V. */
68 kVIDEO_PixelFormatYVYU = FSL_VIDEO_FOURCC('Y', 'V', 'Y', 'U'), /*!< YUV422, Y-V-Y-U. */
69 kVIDEO_PixelFormatUYVY = FSL_VIDEO_FOURCC('U', 'Y', 'V', 'Y'), /*!< YUV422, U-Y-V-Y. */
70 kVIDEO_PixelFormatVYUY = FSL_VIDEO_FOURCC('V', 'Y', 'U', 'Y'), /*!< YUV422, V-Y-U-Y. */
71
72 kVIDEO_PixelFormatXYUV = FSL_VIDEO_FOURCC('X', 'Y', 'U', 'V'), /*!< YUV444, X-Y-U-V. */
73 kVIDEO_PixelFormatXYVU = FSL_VIDEO_FOURCC('X', 'Y', 'V', 'U'), /*!< YUV444, X-Y-V-U. */
74} video_pixel_format_t;
75
76/*! @brief Resolution definition. */
77typedef enum _video_resolution
78{
79 kVIDEO_ResolutionVGA = FSL_VIDEO_RESOLUTION(640, 480), /*!< VGA, 640 * 480 */
80 kVIDEO_ResolutionQVGA = FSL_VIDEO_RESOLUTION(320, 240), /*!< QVGA, 320 * 240 */
81 kVIDEO_ResolutionQQVGA = FSL_VIDEO_RESOLUTION(160, 120), /*!< QQVGA, 160 * 120 */
82 kVIDEO_ResolutionCIF = FSL_VIDEO_RESOLUTION(352, 288), /*!< CIF, 352 * 288 */
83 kVIDEO_ResolutionQCIF = FSL_VIDEO_RESOLUTION(176, 144), /*!< QCIF, 176 * 144 */
84 kVIDEO_ResolutionQQCIF = FSL_VIDEO_RESOLUTION(88, 72), /*!< QQCIF, 88 * 72 */
85 kVIDEO_Resolution720P = FSL_VIDEO_RESOLUTION(1280, 720), /*!< 720P, 1280 * 720 */
86 kVIDEO_Resolution1080P = FSL_VIDEO_RESOLUTION(1920, 1080), /*!< 1080P, 1920 * 1280*/
87 kVIDEO_ResolutionWXGA = FSL_VIDEO_RESOLUTION(1280, 800), /*!< WXGA, 1280 * 800 */
88} video_resolution_t;
89
90/*!
91 * @brief Ring buffer structure.
92 *
93 * There is one empty room reserved in the ring buffer, used to distinguish
94 * whether the ring buffer is full or empty. When rear equals front, it is empty;
95 * when rear+1 equals front, it is full.
96 */
97typedef struct
98{
99 volatile uint32_t rear; /*!< Pointer to save the incoming item. */
100 volatile uint32_t front; /*!< Pointer to read out the item. */
101 void *volatile *buf; /*!< Memory to the ring buffer. */
102 uint32_t size; /*!< Ring buffer total size. */
103} video_ringbuf_t;
104
105/*!
106 * @brief Memory pool structure.
107 */
108typedef struct
109{
110 void *volatile pool; /*!< Pointer to the pool. */
111 volatile uint32_t cnt; /*!< Count of memory blocks in the pool. */
112} video_mempool_t;
113
114/*******************************************************************************
115 * API
116 ******************************************************************************/
117
118#if defined(__cplusplus)
119extern "C" {
120#endif
121
122/*!
123 * @name Common
124 * @{
125 */
126
127/*!
128 * @brief Check the pixel format is YUV or not.
129 *
130 * @param format Pixel format.
131 */
132bool VIDEO_IsYUV(video_pixel_format_t format);
133
134/*!
135 * @brief Delay the specific time.
136 *
137 * @param ms How many milli-second to delay.
138 */
139void VIDEO_DelayMs(uint32_t ms);
140
141/*!
142 * @brief Get the pixel size in bits.
143 *
144 * @param pixelFormat The pixel format.
145 * @return Bits per pixel.
146 */
147uint8_t VIDEO_GetPixelSizeBits(video_pixel_format_t pixelFormat);
148
149/* @} */
150
151/*!
152 * @name Ring buffer.
153 * @{
154 */
155
156/*!
157 * @brief Initializes ring buffer.
158 *
159 * @param ringbuf Pointer to the ring buffer handle.
160 * @param buf Memory to save the items.
161 * @param size Size of the @p buf.
162 * @return Returns @ref kStatus_Success if initialize success, otherwise returns
163 * error code.
164 */
165status_t VIDEO_RINGBUF_Init(video_ringbuf_t *ringbuf, void **buf, uint32_t size);
166
167/*!
168 * @brief Get one item from the ring buffer.
169 *
170 * @param ringbuf Pointer to the ring buffer handle.
171 * @param item Memory to save the item.
172 * @return Returns @ref kStatus_Success if get success, otherwise returns
173 * error code.
174 */
175status_t VIDEO_RINGBUF_Get(video_ringbuf_t *ringbuf, void **item);
176
177/*!
178 * @brief Put one item to the ring buffer.
179 *
180 * @param ringbuf Pointer to the ring buffer handle.
181 * @param item The new item to save.
182 * @return Returns @ref kStatus_Success if put success, otherwise returns
183 * error code.
184 */
185status_t VIDEO_RINGBUF_Put(video_ringbuf_t *ringbuf, void *item);
186
187/*!
188 * @brief Get current count of items in the ring buffer.
189 *
190 * @param ringbuf Pointer to the ring buffer handle.
191 * @return Returns the item count.
192 */
193uint32_t VIDEO_RINGBUF_GetLength(video_ringbuf_t *ringbuf);
194
195/*!
196 * @brief Check whether the ring buffer is empty.
197 *
198 * @param ringbuf Pointer to the ring buffer handle.
199 * @return Returns true if the ring buffer is empty, otherwise returns false.
200 */
201bool VIDEO_RINGBUF_IsEmpty(video_ringbuf_t *ringbuf);
202
203/*!
204 * @brief Check whether the ring buffer is full.
205 *
206 * @param ringbuf Pointer to the ring buffer handle.
207 * @return Returns true if the ring buffer is full, otherwise returns false.
208 */
209bool VIDEO_RINGBUF_IsFull(video_ringbuf_t *ringbuf);
210/* @} */
211
212/*!
213 * @name Memory Pool
214 *
215 * User can put memory block to the pool, or get memory block from the pool.
216 * There is no count limitation to put memory block in to the pool. The memory
217 * content in the pool might be modified.
218 *
219 * The memory block should be 4-byte aligned, and the dividable by 4-byte.
220 *
221 * @{
222 */
223
224/*!
225 * @brief Initializes memory pool.
226 *
227 * Initializes memory pool. Initial memory blocks in the memory pool is optional.
228 * If initial blocks are used, user should specify the initial block size and count.
229 *
230 * @param mempool Pointer to the memory pool handle.
231 * @param initMem Initial memory blocks to saved in the pool.
232 * @param size Every memory block's size (bytes) in the @p initMem.
233 * @param count Number of memory blocks @p initMem.
234 * @return Returns @ref kStatus_Success if initialize success, otherwise returns
235 * error code.
236 */
237status_t VIDEO_MEMPOOL_Init(video_mempool_t *mempool, void *initMem, uint32_t size, uint32_t count);
238
239/*!
240 * @brief Create an empty memory pool.
241 *
242 * @param mempool Pointer to the memory pool handle.
243 */
244void VIDEO_MEMPOOL_InitEmpty(video_mempool_t *mempool);
245
246/*!
247 * @brief Put memory block in the pool.
248 *
249 * @param mempool Pointer to the memory pool handle.
250 * @param mem Pointer to the memory block.
251 */
252void VIDEO_MEMPOOL_Put(video_mempool_t *mempool, void *mem);
253
254/*!
255 * @brief Get memory block in the pool.
256 *
257 * @param mempool Pointer to the memory pool handle.
258 * @return The memory block get from pool. If the pool is empty, returns NULL.
259 */
260void *VIDEO_MEMPOOL_Get(video_mempool_t *mempool);
261
262/*!
263 * @brief How many memory blocks in the pool.
264 *
265 * @param mempool Pointer to the memory pool handle.
266 * @return The memory block count in the pool
267 */
268uint32_t VIDEO_MEMPOOL_GetCount(video_mempool_t *mempool);
269
270/* @} */
271
272#if defined(__cplusplus)
273}
274#endif
275
276#endif /* _FSL_VIDEO_COMMON_H_ */