Arm-2D  
2D Image Processing Library for Cortex-M Processors
arm_2d.h
1/*
2 * Copyright (C) 2022 Arm Limited or its affiliates. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/* ----------------------------------------------------------------------
20 * Project: Arm-2D Library
21 * Title: #include "arm_2d.h"
22 * Description: Public header file to contain the all avaialble Arm-2D
23 * interface header files
24 *
25 * $Date: 11. Sept 2024
26 * $Revision: V.1.2.1-dev
27 *
28 * Target Processor: Cortex-M cores
29 * -------------------------------------------------------------------- */
30
31#ifndef __ARM_2D_H__
32#define __ARM_2D_H__
33
34/*============================ INCLUDES ======================================*/
35#include "arm_2d_types.h"
36#include "arm_2d_op.h"
37#include "arm_2d_tile.h"
38#include "arm_2d_draw.h"
39#include "arm_2d_conversion.h"
40#include "arm_2d_alpha_blending.h"
41#include "arm_2d_transform.h"
42#include "arm_2d_filter.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/* suppress some warnings for user applications when using arm-2d.
49 */
50#if defined(__clang__)
51# pragma clang diagnostic push
52# pragma clang diagnostic ignored "-Wunknown-warning-option"
53# pragma clang diagnostic ignored "-Wreserved-identifier"
54# pragma clang diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
55# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
56# pragma clang diagnostic ignored "-Wgnu-statement-expression"
57# pragma clang diagnostic ignored "-Wextra-semi-stmt"
58# pragma clang diagnostic ignored "-Wcompound-token-split-by-macro"
59# pragma clang diagnostic ignored "-Winitializer-overrides"
60# pragma clang diagnostic ignored "-Wgcc-compat"
61# pragma clang diagnostic ignored "-Wgnu-empty-initializer"
62# pragma clang diagnostic ignored "-Wshadow"
63# pragma clang diagnostic ignored "-Wconditional-uninitialized"
64# pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
65# pragma clang diagnostic ignored "-Wc23-extensions"
66# pragma clang diagnostic ignored "-Wunused-value"
67# pragma clang diagnostic ignored "-Wbad-function-cast"
68# pragma clang diagnostic ignored "-Wundef"
69#elif __IS_COMPILER_GCC__
70# pragma GCC diagnostic ignored "-Wpedantic"
71# pragma GCC diagnostic ignored "-Wmissing-braces"
72# pragma GCC diagnostic ignored "-Wunused-value"
73# pragma GCC diagnostic ignored "-Wnonnull-compare"
74# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
75#elif defined(__IS_COMPILER_ARM_COMPILER_5__)
76# pragma diag_suppress 1296,174,64,177,1
77#endif
78
79/*!
80 * \addtogroup gKernel 1 Kernel
81 * @{
82 */
83
84/*============================ MACROS ========================================*/
85
86/* arm-2d version */
87#define ARM_2D_VERSION_MAJOR 1 //!< Major version
88#define ARM_2D_VERSION_MINOR 2 //!< Minor version
89#define ARM_2D_VERSION_PATCH 1 //!< Patch number
90#define ARM_2D_VERSION_STR "dev" //!< tag
91
92/*!
93 * \brief arm-2d version number in decimal
94 *
95 */
96#define ARM_2D_VERSION ( ARM_2D_VERSION_MAJOR * 10000ul \
97 + ARM_2D_VERSION_MINOR * 100ul \
98 + ARM_2D_VERSION_PATCH)
99
100/*============================ MACROFIED FUNCTIONS ===========================*/
101
102#define ARM_2D_OP_INIT(__OP) \
103 arm_2d_op_init((arm_2d_op_core_t *)&(__OP), sizeof(__OP))
104#define ARM_2D_OP_DEPOSE(__OP) \
105 arm_2d_op_depose((arm_2d_op_core_t *)&(__OP), sizeof(__OP))
106/*!
107 * \brief wait asynchronous operation complete
108 * \param[in] ... [OPTIONAL] the address of the target OP (NULL or ignore means using the default OP)
109 * \retval true sync up with operation
110 * \retval false operation is busy
111 */
112#define ARM_2D_OP_WAIT_ASYNC(...) \
113 arm_2d_op_wait_async((arm_2d_op_core_t *)(NULL,##__VA_ARGS__))
114
115/*============================ TYPES =========================================*/
116
117/*!
118 * \brief a type for arm-2d runtime configuration
119 *
120 */
121typedef struct {
122 /*! if the target region is out of the target tile, return arm_fsm_rt_cpl */
124
125 /*! indicate that there is a dedicated thread to run arm_2d_task() in RTOS env */
127 uint8_t : 6;
129
130/*!
131 * \brief a type for arm-2d version
132 *
133 */
134typedef struct {
135 uint8_t Major; //!< major version
136 uint8_t Minor; //!< minor version
137 uint8_t Patch; //!< patch number
138 uint8_t : 8;
140
141/*============================ GLOBAL VARIABLES ==============================*/
142
143/*!
144 * \brief arm-2d runtime feature configuration
145 *
146 */
147extern
149
150/*!
151 * \brief arm-2d version
152 *
153 */
154extern
156
157/*============================ PROTOTYPES ====================================*/
158
159/*!
160 * \brief initialise arm-2d
161 */
162extern
163void arm_2d_init(void);
164
165/*!
166 * \brief set the default frame buffer
167 * \param ptFrameBuffer the new frame buffer,
168 * \note Passing NULL means using no default framebuffer
169 * \return arm_2d_tile_t* the address of the old frame buffer
170 */
171extern
173 const arm_2d_tile_t *ptFrameBuffer);
174
175/*!
176 * \brief get the default frame buffer
177 * \return arm_2d_tile_t* the address of the default frame buffer
178 */
179extern
181
182/*!
183 * \brief attach a user param (which could be a pointer) to specified OP
184 * \param ptOP the address of the target OP (NULL means using the default OP)
185 * \param pUserParam a user parameter (it can be used as a pointer)
186 */
187extern
188void arm_2d_set_user_param(arm_2d_op_core_t *ptOP, uintptr_t pUserParam);
189
190
191/*!
192 * \brief initialize an given opcode
193 * \param ptOP the address of the target OP
194 * \param tSize the size of the opcode object
195 * \return arm_2d_op_core_t * the address of the OP
196 */
197extern
199
200
201/*!
202 * \brief depose an given opcode
203 * \param ptOP the address of the target OP
204 * \param tSize the size of the opcode object
205 * \return arm_2d_op_core_t * the address of the OP
206 */
207extern
209
210/*!
211 * \brief attach a semaphore (which could be a pointer) to specified OP
212 * \param ptOP the address of the target OP (NULL means using the default OP)
213 * \param pSemaphore a pointer points to a RTOS semaphore
214 * \note this API only available when __ARM_2D_HAS_ASYNC__ is 1
215 */
216extern
217void arm_2d_op_attach_semaphore(arm_2d_op_core_t *ptOP, uintptr_t pSemaphore);
218
219/*!
220 * \brief get the attached semaphore (which could be a pointer) from specified OP
221 * \param ptOP the address of the target OP (NULL means using the default OP)
222 * \return uintptr_t the semaphore
223 * \note this API only available when __ARM_2D_HAS_ASYNC__ is 1
224 */
225extern
227
228/*!
229 * \brief wait asynchronous operation complete
230 * \param[in] ptOP the address of the target OP (NULL means using the default OP)
231 * \retval true sync up with operation
232 * \retval false operation is busy
233 */
234extern
236
237/*!
238 \brief get the status of a specified OP,
239 \details usually, it is used after calling arm_2d_op_wait_async().
240 E.g.
241 \code
242 //! wait for previous operation complete
243 do {
244 arm_2d_op_wait_async();
245 arm_2d_op_status_t tStatus = arm_2d_get_op_status();
246 if (tStatus.bIOError) {
247 //! error detected
248 ...
249 } else if (tStatus.bOpCpl) {
250 break;
251 }
252 } while(true);
253 \endcode
254 \param ptOP the address of the target OP (NULL means using the default OP)
255 \return arm_2d_op_status_t the operation status
256 */
257extern
259
260/*!
261 * \brief arm-2d pixel pipeline task entery
262 * \note This function is *TRHEAD-SAFE*
263 * \param ptTask the address of an arm-2d task control block
264 * \retval arm_fsm_rt_cpl The sub-task FIFO is empty, the caller can wait for a
265 * semaphore set by arm_2d_notif_sub_task_fifo_task_arrive()
266 * \retval arm_fsm_rt_on_going The arm_2d_task yields
267 * \retval arm_fsm_rt_async You shouldn't see this value
268 * \retval arm_fsm_rt_wait_for_obj hardware accelerator wants to sync-up with applications.
269 * \retval (<0) Serious error is detected.
270 */
271extern
273
274/*!
275 * \brief allocate a memory block with specified memory type
276 *
277 * \param wSize the minimal size
278 * \param nAlign the alignment
279 * \param tType the type of memory
280 * \return void* the memory address
281 */
282extern
283void *__arm_2d_allocate_scratch_memory( uint32_t wSize,
284 uint_fast8_t nAlign,
285 arm_2d_mem_type_t tType);
286/*!
287 * \brief free a specified memory block
288 *
289 * \param tType the type of memory
290 * \param pBuff the address of the memory
291 */
292extern
294 void *pBuff);
295
296/*!
297 * \brief allocate a scratch memory and initialize arm_2d_scratch_mem_t object
298 *
299 * \param[out] ptMemory the address of an arm_2d_scratch_mem_t object to hold
300 * the result
301 * \param[in] hwItemSize the size of each item
302 * \param[in] hwItemCount the number of items
303 * \param[in] hwAlignment the alignment requirement
304 * \param[in] tType the type of memory
305 * \return arm_2d_scratch_mem_t* the initialized the arm_2d_scratch_mem_t object
306 * address. NULL means failed to allocate scratch memory
307 */
308extern
309ARM_NONNULL(1)
311 uint16_t hwItemSize,
312 uint16_t hwItemCount,
313 uint16_t hwAlignment,
314 arm_2d_mem_type_t tType);
315
316
317/*!
318 * \brief free a scratch memory with a given scratch memory descriptor object
319 *
320 * \param[in] the target scratch memory descriptor
321 * \return arm_2d_scratch_mem_t * the de-initialized the scratch memory descriptor
322 */
323extern
324ARM_NONNULL(1)
326
327/*! @} */
328
329/*! \note delibrately comment out */
330//#if defined(__clang__)
331//# pragma clang diagnostic pop
332//#endif
333
334#ifdef __cplusplus
335}
336#endif
337
338
339#endif