Arm-2D  
2D Image Processing Library for Cortex-M Processors
arm_2d_helper.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_helper.h"
22 * Description: Public header file for the all helper services
23 *
24 * $Date: 03. Sept 2022
25 * $Revision: V.1.2.0
26 *
27 * Target Processor: Cortex-M cores
28 * -------------------------------------------------------------------- */
29
30#ifndef __ARM_2D_HELPER_H__
31#define __ARM_2D_HELPER_H__
32
33/*============================ INCLUDES ======================================*/
34#include "arm_2d.h"
35#include "./arm_2d_helper_pfb.h"
36#include "./arm_2d_helper_scene.h"
37#include "./arm_2d_disp_adapters.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43#if defined(__clang__)
44# pragma clang diagnostic push
45# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
46# pragma clang diagnostic ignored "-Wunused-function"
47#endif
48
49
50/*!
51 * \addtogroup gHelper 7 Helper Services
52 * @{
53 */
54/*============================ MACROS ========================================*/
55/*============================ MACROFIED FUNCTIONS ===========================*/
56
57#define __declare_tile(__name) \
58 extern const arm_2d_tile_t __name;
59#define declare_tile(__name) __declare_tile(__name)
60
61#define dcl_tile(__name) declare_tile(__name)
62#define dcl_fb(__name) declare_tile(__name)
63
64
65#define __impl_fb(__NAME, __WIDTH, __HEIGHT, __TYPE, ...) \
66 ARM_NOINIT static __TYPE \
67 __NAME##Buffer[(__WIDTH) * (__HEIGHT)]; \
68 const arm_2d_tile_t __NAME = { \
69 .tRegion = { \
70 .tSize = {(__WIDTH), (__HEIGHT)}, \
71 }, \
72 .tInfo.bIsRoot = true, \
73 .pchBuffer = (uint8_t *)__NAME##Buffer, \
74 __VA_ARGS__ \
75 };
76
77#define impl_fb(__NAME, __WIDTH, __HEIGHT, __TYPE, ...) \
78 __impl_fb(__NAME, __WIDTH, __HEIGHT, __TYPE, ##__VA_ARGS__)
79
80#define get_tile_buffer_pixel_count(__NAME) \
81 (uint32_t)( (__NAME.tRegion.tSize.iWidth) \
82 * (__NAME.tRegion.tSize.iHeight))
83
84#define get_tile_buffer_size(__NAME, __TYPE) \
85 (get_2d_layer_buffer_pixel_count(__NAME) * sizeof(TYPE))
86
87
88#define impl_child_tile(__PARENT, __X, __Y, __WIDTH, __HEIGHT, ...) { \
89 .tRegion = { \
90 .tLocation = { \
91 .iX = (__X), \
92 .iY = (__Y), \
93 }, \
94 .tSize = { \
95 .iWidth = (__WIDTH), \
96 .iHeight = (__HEIGHT), \
97 }, \
98 }, \
99 .tInfo.bIsRoot = false, \
100 .tInfo.bDerivedResource = true, \
101 .ptParent = (arm_2d_tile_t *)&(__PARENT), \
102 __VA_ARGS__ \
103 }
104
105#define __arm_2d_align_centre2(__region, __size) \
106 for (arm_2d_region_t __centre_region = { \
107 .tSize = (__size), \
108 .tLocation = { \
109 .iX = ((__region).tSize.iWidth - (__size).iWidth) >> 1,\
110 .iY = ((__region).tSize.iHeight - (__size).iHeight)>> 1,\
111 }, \
112 }, \
113 *ARM_CONNECT3(__ARM_USING_, __LINE__,_ptr) = NULL; \
114 ARM_CONNECT3(__ARM_USING_, __LINE__,_ptr)++ == NULL; \
115 arm_2d_op_wait_async(NULL) \
116 )
117
118#define __arm_2d_align_centre3(__region, __width, __height) \
119 for (arm_2d_region_t __centre_region = { \
120 .tSize = { \
121 .iWidth = (__width), \
122 .iHeight = (__height), \
123 }, \
124 .tLocation = { \
125 .iX = ((__region).tSize.iWidth - (__width)) >> 1, \
126 .iY = ((__region).tSize.iHeight - (__height))>> 1, \
127 }, \
128 }, \
129 *ARM_CONNECT3(__ARM_USING_, __LINE__,_ptr) = NULL; \
130 ARM_CONNECT3(__ARM_USING_, __LINE__,_ptr)++ == NULL; \
131 arm_2d_op_wait_async(NULL) \
132 )
133
134#define arm_2d_align_centre(...) \
135 ARM_CONNECT2( __arm_2d_align_centre, \
136 __ARM_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
137
138/*!
139 * \brief set an alarm with given period and check the status
140 *
141 * \param[in] wMS a time period in millisecond
142 * \param[in] ... an optional timestamp holder
143 *
144 * \return bool whether it is timeout
145 */
146#define arm_2d_helper_is_time_out(__MS, ...) \
147 __arm_2d_helper_is_time_out((__MS), (NULL, ##__VA_ARGS__))
148
149/*============================ TYPES =========================================*/
150/*============================ GLOBAL VARIABLES ==============================*/
151/*============================ LOCAL VARIABLES ===============================*/
152/*============================ PROTOTYPES ====================================*/
153
154__STATIC_INLINE bool __arm_2d_helper_is_time_out(uint32_t wMS, int64_t *plTimestamp)
155{
156 int64_t lTimestamp = arm_2d_helper_get_system_timestamp();
157 static int64_t s_lTimestamp = 0;
158 if (NULL == plTimestamp) {
159 plTimestamp = &s_lTimestamp;
160 }
161
162 if (0 == *plTimestamp) {
163 *plTimestamp = arm_2d_helper_convert_ms_to_ticks(wMS);
164 *plTimestamp += lTimestamp;
165
166 return false;
167 }
168
169 if (lTimestamp >= *plTimestamp) {
170 *plTimestamp = arm_2d_helper_convert_ms_to_ticks(wMS) + lTimestamp;
171 return true;
172 }
173
174 return false;
175}
176
177/*! @} */
178
179#if defined(__clang__)
180# pragma clang diagnostic pop
181#endif
182
183#ifdef __cplusplus
184}
185#endif
186
187#endif