2D Image Processing Library for Cortex-M Processors
All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
arm_2d_types.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: cmsis_nn_typs.h
22 * Description: Public header file to contain the Arm-2D structs
23 *
24 * $Date: 09. Aug 2022
25 * $Revision: V.1.0.4
26 *
27 * Target Processor: Cortex-M cores
28 * -------------------------------------------------------------------- */
29
30
31#ifndef __ARM_2D_TYPES_H__
32#define __ARM_2D_TYPES_H__
33
34/*============================ INCLUDES ======================================*/
35#include <string.h>
36#include <stdint.h>
37#include <stdbool.h>
38#include <assert.h>
39
40#include "arm_2d_features.h"
41#include "arm_2d_utils.h"
42#include "__arm_2d_math.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48#if defined(__clang__)
49# pragma clang diagnostic push
50# pragma clang diagnostic ignored "-Wunknown-warning-option"
51# pragma clang diagnostic ignored "-Wreserved-identifier"
52# pragma clang diagnostic ignored "-Wmissing-declarations"
53# pragma clang diagnostic ignored "-Wpadded"
54# pragma clang diagnostic ignored "-Wc11-extensions"
55#elif __IS_COMPILER_ARM_COMPILER_5__
56# pragma diag_suppress 64
57#elif __IS_COMPILER_GCC__
58# pragma GCC diagnostic push
59# pragma GCC diagnostic ignored "-Wmissing-declarations"
60# pragma GCC diagnostic ignored "-Wpadded"
61#endif
62
63/*!
64 * \addtogroup gKernel 1 Kernel
65 * @{
66 */
67
68/*============================ MACROS ========================================*/
69/*============================ MACROFIED FUNCTIONS ===========================*/
70/*============================ TYPES =========================================*/
71
72
73/*----------------------------------------------------------------------------*
74 * Infrastructure *
75 *----------------------------------------------------------------------------*/
76
77/*!
78 * \brief finite-state-machine status return (Compatible with arm_status, minimal integer: int8_t)
79 *
80 */
81typedef enum {
82 arm_fsm_rt_err = -1, //!< fsm error
83 arm_fsm_rt_cpl = 0, //!< fsm complete
84 arm_fsm_rt_on_going = 1, //!< fsm on-going
85 arm_fsm_rt_wait_for_obj = 2, //!< fsm wait for IPC object
86 arm_fsm_rt_async = 3, //!< fsm work asynchronously, please check it later.
87 arm_fsm_rt_wait_for_res = 4, //!< wait for resource
89
90/*!
91 * \brief the error code for arm-2d (minimal integer: int8_t)
92 *
93 */
94typedef enum {
95 ARM_2D_ERR_UNSUPPORTED_COLOUR = -11, //!< the specified colour is not supported
96 ARM_2D_ERR_BUSY = -10, //!< service is busy
97 ARM_2D_ERR_INSUFFICIENT_RESOURCE = -9, //!< insufficient resource
98 ARM_2D_ERR_IO_BUSY = -8, //!< HW accelerator is busy
99 ARM_2D_ERR_IO_ERROR = -7, //!< Generic HW error
100 ARM_2D_ERR_MISSING_PARAM = -6, //!< missing mandatory parameter
101 ARM_2D_ERR_INVALID_OP = -5, //!< unsupported / invalid operation
102 ARM_2D_ERR_NOT_SUPPORT = -4, //!< feature/service/operation is not supported
103 ARM_2D_ERR_OUT_OF_REGION = -3, //!< the operation is out of target area
104 ARM_2D_ERR_INVALID_PARAM = -2, //!< invalid parameter
105 ARM_2D_ERR_UNKNOWN = -1, //!< generic or unknown errors
106 ARM_2D_ERR_NONE = 0, //!< no error
108
109/*!
110 * \brief comparison result
111 *
112 */
113typedef enum {
114 ARM_2D_CMP_SMALLER = -1, //!< the target is smaller than the reference
115 ARM_2D_CMP_EQUALS = 0, //!< the target is equal to the reference
116 ARM_2D_CMP_LARGER = 1, //!< the target is larger than the reference
118
119/*----------------------------------------------------------------------------*
120 * Colour definitions *
121 *----------------------------------------------------------------------------*/
122
123/*!
124 * \brief the colour type for gray8 (8bit gray scale)
125 *
126 */
127typedef union arm_2d_color_gray8_t {
128 uint8_t tValue;
130
131/*!
132 * \brief the colour type for rgb565
133 *
134 */
136 uint16_t tValue;
137 struct {
138 uint16_t u5B : 5;
139 uint16_t u6G : 6;
140 uint16_t u5R : 5;
141 };
143
144/*!
145 * \brief the colour type for brga8888
146 *
147 * \details In most cases four equal-sized pieces of adjacent memory are used,
148 * one for each channel, and a 0 in a channel indicates black color or
149 * transparent alpha, while all-1 bits indicates white or fully opaque
150 * alpha. By far the most common format is to store 8 bits (one byte)
151 * for each channel, which is 32 bits for each pixel.
152 *
153 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
154 */
156 uint32_t tValue;
157 struct {
158 uint32_t u8B : 8;
159 uint32_t u8G : 8;
160 uint32_t u8R : 8;
161 uint32_t u8A : 8;
162 };
164
165/*!
166 * \brief the colour type for rgb888 (compliant with ccca888 and bgra8888)
167 *
168 * \details In most cases four equal-sized pieces of adjacent memory are used,
169 * one for each channel, and a 0 in a channel indicates black color or
170 * transparent alpha, while all-1 bits indicates white or fully opaque
171 * alpha. By far the most common format is to store 8 bits (one byte)
172 * for each channel, which is 32 bits for each pixel.
173 *
174 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
175 */
177 uint32_t tValue;
178 struct {
179 uint32_t u8B : 8;
180 uint32_t u8G : 8;
181 uint32_t u8R : 8;
182 uint32_t : 8;
183 };
185
186/*!
187 * \brief the colour type for any 32bit colour formats which has an alpha channel on its 3rd byte.
188 *
189 * \details In most cases four equal-sized pieces of adjacent memory are used,
190 * one for each channel, and a 0 in a channel indicates black color or
191 * transparent alpha, while all-1 bits indicates white or fully opaque
192 * alpha. By far the most common format is to store 8 bits (one byte)
193 * for each channel, which is 32 bits for each pixel.
194 *
195 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
196 */
198 uint32_t tValue;
199 struct {
200 uint8_t u8C[3];
201 uint8_t u8A;
202 };
204
205/*!
206 * \brief the colour type for any 32bit colour formats which has an alpha channel on its first byte.
207 *
208 * \details In most cases four equal-sized pieces of adjacent memory are used,
209 * one for each channel, and a 0 in a channel indicates black color or
210 * transparent alpha, while all-1 bits indicates white or fully opaque
211 * alpha. By far the most common format is to store 8 bits (one byte)
212 * for each channel, which is 32 bits for each pixel.
213 *
214 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
215 */
217 uint32_t tValue;
218 struct {
219 uint8_t u8A;
220 uint8_t u8C[3];
221 };
223
224/*!
225 * \brief the colour type for any 32bit colour formats which has an unused-alpha channel on its 3rd byte.
226 *
227 * \details In most cases four equal-sized pieces of adjacent memory are used,
228 * one for each channel, and a 0 in a channel indicates black color or
229 * transparent alpha, while all-1 bits indicates white or fully opaque
230 * alpha. By far the most common format is to store 8 bits (one byte)
231 * for each channel, which is 32 bits for each pixel.
232 *
233 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
234 */
236 uint32_t tValue;
237 struct {
238 uint8_t u8C[3];
239 uint8_t : 8;
240 };
242
243/*!
244 * \brief the colour type for any 32bit colour formats which has an unused-alpha channel on its first byte.
245 *
246 * \details In most cases four equal-sized pieces of adjacent memory are used,
247 * one for each channel, and a 0 in a channel indicates black color or
248 * transparent alpha, while all-1 bits indicates white or fully opaque
249 * alpha. By far the most common format is to store 8 bits (one byte)
250 * for each channel, which is 32 bits for each pixel.
251 *
252 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
253 */
255 uint32_t tValue;
256 struct {
257 uint8_t : 8;
258 uint8_t u8C[3];
259 };
261
262/*!
263 * \brief enumerations for colour attributes
264 */
265enum {
266 ARM_2D_COLOUR_SZ_1BIT = 0, //!< 1 bit:black and white
267 ARM_2D_COLOUR_SZ_2BIT = 1, //!< 4 colours or 4 gray-levels
268 ARM_2D_COLOUR_SZ_4BIT = 2, //!< 16 colours or 16 gray-levels
269 ARM_2D_COLOUR_SZ_8BIT = 3, //!< 256 colours
270 ARM_2D_COLOUR_SZ_16BIT = 4, //!< 16bits
271 ARM_2D_COLOUR_SZ_32BIT = 5, //!< true colour
272
273 ARM_2D_COLOUR_SZ_1BIT_msk = ARM_2D_COLOUR_SZ_1BIT << 1,
274 ARM_2D_COLOUR_SZ_2BIT_msk = ARM_2D_COLOUR_SZ_2BIT << 1,
275 ARM_2D_COLOUR_SZ_4BIT_msk = ARM_2D_COLOUR_SZ_4BIT << 1,
276 ARM_2D_COLOUR_SZ_8BIT_msk = ARM_2D_COLOUR_SZ_8BIT << 1,
277 ARM_2D_COLOUR_SZ_16BIT_msk = ARM_2D_COLOUR_SZ_16BIT<< 1,
278 ARM_2D_COLOUR_SZ_32BIT_msk = ARM_2D_COLOUR_SZ_32BIT<< 1,
279 ARM_2D_COLOUR_SZ_msk = (0x07 << 1),
280
281 ARM_2D_COLOUR_LITTLE_ENDIAN = 0,
282 ARM_2D_COLOUR_BIG_ENDIAN = 1,
283
284 ARM_2D_COLOUR_LITTLE_ENDIAN_msk = ARM_2D_COLOUR_LITTLE_ENDIAN << 4,
285 ARM_2D_COLOUR_BIG_ENDIAN_msk = ARM_2D_COLOUR_BIG_ENDIAN << 4,
286
287 ARM_2D_COLOUR_NO_ALPHA = 0,
288 ARM_2D_COLOUR_HAS_ALPHA = 1,
289
290 ARM_2D_COLOUR_NO_ALPHA_msk = ARM_2D_COLOUR_NO_ALPHA << 0,
291 ARM_2D_COLOUR_HAS_ALPHA_msk = ARM_2D_COLOUR_HAS_ALPHA << 0,
292
293 ARM_2D_COLOUR_VARIANT_pos = 5,
294 ARM_2D_COLOUR_VARIANT_msk = 0x07 << ARM_2D_COLOUR_VARIANT_pos,
295};
296
297/* macros for colour attributes */
298#define ARM_2D_M_COLOUR_SZ_1BIT 0 //!< 1 bit:black and white
299#define ARM_2D_M_COLOUR_SZ_2BIT 1 //!< 4 colours or 4 gray-levels
300#define ARM_2D_M_COLOUR_SZ_4BIT 2 //!< 16 colours or 16 gray-levels
301#define ARM_2D_M_COLOUR_SZ_8BIT 3 //!< 256 colours
302#define ARM_2D_M_COLOUR_SZ_16BIT 4 //!< 16bits
303#define ARM_2D_M_COLOUR_SZ_32BIT 5 //!< true colour
304
305#define ARM_2D_M_COLOUR_SZ_1BIT_msk (ARM_2D_M_COLOUR_SZ_1BIT << 1)
306#define ARM_2D_M_COLOUR_SZ_2BIT_msk (ARM_2D_M_COLOUR_SZ_2BIT << 1)
307#define ARM_2D_M_COLOUR_SZ_4BIT_msk (ARM_2D_M_COLOUR_SZ_4BIT << 1)
308#define ARM_2D_M_COLOUR_SZ_8BIT_msk (ARM_2D_M_COLOUR_SZ_8BIT << 1)
309#define ARM_2D_M_COLOUR_SZ_16BIT_msk (ARM_2D_M_COLOUR_SZ_16BIT<< 1)
310#define ARM_2D_M_COLOUR_SZ_32BIT_msk (ARM_2D_M_COLOUR_SZ_32BIT<< 1)
311#define ARM_2D_M_COLOUR_SZ_msk (0x07 << 1),
312
313#define ARM_2D_M_COLOUR_LITTLE_ENDIAN 0
314#define ARM_2D_M_COLOUR_BIG_ENDIAN 1
315
316#define ARM_2D_M_COLOUR_LITTLE_ENDIAN_msk (ARM_2D_M_COLOUR_LITTLE_ENDIAN << 4)
317#define ARM_2D_M_COLOUR_BIG_ENDIAN_msk (ARM_2D_M_COLOUR_BIG_ENDIAN << 4)
318
319#define ARM_2D_M_COLOUR_NO_ALPHA 0
320#define ARM_2D_M_COLOUR_HAS_ALPHA 1
321
322#define ARM_2D_M_COLOUR_NO_ALPHA_msk (ARM_2D_M_COLOUR_NO_ALPHA << 0)
323#define ARM_2D_M_COLOUR_HAS_ALPHA_msk (ARM_2D_M_COLOUR_HAS_ALPHA << 0)
324
325#define ARM_2D_M_COLOUR_VARIANT_pos 5
326#define ARM_2D_M_COLOUR_VARIANT_msk (0x07 << ARM_2D_M_COLOUR_VARIANT_pos)
327
328/*!
329 * \brief enumerations for colour types
330 *
331 */
332enum {
333 ARM_2D_COLOUR_BIN = ARM_2D_COLOUR_SZ_1BIT_msk,
334 ARM_2D_COLOUR_1BIT = ARM_2D_COLOUR_SZ_1BIT_msk,
335
336 ARM_2D_COLOUR_8BIT = ARM_2D_COLOUR_SZ_8BIT_msk,
337 ARM_2D_COLOUR_GRAY8 = ARM_2D_COLOUR_SZ_8BIT_msk,
338
339 ARM_2D_COLOUR_16BIT = ARM_2D_COLOUR_SZ_16BIT_msk,
340 ARM_2D_COLOUR_RGB16 = ARM_2D_COLOUR_SZ_16BIT_msk,
341 ARM_2D_COLOUR_RGB565 = ARM_2D_COLOUR_RGB16,
342
343/* won't support
344 ARM_2D_COLOUR_RGB565_BE = ARM_2D_COLOUR_SZ_16BIT_msk |
345 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
346 */
347
348 ARM_2D_COLOUR_32BIT = ARM_2D_COLOUR_SZ_32BIT_msk ,
349 ARM_2D_COLOUR_RGB32 = ARM_2D_COLOUR_SZ_32BIT_msk ,
350
351 ARM_2D_COLOUR_CCCN888 = ARM_2D_COLOUR_RGB32 ,
352 ARM_2D_COLOUR_CCCA8888 = ARM_2D_COLOUR_SZ_32BIT_msk |
353 ARM_2D_COLOUR_HAS_ALPHA_msk ,
354
355 ARM_2D_COLOUR_RGB888 = ARM_2D_COLOUR_CCCN888 ,
356 ARM_2D_COLOUR_BGRA8888 = ARM_2D_COLOUR_CCCA8888 ,
357
358/* not supported yet
359 ARM_2D_COLOUR_NCCC888 = ARM_2D_COLOUR_RGB32 |
360 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
361 ARM_2D_COLOUR_ACCC8888 = ARM_2D_COLOUR_SZ_32BIT_msk |
362 ARM_2D_COLOUR_HAS_ALPHA_msk |
363 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
364*/
365 ARM_2D_CHANNEL_8in32 = ARM_2D_COLOUR_SZ_32BIT_msk |
366 ARM_2D_COLOUR_HAS_ALPHA_msk |
367 ARM_2D_COLOUR_VARIANT_msk ,
368};
369
370/* macros for colour formats */
371#define ARM_2D_M_COLOUR_BIN ARM_2D_M_COLOUR_SZ_1BIT_msk
372#define ARM_2D_M_COLOUR_1BIT ARM_2D_M_COLOUR_SZ_1BIT_msk
373
374#define ARM_2D_M_COLOUR_8BIT ARM_2D_M_COLOUR_SZ_8BIT_msk
375#define ARM_2D_M_COLOUR_GRAY8 ARM_2D_M_COLOUR_SZ_8BIT_msk
376
377#define ARM_2D_M_COLOUR_16BIT ARM_2D_M_COLOUR_SZ_16BIT_msk
378#define ARM_2D_M_COLOUR_RGB16 ARM_2D_M_COLOUR_SZ_16BIT_msk
379#define ARM_2D_M_COLOUR_RGB565 ARM_2D_M_COLOUR_RGB16
380
381/* won't support
382#define ARM_2D_M_COLOUR_RGB565_BE ( ARM_2D_M_COLOUR_SZ_16BIT_msk \
383 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
384 */
385
386#define ARM_2D_M_COLOUR_32BIT ARM_2D_M_COLOUR_SZ_32BIT_msk
387#define ARM_2D_M_COLOUR_RGB32 ARM_2D_M_COLOUR_SZ_32BIT_msk
388
389#define ARM_2D_M_COLOUR_CCCN888 ARM_2D_M_COLOUR_RGB32
390#define ARM_2D_M_COLOUR_CCCA8888 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
391 | ARM_2D_M_COLOUR_HAS_ALPHA_msk)
392
393#define ARM_2D_M_COLOUR_RGB888 ARM_2D_M_COLOUR_CCCN888
394#define ARM_2D_M_COLOUR_RGBA8888 ARM_2D_M_COLOUR_CCCA8888
395
396/* not supported yet
397#define ARM_2D_M_COLOUR_NCCC888 ( ARM_2D_M_COLOUR_RGB32 \
398 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
399#define ARM_2D_M_COLOUR_ACCC8888 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
400 | ARM_2D_M_COLOUR_HAS_ALPHA_msk \
401 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
402*/
403#define ARM_2D_M_CHANNEL_8in32 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
404 | ARM_2D_M_COLOUR_HAS_ALPHA_msk) \
405 | ARM_2D_M_COLOUR_VARIANT_msk )
406
407/*!
408 * \brief a type used as colour descriptor
409 *
410 */
411typedef union {
412 struct {
413 uint8_t bHasAlpha : 1; //!< whether the target colour has alpha channel
414 uint8_t u3ColourSZ : 3; //!< the size of the colour
415 uint8_t bBigEndian : 1; //!< whether the colour is stored in big endian
416 uint8_t u3Variant : 3;
417 };
418 uint8_t chScheme;
420
421/*----------------------------------------------------------------------------*
422 * Tile and Regions *
423 *----------------------------------------------------------------------------*/
424
425/*!
426 * \brief a type for coordinates (integer)
427 *
428 */
429typedef struct arm_2d_location_t {
430 int16_t iX; //!< x in Cartesian coordinate system
431 int16_t iY; //!< y in Cartesian coordinate system
433
434/*!
435 * \brief a type for coordinates in floating point
436 *
437 */
438typedef struct arm_2d_point_float_t {
439 float fX; //!< x in Cartesian coordinate system
440 float fY; //!< y in Cartesian coordinate system
442
443/*!
444 * \brief a type for coordinates in fixed point
445 *
446 */
447typedef struct arm_2d_point_fx_t {
448 int32_t X; //!< x in Cartesian coordinate system
449 int32_t Y; //!< y in Cartesian coordinate system
451
452/*!
453 * \brief a type for the size of an rectangular area
454 *
455 */
456typedef struct arm_2d_size_t {
457 int16_t iWidth; //!< width of an rectangular area
458 int16_t iHeight; //!< height of an rectangular area
460
461/*!
462 * \brief a type for an rectangular area
463 *
464 */
465typedef struct arm_2d_region_t {
466 implement_ex(arm_2d_location_t, tLocation); //!< the location (top-left corner)
467 implement_ex(arm_2d_size_t, tSize); //!< the size
469
470/*!
471 * \brief a type for tile
472 *
473 */
474typedef struct arm_2d_tile_t arm_2d_tile_t;
476 implement_ex(struct {
477 uint8_t bIsRoot : 1; //!< is this tile a root tile
478 uint8_t bHasEnforcedColour : 1; //!< does this tile contains enforced colour info
479 uint8_t bDerivedResource : 1; //!< indicate whether this is a derived resources (when bIsRoot == 0)
480 uint8_t bVirtualResource : 1; //!< indicate whether the resource should be loaded on-demand
481 uint8_t : 4;
482 uint8_t : 8;
483 uint8_t : 8;
484 arm_2d_color_info_t tColourInfo; //!< enforced colour
485 }, tInfo);
486
487 implement_ex(arm_2d_region_t, tRegion); //!< the region of the tile
488
489 union {
490 /* when bIsRoot is true, phwBuffer is available,
491 * otherwise ptParent is available
492 */
493 arm_2d_tile_t *ptParent; //!< a pointer points to the parent tile
494 uint8_t *pchBuffer; //!< a pointer points to a buffer in a 8bit colour type
495 uint16_t *phwBuffer; //!< a pointer points to a buffer in a 16bit colour type
496 uint32_t *pwBuffer; //!< a pointer points to a buffer in a 32bit colour type
497
498 intptr_t nAddress; //!< a pointer in integer
499 };
500};
501
502/*!
503 * \brief a type for virtual resource
504 *
505 * \note the flag tTile.tInfo.bVirtualResource must be true (1)
506 */
507typedef struct arm_2d_vres_t arm_2d_vres_t;
509
510 /*! base class: tTile */
511 implement_ex( arm_2d_tile_t, tTile);
512
513 /*! a reference of an user object */
514 uintptr_t pTarget;
515
516 /*!
517 * \brief a method to load a specific part of an image
518 * \param[in] pTarget a reference of an user object
519 * \param[in] ptVRES a reference of this virtual resource
520 * \param[in] ptRegion the target region of the image
521 * \return intptr_t the address of a resource buffer which holds the content
522 */
523 intptr_t (*Load) ( uintptr_t pTarget,
524 arm_2d_vres_t *ptVRES,
525 arm_2d_region_t *ptRegion);
526
527 /*!
528 * \brief a method to despose the buffer
529 * \param[in] pTarget a reference of an user object
530 * \param[in] ptVRES a reference of this virtual resource
531 * \param[in] pBuffer the target buffer
532 */
533 void (*Depose) ( uintptr_t pTarget,
534 arm_2d_vres_t *ptVRES,
535 intptr_t pBuffer );
536};
537
538/*----------------------------------------------------------------------------*
539 * Task *
540 *----------------------------------------------------------------------------*/
541
542/*!
543 * \brief arm-2d application level task control block
544 *
545 */
546typedef struct arm_2d_task_t {
547ARM_PRIVATE(
548 arm_fsm_rt_t tResult; //!< the temporary result of the task
549 uint8_t chState; //!< the state of the FSM
550
551 void *ptTask; //!< a pointer for an internal object
554
555/*----------------------------------------------------------------------------*
556 * Operation and Events Handling *
557 *----------------------------------------------------------------------------*/
558
559
561
562/*!
563 * \brief a prototype of event handlers for 2D operations
564 *
565 * \param[in] ptThisOP the target 2D operation descriptor
566 * \param[in] tResult the operation result
567 * \param[in] pTarget A user attached object
568 * \return bool a boolean value to indicate whether the event has been handled
569 */
571 arm_fsm_rt_t tResult,
572 void *pTarget);
573
574/*!
575 * \brief a type for 2D operation event handling
576 *
577 */
578typedef struct arm_2d_op_evt_t {
580 void *pTarget; //!< user attached target
582
583/*!
584 * \brief a prototype for generic event handlers
585 *
586 * \param pTarget A user attached object
587 * \return bool a boolean value to indicate whether the event has been handled
588 */
589typedef bool arm_2d_evt_handler_t(void *pTarget);
590
591/*!
592 * \brief a type for generic event handling
593 *
594 */
595typedef struct arm_2d_evt_t {
596 arm_2d_evt_handler_t *fnHandler; //!< event handler
597 void *pTarget; //!< user attached target
599
600
601#define ARM_2D_OP_INFO_PARAM_HAS_SOURCE _BV(0)
602#define ARM_2D_OP_INFO_PARAM_HAS_TARGET _BV(1)
603#define ARM_2D_OP_INFO_PARAM_HAS_SOURCE_MASK _BV(2)
604#define ARM_2D_OP_INFO_PARAM_HAS_TARGET_MASK _BV(3)
605#define ARM_2D_OP_INFO_PARAM_HAS_ORIGIN _BV(4)
606
607#define ARM_2D_OP_INFO_PARAM_TILES_MASK ( \
608 ARM_2D_OP_INFO_PARAM_HAS_SOURCE | \
609 ARM_2D_OP_INFO_PARAM_HAS_TARGET | \
610 ARM_2D_OP_INFO_PARAM_HAS_SOURCE_MASK | \
611 ARM_2D_OP_INFO_PARAM_HAS_TARGET_MASK | \
612 ARM_2D_OP_INFO_PARAM_HAS_ORIGIN )
613
614
615//! \brief an incomplete defintion which is only used for defining pointers
617
618/*!
619 * \brief A descriptive header for 2D operations
620 */
621typedef union __arm_2d_op_info_t {
622 struct {
623 arm_2d_color_info_t Colour; //!< the colour used in thie operation
624 union {
625 struct {
626 uint8_t bHasSource : 1; //!< whether this operation contains source tile
627 uint8_t bHasTarget : 1; //!< whether this operation contains target tile
628 uint8_t bHasSrcMask : 1; //!< whether this operation has Mask layer for source tile
629 uint8_t bHasDesMask : 1; //!< whether this operation has Mask layer for target tile
630 uint8_t bHasOrigin : 1; //!< whether the Source has an origin tile
631 uint8_t : 2;
632 uint8_t bAllowEnforcedColour : 1; //!< whether this operation allow enforced colours in tiles
633 };
634 uint8_t chValue; //!< feature value
635 }Param; //!< operation feature set
636
637 uint8_t chInClassOffset; //!< some operation uses this as the offset of the key member in the class
638 uint8_t chOpIndex; //!< __ARM_2D_OP_IDX_XXXXXX
639
640 union {
641 struct {
642 uint8_t CopyLike; //!< A copy-like interface contains the target tile, the source tile and the copy size
643 uint8_t FillLike; //!< A copy-like interface contains the target tile and the source tile
644 };
645 struct {
646 uint8_t CopyOrigLike; //!< A copy-like interface contains the target tile, the dummy tile, the reference to the original source tile and the copy size
647 uint8_t FillOrigLike; //!< A copy-like interface contains the target tile, the dummy tile and the reference to the original source tile
648 };
649 struct {
650 uint8_t TileProcessLike; //!< A simple interface contains only the target tile
651 };
652 }LowLevelInterfaceIndex; //!< Low level interface index
653
654 union {
655 const __arm_2d_low_level_io_t *IO[2]; //!< array of IOs
656
657 struct {
658 const __arm_2d_low_level_io_t *ptCopyLike; //!< the function pointer for a copy-like implementation
659 const __arm_2d_low_level_io_t *ptFillLike; //!< the function pointer for a fill-like implementation
660 };
661 struct {
662 const __arm_2d_low_level_io_t *ptCopyOrigLike; //!< the function pointer for a copy-orig-like implementation
663 const __arm_2d_low_level_io_t *ptFillOrigLike; //!< the function pointer for a fill-orig-like implementation
664 };
665 struct {
666 const __arm_2d_low_level_io_t *ptTileProcessLike; //!< the function pointer for the tile-process-like implementation
667 };
668 }LowLevelIO; //!< low level IO definition
669
670 }Info; //!< operation description
671 uint32_t wID; //!< Operation ID
673
674/*!
675 * \brief how would you want to accelerate the 2d-operation
676 */
677enum {
678 //! Use hardware acceleration if possible, even if there is a long queue to wait
680
681 //! Only use Hardware Acceleration, if it is not supported, IO error will be issued
683
684 //! Only use software algorithm
686
687 //!< don't care, let the arm-2d library decide
688 ARM_2D_PREF_ACC_DONT_CARE = 3,
689};
690
691#define __ARM_2D_OP_STATUS_BUSY_msk (1 << 4)
692#define __ARM_2D_OP_STATUS_IO_ERROR_msk (1 << 5)
693#define __ARM_2D_OP_STATUS_CPL_msk (1 << 6)
694
695/*!
696 * \brief a type for 2D operation status
697 *
698 */
699typedef union arm_2d_op_status_t {
700 struct {
701 uint16_t u4SubTaskCount : 4; //!< sub task count
702 uint16_t bIsBusy : 1; //!< busy flag
703 uint16_t bIOError : 1; //!< HW IO Error
704 uint16_t bOpCpl : 1; //!< the whole operation complete
705 uint16_t : 9; //!< reserved
706 };
707 uint16_t tValue; //!< the host integer
709
710/*!
711 * \brief the abstract class of 2D operations
712 *
713 */
715ARM_PRIVATE(
716 arm_2d_op_core_t *ptNext; //!< a pointer for a single list
717
718 const __arm_2d_op_info_t *ptOp; //!< the pointer for the corresponding 2D operation description
719
720 struct {
721 uint8_t u2ACCMethods : 2; //!< acceleration Methods
722 uint8_t : 6; //!< reserved
723 }Preference;
724
725 int8_t tResult; //!< operation result
726 volatile arm_2d_op_status_t Status; //!< operation status
727
728 arm_2d_op_evt_t evt2DOpCpl; //!< operation-complete event
729
731 uintptr_t pUserParam; //!< user attached object
732};
733
734/*!
735 * \brief the base class for operations with only a target tile
736 * \note arm_2d_op_msk_t inherits from arm_2d_op_core_t
737 */
738typedef struct arm_2d_op_t {
739 inherit(arm_2d_op_core_t);
740 struct {
741 const arm_2d_tile_t *ptTile; //!< target tile
742 const arm_2d_region_t *ptRegion; //!< target region
743 } Target;
745
746/*!
747 * \brief the base class for operations with a target tile and a target mask
748 * \note arm_2d_op_msk_t inherits from arm_2d_op_t
749 */
750typedef struct arm_2d_op_msk_t {
751 inherit(arm_2d_op_core_t);
752 struct {
753 const arm_2d_tile_t *ptTile; //!< target tile
754 const arm_2d_region_t *ptRegion; //!< target region
755 } Target;
756
757 /* derived part */
758 struct {
759 const arm_2d_tile_t *ptTile; //!< target tile
760 } Mask;
762
763/*!
764 * \brief the base class for operations with a target tile and a source tile
765 * \note arm_2d_op_src_t inherits from arm_2d_op_t
766 */
767typedef struct arm_2d_op_src_t {
768 inherit(arm_2d_op_core_t);
769 struct {
770 const arm_2d_tile_t *ptTile; //!< target tile
771 const arm_2d_region_t *ptRegion; //!< target region
772 } Target;
773
774 /* derived part */
775 struct {
776 const arm_2d_tile_t *ptTile; //!< source tile
777 }Source;
778 uint32_t wMode;
780
781/*!
782 * \brief the base class for operations with a target tile, a source tile and masks
783 * \note arm_2d_op_src_msk_t inherits from arm_2d_op_src_t
784 */
785typedef struct arm_2d_op_src_msk_t {
786 inherit(arm_2d_op_core_t);
787 struct {
788 const arm_2d_tile_t *ptTile; //!< target tile
789 const arm_2d_region_t *ptRegion; //!< target region
790 } Target;
791 struct {
792 const arm_2d_tile_t *ptTile; //!< source tile
793 }Source;
794 uint32_t wMode;
795
796 /* derived part */
797 struct {
798 const arm_2d_tile_t *ptSourceSide; //!< source side mask
799 const arm_2d_tile_t *ptTargetSide; //!< target side mask
800 } Mask;
802
803/*!
804 * \brief the base class for operations with a target tile, a dummy tile and a reference to the original source tile
805 * \note arm_2d_op_src_orig_t inherits from arm_2d_op_src_t
806 */
807typedef struct arm_2d_op_src_orig_t {
808 inherit(arm_2d_op_core_t);
809 struct {
810 const arm_2d_tile_t *ptTile; //!< target tile
811 const arm_2d_region_t *ptRegion; //!< target region
812 } Target;
813 struct {
814 const arm_2d_tile_t *ptTile; //!< the dummy source tile
815 }Source;
816 uint32_t wMode;
817
818 /* derived part */
819 struct {
820 const arm_2d_tile_t *ptTile; //!< the origin tile
821 arm_2d_tile_t tDummySource; //!< the buffer for the source
822 }Origin;
823
825
826/*!
827 * \brief the base class for operations with a target tile, a dummy tile, a reference to the original source tile and masks
828 * \note arm_2d_op_src_orig_msk_t inherits from arm_2d_op_src_orig_t
829 */
831 inherit(arm_2d_op_core_t);
832 struct {
833 const arm_2d_tile_t *ptTile; //!< target tile
834 const arm_2d_region_t *ptRegion; //!< target region
835 } Target;
836 struct {
837 const arm_2d_tile_t *ptTile; //!< the dummy source tile
838 }Source;
839 uint32_t wMode;
840 struct {
841 const arm_2d_tile_t *ptTile; //!< the origin tile
842 arm_2d_tile_t tDummySource; //!< the buffer for the source
843 }Origin;
844
845 /* derived part */
846 struct {
847 const arm_2d_tile_t *ptOriginSide; //!< origin side mask
848 const arm_2d_tile_t *ptTargetSide; //!< target side mask
849 } Mask;
851
852
853/*----------------------------------------------------------------------------*
854 * Fast Rotation linear regression structure
855 *----------------------------------------------------------------------------*/
856
857#if (__ARM_2D_HAS_HELIUM_FLOAT__ || __ARM_2D_HAS_FPU__) \
858 && !__ARM_2D_CFG_FORCED_FIXED_POINT_TRANSFORM__
859/*!
860 * \brief a type for parameters of linear interpolation (in floating point)
861 *
862 */
863typedef struct arm_2d_rot_linear_regr_t {
864 float slopeY;
865 float interceptY;
866 float slopeX;
867 float interceptX;
869
870#else
871/*!
872 * \brief a type for parameters of linear interpolation (in fixed point)
873 *
874 */
876 int32_t slopeY;
877 int32_t interceptY;
878 int32_t slopeX;
879 int32_t interceptX;
881
882#endif
883
884/*============================ GLOBAL VARIABLES ==============================*/
885/*============================ PROTOTYPES ====================================*/
886
887/*! @} */
888
889#if defined(__clang__)
890#pragma clang diagnostic pop
891#elif __IS_COMPILER_ARM_COMPILER_5__
892#pragma diag_warning 64
893#elif __IS_COMPILER_GCC__
894#pragma GCC diagnostic pop
895#endif
896
897#ifdef __cplusplus
898}
899#endif
900
901#endif // __ARM_2D_TYPES_H__
902
903