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: 06. April 2023
25 * $Revision: V.1.6.2
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_common.h"
36#include "./arm_2d_helper_pfb.h"
37#include "./arm_2d_helper_scene.h"
38#include "./arm_2d_disp_adapters.h"
39#include "./arm_2d_helper_list.h"
40
41#include <stdlib.h>
42#include <assert.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48#if defined(__clang__)
49# pragma clang diagnostic push
50# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
51# pragma clang diagnostic ignored "-Wunused-function"
52#endif
53
54/*!
55 * \addtogroup Deprecated
56 * @{
57 */
58#define arm_2d_draw_box arm_2d_helper_draw_box
59/*! @} */
60
61/*!
62 * \addtogroup gHelper 7 Helper Services
63 * @{
64 */
65/*============================ MACROS ========================================*/
66/*============================ MACROFIED FUNCTIONS ===========================*/
67
68/*!
69 * \brief set an alarm with given period and check the status
70 *
71 * \param[in] __ms a time period in millisecond
72 * \param[in] ... an optional timestamp holder
73 *
74 * \return bool whether it is timeout
75 */
76#define arm_2d_helper_is_time_out(__ms, ...) \
77 ({ static int64_t arm_2d_safe_name(s_lTimestamp); \
78 __arm_2d_helper_is_time_out(arm_2d_helper_convert_ms_to_ticks(__ms), \
79 (&arm_2d_safe_name(s_lTimestamp),##__VA_ARGS__));})
80
81
82/*!
83 * \brief calculate the stroke of a liner slider based on time
84 *
85 * \param[in] __from the start of the slider
86 * \param[in] __to the end of the slider
87 * \param[in] __ms a given period (ms) in which the slider should finish the
88 * whole stroke
89 * \param[out] __stroke_ptr the address of an int32_t stroke variable
90 * \param[in] ... an optional address of a timestamp variable, if you omit it,
91 * NULL will be passed, and the code that call this funtion will not
92 * be reentrant.
93 * \retval true the slider has finished the whole stroke
94 * \retval false the slider hasn't reach the target end
95 */
96#define arm_2d_helper_time_liner_slider( __from, \
97 __to, \
98 __ms, \
99 __stroke_ptr, \
100 ...) \
101 ({static int64_t arm_2d_safe_name(s_lTimestamp); \
102 __arm_2d_helper_time_liner_slider((__from), \
103 (__to), \
104 arm_2d_helper_convert_ms_to_ticks(__ms), \
105 (__stroke_ptr), \
106 (&arm_2d_safe_name(s_lTimestamp),##__VA_ARGS__));})
107
108/*!
109 * \brief calculate the stroke of a cosine slider based on time
110 *
111 * \param[in] __from the start of the slider
112 * \param[in] __to the end of the slider
113 * \param[in] __ms a given period (ms) in which the slider should finish the
114 * whole stroke
115 * \param[in] __phase the phase offset
116 * \param[out] __stroke_ptr the address of an int32_t stroke variable
117 * \param[in] ... an optional address of a timestamp variable, if you omit it,
118 * NULL will be passed, and the code that call this funtion will not
119 * be reentrant.
120 * \retval true the slider has finished the whole stroke
121 * \retval false the slider hasn't reach the target end
122 */
123#define arm_2d_helper_time_cos_slider( __from, \
124 __to, \
125 __ms, \
126 __phase, \
127 __stroke_ptr, \
128 ...) \
129 ({static int64_t arm_2d_safe_name(s_lTimestamp); \
130 __arm_2d_helper_time_cos_slider((__from), \
131 (__to), \
132 arm_2d_helper_convert_ms_to_ticks(__ms), \
133 (__phase), \
134 (__stroke_ptr), \
135 (&arm_2d_safe_name(s_lTimestamp),##__VA_ARGS__));})
136
137/*!
138 * \brief calculate the stroke of a cosine slider(0~pi) based on time
139 *
140 * \param[in] __from the start of the slider
141 * \param[in] __to the end of the slider
142 * \param[in] __ms a given period (ms) in which the slider should finish the
143 * whole stroke
144 * \param[out] __stroke_ptr the address of an int32_t stroke variable
145 * \param[in] ... an optional address of a timestamp variable, if you omit it,
146 * NULL will be passed, and the code that call this funtion will not
147 * be reentrant.
148 * \retval true the slider has finished the whole stroke
149 * \retval false the slider hasn't reach the target end
150 */
151#define arm_2d_helper_time_half_cos_slider( __from, \
152 __to, \
153 __ms, \
154 __stroke_ptr, \
155 ...) \
156 ({static int64_t arm_2d_safe_name(s_lTimestamp); \
157 __arm_2d_helper_time_half_cos_slider((__from), \
158 (__to), \
159 arm_2d_helper_convert_ms_to_ticks(__ms), \
160 (__stroke_ptr), \
161 (&arm_2d_safe_name(s_lTimestamp),##__VA_ARGS__));})
162
163
164
165/*============================ TYPES =========================================*/
166/*============================ GLOBAL VARIABLES ==============================*/
167/*============================ LOCAL VARIABLES ===============================*/
168/*============================ PROTOTYPES ====================================*/
169
170/*!
171 * \brief initialize helper services
172 */
173extern
175
176/*!
177 * \brief backend task for asynchronose mode
178 */
179extern
181
182/*!
183 * \brief convert ticks of a reference timer to millisecond
184 *
185 * \param[in] lTick the tick count
186 * \return int64_t the millisecond
187 */
188extern
190
191/*!
192 * \brief convert millisecond into ticks of the reference timer
193 *
194 * \param[in] wMS the target time in millisecond
195 * \return int64_t the ticks
196 */
197extern
199
200/*!
201 * \brief get the reference clock frequency
202 * \return uint32_t the frequency
203 */
204extern
206
207/*!
208 * \brief get the current system stamp from the reference clock
209 *
210 * \return int64_t the timestamp in ticks (no overflow issue)
211 * \note you have to call arm_2d_helper_convert_ticks_to_ms() to convert the
212 * the timestamp into milliseconds when required.
213 */
214extern
216
217
218/*!
219 * \brief set an alarm with given period and check the status
220 *
221 * \param[in] lPeriod a time period in ticks
222 * \param[in] plTimestamp a pointer points to an int64_t integer, if NULL is
223 * passed, an static local variable inside the function will be used
224 * \return bool whether it is timeout or not
225 */
226ARM_NONNULL(2)
227extern
228bool __arm_2d_helper_is_time_out(int64_t lPeriod, int64_t *plTimestamp);
229
230/*!
231 * \brief calculate the stroke of a liner slider based on time
232 *
233 * \param[in] nFrom the start of the slider
234 * \param[in] nTo the end of the slider
235 * \param[in] lPeriod a given period in which the slider should finish the whole
236 * stroke
237 * \param[out] pnStroke the address of an int32_t stroke variable
238 * \param[in] plTimestamp the address of a timestamp variable, if you pass NULL
239 * the code that call this funtion will not be reentrant.
240 * \retval true the slider has finished the whole stroke
241 * \retval false the slider hasn't reach the target end
242 */
243ARM_NONNULL(4,5)
244extern
246 int32_t nTo,
247 int64_t lPeriod,
248 int32_t *pnStroke,
249 int64_t *plTimestamp);
250
251/*!
252 * \brief calculate the stroke of a cosine slider (0~pi) based on time
253 *
254 * \param[in] nFrom the start of the slider
255 * \param[in] nTo the end of the slider
256 * \param[in] lPeriod a given period in which the slider should finish the whole
257 * stroke
258 * \param[out] pnStroke the address of an int32_t stroke variable
259 * \param[in] plTimestamp the address of a timestamp variable, if you pass NULL
260 * the code that call this funtion will not be reentrant.
261 * \retval true the slider has finished the whole stroke
262 * \retval false the slider hasn't reach the target end
263 */
264ARM_NONNULL(4,5)
265extern
267 int32_t nTo,
268 int64_t lPeriod,
269 int32_t *pnStroke,
270 int64_t *plTimestamp);
271
272/*!
273 * \brief calculate the stroke of a consine slider (0~2pi) based on time
274 *
275 * \param[in] nFrom the start of the slider
276 * \param[in] nTo the end of the slider
277 * \param[in] lPeriod a given period in which the slider should finish the whole
278 * stroke
279 * \param[in] lPhase the phase offset
280 * \param[out] pnStroke the address of an int32_t stroke variable
281 * \param[in] plTimestamp the address of a timestamp variable, if you pass NULL
282 * the code that call this funtion will not be reentrant.
283 * \retval true the slider has finished the whole stroke
284 * \retval false the slider hasn't reach the target end
285 */
286ARM_NONNULL(5,6)
287extern
289 int32_t nTo,
290 int64_t lPeriod,
291 float fPhase,
292 int32_t *pnStroke,
293 int64_t *plTimestamp);
294
295/*!
296 * \brier colour intrapolation
297 * \param[in] wFrom a 32bit colour (4 8bit colour channels) on the start
298 * \param[in] wTo a 32bit colour (4 8bit colour channels) on the end
299 * \param[in] nDistance the reference full distance between two end points
300 * \param[in] nOffset the offset from the start
301 * \return uint32_t 32bit colour
302 */
303extern
304uint32_t __arm_2d_helper_colour_slider( uint32_t wFrom,
305 uint32_t wTo,
306 int32_t nDistance,
307 int32_t nOffset);
308
309/*!
310 * \brier draw a box with specified colour, border width and opacity
311 * \param[in] ptTarget the target tile
312 * \param[in] ptRegion the target region
313 * \param[in] iBorderWidth the border width
314 * \param[in] tColour the target colour
315 * \param[in] chOpacity the opacity
316 */
317extern
319 const arm_2d_region_t *ptRegion,
320 int16_t iBorderWidth,
321 COLOUR_INT tColour,
322 uint8_t chOpacity);
323
324
325/*! @} */
326
327#if defined(__clang__)
328# pragma clang diagnostic pop
329#endif
330
331#ifdef __cplusplus
332}
333#endif
334
335#endif